/* $RCSfile: walk.c,v $$Revision: 4.1 $$Date: 92/08/07 18:29:31 $
*
* Copyright (C) 1991, 1992, 1993, 1994, 1995, 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: walk.c,v $
*/
#include "EXTERN.h"
#include "a2p.h"
#include "util.h"
int maxtmp = 0;
char *lparen;
char *rparen;
char *limit;
static void numericize ( int node );
#ifdef NETWARE
#endif
STR *
/* minimum precedence without parens */
{
register int len;
register int type;
register int i;
char *t;
char *d, *s;
int numarg;
if (!node) {
*numericptr = 0;
return str_make("");
}
type &= 255;
switch (type) {
case OPROG:
arymax = 0;
if (namelist) {
*d++ = *s++) ;
*d = '\0';
while (*s && !isALPHA(*s)) s++;
namelist = s;
}
}
if (do_split && split_to_array)
if (set_array_base) {
}
const_FS = 0;
if (saw_ORS && need_entire)
if (fswitch) {
}
}
if (saw_OFS) {
}
if (saw_ORS) {
}
if (saw_argv0) {
}
}
if (saw_line_op)
if (do_chop) {
}
if (do_split)
if (saw_FNR)
}
else if (old_awk)
}
if (exitval)
}
if (saw_getline) {
if (len & 2) {
if (do_fancy_opens)
else
}
else {
if (saw_FNR)
}
if (len & 1)
if (len & 2)
" if ($getline_ok = (($_ = <$fh>) ne ''))");
else
" if ($getline_ok = (($_ = <>) ne ''))");
level += 2;
i = 0;
if (do_chop) {
i++;
}
i++;
}
if (!i)
--level;
}
}
}
if (do_fancy_opens) {
sub Pick {\n\
local($mode,$name,$pipe) = @_;\n\
$fh = $name;\n\
open($name,$mode.$name.$pipe) unless $opened{$name}++;\n\
}\n\
");
}
break;
case OHUNKS:
if (len == 3) {
}
else {
}
break;
case ORANGE:
break;
case OPAT:
goto def;
case OREGEX:
/* translate \nnn to [\nnn] */
*d++ = '[';
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
*d++ = *s;
*d = ']';
}
else
*d = *s;
}
*d = '\0';
for (d=tokenbuf; *d; d++)
*d += (char)128;
break;
case OHUNK:
if (len == 1) {
}
else {
}
else {
}
}
break;
case OPPAREN:
break;
case OPANDAND:
break;
case OPOROR:
break;
case OPNOT:
break;
case OCOND:
break;
case OCPAREN:
break;
case OCANDAND:
numeric = 1;
break;
case OCOROR:
numeric = 1;
break;
case OCNOT:
numeric = 1;
break;
case ORELOP:
if (!numeric ||
if (strEQ(t,"=="))
else if (strEQ(t,"!="))
else if (strEQ(t,"<"))
else if (strEQ(t,"<="))
else if (strEQ(t,">"))
else if (strEQ(t,">="))
numeric |= 2;
}
if (numeric & 2) {
else
numeric = 1;
}
else
numeric = 1;
break;
case ORPAREN:
break;
case OMATCHOP:
else {
}
numeric = 1;
break;
case OMPAREN:
break;
case OCONCAT:
break;
case OASSIGN:
numeric = 1;
break;
case OADD:
numeric = 1;
break;
case OSUBTRACT:
numeric = 1;
break;
case OMULT:
numeric = 1;
break;
case ODIV:
numeric = 1;
break;
case OPOW:
numeric = 1;
break;
case OMOD:
numeric = 1;
break;
case OPOSTINCR:
numeric = 1;
break;
case OPOSTDECR:
numeric = 1;
break;
case OPREINCR:
numeric = 1;
break;
case OPREDECR:
numeric = 1;
break;
case OUMINUS:
numeric = 1;
break;
case OUPLUS:
numeric = 1;
goto def;
case OPAREN:
break;
case OGETLINE:
if (useval)
if (len > 0) {
}
}
else
if (len > 1) {
if (!do_fancy_opens) {
if (*t == '"' || *t == '\'')
else
fatal("Internal error: OGETLINE %s", t);
d = savestr(t);
for (t = tokenbuf; *t; t++) {
*t &= 127;
if (isLOWER(*t))
*t = toUPPER(*t);
*t = '_';
}
strcpy(t,"_FH");
if (!tmp3str) {
d[1] = '\0';
else
if (*d == '"')
if (*d == '"')
}
safefree(s);
safefree(d);
}
}
else
if (useval)
break;
case OSPRINTF:
break;
case OSUBSTR:
if (len == 3) {
}
else
break;
case OSTRING:
break;
case OSPLIT:
limit = ", 9999)";
numeric = 1;
if (useval)
else
if (len == 3) {
if (strchr("*+?.[]()|^$\\",i))
else if (i == ' ')
else
}
else
}
else if (const_FS) {
}
else if (saw_FS)
else {
limit = ")";
}
if (useval) {
}
break;
case OINDEX:
numeric = 1;
break;
case OMATCH:
numeric = 1;
break;
case OUSERDEF:
level--;
s = Nullch;
while ((t = instr(t,"return ")))
s = t++;
if (s) {
i = 0;
for (t = s+7; *t; t++) {
if (*t == ';' || *t == '}')
i++;
}
if (i == 1) {
strcpy(s,s+7);
}
}
}
if (subretnum)
level++;
break;
case ORETURN:
if (len > 0) {
if (numarg)
}
else
break;
case OUSERFUN:
break;
case OGSUB:
case OSUB: {
i = 0;
if (len == 3) {
i++;
}
else
}
else
type &= 255;
if (*t == '&')
*d++ = '$' + (char)128;
else if (*t == '$')
*d++ = '\\' + (char)128;
*d = *t + 128;
}
*d = '\0';
}
else {
i++;
}
type &= 255;
if (useval && i)
}
if (useval && i)
}
else {
i++;
if (useval)
}
if (useval && i)
numeric = 1;
break; }
case ONUM:
numeric = 1;
break;
case OSTR:
s = "'";
if (*t == '\'')
s = "\"";
else if (*t == '\\') {
s = "\"";
*d++ = *t++ + 128;
switch (*t) {
case '\\': case '"': case 'n': case 't': case '$':
break;
default: /* hide this from perl */
*d++ = '\\' + (char)128;
}
}
*d = *t + 128;
}
*d = '\0';
break;
case ODEFINED:
goto addvar;
case ODELETE:
goto addvar;
case OSTAR:
goto addvar;
case OVAR:
if (len == 1) {
numeric = 2;
numeric = 1;
saw_FNR++;
}
numeric = 1;
}
numeric = 1;
}
}
else {
#ifdef NOTDEF
if (curargs) {
}
#endif
else
saw_argv0++;
}
else {
else
*tokenbuf += (char)128;
}
}
break;
case OFLD:
if (split_to_array) {
}
else {
if (i <= arymax)
else
}
break;
case OVFLD:
break;
case OJUNK:
goto def;
case OSNEWLINE:
break;
case ONEWLINE:
break;
case OSCOMMENT:
*s += (char)128;
break;
case OCOMMENT:
*s += (char)128;
break;
case OCOMMA:
break;
case OSEMICOLON:
break;
case OSTATES:
break;
case OSTATE:
if (len >= 1) {
if (len >= 2) {
}
}
}
break;
case OCLOSE:
if (!do_fancy_opens) {
if (*t == '"' || *t == '\'')
else
fatal("Internal error: OCLOSE %s",t);
for (t = tokenbuf; *t; t++) {
*t &= 127;
if (isLOWER(*t))
*t = toUPPER(*t);
*t = '_';
}
strcpy(t,"_FH");
safefree(s);
}
else {
}
break;
case OPRINTF:
case OPRINT:
rparen = "";
if (!do_fancy_opens) {
if (*t == '"' || *t == '\'')
else
fatal("Internal error: OPRINT");
d = savestr(t);
for (t = tokenbuf; *t; t++) {
*t &= 127;
if (isLOWER(*t))
*t = toUPPER(*t);
*t = '_';
}
strcpy(t,"_FH");
if (!tmp3str) {
d[1] = '\0';
else
if (*d == '"')
if (*d == '"')
}
safefree(s);
safefree(d);
}
else {
lparen = "(";
rparen = ")";
}
}
else
else
saw_fh = 0;
if (*tokenbuf) {
saw_fh = 1;
}
}
if (split_to_array) {
}
else {
for (i = 1; i < maxfld; i++) {
if (i <= arymax)
else
}
else
}
}
}
else
}
else {
}
break;
case ORAND:
break;
case OSRAND:
goto maybe0;
case OATAN2:
goto maybe0;
case OSIN:
goto maybe0;
case OCOS:
goto maybe0;
case OSYSTEM:
goto maybe0;
case OLENGTH:
goto maybe0;
case OLOG:
goto maybe0;
case OEXP:
goto maybe0;
case OSQRT:
goto maybe0;
case OINT:
numeric = 1;
if (len > 0)
else
if (lval_field) {
if (split_to_array) {
}
else {
for (i = 1; i < maxfld; i++) {
if (i <= arymax)
else
}
else
}
}
else
}
}
}
break;
case OBREAK:
break;
case ONEXT:
break;
case OEXIT:
if (realexit) {
if (len == 1) {
}
}
else {
if (len == 1) {
}
}
break;
case OCONTINUE:
break;
case OREDIR:
goto def;
case OIF:
if (len == 3) {
if (i) {
if (i) {
i = 0;
}
}
else
i = 0;
}
if (i) {
}
else {
}
}
break;
case OWHILE:
break;
case ODO:
break;
case OFOR:
i = numarg;
if (i) {
t++;
i = t - s;
if (i < 2)
i = 0;
}
*t = ' ';
}
break;
case OFORIN:
if (!d)
s = strchr(d,'{');
if (!s)
s = strchr(d,'[');
if (!s)
fatal("Illegal for loop: %s",d);
*s++ = '\0';
for (t = s; (i = *t); t++) {
i &= 127;
if (i == '}' || i == ']')
break;
}
if (*t)
*t = '\0';
"foreach %s ($[ .. $#%s) ",
s,
d+1);
}
else {
"foreach %s (keys %%%s) ",
s,
d+1);
}
break;
case OBLOCK:
}
if (len >= 3) {
}
break;
default:
def:
if (len) {
if (len > 5)
fatal("Garbage length in walk");
for (i = 2; i<= len; i++) {
}
}
else {
}
break;
}
if (!str)
}
*numericptr = numeric;
#ifdef DEBUGGING
if (debug & 4) {
if (*t == '\n')
printf("\\n");
else if (*t == '\t')
printf("\\t");
else
putchar(*t);
putchar('\n');
}
#endif
return str;
}
static void
{
while (lvl > 1) {
lvl -= 2;
}
if (lvl)
}
static void
{
register char *s;
/* strip trailing white space */
s--;
s[1] = '\0';
}
static void
{
register char *s;
s--;
}
static void
{
register int i;
if (split_to_array)
else {
for (i = 1; i < maxfld; i++) {
if (i <= arymax)
else
}
else
}
if (const_FS) {
}
else if (saw_FS)
else
}
int
{
register int len;
register int type;
register int i;
int numarg;
if (!node) {
*numericptr = 0;
return 0;
}
type &= 255;
switch (type) {
case OPROG:
}
++level;
--level;
}
break;
case OHUNKS:
if (len == 3) {
}
break;
case ORANGE:
break;
case OPAT:
goto def;
case OREGEX:
break;
case OHUNK:
if (len == 1) {
}
else {
if (i) {
++level;
--level;
}
else {
}
}
break;
case OPPAREN:
break;
case OPANDAND:
break;
case OPOROR:
break;
case OPNOT:
break;
case OCPAREN:
break;
case OCANDAND:
numeric = 1;
break;
case OCOROR:
numeric = 1;
break;
case OCNOT:
numeric = 1;
break;
case ORELOP:
numeric = 1;
break;
case ORPAREN:
break;
case OMATCHOP:
numeric = 1;
break;
case OMPAREN:
break;
case OCONCAT:
break;
case OASSIGN:
if (!numarg)
}
break;
case OADD:
numeric = 1;
break;
case OSUBTRACT:
numeric = 1;
break;
case OMULT:
numeric = 1;
break;
case ODIV:
numeric = 1;
break;
case OPOW:
numeric = 1;
break;
case OMOD:
numeric = 1;
break;
case OPOSTINCR:
numeric = 1;
break;
case OPOSTDECR:
numeric = 1;
break;
case OPREINCR:
numeric = 1;
break;
case OPREDECR:
numeric = 1;
break;
case OUMINUS:
numeric = 1;
break;
case OUPLUS:
numeric = 1;
break;
case OPAREN:
break;
case OGETLINE:
break;
case OSPRINTF:
break;
case OSUBSTR:
if (len == 3) {
}
break;
case OSTRING:
break;
case OSPLIT:
numeric = 1;
if (len == 3)
break;
case OINDEX:
numeric = 1;
break;
case OMATCH:
numeric = 1;
break;
case OUSERDEF:
--level;
++level;
--level;
level++;
break;
case ORETURN:
if (len > 0) {
if (numarg)
}
break;
case OUSERFUN:
break;
case OGSUB:
case OSUB:
if (len >= 3)
numeric = 1;
break;
case ONUM:
numeric = 1;
break;
case OSTR:
break;
case ODEFINED:
case ODELETE:
case OSTAR:
case OVAR:
if (len == 1) {
if (numit)
}
else {
}
break;
case OFLD:
break;
case OVFLD:
break;
case OJUNK:
goto def;
case OSNEWLINE:
break;
case ONEWLINE:
break;
case OSCOMMENT:
break;
case OCOMMENT:
break;
case OCOMMA:
break;
case OSEMICOLON:
break;
case OSTATES:
break;
case OSTATE:
if (len >= 1) {
if (len >= 2) {
}
}
break;
case OCLOSE:
break;
case OPRINTF:
case OPRINT:
}
break;
case ORAND:
break;
case OSRAND:
goto maybe0;
case OATAN2:
goto maybe0;
case OSIN:
goto maybe0;
case OCOS:
goto maybe0;
case OSYSTEM:
goto maybe0;
case OLENGTH:
goto maybe0;
case OLOG:
goto maybe0;
case OEXP:
goto maybe0;
case OSQRT:
goto maybe0;
case OINT:
numeric = 1;
if (len > 0)
break;
case OBREAK:
break;
case ONEXT:
break;
case OEXIT:
if (len == 1) {
}
break;
case OCONTINUE:
break;
case OREDIR:
goto def;
case OIF:
if (len == 3) {
}
break;
case OWHILE:
break;
case OFOR:
break;
case OFORIN:
break;
case OBLOCK:
if (len == 2) {
}
++level;
--level;
break;
default:
def:
if (len) {
if (len > 5)
fatal("Garbage length in prewalk");
for (i = 2; i<= len; i++) {
}
}
break;
}
*numericptr = numeric;
return 1;
}
static void
{
register int len;
register int type;
int numarg;
type &= 255;
}
}