X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=x2p%2Fa2py.c;h=3976c860c5ad3f5d7334e6c87ecb5f951a6d90c9;hb=189d1e8d580baf589b8a569f3f4af6e73eba632f;hp=46ec604c0662d5372c1b2b899c3c9f4ad8878258;hpb=9607fc9c489d4095e3baa795d7ead7acba96137d;p=p5sagit%2Fp5-mst-13.2.git diff --git a/x2p/a2py.c b/x2p/a2py.c index 46ec604..3976c86 100644 --- a/x2p/a2py.c +++ b/x2p/a2py.c @@ -8,7 +8,10 @@ * $Log: a2py.c,v $ */ -#ifdef OS2 +#if defined(OS2) || defined(WIN32) +#if defined(WIN32) +#include +#endif #include "../patchlevel.h" #endif #include "util.h" @@ -18,19 +21,21 @@ char *myname; int checkers = 0; -int oper0(); -int oper1(); -int oper2(); -int oper3(); -int oper4(); -int oper5(); -STR *walk(); +int oper0(int type); +int oper1(int type, int arg1); +int oper2(int type, int arg1, int arg2); +int oper3(int type, int arg1, int arg2, int arg3); +int oper4(int type, int arg1, int arg2, int arg3, int arg4); +int oper5(int type, int arg1, int arg2, int arg3, int arg4, int arg5); +STR *walk(int useval, int level, register int node, int *numericptr, int minprec); + +#if defined(OS2) || defined(WIN32) +static void usage(void); -#ifdef OS2 static void usage() { - printf("\nThis is the AWK to PERL translator, version 5.0, patchlevel %d\n", PATCHLEVEL); + printf("\nThis is the AWK to PERL translator, revision %d.0, version %d\n", PERL_REVISION, PERL_VERSION); printf("\nUsage: %s [-D] [-F] [-n] [-] filename\n", myname); printf("\n -D sets debugging flags." "\n -F the awk script to translate is always invoked with" @@ -44,10 +49,7 @@ usage() #endif int -main(argc,argv,env) -register int argc; -register char **argv; -register char **env; +main(register int argc, register char **argv, register char **env) { register STR *str; int i; @@ -64,7 +66,7 @@ register char **env; #ifdef DEBUGGING case 'D': debug = atoi(argv[0]+2); -#ifdef YYDEBUG +#if YYDEBUG yydebug = (debug & 1); #endif break; @@ -80,15 +82,20 @@ register char **env; case 'n': namelist = savestr(argv[0]+2); break; + case 'o': + old_awk = TRUE; + break; case '-': argc--,argv++; goto switch_end; case 0: break; default: - fatal("Unrecognized switch: %s\n",argv[0]); -#ifdef OS2 +#if defined(OS2) || defined(WIN32) + fprintf(stderr, "Unrecognized switch: %s\n",argv[0]); usage(); +#else + fatal("Unrecognized switch: %s\n",argv[0]); #endif } } @@ -97,7 +104,7 @@ register char **env; /* open script */ if (argv[0] == Nullch) { -#ifdef OS2 +#if defined(OS2) || defined(WIN32) if ( isatty(fileno(stdin)) ) usage(); #endif @@ -197,14 +204,14 @@ register char **env; int idtype; int -yylex() +yylex(void) { register char *s = bufptr; register char *d; register int tmp; retry: -#ifdef YYDEBUG +#if YYDEBUG if (yydebug) if (strchr(s,'\n')) fprintf(stderr,"Tokener at %s",s); @@ -266,7 +273,11 @@ yylex() case ':': tmp = *s++; XOP(tmp); +#ifdef EBCDIC + case 7: +#else case 127: +#endif s++; XTERM('}'); case '}': @@ -694,8 +705,15 @@ yylex() } if (strEQ(d,"sub")) XTERM(SUB); - if (strEQ(d,"sprintf")) - XTERM(SPRINTF); + if (strEQ(d,"sprintf")) { + /* In old awk, { print sprintf("str%sg"),"in" } prints + * "string"; in new awk, "in" is not considered an argument to + * sprintf, so the statement breaks. To support both, the + * grammar treats arguments to SPRINTF_OLD like old awk, + * SPRINTF_NEW like new. Here we return the appropriate one. + */ + XTERM(old_awk ? SPRINTF_OLD : SPRINTF_NEW); + } if (strEQ(d,"sqrt")) { yylval = OSQRT; XTERM(FUN1); @@ -791,8 +809,7 @@ yylex() } char * -scanpat(s) -register char *s; +scanpat(register char *s) { register char *d; @@ -837,16 +854,14 @@ register char *s; } void -yyerror(s) -char *s; +yyerror(char *s) { fprintf(stderr,"%s in file %s at line %d\n", s,filename,line); } char * -scannum(s) -register char *s; +scannum(register char *s) { register char *d; @@ -882,16 +897,14 @@ register char *s; } int -string(ptr,len) -char *ptr; -int len; +string(char *ptr, int len) { int retval = mop; ops[mop++].ival = OSTRING + (1<<8); if (!len) len = strlen(ptr); - ops[mop].cval = safemalloc(len+1); + ops[mop].cval = (char *) safemalloc(len+1); strncpy(ops[mop].cval,ptr,len); ops[mop++].cval[len] = '\0'; if (mop >= OPSMAX) @@ -900,8 +913,7 @@ int len; } int -oper0(type) -int type; +oper0(int type) { int retval = mop; @@ -914,9 +926,7 @@ int type; } int -oper1(type,arg1) -int type; -int arg1; +oper1(int type, int arg1) { int retval = mop; @@ -930,10 +940,7 @@ int arg1; } int -oper2(type,arg1,arg2) -int type; -int arg1; -int arg2; +oper2(int type, int arg1, int arg2) { int retval = mop; @@ -948,11 +955,7 @@ int arg2; } int -oper3(type,arg1,arg2,arg3) -int type; -int arg1; -int arg2; -int arg3; +oper3(int type, int arg1, int arg2, int arg3) { int retval = mop; @@ -968,12 +971,7 @@ int arg3; } int -oper4(type,arg1,arg2,arg3,arg4) -int type; -int arg1; -int arg2; -int arg3; -int arg4; +oper4(int type, int arg1, int arg2, int arg3, int arg4) { int retval = mop; @@ -990,13 +988,7 @@ int arg4; } int -oper5(type,arg1,arg2,arg3,arg4,arg5) -int type; -int arg1; -int arg2; -int arg3; -int arg4; -int arg5; +oper5(int type, int arg1, int arg2, int arg3, int arg4, int arg5) { int retval = mop; @@ -1016,8 +1008,7 @@ int arg5; int depth = 0; void -dump(branch) -int branch; +dump(int branch) { register int type; register int len; @@ -1044,9 +1035,7 @@ int branch; } int -bl(arg,maybe) -int arg; -int maybe; +bl(int arg, int maybe) { if (!arg) return 0; @@ -1059,8 +1048,7 @@ int maybe; } void -fixup(str) -STR *str; +fixup(STR *str) { register char *s; register char *t; @@ -1085,8 +1073,7 @@ STR *str; } void -putlines(str) -STR *str; +putlines(STR *str) { register char *d, *s, *t, *e; register int pos, newpos; @@ -1162,7 +1149,7 @@ STR *str; } void -putone() +putone(void) { register char *t; @@ -1185,8 +1172,7 @@ putone() } int -numary(arg) -int arg; +numary(int arg) { STR *key; int dummy; @@ -1200,8 +1186,7 @@ int arg; } int -rememberargs(arg) -int arg; +rememberargs(int arg) { int type; STR *str; @@ -1223,8 +1208,7 @@ int arg; } int -aryrefarg(arg) -int arg; +aryrefarg(int arg) { int type = ops[arg].ival & 255; STR *str; @@ -1238,10 +1222,7 @@ int arg; } int -fixfargs(name,arg,prevargs) -int name; -int arg; -int prevargs; +fixfargs(int name, int arg, int prevargs) { int type; STR *str; @@ -1277,10 +1258,7 @@ int prevargs; } int -fixrargs(name,arg,prevargs) -char *name; -int arg; -int prevargs; +fixrargs(char *name, int arg, int prevargs) { int type; STR *str; @@ -1294,10 +1272,10 @@ int prevargs; numargs = fixrargs(name,ops[arg+3].ival,numargs); } else { - char tmpbuf[128]; - + char *tmpbuf = (char *) safemalloc(strlen(name) + (sizeof(prevargs) * 3) + 5); sprintf(tmpbuf,"%s:%d",name,prevargs); str = hfetch(curarghash,tmpbuf); + safefree(tmpbuf); if (str && strEQ(str->str_ptr,"*")) { if (type == OVAR || type == OSTAR) { ops[arg].ival &= ~255;