version 1.2, 2000/08/21 08:31:46 |
version 1.6, 2015/08/08 14:19:42 |
|
|
* shall be made on your publication or presentation in any form of the |
* shall be made on your publication or presentation in any form of the |
* results obtained by use of the SOFTWARE. |
* results obtained by use of the SOFTWARE. |
* (4) In the event that you modify the SOFTWARE, you shall notify FLL by |
* (4) In the event that you modify the SOFTWARE, you shall notify FLL by |
* e-mail at risa-admin@flab.fujitsu.co.jp of the detailed specification |
* e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification |
* for such modification or the source code of the modified part of the |
* for such modification or the source code of the modified part of the |
* SOFTWARE. |
* SOFTWARE. |
* |
* |
|
|
* 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.1.1.1 1999/12/03 07:39:12 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/parse/cpp.c,v 1.5 2015/08/06 10:01:53 fujimoto Exp $ |
*/ |
*/ |
#if defined(__MWERKS__) |
|
#define THINK_C |
|
#endif |
|
|
|
#include <stdio.h> |
#include <stdio.h> |
#include <ctype.h> |
#include <ctype.h> |
#include <setjmp.h> |
#include <setjmp.h> |
|
|
#include "unctrl.h" |
#include "unctrl.h" |
#endif |
#endif |
|
|
#if defined(THINK_C) |
|
#include <string.h> |
|
|
|
int define(char *,int,unsigned char *,int); |
|
void Bcopy(char *,char *,int); |
|
#endif |
|
|
|
|
|
#include "cpp.h" |
#include "cpp.h" |
|
|
char *init_accum(void) |
char *init_accum(void) |
Line 218 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 367 void read_formals(void) |
|
Line 359 void read_formals(void) |
|
} |
} |
} |
} |
} |
} |
|
#if defined(__MINGW32__) || defined(__MINGW64__) |
|
fflush(stderr); |
|
#endif |
} |
} |
} |
} |
|
|
Line 412 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 422 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 615 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 641 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 674 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 808 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 1101 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 1177 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 1224 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 1246 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 1257 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 1839 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 1862 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 1887 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 1992 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 2188 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 2243 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 2267 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 2349 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 2481 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 2501 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 2516 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 |
} |
} |
} |
} |
|
|
#if defined(THINK_C) |
|
#if defined(DELIM) |
|
#undef DELIM |
|
#endif |
|
#define DELIM ':' |
|
#endif |
|
|
|
#if defined(SYSV) |
#if defined(SYSV) |
#else |
#else |
#if defined(DELIM) |
#if defined(DELIM) |
Line 2534 void do_include(int expr_sharp) |
|
Line 2594 void do_include(int expr_sharp) |
|
#define DELIM '/' |
#define DELIM '/' |
#endif |
#endif |
|
|
#if defined(VISUAL) |
#if defined(VISUAL) || defined(__MINGW32__) || defined(__MINGW64__) |
#if defined(DELIM) |
#if defined(DELIM) |
#undef DELIM |
#undef DELIM |
#endif |
#endif |
Line 2581 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 2797 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 3175 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 3637 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 3696 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 3759 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 3927 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 4557 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)) |