[BACK]Return to compile_et.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / compile_et

Diff for /src/usr.bin/compile_et/Attic/compile_et.c between version 1.6 and 1.7

version 1.6, 2000/11/22 12:51:47 version 1.7, 2000/12/24 11:48:57
Line 71 
Line 71 
 static int  static int
 generate_c(void)  generate_c(void)
 {  {
     int n;          int n;
     struct error_code *ec;          struct error_code *ec;
           FILE *c_file = fopen(cfn, "w");
   
     FILE *c_file = fopen(cfn, "w");          if (c_file == NULL)
     if(c_file == NULL)                  return 1;
         return 1;  
   
     fprintf(c_file, "/* Generated from %s */\n", filename);          fprintf(c_file, "/* Generated from %s */\n", filename);
     if(id_str)          if (id_str)
         fprintf(c_file, "/* %s */\n", id_str);                  frintf(c_file, "/* %s */\n", id_str);
     fprintf(c_file, "\n");  
     fprintf(c_file, "#include <stddef.h>\n");  
     fprintf(c_file, "#include <com_err.h>\n");  
     fprintf(c_file, "#include \"%s\"\n", hfn);  
     fprintf(c_file, "\n");  
   
     fprintf(c_file, "static const char *text[] = {\n");          fprintf(c_file, "\n");
           fprintf(c_file, "#include <stddef.h>\n");
           fprintf(c_file, "#include <com_err.h>\n");
           fprintf(c_file, "#include \"%s\"\n", hfn);
           fprintf(c_file, "\n");
   
     for(ec = codes, n = 0; ec; ec = ec->next, n++) {          fprintf(c_file, "static const char *text[] = {\n");
         while(n < ec->number) {  
             fprintf(c_file, "\t/* %03d */ \"Reserved %s error (%d)\",\n",          for (ec = codes, n = 0; ec; ec = ec->next, n++) {
                     n, name, n);                  while (n < ec->number) {
             n++;                          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, "\tNULL\n");
     fprintf(c_file, "};\n");          fprintf(c_file, "};\n");
     fprintf(c_file, "\n");          fprintf(c_file, "\n");
     fprintf(c_file,          fprintf(c_file,
             "void initialize_%s_error_table_r(struct et_list **list)\n",              "void initialize_%s_error_table_r(struct et_list **list)\n", name);
             name);          fprintf(c_file, "{\n");
     fprintf(c_file, "{\n");          fprintf(c_file,
     fprintf(c_file,  
             "    initialize_error_table_r(list, text, "              "    initialize_error_table_r(list, text, "
             "%s_num_errors, ERROR_TABLE_BASE_%s);\n", name, name);              "%s_num_errors, ERROR_TABLE_BASE_%s);\n", name, name);
     fprintf(c_file, "}\n");          fprintf(c_file, "}\n");
     fprintf(c_file, "\n");          fprintf(c_file, "\n");
     fprintf(c_file, "void initialize_%s_error_table(void)\n", name);          fprintf(c_file, "void initialize_%s_error_table(void)\n", name);
     fprintf(c_file, "{\n");          fprintf(c_file, "{\n");
     fprintf(c_file,          fprintf(c_file,
             "    init_error_table(text, ERROR_TABLE_BASE_%s, "              "    init_error_table(text, ERROR_TABLE_BASE_%s, "
             "%s_num_errors);\n", name, name);              "%s_num_errors);\n", name, name);
     fprintf(c_file, "}\n");          fprintf(c_file, "}\n");
   
     fclose(c_file);          fclose(c_file);
     return 0;          return 0;
 }  }
   
 static int  static int
 generate_h(void)  generate_h(void)
 {  {
     struct error_code *ec;          struct error_code *ec;
     char fn[128];          char fn[128], *p;
     FILE *h_file = fopen(hfn, "w");          FILE *h_file = fopen(hfn, "w");
     char *p;  
   
     if(h_file == NULL)          if (h_file == NULL)
         return 1;                  return 1;
   
     snprintf(fn, sizeof(fn), "__%s__", hfn);          snprintf(fn, sizeof(fn), "__%s__", hfn);
     for(p = fn; *p; p++)          for (p = fn; *p; p++) {
         if(!isalnum((unsigned char)*p))                  if(!isalnum((unsigned char)*p))
             *p = '_';                          *p = '_';
           }
     fprintf(h_file, "/* Generated from %s */\n", filename);  
     if(id_str)          fprintf(h_file, "/* Generated from %s */\n", filename);
         fprintf(h_file, "/* %s */\n", id_str);          if (id_str)
     fprintf(h_file, "\n");                  fprintf(h_file, "/* %s */\n", id_str);
     fprintf(h_file, "#ifndef %s\n", fn);  
     fprintf(h_file, "#define %s\n", fn);          fprintf(h_file, "\n");
     fprintf(h_file, "\n");          fprintf(h_file, "#ifndef %s\n", fn);
     fprintf(h_file, "#include <com_err.h>\n");          fprintf(h_file, "#define %s\n", fn);
     fprintf(h_file, "\n");          fprintf(h_file, "\n");
     fprintf(h_file,          fprintf(h_file, "#include <com_err.h>\n");
           fprintf(h_file, "\n");
           fprintf(h_file,
             "void initialize_%s_error_table_r(struct et_list **);\n",              "void initialize_%s_error_table_r(struct et_list **);\n",
             name);              name);
     fprintf(h_file, "\n");          fprintf(h_file, "\n");
     fprintf(h_file, "void initialize_%s_error_table(void);\n", name);          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, "#define init_%s_err_tbl initialize_%s_error_table\n",
             name, name);              name, name);
     fprintf(h_file, "\n");          fprintf(h_file, "\n");
     fprintf(h_file, "typedef enum %s_error_number{\n", name);          fprintf(h_file, "typedef enum %s_error_number{\n", name);
     fprintf(h_file, "\tERROR_TABLE_BASE_%s = %ld,\n", name, base);          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, "\t%s_err_base = %ld,\n", name, base);
   
     for(ec = codes; ec; ec = ec->next) {          for (ec = codes; ec; ec = ec->next)
         fprintf(h_file, "\t%s = %ld,\n", ec->name, base + ec->number);                  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, "\t%s_num_errors = %d\n", name, number);
     fprintf(h_file, "} %s_error_number;\n", name);          fprintf(h_file, "} %s_error_number;\n", name);
     fprintf(h_file, "\n");          fprintf(h_file, "\n");
     fprintf(h_file, "#endif /* %s */\n", fn);          fprintf(h_file, "#endif /* %s */\n", fn);
   
           fclose(h_file);
     fclose(h_file);          return 0;
     return 0;  
 }  }
   
 static int  static int
 generate(void)  generate(void)
 {  {
     return generate_c() || generate_h();          return generate_c() || generate_h();
 }  }
   
 static void  static void
 usage(int code)  usage(int code)
 {  {
     extern char *__progname;          extern char *__progname;
     fprintf(stderr, "usage: %s file\n", __progname);  
     exit(1);          fprintf(stderr, "usage: %s file\n", __progname);
           exit(1);
 }  }
   
 int  int
 main(int argc, char **argv)  main(int argc, char **argv)
 {  {
     char *p;          char *p;
   
     if(argc != 2)          if (argc != 2)
         usage(1);                  usage(1);
   
     filename = argv[1];          filename = argv[1];
     yyin = fopen(filename, "r");          yyin = fopen(filename, "r");
     if(yyin == NULL)          if (yyin == NULL)
         err(1, "%s", filename);                  err(1, "%s", filename);
   
           p = strrchr(filename, '/');
     p = strrchr(filename, '/');          if (p)
     if(p)                  p++;
         p++;          else
     else                  p = filename;
         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;  
   
     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();
 }  }

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7