int main( // MAIN-LINE FOR DLL DRIVER #if !defined(RAW_CMDLINE) int argc, // - arg count char **argv // - arg.s #endif ) { int retcode; // - return code #if defined(USE_ARGV) retcode = IdeDrvExecDLLArgv( &info, argc, argv ); #elif defined(wpp_drv) argc = argc; argv = argv; getcmd( cmd_line ); retcode = IdeDrvExecDLL( &info, cmd_line ); #elif defined(RAW_CMDLINE) size_t len; char *lcl_argv[2]; len = _bgetcmd( NULL, INT_MAX ); lcl_argv[1] = NULL; if( len >= sizeof( cmd_line ) ) { lcl_argv[0] = CMemAlloc( len + 1 ); } else { lcl_argv[0] = cmd_line; } _bgetcmd( lcl_argv[0], len + 1 ); retcode = IdeDrvExecDLL( &info, cmd_line ); if( len >= sizeof( cmd_line ) ) { CMemFree( lcl_argv[0] ); } #else argc = argc; cmd_line[0] = cmd_line[0]; retcode = IdeDrvExecDLL( &info, &argv[1] ); #endif switch( retcode ) { case IDEDRV_SUCCESS : case IDEDRV_ERR_RUN : case IDEDRV_ERR_RUN_EXEC : case IDEDRV_ERR_RUN_FATAL : break; default : retcode = IdeDrvPrintError( &info ); break; } return retcode; }
/* * Execute progname. If successful, this function does not return. */ void SpawnProgStub( const char *progname ) /****************************************/ { char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char ext[_MAX_EXT]; char fullPath[_MAX_PATH]; size_t len; char * argv[3]; int rc; /*** Make a copy of the command line ***/ argv[0] = (char*)progname; len = _bgetcmd( NULL, 0 ) + 1; argv[1] = AllocMem( len ); getcmd( argv[1] ); argv[2] = NULL; /*** Try to execute the program ***/ rc = spawnvp( P_WAIT, progname, (const char **)argv ); if( rc != -1 ) { exit( rc ); } /*** Didn't work; try looking in the same directory as this program ***/ _fullpath( fullPath, progname, _MAX_PATH ); _splitpath( fullPath, drive, dir, NULL, NULL ); _splitpath( progname, NULL, NULL, fname, ext ); _makepath( fullPath, drive, dir, fname, ext ); rc = spawnvp( P_WAIT, fullPath, (const char **)argv ); if( rc != -1 ) { exit( rc ); } }
int main( int argc, char **argv ) /*******************************/ { argc = argc; #ifndef __WATCOMC__ _argv = argv; _argc = argc; #endif #else int main( void ) /**************/ { char *argv[2]; int len; char *buff; #endif main_init(); SwitchChar = _dos_switch_char(); #ifndef __UNIX__ len = _bgetcmd( NULL, INT_MAX ) + 1; buff = malloc( len ); if( buff != NULL ) { argv[0] = buff; argv[1] = NULL; _bgetcmd( buff, len ); } else { return( -1 ); } do_init_stuff( argv ); #else do_init_stuff( &argv[1] ); #endif SetMemoryModel(); WriteObjModule(); // main body: parse the source file MsgFini(); main_fini(); #ifndef __UNIX__ free( buff ); #endif return( Options.error_count ); /* zero if no errors */ }
void GUImain( void ) { char *buff; int len; // fix up env vars if necessary watcom_setup_env(); SetErrorMode( ERR_MODE ); #if defined( _M_IX86 ) _8087 = 0; #endif len = _bgetcmd( NULL, 0 ); _AllocA( buff, len + 1 ); getcmd( buff ); CmdData = buff; DebugMain(); }
/* * Open a new command line context. */ int OpenCmdLineContext( void ) /****************************/ { int len; if( curContextInitialized ) Zoinks(); clear_context( &curContext ); /*** Make a copy of the command line ***/ len = _bgetcmd( NULL, 0 ) + 1; curContext.dataStart = AllocMem( len ); getcmd( curContext.dataStart ); curContext.data = curContext.dataStart; curContext.dataLen = strlen( curContext.dataStart ); curContextInitialized = 1; curContext.type = COMMAND_LINE_CONTEXT; return( 0 ); }
int main( int argc, char **argv ) { /************************************/ wbool ignore; #if defined( __WATCOMC__ ) wbool prtcmd; int cmdlen; char *cmdline; #endif char *fs; char ch; char *lf; char *p; char **currs; char *allfiles[2]; argc = argc; ++argv; if( argv[0] == NULL || argv[0][0] == '?' ) { printHelp( ); exit( 2 ); } #if defined( __WATCOMC__ ) cmdlen = _bgetcmd( NULL, 0 ) + 1; cmdline = malloc( cmdlen ); if( cmdline != NULL ) { cmdlen = _bgetcmd( cmdline, cmdlen ); } prtcmd = FALSE; #endif ignore = FALSE; // initialize options PrtAll = FALSE; PrtCount = FALSE; PrtPath = FALSE; QuitFirst = FALSE; OnePerFile = FALSE; PrtMatch = TRUE; PrtLines = FALSE; PrtFiles = TRUE; Similar = FALSE; NoSubstring = FALSE; FOut = NULL; Context = 0; RecurLevels = 0; TotalMatchCount = 0; lf = NULL; while( *argv != NULL && **argv == '-' ) { if( argv[0][1] == 'e' ) { break; } switch( tolower( argv[0][1] ) ) { case 'a': PrtAll = TRUE; break; case 'c': PrtCount = TRUE; PrtMatch = FALSE; break; #if defined( __WATCOMC__ ) case 'd': prtcmd = TRUE; break; #endif case 'f': PrtFiles = FALSE; break; case 'g': GetDefIgnoreList( argv[0] ); break; case 'h': case '?': printHelp( ); exit( 2 ); case 'i': ignore = TRUE; break; case 'l': PrtMatch = FALSE; break; case 'n': PrtLines = TRUE; break; case 'o': lf = *argv + 2; break; case 'p': PrtPath = TRUE; break; case 'q': PrtLines = FALSE; PrtMatch = FALSE; PrtFiles = FALSE; break; case 'r': ch = tolower( argv[0][2] ); if( ch == 'o' ) { FileMode = WRITABLE; // -ro } else if( ch == '\0' ) { RecurLevels = INT_MAX; PrtPath = TRUE; } else { RecurLevels = atoi( *argv + 2 ); PrtPath = TRUE; } break; case 's': ignore = FALSE; Similar = TRUE; break; case 't': NoSubstring = TRUE; break; case 'w': Context = atoi( *argv + 2 ); break; case 'x': OnePerFile = TRUE; break; case '1': QuitFirst = TRUE; break; default: Error( "Option not recognized at", *argv ); } ++argv; } #if defined( __WATCOMC__ ) if( prtcmd ) { printf( "Demarcated command line arguments: [%s]\n", cmdline ); } #endif argv = parseSearchStrings( argv ); if( SrchStrings[ 0 ] == NULL ) { printHelp(); } else { CurOutMode = 0x1234; /* it's a hack... */ OutMode( O_BINARY ); if( lf != NULL ) { if( !*lf ) lf = "tmp.bat(%s)"; p = strchr( lf, '(' ); if( p ) { *p = '\0'; ++p; FOutFmt = p; p = strrchr( p, ')' ); if( p ) { *p = '\0'; convertBlanks( FOutFmt ); } } else { FOutFmt = "%s"; } if( !*lf ) lf = "tmp.bat"; FOut = fopen( lf, "w+" ); if( FOut == NULL ) { Error( "Cannot open output file", lf ); } } if( ignore ) { ch = 'A'; while( ch <= 'Z' ) { // zap all Uppers to Lower in char table CharTrans[ (unsigned char)ch ] |= 0x20; ++ch; } currs = SrchStrings; while( *currs != NULL ) { fs = *currs; while( *fs ) { // zap search string to lower *fs = CharTrans[ (unsigned char)*fs ]; ++fs; } ++currs; } } if( *argv != NULL ) { startWgrep( argv ); } else { if( !isatty( STDIN_FILENO ) ) { allfiles[ 0 ] = "@@"; } else { allfiles[ 0 ] = "*.*"; } allfiles[ 1 ] = NULL; startWgrep( allfiles ); } if( FOut != NULL ) { fclose( FOut ); FOut = NULL; } } if( PrtCount && (TotalMatchCount != 0) && (MatchCount != TotalMatchCount) ) { printf( "Total lines: %d\n", TotalMatchCount ); } if( IgnoreListBuffer != NULL ) { free( IgnoreListBuffer ); } if( IgnoreList != NULL ) { free( IgnoreList ); } return( QuitFirst ? ExitStatus : 0 ); }
_WCRTLINK char *getcmd( char *buffer ) { _bgetcmd( buffer, INT_MAX ); return( buffer ); } /* getcmd() */
int main() { /* Declare automatic variables. */ size_t cmdlen = 0; char * cmdline = NULL; int retval; /* Display the banner. */ print_banner(); /* Display the usage information if the command line is empty. */ cmdlen = _bgetcmd( NULL, 0 ); if( cmdlen == 0 ) { print_usage(); return( EXIT_FAILURE ); } /* Include space for the terminating null character. */ cmdlen++; /* Get the command line. */ cmdline = malloc( cmdlen ); if( cmdline == NULL ) { return( EXIT_FAILURE ); } cmdlen = _bgetcmd( cmdline, cmdlen ); /* Initialize the globals. */ initialize_globals(); res_initialize_globals(); /* Initialize the statics, which should be globals in gendev. */ cur_file = (file_info *) malloc( sizeof( file_info ) ); cur_file->filebuf = (char * ) malloc( BUF_SIZE ); cur_file->buflen = BUF_SIZE; cur_file->scanptr = NULL; cur_file->usedlen = 0; cur_token = (token *) malloc( sizeof( token ) ); /* Parse the command line: allocates and sets tgt_path. */ retval = parse_cmdline( cmdline ); if( retval == FAILURE ) { free( cmdline ); return( EXIT_FAILURE ); } /* Free the memory held by cmdline and reset it. */ free( cmdline ); cmdline = NULL; /* Check all files in current directory. */ retval = check_directory(); /* Free the memory held by tgt_path and the statics. */ free( tgt_path ); tgt_path = NULL; free( cur_file->filebuf ); cur_file->filebuf = NULL; free( cur_file ); cur_file = NULL; free( cur_token ); cur_token = NULL; /* Print the useage if the process failed. */ if( retval == FAILURE ) { print_usage(); return( EXIT_FAILURE ); } return( EXIT_SUCCESS ); }
_WCRTLINK char *(getcmd)( char *buffer ) { _bgetcmd( buffer, INT_MAX ); return( buffer ); }