X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=x2p%2Fwalk.c;h=59ac8a9f3d4cd86fd09a46f5399ba4f31cea0acb;hb=5999ed7d8e1601dce57087d0b16df2b7b3923d34;hp=4e11076b5793870d31e6b1a90902ebe8bd3464fd;hpb=7c0587c85ff56c1fa1d95bc5228a7aff2da43d6c;p=p5sagit%2Fp5-mst-13.2.git diff --git a/x2p/walk.c b/x2p/walk.c index 4e11076..59ac8a9 100644 --- a/x2p/walk.c +++ b/x2p/walk.c @@ -1,33 +1,16 @@ -/* $RCSfile: walk.c,v $$Revision: 4.0.1.3 $$Date: 92/06/08 17:33:46 $ +/* $RCSfile: walk.c,v $$Revision: 4.1 $$Date: 92/08/07 18:29:31 $ * - * Copyright (c) 1991, Larry Wall + * Copyright (c) 1991-2001, 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 $ - * Revision 4.0.1.3 92/06/08 17:33:46 lwall - * patch20: in a2p, simplified the filehandle model - * patch20: in a2p, made RS="" translate to $/ = "\n\n" - * patch20: in a2p, do {...} while ... was missing some reconstruction code - * patch20: in a2p, getline should allow variable to be array element - * - * Revision 4.0.1.2 91/11/05 19:25:09 lwall - * patch11: in a2p, split on whitespace produced extra null field - * - * Revision 4.0.1.1 91/06/07 12:22:04 lwall - * patch4: new copyright notice - * patch4: a2p didn't correctly implement -n switch - * - * Revision 4.0 91/03/20 01:58:36 lwall - * 4.0 baseline. - * */ -#include "handy.h" #include "EXTERN.h" -#include "util.h" #include "a2p.h" +#include "util.h" bool exitval = FALSE; bool realexit = FALSE; @@ -43,13 +26,23 @@ char *limit; 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; @@ -64,7 +57,6 @@ int minprec; /* minimum precedence without parens */ int numeric = FALSE; STR *fstr; int prec = P_MAX; /* assume no parens needed */ - char *index(); if (!node) { *numericptr = 0; @@ -107,7 +99,7 @@ int minprec; /* minimum precedence without parens */ do_chop = TRUE; if (fswitch) { str_cat(str,"$FS = '"); - if (index("*+?.[]()|^$\\",fswitch)) + if (strchr("*+?.[]()|^$\\",fswitch)) str_cat(str,"\\"); sprintf(tokenbuf,"%c",fswitch); str_cat(str,tokenbuf); @@ -141,7 +133,7 @@ int minprec; /* minimum precedence without parens */ 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) @@ -153,7 +145,7 @@ int minprec; /* minimum precedence without parens */ 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; @@ -198,7 +190,7 @@ int minprec; /* minimum precedence without parens */ 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)) { @@ -395,8 +387,8 @@ sub Pick {\n\ str_set(tmpstr,"gt"); else if (strEQ(t,">=")) str_set(tmpstr,"ge"); - if (!index(tmpstr->str_ptr,'\'') && !index(tmpstr->str_ptr,'"') && - !index(tmp2str->str_ptr,'\'') && !index(tmp2str->str_ptr,'"') ) + if (!strchr(tmpstr->str_ptr,'\'') && !strchr(tmpstr->str_ptr,'"') && + !strchr(tmp2str->str_ptr,'\'') && !strchr(tmp2str->str_ptr,'"') ) numeric |= 2; } if (numeric & 2) { @@ -602,7 +594,7 @@ sub Pick {\n\ if (!isalpha(*t) && !isdigit(*t)) *t = '_'; } - if (!index(tokenbuf,'_')) + if (!strchr(tokenbuf,'_')) strcpy(t,"_FH"); tmp3str = hfetch(symtab,tokenbuf); if (!tmp3str) { @@ -691,7 +683,7 @@ sub Pick {\n\ fstr = walk(1,level,ops[node+3].ival,&numarg,P_COMMA+1); if (str_len(fstr) == 3 && *fstr->str_ptr == '\'') { i = fstr->str_ptr[1] & 127; - if (index("*+?.[]()|^$\\",i)) + if (strchr("*+?.[]()|^$\\",i)) sprintf(tokenbuf,"/\\%c/",i); else if (i == ' ') sprintf(tokenbuf,"' '"); @@ -871,7 +863,7 @@ sub Pick {\n\ str_scat(tmp3str,tmp2str); str_cat(tmp3str,").'\"') =~ s/&/\\$&/g, "); str_set(tmp2str,"eval $s_"); - s = (*s == 'g' ? "ge" : "e"); + s = (char*)(*s == 'g' ? "ge" : "e"); i++; } type = ops[ops[node+1].ival].ival; @@ -1133,7 +1125,7 @@ sub Pick {\n\ if (!isalpha(*t) && !isdigit(*t)) *t = '_'; } - if (!index(tokenbuf,'_')) + if (!strchr(tokenbuf,'_')) strcpy(t,"_FH"); str_free(tmpstr); safefree(s); @@ -1170,7 +1162,7 @@ sub Pick {\n\ if (!isalpha(*t) && !isdigit(*t)) *t = '_'; } - if (!index(tokenbuf,'_')) + if (!strchr(tokenbuf,'_')) strcpy(t,"_FH"); tmp3str = hfetch(symtab,tokenbuf); if (!tmp3str) { @@ -1227,7 +1219,7 @@ sub Pick {\n\ } tmpstr = walk(1+(type==OPRINT),level,ops[node+1].ival,&numarg,P_MIN); if (!*tmpstr->str_ptr && lval_field) { - t = saw_OFS ? "$," : "' '"; + t = (char*)(saw_OFS ? "$," : "' '"); if (split_to_array) { sprintf(tokenbuf,"join(%s,@Fld)",t); str_cat(tmpstr,tokenbuf); @@ -1300,10 +1292,10 @@ sub Pick {\n\ if (len > 0) tmpstr = walk(1,level,ops[node+1].ival,&numarg,P_MIN); else - tmpstr = str_new(0);; + tmpstr = str_new(0); if (!tmpstr->str_ptr || !*tmpstr->str_ptr) { if (lval_field) { - t = saw_OFS ? "$," : "' '"; + t = (char*)(saw_OFS ? "$," : "' '"); if (split_to_array) { sprintf(tokenbuf,"join(%s,@Fld)",t); str_cat(tmpstr,tokenbuf); @@ -1425,7 +1417,7 @@ sub Pick {\n\ str_scat(str,fstr=walk(1,level,ops[node+1].ival,&numarg,P_MIN)); str_free(fstr); if (str->str_ptr[str->str_cur - 1] == '\n') - --str->str_cur;; + --str->str_cur; str_cat(str," while ("); str_scat(str,fstr=walk(0,level,ops[node+2].ival,&numarg,P_MIN)); str_free(fstr); @@ -1446,7 +1438,7 @@ sub Pick {\n\ } str_cat(str,"; "); fstr=walk(1,level,ops[node+2].ival,&numarg,P_MIN); - if (i && (t = index(fstr->str_ptr,0377))) { + if (i && (t = strchr(fstr->str_ptr,0377))) { if (strnEQ(fstr->str_ptr,s,i)) *t = ' '; } @@ -1462,12 +1454,12 @@ sub Pick {\n\ break; case OFORIN: tmpstr = walk(0,level,ops[node+1].ival,&numarg,P_MIN); - d = index(tmpstr->str_ptr,'$'); + d = strchr(tmpstr->str_ptr,'$'); if (!d) fatal("Illegal for loop: %s",tmpstr->str_ptr); - s = index(d,'{'); + s = strchr(d,'{'); if (!s) - s = index(d,'['); + s = strchr(d,'['); if (!s) fatal("Illegal for loop: %s",d); *s++ = '\0'; @@ -1563,9 +1555,8 @@ sub Pick {\n\ 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"); @@ -1575,9 +1566,8 @@ register int lvl; str_cat(str," "); } -fixtab(str,lvl) -register STR *str; -register int lvl; +static void +fixtab(register STR *str, register int lvl) { register char *s; @@ -1594,8 +1584,8 @@ register int lvl; tab(str,lvl); } -addsemi(str) -register STR *str; +static void +addsemi(register STR *str) { register char *s; @@ -1606,9 +1596,8 @@ register STR *str; str_cat(str,";"); } -emit_split(str,level) -register STR *str; -int level; +static void +emit_split(register STR *str, int level) { register int i; @@ -1640,17 +1629,12 @@ int level; 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; @@ -1770,7 +1754,7 @@ int *numericptr; 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); @@ -2062,12 +2046,11 @@ int *numericptr; 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;