-/* $RCSfile: a2py.c,v $$Revision: 4.1 $$Date: 92/08/07 18:29:14 $
+/* a2py.c
*
- * Copyright (c) 1991-1997, Larry Wall
+ * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+ * 2000, 2001, 2002, by Larry Wall and others
*
* 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 $
*/
-#if defined(OS2) || defined(WIN32)
+#if defined(OS2) || defined(WIN32) || defined(NETWARE)
#if defined(WIN32)
#include <io.h>
#endif
+#if defined(NETWARE)
+#include "../netware/clibstuf.h"
+#endif
#include "../patchlevel.h"
#endif
#include "util.h"
-char *filename;
-char *myname;
+const char *filename;
+const char *myname;
int checkers = 0;
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 NETWARE
+char *savestr(char *str);
+char *cpy2(register char *to, register char *from, register int delim);
+#endif
-#if defined(OS2) || defined(WIN32)
+#if defined(OS2) || defined(WIN32) || defined(NETWARE)
static void usage(void);
static void
}
#endif
+#ifdef __osf__
+#pragma message disable (mainparm) /* We have the envp in main(). */
+#endif
+
int
-main(register int argc, register char **argv, register char **env)
+main(register int argc, register const char **argv, register const char **env)
{
register STR *str;
int i;
STR *tmpstr;
+ /* char *namelist; */
+
+ #ifdef NETWARE
+ fnInitGpfGlobals(); /* For importing the CLIB calls in place of Watcom calls */
+ #endif /* NETWARE */
myname = argv[0];
linestr = str_new(80);
case 0:
break;
default:
-#if defined(OS2) || defined(WIN32)
+#if defined(OS2) || defined(WIN32) || defined(NETWARE)
fprintf(stderr, "Unrecognized switch: %s\n",argv[0]);
usage();
#else
/* open script */
- if (argv[0] == Nullch) {
-#if defined(OS2) || defined(WIN32)
+ if (argv[0] == NULL) {
+#if defined(OS2) || defined(WIN32) || defined(NETWARE)
if ( isatty(fileno(stdin)) )
usage();
#endif
}
filename = savestr(argv[0]);
- filename = savestr(argv[0]);
if (strEQ(filename,"-"))
argv[0] = "";
if (!*argv[0])
rsfp = stdin;
else
rsfp = fopen(argv[0],"r");
- if (rsfp == Nullfp)
+ if (rsfp == NULL)
fatal("Awk script \"%s\" doesn't seem to exist.\n",filename);
/* init tokener */
"The operation I've selected may be wrong for the operand types.\n");
}
exit(0);
+ /* by ANSI specs return is needed. This also shuts up VC++ and his warnings */
+ return(0);
}
#define RETURN(retval) return (bufptr = s,retval)
if (!rsfp)
RETURN(0);
line++;
- if ((s = str_gets(linestr, rsfp)) == Nullch) {
+ if ((s = str_gets(linestr, rsfp)) == NULL) {
if (rsfp != stdin)
fclose(rsfp);
- rsfp = Nullfp;
+ rsfp = NULL;
s = str_get(linestr);
RETURN(0);
}
maxfld = tmp;
XOP(FIELD);
}
- split_to_array = set_array_base = TRUE;
+ for (d = s; isALPHA(*s) || isDIGIT(*s) || *s == '_'; )
+ s++;
+ split_to_array = TRUE;
+ if (d != s)
+ {
+ yylval = string(d,s-d);
+ XTERM(SVFIELD);
+ }
XOP(VFIELD);
case '/': /* may either be division or pattern */
case 'a': case 'A':
SNARFWORD;
- if (strEQ(d,"ARGC"))
- set_array_base = TRUE;
if (strEQ(d,"ARGV")) {
yylval=numary(string("ARGV",0));
XOP(VAR);
else if (strEQ(d,"function"))
XTERM(FUNCTION);
if (strEQ(d,"FILENAME"))
- d = "ARGV";
+ ID("ARGV");
if (strEQ(d,"foreach"))
*d = toUPPER(*d);
else if (strEQ(d,"format"))
if (strEQ(d,"in"))
XTERM(IN);
if (strEQ(d,"index")) {
- set_array_base = TRUE;
XTERM(INDEX);
}
if (strEQ(d,"int")) {
case 'm': case 'M':
SNARFWORD;
if (strEQ(d,"match")) {
- set_array_base = TRUE;
XTERM(MATCH);
}
if (strEQ(d,"m"))
case 'n': case 'N':
SNARFWORD;
if (strEQ(d,"NF"))
- do_chop = do_split = split_to_array = set_array_base = TRUE;
+ do_chop = do_split = split_to_array = TRUE;
if (strEQ(d,"next")) {
saw_line_op = TRUE;
XTERM(NEXT);
SNARFWORD;
if (strEQ(d,"ORS")) {
saw_ORS = TRUE;
- d = "\\";
+ ID("\\");
}
if (strEQ(d,"OFS")) {
saw_OFS = TRUE;
- d = ",";
+ ID(",");
}
if (strEQ(d,"OFMT")) {
- d = "#";
+ ID("#");
}
if (strEQ(d,"open"))
*d = toUPPER(*d);
case 'r': case 'R':
SNARFWORD;
if (strEQ(d,"RS")) {
- d = "/";
saw_RS = TRUE;
+ ID("/");
}
if (strEQ(d,"rand")) {
yylval = ORAND;
case 's': case 'S':
SNARFWORD;
if (strEQ(d,"split")) {
- set_array_base = TRUE;
XOP(SPLIT);
}
if (strEQ(d,"substr")) {
- set_array_base = TRUE;
XTERM(SUBSTR);
}
if (strEQ(d,"sub"))
XTERM(FUN1);
}
if (strEQ(d,"SUBSEP")) {
- d = ";";
+ ID(";");
}
if (strEQ(d,"sin")) {
yylval = OSIN;
}
void
-yyerror(char *s)
+yyerror(const char *s)
{
fprintf(stderr,"%s in file %s at line %d\n",
s,filename,line);
}
int
-string(char *ptr, int len)
+string(const char *ptr, int len)
{
int retval = mop;
str_cat(key,"[]");
hstore(symtab,key->str_ptr,str_make("1"));
str_free(key);
- set_array_base = TRUE;
return arg;
}