void CustomerSettings1_TelnetProcessCharacter(uchar u) { ASSERT(u < UART_COUNT); if (mbCustomerSettings[u] == 1) { if (mbFlags[u] == true) { mbFlags[u] = false; OutMode(u); SerialSend(u, 0x99); mcwUARTTxOut[u]++; } } }
static void performSearch( char *fn ) { int io; int retries; // number of times we read the pipe and got nothing int red; int sav; size_t size; unsigned frag; char *locn; unsigned saveRecs; char **currs; char **nexts; char *probe; struct stat buf; MatchCount = 0; if( strcmp( fn, "@@" ) == 0 ) { fn = "stdin"; io = STDIN_FILENO; setmode( io, O_BINARY ); } else { if( FileMode != 0 ) { if( stat( fn, &buf ) != -1 ) { if( (buf.st_mode & FileMode) != 0 ) { return; } } } io = open( fn, O_RDONLY | O_BINARY ); if( io == -1 ) { Warning( "Unable to open", fn ); return; } } FName = fn; retries = 0; // number of times we read the pipe and got nothing if( PrtAll ) { printFileName(); } PrtFn = TRUE; red = readFile( io, Buff, BSize ); if( red == -1 ) { // Warning( "Error reading file", fn ); // removed for 0 length files if( io != STDIN_FILENO ) { close( io ); } return; } // look for two '\n's with no preceeding '\r' probe = (char *)memchr( Buff, '\n', red ); // look for a newline if( ( probe == Buff || ( probe != NULL && probe[-1] != '\r' ) ) && red > 1 ) { probe = (char *)memchr( probe+1, '\n', red - ( probe+1 - Buff ) ); if( probe != NULL && probe[-1] != '\n' ) { OutMode( O_TEXT ); // we'll assume file has no \r's in it } else { OutMode( O_BINARY ); // assume file has \r\n pairs } } else { OutMode( O_BINARY ); } Recs = 1; locn = Buff; size = BSize; for(;;) { retries = 0; // we actually got something sav = red; // preserve old value Buff[ sav + 0 ] = '\0'; Buff[ sav + 1 ] = '\n'; // put this here as a sentinel // (required by searchBuffer) while( red != 0 && Buff[red-1] != '\n' ) { // break on record boundary --red; } if( red == 0 ) red = sav; // if we did not find NL restore red currs = SrchStrings; saveRecs = Recs; // reset line number for each search string while( *currs ) { Recs = saveRecs; strcpy( Buff + sav + 2, *currs ); searchBuffer( *currs, red ); // - search the buffer if( ExitStatus && QuitFirst ) { nexts = currs; for( ;; ) { nexts[ 0 ] = nexts[ 1 ]; if( nexts[ 0 ] == NULL ) break; ++nexts; } if( *SrchStrings ) { ExitStatus = 0; } } else { ++currs; } } if( ExitStatus ) break; frag = (unsigned)(sav - red); if( frag != 0) { memcpy( Buff, &Buff[red], frag ); } locn = &Buff[frag]; size = BSize - frag; red = readFile( io, locn, size ); // read a big hunk of the file if( red == -1 ) { // if nothing read if( frag == 0 ) break; // - and no fragment quit red = 0; // - did not read anything } // endif red += frag; // include size of piece moved } if( io != STDIN_FILENO ) { close( io ); } if( PrtCount && (MatchCount != 0) ) { printf( "Lines: %d\r\n", MatchCount ); } }
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 ); }