Canola  0.8.D001
test_calculator/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/program_name.h>
00022 
00023 #include <lib/lexer.h>
00024 #include <lib/print_version.h>
00025 #include <lib/search_path.h>
00026 
00027 #include <test_calculator/calculator/test.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, "I:P:V");
00046         if (c == EOF)
00047             break;
00048         switch (c)
00049         {
00050         case 'I':
00051         case 'P':
00052             // resource path
00053             lexer::search_path_append(optarg);
00054             break;
00055 
00056         case 'V':
00057             print_version();
00058             return 0;
00059 
00060         default:
00061             usage();
00062         }
00063     }
00064 
00065     calculator::pointer calc = calculator_test::create();
00066 
00067     switch (argc - optind)
00068     {
00069     case 0:
00070         break;
00071 
00072     case 1:
00073         {
00074             lexer prog(argv[optind], *calc);
00075             prog.test_mode_set();
00076             prog.read_and_execute();
00077         }
00078         break;
00079 
00080     default:
00081         usage();
00082     }
00083 
00084     calc->run();
00085     return EXIT_SUCCESS;
00086 }