| version 1.5, 2015/08/06 10:01:53 |
version 1.6, 2015/08/08 14:19:42 |
|
|
| * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
| * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
| * |
* |
| * $OpenXM: OpenXM_contrib2/asir2000/parse/cpp.c,v 1.4 2000/12/05 01:24:56 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/parse/cpp.c,v 1.5 2015/08/06 10:01:53 fujimoto Exp $ |
| */ |
*/ |
| #include <stdio.h> |
#include <stdio.h> |
| #include <ctype.h> |
#include <ctype.h> |
| Line 207 void do_at(void) |
|
| Line 207 void do_at(void) |
|
| { if (! in_false_if()) |
{ if (! in_false_if()) |
| { err_head(); |
{ err_head(); |
| fprintf(stderr,"unknown control `%s'\n",w); |
fprintf(stderr,"unknown control `%s'\n",w); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| } |
} |
| } |
} |
| free(w); |
free(w); |
| Line 356 void read_formals(void) |
|
| Line 359 void read_formals(void) |
|
| } |
} |
| } |
} |
| } |
} |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| } |
} |
| } |
} |
| |
|
| Line 401 void do_define(int sharp, int redef) |
|
| Line 407 void do_define(int sharp, int redef) |
|
| if (! mac) |
if (! mac) |
| { err_head(); |
{ err_head(); |
| fprintf(stderr,"missing/illegal macro name\n"); |
fprintf(stderr,"missing/illegal macro name\n"); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| flush_sharp_line(); |
flush_sharp_line(); |
| return; |
return; |
| } |
} |
| Line 411 void do_define(int sharp, int redef) |
|
| Line 420 void do_define(int sharp, int redef) |
|
| if (nargs > 128) |
if (nargs > 128) |
| { err_head(); |
{ err_head(); |
| fprintf(stderr,"too many macro formals, more than 128 ignored\n"); |
fprintf(stderr,"too many macro formals, more than 128 ignored\n"); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| nargs = 128; |
nargs = 128; |
| } |
} |
| } |
} |
| Line 604 void do_dump(void) |
|
| Line 616 void do_dump(void) |
|
| { fprintf(stderr,"\t\t%s\n",incldir[i]); |
{ fprintf(stderr,"\t\t%s\n",incldir[i]); |
| } |
} |
| fprintf(stderr,"\t\t%s\n",cur_incldir); |
fprintf(stderr,"\t\t%s\n",cur_incldir); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| } |
} |
| |
|
| void dump_single(DEF *d) |
void dump_single(DEF *d) |
| Line 630 void dump_single(DEF *d) |
|
| Line 645 void dump_single(DEF *d) |
|
| { putc(*cp,stderr); |
{ putc(*cp,stderr); |
| } |
} |
| } |
} |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| } |
} |
| |
|
| void err_head(void) |
void err_head(void) |
| { |
{ |
| fprintf(stderr,"\"%s\", line %d: ",curfile(),curline()); |
fprintf(stderr,"\"%s\", line %d: ",curfile(),curline()); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| } |
} |
| |
|
| void Check_malloc(char *ptr) |
void Check_malloc(char *ptr) |
| { |
{ |
| if (ptr == 0) |
if (ptr == 0) |
| { fprintf(stderr,"out of memory!\n"); |
{ fprintf(stderr,"out of memory!\n"); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| abort(); |
abort(); |
| } |
} |
| } |
} |
| Line 663 void do_eval(void) |
|
| Line 687 void do_eval(void) |
|
| for (i=strlen(temp)-1;i>=0;i--) |
for (i=strlen(temp)-1;i>=0;i--) |
| { Push(temp[i]); |
{ Push(temp[i]); |
| } |
} |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| } |
} |
| } |
} |
| |
|
| Line 797 void read_actuals(DEF *d) |
|
| Line 824 void read_actuals(DEF *d) |
|
| actlens[i] = 0; |
actlens[i] = 0; |
| } |
} |
| } |
} |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| } |
} |
| |
|
| void expand_def(DEF *d) |
void expand_def(DEF *d) |
| Line 1090 int get_quote_char(void) |
|
| Line 1120 int get_quote_char(void) |
|
| if (c == '\n') |
if (c == '\n') |
| { err_head(); |
{ err_head(); |
| fprintf(stderr,"newline in character constant\n"); |
fprintf(stderr,"newline in character constant\n"); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| return(-1); |
return(-1); |
| } |
} |
| if (c != '\\') |
if (c != '\\') |
| Line 1166 NODE *read_expr_11(void) |
|
| Line 1199 NODE *read_expr_11(void) |
|
| if (c != ')') |
if (c != ')') |
| { err_head(); |
{ err_head(); |
| fprintf(stderr,"expression syntax error -- missing ) supplied\n"); |
fprintf(stderr,"expression syntax error -- missing ) supplied\n"); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| Push(c); |
Push(c); |
| } |
} |
| #ifdef DEBUG_EXPR |
#ifdef DEBUG_EXPR |
| Line 1213 NODE *read_expr_11(void) |
|
| Line 1249 NODE *read_expr_11(void) |
|
| { err_head(); |
{ err_head(); |
| fprintf(stderr,"warning: illegal %sdigit `%c'\n", |
fprintf(stderr,"warning: illegal %sdigit `%c'\n", |
| (base==16)?"hex ":(base==8)?"octal ":"",c); |
(base==16)?"hex ":(base==8)?"octal ":"",c); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| } |
} |
| v = (v * base) + values[d-digits]; |
v = (v * base) + values[d-digits]; |
| c = Get(); |
c = Get(); |
| Line 1235 NODE *read_expr_11(void) |
|
| Line 1274 NODE *read_expr_11(void) |
|
| if (n > 4) |
if (n > 4) |
| { err_head(); |
{ err_head(); |
| fprintf(stderr,"warning: too many characters in character constant\n"); |
fprintf(stderr,"warning: too many characters in character constant\n"); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| } |
} |
| return(newleaf(i)); |
return(newleaf(i)); |
| } |
} |
| Line 1246 NODE *read_expr_11(void) |
|
| Line 1288 NODE *read_expr_11(void) |
|
| if (complain) |
if (complain) |
| { err_head(); |
{ err_head(); |
| fprintf(stderr,"expression syntax error -- number expected\n"); |
fprintf(stderr,"expression syntax error -- number expected\n"); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| } |
} |
| if (isbsymchar(c)) |
if (isbsymchar(c)) |
| { Push(c); |
{ Push(c); |
| Line 1828 NODE *read_expr_(void) |
|
| Line 1873 NODE *read_expr_(void) |
|
| default: |
default: |
| err_head(); |
err_head(); |
| fprintf(stderr,"expression syntax error -- bad operator `%c'\n",c); |
fprintf(stderr,"expression syntax error -- bad operator `%c'\n",c); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| return(l); |
return(l); |
| break; |
break; |
| } |
} |
| Line 1851 NODE *read_expr_p(void) |
|
| Line 1899 NODE *read_expr_p(void) |
|
| if (c != ')') |
if (c != ')') |
| { err_head(); |
{ err_head(); |
| fprintf(stderr,"junk after expression\n"); |
fprintf(stderr,"junk after expression\n"); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| } |
} |
| return(rv); |
return(rv); |
| } |
} |
| Line 1876 int eval_expr(int Sharp, int Complain) |
|
| Line 1927 int eval_expr(int Sharp, int Complain) |
|
| { if (complain) |
{ if (complain) |
| { err_head(); |
{ err_head(); |
| fprintf(stderr,"expression syntax error -- junk after expression\n"); |
fprintf(stderr,"expression syntax error -- junk after expression\n"); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| } |
} |
| while (Get() != d) ; |
while (Get() != d) ; |
| } |
} |
| Line 1981 void do_if(int expr_sharp) |
|
| Line 2035 void do_if(int expr_sharp) |
|
| if (c != '(') |
if (c != '(') |
| { err_head(); |
{ err_head(); |
| fprintf(stderr,"@if must have ()s\n"); |
fprintf(stderr,"@if must have ()s\n"); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| Push(c); |
Push(c); |
| iffalse(); |
iffalse(); |
| #ifdef DEBUG_IF |
#ifdef DEBUG_IF |
| Line 2177 void do_else(int expr_sharp) |
|
| Line 2234 void do_else(int expr_sharp) |
|
| #endif |
#endif |
| err_head(); |
err_head(); |
| fprintf(stderr,"if-less else\n"); |
fprintf(stderr,"if-less else\n"); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| } |
} |
| } |
} |
| else |
else |
| Line 2232 void do_elif(int expr_sharp) |
|
| Line 2292 void do_elif(int expr_sharp) |
|
| if (ifstack == 0) |
if (ifstack == 0) |
| { err_head(); |
{ err_head(); |
| fprintf(stderr,"if-less elif converted to normal if\n"); |
fprintf(stderr,"if-less elif converted to normal if\n"); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| iffalse(); |
iffalse(); |
| } |
} |
| if (n_skipped_ifs > 0) |
if (n_skipped_ifs > 0) |
| Line 2256 void do_elif(int expr_sharp) |
|
| Line 2319 void do_elif(int expr_sharp) |
|
| if (c != '(') |
if (c != '(') |
| { err_head(); |
{ err_head(); |
| fprintf(stderr,"@elif must have ()s\n"); |
fprintf(stderr,"@elif must have ()s\n"); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| Push(c); |
Push(c); |
| ifstack->condstate = IFSTATE_STAYFALSE; |
ifstack->condstate = IFSTATE_STAYFALSE; |
| #ifdef DEBUG_IF |
#ifdef DEBUG_IF |
| Line 2338 void do_endif(int expr_sharp) |
|
| Line 2404 void do_endif(int expr_sharp) |
|
| else |
else |
| { err_head(); |
{ err_head(); |
| fprintf(stderr,"if-less endif\n"); |
fprintf(stderr,"if-less endif\n"); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| #ifdef DEBUG_IF |
#ifdef DEBUG_IF |
| if (debugging) |
if (debugging) |
| { outputc('>'); |
{ outputc('>'); |
| Line 2470 void do_include(int expr_sharp) |
|
| Line 2539 void do_include(int expr_sharp) |
|
| err_head(); |
err_head(); |
| fprintf(stderr,"warning: unterminated %cinclude filename\n", |
fprintf(stderr,"warning: unterminated %cinclude filename\n", |
| sharp?'#':'@'); |
sharp?'#':'@'); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| } |
} |
| if (c == '"') |
if (c == '"') |
| { break; |
{ break; |
| Line 2490 void do_include(int expr_sharp) |
|
| Line 2562 void do_include(int expr_sharp) |
|
| err_head(); |
err_head(); |
| fprintf(stderr,"warning: unterminated %cinclude filename\n", |
fprintf(stderr,"warning: unterminated %cinclude filename\n", |
| sharp?'#':'@'); |
sharp?'#':'@'); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| } |
} |
| if (c == '>') |
if (c == '>') |
| { break; |
{ break; |
| Line 2505 void do_include(int expr_sharp) |
|
| Line 2580 void do_include(int expr_sharp) |
|
| { free(accum_result(acc)); |
{ free(accum_result(acc)); |
| err_head(); |
err_head(); |
| fprintf(stderr,"illegal %cinclude filename delimiter\n",sharp?'#':'@'); |
fprintf(stderr,"illegal %cinclude filename delimiter\n",sharp?'#':'@'); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| } |
} |
| } |
} |
| |
|
| Line 2563 void read_include_file(char *name, int dohere, int exp |
|
| Line 2641 void read_include_file(char *name, int dohere, int exp |
|
| if (f == NULL) |
if (f == NULL) |
| { err_head(); |
{ err_head(); |
| fprintf(stderr,"can't find include file %s\n",name); |
fprintf(stderr,"can't find include file %s\n",name); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| free(name); |
free(name); |
| return; |
return; |
| } |
} |
| Line 2779 void Push(char c) |
|
| Line 2860 void Push(char c) |
|
| { |
{ |
| if (cur_npushed > MAX_PUSHBACK) |
if (cur_npushed > MAX_PUSHBACK) |
| { fprintf(stderr,"too much pushback\n"); |
{ fprintf(stderr,"too much pushback\n"); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| cur_npushed = 0; |
cur_npushed = 0; |
| } |
} |
| PUSH() = c; |
PUSH() = c; |
| Line 3157 void mark_file_ending(void) |
|
| Line 3241 void mark_file_ending(void) |
|
| } |
} |
| else if (m->nincs <= 0) |
else if (m->nincs <= 0) |
| { fprintf(stderr,"INTERNAL BUG: nincs<0 in mark_file_ending\n"); |
{ fprintf(stderr,"INTERNAL BUG: nincs<0 in mark_file_ending\n"); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| abort(); |
abort(); |
| } |
} |
| else |
else |
| Line 3619 void cpp_main(int ac, char **av) |
|
| Line 3706 void cpp_main(int ac, char **av) |
|
| } |
} |
| } |
} |
| } |
} |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| } |
} |
| |
|
| void do_pragma(void) |
void do_pragma(void) |
| Line 3678 void do_set(void) |
|
| Line 3768 void do_set(void) |
|
| check_malloc(cp); |
check_malloc(cp); |
| define(mac,-1,(unsigned char *)cp,DEF_DEFINE); |
define(mac,-1,(unsigned char *)cp,DEF_DEFINE); |
| } |
} |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| free(mac); |
free(mac); |
| } |
} |
| |
|
| Line 3741 void do_sharp(void) |
|
| Line 3834 void do_sharp(void) |
|
| flush_sharp_line(); |
flush_sharp_line(); |
| } |
} |
| } |
} |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| maybe_print('\n'); |
maybe_print('\n'); |
| free(w); |
free(w); |
| } |
} |
| Line 3909 void define(char *name, int nargs, unsigned char *repl |
|
| Line 4005 void define(char *name, int nargs, unsigned char *repl |
|
| { if ( (nargs != d->nargs) || strcmp((char *)repl,(char *)d->repl) ) |
{ if ( (nargs != d->nargs) || strcmp((char *)repl,(char *)d->repl) ) |
| { err_head(); |
{ err_head(); |
| fprintf(stderr,"%s redefined\n",n); |
fprintf(stderr,"%s redefined\n",n); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| } |
} |
| free((char *)d->repl); |
free((char *)d->repl); |
| free(d->name); |
free(d->name); |
| Line 4539 void do_undef(int expr_sharp) |
|
| Line 4638 void do_undef(int expr_sharp) |
|
| if (! mac) |
if (! mac) |
| { err_head(); |
{ err_head(); |
| fprintf(stderr,"missing/illegal macro name\n"); |
fprintf(stderr,"missing/illegal macro name\n"); |
| |
#if defined(__MINGW32__) || defined(__MINGW64__) |
| |
fflush(stderr); |
| |
#endif |
| } |
} |
| else |
else |
| { if (undef(mac)) |
{ if (undef(mac)) |