From 2a03849d6c347eb70cdcfedaf3e770ab57dfcd6d Mon Sep 17 00:00:00 2001 From: Nick Downing Date: Sat, 14 Jan 2017 17:45:08 +1100 Subject: [PATCH] Patches to cproto to fix varargs handling and adjust output, add xify program --- .gitignore | 12 ++ cproto-4.6/cproto.c | 50 +++++++ cproto-4.6/cproto.h | 6 + cproto-4.6/grammar.y | 8 ++ cproto-4.6/lex.l | 39 +++++- cproto-4.6/semantic.c | 151 +++++++++++++++++++++ cproto-4.6/symbol.c | 17 +++ cproto-4.6/symbol.h | 4 + xify/Makefile | 6 + xify/xify.c | 297 ++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 589 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 xify/Makefile create mode 100644 xify/xify.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0e25309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +*.a +*.o +cproto-4.6/Makefile +cproto-4.6/config.cache +cproto-4.6/config.h +cproto-4.6/config.log +cproto-4.6/config.status +cproto-4.6/cproto +cproto-4.6/lex.yy.c +cproto-4.6/stamp-h +cproto-4.6/y.tab.c +xify/xify diff --git a/cproto-4.6/cproto.c b/cproto-4.6/cproto.c index b6a5808..25c7ab3 100644 --- a/cproto-4.6/cproto.c +++ b/cproto-4.6/cproto.c @@ -55,15 +55,30 @@ PrototypeStyle proto_style = PROTO_ANSI; /* Function definition style converted to */ FuncDefStyle func_style = FUNC_UNKNOWN; +#if 1 /* Nick */ +FuncDefStyle func_style_varargs = FUNC_UNKNOWN; +#endif /* If TRUE, put guard macro around prototype parameters */ +#if 1 /* Nick */ +boolean proto_macro = TRUE; +#else boolean proto_macro = FALSE; +#endif /* Name of macro to guard prototypes */ +#if 1 /* Nick */ +char *macro_name = "__P"; +#else char *macro_name = "P_"; +#endif /* If TRUE, output prototype macro definition */ +#if 1 /* Nick */ +boolean define_macro = FALSE; +#else boolean define_macro = TRUE; +#endif /* If TRUE, output comments in prototypes */ boolean proto_comments = FALSE; @@ -80,10 +95,17 @@ FuncFormat fmt[] = { { "", " ", "", "", " ", "" }, /* prototype */ { "", " ", "", "", " ", "" }, +#if 1 /* Nick */ + /* function definition */ + { "", " ", "", "", " ", "" }, + /* function definition with parameter comments */ + { "", " ", "", "\n\t", "\n\t", "\n" }, +#else /* function definition */ { "", "\n", " ", "", " ", "" }, /* function definition with parameter comments */ { "", "\n", " ", "\n ", "\n ", "\n" }, +#endif }; /* If TRUE, don't output message if unable to read an include file */ @@ -108,6 +130,10 @@ char *inc_dir[MAX_INC_DIR] = { "", "/usr/include" }; # endif #endif +#if 1 /* Nick */ +boolean insert_stdin = FALSE; +#endif + /* Run the C preprocessor */ #ifdef CPP # if !HAVE_POPEN_PROTOTYPE @@ -484,8 +510,28 @@ char ***pargv; *(cpp_cmd = xmalloc(n)) = '\0'; #endif +#if 1 /* Nick */ + while ((c = getopt(argc, argv, "ALHaB:bC:cD:dE:eF:f:i:I:jmM:P:pqSstU:Vvo:O:Tlx")) != EOF) { + switch (c) { + case 'A': + func_style_varargs = FUNC_ANSI; + break; + case 'L': + func_style_varargs = FUNC_TRADITIONAL; + break; + case 'H': + func_style_varargs = FUNC_BOTH; + break; + case 'i': + inc_dir[num_inc_dir - 1] = trim_path_sep(xstrdup(optarg)); + break; + case 'j': + insert_stdin = TRUE; + break; +#else while ((c = getopt(argc, argv, "aB:bC:cD:dE:eF:f:I:mM:P:pqSstU:Vvo:O:Tlx")) != EOF) { switch (c) { +#endif case 'I': #ifdef vms add2list(cpp_include, optarg); @@ -657,6 +703,10 @@ char ***pargv; usage(); } } +#if 1 /* Nick */ + if (func_style_varargs == FUNC_UNKNOWN) + func_style_varargs = func_style; +#endif #ifdef vms add_option("includes", cpp_include); diff --git a/cproto-4.6/cproto.h b/cproto-4.6/cproto.h index fab5da9..7da7dde 100644 --- a/cproto-4.6/cproto.h +++ b/cproto-4.6/cproto.h @@ -173,6 +173,9 @@ extern boolean variables_out; extern boolean promote_param; extern PrototypeStyle proto_style; extern FuncDefStyle func_style; +#if 1 /* Nick */ +extern FuncDefStyle func_style_varargs; +#endif extern boolean proto_macro; extern boolean define_macro; extern char *macro_name; @@ -182,6 +185,9 @@ extern boolean quiet; extern char *func_directive; extern int num_inc_dir; extern char *inc_dir[]; +#if 1 /* Nick */ +extern boolean insert_stdin; +#endif extern FuncFormat fmt[4]; /* Global declarations */ diff --git a/cproto-4.6/grammar.y b/cproto-4.6/grammar.y index f54ebb0..8ed8f51 100644 --- a/cproto-4.6/grammar.y +++ b/cproto-4.6/grammar.y @@ -339,6 +339,7 @@ function_definition opt_declaration_list : /* empty */ +/* Nick | T_VA_DCL | declaration_list ; @@ -347,6 +348,13 @@ declaration_list : declaration | declaration_list declaration ; +*/ + | opt_declaration_list declaration + | opt_declaration_list T_VA_DCL + { + set_param_types(func_params, NULL, NULL); + } + ; decl_specifiers : decl_specifier diff --git a/cproto-4.6/lex.l b/cproto-4.6/lex.l index aca67c2..8a55787 100644 --- a/cproto-4.6/lex.l +++ b/cproto-4.6/lex.l @@ -154,6 +154,15 @@ QUOTE [\"\'] new_symbol(define_names, name, value, DS_NONE); } +undef{WS}+{ID} { /* Nick */ + char name[MAX_TEXT_SIZE]; + + save_text(); + sscanf(yytext, "undef %s", name); + get_cpp_directive(buf, sizeof(buf)); + del_symbol(define_names, name); + } + include{WS}* { save_text(); get_cpp_directive(buf, sizeof(buf)); @@ -243,7 +252,15 @@ QUOTE [\"\'] enum { save_text_offset(); return T_ENUM; } struct { save_text_offset(); return T_STRUCT; } union { save_text_offset(); return T_UNION; } -va_dcl { save_text_offset(); return T_VA_DCL; } +va_dcl { + save_text_offset(); +#if 1 /* Nick */ + if (cur_file->convert) + cur_file->begin_comment = + ftell(cur_file->tmp_file); +#endif + return T_VA_DCL; + } __signed { save_text_offset(); return T_SIGNED; } __signed__ { save_text_offset(); return T_SIGNED; } @@ -944,6 +961,7 @@ char *file_spec; /* path surrounded by "" or <> */ n = (s != NULL) ? (unsigned)(s - file_spec - 1) : 0; strncpy(file, file_spec+1, (size_t)n); file[n] = '\0'; + /*fprintf(stderr, "request %s\n", file);*/ /* Do nothing if the file was already included. */ sprintf(path, stdinc ? "<%s>" : "\"%s\"", file); @@ -951,17 +969,36 @@ char *file_spec; /* path surrounded by "" or <> */ return; new_symbol(included_files, path, NULL, DS_NONE); +#if 1 /* Nick */ + int j = strlen(cur_file->file_name); + while (j >= 0 && cur_file->file_name[j--] != '/') + ; + char c = cur_file->file_name[++j]; + cur_file->file_name[j] = 0; + inc_dir[0] = cur_file->file_name; +#endif for (i = stdinc != 0; i < num_inc_dir; ++i) { if (strlen(inc_dir[i]) == 0) { strcpy(path, file); } else { sprintf(path, "%s/%s", inc_dir[i], file); } + /*fprintf(stderr, "trying %s\n", path);*/ if ((fp = fopen(path, "r")) != NULL) { + /*fprintf(stderr, "success!\n");*/ +#if 1 /* Nick */ + cur_file->file_name[j] = c; + inc_dir[0] = ""; +#endif yyin = fp; include_file(path, func_style != FUNC_NONE && !stdinc); return; } + /*fprintf(stderr, "failure!\n");*/ +#if 1 /* Nick */ + cur_file->file_name[j] = c; + inc_dir[0] = ""; +#endif } if (!quiet) { diff --git a/cproto-4.6/semantic.c b/cproto-4.6/semantic.c index aefa0b2..1781ce3 100644 --- a/cproto-4.6/semantic.c +++ b/cproto-4.6/semantic.c @@ -4,6 +4,9 @@ * C function prototype generator. */ #include +#if 1 /* Nick */ +#include +#endif #include "cproto.h" #include "semantic.h" @@ -29,7 +32,9 @@ static void put_decl_spec ARGS((FILE *outf, DeclSpec *decl_spec)); #if OPT_LINTLIBRARY static void put_llib_params ARGS((Declarator *d, int c)); #endif +#if 0 /* Nick */ static int uses_varargs ARGS((Declarator *declarator)); +#endif static void check_void_param ARGS((Declarator *declarator)); static void set_param_decl_spec ARGS((Declarator *declarator)); static void put_param_decl ARGS((Declarator *declarator, int commented)); @@ -379,6 +384,23 @@ DeclaratorList *declarators; Parameter *p; char *decl_spec_text; +#if 1 /* Nick */ + if (decl_spec == NULL) { + /* had va_dcl, change va_alist to ellipsis */ + /* make it behave like we'd called add_ident_list() initially */ + if ((p = search_parameter_list(params, "va_alist")) == NULL) { + put_error(); + fprintf(stderr, "declared argument \"va_alist\" is missing\n"); + } else { + free_decl_spec(&p->decl_spec); + new_decl_spec(&p->decl_spec, "", 0L, DS_NONE); + + free_declarator(p->declarator); + p->declarator = new_declarator(ELLIPSIS, ELLIPSIS, 0L); + } + return; + } +#endif for (d = declarators->first; d != NULL; d = d->next) { /* Search the parameter list for a matching name. */ if ((p = search_parameter_list(params, d->name)) == NULL) { @@ -616,12 +638,21 @@ int commented; put_string(outf, fmt[format].first_param_prefix); put_string(outf, p->declarator->name); p = p->next; +#if 1 /* Nick */ + while (p != NULL) { + put_char(outf, ','); + put_string(outf, fmt[format].middle_param_prefix); + put_string(outf, strcmp(p->declarator->text, ELLIPSIS) == 0 ? "va_alist" : p->declarator->name); + p = p->next; + } +#else while (p != NULL && strcmp(p->declarator->text, ELLIPSIS) != 0) { put_char(outf, ','); put_string(outf, fmt[format].middle_param_prefix); put_string(outf, p->declarator->name); p = p->next; } +#endif put_string(outf, fmt[format].last_param_suffix); } } else { @@ -912,6 +943,7 @@ DeclaratorList *decl_list; /* list of declared variables */ exitlike_func = FALSE; } +#if 0 /* Nick */ /* Return TRUE if the function uses varargs. */ static int @@ -924,6 +956,7 @@ Declarator *declarator; && (p->next == NULL) && (!strcmp(p->declarator->name, "va_alist")); } +#endif /* If the parameter list is empty, then replace it with "void". */ @@ -995,6 +1028,7 @@ Declarator *declarator; #endif func_declarator = declarator->head; +#if 0 /* Nick */ if (uses_varargs(func_declarator)) { /* Generate a prototype for a function that uses varargs by replacing * the "va_alist" parameter with an empty parameter list. @@ -1002,6 +1036,7 @@ Declarator *declarator; free_param_list(&func_declarator->params); func_declarator->params.first = NULL; } +#endif check_void_param(func_declarator); set_param_decl_spec(func_declarator); @@ -1056,14 +1091,36 @@ int commented; #endif Parameter *p; +#if 1 /* Nick */ + if (declarator->params.comment != NULL) + put_string(cur_tmp_file(), declarator->params.comment); +#endif p = declarator->params.first; if (!is_void_parameter(p)) { +#if 1 /* Nick */ + fputc(' ', cur_tmp_file()); +#else fputc('\n', cur_tmp_file()); +#endif (void)putParameter(cur_tmp_file(), p, knrLintLibrary(), ++count, commented); fputc(';', cur_tmp_file()); if (p->comment != 0) fputs(p->comment, cur_tmp_file()); p = p->next; +#if 1 /* Nick */ + while (p != NULL) { + fputc(' ', cur_tmp_file()); + if (strcmp(p->declarator->text, ELLIPSIS) == 0) + put_string(cur_tmp_file(), "va_dcl"); + else { + (void)putParameter(cur_tmp_file(), p, knrLintLibrary(), ++count, commented); + fputc(';', cur_tmp_file()); + } + if (p->comment != 0) + fputs(p->comment, cur_tmp_file()); + p = p->next; + } +#else while (p != NULL && strcmp(p->declarator->text, ELLIPSIS) != 0) { fputc('\n', cur_tmp_file()); (void)putParameter(cur_tmp_file(), p, knrLintLibrary(), ++count, commented); @@ -1072,6 +1129,7 @@ int commented; fputs(p->comment, cur_tmp_file()); p = p->next; } +#endif } } @@ -1093,9 +1151,11 @@ Declarator *declarator; * or if the function uses varargs. */ func_declarator = declarator->head; +#if 0 /* Nick */ if (func_declarator->func_def == func_style || uses_varargs(func_declarator)) return; +#endif /* Save the text between the function head and the function body. * Read the temporary file from after the last ) or ; to the @@ -1148,7 +1208,20 @@ Declarator *declarator; where = FUNC_DEF; fseek(cur_tmp_file(), decl_spec->begin, 0); +#if 1 /* Nick */ + if (insert_stdin) { + int c; + while ((c = getchar()) != EOF) + fputc(c, cur_tmp_file()); + } +#endif +#if 1 /* Nick */ + FuncDefStyle func_style_save = func_style; + if (search_parameter_list(&func_declarator->params, ELLIPSIS) != NULL) + func_style = func_style_varargs; +#endif if (func_style == FUNC_BOTH) { +#if 0 /* Nick */ char *cur_func; unsigned func_len; @@ -1161,40 +1234,66 @@ Declarator *declarator; cur_func = 0; func_len = 0; } +#endif fseek(cur_tmp_file(), decl_spec->begin, 0); +#if 1 /* Nick */ + fputs("#ifdef __STDC__\n", cur_tmp_file()); +#else fprintf(cur_tmp_file(), "%s\n\n", func_directive); +#endif /* Output new style function definition head. */ +#if 0 /* Nick */ if (func_declarator->func_def == FUNC_ANSI) { if (cur_func != 0) fwrite(cur_func, sizeof(char), func_len, cur_tmp_file()); } else { +#endif fputs(fmt[format].decl_spec_prefix, cur_tmp_file()); fputs(decl_spec->text, cur_tmp_file()); fputc(' ', cur_tmp_file()); func_style = FUNC_ANSI; put_func_declarator(cur_tmp_file(), declarator, FALSE); +#if 0 /* Nick */ } +#endif +#if 1 /* Nick */ + fputs("\n#else\n", cur_tmp_file()); +#else fputs("\n#else\n\n", cur_tmp_file()); +#endif /* Output old style function definition head. */ +#if 0 /* Nick */ if (func_declarator->func_def == FUNC_TRADITIONAL || func_declarator->func_def == FUNC_BOTH) { if (cur_func != 0) fwrite(cur_func, sizeof(char), func_len, cur_tmp_file()); } else { +#endif fputs(fmt[format].decl_spec_prefix, cur_tmp_file()); fputs(decl_spec->text, cur_tmp_file()); fputc(' ', cur_tmp_file()); +#if 1 /* Nick */ + int i = format; +#endif format = FMT_FUNC; func_style = FUNC_TRADITIONAL; put_func_declarator(cur_tmp_file(), declarator, FALSE); +#if 1 /* Nick */ + format = i; +#endif put_param_decl(func_declarator, FALSE); +#if 0 /* Nick */ } +#endif +#if 1 /* Nick */ + fputs("\n#endif\n", cur_tmp_file()); +#else fputs("\n#endif", cur_tmp_file()); if (*comment != '\n') fputc('\n', cur_tmp_file()); @@ -1202,7 +1301,20 @@ Declarator *declarator; if (cur_func != 0) free(cur_func); +#endif +#if 1 /* Nick */ + /* Output text between function head and body. */ + if (comment != 0) { + int i; + for (i = 0; i < comment_len && isblank(comment[i]); ++i) + ; + for (; i < comment_len && comment[i] == '\n'; ++i) + ; + fwrite(comment + i, sizeof(char), comment_len - i, cur_tmp_file()); + free(comment); + } +#endif } else { /* Output declarator specifiers. */ fputs(fmt[format].decl_spec_prefix, cur_tmp_file()); @@ -1210,16 +1322,55 @@ Declarator *declarator; fputc(' ', cur_tmp_file()); /* Output function declarator. */ +#if 1 /* Nick */ + if (func_style == FUNC_TRADITIONAL) { + int i = format; + format = FMT_FUNC; + put_func_declarator(cur_tmp_file(), declarator, FALSE); + format = i; + put_param_decl(func_declarator, FALSE); + } + else + put_func_declarator(cur_tmp_file(), declarator, FALSE); +#else put_func_declarator(cur_tmp_file(), declarator, FALSE); if (func_style == FUNC_TRADITIONAL) put_param_decl(func_declarator, FALSE); +#endif + +#if 1 /* Nick */ + /* Output text between function head and body. */ + if (comment == 0) + fputc(' ', cur_tmp_file()); + else { + int i; + for (i = 0; i < comment_len && isblank(comment[i]); ++i) + ; + if (i < comment_len && comment[i] == '\n') { + for (++i; i < comment_len && comment[i] == '\n'; ++i) + ; + if (i < comment_len && comment[i] == '{') + fputc(' ', cur_tmp_file()); + else + fputc('\n', cur_tmp_file()); + } + else + fputc(' ', cur_tmp_file()); + fwrite(comment + i, sizeof(char), comment_len - i, cur_tmp_file()); + free(comment); + } +#endif } +#if 1 /* Nick */ + func_style = func_style_save; +#else /* Output text between function head and body. */ if (comment != 0) { fwrite(comment, sizeof(char), comment_len, cur_tmp_file()); free(comment); } +#endif cur_file_changed(); } diff --git a/cproto-4.6/symbol.c b/cproto-4.6/symbol.c index 25e18b7..54c5319 100644 --- a/cproto-4.6/symbol.c +++ b/cproto-4.6/symbol.c @@ -123,3 +123,20 @@ int flags; /* symbol attributes */ sym->flags = flags; return sym; } + + +#if 1 /* Nick */ +void +del_symbol (symtab, name) +SymbolTable *symtab; /* symbol table */ +char *name; /* symbol name */ +{ + Symbol **psym, *sym; + + for (psym = symtab->bucket + hash(name); (sym = *psym) != NULL; psym = &sym->next) + if (strcmp(sym->name, name) == 0) { + *psym = sym->next; + break; + } +} +#endif diff --git a/cproto-4.6/symbol.h b/cproto-4.6/symbol.h index eb0fa77..506bcd2 100644 --- a/cproto-4.6/symbol.h +++ b/cproto-4.6/symbol.h @@ -28,5 +28,9 @@ extern Symbol *find_symbol /* Lookup symbol name */ ARGS((SymbolTable *s, char *n)); extern Symbol *new_symbol /* Define new symbol */ ARGS((SymbolTable *s, char *n, char *v, int f)); +#if 1 /* Nick */ +extern void del_symbol + ARGS((SymbolTable *s, char *n)); +#endif #endif diff --git a/xify/Makefile b/xify/Makefile new file mode 100644 index 0000000..a8b363d --- /dev/null +++ b/xify/Makefile @@ -0,0 +1,6 @@ +CFLAGS=-g -Wall + +xify: xify.c + +clean: + rm -f xify diff --git a/xify/xify.c b/xify/xify.c new file mode 100644 index 0000000..b375798 --- /dev/null +++ b/xify/xify.c @@ -0,0 +1,297 @@ +#include +#include +#include +#include +#include + +char buf[1024]; + +int main() { + char *p, *q; + int l, m; + int e; + + printf("#include \"x_.h\"\n\n"); + while (fgets(buf, sizeof(buf), stdin)) { + p = buf; + l = 0; + if (p[l] == '#') { + ++l; + while (isblank(p[l])) + ++l; + q = p + l; + m = 0; + if (isalpha(q[m])) { + ++m; + while (isalnum(q[m]) || q[m] == '_') + ++m; + l += m; + if (m == 7 && memcmp(q, "include", 7) == 0) { + while (isblank(p[l])) + ++l; + if (p[l] == '<') { + e = '>'; + goto include; + } + else if (p[l] == '"') { + e = '"'; + include: + fwrite(p, ++l, 1, stdout); + p += l; + l = 0; + while (p[l]) { + if (p[l] == '/') { + fwrite(p, ++l, 1, stdout); + p += l; + l = 0; + } + else if (p[l] == e) { + if (l >= 4 && memcmp(p, "nox_", 4) == 0) { + p += 4; + l -= 4; + } + else if ( + (l != 8 || memcmp(p, "stdarg.h", 8) != 0) && + (l != 9 || memcmp(p, "varargs.h", 9) != 0) + ) + fwrite("x_", 2, 1, stdout); + break; + } + else + ++l; + } + } + } + } + fwrite(p, l, 1, stdout); + p += l; + l = 0; + } + while (p[l]) { + if (isalpha(p[l]) || p[l] == '_') { + ++l; + while (isalnum(p[l]) || p[l] == '_') + ++l; + if ( + (l == 8 && memcmp(p, "register", 8) == 0) || + (l == 6 && memcmp(p, "static", 6) == 0) + ) { + fwrite(p, l, 1, stdout); + p += l; + l = 0; + while (isblank(p[l])) + ++l; + q = p + l; + m = 0; + if (isalpha(q[m]) || q[m] == '_') { + ++m; + while (isalnum(q[m]) || q[m] == '_') + ++m; + if ( + (m != 4 || memcmp(q, "char", 4) != 0) && + (m != 6 || memcmp(q, "double", 6) != 0) && + (m != 4 || memcmp(q, "enum", 4) != 0) && + (m != 5 || memcmp(q, "float", 5) != 0) && + (m != 3 || memcmp(q, "int", 3) != 0) && + (m != 8 || memcmp(q, "intptr_t", 8) != 0) && + (m != 4 || memcmp(q, "long", 4) != 0) && + (m != 5 || memcmp(q, "short", 5) != 0) && + (m != 6 || memcmp(q, "struct", 6) != 0) && + (m != 5 || memcmp(q, "union", 5) != 0) && + (m != 8 || memcmp(q, "unsigned", 8) != 0) && + (m != 7 || memcmp(q, "va_list", 7) != 0) + ) { + q += m; + m = 0; + while (isblank(q[m])) + ++m; + if (q[m] != '*') /* avoid something like: register FILE *fp; */ + fwrite(" x_int", 6, 1, stdout); + } + } + else /* maybe something like: register *p; */ + fwrite(" x_int", 6, 1, stdout); + } + else if (l == 3 && memcmp(p, "int", 3) == 0) { + fwrite("x_int", 5, 1, stdout); + p += l; + l = 0; + } + else if ( + (l == 5 && memcmp(p, "short", 5) == 0) || + (l == 4 && memcmp(p, "long", 4) == 0) + ) { + fwrite("x_", 2, 1, stdout); + fwrite(p, l, 1, stdout); + p += l; + l = 0; + while (isblank(p[l])) + ++l; + q = p + l; + m = 0; + if (isalpha(q[m])) { + ++m; + while (isalnum(q[m]) || q[m] == '_') + ++m; + if (m == 3 && memcmp(q, "int", 3) == 0) { + p += l + m; + l = 0; + } + } + } + else if (l == 8 && memcmp(p, "unsigned", 8) == 0) { + while (isblank(p[l])) + ++l; + q = p + l; + m = 0; + if (isalpha(q[m])) { + ++m; + while (isalnum(q[m]) || q[m] == '_') + ++m; + if (m == 3 && memcmp(q, "int", 3) == 0) { + fwrite("x_unsigned_int", 14, 1, stdout); + p += l + m; + l = 0; + } + else if ( + (m == 5 && memcmp(q, "short", 5) == 0) || + (m == 4 && memcmp(q, "long", 4) == 0) + ) { + fwrite("x_unsigned_", 11, 1, stdout); + fwrite(q, m, 1, stdout); + p += l + m; + l = 0; + while (isblank(p[l])) + ++l; + q = p + l; + m = 0; + if (isalpha(q[m])) { + ++m; + while (isalnum(q[m]) || q[m] == '_') + ++m; + if (m == 3 && memcmp(q, "int", 3) == 0) { + p += l + m; + l = 0; + } + } + } + else if (m != 4 || memcmp(q, "char", 4) != 0) { + fwrite("x_unsigned_int", 14, 1, stdout); + p += 8; + l -= 8; + } + } + } + else if (l >= 4 && memcmp(p, "nox_", 4) == 0) { + p += 4; + l -= 4; + } + else if ( + (l != 5 || memcmp(p, "break", 5) != 0) && + (l != 4 || memcmp(p, "case", 4) != 0) && + (l != 4 || memcmp(p, "char", 4) != 0) && + (l != 8 || memcmp(p, "continue", 8) != 0) && + (l != 7 || memcmp(p, "defined", 7) != 0 || buf[0] != '#') && + (l != 2 || memcmp(p, "do", 2) != 0) && + (l != 6 || memcmp(p, "double", 6) != 0) && + (l != 4 || memcmp(p, "else", 4) != 0) && + (l != 4 || memcmp(p, "enum", 4) != 0) && + (l != 6 || memcmp(p, "extern", 6) != 0) && + (l != 5 || memcmp(p, "float", 5) != 0) && + (l != 2 || memcmp(p, "if", 2) != 0) && + (l != 8 || memcmp(p, "intptr_t", 8) != 0) && + (l != 3 || memcmp(p, "for", 3) != 0) && + (l != 4 || memcmp(p, "goto", 4) != 0) && + (l != 6 || memcmp(p, "return", 6) != 0) && + (l != 8 || memcmp(p, "register", 8) != 0) && + (l != 6 || memcmp(p, "sizeof", 6) != 0) && + (l != 6 || memcmp(p, "static", 6) != 0) && + (l != 6 || memcmp(p, "struct", 6) != 0) && + (l != 6 || memcmp(p, "switch", 6) != 0) && + (l != 7 || memcmp(p, "typedef", 7) != 0) && + (l != 5 || memcmp(p, "union", 5) != 0) && + (l != 8 || memcmp(p, "va_alist", 8) != 0) && + (l != 6 || memcmp(p, "va_arg", 6) != 0) && + (l != 6 || memcmp(p, "va_dcl", 6) != 0) && + (l != 6 || memcmp(p, "va_end", 6) != 0) && + (l != 7 || memcmp(p, "va_list", 7) != 0) && + (l != 8 || memcmp(p, "va_start", 8) != 0) && + (l != 4 || memcmp(p, "void", 4) != 0) && + (l != 5 || memcmp(p, "while", 5) != 0) && + (l != 3 || memcmp(p, "__P", 3) != 0) && + (l != 8 || memcmp(p, "__FILE__", 8) != 0) && + (l != 8 || memcmp(p, "__LINE__", 8) != 0) && + (l != 8 || memcmp(p, "__STDC__", 8) != 0) + ) + fwrite("x_", 2, 1, stdout); + } + else if (p[l] == '.' && isdigit(p[l + 1])) { + l += 2; + goto decimal; + } + else if (p[l] == '0' && (p[l + 1] == 'x' || p[l + 1] == 'X')) { + l += 2; + while (isxdigit(p[l])) + ++l; + goto integer; + } + else if (isdigit(p[l])) { + ++l; + while (isdigit(p[l])) + ++l; + if (p[l] == '.') { + ++l; + decimal: + while (isdigit(p[l])) + ++l; + if (p[l] == 'E' || p[l] == 'e' || p[l] == 'D' || p[l] == 'd') + goto exponent; + } + else if (p[l] == 'E' || p[l] == 'e' || p[l] == 'D' || p[l] == 'd') { + exponent: + ++l; + if (p[l] == '+' || p[l] == '-') + ++l; + while (isdigit(p[l])) + ++l; + } + else { + integer: + if (p[l] == 'U' || p[l] == 'u') + ++l; + if (p[l] == 'L' || p[l] == 'l') + ++l; + } + } + else if (p[l] == '\'' || p[l] == '"') { + e = p[l++]; + while (p[l]) { + if (p[l++] == e) + break; + if (p[l - 1] == '\\' && p[l]) + ++l; + } + } + else if (p[l] == '/' && p[l + 1] == '*') { + l += 2; + while (p[l] != '*' || p[l + 1] != '/') + if (p[l] == 0) { + fwrite(p, l, 1, stdout); + if (fgets(buf, sizeof(buf), stdin) == 0) + return 0; + p = buf; + l = 0; + } + else + ++l; + l += 2; + } + else + ++l; + fwrite(p, l, 1, stdout); + p += l; + l = 0; + } + } + return 0; +} -- 2.34.1