Main Page | Data Structures | File List | Data Fields | Globals

toke.c

Go to the documentation of this file.
00001 /*
00002  *                     OpenBIOS - free your system! 
00003  *                         ( FCode tokenizer )
00004  *                          
00005  *  toke.c - main tokenizer loop and parameter parsing.
00006  *  
00007  *  This program is part of a free implementation of the IEEE 1275-1994 
00008  *  Standard for Boot (Initialization Configuration) Firmware.
00009  *
00010  *  Copyright (C) 2001-2005 by Stefan Reinauer <stepan@openbios.org>
00011  *
00012  *  This program is free software; you can redistribute it and/or modify
00013  *  it under the terms of the GNU General Public License as published by
00014  *  the Free Software Foundation; version 2 of the License.
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU General Public License for more details.
00020  *
00021  *  You should have received a copy of the GNU General Public License
00022  *  along with this program; if not, write to the Free Software
00023  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
00024  *
00025  */
00026 
00027 #include <stdio.h>
00028 #include <stdlib.h>
00029 #include <string.h>
00030 #include <unistd.h>
00031 
00032 #ifdef __GLIBC__
00033 #define _GNU_SOURCE
00034 #include <getopt.h>
00035 #endif
00036 
00037 #include "toke.h"
00038 #include "stream.h"
00039 #include "stack.h"
00040 #include "emit.h"
00041 
00042 #define TOKE_VERSION "0.6.10"
00043 
00044 int verbose=0;
00045 int noerrors=0;
00046 
00047 static void print_copyright(void)
00048 {
00049         printf( "Welcome to toke - OpenBIOS tokenizer v%s\nCopyright (c)"
00050                 " 2001-2005 by Stefan Reinauer <stepan@openbios.org>\n"
00051                 "This program is free software; you may redistribute it "
00052                 "under the terms of\nthe GNU General Public License. This "
00053                 "program has absolutely no warranty.\n\n", TOKE_VERSION);
00054 }
00055 
00056 static void usage(char *name)
00057 {
00058         printf("usage: %s [-v] [-i] [-o target] <forth-file>\n\n",name);
00059         printf("  -v|--verbose          print debug messages\n");
00060         printf("  -i|--ignore-errors    don't bail out after an error\n");
00061         printf("  -h|--help             print this help message\n\n");
00062 
00063 }
00064 
00065 int main(int argc, char **argv)
00066 {
00067         const char *optstring="vhio:?";
00068         char *outputname = NULL;
00069         int c;
00070 
00071         while (1) {
00072 #ifdef __GLIBC__
00073                 int option_index = 0;
00074                 static struct option long_options[] = {
00075                         { "verbose", 0, 0, 'v' },
00076                         { "ignore-errors", 0, 0, 'i' },
00077                         { "help", 0, 0, 'h' },
00078                         { 0, 0, 0, 0 }
00079                 };
00080 
00081                 c = getopt_long (argc, argv, optstring,
00082                                  long_options, &option_index);
00083 #else
00084                 c = getopt (argc, argv, optstring);
00085 #endif
00086                 if (c == -1)
00087                         break;
00088 
00089                 switch (c) {
00090                 case 'v':
00091                         verbose=1;
00092                         break;
00093                 case 'o':
00094                         outputname = optarg;
00095                         break;
00096                 case 'i':
00097                         noerrors=1;
00098                         break;
00099                 case 'h':
00100                 case '?':
00101                         print_copyright();
00102                         usage(argv[0]);
00103                         return 0;               
00104                 default:
00105                         print_copyright();
00106                         printf ("%s: unknown options.\n",argv[0]);
00107                         usage(argv[0]);
00108                         return 1;
00109                 }
00110         }
00111 
00112         if (verbose)
00113                 print_copyright();
00114 
00115         if (optind >= argc) {
00116                 print_copyright();
00117                 printf ("%s: filename missing.\n",argv[0]);
00118                 usage(argv[0]);
00119                 return 1;
00120         }
00121 
00122         init_stack();
00123         init_dictionary();
00124         init_macros();
00125         init_scanner();
00126         
00127         while (optind < argc) {
00128                 if (init_stream(argv[optind])) {
00129                         printf ("%s: warning: could not open file \"%s\"\n",
00130                                         argv[0], argv[optind]);
00131                         optind++;
00132                         continue;
00133                 }
00134                 init_output(argv[optind], outputname);
00135 
00136                 tokenize();
00137                 finish_headers();
00138                 
00139                 close_output();
00140                 close_stream();
00141                 
00142                 optind++;
00143         }
00144         
00145         exit_scanner();
00146         return 0;
00147 }
00148 

Generated on Fri Aug 18 14:11:42 2006 for Toke0.6.10 by  doxygen 1.4.4