00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <stdio.h>
00034 #include <stdlib.h>
00035 #include <string.h>
00036 #include <unistd.h>
00037
00038 #ifdef __GLIBC__
00039 #define _GNU_SOURCE
00040 #include <getopt.h>
00041 #endif
00042
00043 #include "types.h"
00044 #include "toke.h"
00045 #include "stream.h"
00046 #include "stack.h"
00047 #include "emit.h"
00048
00049 #define TOKE_VERSION "1.0.0"
00050
00051 #include "vocabfuncts.h"
00052 #include "scanner.h"
00053 #include "errhandler.h"
00054 #include "usersymbols.h"
00055 #include "clflags.h"
00056 #include "tracesyms.h"
00057
00058 #define CORE_COPYR "(C) Copyright 2001-2006 Stefan Reinauer.\n" \
00059 "(C) Copyright 2006 coresystems GmbH <info@coresystems.de>"
00060 #define IBM_COPYR "(C) Copyright 2005 IBM Corporation. All Rights Reserved."
00061
00062
00063 #ifdef DEVEL
00064 #include "date_stamp.h"
00065 #endif
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 bool verbose = FALSE;
00078 bool noerrors = FALSE;
00079 bool fload_list = FALSE;
00080 bool dependency_list = FALSE;
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 static char *outputname = NULL;
00094
00095
00096
00097
00098
00099
00100 static void print_copyright(void)
00101 {
00102 printf( "Welcome to toke - OpenBIOS tokenizer v" TOKE_VERSION "\n"
00103 CORE_COPYR "\n" IBM_COPYR "\n"
00104 "This program is free software; you may redistribute it "
00105 "under the terms of\nthe GNU General Public License. This "
00106 "program has absolutely no warranty.\n\n");
00107 #ifdef DEVEL
00108
00109 printf( "\tTokenizer Compiled " DATE_STAMP "\n" );
00110 #endif
00111
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121 static void usage(char *name)
00122 {
00123 printf("usage: %s [-v] [-i] [-l] [-P] [-o target] <[-d name[=value]]> "
00124 "<[-f [no]flagname]> <[-I dir-path]> "
00125 "<[-T symbol]> <forth-file>\n\n",name);
00126 printf(" -v|--verbose print Advisory messages\n");
00127 printf(" -i|--ignore-errors don't suppress output after errors\n");
00128 printf(" -l|--load-list create list of FLoaded file names\n");
00129 printf(" -P|--dependencies create dePendency-list file\n");
00130 printf(" -o|--output-name send output to filename given\n");
00131 printf(" -d|--define create user-defined symbol\n");
00132 printf(" -f|--flag set (or clear) Special-Feature flag\n");
00133 printf(" -I|--Include add a directory to the Include-List\n");
00134 printf(" -T|--Trace add a symbol to the Trace List\n");
00135 printf(" -h|--help print this help message\n\n");
00136 printf(" -f|--flag help Help for Special-Feature flags\n");
00137 }
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228 static void get_args( int argc, char **argv )
00229 {
00230 const char *optstring="vhilPo:d:f:I:T:?";
00231 int c;
00232 int argindx = 0;
00233 bool inval_opt = FALSE;
00234 bool help_mssg = FALSE;
00235 bool cl_flag_error = FALSE;
00236
00237 while (1) {
00238 #ifdef __GLIBC__
00239 int option_index = 0;
00240 static struct option long_options[] = {
00241 { "verbose", 0, 0, 'v' },
00242 { "help", 0, 0, 'h' },
00243 { "ignore-errors", 0, 0, 'i' },
00244 { "load-list", 0, 0, 'l' },
00245 { "dependencies", 0, 0, 'P' },
00246 { "output-name", 1, 0, 'o' },
00247 { "define", 1, 0, 'd' },
00248 { "flag", 1, 0, 'f' },
00249 { "Include", 1, 0, 'I' },
00250 { "Trace", 1, 0, 'T' },
00251 { 0, 0, 0, 0 }
00252 };
00253
00254 c = getopt_long (argc, argv, optstring,
00255 long_options, &option_index);
00256 #else
00257 c = getopt (argc, argv, optstring);
00258 #endif
00259 if (c == -1)
00260 break;
00261
00262 argindx++;
00263 switch (c) {
00264 case 'v':
00265 verbose=TRUE;
00266 break;
00267 case 'o':
00268 outputname = optarg;
00269 break;
00270 case 'i':
00271 noerrors = TRUE;
00272 break;
00273 case 'l':
00274 fload_list = TRUE;
00275 break;
00276 case 'P':
00277 dependency_list = TRUE;
00278 break;
00279 case 'd':
00280 {
00281 char *user_symb = optarg;
00282 add_user_symbol(user_symb);
00283 }
00284 break;
00285 case 'f':
00286 cl_flag_error = set_cl_flag(optarg, FALSE) ;
00287 break;
00288 case 'I':
00289 {
00290 char *incl_list_elem = optarg;
00291 add_to_include_list(incl_list_elem);
00292 }
00293 break;
00294 case 'T':
00295 add_to_trace_list(optarg);
00296 break;
00297 case '?':
00298
00299
00300
00301 if ( argv[argindx][1] != '?' )
00302 {
00303 inval_opt = TRUE;
00304 break;
00305 }
00306 case 'h':
00307 case 'H':
00308 help_mssg = TRUE;
00309 break;
00310 default:
00311
00312
00313
00314
00315
00316 printf ("%s: unknown options.\n",argv[0]);
00317 usage(argv[0]);
00318 exit( 1 );
00319 }
00320 }
00321
00322 if ( help_mssg )
00323 {
00324 usage(argv[0]);
00325 if ( ! clflag_help )
00326 {
00327 list_cl_flag_names();
00328 }
00329 }
00330 if ( clflag_help ) cl_flags_help();
00331 if ( help_mssg || clflag_help )
00332 {
00333 exit( 0 );
00334 }
00335
00336 if ( inval_opt ) printf ("unknown options.\n");
00337 if (optind >= argc) printf ("Input file name missing.\n");
00338 if ( inval_opt || (optind >= argc) )
00339 {
00340 usage(argv[0]);
00341 }
00342 if ( cl_flag_error ) list_cl_flag_names();
00343
00344 if ( inval_opt || (optind >= argc) || cl_flag_error )
00345 {
00346 exit( 1);
00347 }
00348
00349 if (verbose)
00350 {
00351 list_user_symbols();
00352 list_cl_flag_settings();
00353 display_include_list();
00354 }
00355 save_cl_flags();
00356 }
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374 int main(int argc, char **argv)
00375 {
00376 int retval = 0;
00377
00378 print_copyright();
00379 get_args( argc, argv );
00380
00381 init_stack();
00382 init_dictionary();
00383
00384 init_scanner();
00385
00386 if ( outputname != NULL )
00387 {
00388 if ( argc > optind + 1 )
00389 {
00390
00391
00392 printf( "Cannot specify single output file name "
00393 "with multiple input file names.\n"
00394 "Please either remove output-file-name specification,\n"
00395 "or use multiple commands.\n");
00396 exit ( -2 );
00397 }
00398 }
00399
00400 for ( ; optind < argc ; optind++ )
00401 {
00402 bool stream_ok ;
00403
00404 printf("\nTokenizing %s ", argv[optind]);
00405 init_error_handler();
00406 stream_ok = init_stream( argv[optind]);
00407 if ( stream_ok )
00408 {
00409 init_output(argv[optind], outputname);
00410
00411 init_scan_state();
00412
00413 reset_vocabs();
00414 reset_cl_flags();
00415
00416 tokenize();
00417 finish_headers();
00418
00419 close_stream( NULL);
00420 if ( close_output() ) retval = 1;
00421 }
00422 }
00423
00424 exit_scanner();
00425 return retval;
00426 }
00427