Canola  0.8.D001
canola-asm/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/calculator/asm.h>
00024 #include <lib/print_version.h>
00025 #include <lib/lexer.h>
00026 
00027 
00028 static void
00029 usage(void)
00030 {
00031     const char *prog = explain_program_name_get();
00032     fprintf(stderr, "Usage: %s [ <option>... ]\n", prog);
00033     fprintf(stderr, "       %s -V\n", prog);
00034     exit(1);
00035 }
00036 
00037 
00038 int
00039 main(int argc, char **argv)
00040 {
00041     bool dis = false;
00042     for (;;)
00043     {
00044         int c = getopt(argc, argv, "dI:V");
00045         if (c == EOF)
00046             break;
00047         switch (c)
00048         {
00049         case 'd':
00050             dis = true;
00051             break;
00052 
00053         case 'I':
00054             lexer::search_path_append(optarg);
00055             break;
00056 
00057         case 'V':
00058             print_version();
00059             return 0;
00060 
00061         default:
00062             usage();
00063         }
00064     }
00065     if (optind + 2 != argc)
00066         usage();
00067 
00068     calculator::pointer foo = calculator_asm::create();
00069     foo->program_mode_set(calculator::program_mode_learn);
00070     if (!dis)
00071     {
00072         foo->load_program(argv[optind], false);
00073         foo->save_program_as(argv[optind + 1], true);
00074     }
00075     else
00076     {
00077         foo->load_program(argv[optind], true);
00078         foo->save_program_as(argv[optind + 1], false);
00079     }
00080 
00081     return 0;
00082 }