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

Go to the documentation of this file.
00001 /*
00002  * Copyright 1993, 1995 Christopher Seiwald.
00003  *
00004  * This file is part of Jam - see jam.c for Copyright information.
00005  */
00006 
00007 /*  This file is ALSO:
00008  *  (C) Copyright David Abrahams 2001. Permission to copy, use,
00009  *  modify, sell and distribute this software is granted provided this
00010  *  copyright notice appears in all copies. This software is provided
00011  *  "as is" without express or implied warranty, and with no claim as
00012  *  to its suitability for any purpose.
00013  */
00014 
00015 /*
00016  * mkjambase.c - turn Jambase into a big C structure
00017  *
00018  * Usage: mkjambase jambase.c Jambase ...
00019  *
00020  * Results look like this:
00021  *
00022  *       char *jambase[] = {
00023  *       "...\n",
00024  *       ...
00025  *       0 };
00026  *
00027  * Handles \'s and "'s specially; knows to delete blank and comment lines.
00028  *
00029  */
00030 
00031 # include <stdio.h>
00032 # include <string.h>
00033 
00034 int main( int argc, char **argv, char **envp )
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 }

Generated on Mon Nov 8 17:07:41 2004 for MPT by  doxygen 1.3.9.1