[win32] various tweaks to build support (NOTE: meant for 5.004_57)
[p5sagit/p5-mst-13.2.git] / x2p / a2py.c
index f404c1a..fefa81d 100644 (file)
@@ -1,6 +1,6 @@
 /* $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.
@@ -8,19 +8,28 @@
  * $Log:       a2py.c,v $
  */
 
-#ifdef OS2
+#if defined(OS2) || defined(WIN32)
 #include "../patchlevel.h"
 #endif
 #include "util.h"
-char *strchr();
 
 char *filename;
 char *myname;
 
 int checkers = 0;
-STR *walk();
 
-#ifdef OS2
+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);
+
+static void
 usage()
 {
     printf("\nThis is the AWK to PERL translator, version 5.0, patchlevel %d\n", PATCHLEVEL);
@@ -35,10 +44,9 @@ 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;
     int i;
@@ -71,15 +79,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
        }
     }
@@ -88,7 +101,7 @@ register char **env;
     /* open script */
 
     if (argv[0] == Nullch) {
-#ifdef OS2
+#if defined(OS2) || defined(WIN32)
        if ( isatty(fileno(stdin)) )
            usage();
 #endif
@@ -147,11 +160,10 @@ 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");
@@ -188,7 +200,8 @@ register char **env;
 
 int idtype;
 
-yylex()
+int
+yylex(void)
 {
     register char *s = bufptr;
     register char *d;
@@ -782,8 +795,7 @@ yylex()
 }
 
 char *
-scanpat(s)
-register char *s;
+scanpat(register char *s)
 {
     register char *d;
 
@@ -828,16 +840,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;
 
@@ -872,15 +882,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)
@@ -888,8 +898,8 @@ char *ptr;
     return retval;
 }
 
-oper0(type)
-int type;
+int
+oper0(int type)
 {
     int retval = mop;
 
@@ -901,9 +911,8 @@ int type;
     return retval;
 }
 
-oper1(type,arg1)
-int type;
-int arg1;
+int
+oper1(int type, int arg1)
 {
     int retval = mop;
 
@@ -916,10 +925,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;
 
@@ -933,11 +940,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;
 
@@ -952,12 +956,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;
 
@@ -973,13 +973,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;
 
@@ -999,8 +994,7 @@ int arg5;
 int depth = 0;
 
 void
-dump(branch)
-int branch;
+dump(int branch)
 {
     register int type;
     register int len;
@@ -1026,9 +1020,8 @@ int branch;
     }
 }
 
-bl(arg,maybe)
-int arg;
-int maybe;
+int
+bl(int arg, int maybe)
 {
     if (!arg)
        return 0;
@@ -1041,8 +1034,7 @@ int maybe;
 }
 
 void
-fixup(str)
-STR *str;
+fixup(STR *str)
 {
     register char *s;
     register char *t;
@@ -1067,8 +1059,7 @@ STR *str;
 }
 
 void
-putlines(str)
-STR *str;
+putlines(STR *str)
 {
     register char *d, *s, *t, *e;
     register int pos, newpos;
@@ -1144,7 +1135,7 @@ STR *str;
 }
 
 void
-putone()
+putone(void)
 {
     register char *t;
 
@@ -1166,8 +1157,8 @@ putone()
     fputs(tokenbuf,stdout);
 }
 
-numary(arg)
-int arg;
+int
+numary(int arg)
 {
     STR *key;
     int dummy;
@@ -1180,8 +1171,8 @@ int arg;
     return arg;
 }
 
-rememberargs(arg)
-int arg;
+int
+rememberargs(int arg)
 {
     int type;
     STR *str;
@@ -1202,8 +1193,8 @@ int arg;
     return arg;
 }
 
-aryrefarg(arg)
-int arg;
+int
+aryrefarg(int arg)
 {
     int type = ops[arg].ival & 255;
     STR *str;
@@ -1216,10 +1207,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;
@@ -1254,10 +1243,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;
@@ -1271,10 +1258,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;