/*\ * LBPP - A GNU Compiler Compiler (GCC) Liberty Basic Frontend * Copyright (C) 2001 Anthony Liguori * * LBPP is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * LBPP is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA \*/ #include #include #include #include "lbpp.h" void print_usage(char *prog) { printf("Usage: %s [OPTIONS] [ ...]\n" " Options\n" " -o The c source file to write to\n" " -b Disable including autoinc.bas\n" " -h Display this help screen\n" " -I Path to search for autoinc.bas\n", prog); } int main(int argc, char **argv) { FILE *o = 0; char line[512]; char c_file[512] = "out.c"; char path[512] = "../liblb"; int i = 0; int auto_inc = 1; extern char *optarg; extern int optind; char opt; while ((opt = getopt(argc, argv, "o:hbI:")) != EOF) { switch (opt) { case 'o': strcpy(c_file, optarg); break; case 'h': print_usage(argv[0]); exit(0); break; case 'b': auto_inc = 0; break; case 'I': strcpy(path, optarg); break; default: break; } } if ((argc - optind) < 1) { print_usage(argv[0]); exit(-1); } strcat(path, "/autoinc.bas"); o = fopen(c_file, "w"); if (!o) { printf("%s: Could not open %s\n", argv[0], c_file); perror(argv[0]); exit(-1); } fprintf(o, "#include \n\n" "void lb_init(LBContext *cxt)\n" "{\n" "setting_labels = 1;\n" "goto label_0;\n" "start:\n\n\n"); if (auto_inc) { FILE *f = fopen(path, "r"); if (!f) { printf("%s: Could not open %s\n", argv[0], argv[i]); perror(argv[0]); exit(-1); } while (get_line(line, sizeof(line), f)) { translate_line(o, line); } fclose(f); } for (i = optind; i < argc; i++) { FILE *f = fopen(argv[i], "r"); if (!f) { printf("%s: Could not open %s\n", argv[0], argv[i]); perror(argv[0]); exit(-1); } while (get_line(line, sizeof(line), f)) { translate_line(o, line); } fclose(f); } fprintf(o, "return;\n"); fprintf(o, "label_%d:\n", label_table_size); fprintf(o, "setting_labels = 0;\n"); fprintf(o, "goto start;\n"); fprintf(o, "}\n\n\n"); fprintf(o, "void init_labels(LBContext *cxt)\n" "{\n"); output_label_table(o); fprintf(o, "}\n\n\n"); fprintf(o, "void init_var_table(LBContext *cxt)\n" "{\n"); output_var_table(o); fprintf(o, "}\n\n\n"); fprintf(o, "#if 0\n"); output_statement_table(o); fprintf(o, "/****************************************************/\n"); output_function_table(o); fprintf(o, "#endif\n"); fclose(o); return 0; }