=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/compile_et/Attic/compile_et.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- src/usr.bin/compile_et/Attic/compile_et.c 2000/11/22 12:51:47 1.6 +++ src/usr.bin/compile_et/Attic/compile_et.c 2000/12/24 11:48:57 1.7 @@ -1,4 +1,4 @@ -/* $OpenBSD: compile_et.c,v 1.6 2000/11/22 12:51:47 aaron Exp $ */ +/* $OpenBSD: compile_et.c,v 1.7 2000/12/24 11:48:57 aaron Exp $ */ /* * Copyright (c) 1998, 1999 Kungliga Tekniska Högskolan * (Royal Institute of Technology, Stockholm, Sweden). @@ -71,152 +71,152 @@ static int generate_c(void) { - int n; - struct error_code *ec; + int n; + struct error_code *ec; + FILE *c_file = fopen(cfn, "w"); - FILE *c_file = fopen(cfn, "w"); - if(c_file == NULL) - return 1; + if (c_file == NULL) + return 1; - fprintf(c_file, "/* Generated from %s */\n", filename); - if(id_str) - fprintf(c_file, "/* %s */\n", id_str); - fprintf(c_file, "\n"); - fprintf(c_file, "#include \n"); - fprintf(c_file, "#include \n"); - fprintf(c_file, "#include \"%s\"\n", hfn); - fprintf(c_file, "\n"); + fprintf(c_file, "/* Generated from %s */\n", filename); + if (id_str) + frintf(c_file, "/* %s */\n", id_str); - fprintf(c_file, "static const char *text[] = {\n"); + fprintf(c_file, "\n"); + fprintf(c_file, "#include \n"); + fprintf(c_file, "#include \n"); + fprintf(c_file, "#include \"%s\"\n", hfn); + fprintf(c_file, "\n"); - for(ec = codes, n = 0; ec; ec = ec->next, n++) { - while(n < ec->number) { - fprintf(c_file, "\t/* %03d */ \"Reserved %s error (%d)\",\n", - n, name, n); - n++; - + fprintf(c_file, "static const char *text[] = {\n"); + + for (ec = codes, n = 0; ec; ec = ec->next, n++) { + while (n < ec->number) { + fprintf(c_file, + "\t/* %03d */ \"Reserved %s error (%d)\",\n", + n, name, n); + n++; + } + fprintf(c_file, + "\t/* %03d */ \"%s\",\n", ec->number, ec->string); } - fprintf(c_file, "\t/* %03d */ \"%s\",\n", ec->number, ec->string); - } - fprintf(c_file, "\tNULL\n"); - fprintf(c_file, "};\n"); - fprintf(c_file, "\n"); - fprintf(c_file, - "void initialize_%s_error_table_r(struct et_list **list)\n", - name); - fprintf(c_file, "{\n"); - fprintf(c_file, + fprintf(c_file, "\tNULL\n"); + fprintf(c_file, "};\n"); + fprintf(c_file, "\n"); + fprintf(c_file, + "void initialize_%s_error_table_r(struct et_list **list)\n", name); + fprintf(c_file, "{\n"); + fprintf(c_file, " initialize_error_table_r(list, text, " "%s_num_errors, ERROR_TABLE_BASE_%s);\n", name, name); - fprintf(c_file, "}\n"); - fprintf(c_file, "\n"); - fprintf(c_file, "void initialize_%s_error_table(void)\n", name); - fprintf(c_file, "{\n"); - fprintf(c_file, + fprintf(c_file, "}\n"); + fprintf(c_file, "\n"); + fprintf(c_file, "void initialize_%s_error_table(void)\n", name); + fprintf(c_file, "{\n"); + fprintf(c_file, " init_error_table(text, ERROR_TABLE_BASE_%s, " "%s_num_errors);\n", name, name); - fprintf(c_file, "}\n"); + fprintf(c_file, "}\n"); - fclose(c_file); - return 0; + fclose(c_file); + return 0; } static int generate_h(void) { - struct error_code *ec; - char fn[128]; - FILE *h_file = fopen(hfn, "w"); - char *p; + struct error_code *ec; + char fn[128], *p; + FILE *h_file = fopen(hfn, "w"); - if(h_file == NULL) - return 1; + if (h_file == NULL) + return 1; - snprintf(fn, sizeof(fn), "__%s__", hfn); - for(p = fn; *p; p++) - if(!isalnum((unsigned char)*p)) - *p = '_'; - - fprintf(h_file, "/* Generated from %s */\n", filename); - if(id_str) - fprintf(h_file, "/* %s */\n", id_str); - fprintf(h_file, "\n"); - fprintf(h_file, "#ifndef %s\n", fn); - fprintf(h_file, "#define %s\n", fn); - fprintf(h_file, "\n"); - fprintf(h_file, "#include \n"); - fprintf(h_file, "\n"); - fprintf(h_file, + snprintf(fn, sizeof(fn), "__%s__", hfn); + for (p = fn; *p; p++) { + if(!isalnum((unsigned char)*p)) + *p = '_'; + } + + fprintf(h_file, "/* Generated from %s */\n", filename); + if (id_str) + fprintf(h_file, "/* %s */\n", id_str); + + fprintf(h_file, "\n"); + fprintf(h_file, "#ifndef %s\n", fn); + fprintf(h_file, "#define %s\n", fn); + fprintf(h_file, "\n"); + fprintf(h_file, "#include \n"); + fprintf(h_file, "\n"); + fprintf(h_file, "void initialize_%s_error_table_r(struct et_list **);\n", name); - fprintf(h_file, "\n"); - fprintf(h_file, "void initialize_%s_error_table(void);\n", name); - fprintf(h_file, "#define init_%s_err_tbl initialize_%s_error_table\n", + fprintf(h_file, "\n"); + fprintf(h_file, "void initialize_%s_error_table(void);\n", name); + fprintf(h_file, "#define init_%s_err_tbl initialize_%s_error_table\n", name, name); - fprintf(h_file, "\n"); - fprintf(h_file, "typedef enum %s_error_number{\n", name); - fprintf(h_file, "\tERROR_TABLE_BASE_%s = %ld,\n", name, base); - fprintf(h_file, "\t%s_err_base = %ld,\n", name, base); + fprintf(h_file, "\n"); + fprintf(h_file, "typedef enum %s_error_number{\n", name); + fprintf(h_file, "\tERROR_TABLE_BASE_%s = %ld,\n", name, base); + fprintf(h_file, "\t%s_err_base = %ld,\n", name, base); - for(ec = codes; ec; ec = ec->next) { - fprintf(h_file, "\t%s = %ld,\n", ec->name, base + ec->number); - } + for (ec = codes; ec; ec = ec->next) + fprintf(h_file, "\t%s = %ld,\n", ec->name, base + ec->number); - fprintf(h_file, "\t%s_num_errors = %d\n", name, number); - fprintf(h_file, "} %s_error_number;\n", name); - fprintf(h_file, "\n"); - fprintf(h_file, "#endif /* %s */\n", fn); + fprintf(h_file, "\t%s_num_errors = %d\n", name, number); + fprintf(h_file, "} %s_error_number;\n", name); + fprintf(h_file, "\n"); + fprintf(h_file, "#endif /* %s */\n", fn); - - fclose(h_file); - return 0; + fclose(h_file); + return 0; } static int generate(void) { - return generate_c() || generate_h(); + return generate_c() || generate_h(); } static void usage(int code) { - extern char *__progname; - fprintf(stderr, "usage: %s file\n", __progname); - exit(1); + extern char *__progname; + + fprintf(stderr, "usage: %s file\n", __progname); + exit(1); } int main(int argc, char **argv) { - char *p; + char *p; - if(argc != 2) - usage(1); + if (argc != 2) + usage(1); - filename = argv[1]; - yyin = fopen(filename, "r"); - if(yyin == NULL) - err(1, "%s", filename); + filename = argv[1]; + yyin = fopen(filename, "r"); + if (yyin == NULL) + err(1, "%s", filename); - - p = strrchr(filename, '/'); - if(p) - p++; - else - p = filename; - strncpy(Basename, p, sizeof(Basename)); - Basename[sizeof(Basename) - 1] = '\0'; - - Basename[strcspn(Basename, ".")] = '\0'; - - snprintf(hfn, sizeof(hfn), "%s.h", Basename); - snprintf(cfn, sizeof(cfn), "%s.c", Basename); - - yyparse(); - if(numerror) - return 1; + p = strrchr(filename, '/'); + if (p) + p++; + else + p = filename; - return generate(); + strncpy(Basename, p, sizeof(Basename)); + Basename[sizeof(Basename) - 1] = '\0'; + Basename[strcspn(Basename, ".")] = '\0'; + + snprintf(hfn, sizeof(hfn), "%s.h", Basename); + snprintf(cfn, sizeof(cfn), "%s.c", Basename); + + yyparse(); + if (numerror) + return 1; + + return generate(); }