aboutsummaryrefslogtreecommitdiff
path: root/editors/awk.c
diff options
context:
space:
mode:
Diffstat (limited to 'editors/awk.c')
-rw-r--r--editors/awk.c66
1 files changed, 33 insertions, 33 deletions
diff --git a/editors/awk.c b/editors/awk.c
index 44c2f45b2..0f8cf94f4 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -463,7 +463,7 @@ static const char EMSG_NO_MATH[] = "Math support is not compiled in";
463 463
464static void syntax_error(const char * const message) 464static void syntax_error(const char * const message)
465{ 465{
466 error_msg("%s:%i: %s", programname, lineno, message); 466 bb_error_msg("%s:%i: %s", programname, lineno, message);
467 awk_exit(1); 467 awk_exit(1);
468} 468}
469 469
@@ -546,7 +546,7 @@ static void *hash_find(xhash *hash, char *name) {
546 if (++hash->nel / hash->csize > 10) 546 if (++hash->nel / hash->csize > 10)
547 hash_rebuild(hash); 547 hash_rebuild(hash);
548 548
549 l = xstrlen(name) + 1; 549 l = bb_strlen(name) + 1;
550 hi = xcalloc(sizeof(hash_item) + l, 1); 550 hi = xcalloc(sizeof(hash_item) + l, 1);
551 memcpy(hi->name, name, l); 551 memcpy(hi->name, name, l);
552 552
@@ -571,7 +571,7 @@ static void hash_remove(xhash *hash, char *name) {
571 while (*phi) { 571 while (*phi) {
572 hi = *phi; 572 hi = *phi;
573 if (strcmp(hi->name, name) == 0) { 573 if (strcmp(hi->name, name) == 0) {
574 hash->glen -= (xstrlen(name) + 1); 574 hash->glen -= (bb_strlen(name) + 1);
575 hash->nel--; 575 hash->nel--;
576 *phi = hi->next; 576 *phi = hi->next;
577 free(hi); 577 free(hi);
@@ -609,7 +609,7 @@ static char nextchar(char **s) {
609 609
610 c = *((*s)++); 610 c = *((*s)++);
611 pps = *s; 611 pps = *s;
612 if (c == '\\') c = process_escape_sequence((const char**)s); 612 if (c == '\\') c = bb_process_escape_sequence((const char**)s);
613 if (c == '\\' && *s == pps) c = *((*s)++); 613 if (c == '\\' && *s == pps) c = *((*s)++);
614 return c; 614 return c;
615} 615}
@@ -621,7 +621,7 @@ static inline int isalnum_(int c) {
621 621
622static FILE *afopen(const char *path, const char *mode) { 622static FILE *afopen(const char *path, const char *mode) {
623 623
624 return (*path == '-' && *(path+1) == '\0') ? stdin : xfopen(path, mode); 624 return (*path == '-' && *(path+1) == '\0') ? stdin : bb_xfopen(path, mode);
625} 625}
626 626
627/* -------- working with variables (set/get/copy/etc) -------- */ 627/* -------- working with variables (set/get/copy/etc) -------- */
@@ -683,7 +683,7 @@ static var *setvar_p(var *v, char *value) {
683/* same as setvar_p but make a copy of string */ 683/* same as setvar_p but make a copy of string */
684static var *setvar_s(var *v, char *value) { 684static var *setvar_s(var *v, char *value) {
685 685
686 return setvar_p(v, (value && *value) ? xstrdup(value) : NULL); 686 return setvar_p(v, (value && *value) ? bb_xstrdup(value) : NULL);
687} 687}
688 688
689/* same as setvar_s but set USER flag */ 689/* same as setvar_s but set USER flag */
@@ -720,7 +720,7 @@ static char *getvar_s(var *v) {
720 /* if v is numeric and has no cached string, convert it to string */ 720 /* if v is numeric and has no cached string, convert it to string */
721 if ((v->type & (VF_NUMBER | VF_CACHED)) == VF_NUMBER) { 721 if ((v->type & (VF_NUMBER | VF_CACHED)) == VF_NUMBER) {
722 fmt_num(buf, MAXVARFMT, getvar_s(V[CONVFMT]), v->number, TRUE); 722 fmt_num(buf, MAXVARFMT, getvar_s(V[CONVFMT]), v->number, TRUE);
723 v->string = xstrdup(buf); 723 v->string = bb_xstrdup(buf);
724 v->type |= VF_CACHED; 724 v->type |= VF_CACHED;
725 } 725 }
726 return (v->string == NULL) ? "" : v->string; 726 return (v->string == NULL) ? "" : v->string;
@@ -755,7 +755,7 @@ static var *copyvar(var *dest, var *src) {
755 dest->type |= (src->type & ~VF_DONTTOUCH); 755 dest->type |= (src->type & ~VF_DONTTOUCH);
756 dest->number = src->number; 756 dest->number = src->number;
757 if (src->string) 757 if (src->string)
758 dest->string = xstrdup(src->string); 758 dest->string = bb_xstrdup(src->string);
759 } 759 }
760 handle_special(dest); 760 handle_special(dest);
761 return dest; 761 return dest;
@@ -903,7 +903,7 @@ static unsigned long next_token(unsigned long expected) {
903 syntax_error(EMSG_UNEXP_EOS); 903 syntax_error(EMSG_UNEXP_EOS);
904 if ((*s++ = *p++) == '\\') { 904 if ((*s++ = *p++) == '\\') {
905 pp = p; 905 pp = p;
906 *(s-1) = process_escape_sequence((const char **)&p); 906 *(s-1) = bb_process_escape_sequence((const char **)&p);
907 if (*pp == '\\') *s++ = '\\'; 907 if (*pp == '\\') *s++ = '\\';
908 if (p == pp) *s++ = *p++; 908 if (p == pp) *s++ = *p++;
909 } 909 }
@@ -1153,7 +1153,7 @@ static node *chain_node(unsigned long info) {
1153 if (seq->programname != programname) { 1153 if (seq->programname != programname) {
1154 seq->programname = programname; 1154 seq->programname = programname;
1155 n = chain_node(OC_NEWSOURCE); 1155 n = chain_node(OC_NEWSOURCE);
1156 n->l.s = xstrdup(programname); 1156 n->l.s = bb_xstrdup(programname);
1157 } 1157 }
1158 1158
1159 n = seq->last; 1159 n = seq->last;
@@ -1373,7 +1373,7 @@ static node *mk_splitter(char *s, tsplitter *spl) {
1373 regfree(re); 1373 regfree(re);
1374 regfree(ire); 1374 regfree(ire);
1375 } 1375 }
1376 if (xstrlen(s) > 1) { 1376 if (bb_strlen(s) > 1) {
1377 mk_re_node(s, n, re); 1377 mk_re_node(s, n, re);
1378 } else { 1378 } else {
1379 n->info = (unsigned long) *s; 1379 n->info = (unsigned long) *s;
@@ -1441,7 +1441,7 @@ static int awk_split(char *s, node *spl, char **slist) {
1441 regmatch_t pmatch[2]; 1441 regmatch_t pmatch[2];
1442 1442
1443 /* in worst case, each char would be a separate field */ 1443 /* in worst case, each char would be a separate field */
1444 *slist = s1 = xstrndup(s, xstrlen(s) * 2 + 3); 1444 *slist = s1 = bb_xstrndup(s, bb_strlen(s) * 2 + 3);
1445 1445
1446 c[0] = c[1] = (char)spl->info; 1446 c[0] = c[1] = (char)spl->info;
1447 c[2] = c[3] = '\0'; 1447 c[2] = c[3] = '\0';
@@ -1536,12 +1536,12 @@ static void handle_special(var *v) {
1536 1536
1537 /* recalculate $0 */ 1537 /* recalculate $0 */
1538 sep = getvar_s(V[OFS]); 1538 sep = getvar_s(V[OFS]);
1539 sl = xstrlen(sep); 1539 sl = bb_strlen(sep);
1540 b = NULL; 1540 b = NULL;
1541 len = 0; 1541 len = 0;
1542 for (i=0; i<n; i++) { 1542 for (i=0; i<n; i++) {
1543 s = getvar_s(&Fields[i]); 1543 s = getvar_s(&Fields[i]);
1544 l = xstrlen(s); 1544 l = bb_strlen(s);
1545 if (b) { 1545 if (b) {
1546 memcpy(b+len, sep, sl); 1546 memcpy(b+len, sep, sl);
1547 len += sl; 1547 len += sl;
@@ -1744,7 +1744,7 @@ static char *awk_printf(node *n) {
1744 var *v, *arg; 1744 var *v, *arg;
1745 1745
1746 v = nvalloc(1); 1746 v = nvalloc(1);
1747 fmt = f = xstrdup(getvar_s(evaluate(nextarg(&n), v))); 1747 fmt = f = bb_xstrdup(getvar_s(evaluate(nextarg(&n), v)));
1748 1748
1749 i = 0; 1749 i = 0;
1750 while (*f) { 1750 while (*f) {
@@ -1767,7 +1767,7 @@ static char *awk_printf(node *n) {
1767 1767
1768 } else if (c == 's') { 1768 } else if (c == 's') {
1769 s1 = getvar_s(arg); 1769 s1 = getvar_s(arg);
1770 qrealloc(&b, incr+i+xstrlen(s1), &bsize); 1770 qrealloc(&b, incr+i+bb_strlen(s1), &bsize);
1771 i += sprintf(b+i, s, s1); 1771 i += sprintf(b+i, s, s1);
1772 1772
1773 } else { 1773 } else {
@@ -1807,7 +1807,7 @@ static int awk_sub(node *rn, char *repl, int nm, var *src, var *dest, int ex) {
1807 1807
1808 i = di = 0; 1808 i = di = 0;
1809 sp = getvar_s(src); 1809 sp = getvar_s(src);
1810 rl = xstrlen(repl); 1810 rl = bb_strlen(repl);
1811 while (regexec(re, sp, 10, pmatch, sp==getvar_s(src) ? 0:REG_NOTBOL) == 0) { 1811 while (regexec(re, sp, 10, pmatch, sp==getvar_s(src) ? 0:REG_NOTBOL) == 0) {
1812 so = pmatch[0].rm_so; 1812 so = pmatch[0].rm_so;
1813 eo = pmatch[0].rm_eo; 1813 eo = pmatch[0].rm_eo;
@@ -1920,7 +1920,7 @@ static var *exec_builtin(node *op, var *res) {
1920 break; 1920 break;
1921 1921
1922 case B_ss: 1922 case B_ss:
1923 l = xstrlen(as[0]); 1923 l = bb_strlen(as[0]);
1924 i = getvar_i(av[1]) - 1; 1924 i = getvar_i(av[1]) - 1;
1925 if (i>l) i=l; if (i<0) i=0; 1925 if (i>l) i=l; if (i<0) i=0;
1926 n = (nargs > 2) ? getvar_i(av[2]) : l-i; 1926 n = (nargs > 2) ? getvar_i(av[2]) : l-i;
@@ -1938,7 +1938,7 @@ static var *exec_builtin(node *op, var *res) {
1938 case B_up: 1938 case B_up:
1939 to_xxx = toupper; 1939 to_xxx = toupper;
1940lo_cont: 1940lo_cont:
1941 s1 = s = xstrdup(as[0]); 1941 s1 = s = bb_xstrdup(as[0]);
1942 while (*s1) { 1942 while (*s1) {
1943 *s1 = (*to_xxx)(*s1); 1943 *s1 = (*to_xxx)(*s1);
1944 s1++; 1944 s1++;
@@ -1948,8 +1948,8 @@ lo_cont:
1948 1948
1949 case B_ix: 1949 case B_ix:
1950 n = 0; 1950 n = 0;
1951 ll = xstrlen(as[1]); 1951 ll = bb_strlen(as[1]);
1952 l = xstrlen(as[0]) - ll; 1952 l = bb_strlen(as[0]) - ll;
1953 if (ll > 0 && l >= 0) { 1953 if (ll > 0 && l >= 0) {
1954 if (! icase) { 1954 if (! icase) {
1955 s = strstr(as[0], as[1]); 1955 s = strstr(as[0], as[1]);
@@ -2112,10 +2112,10 @@ static var *evaluate(node *op, var *res) {
2112 if (! X.rsm->F) { 2112 if (! X.rsm->F) {
2113 if (opn == '|') { 2113 if (opn == '|') {
2114 if((X.rsm->F = popen(R.s, "w")) == NULL) 2114 if((X.rsm->F = popen(R.s, "w")) == NULL)
2115 perror_msg_and_die("popen"); 2115 bb_perror_msg_and_die("popen");
2116 X.rsm->is_pipe = 1; 2116 X.rsm->is_pipe = 1;
2117 } else { 2117 } else {
2118 X.rsm->F = xfopen(R.s, opn=='w' ? "w" : "a"); 2118 X.rsm->F = bb_xfopen(R.s, opn=='w' ? "w" : "a");
2119 } 2119 }
2120 } 2120 }
2121 X.F = X.rsm->F; 2121 X.F = X.rsm->F;
@@ -2269,7 +2269,7 @@ re_cont:
2269 X.rsm->F = popen(L.s, "r"); 2269 X.rsm->F = popen(L.s, "r");
2270 X.rsm->is_pipe = TRUE; 2270 X.rsm->is_pipe = TRUE;
2271 } else { 2271 } else {
2272 X.rsm->F = fopen(L.s, "r"); /* not xfopen! */ 2272 X.rsm->F = fopen(L.s, "r"); /* not bb_xfopen! */
2273 } 2273 }
2274 } 2274 }
2275 } else { 2275 } else {
@@ -2351,7 +2351,7 @@ re_cont:
2351 case F_le: 2351 case F_le:
2352 if (! op1) 2352 if (! op1)
2353 L.s = getvar_s(V[F0]); 2353 L.s = getvar_s(V[F0]);
2354 R.d = xstrlen(L.s); 2354 R.d = bb_strlen(L.s);
2355 break; 2355 break;
2356 2356
2357 case F_sy: 2357 case F_sy:
@@ -2439,12 +2439,12 @@ re_cont:
2439 /* concatenation (" ") and index joining (",") */ 2439 /* concatenation (" ") and index joining (",") */
2440 case XC( OC_CONCAT ): 2440 case XC( OC_CONCAT ):
2441 case XC( OC_COMMA ): 2441 case XC( OC_COMMA ):
2442 opn = xstrlen(L.s) + xstrlen(R.s) + 2; 2442 opn = bb_strlen(L.s) + bb_strlen(R.s) + 2;
2443 X.s = (char *)xmalloc(opn); 2443 X.s = (char *)xmalloc(opn);
2444 strcpy(X.s, L.s); 2444 strcpy(X.s, L.s);
2445 if ((opinfo & OPCLSMASK) == OC_COMMA) { 2445 if ((opinfo & OPCLSMASK) == OC_COMMA) {
2446 L.s = getvar_s(V[SUBSEP]); 2446 L.s = getvar_s(V[SUBSEP]);
2447 X.s = (char *)xrealloc(X.s, opn + xstrlen(L.s)); 2447 X.s = (char *)xrealloc(X.s, opn + bb_strlen(L.s));
2448 strcat(X.s, L.s); 2448 strcat(X.s, L.s);
2449 } 2449 }
2450 strcat(X.s, R.s); 2450 strcat(X.s, R.s);
@@ -2554,7 +2554,7 @@ static int is_assignment(char *expr) {
2554 2554
2555 char *exprc, *s, *s0, *s1; 2555 char *exprc, *s, *s0, *s1;
2556 2556
2557 exprc = xstrdup(expr); 2557 exprc = bb_xstrdup(expr);
2558 if (!isalnum_(*exprc) || (s = strchr(exprc, '=')) == NULL) { 2558 if (!isalnum_(*exprc) || (s = strchr(exprc, '=')) == NULL) {
2559 free(exprc); 2559 free(exprc);
2560 return FALSE; 2560 return FALSE;
@@ -2649,7 +2649,7 @@ extern int awk_main(int argc, char **argv) {
2649 } 2649 }
2650 2650
2651 for (envp=environ; *envp; envp++) { 2651 for (envp=environ; *envp; envp++) {
2652 s = xstrdup(*envp); 2652 s = bb_xstrdup(*envp);
2653 s1 = strchr(s, '='); 2653 s1 = strchr(s, '=');
2654 *(s1++) = '\0'; 2654 *(s1++) = '\0';
2655 setvar_u(findvar(iamarray(V[ENVIRON]), s), s1); 2655 setvar_u(findvar(iamarray(V[ENVIRON]), s), s1);
@@ -2663,7 +2663,7 @@ extern int awk_main(int argc, char **argv) {
2663 break; 2663 break;
2664 case 'v': 2664 case 'v':
2665 if (! is_assignment(optarg)) 2665 if (! is_assignment(optarg))
2666 show_usage(); 2666 bb_show_usage();
2667 break; 2667 break;
2668 case 'f': 2668 case 'f':
2669 from_file = TRUE; 2669 from_file = TRUE;
@@ -2680,17 +2680,17 @@ extern int awk_main(int argc, char **argv) {
2680 free(s); 2680 free(s);
2681 break; 2681 break;
2682 case 'W': 2682 case 'W':
2683 error_msg("Warning: unrecognized option '-W %s' ignored\n", optarg); 2683 bb_error_msg("Warning: unrecognized option '-W %s' ignored\n", optarg);
2684 break; 2684 break;
2685 2685
2686 default: 2686 default:
2687 show_usage(); 2687 bb_show_usage();
2688 } 2688 }
2689 } 2689 }
2690 2690
2691 if (!from_file) { 2691 if (!from_file) {
2692 if (argc == optind) 2692 if (argc == optind)
2693 show_usage(); 2693 bb_show_usage();
2694 programname="cmd. line"; 2694 programname="cmd. line";
2695 parse_program(argv[optind++]); 2695 parse_program(argv[optind++]);
2696 2696