aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/awk.c66
-rw-r--r--editors/sed.c62
-rw-r--r--editors/vi.c16
3 files changed, 71 insertions, 73 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
diff --git a/editors/sed.c b/editors/sed.c
index 8bd627a9c..2ff028498 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -200,7 +200,7 @@ static int get_address(char *delimiter, char *my_str, int *linenum, regex_t **re
200 } 200 }
201 idx = index_of_next_unescaped_regexp_delim(*delimiter, my_str, ++idx); 201 idx = index_of_next_unescaped_regexp_delim(*delimiter, my_str, ++idx);
202 if (idx == -1) { 202 if (idx == -1) {
203 error_msg_and_die("unterminated match expression"); 203 bb_error_msg_and_die("unterminated match expression");
204 } 204 }
205 my_str[idx] = '\0'; 205 my_str[idx] = '\0';
206 *regex = (regex_t *)xmalloc(sizeof(regex_t)); 206 *regex = (regex_t *)xmalloc(sizeof(regex_t));
@@ -230,7 +230,7 @@ static int parse_subst_cmd(sed_cmd_t * const sed_cmd, const char *substr)
230 /* verify that the 's' is followed by something. That something 230 /* verify that the 's' is followed by something. That something
231 * (typically a 'slash') is now our regexp delimiter... */ 231 * (typically a 'slash') is now our regexp delimiter... */
232 if (substr[idx] == '\0') 232 if (substr[idx] == '\0')
233 error_msg_and_die("bad format in substitution expression"); 233 bb_error_msg_and_die("bad format in substitution expression");
234 else 234 else
235 sed_cmd->delimiter=substr[idx]; 235 sed_cmd->delimiter=substr[idx];
236 236
@@ -238,8 +238,8 @@ static int parse_subst_cmd(sed_cmd_t * const sed_cmd, const char *substr)
238 oldidx = idx+1; 238 oldidx = idx+1;
239 idx = index_of_next_unescaped_regexp_delim(sed_cmd->delimiter, substr, ++idx); 239 idx = index_of_next_unescaped_regexp_delim(sed_cmd->delimiter, substr, ++idx);
240 if (idx == -1) 240 if (idx == -1)
241 error_msg_and_die("bad format in substitution expression"); 241 bb_error_msg_and_die("bad format in substitution expression");
242 match = xstrndup(substr + oldidx, idx - oldidx); 242 match = bb_xstrndup(substr + oldidx, idx - oldidx);
243 243
244 /* determine the number of back references in the match string */ 244 /* determine the number of back references in the match string */
245 /* Note: we compute this here rather than in the do_subst_command() 245 /* Note: we compute this here rather than in the do_subst_command()
@@ -257,8 +257,8 @@ static int parse_subst_cmd(sed_cmd_t * const sed_cmd, const char *substr)
257 oldidx = idx+1; 257 oldidx = idx+1;
258 idx = index_of_next_unescaped_regexp_delim(sed_cmd->delimiter, substr, ++idx); 258 idx = index_of_next_unescaped_regexp_delim(sed_cmd->delimiter, substr, ++idx);
259 if (idx == -1) 259 if (idx == -1)
260 error_msg_and_die("bad format in substitution expression"); 260 bb_error_msg_and_die("bad format in substitution expression");
261 sed_cmd->replace = xstrndup(substr + oldidx, idx - oldidx); 261 sed_cmd->replace = bb_xstrndup(substr + oldidx, idx - oldidx);
262 262
263 /* process the flags */ 263 /* process the flags */
264 while (substr[++idx]) { 264 while (substr[++idx]) {
@@ -278,7 +278,7 @@ static int parse_subst_cmd(sed_cmd_t * const sed_cmd, const char *substr)
278 if (strchr(semicolon_whitespace, substr[idx])) 278 if (strchr(semicolon_whitespace, substr[idx]))
279 goto out; 279 goto out;
280 /* else */ 280 /* else */
281 error_msg_and_die("bad option in substitution expression"); 281 bb_error_msg_and_die("bad option in substitution expression");
282 } 282 }
283 } 283 }
284 284
@@ -317,7 +317,7 @@ static int parse_edit_cmd(sed_cmd_t *sed_cmd, const char *editstr)
317 * 317 *
318 */ 318 */
319 if ((*editstr != '\\') || ((editstr[1] != '\n') && (editstr[1] != '\r'))) { 319 if ((*editstr != '\\') || ((editstr[1] != '\n') && (editstr[1] != '\r'))) {
320 error_msg_and_die("bad format in edit expression"); 320 bb_error_msg_and_die("bad format in edit expression");
321 } 321 }
322 322
323 /* store the edit line text */ 323 /* store the edit line text */
@@ -390,20 +390,20 @@ static char *parse_cmd_str(sed_cmd_t * const sed_cmd, char *cmdstr)
390 /* handle edit cmds: (a)ppend, (i)nsert, and (c)hange */ 390 /* handle edit cmds: (a)ppend, (i)nsert, and (c)hange */
391 else if (strchr("aic", sed_cmd->cmd)) { 391 else if (strchr("aic", sed_cmd->cmd)) {
392 if ((sed_cmd->end_line || sed_cmd->end_match) && sed_cmd->cmd != 'c') 392 if ((sed_cmd->end_line || sed_cmd->end_match) && sed_cmd->cmd != 'c')
393 error_msg_and_die("only a beginning address can be specified for edit commands"); 393 bb_error_msg_and_die("only a beginning address can be specified for edit commands");
394 cmdstr += parse_edit_cmd(sed_cmd, cmdstr); 394 cmdstr += parse_edit_cmd(sed_cmd, cmdstr);
395 } 395 }
396 /* handle file cmds: (r)ead */ 396 /* handle file cmds: (r)ead */
397 else if (sed_cmd->cmd == 'r') { 397 else if (sed_cmd->cmd == 'r') {
398 if (sed_cmd->end_line || sed_cmd->end_match) 398 if (sed_cmd->end_line || sed_cmd->end_match)
399 error_msg_and_die("Command only uses one address"); 399 bb_error_msg_and_die("Command only uses one address");
400 cmdstr += parse_file_cmd(sed_cmd, cmdstr); 400 cmdstr += parse_file_cmd(sed_cmd, cmdstr);
401 } 401 }
402 /* if it wasnt a single-letter command that takes no arguments 402 /* if it wasnt a single-letter command that takes no arguments
403 * then it must be an invalid command. 403 * then it must be an invalid command.
404 */ 404 */
405 else if (strchr("nNpPqd=", sed_cmd->cmd) == 0) { 405 else if (strchr("nNpPqd=", sed_cmd->cmd) == 0) {
406 error_msg_and_die("Unsupported command %c", sed_cmd->cmd); 406 bb_error_msg_and_die("Unsupported command %c", sed_cmd->cmd);
407 } 407 }
408 408
409 /* give back whatever's left over */ 409 /* give back whatever's left over */
@@ -442,7 +442,7 @@ static char *add_cmd(sed_cmd_t *sed_cmd, char *cmdstr)
442 cmdstr++; 442 cmdstr++;
443 idx = get_address(&(sed_cmd->delimiter), cmdstr, &sed_cmd->end_line, &sed_cmd->end_match); 443 idx = get_address(&(sed_cmd->delimiter), cmdstr, &sed_cmd->end_line, &sed_cmd->end_match);
444 if (idx == 0) { 444 if (idx == 0) {
445 error_msg_and_die("get_address: no address found in string\n" 445 bb_error_msg_and_die("get_address: no address found in string\n"
446 "\t(you probably didn't check the string you passed me)"); 446 "\t(you probably didn't check the string you passed me)");
447 } 447 }
448 cmdstr += idx; 448 cmdstr += idx;
@@ -465,7 +465,7 @@ static char *add_cmd(sed_cmd_t *sed_cmd, char *cmdstr)
465 * with <blank>s. 465 * with <blank>s.
466 */ 466 */
467 if (isblank(cmdstr[idx]) { 467 if (isblank(cmdstr[idx]) {
468 error_msg_and_die("blank follows '!'"); 468 bb_error_msg_and_die("blank follows '!'");
469 } 469 }
470#else 470#else
471 /* skip whitespace before the command */ 471 /* skip whitespace before the command */
@@ -478,7 +478,7 @@ static char *add_cmd(sed_cmd_t *sed_cmd, char *cmdstr)
478 478
479 /* last part (mandatory) will be a command */ 479 /* last part (mandatory) will be a command */
480 if (*cmdstr == '\0') 480 if (*cmdstr == '\0')
481 error_msg_and_die("missing command"); 481 bb_error_msg_and_die("missing command");
482 482
483 sed_cmd->cmd = *cmdstr; 483 sed_cmd->cmd = *cmdstr;
484 cmdstr++; 484 cmdstr++;
@@ -517,14 +517,16 @@ static void load_cmd_file(char *filename)
517 FILE *cmdfile; 517 FILE *cmdfile;
518 char *line; 518 char *line;
519 char *nextline; 519 char *nextline;
520 char *e;
520 521
521 cmdfile = xfopen(filename, "r"); 522 cmdfile = bb_xfopen(filename, "r");
522 523
523 while ((line = get_line_from_file(cmdfile)) != NULL) { 524 while ((line = bb_get_line_from_file(cmdfile)) != NULL) {
524 /* if a line ends with '\' it needs the next line appended to it */ 525 /* if a line ends with '\' it needs the next line appended to it */
525 while (line[strlen(line)-2] == '\\' && 526 while (((e = last_char_is(line, '\n')) != NULL)
526 (nextline = get_line_from_file(cmdfile)) != NULL) { 527 && (e > line) && (e[-1] == '\\')
527 line = xrealloc(line, strlen(line) + strlen(nextline) + 1); 528 && ((nextline = bb_get_line_from_file(cmdfile)) != NULL)) {
529 line = xrealloc(line, (e - line) + 1 + strlen(nextline) + 1);
528 strcat(line, nextline); 530 strcat(line, nextline);
529 free(nextline); 531 free(nextline);
530 } 532 }
@@ -677,20 +679,18 @@ static void process_file(FILE *file)
677 int altered; 679 int altered;
678 int i; 680 int i;
679 681
680 line = get_line_from_file(file); 682 line = bb_get_chomped_line_from_file(file);
681 if (line == NULL) { 683 if (line == NULL) {
682 return; 684 return;
683 } 685 }
684 chomp(line);
685 686
686 /* go through every line in the file */ 687 /* go through every line in the file */
687 do { 688 do {
688 char *next_line; 689 char *next_line;
689 690
690 /* Read one line in advance so we can act on the last line, the '$' address */ 691 /* Read one line in advance so we can act on the last line, the '$' address */
691 next_line = get_line_from_file(file); 692 next_line = bb_get_chomped_line_from_file(file);
692 693
693 chomp(next_line);
694 linenum++; 694 linenum++;
695 altered = 0; 695 altered = 0;
696 696
@@ -805,7 +805,7 @@ static void process_file(FILE *file)
805 puts(line); 805 puts(line);
806 outfile = fopen(sed_cmd->filename, "r"); 806 outfile = fopen(sed_cmd->filename, "r");
807 if (outfile) 807 if (outfile)
808 print_file(outfile); 808 bb_xprint_and_close_file(outfile);
809 /* else if we couldn't open the output file, 809 /* else if we couldn't open the output file,
810 * no biggie, just don't print anything */ 810 * no biggie, just don't print anything */
811 altered++; 811 altered++;
@@ -817,16 +817,14 @@ static void process_file(FILE *file)
817 case 'n': /* Read next line from input */ 817 case 'n': /* Read next line from input */
818 free(line); 818 free(line);
819 line = next_line; 819 line = next_line;
820 next_line = get_line_from_file(file); 820 next_line = bb_get_chomped_line_from_file(file);
821 chomp(next_line);
822 linenum++; 821 linenum++;
823 break; 822 break;
824 case 'N': /* Append the next line to the current line */ 823 case 'N': /* Append the next line to the current line */
825 line = realloc(line, strlen(line) + strlen(next_line) + 2); 824 line = realloc(line, strlen(line) + strlen(next_line) + 2);
826 strcat(line, "\n"); 825 strcat(line, "\n");
827 strcat(line, next_line); 826 strcat(line, next_line);
828 next_line = get_line_from_file(file); 827 next_line = bb_get_chomped_line_from_file(file);
829 chomp(next_line);
830 linenum++; 828 linenum++;
831 } 829 }
832 } 830 }
@@ -880,7 +878,7 @@ extern int sed_main(int argc, char **argv)
880#ifdef CONFIG_FEATURE_CLEAN_UP 878#ifdef CONFIG_FEATURE_CLEAN_UP
881 /* destroy command strings on exit */ 879 /* destroy command strings on exit */
882 if (atexit(destroy_cmd_strs) == -1) 880 if (atexit(destroy_cmd_strs) == -1)
883 perror_msg_and_die("atexit"); 881 bb_perror_msg_and_die("atexit");
884#endif 882#endif
885 883
886 /* do normal option parsing */ 884 /* do normal option parsing */
@@ -896,7 +894,7 @@ extern int sed_main(int argc, char **argv)
896 load_cmd_file(optarg); 894 load_cmd_file(optarg);
897 break; 895 break;
898 default: 896 default:
899 show_usage(); 897 bb_show_usage();
900 } 898 }
901 } 899 }
902 900
@@ -904,7 +902,7 @@ extern int sed_main(int argc, char **argv)
904 * argv[optind] should be the pattern. no pattern, no worky */ 902 * argv[optind] should be the pattern. no pattern, no worky */
905 if (ncmds == 0) { 903 if (ncmds == 0) {
906 if (argv[optind] == NULL) 904 if (argv[optind] == NULL)
907 show_usage(); 905 bb_show_usage();
908 else { 906 else {
909 add_cmd_str(argv[optind]); 907 add_cmd_str(argv[optind]);
910 optind++; 908 optind++;
@@ -921,7 +919,7 @@ extern int sed_main(int argc, char **argv)
921 int i; 919 int i;
922 FILE *file; 920 FILE *file;
923 for (i = optind; i < argc; i++) { 921 for (i = optind; i < argc; i++) {
924 file = wfopen(argv[i], "r"); 922 file = bb_wfopen(argv[i], "r");
925 if (file) { 923 if (file) {
926 process_file(file); 924 process_file(file);
927 fclose(file); 925 fclose(file);
diff --git a/editors/vi.c b/editors/vi.c
index cda17db1a..144e9d760 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -19,7 +19,7 @@
19 */ 19 */
20 20
21static const char vi_Version[] = 21static const char vi_Version[] =
22 "$Id: vi.c,v 1.27 2002/12/03 21:48:15 bug1 Exp $"; 22 "$Id: vi.c,v 1.28 2003/03/19 09:11:45 mjn3 Exp $";
23 23
24/* 24/*
25 * To compile for standalone use: 25 * To compile for standalone use:
@@ -403,7 +403,7 @@ extern int vi_main(int argc, char **argv)
403 for (; optind < argc; optind++) { 403 for (; optind < argc; optind++) {
404 editing = 1; // 0=exit, 1=one file, 2+ =many files 404 editing = 1; // 0=exit, 1=one file, 2+ =many files
405 free(cfn); 405 free(cfn);
406 cfn = (Byte *) xstrdup(argv[optind]); 406 cfn = (Byte *) bb_xstrdup(argv[optind]);
407 edit_file(cfn); 407 edit_file(cfn);
408 } 408 }
409 } 409 }
@@ -597,7 +597,7 @@ static Byte *get_one_address(Byte * p, int *addr) // get colon addr, if present
597 *q++ = *p; 597 *q++ = *p;
598 *q = '\0'; 598 *q = '\0';
599 } 599 }
600 pat = (Byte *) xstrdup((char *) buf); // save copy of pattern 600 pat = (Byte *) bb_xstrdup((char *) buf); // save copy of pattern
601 if (*p == '/') 601 if (*p == '/')
602 p++; 602 p++;
603 q = char_search(dot, pat, FORWARD, FULL); 603 q = char_search(dot, pat, FORWARD, FULL);
@@ -811,7 +811,7 @@ static void colon(Byte * buf)
811 811
812 // There is a read-able regular file 812 // There is a read-able regular file
813 // make this the current file 813 // make this the current file
814 q = (Byte *) xstrdup((char *) fn); // save the cfn 814 q = (Byte *) bb_xstrdup((char *) fn); // save the cfn
815 free(cfn); // free the old name 815 free(cfn); // free the old name
816 cfn = q; // remember new cfn 816 cfn = q; // remember new cfn
817 817
@@ -862,7 +862,7 @@ static void colon(Byte * buf)
862 if (strlen((char *) args) > 0) { 862 if (strlen((char *) args) > 0) {
863 // user wants a new filename 863 // user wants a new filename
864 free(cfn); 864 free(cfn);
865 cfn = (Byte *) xstrdup((char *) args); 865 cfn = (Byte *) bb_xstrdup((char *) args);
866 } else { 866 } else {
867 // user wants file status info 867 // user wants file status info
868 edit_status(); 868 edit_status();
@@ -2432,7 +2432,7 @@ static Byte *get_input_line(Byte * prompt) // get input line- use "status line"
2432 } 2432 }
2433 refresh(FALSE); 2433 refresh(FALSE);
2434 free(obufp); 2434 free(obufp);
2435 obufp = (Byte *) xstrdup((char *) buf); 2435 obufp = (Byte *) bb_xstrdup((char *) buf);
2436 return (obufp); 2436 return (obufp);
2437} 2437}
2438 2438
@@ -3263,7 +3263,7 @@ key_cmd_mode:
3263 // Stuff the last_modifying_cmd back into stdin 3263 // Stuff the last_modifying_cmd back into stdin
3264 // and let it be re-executed. 3264 // and let it be re-executed.
3265 if (last_modifying_cmd != 0) { 3265 if (last_modifying_cmd != 0) {
3266 ioq = ioq_start = (Byte *) xstrdup((char *) last_modifying_cmd); 3266 ioq = ioq_start = (Byte *) bb_xstrdup((char *) last_modifying_cmd);
3267 } 3267 }
3268 break; 3268 break;
3269#endif /* CONFIG_FEATURE_VI_DOT_CMD */ 3269#endif /* CONFIG_FEATURE_VI_DOT_CMD */
@@ -3278,7 +3278,7 @@ key_cmd_mode:
3278 if (strlen((char *) q) > 1) { // new pat- save it and find 3278 if (strlen((char *) q) > 1) { // new pat- save it and find
3279 // there is a new pat 3279 // there is a new pat
3280 free(last_search_pattern); 3280 free(last_search_pattern);
3281 last_search_pattern = (Byte *) xstrdup((char *) q); 3281 last_search_pattern = (Byte *) bb_xstrdup((char *) q);
3282 goto dc3; // now find the pattern 3282 goto dc3; // now find the pattern
3283 } 3283 }
3284 // user changed mind and erased the "/"- do nothing 3284 // user changed mind and erased the "/"- do nothing