Example #1
0
int main( int argc,char *argv[] )
{
   char *filename;

   if ( argc < 2 )
   {
      fprintf(
              stderr,
              "USAGE:\n"
              "   %s [options] <input file> [<input file> [...]]\n"
              "\n"
              "OPTIONS:\n"
              "   -o filename   Specifies output file.\n"
              "\n"
              "NOTES:\n"
              "   If -o is left unspecified, output defaults to stdout.\n",
              argv[0]
             );
      return 3;
   }

   EstablishOutputFile( argc, argv );
   DetermineCutHLocation( argc, argv );

   /* Skip the executable's name and the output filename. */
   StartArguments(0,argc,argv);

   /* Consume the rest of the arguments, one at a time. */
   while ( NextArgument() )
   {
      filename = GetArgument();

      if( strcmp( filename, DO_NOT_PROCESS ) )
      {
         fprintf( stderr, "  - parsing '%s'... ", filename);
         ProcessSourceFile( filename );
         fprintf( stderr, "done.\n");
      }
   }
   
   EmitCutCheck();
   fflush(outfile);
   fclose(outfile);
   return 0;
}
Example #2
0
/*
// LoadInclude
//
// Processes a #include command
//
// Returns 1 on success, 0 on error
*/
static int LoadInclude( SOURCEFILE *ps, char *Src )
{
    char c,term;
    char NewFileName[SOURCE_BASE_DIR];
    int  rc,idx,oldidx,srcIdx;
    SOURCEFILE *psNew;

    srcIdx=0;

    /* Remove leading white space */
    do
    {
        c = Src[srcIdx++];
    } while( c==' ' || c==0x9 );

    /* Charater must be '"' or '<' */
    if( c=='"' )
    {
        term = '"';
        strcpy( NewFileName, ps->SourceBaseDir );
        idx = strlen(NewFileName);
    }
    else if( c=='<' )
    {
        term = '>';
        idx=0;
    }
    else
        { Report(ps,REP_ERROR,"Expected \" or < after #include"); return(0); }

    /* Read in the filename to the terminating character */
    // Check for include paths that start with "/" or "\"
    // (assume an absolute path)
    if( Src[srcIdx]=='/' || Src[srcIdx]=='\\' )
        idx = 0;
    oldidx = idx;
    for(;;)
    {
        c = Src[srcIdx++];
        // Check for include paths that include a ":"
        // (assume a driver letter preceeded)
        if( c==':' && idx>0 )
        {
            NewFileName[0]=NewFileName[idx-1];
            idx = 1;
            oldidx = idx;
        }
        if( c==term )
            break;
        if( !c )
            { Report(ps,REP_ERROR,"Bad filename in #include"); return(0); }
        if( idx >= (SOURCE_BASE_DIR-1) )
            { Report(ps,REP_ERROR,"Filename too long in #include"); return(0); }
        NewFileName[idx++]=c;
    }

    /* The line should be done now */
    if( Src[srcIdx] )
        { Report(ps,REP_ERROR,"Expected EOL after '%s'",NewFileName); return(0); }

    /* Null terminate the filename and make sure something got copied */
    NewFileName[idx]=0;
    if( idx == oldidx )
        { Report(ps,REP_ERROR,"Null filename in #include"); return(0); }

    /* Open the new file */
    if( !(psNew=InitSourceFile(ps, NewFileName)) )
        return(0);

    /* Process the new file */
    rc = ProcessSourceFile( psNew );

    /* Free the file block */
    CloseSourceFile( psNew );

    if( !rc && Pass==2 )
        return(0);
    else
        return(1);
}