Lines Matching +full:1 +full:- +full:cell

48 #if 1
51 void tempfree(Cell *p) { in tempfree()
52 if (p->ctype == OCELL && (p->csub < CUNK || p->csub > CFREE)) { in tempfree()
53 WARNING("bad csub %d in Cell %d %s", in tempfree()
54 p->csub, p->ctype, p->sval); in tempfree()
81 Cell *tmps; /* free temporary cells for execution */
83 static Cell truecell ={ OBOOL, BTRUE, 0, 0, 1.0, NUM, NULL, NULL };
84 Cell *True = &truecell;
85 static Cell falsecell ={ OBOOL, BFALSE, 0, 0, 0.0, NUM, NULL, NULL };
86 Cell *False = &falsecell;
87 static Cell breakcell ={ OJUMP, JBREAK, 0, 0, 0.0, NUM, NULL, NULL };
88 Cell *jbreak = &breakcell;
89 static Cell contcell ={ OJUMP, JCONT, 0, 0, 0.0, NUM, NULL, NULL };
90 Cell *jcont = &contcell;
91 static Cell nextcell ={ OJUMP, JNEXT, 0, 0, 0.0, NUM, NULL, NULL };
92 Cell *jnext = &nextcell;
93 static Cell nextfilecell ={ OJUMP, JNEXTFILE, 0, 0, 0.0, NUM, NULL, NULL };
94 Cell *jnextfile = &nextfilecell;
95 static Cell exitcell ={ OJUMP, JEXIT, 0, 0, 0.0, NUM, NULL, NULL };
96 Cell *jexit = &exitcell;
97 static Cell retcell ={ OJUMP, JRET, 0, 0, 0.0, NUM, NULL, NULL };
98 Cell *jret = &retcell;
99 static Cell tempcell ={ OCELL, CTEMP, 0, EMPTY, 0.0, NUM|STR|DONTFREE, NULL, NULL };
119 int boff = pbptr ? *pbptr - *pbuf : 0; in adjbuf()
122 minlen += quantum - rminlen; in adjbuf()
135 return 1; in adjbuf()
146 Cell *execute(Node *u) /* execute a node of the parse tree */ in execute()
148 Cell *(*proc)(Node **, int); in execute()
149 Cell *x; in execute()
154 for (a = u; ; a = a->nnext) { in execute()
157 x = (Cell *) (a->narg[0]); in execute()
164 if (notlegal(a->nobj)) /* probably a Cell* but too risky to print */ in execute()
166 proc = proctab[a->nobj-FIRSTTOKEN]; in execute()
167 x = (*proc)(a->narg, a->nobj); in execute()
176 if (a->nnext == NULL) in execute()
183 Cell *program(Node **a, int n) /* execute an awk program */ in program()
184 { /* a[0] = BEGIN, a[1] = body, a[2] = END */ in program()
185 Cell *x; in program()
197 if (a[1] || a[2]) in program()
199 x = execute(a[1]); in program()
219 Cell *fcncell; /* pointer to Cell for function */
220 Cell **args; /* pointer to array of arguments after execute */
221 Cell *retval; /* return value */
230 Cell *call(Node **a, int n) /* function call. very kludgy and fragile */ in call()
232 static const Cell newcopycell = { OCELL, CCOPY, 0, EMPTY, 0.0, NUM|STR|DONTFREE, NULL, NULL }; in call()
236 Cell *args[NARGS], *oargs[NARGS]; /* BUG: fixed size arrays */ in call()
237 Cell *y, *z, *fcn; in call()
241 s = fcn->nval; in call()
249 for (ncall = 0, x = a[1]; x != NULL; x = x->nnext) /* args in call */ in call()
251 ndef = (int) fcn->fval; /* args in defn */ in call()
252 DPRINTF("calling %s, %d args (%d in defn), frp=%d\n", s, ncall, ndef, (int) (frp-frame)); in call()
258 for (i = 0, x = a[1]; x != NULL; i++, x = x->nnext) { /* get call args */ in call()
259 DPRINTF("evaluate args[%d], frp=%d:\n", i, (int) (frp-frame)); in call()
263 i, NN(y->nval), y->fval, isarr(y) ? "(array)" : NN(y->sval), y->tval); in call()
265 FATAL("can't use function %s as argument in %s", y->nval, s); in call()
278 int dfp = frp - frame; /* old index */ in call()
284 frp->fcncell = fcn; in call()
285 frp->args = args; in call()
286 frp->nargs = ndef; /* number defined with (excess are locals) */ in call()
287 frp->retval = gettemp(); in call()
289 DPRINTF("start exec of %s, frp=%d\n", s, (int) (frp-frame)); in call()
290 y = execute((Node *)(fcn->sval)); /* execute body */ in call()
291 DPRINTF("finished exec of %s, frp=%d\n", s, (int) (frp-frame)); in call()
294 Cell *t = frp->args[i]; in call()
296 if (t->csub == CCOPY) { in call()
299 t->csub = CTEMP; in call()
302 oargs[i]->tval = t->tval; in call()
303 oargs[i]->tval &= ~(STR|NUM|DONTFREE); in call()
304 oargs[i]->sval = t->sval; in call()
309 t->csub = CTEMP; in call()
311 } else if (t == y && t->csub == CCOPY) { in call()
312 t->csub = CTEMP; in call()
314 freed = 1; in call()
323 z = frp->retval; /* return value */ in call()
324 DPRINTF("%s returns %g |%s| %o\n", s, getfval(z), getsval(z), z->tval); in call()
325 frp--; in call()
329 Cell *copycell(Cell *x) /* make a copy of a cell in a temp */ in copycell()
331 Cell *y; in copycell()
336 y->tval = x->tval & ~(CON|FLD|REC); in copycell()
337 y->csub = CCOPY; /* prevents freeing until call is over */ in copycell()
338 y->nval = x->nval; /* BUG? */ in copycell()
339 if (isstr(x) /* || x->ctype == OCELL */) { in copycell()
340 y->sval = tostring(x->sval); in copycell()
341 y->tval &= ~DONTFREE; in copycell()
343 y->tval |= DONTFREE; in copycell()
344 y->fval = x->fval; in copycell()
348 Cell *arg(Node **a, int n) /* nth argument of a function */ in arg()
352 DPRINTF("arg(%d), frp->nargs=%d\n", n, frp->nargs); in arg()
353 if (n+1 > frp->nargs) in arg()
355 n+1, frp->fcncell->nval); in arg()
356 return frp->args[n]; in arg()
359 Cell *jump(Node **a, int n) /* break, continue, next, nextfile, return */ in jump()
361 Cell *y; in jump()
370 longjmp(env, 1); in jump()
374 if ((y->tval & (STR|NUM)) == (STR|NUM)) { in jump()
375 setsval(frp->retval, getsval(y)); in jump()
376 frp->retval->fval = getfval(y); in jump()
377 frp->retval->tval |= NUM; in jump()
379 else if (y->tval & STR) in jump()
380 setsval(frp->retval, getsval(y)); in jump()
381 else if (y->tval & NUM) in jump()
382 setfval(frp->retval, getfval(y)); in jump()
384 FATAL("bad type variable %d", y->tval); in jump()
403 Cell *awkgetline(Node **a, int n) /* get next line from specific input */ in awkgetline()
404 { /* a[0] is variable, a[1] is operator, a[2] is filename */ in awkgetline()
405 Cell *r, *x; in awkgetline()
406 extern Cell **fldtab; in awkgetline()
419 if (a[1] != NULL) { /* getline < file */ in awkgetline()
421 mode = ptoi(a[1]); in awkgetline()
427 n = -1; in awkgetline()
435 if (is_number(x->sval, & result)) { in awkgetline()
436 x->fval = result; in awkgetline()
437 x->tval |= NUM; in awkgetline()
442 if (is_number(fldtab[0]->sval, & result)) { in awkgetline()
443 fldtab[0]->fval = result; in awkgetline()
444 fldtab[0]->tval |= NUM; in awkgetline()
455 if (is_number(x->sval, & result)) { in awkgetline()
456 x->fval = result; in awkgetline()
457 x->tval |= NUM; in awkgetline()
468 Cell *getnf(Node **a, int n) /* get NF */ in getnf()
472 return (Cell *) a[0]; in getnf()
489 for (; p; p = p->nnext) { in makearraystring()
490 Cell *x = execute(p); /* expr */ in makearraystring()
493 size_t nsub = p->nnext ? seplen : 0; in makearraystring()
497 if (!adjbuf(&buf, &bufsz, tlen + 1, recsize, 0, func)) { in makearraystring()
499 func, x->nval, buf); in makearraystring()
512 Cell *array(Node **a, int n) /* a[0] is symtab, a[1] is list of subscripts */ in array()
514 Cell *x, *z; in array()
517 x = execute(a[0]); /* Cell* for symbol table */ in array()
518 buf = makearraystring(a[1], __func__); in array()
520 DPRINTF("making %s into an array\n", NN(x->nval)); in array()
522 xfree(x->sval); in array()
523 x->tval &= ~(STR|NUM|DONTFREE); in array()
524 x->tval |= ARR; in array()
525 x->sval = (char *) makesymtab(NSYMTAB); in array()
527 z = setsymtab(buf, "", 0.0, STR|NUM, (Array *) x->sval); in array()
528 z->ctype = OCELL; in array()
529 z->csub = CVAR; in array()
535 Cell *awkdelete(Node **a, int n) /* a[0] is symtab, a[1] is list of subscripts */ in awkdelete()
537 Cell *x; in awkdelete()
539 x = execute(a[0]); /* Cell* for symbol table */ in awkdelete()
545 if (a[1] == NULL) { /* delete the elements, not the table */ in awkdelete()
547 x->tval &= ~STR; in awkdelete()
548 x->tval |= ARR; in awkdelete()
549 x->sval = (char *) makesymtab(NSYMTAB); in awkdelete()
551 char *buf = makearraystring(a[1], __func__); in awkdelete()
559 Cell *intest(Node **a, int n) /* a[0] is index (list), a[1] is symtab */ in intest()
561 Cell *ap, *k; in intest()
564 ap = execute(a[1]); /* array name */ in intest()
566 DPRINTF("making %s into an array\n", ap->nval); in intest()
568 xfree(ap->sval); in intest()
569 ap->tval &= ~(STR|NUM|DONTFREE); in intest()
570 ap->tval |= ARR; in intest()
571 ap->sval = (char *) makesymtab(NSYMTAB); in intest()
574 k = lookup(buf, (Array *) ap->sval); in intest()
584 /* ======== utf-8 code ========== */
587 * Awk strings can contain ascii, random 8-bit items (eg Latin-1),
588 * or utf-8. u8_isutf tests whether a string starts with a valid
589 * utf-8 sequence, and returns 0 if not (e.g., high bit set).
591 * 1 for ascii, 2..4 for utf-8, or 1 for high bit non-utf.
592 * u8_strlen returns length of string in valid utf-8 sequences
593 * and/or high-bit bytes. Conversion functions go between byte
596 * In theory, this behaves the same as before for non-utf8 bytes.
601 /* is s the beginning of a valid utf-8 string? */
602 /* return length 1..4 if yes, 0 if no */
609 if (c < 128 || awk_mb_cur_max == 1) in u8_isutf()
610 return 1; /* what if it's 0? */ in u8_isutf()
613 if (n >= 2 && ((c>>5) & 0x7) == 0x6 && (s[1] & 0xC0) == 0x80) { in u8_isutf()
615 } else if (n >= 3 && ((c>>4) & 0xF) == 0xE && (s[1] & 0xC0) == 0x80 in u8_isutf()
618 } else if (n >= 4 && ((c>>3) & 0x1F) == 0x1E && (s[1] & 0xC0) == 0x80 in u8_isutf()
627 /* Convert (prefix of) utf8 string to utf-32 rune. */
636 if (c < 128 || awk_mb_cur_max == 1) { in u8_rune()
638 return 1; in u8_rune()
642 if (n >= 2 && ((c>>5) & 0x7) == 0x6 && (s[1] & 0xC0) == 0x80) { in u8_rune()
643 *rune = ((c & 0x1F) << 6) | (s[1] & 0x3F); /* 110xxxxx 10xxxxxx */ in u8_rune()
645 } else if (n >= 3 && ((c>>4) & 0xF) == 0xE && (s[1] & 0xC0) == 0x80 in u8_rune()
647 *rune = ((c & 0xF) << 12) | ((s[1] & 0x3F) << 6) | (s[2] & 0x3F); in u8_rune()
650 } else if (n >= 4 && ((c>>3) & 0x1F) == 0x1E && (s[1] & 0xC0) == 0x80 in u8_rune()
652 *rune = ((c & 0x7) << 18) | ((s[1] & 0x3F) << 12) | ((s[2] & 0x3F) << 6) | (s[3] & 0x3F); in u8_rune()
657 ret = 1; in u8_rune()
662 /* return length of next sequence: 1 for ascii or random, 2..4 for valid utf8 */
669 len = 1; in u8_nextlen()
673 /* return number of utf characters or single non-utf bytes */
683 if (c < 128 || awk_mb_cur_max == 1) { in u8_strlen()
684 len = 1; in u8_strlen()
695 /* convert utf-8 char number in a string to its byte offset */
705 charnum--; in u8_char2byte()
710 /* convert byte offset in s to utf-8 char number that starts there */
719 return -1; /* ??? */ in u8_byte2char()
742 T1 = ((1<<(Bit1+1))-1) ^ 0xFF, /* 0000 0000 */
743 Tx = ((1<<(Bitx+1))-1) ^ 0xFF, /* 1000 0000 */
744 T2 = ((1<<(Bit2+1))-1) ^ 0xFF, /* 1100 0000 */
745 T3 = ((1<<(Bit3+1))-1) ^ 0xFF, /* 1110 0000 */
746 T4 = ((1<<(Bit4+1))-1) ^ 0xFF, /* 1111 0000 */
747 T5 = ((1<<(Bit5+1))-1) ^ 0xFF, /* 1111 1000 */
749 Rune1 = (1<<(Bit1+0*Bitx))-1, /* 0000 0000 0000 0000 0111 1111 */
750 Rune2 = (1<<(Bit2+1*Bitx))-1, /* 0000 0000 0000 0111 1111 1111 */
751 Rune3 = (1<<(Bit3+2*Bitx))-1, /* 0000 0000 1111 1111 1111 1111 */
752 Rune4 = (1<<(Bit4+3*Bitx))-1, /* 0011 1111 1111 1111 1111 1111 */
754 Maskx = (1<<Bitx)-1, /* 0011 1111 */
761 /* one character sequence 00000-0007F => 00-7F */ in runetochar()
764 return 1; in runetochar()
767 /* two character sequence 00080-007FF => T2 Tx */ in runetochar()
769 str[0] = T2 | (c >> 1*Bitx); in runetochar()
770 str[1] = Tx | (c & Maskx); in runetochar()
774 /* three character sequence 00800-0FFFF => T3 Tx Tx */ in runetochar()
779 str[1] = Tx | ((c >> 1*Bitx) & Maskx); in runetochar()
784 /* four character sequence 010000-1FFFFF => T4 Tx Tx Tx */ in runetochar()
786 str[1] = Tx | ((c >> 2*Bitx) & Maskx); in runetochar()
787 str[2] = Tx | ((c >> 1*Bitx) & Maskx); in runetochar()
797 Cell *matchop(Node **a, int n) /* ~ and match() */ in matchop()
799 Cell *x, *y, *z; in matchop()
808 mode = 1; in matchop()
810 x = execute(a[1]); /* a[1] = target text */ in matchop()
812 if (a[0] == NULL) /* a[1] == 0: already-compiled reg expr */ in matchop()
823 int start = patbeg - s + 1; /* origin 1 */ in matchop()
827 cstart = u8_byte2char(s, start-1); in matchop()
841 x->tval = NUM; in matchop()
842 x->fval = start; in matchop()
843 } else if ((n == MATCH && i == 1) || (n == NOTMATCH && i == 0)) in matchop()
853 Cell *boolop(Node **a, int n) /* a[0] || a[1], a[0] && a[1], !a[0] */ in boolop()
855 Cell *x, *y; in boolop()
864 y = execute(a[1]); in boolop()
871 y = execute(a[1]); in boolop()
885 Cell *relop(Node **a, int n) /* a[0 < a[1], etc. */ in relop()
888 Cell *x, *y; in relop()
893 y = execute(a[1]); in relop()
894 x_is_nan = isnan(x->fval); in relop()
895 y_is_nan = isnan(y->fval); in relop()
896 if (x->tval&NUM && y->tval&NUM) { in relop()
899 j = x->fval - y->fval; in relop()
900 i = j<0? -1: (j>0? 1: 0); in relop()
926 void tfree(Cell *a) /* free a tempcell */ in tfree()
929 DPRINTF("freeing %s %s %o\n", NN(a->nval), NN(a->sval), a->tval); in tfree()
930 xfree(a->sval); in tfree()
934 a->cnext = tmps; in tfree()
938 Cell *gettemp(void) /* get a tempcell */ in gettemp()
940 Cell *x; in gettemp()
943 tmps = (Cell *) calloc(100, sizeof(*tmps)); in gettemp()
946 for (i = 1; i < 100; i++) in gettemp()
947 tmps[i-1].cnext = &tmps[i]; in gettemp()
948 tmps[i-1].cnext = NULL; in gettemp()
951 tmps = x->cnext; in gettemp()
956 Cell *indirect(Node **a, int n) /* $( a[0] ) */ in indirect()
959 Cell *x; in indirect()
965 FATAL("trying to access out of range field %s", x->nval); in indirect()
969 x->ctype = OCELL; /* BUG? why are these needed? */ in indirect()
970 x->csub = CFLD; in indirect()
974 Cell *substr(Node **a, int nnn) /* substr(a[0], a[1], a[2]) */ in substr()
980 Cell *x, *y, *z = NULL; in substr()
983 y = execute(a[1]); in substr()
987 k = u8_strlen(s) + 1; in substr()
988 if (k <= 1) { in substr()
1000 m = 1; in substr()
1008 n = k - 1; in substr()
1011 else if (n > k - m) in substr()
1012 n = k - m; in substr()
1016 mb = u8_char2byte(s, m-1); /* byte offset of start char in s */ in substr()
1017 nb = u8_char2byte(s, m-1+n); /* byte offset of end+1 char in s */ in substr()
1027 Cell *sindex(Node **a, int nnn) /* index(a[0], a[1]) */ in sindex()
1029 Cell *x, *y, *z; in sindex()
1035 y = execute(a[1]); in sindex()
1043 /* v = (Awkfloat) (p1 - s1 + 1); origin 1 */ in sindex()
1048 for (i = 0; i < p1-s1+1; i += len) { in sindex()
1061 int has_utf8(char *s) /* return 1 if s contains any utf-8 (2 bytes or more) character */ in has_utf8()
1067 if (n > 1) in has_utf8()
1068 return 1; in has_utf8()
1075 int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like conversions */ in format()
1080 Cell *x; in format()
1086 #define FMTSZ(a) (fmtsz - ((a) - fmt)) in format()
1087 #define BUFSZ(a) (bufsize - ((a) - buf)) in format()
1105 adjbuf(&buf, &bufsize, MAXNUMSIZE+1+p-buf, recsize, &p, "format1"); in format()
1110 if (*(s+1) == '%') { in format()
1115 fmtwd = atoi(s+1); in format()
1117 fmtwd = -fmtwd; in format()
1118 adjbuf(&buf, &bufsize, fmtwd+1+p-buf, recsize, &p, "format2"); in format()
1120 if (!adjbuf(&fmt, &fmtsz, MAXNUMSIZE+1+t-fmt, recsize, &t, "format3")) in format()
1124 t--; in format()
1137 a = a->nnext; in format()
1138 snprintf(t - 1, FMTSZ(t - 1), in format()
1141 fmtwd = -fmtwd; in format()
1142 adjbuf(&buf, &bufsize, fmtwd+1+p-buf, recsize, &p, "format"); in format()
1149 fmtwd = -fmtwd; in format()
1150 adjbuf(&buf, &bufsize, fmtwd+1+p-buf, recsize, &p, "format4"); in format()
1163 *(t-1) = 'j'; in format()
1181 a = a->nnext; in format()
1185 adjbuf(&buf, &bufsize, 1+n+p-buf, recsize, &p, "format5"); in format()
1193 adjbuf(&buf, &bufsize, 1+strlen(p)+n+p-buf, recsize, &p, "format6"); in format()
1206 /* if simple format or no utf-8 in the string, sprintf works */ in format()
1210 if (!adjbuf(&buf, &bufsize, 1+n+p-buf, recsize, &p, "format7")) in format()
1217 /* get here if string has utf-8 chars and fmt is not plain %s */ in format()
1218 /* "%-w.ps", where -, w and .p are all optional */ in format()
1222 char *f = fmt+1; in format()
1223 if (f[0] == '-') { in format()
1224 ljust = 1; in format()
1246 pad = wid>prec ? wid - prec : 0; // has to be >= 0 in format()
1283 * our best to convert it back into UTF-8. If we in format()
1291 if (charval < 128 || awk_mb_cur_max == 1) in format()
1324 char *f = fmt+1; in format()
1325 if (f[0] == '-') { in format()
1326 ljust = 1; in format()
1346 if (prec > 1) // %c --> only one character in format()
1347 prec = 1; in format()
1348 pad = wid>prec ? wid - prec : 0; // has to be >= 0 in format()
1379 for ( ; a; a = a->nnext) { /* evaluate any remaining args */ in format()
1385 return p - buf; in format()
1388 Cell *awksprintf(Node **a, int n) /* sprintf(a[0]) */ in awksprintf()
1390 Cell *x; in awksprintf()
1397 y = a[0]->nnext; in awksprintf()
1399 if (format(&buf, &bufsz, getsval(x), y) == -1) in awksprintf()
1403 x->sval = buf; in awksprintf()
1404 x->tval = STR; in awksprintf()
1408 Cell *awkprintf(Node **a, int n) /* printf */ in awkprintf()
1410 /* a[1] is redirection operator, a[2] is redirection file */ in awkprintf()
1412 Cell *x; in awkprintf()
1420 y = a[0]->nnext; in awkprintf()
1422 if ((len = format(&buf, &bufsz, getsval(x), y)) == -1) in awkprintf()
1425 if (a[1] == NULL) { in awkprintf()
1427 fwrite(buf, len, 1, stdout); in awkprintf()
1431 fp = redirect(ptoi(a[1]), a[2]); in awkprintf()
1433 fwrite(buf, len, 1, fp); in awkprintf()
1442 Cell *arith(Node **a, int n) /* a[0] + a[1], etc. also -a[0] */ in arith()
1446 Cell *x, *y, *z; in arith()
1452 y = execute(a[1]); in arith()
1462 i -= j; in arith()
1476 i = i - j * v; in arith()
1479 i = -i; in arith()
1503 return 1; in ipow()
1511 Cell *incrdecr(Node **a, int n) /* a[0]++, etc. */ in incrdecr()
1513 Cell *x, *z; in incrdecr()
1519 k = (n == PREINCR || n == POSTINCR) ? 1 : -1; in incrdecr()
1531 Cell *assign(Node **a, int n) /* a[0] = a[1], a[0] += a[1], etc. */ in assign()
1533 Cell *x, *y; in assign()
1537 y = execute(a[1]); in assign()
1540 if (x == y && !(x->tval & (FLD|REC)) && x != nfloc) in assign()
1541 ; /* self-assignment: leave alone unless it's a field or NF */ in assign()
1542 else if ((y->tval & (STR|NUM)) == (STR|NUM)) { in assign()
1545 x->fval = yf; in assign()
1546 x->tval |= NUM; in assign()
1564 xf -= yf; in assign()
1578 xf = xf - yf * v; in assign()
1597 Cell *cat(Node **a, int q) /* a[0] cat a[1] */ in cat()
1599 Cell *x, *y, *z; in cat()
1606 adjbuf(&s, &ssz, n1 + 1, recsize, 0, "cat1"); in cat()
1607 memcpy(s, x->sval, n1); in cat()
1611 y = execute(a[1]); in cat()
1613 adjbuf(&s, &ssz, n1 + n2 + 1, recsize, 0, "cat2"); in cat()
1614 memcpy(s + n1, y->sval, n2); in cat()
1620 z->sval = s; in cat()
1621 z->tval = STR; in cat()
1626 Cell *pastat(Node **a, int n) /* a[0] { a[1] } */ in pastat()
1628 Cell *x; in pastat()
1631 x = execute(a[1]); in pastat()
1636 x = execute(a[1]); in pastat()
1642 Cell *dopa2(Node **a, int n) /* a[0], a[1] { a[2] } */ in dopa2()
1644 Cell *x; in dopa2()
1651 pairstack[pair] = 1; in dopa2()
1654 if (pairstack[pair] == 1) { in dopa2()
1655 x = execute(a[1]); in dopa2()
1665 Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */ in split()
1667 Cell *x = NULL, *y, *ap; in split()
1693 ap = execute(a[1]); /* array name */ in split()
1696 DPRINTF("split: s=|%s|, a=%s, sep=|%s|\n", s, NN(ap->nval), fs); in split()
1697 ap->tval &= ~STR; in split()
1698 ap->tval |= ARR; in split()
1699 ap->sval = (char *) makesymtab(NSYMTAB); in split()
1702 if (arg3type == REGEXPR && strlen((char*)((fa*)a[2])->restr) == 0) { in split()
1708 if (*s != '\0' && (strlen(fs) > 1 || arg3type == REGEXPR)) { /* reg expr */ in split()
1713 pfa = makedfa(fs, 1); in split()
1716 tempstat = pfa->initstat; in split()
1717 pfa->initstat = 2; in split()
1724 setsymtab(num, s, result, STR|NUM, (Array *) ap->sval); in split()
1726 setsymtab(num, s, 0.0, STR, (Array *) ap->sval); in split()
1729 if (*(patbeg+patlen-1) == '\0' || *s == '\0') { in split()
1732 setsymtab(num, "", 0.0, STR, (Array *) ap->sval); in split()
1733 pfa->initstat = tempstat; in split()
1737 pfa->initstat = tempstat; /* bwk: has to be here to reset */ in split()
1743 setsymtab(num, s, result, STR|NUM, (Array *) ap->sval); in split()
1745 setsymtab(num, s, 0.0, STR, (Array *) ap->sval); in split()
1756 if (*s == '"' && s[1] != '\0' && s[1] == '"') { in split()
1759 } else if (*s == '"' && (s[1] == '\0' || s[1] == ',')) { in split()
1774 setsymtab(num, newt, result, STR|NUM, (Array *) ap->sval); in split()
1776 setsymtab(num, newt, 0.0, STR, (Array *) ap->sval); in split()
1798 setsymtab(num, t, result, STR|NUM, (Array *) ap->sval); in split()
1800 setsymtab(num, t, 0.0, STR, (Array *) ap->sval); in split()
1806 } else if (sep == 0) { /* new: split(s, a, "") => 1 char/elem */ in split()
1818 setsymtab(num, buf, atof(buf), STR|NUM, (Array *) ap->sval); in split()
1820 setsymtab(num, buf, 0.0, STR, (Array *) ap->sval); in split()
1833 setsymtab(num, t, result, STR|NUM, (Array *) ap->sval); in split()
1835 setsymtab(num, t, 0.0, STR, (Array *) ap->sval); in split()
1845 x->tval = NUM; in split()
1846 x->fval = n; in split()
1850 Cell *condexpr(Node **a, int n) /* a[0] ? a[1] : a[2] */ in condexpr()
1852 Cell *x; in condexpr()
1857 x = execute(a[1]); in condexpr()
1865 Cell *ifstat(Node **a, int n) /* if (a[0]) a[1]; else a[2] */ in ifstat()
1867 Cell *x; in ifstat()
1872 x = execute(a[1]); in ifstat()
1880 Cell *whilestat(Node **a, int n) /* while (a[0]) a[1] */ in whilestat()
1882 Cell *x; in whilestat()
1889 x = execute(a[1]); in whilestat()
1900 Cell *dostat(Node **a, int n) /* do a[0]; while(a[1]) */ in dostat()
1902 Cell *x; in dostat()
1911 x = execute(a[1]); in dostat()
1918 Cell *forstat(Node **a, int n) /* for (a[0]; a[1]; a[2]) a[3] */ in forstat()
1920 Cell *x; in forstat()
1925 if (a[1]!=NULL) { in forstat()
1926 x = execute(a[1]); in forstat()
1941 Cell *instat(Node **a, int n) /* for (a[0] in a[1]) a[2] */ in instat()
1943 Cell *x, *vp, *arrayp, *cp, *ncp; in instat()
1948 arrayp = execute(a[1]); in instat()
1952 tp = (Array *) arrayp->sval; in instat()
1954 for (i = 0; i < tp->size; i++) { /* this routine knows too much */ in instat()
1955 for (cp = tp->tab[i]; cp != NULL; cp = ncp) { in instat()
1956 setsval(vp, cp->nval); in instat()
1957 ncp = cp->cnext; in instat()
1984 if (sz == 1) { in nawk_convert()
1993 buf = tostringN(s, strlen(s) * sz + 1); in nawk_convert()
2008 n > 0 && n != (size_t)-1 && n != (size_t)-2) in nawk_convert()
2013 if (n == (size_t)-1) in nawk_convert()
2058 Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg list */ in bltin()
2060 Cell *x, *y; in bltin()
2073 x = execute(a[1]); in bltin()
2074 nextarg = a[1]->nnext; in bltin()
2078 u = ((Array *) x->sval)->nelem; /* GROT. should be function*/ in bltin()
2105 y = execute(a[1]->nnext); in bltin()
2108 nextarg = nextarg->nnext; in bltin()
2120 y = execute(a[1]->nnext); in bltin()
2123 nextarg = nextarg->nnext; in bltin()
2131 y = execute(a[1]->nnext); in bltin()
2134 nextarg = nextarg->nnext; in bltin()
2142 y = execute(a[1]->nnext); in bltin()
2145 nextarg = nextarg->nnext; in bltin()
2153 y = execute(a[1]->nnext); in bltin()
2156 nextarg = nextarg->nnext; in bltin()
2164 y = execute(a[1]->nnext); in bltin()
2167 nextarg = nextarg->nnext; in bltin()
2172 if (status != -1) { in bltin()
2184 /* else estatus was set to -1 */ in bltin()
2188 /* random() returns numbers in [0..2^31-1] in bltin()
2189 * in order to get a number in [0, 1), divide it by 2^31 in bltin()
2216 flush_all(); /* fflush() or fflush("") -> all */ in bltin()
2227 &tm->tm_year, &tm->tm_mon, &tm->tm_mday, &tm->tm_hour, in bltin()
2228 &tm->tm_min, &tm->tm_sec, &tm->tm_isdst); in bltin()
2231 tm->tm_isdst = -1; /* let mktime figure it out */ in bltin()
2234 tm->tm_year -= 1900; in bltin()
2235 tm->tm_mon--; in bltin()
2239 u = -1; in bltin()
2250 nextarg = nextarg->nnext; in bltin()
2287 for ( ; nextarg; nextarg = nextarg->nnext) { in bltin()
2295 Cell *printstat(Node **a, int n) /* print a[0] */ in printstat()
2298 Cell *y; in printstat()
2301 if (a[1] == NULL) /* a[1] is redirection operator, a[2] is file */ in printstat()
2304 fp = redirect(ptoi(a[1]), a[2]); in printstat()
2305 for (x = a[0]; x != NULL; x = x->nnext) { in printstat()
2309 if (x->nnext == NULL) in printstat()
2314 if (a[1] != NULL) in printstat()
2321 Cell *nullproc(Node **a, int n) in nullproc()
2330 Cell *x; in redirect()
2359 files[1].fp = stdout; in stdinit()
2360 files[1].fname = tostring("/dev/stdout"); in stdinit()
2361 files[1].mode = GT; in stdinit()
2420 fp = strcmp(s, "-") == 0 ? stdin : fopen(s, "r"); /* "-" is stdin */ in openfile()
2445 Cell *closefile(Node **a, int n) in closefile()
2447 Cell *x; in closefile()
2455 if (!files[i].fname || strcmp(x->sval, files[i].fname) != 0) in closefile()
2470 stat = pclose(files[i].fp) == -1; in closefile()
2482 setfval(x, (Awkfloat) (stat ? -1 : 0)); in closefile()
2507 stat = pclose(files[i].fp) == -1; in closeall()
2526 Cell *dosub(Node **a, int subop) /* sub and gsub */ in dosub()
2531 Cell *x; in dosub()
2544 if (a[0] == NULL) { /* 0 => a[1] is already-compiled regexpr */ in dosub()
2545 pfa = (fa *) a[1]; in dosub()
2547 x = execute(a[1]); in dosub()
2548 pfa = makedfa(getsval(x), 1); in dosub()
2558 whichm = 1; in dosub()
2574 tempstat = pfa->initstat; in dosub()
2575 pfa->initstat = 2; in dosub()
2580 #define MT_INSERT 1 /* selected, empty */ in dosub()
2595 adjbuf(&buf, &bufsz, (pb - buf) + (patbeg - start), in dosub()
2607 adjbuf(&buf, &bufsz, 5+pb-buf, recsize, &pb, "dosub"); in dosub()
2612 adjbuf(&buf, &bufsz, 1+patlen+pb-buf, recsize, in dosub()
2627 adjbuf(&buf, &bufsz, (pb-buf) + patlen, recsize, &pb, "dosub"); in dosub()
2647 pfa->initstat = tempstat; in dosub()
2650 adjbuf(&buf, &bufsz, 1+strlen(start)+pb-buf, 0, &pb, "dosub"); in dosub()
2660 x->tval = NUM; in dosub()
2661 x->fval = m; in dosub()
2665 Cell *gensub(Node **a, int nnn) /* global selective substitute */ in gensub()
2666 /* XXX incomplete - doesn't support backreferences \0 ... \9 */ in gensub()
2668 Cell *x, *y, *res, *h; in gensub()
2683 res = copycell(x); /* target string - initially copy of source */ in gensub()
2684 res->csub = CTEMP; /* result values are temporary */ in gensub()
2685 if (a[0] == 0) /* 0 => a[1] is already-compiled regexpr */ in gensub()
2686 pfa = (fa *) a[1]; /* regular expression */ in gensub()
2688 y = execute(a[1]); in gensub()
2689 pfa = makedfa(getsval(y), 1); in gensub()
2696 whichm = -1; in gensub()
2700 * from 1. GNU awk treats index lower than 0 same as in gensub()
2701 * 1, we do same for compatibility. in gensub()
2703 whichm = (int) getfval(h) - 1; in gensub()
2712 tempstat = pfa->initstat; in gensub()
2713 pfa->initstat = 2; in gensub()
2720 for (sl = rptr; (sl = strchr(sl, '\\')) && sl[1]; sl++) { in gensub()
2721 if (strchr("0123456789", sl[1])) { in gensub()
2729 adjbuf(&buf, &bufsz, (pb - buf) + (patbeg - t) + patlen, recsize, &pb, "gensub"); in gensub()
2743 adjbuf(&buf, &bufsz, 5+pb-buf, recsize, &pb, "gensub"); in gensub()
2748 adjbuf(&buf, &bufsz, 1+patlen+pb-buf, recsize, &pb, "gensub"); in gensub()
2757 adjbuf(&buf, &bufsz, 2+pb-buf, recsize, &pb, "gensub"); in gensub()
2766 adjbuf(&buf, &bufsz, 1+(patbeg-sptr)+pb-buf, recsize, &pb, "gensub"); in gensub()
2771 adjbuf(&buf, &bufsz, 5+pb-buf, recsize, &pb, "gensub"); in gensub()
2776 adjbuf(&buf, &bufsz, 1+patlen+pb-buf, recsize, &pb, "gensub"); in gensub()
2783 if (patlen == 0 || *t == 0 || *(t-1) == 0) in gensub()
2787 mflag = 1; in gensub()
2791 adjbuf(&buf, &bufsz, 1+strlen(sptr)+pb-buf, 0, &pb, "gensub"); in gensub()
2798 pfa->initstat = tempstat; in gensub()
2818 if (sptr[1] == '\\') { in backsub()
2819 if (sptr[2] == '\\' && sptr[3] == '&') { /* \\\& -> \& */ in backsub()
2823 } else if (sptr[2] == '&') { /* \\& -> \ + matched */ in backsub()
2826 } else if (do_posix) { /* \\x -> \x */ in backsub()
2829 } else { /* \\x -> \\x */ in backsub()
2833 } else if (sptr[1] == '&') { /* literal & */ in backsub()
2867 // 0x00010000 - 0x10FFFF in wide_char_to_byte_str()