void print_funcall(struct funcall *f, int indent) { print_indent(indent); int fun_id = get_funcall_name(f); switch (fun_id) { case 1: /* 1 is ecrire */ print_write_fun(f); break; case 2: /* 2 is allouer */ print_alloc_fun(f); break; case 3: print_read_function(f); break; case 4: print_free_fun(f); break; default: printf("%s(", f->fun_ident); print_arglist(f->args); printf(");\n"); } }
void print_read_function(struct funcall *f) { printf("scanf(\""); print_type_format(f->args.data[0]->e->type); printf("\\n\", "); print_arglist(f->args); printf(");\n"); }
void print_expression(struct expr *e) { switch (e->exprtype) { case valtype: print_val(e->val.val); break; case binopexprtype: printf("("); print_expression(e->val.binopexpr.e1); printf(" %s ", getopstr(e->val.binopexpr.op)); print_expression(e->val.binopexpr.e2); printf(")"); break; case unopexprtype: printf("("); printf("%s ", getopstr(e->val.unopexpr.op)); print_expression(e->val.unopexpr.e); printf(")"); break; case arrayexprtype: print_expression(e->val.arrayexpr.e1); for (unsigned i = 0; i < e->val.arrayexpr.indices.size; ++i) { printf("["); print_expression(list_nth(e->val.arrayexpr.indices, i)); printf(" - 1]"); } break; case identtype: if (e->argref) printf("*(%s)", e->val.ident); else printf("%s", e->val.ident); break; case dereftype: printf("*"); print_expression(e->val.deref.e); break; case funcalltype: printf("%s(", e->val.funcall.fun_ident); print_arglist(e->val.funcall.args); printf(")"); break; case structelttype: printf("("); print_expression(e->val.structelt.record); printf(").%s", e->val.structelt.field); break; default: printf("expr not handled yet in print_expression\n"); } }
void print_write_fun(struct funcall *f) { assert(strcmp(f->fun_ident, "ecrire") == 0); printf("printf(\""); for (unsigned i = 0; i < f->args.size - 1; ++i) { print_type_format(f->args.data[i]->e->type); printf(" "); } print_type_format(f->args.data[f->args.size - 1]->e->type); printf("\\n\", "); print_arglist(f->args); printf(");\n"); }
static void read_options(struct options * o, int argc, char * argv[]) { char * s; int i = 2; /* set defaults: */ o->output_file = 0; o->syntax_tree = false; o->externals_prefix = NULL; o->variables_prefix = 0; o->runtime_path = 0; o->parent_class_name = DEFAULT_BASE_CLASS; #ifndef DISABLE_JAVA o->string_class = DEFAULT_STRING_CLASS; o->among_class = DEFAULT_AMONG_CLASS; o->package = DEFAULT_PACKAGE; #endif o->name = ""; o->make_lang = LANG_C; o->widechars = false; o->includes = 0; o->includes_end = 0; o->utf8 = false; /* read options: */ while (i < argc) { s = argv[i++]; { if (eq(s, "-o") || eq(s, "-output")) { check_lim(i, argc); o->output_file = argv[i++]; continue; } if (eq(s, "-n") || eq(s, "-name")) { check_lim(i, argc); o->name = argv[i++]; continue; } #ifndef DISABLE_JSX if (eq(s, "-jsx")) { o->make_lang = LANG_JSX; o->widechars = true; continue; } #endif #ifndef DISABLE_JAVA if (eq(s, "-j") || eq(s, "-java")) { o->make_lang = LANG_JAVA; o->widechars = true; continue; } #endif if (eq(s, "-c++")) { o->make_lang = LANG_CPLUSPLUS; continue; } #ifndef DISABLE_PYTHON if (eq(s, "-py") || eq(s, "-python")) { o->make_lang = LANG_PYTHON; o->widechars = true; continue; } #endif if (eq(s, "-w") || eq(s, "-widechars")) { o->widechars = true; o->utf8 = false; continue; } if (eq(s, "-s") || eq(s, "-syntax")) { o->syntax_tree = true; continue; } if (eq(s, "-ep") || eq(s, "-eprefix")) { check_lim(i, argc); o->externals_prefix = argv[i++]; continue; } if (eq(s, "-vp") || eq(s, "-vprefix")) { check_lim(i, argc); o->variables_prefix = argv[i++]; continue; } if (eq(s, "-i") || eq(s, "-include")) { check_lim(i, argc); { NEW(include, p); symbol * b = add_s_to_b(0, argv[i++]); b = add_s_to_b(b, "/"); p->next = 0; p->b = b; if (o->includes == 0) o->includes = p; else o->includes_end->next = p; o->includes_end = p; } continue; } if (eq(s, "-r") || eq(s, "-runtime")) { check_lim(i, argc); o->runtime_path = argv[i++]; continue; } if (eq(s, "-u") || eq(s, "-utf8")) { o->utf8 = true; o->widechars = false; continue; } if (eq(s, "-p") || eq(s, "-parentclassname")) { check_lim(i, argc); o->parent_class_name = argv[i++]; continue; } #ifndef DISABLE_JAVA if (eq(s, "-P") || eq(s, "-Package")) { check_lim(i, argc); o->package = argv[i++]; continue; } if (eq(s, "-S") || eq(s, "-stringclass")) { check_lim(i, argc); o->string_class = argv[i++]; continue; } if (eq(s, "-a") || eq(s, "-amongclass")) { check_lim(i, argc); o->among_class = argv[i++]; continue; } #endif fprintf(stderr, "'%s' misplaced\n", s); print_arglist(); } } if (o->make_lang != LANG_C && o->make_lang != LANG_CPLUSPLUS) { if (o->runtime_path) { fprintf(stderr, "warning: -r/-runtime only meaningful for C and C++\n"); } if (o->externals_prefix) { fprintf(stderr, "warning: -ep/-eprefix only meaningful for C and C++\n"); } } if (!o->externals_prefix) o->externals_prefix = ""; }
static void check_lim(int i, int argc) { if (i >= argc) { fprintf(stderr, "argument list is one short\n"); print_arglist(); } }
extern int main(int argc, char * argv[]) { NEW(options, o); if (argc == 1) print_arglist(); read_options(o, argc, argv); { symbol * filename = add_s_to_b(0, argv[1]); char * file; symbol * u = get_input(filename, &file); if (u == 0) { fprintf(stderr, "Can't open input %s\n", argv[1]); exit(1); } { struct tokeniser * t = create_tokeniser(u, file); struct analyser * a = create_analyser(t); t->widechars = o->widechars; t->includes = o->includes; a->utf8 = t->utf8 = o->utf8; read_program(a); if (t->error_count > 0) exit(1); if (o->syntax_tree) print_program(a); close_tokeniser(t); if (!o->syntax_tree) { struct generator * g; const char * s = o->output_file; if (!s) { fprintf(stderr, "Please include the -o option\n"); print_arglist(); exit(1); } g = create_generator(a, o); if (o->make_lang == LANG_C || o->make_lang == LANG_CPLUSPLUS) { symbol * b = add_s_to_b(0, s); b = add_s_to_b(b, ".h"); o->output_h = get_output(b); b[SIZE(b) - 1] = 'c'; if (o->make_lang == LANG_CPLUSPLUS) { b = add_s_to_b(b, "c"); } o->output_src = get_output(b); lose_b(b); generate_program_c(g); fclose(o->output_src); fclose(o->output_h); } #ifndef DISABLE_JAVA if (o->make_lang == LANG_JAVA) { symbol * b = add_s_to_b(0, s); b = add_s_to_b(b, ".java"); o->output_src = get_output(b); lose_b(b); generate_program_java(g); fclose(o->output_src); } #endif #ifndef DISABLE_PYTHON if (o->make_lang == LANG_PYTHON) { symbol * b = add_s_to_b(0, s); b = add_s_to_b(b, ".py"); o->output_src = get_output(b); lose_b(b); generate_program_python(g); fclose(o->output_src); } #endif #ifndef DISABLE_JSX if (o->make_lang == LANG_JSX) { symbol * b = add_s_to_b(0, s); b = add_s_to_b(b, ".jsx"); o->output_src = get_output(b); lose_b(b); generate_program_jsx(g); fclose(o->output_src); } #endif close_generator(g); } close_analyser(a); } lose_b(u); lose_b(filename); } { struct include * p = o->includes; while (p) { struct include * q = p->next; lose_b(p->b); FREE(p); p = q; } } FREE(o); if (space_count) fprintf(stderr, "%d blocks unfreed\n", space_count); return 0; }
int main (int argc, char **argv) { /* * Process command-line arguments. */ /* Get rid of the program name. */ argc--; argv++; /* CHECKME: get rid of the '+' syntax? */ while ((argc > 0) && ((argv[0][0] == '-') || (argv[0][0] == '+'))) { switch (argv[0][1]) { case 'a': /* Need the "+" syntax here... */ ahead = ((argv[0][0] == '-') ? false : true); break; case 'b': argc--; argv++; if (argc > 0) { bookfile = argv[0]; #ifdef BINBOOK binbookfile = NULL; #endif } break; #ifdef BINBOOK case 'B': argc--; argv++; if (argc > 0) binbookfile = argv[0]; break; #endif case 'C': /* Curses interface. */ display_type = DISPLAY_CURSES; break; case 'h': /* Need the "+" syntax here... */ hash = ((argv[0][0] == '-') ? false : true); break; case 'l': argc--; argv++; if (argc > 0) Lang = argv[0]; break; case 'L': argc--; argv++; if (argc > 0) strcpy(listfile, argv[0]); break; case 's': argc--; argv++; if (argc > 0) strcpy(savefile, argv[0]); break; case 'P': argc--; argv++; if (argc > 0) bookmaxply = atoi(argv[0]); break; case 'R': /* Raw text interface. */ display_type = DISPLAY_RAW; break; case 'S': argc--; argv++; if (argc > 0) booksize = atoi(argv[0]); break; #if ttblsz case 'r': argc--; argv++; if (argc > 0) rehash = atoi(argv[0]); if (rehash > MAXrehash) rehash = MAXrehash; break; case 'T': argc--; argv++; if (argc > 0) ttblsize = atoi(argv[0]); if ((ttblsize <= MINTTABLE)) ttblsize = (MINTTABLE) + 1; break; #ifdef HASHFILE case 'c': /* Create or test persistent transposition table. */ argc--; argv++; if (argc > 0) filesz = atoi(argv[0]); else filesz = vfilesz; if ((filesz > 0) && (filesz < 24)) filesz = (1 << filesz) - 1 + MAXrehash; else filesz = filesz + MAXrehash; if ((hashfile = fopen(HASHFILE, RWA_ACC)) == NULL) hashfile = fopen(HASHFILE, WA_ACC); if (hashfile != NULL) { long j; struct fileentry n; printf(CP[66]); n.f = n.t = 0; n.flags = 0; n.depth = 0; n.sh = n.sl = 0; for (j = 0; j < filesz + 1; j++) fwrite(&n, sizeof(struct fileentry), 1, hashfile); fclose(hashfile); } else { printf(CP[50], HASHFILE); } return 0; case 't': /* Create or test persistent transposition table. */ hashfile = fopen(HASHFILE, RWA_ACC); if (hashfile) { fseek(hashfile, 0L, SEEK_END); filesz = (ftell(hashfile) / (sizeof(struct fileentry))) - 1; } if (hashfile != NULL) { long i, j; int nr[MAXDEPTH]; struct fileentry n; printf(CP[49]); for (i = 0; i < MAXDEPTH; i++) nr[i] = 0; fseek(hashfile, 0L, SEEK_END); i = ftell(hashfile) / (sizeof(struct fileentry)); fseek(hashfile, 0L, SEEK_SET); for (j = 0; j < i + 1; j++) { fread(&n, sizeof(struct fileentry), 1, hashfile); if (n.depth > MAXDEPTH) { printf("ERROR\n"); exit(1); } if (n.depth) { nr[n.depth]++; nr[0]++; } } printf(CP[109], nr[0], i); for (j = 1; j < MAXDEPTH; j++) printf("%d ", nr[j]); printf("\n"); } return 0; #endif /* HASHFILE */ #endif /* ttblsz */ case 'v': fprintf(stderr, CP[102], version, patchlevel); exit(1); case 'X': /* X interface. */ display_type = DISPLAY_X; break; case 'x': argc--; argv++; if (argc > 0) xwin = argv[0]; break; default: fprintf(stderr, CP[113]); exit(1); } argc--; argv++; } if (argc == 2) { char *p; MaxResponseTime = 100L * strtol(argv[1], &p, 10); if (*p == ':') { MaxResponseTime = 60L * MaxResponseTime + 100L * strtol(++p, (char **) NULL, 10); } TCflag = false; TCmoves = 0; TCminutes = 0; TCseconds = 0; } if (argc >= 3) { char *p; if (argc > 9) { printf("%s\n", CP[220]); exit(1); } TCmoves = atoi(argv[1]); TCminutes = (short)strtol(argv[2], &p, 10); if (*p == ':') TCseconds = (short)strtol(p + 1, (char **) NULL, 10); else TCseconds = 0; TCflag = true; argc -= 3; argv += 3; while (argc > 1) { XCmoves[XC] = atoi(argv[0]); XCminutes[XC] = (short)strtol(argv[1], &p, 10); if (*p == ':') XCseconds[XC] = (short)strtol(p + 1, (char **) NULL, 10); else XCseconds[XC] = 0; if (XCmoves[XC] && (XCminutes[XC] || XCseconds[XC])) XC++; else { printf("%s\n", CP[220]); exit(1); } argc -= 2; argv += 2; } if (argc) { /* * If we got here, there are unknown arguments, so issue * an error message and quit. */ printf("%s\n", CP[233]); print_arglist(argc, argv); exit(1); } } if (InitMain() != 0) exit(1); while (!flag.quit) { oppptr = (oppptr + 1) % MINGAMEIN; if (flag.bothsides && !flag.mate) SelectMove(opponent, FOREGROUND_MODE); else InputCommand(NULL); if (opponent == white) { if (flag.gamein || TCadd) { TimeCalc(); } else if (TimeControl.moves[opponent] == 0) { if (XC) { if (XCmore < XC) { TCmoves = XCmoves[XCmore]; TCminutes = XCminutes[XCmore]; TCseconds = XCseconds[XCmore]; XCmore++; } } SetTimeControl(); } } compptr = (compptr + 1) % MINGAMEIN; if (!(flag.quit || flag.mate || flag.force)) { #ifdef INTERRUPT_TEST printf("starting search...\n"); #endif SelectMove(computer, FOREGROUND_MODE); if (computer == white) { if (flag.gamein) { TimeCalc(); } else if (TimeControl.moves[computer] == 0) { if (XC) { if (XCmore < XC) { TCmoves = XCmoves[XCmore]; TCminutes = XCminutes[XCmore]; TCseconds = XCseconds[XCmore]; XCmore++; } } SetTimeControl(); } } } } ExitMain(); return 0; }