summaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorManuel Novoa III2003-03-19 09:13:01 +0000
committerManuel Novoa III2003-03-19 09:13:01 +0000
commitcad5364599eb5062d59e0c397ed638ddd61a8d5d (patch)
treea318d0f03aa076c74b576ea45dc543a5669e8e91 /editors
parente01f9662a5bd5d91be4f6b3941b57fff73cd5af1 (diff)
downloadbusybox-cad5364599eb5062d59e0c397ed638ddd61a8d5d.zip
busybox-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.gz
Major coreutils update.
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 44c2f45..0f8cf94 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";
static void syntax_error(const char * const message)
{
- error_msg("%s:%i: %s", programname, lineno, message);
+ bb_error_msg("%s:%i: %s", programname, lineno, message);
awk_exit(1);
}
@@ -546,7 +546,7 @@ static void *hash_find(xhash *hash, char *name) {
if (++hash->nel / hash->csize > 10)
hash_rebuild(hash);
- l = xstrlen(name) + 1;
+ l = bb_strlen(name) + 1;
hi = xcalloc(sizeof(hash_item) + l, 1);
memcpy(hi->name, name, l);
@@ -571,7 +571,7 @@ static void hash_remove(xhash *hash, char *name) {
while (*phi) {
hi = *phi;
if (strcmp(hi->name, name) == 0) {
- hash->glen -= (xstrlen(name) + 1);
+ hash->glen -= (bb_strlen(name) + 1);
hash->nel--;
*phi = hi->next;
free(hi);
@@ -609,7 +609,7 @@ static char nextchar(char **s) {
c = *((*s)++);
pps = *s;
- if (c == '\\') c = process_escape_sequence((const char**)s);
+ if (c == '\\') c = bb_process_escape_sequence((const char**)s);
if (c == '\\' && *s == pps) c = *((*s)++);
return c;
}
@@ -621,7 +621,7 @@ static inline int isalnum_(int c) {
static FILE *afopen(const char *path, const char *mode) {
- return (*path == '-' && *(path+1) == '\0') ? stdin : xfopen(path, mode);
+ return (*path == '-' && *(path+1) == '\0') ? stdin : bb_xfopen(path, mode);
}
/* -------- working with variables (set/get/copy/etc) -------- */
@@ -683,7 +683,7 @@ static var *setvar_p(var *v, char *value) {
/* same as setvar_p but make a copy of string */
static var *setvar_s(var *v, char *value) {
- return setvar_p(v, (value && *value) ? xstrdup(value) : NULL);
+ return setvar_p(v, (value && *value) ? bb_xstrdup(value) : NULL);
}
/* same as setvar_s but set USER flag */
@@ -720,7 +720,7 @@ static char *getvar_s(var *v) {
/* if v is numeric and has no cached string, convert it to string */
if ((v->type & (VF_NUMBER | VF_CACHED)) == VF_NUMBER) {
fmt_num(buf, MAXVARFMT, getvar_s(V[CONVFMT]), v->number, TRUE);
- v->string = xstrdup(buf);
+ v->string = bb_xstrdup(buf);
v->type |= VF_CACHED;
}
return (v->string == NULL) ? "" : v->string;
@@ -755,7 +755,7 @@ static var *copyvar(var *dest, var *src) {
dest->type |= (src->type & ~VF_DONTTOUCH);
dest->number = src->number;
if (src->string)
- dest->string = xstrdup(src->string);
+ dest->string = bb_xstrdup(src->string);
}
handle_special(dest);
return dest;
@@ -903,7 +903,7 @@ static unsigned long next_token(unsigned long expected) {
syntax_error(EMSG_UNEXP_EOS);
if ((*s++ = *p++) == '\\') {
pp = p;
- *(s-1) = process_escape_sequence((const char **)&p);
+ *(s-1) = bb_process_escape_sequence((const char **)&p);
if (*pp == '\\') *s++ = '\\';
if (p == pp) *s++ = *p++;
}
@@ -1153,7 +1153,7 @@ static node *chain_node(unsigned long info) {
if (seq->programname != programname) {
seq->programname = programname;
n = chain_node(OC_NEWSOURCE);
- n->l.s = xstrdup(programname);
+ n->l.s = bb_xstrdup(programname);
}
n = seq->last;
@@ -1373,7 +1373,7 @@ static node *mk_splitter(char *s, tsplitter *spl) {
regfree(re);
regfree(ire);
}
- if (xstrlen(s) > 1) {
+ if (bb_strlen(s) > 1) {
mk_re_node(s, n, re);
} else {
n->info = (unsigned long) *s;
@@ -1441,7 +1441,7 @@ static int awk_split(char *s, node *spl, char **slist) {
regmatch_t pmatch[2];
/* in worst case, each char would be a separate field */
- *slist = s1 = xstrndup(s, xstrlen(s) * 2 + 3);
+ *slist = s1 = bb_xstrndup(s, bb_strlen(s) * 2 + 3);
c[0] = c[1] = (char)spl->info;
c[2] = c[3] = '\0';
@@ -1536,12 +1536,12 @@ static void handle_special(var *v) {
/* recalculate $0 */
sep = getvar_s(V[OFS]);
- sl = xstrlen(sep);
+ sl = bb_strlen(sep);
b = NULL;
len = 0;
for (i=0; i<n; i++) {
s = getvar_s(&Fields[i]);
- l = xstrlen(s);
+ l = bb_strlen(s);
if (b) {
memcpy(b+len, sep, sl);
len += sl;
@@ -1744,7 +1744,7 @@ static char *awk_printf(node *n) {
var *v, *arg;
v = nvalloc(1);
- fmt = f = xstrdup(getvar_s(evaluate(nextarg(&n), v)));
+ fmt = f = bb_xstrdup(getvar_s(evaluate(nextarg(&n), v)));
i = 0;
while (*f) {
@@ -1767,7 +1767,7 @@ static char *awk_printf(node *n) {
} else if (c == 's') {
s1 = getvar_s(arg);
- qrealloc(&b, incr+i+xstrlen(s1), &bsize);
+ qrealloc(&b, incr+i+bb_strlen(s1), &bsize);
i += sprintf(b+i, s, s1);
} else {
@@ -1807,7 +1807,7 @@ static int awk_sub(node *rn, char *repl, int nm, var *src, var *dest, int ex) {
i = di = 0;
sp = getvar_s(src);
- rl = xstrlen(repl);
+ rl = bb_strlen(repl);
while (regexec(re, sp, 10, pmatch, sp==getvar_s(src) ? 0:REG_NOTBOL) == 0) {
so = pmatch[0].rm_so;
eo = pmatch[0].rm_eo;
@@ -1920,7 +1920,7 @@ static var *exec_builtin(node *op, var *res) {
break;
case B_ss:
- l = xstrlen(as[0]);
+ l = bb_strlen(as[0]);
i = getvar_i(av[1]) - 1;
if (i>l) i=l; if (i<0) i=0;
n = (nargs > 2) ? getvar_i(av[2]) : l-i;
@@ -1938,7 +1938,7 @@ static var *exec_builtin(node *op, var *res) {
case B_up:
to_xxx = toupper;
lo_cont:
- s1 = s = xstrdup(as[0]);
+ s1 = s = bb_xstrdup(as[0]);
while (*s1) {
*s1 = (*to_xxx)(*s1);
s1++;
@@ -1948,8 +1948,8 @@ lo_cont:
case B_ix:
n = 0;
- ll = xstrlen(as[1]);
- l = xstrlen(as[0]) - ll;
+ ll = bb_strlen(as[1]);
+ l = bb_strlen(as[0]) - ll;
if (ll > 0 && l >= 0) {
if (! icase) {
s = strstr(as[0], as[1]);
@@ -2112,10 +2112,10 @@ static var *evaluate(node *op, var *res) {
if (! X.rsm->F) {
if (opn == '|') {
if((X.rsm->F = popen(R.s, "w")) == NULL)
- perror_msg_and_die("popen");
+ bb_perror_msg_and_die("popen");
X.rsm->is_pipe = 1;
} else {
- X.rsm->F = xfopen(R.s, opn=='w' ? "w" : "a");
+ X.rsm->F = bb_xfopen(R.s, opn=='w' ? "w" : "a");
}
}
X.F = X.rsm->F;
@@ -2269,7 +2269,7 @@ re_cont:
X.rsm->F = popen(L.s, "r");
X.rsm->is_pipe = TRUE;
} else {
- X.rsm->F = fopen(L.s, "r"); /* not xfopen! */
+ X.rsm->F = fopen(L.s, "r"); /* not bb_xfopen! */
}
}
} else {
@@ -2351,7 +2351,7 @@ re_cont:
case F_le:
if (! op1)
L.s = getvar_s(V[F0]);
- R.d = xstrlen(L.s);
+ R.d = bb_strlen(L.s);
break;
case F_sy:
@@ -2439,12 +2439,12 @@ re_cont:
/* concatenation (" ") and index joining (",") */
case XC( OC_CONCAT ):
case XC( OC_COMMA ):
- opn = xstrlen(L.s) + xstrlen(R.s) + 2;
+ opn = bb_strlen(L.s) + bb_strlen(R.s) + 2;
X.s = (char *)xmalloc(opn);
strcpy(X.s, L.s);
if ((opinfo & OPCLSMASK) == OC_COMMA) {
L.s = getvar_s(V[SUBSEP]);
- X.s = (char *)xrealloc(X.s, opn + xstrlen(L.s));
+ X.s = (char *)xrealloc(X.s, opn + bb_strlen(L.s));
strcat(X.s, L.s);
}
strcat(X.s, R.s);
@@ -2554,7 +2554,7 @@ static int is_assignment(char *expr) {
char *exprc, *s, *s0, *s1;
- exprc = xstrdup(expr);
+ exprc = bb_xstrdup(expr);
if (!isalnum_(*exprc) || (s = strchr(exprc, '=')) == NULL) {
free(exprc);
return FALSE;
@@ -2649,7 +2649,7 @@ extern int awk_main(int argc, char **argv) {
}
for (envp=environ; *envp; envp++) {
- s = xstrdup(*envp);
+ s = bb_xstrdup(*envp);
s1 = strchr(s, '=');
*(s1++) = '\0';
setvar_u(findvar(iamarray(V[ENVIRON]), s), s1);
@@ -2663,7 +2663,7 @@ extern int awk_main(int argc, char **argv) {
break;
case 'v':
if (! is_assignment(optarg))
- show_usage();
+ bb_show_usage();
break;
case 'f':
from_file = TRUE;
@@ -2680,17 +2680,17 @@ extern int awk_main(int argc, char **argv) {
free(s);
break;
case 'W':
- error_msg("Warning: unrecognized option '-W %s' ignored\n", optarg);
+ bb_error_msg("Warning: unrecognized option '-W %s' ignored\n", optarg);
break;
default:
- show_usage();
+ bb_show_usage();
}
}
if (!from_file) {
if (argc == optind)
- show_usage();
+ bb_show_usage();
programname="cmd. line";
parse_program(argv[optind++]);
diff --git a/editors/sed.c b/editors/sed.c
index 8bd627a..2ff0284 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
}
idx = index_of_next_unescaped_regexp_delim(*delimiter, my_str, ++idx);
if (idx == -1) {
- error_msg_and_die("unterminated match expression");
+ bb_error_msg_and_die("unterminated match expression");
}
my_str[idx] = '\0';
*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)
/* verify that the 's' is followed by something. That something
* (typically a 'slash') is now our regexp delimiter... */
if (substr[idx] == '\0')
- error_msg_and_die("bad format in substitution expression");
+ bb_error_msg_and_die("bad format in substitution expression");
else
sed_cmd->delimiter=substr[idx];
@@ -238,8 +238,8 @@ static int parse_subst_cmd(sed_cmd_t * const sed_cmd, const char *substr)
oldidx = idx+1;
idx = index_of_next_unescaped_regexp_delim(sed_cmd->delimiter, substr, ++idx);
if (idx == -1)
- error_msg_and_die("bad format in substitution expression");
- match = xstrndup(substr + oldidx, idx - oldidx);
+ bb_error_msg_and_die("bad format in substitution expression");
+ match = bb_xstrndup(substr + oldidx, idx - oldidx);
/* determine the number of back references in the match string */
/* 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)
oldidx = idx+1;
idx = index_of_next_unescaped_regexp_delim(sed_cmd->delimiter, substr, ++idx);
if (idx == -1)
- error_msg_and_die("bad format in substitution expression");
- sed_cmd->replace = xstrndup(substr + oldidx, idx - oldidx);
+ bb_error_msg_and_die("bad format in substitution expression");
+ sed_cmd->replace = bb_xstrndup(substr + oldidx, idx - oldidx);
/* process the flags */
while (substr[++idx]) {
@@ -278,7 +278,7 @@ static int parse_subst_cmd(sed_cmd_t * const sed_cmd, const char *substr)
if (strchr(semicolon_whitespace, substr[idx]))
goto out;
/* else */
- error_msg_and_die("bad option in substitution expression");
+ bb_error_msg_and_die("bad option in substitution expression");
}
}
@@ -317,7 +317,7 @@ static int parse_edit_cmd(sed_cmd_t *sed_cmd, const char *editstr)
*
*/
if ((*editstr != '\\') || ((editstr[1] != '\n') && (editstr[1] != '\r'))) {
- error_msg_and_die("bad format in edit expression");
+ bb_error_msg_and_die("bad format in edit expression");
}
/* store the edit line text */
@@ -390,20 +390,20 @@ static char *parse_cmd_str(sed_cmd_t * const sed_cmd, char *cmdstr)
/* handle edit cmds: (a)ppend, (i)nsert, and (c)hange */
else if (strchr("aic", sed_cmd->cmd)) {
if ((sed_cmd->end_line || sed_cmd->end_match) && sed_cmd->cmd != 'c')
- error_msg_and_die("only a beginning address can be specified for edit commands");
+ bb_error_msg_and_die("only a beginning address can be specified for edit commands");
cmdstr += parse_edit_cmd(sed_cmd, cmdstr);
}
/* handle file cmds: (r)ead */
else if (sed_cmd->cmd == 'r') {
if (sed_cmd->end_line || sed_cmd->end_match)
- error_msg_and_die("Command only uses one address");
+ bb_error_msg_and_die("Command only uses one address");
cmdstr += parse_file_cmd(sed_cmd, cmdstr);
}
/* if it wasnt a single-letter command that takes no arguments
* then it must be an invalid command.
*/
else if (strchr("nNpPqd=", sed_cmd->cmd) == 0) {
- error_msg_and_die("Unsupported command %c", sed_cmd->cmd);
+ bb_error_msg_and_die("Unsupported command %c", sed_cmd->cmd);
}
/* give back whatever's left over */
@@ -442,7 +442,7 @@ static char *add_cmd(sed_cmd_t *sed_cmd, char *cmdstr)
cmdstr++;
idx = get_address(&(sed_cmd->delimiter), cmdstr, &sed_cmd->end_line, &sed_cmd->end_match);
if (idx == 0) {
- error_msg_and_die("get_address: no address found in string\n"
+ bb_error_msg_and_die("get_address: no address found in string\n"
"\t(you probably didn't check the string you passed me)");
}
cmdstr += idx;
@@ -465,7 +465,7 @@ static char *add_cmd(sed_cmd_t *sed_cmd, char *cmdstr)
* with <blank>s.
*/
if (isblank(cmdstr[idx]) {
- error_msg_and_die("blank follows '!'");
+ bb_error_msg_and_die("blank follows '!'");
}
#else
/* skip whitespace before the command */
@@ -478,7 +478,7 @@ static char *add_cmd(sed_cmd_t *sed_cmd, char *cmdstr)
/* last part (mandatory) will be a command */
if (*cmdstr == '\0')
- error_msg_and_die("missing command");
+ bb_error_msg_and_die("missing command");
sed_cmd->cmd = *cmdstr;
cmdstr++;
@@ -517,14 +517,16 @@ static void load_cmd_file(char *filename)
FILE *cmdfile;
char *line;
char *nextline;
+ char *e;
- cmdfile = xfopen(filename, "r");
+ cmdfile = bb_xfopen(filename, "r");
- while ((line = get_line_from_file(cmdfile)) != NULL) {
+ while ((line = bb_get_line_from_file(cmdfile)) != NULL) {
/* if a line ends with '\' it needs the next line appended to it */
- while (line[strlen(line)-2] == '\\' &&
- (nextline = get_line_from_file(cmdfile)) != NULL) {
- line = xrealloc(line, strlen(line) + strlen(nextline) + 1);
+ while (((e = last_char_is(line, '\n')) != NULL)
+ && (e > line) && (e[-1] == '\\')
+ && ((nextline = bb_get_line_from_file(cmdfile)) != NULL)) {
+ line = xrealloc(line, (e - line) + 1 + strlen(nextline) + 1);
strcat(line, nextline);
free(nextline);
}
@@ -677,20 +679,18 @@ static void process_file(FILE *file)
int altered;
int i;
- line = get_line_from_file(file);
+ line = bb_get_chomped_line_from_file(file);
if (line == NULL) {
return;
}
- chomp(line);
/* go through every line in the file */
do {
char *next_line;
/* Read one line in advance so we can act on the last line, the '$' address */
- next_line = get_line_from_file(file);
+ next_line = bb_get_chomped_line_from_file(file);
- chomp(next_line);
linenum++;
altered = 0;
@@ -805,7 +805,7 @@ static void process_file(FILE *file)
puts(line);
outfile = fopen(sed_cmd->filename, "r");
if (outfile)
- print_file(outfile);
+ bb_xprint_and_close_file(outfile);
/* else if we couldn't open the output file,
* no biggie, just don't print anything */
altered++;
@@ -817,16 +817,14 @@ static void process_file(FILE *file)
case 'n': /* Read next line from input */
free(line);
line = next_line;
- next_line = get_line_from_file(file);
- chomp(next_line);
+ next_line = bb_get_chomped_line_from_file(file);
linenum++;
break;
case 'N': /* Append the next line to the current line */
line = realloc(line, strlen(line) + strlen(next_line) + 2);
strcat(line, "\n");
strcat(line, next_line);
- next_line = get_line_from_file(file);
- chomp(next_line);
+ next_line = bb_get_chomped_line_from_file(file);
linenum++;
}
}
@@ -880,7 +878,7 @@ extern int sed_main(int argc, char **argv)
#ifdef CONFIG_FEATURE_CLEAN_UP
/* destroy command strings on exit */
if (atexit(destroy_cmd_strs) == -1)
- perror_msg_and_die("atexit");
+ bb_perror_msg_and_die("atexit");
#endif
/* do normal option parsing */
@@ -896,7 +894,7 @@ extern int sed_main(int argc, char **argv)
load_cmd_file(optarg);
break;
default:
- show_usage();
+ bb_show_usage();
}
}
@@ -904,7 +902,7 @@ extern int sed_main(int argc, char **argv)
* argv[optind] should be the pattern. no pattern, no worky */
if (ncmds == 0) {
if (argv[optind] == NULL)
- show_usage();
+ bb_show_usage();
else {
add_cmd_str(argv[optind]);
optind++;
@@ -921,7 +919,7 @@ extern int sed_main(int argc, char **argv)
int i;
FILE *file;
for (i = optind; i < argc; i++) {
- file = wfopen(argv[i], "r");
+ file = bb_wfopen(argv[i], "r");
if (file) {
process_file(file);
fclose(file);
diff --git a/editors/vi.c b/editors/vi.c
index cda17db..144e9d7 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -19,7 +19,7 @@
*/
static const char vi_Version[] =
- "$Id: vi.c,v 1.27 2002/12/03 21:48:15 bug1 Exp $";
+ "$Id: vi.c,v 1.28 2003/03/19 09:11:45 mjn3 Exp $";
/*
* To compile for standalone use:
@@ -403,7 +403,7 @@ extern int vi_main(int argc, char **argv)
for (; optind < argc; optind++) {
editing = 1; // 0=exit, 1=one file, 2+ =many files
free(cfn);
- cfn = (Byte *) xstrdup(argv[optind]);
+ cfn = (Byte *) bb_xstrdup(argv[optind]);
edit_file(cfn);
}
}
@@ -597,7 +597,7 @@ static Byte *get_one_address(Byte * p, int *addr) // get colon addr, if present
*q++ = *p;
*q = '\0';
}
- pat = (Byte *) xstrdup((char *) buf); // save copy of pattern
+ pat = (Byte *) bb_xstrdup((char *) buf); // save copy of pattern
if (*p == '/')
p++;
q = char_search(dot, pat, FORWARD, FULL);
@@ -811,7 +811,7 @@ static void colon(Byte * buf)
// There is a read-able regular file
// make this the current file
- q = (Byte *) xstrdup((char *) fn); // save the cfn
+ q = (Byte *) bb_xstrdup((char *) fn); // save the cfn
free(cfn); // free the old name
cfn = q; // remember new cfn
@@ -862,7 +862,7 @@ static void colon(Byte * buf)
if (strlen((char *) args) > 0) {
// user wants a new filename
free(cfn);
- cfn = (Byte *) xstrdup((char *) args);
+ cfn = (Byte *) bb_xstrdup((char *) args);
} else {
// user wants file status info
edit_status();
@@ -2432,7 +2432,7 @@ static Byte *get_input_line(Byte * prompt) // get input line- use "status line"
}
refresh(FALSE);
free(obufp);
- obufp = (Byte *) xstrdup((char *) buf);
+ obufp = (Byte *) bb_xstrdup((char *) buf);
return (obufp);
}
@@ -3263,7 +3263,7 @@ key_cmd_mode:
// Stuff the last_modifying_cmd back into stdin
// and let it be re-executed.
if (last_modifying_cmd != 0) {
- ioq = ioq_start = (Byte *) xstrdup((char *) last_modifying_cmd);
+ ioq = ioq_start = (Byte *) bb_xstrdup((char *) last_modifying_cmd);
}
break;
#endif /* CONFIG_FEATURE_VI_DOT_CMD */
@@ -3278,7 +3278,7 @@ key_cmd_mode:
if (strlen((char *) q) > 1) { // new pat- save it and find
// there is a new pat
free(last_search_pattern);
- last_search_pattern = (Byte *) xstrdup((char *) q);
+ last_search_pattern = (Byte *) bb_xstrdup((char *) q);
goto dc3; // now find the pattern
}
// user changed mind and erased the "/"- do nothing