summaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/awk.c38
-rw-r--r--editors/patch.c12
-rw-r--r--editors/sed.c32
-rw-r--r--editors/vi.c28
4 files changed, 44 insertions, 66 deletions
diff --git a/editors/awk.c b/editors/awk.c
index 16c871f..5d43e1d 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -7,19 +7,9 @@
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <strings.h>
-#include <time.h>
-#include <math.h>
-#include <ctype.h>
-#include <getopt.h>
-
-#include "xregex.h"
#include "busybox.h"
+#include "xregex.h"
+#include <math.h>
#define MAXVARFMT 240
@@ -610,7 +600,7 @@ static inline int isalnum_(int c)
static FILE *afopen(const char *path, const char *mode)
{
- return (*path == '-' && *(path+1) == '\0') ? stdin : bb_xfopen(path, mode);
+ return (*path == '-' && *(path+1) == '\0') ? stdin : xfopen(path, mode);
}
/* -------- working with variables (set/get/copy/etc) -------- */
@@ -672,7 +662,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, const char *value)
{
- return setvar_p(v, (value && *value) ? bb_xstrdup(value) : NULL);
+ return setvar_p(v, (value && *value) ? xstrdup(value) : NULL);
}
/* same as setvar_s but set USER flag */
@@ -709,7 +699,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 = bb_xstrdup(buf);
+ v->string = xstrdup(buf);
v->type |= VF_CACHED;
}
return (v->string == NULL) ? "" : v->string;
@@ -744,7 +734,7 @@ static var *copyvar(var *dest, const var *src)
dest->type |= (src->type & ~VF_DONTTOUCH);
dest->number = src->number;
if (src->string)
- dest->string = bb_xstrdup(src->string);
+ dest->string = xstrdup(src->string);
}
handle_special(dest);
return dest;
@@ -1144,7 +1134,7 @@ static node *chain_node(uint32_t info)
if (seq->programname != programname) {
seq->programname = programname;
n = chain_node(OC_NEWSOURCE);
- n->l.s = bb_xstrdup(programname);
+ n->l.s = xstrdup(programname);
}
n = seq->last;
@@ -1433,7 +1423,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 = bb_xstrndup(s, strlen(s) * 2 + 3);
+ *slist = s1 = xstrndup(s, strlen(s) * 2 + 3);
c[0] = c[1] = (char)spl->info;
c[2] = c[3] = '\0';
@@ -1747,7 +1737,7 @@ static char *awk_printf(node *n)
var *v, *arg;
v = nvalloc(1);
- fmt = f = bb_xstrdup(getvar_s(evaluate(nextarg(&n), v)));
+ fmt = f = xstrdup(getvar_s(evaluate(nextarg(&n), v)));
i = 0;
while (*f) {
@@ -1941,7 +1931,7 @@ static var *exec_builtin(node *op, var *res)
case B_up:
to_xxx = toupper;
lo_cont:
- s1 = s = bb_xstrdup(as[0]);
+ s1 = s = xstrdup(as[0]);
while (*s1) {
*s1 = (*to_xxx)(*s1);
s1++;
@@ -2118,7 +2108,7 @@ static var *evaluate(node *op, var *res)
bb_perror_msg_and_die("popen");
X.rsm->is_pipe = 1;
} else {
- X.rsm->F = bb_xfopen(R.s, opn=='w' ? "w" : "a");
+ X.rsm->F = xfopen(R.s, opn=='w' ? "w" : "a");
}
}
X.F = X.rsm->F;
@@ -2272,7 +2262,7 @@ re_cont:
X.rsm->F = popen(L.s, "r");
X.rsm->is_pipe = TRUE;
} else {
- X.rsm->F = fopen(L.s, "r"); /* not bb_xfopen! */
+ X.rsm->F = fopen(L.s, "r"); /* not xfopen! */
}
}
} else {
@@ -2564,7 +2554,7 @@ static int is_assignment(const char *expr)
{
char *exprc, *s, *s0, *s1;
- exprc = bb_xstrdup(expr);
+ exprc = xstrdup(expr);
if (!isalnum_(*exprc) || (s = strchr(exprc, '=')) == NULL) {
free(exprc);
return FALSE;
@@ -2659,7 +2649,7 @@ int awk_main(int argc, char **argv)
}
for (envp=environ; *envp; envp++) {
- s = bb_xstrdup(*envp);
+ s = xstrdup(*envp);
s1 = strchr(s, '=');
if (!s1) {
goto keep_going;
diff --git a/editors/patch.c b/editors/patch.c
index 337d1bb..a710d82 100644
--- a/editors/patch.c
+++ b/editors/patch.c
@@ -67,7 +67,7 @@ static char *extract_filename(char *line, int patch_level)
filename_start_ptr = temp + 1;
}
- return(bb_xstrdup(filename_start_ptr));
+ return(xstrdup(filename_start_ptr));
}
static int file_doesnt_exist(const char *filename)
@@ -89,7 +89,7 @@ int patch_main(int argc, char **argv)
if (ret & 1)
patch_level = bb_xgetlarg(p, 10, -1, USHRT_MAX);
if (ret & 2) {
- patch_file = bb_xfopen(i, "r");
+ patch_file = xfopen(i, "r");
} else {
patch_file = stdin;
}
@@ -140,7 +140,7 @@ int patch_main(int argc, char **argv)
bb_make_directory(new_filename, -1, FILEUTILS_RECUR);
*line_ptr = '/';
}
- dst_stream = bb_xfopen(new_filename, "w+");
+ dst_stream = xfopen(new_filename, "w+");
backup_filename = NULL;
} else {
backup_filename = xmalloc(strlen(new_filename) + 6);
@@ -150,16 +150,16 @@ int patch_main(int argc, char **argv)
bb_perror_msg_and_die("Couldnt create file %s",
backup_filename);
}
- dst_stream = bb_xfopen(new_filename, "w");
+ dst_stream = xfopen(new_filename, "w");
}
if ((backup_filename == NULL) || file_doesnt_exist(original_filename)) {
src_stream = NULL;
} else {
if (strcmp(original_filename, new_filename) == 0) {
- src_stream = bb_xfopen(backup_filename, "r");
+ src_stream = xfopen(backup_filename, "r");
} else {
- src_stream = bb_xfopen(original_filename, "r");
+ src_stream = xfopen(original_filename, "r");
}
}
diff --git a/editors/sed.c b/editors/sed.c
index 89b8dd7..d5cf3f2 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -132,7 +132,7 @@ void sed_free_and_close_stuff(void)
sed_cmd_t *sed_cmd_next = sed_cmd->next;
if(sed_cmd->file)
- bb_xprint_and_close_file(sed_cmd->file);
+ xprint_and_close_file(sed_cmd->file);
if (sed_cmd->beg_match) {
regfree(sed_cmd->beg_match);
@@ -300,7 +300,7 @@ static int parse_file_cmd(sed_cmd_t *sed_cmd, char *filecmdstr, char **retval)
/* If lines glued together, put backslash back. */
if(filecmdstr[idx]=='\n') hack=1;
if(idx==start) bb_error_msg_and_die("Empty filename");
- *retval = bb_xstrndup(filecmdstr+start, idx-start+hack+1);
+ *retval = xstrndup(filecmdstr+start, idx-start+hack+1);
if(hack) *(idx+*retval)='\\';
return idx;
@@ -406,7 +406,7 @@ static char *parse_cmd_args(sed_cmd_t *sed_cmd, char *cmdstr)
} else if(isspace(*cmdstr)) cmdstr++;
else break;
}
- sed_cmd->string = bb_xstrdup(cmdstr);
+ sed_cmd->string = xstrdup(cmdstr);
parse_escapes(sed_cmd->string,sed_cmd->string,strlen(cmdstr),0,0);
cmdstr += strlen(cmdstr);
/* handle file cmds: (r)ead */
@@ -415,7 +415,7 @@ static char *parse_cmd_args(sed_cmd_t *sed_cmd, char *cmdstr)
bb_error_msg_and_die("Command only uses one address");
cmdstr += parse_file_cmd(sed_cmd, cmdstr, &sed_cmd->string);
if(sed_cmd->cmd=='w')
- sed_cmd->file=bb_xfopen(sed_cmd->string,"w");
+ sed_cmd->file=xfopen(sed_cmd->string,"w");
/* handle branch commands */
} else if (strchr(":btT", sed_cmd->cmd)) {
int length;
@@ -423,7 +423,7 @@ static char *parse_cmd_args(sed_cmd_t *sed_cmd, char *cmdstr)
while(isspace(*cmdstr)) cmdstr++;
length = strcspn(cmdstr, semicolon_whitespace);
if (length) {
- sed_cmd->string = bb_xstrndup(cmdstr, length);
+ sed_cmd->string = xstrndup(cmdstr, length);
cmdstr += length;
}
}
@@ -466,7 +466,7 @@ static void add_cmd(char *cmdstr)
/* Append this line to any unfinished line from last time. */
if (bbg.add_cmd_line) {
- cmdstr = bb_xasprintf("%s\n%s", bbg.add_cmd_line, cmdstr);
+ cmdstr = xasprintf("%s\n%s", bbg.add_cmd_line, cmdstr);
free(bbg.add_cmd_line);
bbg.add_cmd_line = cmdstr;
}
@@ -474,7 +474,7 @@ static void add_cmd(char *cmdstr)
/* If this line ends with backslash, request next line. */
temp=strlen(cmdstr);
if(temp && cmdstr[temp-1]=='\\') {
- if (!bbg.add_cmd_line) bbg.add_cmd_line = bb_xstrdup(cmdstr);
+ if (!bbg.add_cmd_line) bbg.add_cmd_line = xstrdup(cmdstr);
bbg.add_cmd_line[temp-1] = 0;
return;
}
@@ -671,7 +671,7 @@ static sed_cmd_t *branch_to(char *label)
static void append(char *s)
{
- llist_add_to_end(&bbg.append_head, bb_xstrdup(s));
+ llist_add_to_end(&bbg.append_head, xstrdup(s));
}
static void flush_append(void)
@@ -852,7 +852,7 @@ restart:
char *tmp = strchr(pattern_space,'\n');
if(tmp) {
- tmp=bb_xstrdup(tmp+1);
+ tmp=xstrdup(tmp+1);
free(pattern_space);
pattern_space=tmp;
goto restart;
@@ -907,7 +907,7 @@ restart:
while ((line = bb_get_chomped_line_from_file(rfile))
!= NULL)
append(line);
- bb_xprint_and_close_file(rfile);
+ xprint_and_close_file(rfile);
}
break;
@@ -996,7 +996,7 @@ restart:
}
case 'g': /* Replace pattern space with hold space */
free(pattern_space);
- pattern_space = bb_xstrdup(bbg.hold_space ? bbg.hold_space : "");
+ pattern_space = xstrdup(bbg.hold_space ? bbg.hold_space : "");
break;
case 'G': /* Append newline and hold space to pattern space */
{
@@ -1019,7 +1019,7 @@ restart:
}
case 'h': /* Replace hold space with pattern space */
free(bbg.hold_space);
- bbg.hold_space = bb_xstrdup(pattern_space);
+ bbg.hold_space = xstrdup(pattern_space);
break;
case 'H': /* Append newline and pattern space to hold space */
{
@@ -1072,7 +1072,7 @@ discard_line:
static void add_cmd_block(char *cmdstr)
{
int go=1;
- char *temp=bb_xstrdup(cmdstr),*temp2=temp;
+ char *temp=xstrdup(cmdstr),*temp2=temp;
while(go) {
int len=strcspn(temp2,"\n");
@@ -1121,14 +1121,14 @@ int sed_main(int argc, char **argv)
FILE *cmdfile;
char *line;
- cmdfile = bb_xfopen(optarg, "r");
+ cmdfile = xfopen(optarg, "r");
while ((line = bb_get_chomped_line_from_file(cmdfile)) != NULL) {
add_cmd(line);
getpat=0;
free(line);
}
- bb_xprint_and_close_file(cmdfile);
+ xprint_and_close_file(cmdfile);
break;
}
@@ -1172,7 +1172,7 @@ int sed_main(int argc, char **argv)
struct stat statbuf;
int nonstdoutfd;
- bbg.outname=bb_xstrndup(argv[i],strlen(argv[i])+6);
+ bbg.outname=xstrndup(argv[i],strlen(argv[i])+6);
strcat(bbg.outname,"XXXXXX");
if(-1==(nonstdoutfd=mkstemp(bbg.outname)))
bb_error_msg_and_die("no temp file");
diff --git a/editors/vi.c b/editors/vi.c
index e0047e4..593dc85 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -23,18 +23,6 @@
#include "busybox.h"
-#include <string.h>
-#include <strings.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <time.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <setjmp.h>
-#include <regex.h>
-#include <ctype.h>
-#include <errno.h>
-#define vi_Version BB_VER " " BB_BT
#ifdef CONFIG_LOCALE_SUPPORT
#define Isprint(c) isprint((c))
@@ -349,7 +337,7 @@ 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 *) bb_xstrdup(argv[optind]);
+ cfn = (Byte *) xstrdup(argv[optind]);
edit_file(cfn);
}
}
@@ -522,7 +510,7 @@ static Byte *get_one_address(Byte * p, int *addr) // get colon addr, if present
*q++ = *p;
*q = '\0';
}
- pat = (Byte *) bb_xstrdup((char *) buf); // save copy of pattern
+ pat = (Byte *) xstrdup((char *) buf); // save copy of pattern
if (*p == '/')
p++;
q = char_search(dot, pat, FORWARD, FULL);
@@ -736,7 +724,7 @@ static void colon(Byte * buf)
// There is a read-able regular file
// make this the current file
- q = (Byte *) bb_xstrdup((char *) fn); // save the cfn
+ q = (Byte *) xstrdup((char *) fn); // save the cfn
free(cfn); // free the old name
cfn = q; // remember new cfn
@@ -788,7 +776,7 @@ static void colon(Byte * buf)
if (strlen((char *) args) > 0) {
// user wants a new filename
free(cfn);
- cfn = (Byte *) bb_xstrdup((char *) args);
+ cfn = (Byte *) xstrdup((char *) args);
} else {
// user wants file status info
last_status_cksum = 0; // force status update
@@ -996,7 +984,7 @@ static void colon(Byte * buf)
}
#endif /* CONFIG_FEATURE_VI_SEARCH */
} else if (strncasecmp((char *) cmd, "version", i) == 0) { // show software version
- psb("%s", vi_Version);
+ psb("%s", BB_VER " " BB_BT);
} else if (strncasecmp((char *) cmd, "write", i) == 0 // write text to file
|| strncasecmp((char *) cmd, "wq", i) == 0
|| strncasecmp((char *) cmd, "wn", i) == 0
@@ -2313,7 +2301,7 @@ static Byte *get_input_line(Byte * prompt) // get input line- use "status line"
}
refresh(FALSE);
free(obufp);
- obufp = (Byte *) bb_xstrdup((char *) buf);
+ obufp = (Byte *) xstrdup((char *) buf);
return (obufp);
}
@@ -3199,7 +3187,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 *) bb_xstrdup((char *) last_modifying_cmd);
+ ioq = ioq_start = (Byte *) xstrdup((char *) last_modifying_cmd);
}
break;
#endif /* CONFIG_FEATURE_VI_DOT_CMD */
@@ -3214,7 +3202,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 *) bb_xstrdup((char *) q);
+ last_search_pattern = (Byte *) xstrdup((char *) q);
goto dc3; // now find the pattern
}
// user changed mind and erased the "/"- do nothing