The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

mkjambase.c File Reference

#include <stdio.h>
#include <string.h>

Include dependency graph for mkjambase.c:

Include dependency graph

Go to the source code of this file.

Functions

int main (int argc, char **argv, char **envp)


Function Documentation

int main int  argc,
char **  argv,
char **  envp
 

Definition at line 34 of file mkjambase.c.

References fclose(), fprintf(), and p.

00035 {
00036         char buf[ 1024 ];
00037         FILE *fin;
00038         FILE *fout;
00039         char *p;
00040         int doDotC = 0;
00041 
00042         if( argc < 3 )
00043         {
00044             fprintf( stderr, "usage: %s jambase.c Jambase ...\n", argv[0] );
00045             return -1;
00046         }
00047 
00048         if( !( fout = fopen( argv[1], "w" ) ) )
00049         {
00050             perror( argv[1] );
00051             return -1;
00052         }
00053 
00054         /* If the file ends in .c generate a C source file */
00055 
00056         if( ( p = strrchr( argv[1], '.' ) ) && !strcmp( p, ".c" ) )
00057             doDotC++;
00058 
00059         /* Now process the files */
00060 
00061         argc -= 2, argv += 2;
00062 
00063         if( doDotC )
00064         {
00065             fprintf( fout, "/* Generated by mkjambase from Jambase */\n" );
00066             fprintf( fout, "char *jambase[] = {\n" );
00067         }
00068 
00069         for( ; argc--; argv++ )
00070         {
00071             if( !( fin = fopen( *argv, "r" ) ) )
00072             {
00073                 perror( *argv );
00074                 return -1;
00075             }
00076 
00077             if( doDotC )
00078             {
00079                 fprintf( fout, "/* %s */\n", *argv );
00080             }
00081             else
00082             {
00083                 fprintf( fout, "### %s ###\n", *argv );
00084             }
00085 
00086             while( fgets( buf, sizeof( buf ), fin ) )
00087             {
00088                 if( doDotC )
00089                 {
00090                     char *p = buf;
00091 
00092                     /* Strip leading whitespace. */
00093 
00094                     while( *p == ' ' || *p == '\t' || *p == '\n' )
00095                         p++;
00096 
00097                     /* Drop comments and empty lines. */
00098 
00099                     if( *p == '#' || !*p )
00100                         continue;
00101 
00102                     /* Copy */
00103 
00104                     putc( '"', fout );
00105 
00106                     for( ; *p && *p != '\n'; p++ )
00107                         switch( *p )
00108                     {
00109                     case '\\': putc( '\\', fout ); putc( '\\', fout ); break;
00110                     case '"': putc( '\\', fout ); putc( '"', fout ); break;
00111                     case '\r': break;
00112                     default: putc( *p, fout ); break;
00113                     }
00114 
00115                     fprintf( fout, "\\n\",\n" );
00116                 }
00117                 else
00118                 {
00119                     fprintf( fout, "%s", buf );
00120                 }
00121 
00122             }
00123 
00124             fclose( fin );
00125         }
00126             
00127         if( doDotC )
00128             fprintf( fout, "0 };\n" );
00129 
00130         fclose( fout );
00131 
00132         return 0;
00133 }

Here is the call graph for this function:


Generated on Mon Nov 8 17:08:12 2004 for MPT by  doxygen 1.3.9.1