--- mpm.c- Sun Apr 4 19:40:41 1999 +++ mpm.c Sun Apr 4 23:47:45 1999 @@ -21,6 +21,7 @@ #include #include #include +#include /* turboc */ #if defined(__TURBOC__) @@ -28,6 +29,8 @@ #define OUTPORT(p,v) outportb( p, v ) #define INPORT(p) inportb( p ) #define DELAY(s) delay((UINT)s*1000) +#define IOOPEN +#define IOCLOSE /* linux */ #elif defined(__linux__) @@ -36,6 +39,19 @@ #define OUTPORT(p,v) outb( v, p ) #define INPORT(p) inb( p ) #define DELAY(s) sleep(s) +#define IOOPEN +#define IOCLOSE + +#elif defined(__FreeBSD__) +#include +#include +#define OUTPORT(p,v) outb(p, v) +#define INPORT(p) inb(p) +#define DELAY(s) sleep(s) +#define IOOPEN get_ioperm(1) +#define IOCLOSE get_ioperm(0) + +void get_ioperm(int); /* else */ #else @@ -907,68 +923,38 @@ } /****************************************************************************/ + +void usage() +{ + printf( "\nmpman utility v%d.%02d - Ashpool Systems (c) 1998\n", + ID_VERSION/100, ID_VERSION%100 ); +} + /* entry point */ -BOOL main( int iArgc, char* paszArgv[] ) +BOOL main( int argc, char* argv[] ) { DIRBLOCK* psDirBlock; DIRHEADER* psDirHeader; char szBuf[ 64 ]; char szBuf2[ 64 ]; + char szBuf3[ 64 ]; long lDump, lSizeFile, lDateTime; DIRENTRY* pDE; USHORT usTemp, usBlock, usInUseBlock, usDestBlock; UCHAR* paucBlock; int iA, iB, iCount; + extern int optind; + extern char *optarg; + int c; + int interactive = 0; + + IOOPEN; /* process command line */ uiPort = PORT_BASE_DEFAULT; uiBlockAvailable = 1024; - for( iA=1; iAm_sDirHeader; /* process */ - while( 1 ) + szBuf[0] = '\0'; + if (argc == 1) + interactive = 1; + + while ((c = getopt(argc, argv, "ip:m:lu:r:I")) != EOF) { + switch (c) { + case 'i': + interactive = 1; + break; + case 'p': + sscanf(optarg, "%x", &uiPort); + break; + case 'm': + sscanf(optarg, "%u", &uiBlockAvailable); + uiBlockAvailable *= 32; + break; + case 'l': + strcpy(szBuf, "l"); + break; + case 'u': + strcpy(szBuf, "u"); + strcpy(szBuf2, optarg); + break; + case 'r': + strcpy(szBuf, "r"); + strcpy(szBuf2, optarg); + break; + case 'I': + strcpy(szBuf, "i"); + break; + default: + usage(); + goto fail; + } + } + argc -= optind; + argv += optind; + +#if defined(__linux__) + if ( ioperm(uiPort, 3, 1) ) { - /* menu */ - printf( "\n(l)ist (u)pload (d)ownload (r)emove (i)nitialize (q)uit\n" ); + printf( "access to IO ports denied\n" ); + return FALSE; + } +#endif - /* get request */ - printf( "\ncommand :" ); - GetUserInput( szBuf, sizeof(szBuf) ); - printf( "\n" ); + do { + if (interactive) { + /* menu */ + printf( "\n(l)ist (u)pload (d)ownload (r)emove (i)nitialize (q)uit\n" ); + + /* get request */ + printf( "\ncommand :" ); + GetUserInput( szBuf, sizeof(szBuf) ); + printf( "\n" ); + } /* list directory */ if ( !strcmp(szBuf, "l") ) @@ -1021,18 +1054,29 @@ } /* get info on file to upload */ - printf( "enter source filename :" ); - GetUserInput( szBuf, sizeof(szBuf) ); - if ( !GetFileInfo(szBuf, &lSizeFile, &lDateTime) ) - { - printf( "unable to open '%s' for read\n", szBuf ); - continue; + if (interactive) { + printf( "enter source filename :" ); + GetUserInput( szBuf, sizeof(szBuf) ); + + if ( !GetFileInfo(szBuf, &lSizeFile, &lDateTime) ) + { + printf( "unable to open '%s' for read\n", szBuf ); + continue; + } + printf( "enter MPMan filename [%s] :", GetFileName(szBuf) ); + GetUserInput( szBuf2, sizeof(szBuf2) ); + if ( szBuf2[0] == 0 ) + strcpy( szBuf2, GetFileName(szBuf) ); + ToUpperCase( szBuf2 ); + } else { + strcpy(szBuf, szBuf2); + ToUpperCase(szBuf2); + if ( !GetFileInfo(szBuf, &lSizeFile, &lDateTime) ) + { + fprintf(stderr, "unable to open '%s' for read\n", szBuf ); + goto fail; + } } - printf( "enter MPMan filename [%s] :", GetFileName(szBuf) ); - GetUserInput( szBuf2, sizeof(szBuf2) ); - if ( szBuf2[0] == 0 ) - strcpy( szBuf2, GetFileName(szBuf) ); - ToUpperCase( szBuf2 ); /* determine if enough room to store file */ usInUseBlock = (lSizeFile/SIZE_BLOCK) + (lSizeFile%SIZE_BLOCK ? 1 : 0); @@ -1135,8 +1179,11 @@ } /* get file to remove */ - printf( "enter MPMan filename to remove :" ); - GetUserInput( szBuf, sizeof(szBuf) ); + if (interactive) { + printf( "enter MPMan filename to remove :" ); + GetUserInput( szBuf, sizeof(szBuf) ); + } else + strcpy(szBuf, szBuf2); ToUpperCase( szBuf ); /* search directory for filename */ @@ -1192,11 +1239,13 @@ else if ( !strcmp(szBuf, "i") ) { /* confirm */ - printf( "are you sure (y/n) ?" ); - GetUserInput( szBuf, sizeof(szBuf) ); - printf( "\n" ); - if ( szBuf[0] != 'y' ) - continue; + if (interactive) { + printf( "are you sure (y/n) ?" ); + GetUserInput( szBuf, sizeof(szBuf) ); + printf( "\n" ); + if ( szBuf[0] != 'y' ) + continue; + } /* init dir block */ InitDirBlock( psDirBlock ); @@ -1230,12 +1279,35 @@ /* quit */ else break; - } + } while (interactive); +fail: /* free memory */ free( psDirBlock ); free( paucBlock ); + IOCLOSE; return TRUE; } + +#ifdef __FreeBSD__ +static int console = -1; + +void +get_ioperm(mode) + int mode; +{ + if (console < 0) { + console = open("/dev/console", O_RDWR); + if (console < 0) { + perror("open"); + exit(1); + } + } + if (ioctl(console, mode ? KDENABIO : KDDISABIO, 0) < 0) { + perror("ioctl"); + exit(1); + } +} +#endif /*__FreeBSD__*/