X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=x2p%2Fa2py.c;h=202d5921e011d2ce724d9465e795ba642db88f69;hb=51cf62d8ec31d46fecbc8564c5b48c17f5776f7f;hp=b2ac121615162f383a6116463561280320eb6012;hpb=2b317908ea5309ab202d1cdbadccfdf42d10e2b1;p=p5sagit%2Fp5-mst-13.2.git diff --git a/x2p/a2py.c b/x2p/a2py.c index b2ac121..202d592 100644 --- a/x2p/a2py.c +++ b/x2p/a2py.c @@ -1,35 +1,36 @@ -/* $RCSfile: a2py.c,v $$Revision: 4.0.1.1 $$Date: 91/06/07 12:12:59 $ +/* $RCSfile: a2py.c,v $$Revision: 4.1 $$Date: 92/08/07 18:29:14 $ * - * Copyright (c) 1991, Larry Wall + * Copyright (c) 1991-1997, Larry Wall * * You may distribute under the terms of either the GNU General Public * License or the Artistic License, as specified in the README file. * * $Log: a2py.c,v $ - * Revision 4.0.1.1 91/06/07 12:12:59 lwall - * patch4: new copyright notice - * - * Revision 4.0 91/03/20 01:57:26 lwall - * 4.0 baseline. - * */ -#ifdef MSDOS -#include "../patchlev.h" +#ifdef OS2 +#include "../patchlevel.h" #endif #include "util.h" -char *index(); char *filename; char *myname; int checkers = 0; -STR *walk(); -#ifdef MSDOS +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); + +#ifdef OS2 +static void usage() { - printf("\nThis is the AWK to PERL translator, version 3.0, patchlevel %d\n", PATCHLEVEL); + printf("\nThis is the AWK to PERL translator, version 5.0, patchlevel %d\n", PATCHLEVEL); 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" @@ -41,13 +42,11 @@ usage() exit(1); } #endif -main(argc,argv,env) -register int argc; -register char **argv; -register char **env; + +int +main(register int argc, register char **argv, register char **env) { register STR *str; - register char *s; int i; STR *tmpstr; @@ -78,6 +77,9 @@ register char **env; case 'n': namelist = savestr(argv[0]+2); break; + case 'o': + old_awk = TRUE; + break; case '-': argc--,argv++; goto switch_end; @@ -85,7 +87,7 @@ register char **env; break; default: fatal("Unrecognized switch: %s\n",argv[0]); -#ifdef MSDOS +#ifdef OS2 usage(); #endif } @@ -95,7 +97,7 @@ register char **env; /* open script */ if (argv[0] == Nullch) { -#ifdef MSDOS +#ifdef OS2 if ( isatty(fileno(stdin)) ) usage(); #endif @@ -154,16 +156,15 @@ register char **env; /* second pass to produce new program */ tmpstr = walk(0,0,root,&i,P_MIN); - str = str_make("#!"); + str = str_make(STARTPERL); + str_cat(str, "\neval 'exec "); str_cat(str, BIN); - str_cat(str, "/perl\neval \"exec "); - str_cat(str, BIN); - str_cat(str, "/perl -S $0 $*\"\n\ + str_cat(str, "/perl -S $0 ${1+\"$@\"}'\n\ if $running_under_some_shell;\n\ # this emulates #! processing on NIH machines.\n\ # (remove #! line above if indigestible)\n\n"); str_cat(str, - "eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_]+=)(.*)/ && shift;\n"); + "eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_0-9]+=)(.*)/ && shift;\n"); str_cat(str, " # process any FOO=bar switches\n\n"); if (do_opens && opens) { @@ -195,7 +196,8 @@ register char **env; int idtype; -yylex() +int +yylex(void) { register char *s = bufptr; register char *d; @@ -204,7 +206,7 @@ yylex() retry: #ifdef YYDEBUG if (yydebug) - if (index(s,'\n')) + if (strchr(s,'\n')) fprintf(stderr,"Tokener at %s",s); else fprintf(stderr,"Tokener at %s\n",s); @@ -216,6 +218,12 @@ yylex() *s++,filename,line); goto retry; case '\\': + s++; + if (*s && *s != '\n') { + yyerror("Ignoring spurious backslash"); + goto retry; + } + /*FALLSTHROUGH*/ case 0: s = str_get(linestr); *s = '\0'; @@ -783,8 +791,7 @@ yylex() } char * -scanpat(s) -register char *s; +scanpat(register char *s) { register char *d; @@ -802,6 +809,8 @@ register char *s; *d++ = *s++; else if (s[1] == '\\') *d++ = *s++; + else if (s[1] == '[') + *d++ = *s++; } else if (*s == '[') { *d++ = *s++; @@ -826,16 +835,15 @@ register char *s; return s; } -yyerror(s) -char *s; +void +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; @@ -846,13 +854,17 @@ register char *s; while (isdigit(*s)) { *d++ = *s++; } - if (*s == '.' && index("0123456789eE",s[1])) { - *d++ = *s++; - while (isdigit(*s)) { + if (*s == '.') { + if (isdigit(s[1])) { *d++ = *s++; + while (isdigit(*s)) { + *d++ = *s++; + } } + else + s++; } - if (index("eE",*s) && index("+-0123456789",s[1])) { + if (strchr("eE",*s) && strchr("+-0123456789",s[1])) { *d++ = *s++; if (*s == '+' || *s == '-') *d++ = *s++; @@ -866,15 +878,15 @@ register char *s; return s; } -string(ptr,len) -char *ptr; +int +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) @@ -882,8 +894,8 @@ char *ptr; return retval; } -oper0(type) -int type; +int +oper0(int type) { int retval = mop; @@ -895,9 +907,8 @@ int type; return retval; } -oper1(type,arg1) -int type; -int arg1; +int +oper1(int type, int arg1) { int retval = mop; @@ -910,10 +921,8 @@ int arg1; return retval; } -oper2(type,arg1,arg2) -int type; -int arg1; -int arg2; +int +oper2(int type, int arg1, int arg2) { int retval = mop; @@ -927,11 +936,8 @@ int arg2; return retval; } -oper3(type,arg1,arg2,arg3) -int type; -int arg1; -int arg2; -int arg3; +int +oper3(int type, int arg1, int arg2, int arg3) { int retval = mop; @@ -946,12 +952,8 @@ int arg3; return retval; } -oper4(type,arg1,arg2,arg3,arg4) -int type; -int arg1; -int arg2; -int arg3; -int arg4; +int +oper4(int type, int arg1, int arg2, int arg3, int arg4) { int retval = mop; @@ -967,13 +969,8 @@ int arg4; return retval; } -oper5(type,arg1,arg2,arg3,arg4,arg5) -int type; -int arg1; -int arg2; -int arg3; -int arg4; -int arg5; +int +oper5(int type, int arg1, int arg2, int arg3, int arg4, int arg5) { int retval = mop; @@ -992,8 +989,8 @@ int arg5; int depth = 0; -dump(branch) -int branch; +void +dump(int branch) { register int type; register int len; @@ -1019,9 +1016,8 @@ int branch; } } -bl(arg,maybe) -int arg; -int maybe; +int +bl(int arg, int maybe) { if (!arg) return 0; @@ -1033,8 +1029,8 @@ int maybe; return arg; } -fixup(str) -STR *str; +void +fixup(STR *str) { register char *s; register char *t; @@ -1058,8 +1054,8 @@ STR *str; } } -putlines(str) -STR *str; +void +putlines(STR *str) { register char *d, *s, *t, *e; register int pos, newpos; @@ -1134,7 +1130,8 @@ STR *str; } } -putone() +void +putone(void) { register char *t; @@ -1156,8 +1153,8 @@ putone() fputs(tokenbuf,stdout); } -numary(arg) -int arg; +int +numary(int arg) { STR *key; int dummy; @@ -1170,8 +1167,8 @@ int arg; return arg; } -rememberargs(arg) -int arg; +int +rememberargs(int arg) { int type; STR *str; @@ -1192,8 +1189,8 @@ int arg; return arg; } -aryrefarg(arg) -int arg; +int +aryrefarg(int arg) { int type = ops[arg].ival & 255; STR *str; @@ -1206,10 +1203,8 @@ int arg; return arg; } -fixfargs(name,arg,prevargs) -int name; -int arg; -int prevargs; +int +fixfargs(int name, int arg, int prevargs) { int type; STR *str; @@ -1244,10 +1239,8 @@ int prevargs; return numargs; } -fixrargs(name,arg,prevargs) -char *name; -int arg; -int prevargs; +int +fixrargs(char *name, int arg, int prevargs) { int type; STR *str; @@ -1261,11 +1254,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); - fprintf(stderr,"Looking for %s\n",tmpbuf); + safefree(tmpbuf); if (str && strEQ(str->str_ptr,"*")) { if (type == OVAR || type == OSTAR) { ops[arg].ival &= ~255; @@ -1279,4 +1271,3 @@ int prevargs; } return numargs; } -