-/* $Header: a2py.c,v 3.0.1.2 90/10/16 11:30:34 lwall Locked $
+/* $RCSfile: a2py.c,v $$Revision: 4.1 $$Date: 92/08/07 18:29:14 $
*
- * Copyright (c) 1989, Larry Wall
+ * Copyright (c) 1991, Larry Wall
*
- * You may distribute under the terms of the GNU General Public License
- * as specified in the README file that comes with the perl 3.0 kit.
+ * 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 3.0.1.2 90/10/16 11:30:34 lwall
- * patch29: various portability fixes
- *
- * Revision 3.0.1.1 90/08/09 05:48:53 lwall
- * patch19: a2p didn't emit a chop when NF was referenced though split needs it
- *
- * Revision 3.0 89/10/18 15:34:35 lwall
- * 3.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;
+
+int oper0();
+int oper1();
+int oper2();
+int oper3();
+int oper4();
+int oper5();
STR *walk();
-#ifdef MSDOS
+#ifdef OS2
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<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"
register char **env;
{
register STR *str;
- register char *s;
int i;
STR *tmpstr;
break;
default:
fatal("Unrecognized switch: %s\n",argv[0]);
-#ifdef MSDOS
+#ifdef OS2
usage();
#endif
}
/* open script */
if (argv[0] == Nullch) {
-#ifdef MSDOS
+#ifdef OS2
if ( isatty(fileno(stdin)) )
usage();
#endif
/* second pass to produce new program */
tmpstr = walk(0,0,root,&i,P_MIN);
- str = str_make("#!");
- str_cat(str, BIN);
- str_cat(str, "/perl\neval \"exec ");
- str_cat(str, BIN);
- str_cat(str, "/perl -S $0 $*\"\n\
+ str = str_make(STARTPERL);
+ str_cat(str, "\neval 'exec perl -S $0 \"$@\"'\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) {
int idtype;
+int
yylex()
{
register char *s = bufptr;
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);
*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';
*d++ = *s++;
else if (s[1] == '\\')
*d++ = *s++;
+ else if (s[1] == '[')
+ *d++ = *s++;
}
else if (*s == '[') {
*d++ = *s++;
return s;
}
+void
yyerror(s)
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++;
return s;
}
+int
string(ptr,len)
char *ptr;
+int len;
{
int retval = mop;
return retval;
}
+int
oper0(type)
int type;
{
return retval;
}
+int
oper1(type,arg1)
int type;
int arg1;
return retval;
}
+int
oper2(type,arg1,arg2)
int type;
int arg1;
return retval;
}
+int
oper3(type,arg1,arg2,arg3)
int type;
int arg1;
return retval;
}
+int
oper4(type,arg1,arg2,arg3,arg4)
int type;
int arg1;
return retval;
}
+int
oper5(type,arg1,arg2,arg3,arg4,arg5)
int type;
int arg1;
int depth = 0;
+void
dump(branch)
int branch;
{
}
}
+int
bl(arg,maybe)
int arg;
int maybe;
return arg;
}
+void
fixup(str)
STR *str;
{
}
}
+void
putlines(str)
STR *str;
{
d--;
}
if (d > t+3) {
- *d = '\0';
+ char save[2048];
+ strcpy(save, d);
+ *d = '\n';
+ d[1] = '\0';
putone();
putchar('\n');
if (d[-1] != ';' && !(newpos % 4)) {
*t++ = ' ';
newpos += 2;
}
- strcpy(t,d+1);
+ strcpy(t,save+1);
newpos += strlen(t);
d = t + strlen(t);
pos = newpos;
}
}
+void
putone()
{
register char *t;
fputs(tokenbuf,stdout);
}
+int
numary(arg)
int arg;
{
return arg;
}
+int
rememberargs(arg)
int arg;
{
return arg;
}
+int
aryrefarg(arg)
int arg;
{
return arg;
}
+int
fixfargs(name,arg,prevargs)
int name;
int arg;
return numargs;
}
+int
fixrargs(name,arg,prevargs)
char *name;
int arg;
sprintf(tmpbuf,"%s:%d",name,prevargs);
str = hfetch(curarghash,tmpbuf);
- fprintf(stderr,"Looking for %s\n",tmpbuf);
if (str && strEQ(str->str_ptr,"*")) {
if (type == OVAR || type == OSTAR) {
ops[arg].ival &= ~255;
}
return numargs;
}
-