Canola  0.8.D001
test_number/main.cc
Go to the documentation of this file.
00001 //
00002 // canola - canon canola 1614p emulator
00003 // Copyright (C) 2011 Peter Miller
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, version 3, as
00007 // published by the Free Software Foundation.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License along
00015 // with this program. If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 #include <lib/ac/stdio.h>
00019 #include <lib/ac/stdlib.h>
00020 #include <lib/ac/unistd.h>
00021 #include <libexplain/fflush.h>
00022 #include <libexplain/freopen.h>
00023 #include <libexplain/program_name.h>
00024 
00025 #include <lib/print_version.h>
00026 
00027 #include <test_number/grammar.h>
00028 
00029 
00030 static void
00031 usage(void)
00032 {
00033     const char *prog = explain_program_name_get();
00034     fprintf(stderr, "Usage: %s [ <option>... ]\n", prog);
00035     fprintf(stderr, "       %s -V\n", prog);
00036     exit(1);
00037 }
00038 
00039 
00040 int
00041 main(int argc, char **argv)
00042 {
00043     for (;;)
00044     {
00045         int c = getopt(argc, argv, "Vy");
00046         if (c == EOF)
00047             break;
00048         switch (c)
00049         {
00050         case 'V':
00051             print_version();
00052             return 0;
00053 
00054         case 'y':
00055             grammar_debugging();
00056             break;
00057 
00058         default:
00059             usage();
00060         }
00061     }
00062     switch (argc - optind)
00063     {
00064     case 2:
00065         explain_freopen_or_die(argv[optind + 1], "w", stdout);
00066         // Fall through...
00067 
00068     case 1:
00069         explain_freopen_or_die(argv[optind], "r", stdin);
00070         // Fall through...
00071 
00072     case 0:
00073         break;
00074 
00075     default:
00076         usage();
00077     }
00078 
00079     grammar();
00080     explain_fflush_or_die(stdout);
00081 
00082     return 0;
00083 }