Lines Matching +full:1 +full:- +full:cell
47 #if 1
50 void tempfree(Cell *p) { in tempfree()
51 if (p->ctype == OCELL && (p->csub < CUNK || p->csub > CFREE)) { in tempfree()
52 WARNING("bad csub %d in Cell %d %s", in tempfree()
53 p->csub, p->ctype, p->sval); in tempfree()
80 Cell *tmps; /* free temporary cells for execution */
82 static Cell truecell ={ OBOOL, BTRUE, 0, 0, 1.0, NUM, NULL, NULL };
83 Cell *True = &truecell;
84 static Cell falsecell ={ OBOOL, BFALSE, 0, 0, 0.0, NUM, NULL, NULL };
85 Cell *False = &falsecell;
86 static Cell breakcell ={ OJUMP, JBREAK, 0, 0, 0.0, NUM, NULL, NULL };
87 Cell *jbreak = &breakcell;
88 static Cell contcell ={ OJUMP, JCONT, 0, 0, 0.0, NUM, NULL, NULL };
89 Cell *jcont = &contcell;
90 static Cell nextcell ={ OJUMP, JNEXT, 0, 0, 0.0, NUM, NULL, NULL };
91 Cell *jnext = &nextcell;
92 static Cell nextfilecell ={ OJUMP, JNEXTFILE, 0, 0, 0.0, NUM, NULL, NULL };
93 Cell *jnextfile = &nextfilecell;
94 static Cell exitcell ={ OJUMP, JEXIT, 0, 0, 0.0, NUM, NULL, NULL };
95 Cell *jexit = &exitcell;
96 static Cell retcell ={ OJUMP, JRET, 0, 0, 0.0, NUM, NULL, NULL };
97 Cell *jret = &retcell;
98 static Cell tempcell ={ OCELL, CTEMP, 0, EMPTY, 0.0, NUM|STR|DONTFREE, NULL, NULL };
118 int boff = pbptr ? *pbptr - *pbuf : 0; in adjbuf()
121 minlen += quantum - rminlen; in adjbuf()
134 return 1; in adjbuf()
145 Cell *execute(Node *u) /* execute a node of the parse tree */ in execute()
147 Cell *(*proc)(Node **, int); in execute()
148 Cell *x; in execute()
153 for (a = u; ; a = a->nnext) { in execute()
156 x = (Cell *) (a->narg[0]); in execute()
163 if (notlegal(a->nobj)) /* probably a Cell* but too risky to print */ in execute()
165 proc = proctab[a->nobj-FIRSTTOKEN]; in execute()
166 x = (*proc)(a->narg, a->nobj); in execute()
175 if (a->nnext == NULL) in execute()
182 Cell *program(Node **a, int n) /* execute an awk program */ in program()
183 { /* a[0] = BEGIN, a[1] = body, a[2] = END */ in program()
184 Cell *x; in program()
196 if (a[1] || a[2]) in program()
198 x = execute(a[1]); in program()
218 Cell *fcncell; /* pointer to Cell for function */
219 Cell **args; /* pointer to array of arguments after execute */
220 Cell *retval; /* return value */
229 Cell *call(Node **a, int n) /* function call. very kludgy and fragile */ in call()
231 static const Cell newcopycell = { OCELL, CCOPY, 0, EMPTY, 0.0, NUM|STR|DONTFREE, NULL, NULL }; in call()
235 Cell *args[NARGS], *oargs[NARGS]; /* BUG: fixed size arrays */ in call()
236 Cell *y, *z, *fcn; in call()
240 s = fcn->nval; in call()
248 for (ncall = 0, x = a[1]; x != NULL; x = x->nnext) /* args in call */ in call()
250 ndef = (int) fcn->fval; /* args in defn */ in call()
251 DPRINTF("calling %s, %d args (%d in defn), frp=%d\n", s, ncall, ndef, (int) (frp-frame)); in call()
257 for (i = 0, x = a[1]; x != NULL; i++, x = x->nnext) { /* get call args */ in call()
258 DPRINTF("evaluate args[%d], frp=%d:\n", i, (int) (frp-frame)); in call()
262 i, NN(y->nval), y->fval, isarr(y) ? "(array)" : NN(y->sval), y->tval); in call()
264 FATAL("can't use function %s as argument in %s", y->nval, s); in call()
277 int dfp = frp - frame; /* old index */ in call()
283 frp->fcncell = fcn; in call()
284 frp->args = args; in call()
285 frp->nargs = ndef; /* number defined with (excess are locals) */ in call()
286 frp->retval = gettemp(); in call()
288 DPRINTF("start exec of %s, frp=%d\n", s, (int) (frp-frame)); in call()
289 y = execute((Node *)(fcn->sval)); /* execute body */ in call()
290 DPRINTF("finished exec of %s, frp=%d\n", s, (int) (frp-frame)); in call()
293 Cell *t = frp->args[i]; in call()
295 if (t->csub == CCOPY) { in call()
298 t->csub = CTEMP; in call()
301 oargs[i]->tval = t->tval; in call()
302 oargs[i]->tval &= ~(STR|NUM|DONTFREE); in call()
303 oargs[i]->sval = t->sval; in call()
308 t->csub = CTEMP; in call()
310 } else if (t == y && t->csub == CCOPY) { in call()
311 t->csub = CTEMP; in call()
313 freed = 1; in call()
322 z = frp->retval; /* return value */ in call()
323 DPRINTF("%s returns %g |%s| %o\n", s, getfval(z), getsval(z), z->tval); in call()
324 frp--; in call()
328 Cell *copycell(Cell *x) /* make a copy of a cell in a temp */ in copycell()
330 Cell *y; in copycell()
335 y->tval = x->tval & ~(CON|FLD|REC); in copycell()
336 y->csub = CCOPY; /* prevents freeing until call is over */ in copycell()
337 y->nval = x->nval; /* BUG? */ in copycell()
338 if (isstr(x) /* || x->ctype == OCELL */) { in copycell()
339 y->sval = tostring(x->sval); in copycell()
340 y->tval &= ~DONTFREE; in copycell()
342 y->tval |= DONTFREE; in copycell()
343 y->fval = x->fval; in copycell()
347 Cell *arg(Node **a, int n) /* nth argument of a function */ in arg()
351 DPRINTF("arg(%d), frp->nargs=%d\n", n, frp->nargs); in arg()
352 if (n+1 > frp->nargs) in arg()
354 n+1, frp->fcncell->nval); in arg()
355 return frp->args[n]; in arg()
358 Cell *jump(Node **a, int n) /* break, continue, next, nextfile, return */ in jump()
360 Cell *y; in jump()
369 longjmp(env, 1); in jump()
373 if ((y->tval & (STR|NUM)) == (STR|NUM)) { in jump()
374 setsval(frp->retval, getsval(y)); in jump()
375 frp->retval->fval = getfval(y); in jump()
376 frp->retval->tval |= NUM; in jump()
378 else if (y->tval & STR) in jump()
379 setsval(frp->retval, getsval(y)); in jump()
380 else if (y->tval & NUM) in jump()
381 setfval(frp->retval, getfval(y)); in jump()
383 FATAL("bad type variable %d", y->tval); in jump()
402 Cell *awkgetline(Node **a, int n) /* get next line from specific input */ in awkgetline()
403 { /* a[0] is variable, a[1] is operator, a[2] is filename */ in awkgetline()
404 Cell *r, *x; in awkgetline()
405 extern Cell **fldtab; in awkgetline()
418 if (a[1] != NULL) { /* getline < file */ in awkgetline()
420 mode = ptoi(a[1]); in awkgetline()
426 n = -1; in awkgetline()
434 if (is_number(x->sval, & result)) { in awkgetline()
435 x->fval = result; in awkgetline()
436 x->tval |= NUM; in awkgetline()
441 if (is_number(fldtab[0]->sval, & result)) { in awkgetline()
442 fldtab[0]->fval = result; in awkgetline()
443 fldtab[0]->tval |= NUM; in awkgetline()
454 if (is_number(x->sval, & result)) { in awkgetline()
455 x->fval = result; in awkgetline()
456 x->tval |= NUM; in awkgetline()
467 Cell *getnf(Node **a, int n) /* get NF */ in getnf()
471 return (Cell *) a[0]; in getnf()
488 for (; p; p = p->nnext) { in makearraystring()
489 Cell *x = execute(p); /* expr */ in makearraystring()
492 size_t nsub = p->nnext ? seplen : 0; in makearraystring()
496 if (!adjbuf(&buf, &bufsz, tlen + 1, recsize, 0, func)) { in makearraystring()
498 func, x->nval, buf); in makearraystring()
511 Cell *array(Node **a, int n) /* a[0] is symtab, a[1] is list of subscripts */ in array()
513 Cell *x, *z; in array()
516 x = execute(a[0]); /* Cell* for symbol table */ in array()
517 buf = makearraystring(a[1], __func__); in array()
519 DPRINTF("making %s into an array\n", NN(x->nval)); in array()
521 xfree(x->sval); in array()
522 x->tval &= ~(STR|NUM|DONTFREE); in array()
523 x->tval |= ARR; in array()
524 x->sval = (char *) makesymtab(NSYMTAB); in array()
526 z = setsymtab(buf, "", 0.0, STR|NUM, (Array *) x->sval); in array()
527 z->ctype = OCELL; in array()
528 z->csub = CVAR; in array()
534 Cell *awkdelete(Node **a, int n) /* a[0] is symtab, a[1] is list of subscripts */ in awkdelete()
536 Cell *x; in awkdelete()
538 x = execute(a[0]); /* Cell* for symbol table */ in awkdelete()
544 if (a[1] == NULL) { /* delete the elements, not the table */ in awkdelete()
546 x->tval &= ~STR; in awkdelete()
547 x->tval |= ARR; in awkdelete()
548 x->sval = (char *) makesymtab(NSYMTAB); in awkdelete()
550 char *buf = makearraystring(a[1], __func__); in awkdelete()
558 Cell *intest(Node **a, int n) /* a[0] is index (list), a[1] is symtab */ in intest()
560 Cell *ap, *k; in intest()
563 ap = execute(a[1]); /* array name */ in intest()
565 DPRINTF("making %s into an array\n", ap->nval); in intest()
567 xfree(ap->sval); in intest()
568 ap->tval &= ~(STR|NUM|DONTFREE); in intest()
569 ap->tval |= ARR; in intest()
570 ap->sval = (char *) makesymtab(NSYMTAB); in intest()
573 k = lookup(buf, (Array *) ap->sval); in intest()
583 /* ======== utf-8 code ========== */
586 * Awk strings can contain ascii, random 8-bit items (eg Latin-1),
587 * or utf-8. u8_isutf tests whether a string starts with a valid
588 * utf-8 sequence, and returns 0 if not (e.g., high bit set).
590 * 1 for ascii, 2..4 for utf-8, or 1 for high bit non-utf.
591 * u8_strlen returns length of string in valid utf-8 sequences
592 * and/or high-bit bytes. Conversion functions go between byte
595 * In theory, this behaves the same as before for non-utf8 bytes.
600 /* is s the beginning of a valid utf-8 string? */
601 /* return length 1..4 if yes, 0 if no */
608 if (c < 128 || awk_mb_cur_max == 1) in u8_isutf()
609 return 1; /* what if it's 0? */ in u8_isutf()
612 if (n >= 2 && ((c>>5) & 0x7) == 0x6 && (s[1] & 0xC0) == 0x80) { in u8_isutf()
614 } else if (n >= 3 && ((c>>4) & 0xF) == 0xE && (s[1] & 0xC0) == 0x80 in u8_isutf()
617 } else if (n >= 4 && ((c>>3) & 0x1F) == 0x1E && (s[1] & 0xC0) == 0x80 in u8_isutf()
626 /* Convert (prefix of) utf8 string to utf-32 rune. */
635 if (c < 128 || awk_mb_cur_max == 1) { in u8_rune()
637 return 1; in u8_rune()
641 if (n >= 2 && ((c>>5) & 0x7) == 0x6 && (s[1] & 0xC0) == 0x80) { in u8_rune()
642 *rune = ((c & 0x1F) << 6) | (s[1] & 0x3F); /* 110xxxxx 10xxxxxx */ in u8_rune()
644 } else if (n >= 3 && ((c>>4) & 0xF) == 0xE && (s[1] & 0xC0) == 0x80 in u8_rune()
646 *rune = ((c & 0xF) << 12) | ((s[1] & 0x3F) << 6) | (s[2] & 0x3F); in u8_rune()
649 } else if (n >= 4 && ((c>>3) & 0x1F) == 0x1E && (s[1] & 0xC0) == 0x80 in u8_rune()
651 *rune = ((c & 0x7) << 18) | ((s[1] & 0x3F) << 12) | ((s[2] & 0x3F) << 6) | (s[3] & 0x3F); in u8_rune()
656 ret = 1; in u8_rune()
661 /* return length of next sequence: 1 for ascii or random, 2..4 for valid utf8 */
668 len = 1; in u8_nextlen()
672 /* return number of utf characters or single non-utf bytes */
682 if (c < 128 || awk_mb_cur_max == 1) { in u8_strlen()
683 len = 1; in u8_strlen()
694 /* convert utf-8 char number in a string to its byte offset */
704 charnum--; in u8_char2byte()
709 /* convert byte offset in s to utf-8 char number that starts there */
718 return -1; /* ??? */ in u8_byte2char()
741 T1 = ((1<<(Bit1+1))-1) ^ 0xFF, /* 0000 0000 */
742 Tx = ((1<<(Bitx+1))-1) ^ 0xFF, /* 1000 0000 */
743 T2 = ((1<<(Bit2+1))-1) ^ 0xFF, /* 1100 0000 */
744 T3 = ((1<<(Bit3+1))-1) ^ 0xFF, /* 1110 0000 */
745 T4 = ((1<<(Bit4+1))-1) ^ 0xFF, /* 1111 0000 */
746 T5 = ((1<<(Bit5+1))-1) ^ 0xFF, /* 1111 1000 */
748 Rune1 = (1<<(Bit1+0*Bitx))-1, /* 0000 0000 0000 0000 0111 1111 */
749 Rune2 = (1<<(Bit2+1*Bitx))-1, /* 0000 0000 0000 0111 1111 1111 */
750 Rune3 = (1<<(Bit3+2*Bitx))-1, /* 0000 0000 1111 1111 1111 1111 */
751 Rune4 = (1<<(Bit4+3*Bitx))-1, /* 0011 1111 1111 1111 1111 1111 */
753 Maskx = (1<<Bitx)-1, /* 0011 1111 */
760 /* one character sequence 00000-0007F => 00-7F */ in runetochar()
763 return 1; in runetochar()
766 /* two character sequence 00080-007FF => T2 Tx */ in runetochar()
768 str[0] = T2 | (c >> 1*Bitx); in runetochar()
769 str[1] = Tx | (c & Maskx); in runetochar()
773 /* three character sequence 00800-0FFFF => T3 Tx Tx */ in runetochar()
778 str[1] = Tx | ((c >> 1*Bitx) & Maskx); in runetochar()
783 /* four character sequence 010000-1FFFFF => T4 Tx Tx Tx */ in runetochar()
785 str[1] = Tx | ((c >> 2*Bitx) & Maskx); in runetochar()
786 str[2] = Tx | ((c >> 1*Bitx) & Maskx); in runetochar()
796 Cell *matchop(Node **a, int n) /* ~ and match() */ in matchop()
798 Cell *x, *y, *z; in matchop()
807 mode = 1; in matchop()
809 x = execute(a[1]); /* a[1] = target text */ in matchop()
811 if (a[0] == NULL) /* a[1] == 0: already-compiled reg expr */ in matchop()
822 int start = patbeg - s + 1; /* origin 1 */ in matchop()
826 cstart = u8_byte2char(s, start-1); in matchop()
840 x->tval = NUM; in matchop()
841 x->fval = start; in matchop()
842 } else if ((n == MATCH && i == 1) || (n == NOTMATCH && i == 0)) in matchop()
852 Cell *boolop(Node **a, int n) /* a[0] || a[1], a[0] && a[1], !a[0] */ in boolop()
854 Cell *x, *y; in boolop()
863 y = execute(a[1]); in boolop()
870 y = execute(a[1]); in boolop()
884 Cell *relop(Node **a, int n) /* a[0 < a[1], etc. */ in relop()
887 Cell *x, *y; in relop()
892 y = execute(a[1]); in relop()
893 x_is_nan = isnan(x->fval); in relop()
894 y_is_nan = isnan(y->fval); in relop()
895 if (x->tval&NUM && y->tval&NUM) { in relop()
898 j = x->fval - y->fval; in relop()
899 i = j<0? -1: (j>0? 1: 0); in relop()
925 void tfree(Cell *a) /* free a tempcell */ in tfree()
928 DPRINTF("freeing %s %s %o\n", NN(a->nval), NN(a->sval), a->tval); in tfree()
929 xfree(a->sval); in tfree()
933 a->cnext = tmps; in tfree()
937 Cell *gettemp(void) /* get a tempcell */ in gettemp()
939 Cell *x; in gettemp()
942 tmps = (Cell *) calloc(100, sizeof(*tmps)); in gettemp()
945 for (i = 1; i < 100; i++) in gettemp()
946 tmps[i-1].cnext = &tmps[i]; in gettemp()
947 tmps[i-1].cnext = NULL; in gettemp()
950 tmps = x->cnext; in gettemp()
955 Cell *indirect(Node **a, int n) /* $( a[0] ) */ in indirect()
958 Cell *x; in indirect()
965 FATAL("trying to access out of range field %s", x->nval); in indirect()
968 FATAL("illegal field $(%s), name \"%s\"", s, x->nval); in indirect()
969 /* BUG: can x->nval ever be null??? */ in indirect()
972 x->ctype = OCELL; /* BUG? why are these needed? */ in indirect()
973 x->csub = CFLD; in indirect()
977 Cell *substr(Node **a, int nnn) /* substr(a[0], a[1], a[2]) */ in substr()
983 Cell *x, *y, *z = NULL; in substr()
986 y = execute(a[1]); in substr()
990 k = u8_strlen(s) + 1; in substr()
991 if (k <= 1) { in substr()
1003 m = 1; in substr()
1011 n = k - 1; in substr()
1014 else if (n > k - m) in substr()
1015 n = k - m; in substr()
1019 mb = u8_char2byte(s, m-1); /* byte offset of start char in s */ in substr()
1020 nb = u8_char2byte(s, m-1+n); /* byte offset of end+1 char in s */ in substr()
1030 Cell *sindex(Node **a, int nnn) /* index(a[0], a[1]) */ in sindex()
1032 Cell *x, *y, *z; in sindex()
1038 y = execute(a[1]); in sindex()
1046 /* v = (Awkfloat) (p1 - s1 + 1); origin 1 */ in sindex()
1051 for (i = 0; i < p1-s1+1; i += len) { in sindex()
1064 int has_utf8(char *s) /* return 1 if s contains any utf-8 (2 bytes or more) character */ in has_utf8()
1070 if (n > 1) in has_utf8()
1071 return 1; in has_utf8()
1078 int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like conversions */ in format()
1083 Cell *x; in format()
1089 #define FMTSZ(a) (fmtsz - ((a) - fmt)) in format()
1090 #define BUFSZ(a) (bufsize - ((a) - buf)) in format()
1108 adjbuf(&buf, &bufsize, MAXNUMSIZE+1+p-buf, recsize, &p, "format1"); in format()
1113 if (*(s+1) == '%') { in format()
1118 fmtwd = atoi(s+1); in format()
1120 fmtwd = -fmtwd; in format()
1121 adjbuf(&buf, &bufsize, fmtwd+1+p-buf, recsize, &p, "format2"); in format()
1123 if (!adjbuf(&fmt, &fmtsz, MAXNUMSIZE+1+t-fmt, recsize, &t, "format3")) in format()
1127 t--; in format()
1140 a = a->nnext; in format()
1141 snprintf(t - 1, FMTSZ(t - 1), in format()
1144 fmtwd = -fmtwd; in format()
1145 adjbuf(&buf, &bufsize, fmtwd+1+p-buf, recsize, &p, "format"); in format()
1152 fmtwd = -fmtwd; in format()
1153 adjbuf(&buf, &bufsize, fmtwd+1+p-buf, recsize, &p, "format4"); in format()
1166 *(t-1) = 'j'; in format()
1184 a = a->nnext; in format()
1188 adjbuf(&buf, &bufsize, 1+n+p-buf, recsize, &p, "format5"); in format()
1196 adjbuf(&buf, &bufsize, 1+strlen(p)+n+p-buf, recsize, &p, "format6"); in format()
1209 /* if simple format or no utf-8 in the string, sprintf works */ in format()
1213 if (!adjbuf(&buf, &bufsize, 1+n+p-buf, recsize, &p, "format7")) in format()
1220 /* get here if string has utf-8 chars and fmt is not plain %s */ in format()
1221 /* "%-w.ps", where -, w and .p are all optional */ in format()
1225 char *f = fmt+1; in format()
1226 if (f[0] == '-') { in format()
1227 ljust = 1; in format()
1249 pad = wid>prec ? wid - prec : 0; // has to be >= 0 in format()
1286 * our best to convert it back into UTF-8. If we in format()
1294 if (charval < 128 || awk_mb_cur_max == 1) in format()
1327 char *f = fmt+1; in format()
1328 if (f[0] == '-') { in format()
1329 ljust = 1; in format()
1349 if (prec > 1) // %c --> only one character in format()
1350 prec = 1; in format()
1351 pad = wid>prec ? wid - prec : 0; // has to be >= 0 in format()
1382 for ( ; a; a = a->nnext) { /* evaluate any remaining args */ in format()
1388 return p - buf; in format()
1391 Cell *awksprintf(Node **a, int n) /* sprintf(a[0]) */ in awksprintf()
1393 Cell *x; in awksprintf()
1400 y = a[0]->nnext; in awksprintf()
1402 if (format(&buf, &bufsz, getsval(x), y) == -1) in awksprintf()
1406 x->sval = buf; in awksprintf()
1407 x->tval = STR; in awksprintf()
1411 Cell *awkprintf(Node **a, int n) /* printf */ in awkprintf()
1413 /* a[1] is redirection operator, a[2] is redirection file */ in awkprintf()
1415 Cell *x; in awkprintf()
1423 y = a[0]->nnext; in awkprintf()
1425 if ((len = format(&buf, &bufsz, getsval(x), y)) == -1) in awkprintf()
1428 if (a[1] == NULL) { in awkprintf()
1430 fwrite(buf, len, 1, stdout); in awkprintf()
1434 fp = redirect(ptoi(a[1]), a[2]); in awkprintf()
1436 fwrite(buf, len, 1, fp); in awkprintf()
1445 Cell *arith(Node **a, int n) /* a[0] + a[1], etc. also -a[0] */ in arith()
1449 Cell *x, *y, *z; in arith()
1455 y = execute(a[1]); in arith()
1465 i -= j; in arith()
1479 i = i - j * v; in arith()
1482 i = -i; in arith()
1506 return 1; in ipow()
1514 Cell *incrdecr(Node **a, int n) /* a[0]++, etc. */ in incrdecr()
1516 Cell *x, *z; in incrdecr()
1522 k = (n == PREINCR || n == POSTINCR) ? 1 : -1; in incrdecr()
1534 Cell *assign(Node **a, int n) /* a[0] = a[1], a[0] += a[1], etc. */ in assign()
1536 Cell *x, *y; in assign()
1540 y = execute(a[1]); in assign()
1543 if (x == y && !(x->tval & (FLD|REC)) && x != nfloc) in assign()
1544 ; /* self-assignment: leave alone unless it's a field or NF */ in assign()
1545 else if ((y->tval & (STR|NUM)) == (STR|NUM)) { in assign()
1548 x->fval = yf; in assign()
1549 x->tval |= NUM; in assign()
1567 xf -= yf; in assign()
1581 xf = xf - yf * v; in assign()
1600 Cell *cat(Node **a, int q) /* a[0] cat a[1] */ in cat()
1602 Cell *x, *y, *z; in cat()
1609 adjbuf(&s, &ssz, n1 + 1, recsize, 0, "cat1"); in cat()
1610 memcpy(s, x->sval, n1); in cat()
1614 y = execute(a[1]); in cat()
1616 adjbuf(&s, &ssz, n1 + n2 + 1, recsize, 0, "cat2"); in cat()
1617 memcpy(s + n1, y->sval, n2); in cat()
1623 z->sval = s; in cat()
1624 z->tval = STR; in cat()
1629 Cell *pastat(Node **a, int n) /* a[0] { a[1] } */ in pastat()
1631 Cell *x; in pastat()
1634 x = execute(a[1]); in pastat()
1639 x = execute(a[1]); in pastat()
1645 Cell *dopa2(Node **a, int n) /* a[0], a[1] { a[2] } */ in dopa2()
1647 Cell *x; in dopa2()
1654 pairstack[pair] = 1; in dopa2()
1657 if (pairstack[pair] == 1) { in dopa2()
1658 x = execute(a[1]); in dopa2()
1668 Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */ in split()
1670 Cell *x = NULL, *y, *ap; in split()
1696 ap = execute(a[1]); /* array name */ in split()
1699 DPRINTF("split: s=|%s|, a=%s, sep=|%s|\n", s, NN(ap->nval), fs); in split()
1700 ap->tval &= ~STR; in split()
1701 ap->tval |= ARR; in split()
1702 ap->sval = (char *) makesymtab(NSYMTAB); in split()
1705 if (arg3type == REGEXPR && strlen((char*)((fa*)a[2])->restr) == 0) { in split()
1711 if (*s != '\0' && (strlen(fs) > 1 || arg3type == REGEXPR)) { /* reg expr */ in split()
1716 pfa = makedfa(fs, 1); in split()
1719 tempstat = pfa->initstat; in split()
1720 pfa->initstat = 2; in split()
1727 setsymtab(num, s, result, STR|NUM, (Array *) ap->sval); in split()
1729 setsymtab(num, s, 0.0, STR, (Array *) ap->sval); in split()
1732 if (*(patbeg+patlen-1) == '\0' || *s == '\0') { in split()
1735 setsymtab(num, "", 0.0, STR, (Array *) ap->sval); in split()
1736 pfa->initstat = tempstat; in split()
1740 pfa->initstat = tempstat; /* bwk: has to be here to reset */ in split()
1746 setsymtab(num, s, result, STR|NUM, (Array *) ap->sval); in split()
1748 setsymtab(num, s, 0.0, STR, (Array *) ap->sval); in split()
1759 if (*s == '"' && s[1] != '\0' && s[1] == '"') { in split()
1762 } else if (*s == '"' && (s[1] == '\0' || s[1] == ',')) { in split()
1777 setsymtab(num, newt, result, STR|NUM, (Array *) ap->sval); in split()
1779 setsymtab(num, newt, 0.0, STR, (Array *) ap->sval); in split()
1801 setsymtab(num, t, result, STR|NUM, (Array *) ap->sval); in split()
1803 setsymtab(num, t, 0.0, STR, (Array *) ap->sval); in split()
1809 } else if (sep == 0) { /* new: split(s, a, "") => 1 char/elem */ in split()
1821 setsymtab(num, buf, atof(buf), STR|NUM, (Array *) ap->sval); in split()
1823 setsymtab(num, buf, 0.0, STR, (Array *) ap->sval); in split()
1836 setsymtab(num, t, result, STR|NUM, (Array *) ap->sval); in split()
1838 setsymtab(num, t, 0.0, STR, (Array *) ap->sval); in split()
1848 x->tval = NUM; in split()
1849 x->fval = n; in split()
1853 Cell *condexpr(Node **a, int n) /* a[0] ? a[1] : a[2] */ in condexpr()
1855 Cell *x; in condexpr()
1860 x = execute(a[1]); in condexpr()
1868 Cell *ifstat(Node **a, int n) /* if (a[0]) a[1]; else a[2] */ in ifstat()
1870 Cell *x; in ifstat()
1875 x = execute(a[1]); in ifstat()
1883 Cell *whilestat(Node **a, int n) /* while (a[0]) a[1] */ in whilestat()
1885 Cell *x; in whilestat()
1892 x = execute(a[1]); in whilestat()
1903 Cell *dostat(Node **a, int n) /* do a[0]; while(a[1]) */ in dostat()
1905 Cell *x; in dostat()
1914 x = execute(a[1]); in dostat()
1921 Cell *forstat(Node **a, int n) /* for (a[0]; a[1]; a[2]) a[3] */ in forstat()
1923 Cell *x; in forstat()
1928 if (a[1]!=NULL) { in forstat()
1929 x = execute(a[1]); in forstat()
1944 Cell *instat(Node **a, int n) /* for (a[0] in a[1]) a[2] */ in instat()
1946 Cell *x, *vp, *arrayp, *cp, *ncp; in instat()
1951 arrayp = execute(a[1]); in instat()
1955 tp = (Array *) arrayp->sval; in instat()
1957 for (i = 0; i < tp->size; i++) { /* this routine knows too much */ in instat()
1958 for (cp = tp->tab[i]; cp != NULL; cp = ncp) { in instat()
1959 setsval(vp, cp->nval); in instat()
1960 ncp = cp->cnext; in instat()
1987 if (sz == 1) { in nawk_convert()
1996 buf = tostringN(s, strlen(s) * sz + 1); in nawk_convert()
2011 n > 0 && n != (size_t)-1 && n != (size_t)-2) in nawk_convert()
2016 if (n == (size_t)-1) in nawk_convert()
2061 Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg list */ in bltin()
2063 Cell *x, *y; in bltin()
2076 x = execute(a[1]); in bltin()
2077 nextarg = a[1]->nnext; in bltin()
2081 u = ((Array *) x->sval)->nelem; /* GROT. should be function*/ in bltin()
2108 y = execute(a[1]->nnext); in bltin()
2111 nextarg = nextarg->nnext; in bltin()
2123 y = execute(a[1]->nnext); in bltin()
2126 nextarg = nextarg->nnext; in bltin()
2134 y = execute(a[1]->nnext); in bltin()
2137 nextarg = nextarg->nnext; in bltin()
2145 y = execute(a[1]->nnext); in bltin()
2148 nextarg = nextarg->nnext; in bltin()
2156 y = execute(a[1]->nnext); in bltin()
2159 nextarg = nextarg->nnext; in bltin()
2167 y = execute(a[1]->nnext); in bltin()
2170 nextarg = nextarg->nnext; in bltin()
2175 if (status != -1) { in bltin()
2187 /* else estatus was set to -1 */ in bltin()
2191 /* random() returns numbers in [0..2^31-1] in bltin()
2192 * in order to get a number in [0, 1), divide it by 2^31 in bltin()
2219 flush_all(); /* fflush() or fflush("") -> all */ in bltin()
2230 &tm->tm_year, &tm->tm_mon, &tm->tm_mday, &tm->tm_hour, in bltin()
2231 &tm->tm_min, &tm->tm_sec, &tm->tm_isdst); in bltin()
2234 tm->tm_isdst = -1; /* let mktime figure it out */ in bltin()
2237 tm->tm_year -= 1900; in bltin()
2238 tm->tm_mon--; in bltin()
2242 u = -1; in bltin()
2253 nextarg = nextarg->nnext; in bltin()
2290 for ( ; nextarg; nextarg = nextarg->nnext) { in bltin()
2298 Cell *printstat(Node **a, int n) /* print a[0] */ in printstat()
2301 Cell *y; in printstat()
2304 if (a[1] == NULL) /* a[1] is redirection operator, a[2] is file */ in printstat()
2307 fp = redirect(ptoi(a[1]), a[2]); in printstat()
2308 for (x = a[0]; x != NULL; x = x->nnext) { in printstat()
2312 if (x->nnext == NULL) in printstat()
2317 if (a[1] != NULL) in printstat()
2324 Cell *nullproc(Node **a, int n) in nullproc()
2333 Cell *x; in redirect()
2362 files[1].fp = stdout; in stdinit()
2363 files[1].fname = tostring("/dev/stdout"); in stdinit()
2364 files[1].mode = GT; in stdinit()
2415 fp = strcmp(s, "-") == 0 ? stdin : fopen(s, "r"); /* "-" is stdin */ in openfile()
2440 Cell *closefile(Node **a, int n) in closefile()
2442 Cell *x; in closefile()
2450 if (!files[i].fname || strcmp(x->sval, files[i].fname) != 0) in closefile()
2465 stat = pclose(files[i].fp) == -1; in closefile()
2477 setfval(x, (Awkfloat) (stat ? -1 : 0)); in closefile()
2502 stat = pclose(files[i].fp) == -1; in closeall()
2521 Cell *dosub(Node **a, int subop) /* sub and gsub */ in dosub()
2526 Cell *x; in dosub()
2539 if (a[0] == NULL) { /* 0 => a[1] is already-compiled regexpr */ in dosub()
2540 pfa = (fa *) a[1]; in dosub()
2542 x = execute(a[1]); in dosub()
2543 pfa = makedfa(getsval(x), 1); in dosub()
2553 whichm = 1; in dosub()
2569 tempstat = pfa->initstat; in dosub()
2570 pfa->initstat = 2; in dosub()
2575 #define MT_INSERT 1 /* selected, empty */ in dosub()
2590 adjbuf(&buf, &bufsz, (pb - buf) + (patbeg - start), in dosub()
2602 adjbuf(&buf, &bufsz, 5+pb-buf, recsize, &pb, "dosub"); in dosub()
2607 adjbuf(&buf, &bufsz, 1+patlen+pb-buf, recsize, in dosub()
2622 adjbuf(&buf, &bufsz, (pb-buf) + patlen, recsize, &pb, "dosub"); in dosub()
2642 pfa->initstat = tempstat; in dosub()
2645 adjbuf(&buf, &bufsz, 1+strlen(start)+pb-buf, 0, &pb, "dosub"); in dosub()
2655 x->tval = NUM; in dosub()
2656 x->fval = m; in dosub()
2660 Cell *gensub(Node **a, int nnn) /* global selective substitute */ in gensub()
2661 /* XXX incomplete - doesn't support backreferences \0 ... \9 */ in gensub()
2663 Cell *x, *y, *res, *h; in gensub()
2678 res = copycell(x); /* target string - initially copy of source */ in gensub()
2679 res->csub = CTEMP; /* result values are temporary */ in gensub()
2680 if (a[0] == 0) /* 0 => a[1] is already-compiled regexpr */ in gensub()
2681 pfa = (fa *) a[1]; /* regular expression */ in gensub()
2683 y = execute(a[1]); in gensub()
2684 pfa = makedfa(getsval(y), 1); in gensub()
2691 whichm = -1; in gensub()
2695 * from 1. GNU awk treats index lower than 0 same as in gensub()
2696 * 1, we do same for compatibility. in gensub()
2698 whichm = (int) getfval(h) - 1; in gensub()
2707 tempstat = pfa->initstat; in gensub()
2708 pfa->initstat = 2; in gensub()
2715 for (sl = rptr; (sl = strchr(sl, '\\')) && sl[1]; sl++) { in gensub()
2716 if (strchr("0123456789", sl[1])) { in gensub()
2724 adjbuf(&buf, &bufsz, (pb - buf) + (patbeg - t) + patlen, recsize, &pb, "gensub"); in gensub()
2738 adjbuf(&buf, &bufsz, 5+pb-buf, recsize, &pb, "gensub"); in gensub()
2743 adjbuf(&buf, &bufsz, 1+patlen+pb-buf, recsize, &pb, "gensub"); in gensub()
2752 adjbuf(&buf, &bufsz, 2+pb-buf, recsize, &pb, "gensub"); in gensub()
2761 adjbuf(&buf, &bufsz, 1+(patbeg-sptr)+pb-buf, recsize, &pb, "gensub"); in gensub()
2766 adjbuf(&buf, &bufsz, 5+pb-buf, recsize, &pb, "gensub"); in gensub()
2771 adjbuf(&buf, &bufsz, 1+patlen+pb-buf, recsize, &pb, "gensub"); in gensub()
2778 if (patlen == 0 || *t == 0 || *(t-1) == 0) in gensub()
2782 mflag = 1; in gensub()
2786 adjbuf(&buf, &bufsz, 1+strlen(sptr)+pb-buf, 0, &pb, "gensub"); in gensub()
2793 pfa->initstat = tempstat; in gensub()
2813 if (sptr[1] == '\\') { in backsub()
2814 if (sptr[2] == '\\' && sptr[3] == '&') { /* \\\& -> \& */ in backsub()
2818 } else if (sptr[2] == '&') { /* \\& -> \ + matched */ in backsub()
2821 } else if (do_posix) { /* \\x -> \x */ in backsub()
2824 } else { /* \\x -> \\x */ in backsub()
2828 } else if (sptr[1] == '&') { /* literal & */ in backsub()
2862 // 0x00010000 - 0x10FFFF in wide_char_to_byte_str()