compile_et.c (127807) | compile_et.c (178846) |
---|---|
1/* 2 * Copyright (c) 1998-2002 Kungliga Tekniska H�gskolan 3 * (Royal Institute of Technology, Stockholm, Sweden). 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 16 unchanged lines hidden (view full) --- 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ | 1/* 2 * Copyright (c) 1998-2002 Kungliga Tekniska H�gskolan 3 * (Royal Institute of Technology, Stockholm, Sweden). 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 16 unchanged lines hidden (view full) --- 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ |
33/* $FreeBSD: head/contrib/com_err/compile_et.c 127807 2004-04-03 21:17:01Z nectar $ */ | 33/* $FreeBSD: head/contrib/com_err/compile_et.c 178846 2008-05-08 11:01:46Z dfr $ */ |
34 35#undef ROKEN_RENAME 36#include "compile_et.h" 37#include <getarg.h> 38 39#if 0 | 34 35#undef ROKEN_RENAME 36#include "compile_et.h" 37#include <getarg.h> 38 39#if 0 |
40RCSID("$Id: compile_et.c,v 1.16 2002/08/20 12:44:51 joda Exp $"); | 40RCSID("$Id: compile_et.c 15426 2005-06-16 19:21:42Z lha $"); |
41#endif 42 43#include <err.h> 44#include "parse.h" 45 46int numerror; 47extern FILE *yyin; 48 49extern void yyparse(void); 50 | 41#endif 42 43#include <err.h> 44#include "parse.h" 45 46int numerror; 47extern FILE *yyin; 48 49extern void yyparse(void); 50 |
51long base; | 51long base_id; |
52int number; 53char *prefix; 54char *id_str; 55 56char name[128]; 57char Basename[128]; 58 59#ifdef YYDEBUG --- 93 unchanged lines hidden (view full) --- 153 fprintf(h_file, "\n"); 154 fprintf(h_file, "void initialize_%s_error_table(void);\n", name); 155 fprintf(h_file, "#define init_%s_err_tbl initialize_%s_error_table\n", 156 name, name); 157 fprintf(h_file, "\n"); 158 fprintf(h_file, "typedef enum %s_error_number{\n", name); 159 160 for(ec = codes; ec; ec = ec->next) { | 52int number; 53char *prefix; 54char *id_str; 55 56char name[128]; 57char Basename[128]; 58 59#ifdef YYDEBUG --- 93 unchanged lines hidden (view full) --- 153 fprintf(h_file, "\n"); 154 fprintf(h_file, "void initialize_%s_error_table(void);\n", name); 155 fprintf(h_file, "#define init_%s_err_tbl initialize_%s_error_table\n", 156 name, name); 157 fprintf(h_file, "\n"); 158 fprintf(h_file, "typedef enum %s_error_number{\n", name); 159 160 for(ec = codes; ec; ec = ec->next) { |
161 fprintf(h_file, "\t%s = %ld%s\n", ec->name, base + ec->number, | 161 fprintf(h_file, "\t%s = %ld%s\n", ec->name, base_id + ec->number, |
162 (ec->next != NULL) ? "," : ""); 163 } 164 165 fprintf(h_file, "} %s_error_number;\n", name); 166 fprintf(h_file, "\n"); | 162 (ec->next != NULL) ? "," : ""); 163 } 164 165 fprintf(h_file, "} %s_error_number;\n", name); 166 fprintf(h_file, "\n"); |
167 fprintf(h_file, "#define ERROR_TABLE_BASE_%s %ld\n", name, base); | 167 fprintf(h_file, "#define ERROR_TABLE_BASE_%s %ld\n", name, base_id); |
168 fprintf(h_file, "\n"); 169 fprintf(h_file, "#endif /* %s */\n", fn); 170 171 172 fclose(h_file); 173 return 0; 174} 175 --- 15 unchanged lines hidden (view full) --- 191 arg_printusage(args, num_args, NULL, "error-table"); 192 exit(code); 193} 194 195int 196main(int argc, char **argv) 197{ 198 char *p; | 168 fprintf(h_file, "\n"); 169 fprintf(h_file, "#endif /* %s */\n", fn); 170 171 172 fclose(h_file); 173 return 0; 174} 175 --- 15 unchanged lines hidden (view full) --- 191 arg_printusage(args, num_args, NULL, "error-table"); 192 exit(code); 193} 194 195int 196main(int argc, char **argv) 197{ 198 char *p; |
199 int optind = 0; | 199 int optidx = 0; |
200 201 setprogname(argv[0]); | 200 201 setprogname(argv[0]); |
202 if(getarg(args, num_args, argc, argv, &optind)) | 202 if(getarg(args, num_args, argc, argv, &optidx)) |
203 usage(1); 204 if(help_flag) 205 usage(0); 206 | 203 usage(1); 204 if(help_flag) 205 usage(0); 206 |
207 if(optind == argc) | 207 if(optidx == argc) |
208 usage(1); | 208 usage(1); |
209 filename = argv[optind]; | 209 filename = argv[optidx]; |
210 yyin = fopen(filename, "r"); 211 if(yyin == NULL) 212 err(1, "%s", filename); 213 214 215 p = strrchr(filename, '/'); 216 if(p) 217 p++; 218 else 219 p = filename; | 210 yyin = fopen(filename, "r"); 211 if(yyin == NULL) 212 err(1, "%s", filename); 213 214 215 p = strrchr(filename, '/'); 216 if(p) 217 p++; 218 else 219 p = filename; |
220 strncpy(Basename, p, sizeof(Basename)); 221 Basename[sizeof(Basename) - 1] = '\0'; | 220 strlcpy(Basename, p, sizeof(Basename)); |
222 223 Basename[strcspn(Basename, ".")] = '\0'; 224 225 snprintf(hfn, sizeof(hfn), "%s.h", Basename); 226 snprintf(cfn, sizeof(cfn), "%s.c", Basename); 227 228 yyparse(); 229 if(numerror) 230 return 1; 231 232 return generate(); 233} | 221 222 Basename[strcspn(Basename, ".")] = '\0'; 223 224 snprintf(hfn, sizeof(hfn), "%s.h", Basename); 225 snprintf(cfn, sizeof(cfn), "%s.c", Basename); 226 227 yyparse(); 228 if(numerror) 229 return 1; 230 231 return generate(); 232} |