* $Log: a2py.c,v $
*/
-#ifdef OS2
+#if defined(OS2) || defined(WIN32)
+#if defined(WIN32)
+#include <io.h>
+#endif
#include "../patchlevel.h"
#endif
#include "util.h"
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<number>] [-F<char>] [-n<fieldlist>] [-<number>] filename\n", myname);
printf("\n -D<number> sets debugging flags."
"\n -F<character> the awk script to translate is always invoked with"
#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;
#ifdef DEBUGGING
case 'D':
debug = atoi(argv[0]+2);
-#ifdef YYDEBUG
+#if YYDEBUG
yydebug = (debug & 1);
#endif
break;
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
}
}
/* open script */
if (argv[0] == Nullch) {
-#ifdef OS2
+#if defined(OS2) || defined(WIN32)
if ( isatty(fileno(stdin)) )
usage();
#endif
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);
case ':':
tmp = *s++;
XOP(tmp);
+#ifdef EBCDIC
+ case 7:
+#else
case 127:
+#endif
s++;
XTERM('}');
case '}':
}
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);
}
char *
-scanpat(s)
-register char *s;
+scanpat(register char *s)
{
register char *d;
}
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;
}
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)
}
int
-oper0(type)
-int type;
+oper0(int type)
{
int retval = mop;
}
int
-oper1(type,arg1)
-int type;
-int arg1;
+oper1(int type, int arg1)
{
int retval = mop;
}
int
-oper2(type,arg1,arg2)
-int type;
-int arg1;
-int arg2;
+oper2(int type, int arg1, int arg2)
{
int retval = mop;
}
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;
}
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;
}
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;
int depth = 0;
void
-dump(branch)
-int branch;
+dump(int branch)
{
register int type;
register int len;
}
int
-bl(arg,maybe)
-int arg;
-int maybe;
+bl(int arg, int maybe)
{
if (!arg)
return 0;
}
void
-fixup(str)
-STR *str;
+fixup(STR *str)
{
register char *s;
register char *t;
}
void
-putlines(str)
-STR *str;
+putlines(STR *str)
{
register char *d, *s, *t, *e;
register int pos, newpos;
}
void
-putone()
+putone(void)
{
register char *t;
}
int
-numary(arg)
-int arg;
+numary(int arg)
{
STR *key;
int dummy;
}
int
-rememberargs(arg)
-int arg;
+rememberargs(int arg)
{
int type;
STR *str;
}
int
-aryrefarg(arg)
-int arg;
+aryrefarg(int arg)
{
int type = ops[arg].ival & 255;
STR *str;
}
int
-fixfargs(name,arg,prevargs)
-int name;
-int arg;
-int prevargs;
+fixfargs(int name, int arg, int prevargs)
{
int type;
STR *str;
}
int
-fixrargs(name,arg,prevargs)
-char *name;
-int arg;
-int prevargs;
+fixrargs(char *name, int arg, int prevargs)
{
int type;
STR *str;
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;