/* $RCSfile: walk.c,v $$Revision: 4.1 $$Date: 92/08/07 18:29:31 $
*
- * 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.
* $Log: walk.c,v $
*/
-#include "handy.h"
#include "EXTERN.h"
-#include "util.h"
#include "a2p.h"
+#include "util.h"
bool exitval = FALSE;
bool realexit = FALSE;
STR *subs;
STR *curargs = Nullstr;
+static void addsemi _(( STR *str ));
+static void emit_split _(( STR *str, int level ));
+static void fixtab _(( STR *str, int lvl ));
+static void numericize _(( int node ));
+static void tab _(( STR *str, int lvl ));
+
+int prewalk _(( int numit, int level, int node, int *numericptr ));
+STR * walk _(( int useval, int level, int node, int *numericptr, int minprec ));
+
+
STR *
-walk(useval,level,node,numericptr,minprec)
-int useval;
-int level;
-register int node;
-int *numericptr;
-int minprec; /* minimum precedence without parens */
+walk(int useval, int level, register int node, int *numericptr, int minprec)
+
+
+
+
+ /* minimum precedence without parens */
{
register int len;
register STR *str;
int numeric = FALSE;
STR *fstr;
int prec = P_MAX; /* assume no parens needed */
- char *strchr();
if (!node) {
*numericptr = 0;
if (saw_FS && !const_FS)
do_chop = TRUE;
if (do_chop) {
- str_cat(str,"chop;\t# strip record separator\n");
+ str_cat(str,"chomp;\t# strip record separator\n");
tab(str,level);
}
if (do_split)
if (saw_FNR)
str_cat(str,"continue {\n $FNRbase = $. if eof;\n}\n");
}
- else
+ else if (old_awk)
str_cat(str,"while (<>) { } # (no line actions)\n");
if (ops[node+4].ival) {
realexit = TRUE;
i = 0;
if (do_chop) {
i++;
- str_cat(str,"chop;\t# strip record separator\n");
+ str_cat(str,"chomp;\t# strip record separator\n");
tab(str,level);
}
if (do_split && !(len & 1)) {
return str;
}
-tab(str,lvl)
-register STR *str;
-register int lvl;
+static void
+tab(register STR *str, register int lvl)
{
while (lvl > 1) {
str_cat(str,"\t");
str_cat(str," ");
}
-fixtab(str,lvl)
-register STR *str;
-register int lvl;
+static void
+fixtab(register STR *str, register int lvl)
{
register char *s;
tab(str,lvl);
}
-addsemi(str)
-register STR *str;
+static void
+addsemi(register STR *str)
{
register char *s;
str_cat(str,";");
}
-emit_split(str,level)
-register STR *str;
-int level;
+static void
+emit_split(register STR *str, int level)
{
register int i;
tab(str,level);
}
-prewalk(numit,level,node,numericptr)
-int numit;
-int level;
-register int node;
-int *numericptr;
+int
+prewalk(int numit, int level, register int node, int *numericptr)
{
register int len;
register int type;
register int i;
- char *t;
- char *d, *s;
int numarg;
int numeric = FALSE;
STR *tmpstr;
prewalk(0,level,ops[node+2].ival,&numarg);
prewalk(0,level,ops[node+1].ival,&numarg);
prewalk(0,level,ops[node+3].ival,&numarg);
- if (numarg || strlen(ops[ops[node+1].ival+1].cval) > 1) {
+ if (numarg || strlen(ops[ops[node+1].ival+1].cval) > (Size_t)1) {
numericize(ops[node+2].ival);
if (!numarg)
numericize(ops[node+3].ival);
return 1;
}
-numericize(node)
-register int node;
+static void
+numericize(register int node)
{
register int len;
register int type;
- register int i;
STR *tmpstr;
STR *tmp2str;
int numarg;