Changed bb_regcomp to xregcomp and #if 0'ed out destroy_cmd_strs in sed.c
(maybe I'll remove it later).
This commit is contained in:
parent
6f96e674b9
commit
c41e8c840f
@ -97,6 +97,7 @@ static const char sed_usage[] =
|
|||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
|
|
||||||
|
#if 0
|
||||||
static void destroy_cmd_strs()
|
static void destroy_cmd_strs()
|
||||||
{
|
{
|
||||||
if (sed_cmds == NULL)
|
if (sed_cmds == NULL)
|
||||||
@ -125,6 +126,7 @@ static void destroy_cmd_strs()
|
|||||||
free(sed_cmds);
|
free(sed_cmds);
|
||||||
sed_cmds = NULL;
|
sed_cmds = NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* trim_str - trims leading and trailing space from a string
|
* trim_str - trims leading and trailing space from a string
|
||||||
@ -199,10 +201,7 @@ static int get_address(const char *str, int *line, regex_t **regex)
|
|||||||
fatalError("unterminated match expression\n");
|
fatalError("unterminated match expression\n");
|
||||||
my_str[idx] = '\0';
|
my_str[idx] = '\0';
|
||||||
*regex = (regex_t *)xmalloc(sizeof(regex_t));
|
*regex = (regex_t *)xmalloc(sizeof(regex_t));
|
||||||
if (bb_regcomp(*regex, my_str+1, REG_NEWLINE) != 0) {
|
xregcomp(*regex, my_str+1, REG_NEWLINE);
|
||||||
free(my_str);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "sed.c:get_address: no address found in string\n");
|
fprintf(stderr, "sed.c:get_address: no address found in string\n");
|
||||||
@ -291,10 +290,7 @@ static void parse_cmd_str(struct sed_cmd *sed_cmd, const char *cmdstr)
|
|||||||
|
|
||||||
/* compile the regex */
|
/* compile the regex */
|
||||||
sed_cmd->sub_match = (regex_t *)xmalloc(sizeof(regex_t));
|
sed_cmd->sub_match = (regex_t *)xmalloc(sizeof(regex_t));
|
||||||
if (bb_regcomp(sed_cmd->sub_match, match, cflags) != 0) {
|
xregcomp(sed_cmd->sub_match, match, cflags);
|
||||||
free(match);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
free(match);
|
free(match);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -460,11 +456,13 @@ extern int sed_main(int argc, char **argv)
|
|||||||
if (argv[1] && (strcmp(argv[1], "--help") == 0))
|
if (argv[1] && (strcmp(argv[1], "--help") == 0))
|
||||||
usage(sed_usage);
|
usage(sed_usage);
|
||||||
|
|
||||||
|
#if 0
|
||||||
/* destroy command strings on exit */
|
/* destroy command strings on exit */
|
||||||
if (atexit(destroy_cmd_strs) == -1) {
|
if (atexit(destroy_cmd_strs) == -1) {
|
||||||
perror("sed");
|
perror("sed");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* do normal option parsing */
|
/* do normal option parsing */
|
||||||
while ((opt = getopt(argc, argv, "Vhne:f:")) > 0) {
|
while ((opt = getopt(argc, argv, "Vhne:f:")) > 0) {
|
||||||
|
@ -146,8 +146,7 @@ extern int grep_main(int argc, char **argv)
|
|||||||
reflags = REG_NOSUB | REG_NEWLINE;
|
reflags = REG_NOSUB | REG_NEWLINE;
|
||||||
if (ignore_case)
|
if (ignore_case)
|
||||||
reflags |= REG_ICASE;
|
reflags |= REG_ICASE;
|
||||||
if (bb_regcomp(®ex, argv[optind], reflags) != 0)
|
xregcomp(®ex, argv[optind], reflags);
|
||||||
exit(1);
|
|
||||||
|
|
||||||
/* argv[(optind+1)..(argc-1)] should be names of file to grep through. If
|
/* argv[(optind+1)..(argc-1)] should be names of file to grep through. If
|
||||||
* there is more than one file to grep, we will print the filenames */
|
* there is more than one file to grep, we will print the filenames */
|
||||||
|
3
grep.c
3
grep.c
@ -146,8 +146,7 @@ extern int grep_main(int argc, char **argv)
|
|||||||
reflags = REG_NOSUB | REG_NEWLINE;
|
reflags = REG_NOSUB | REG_NEWLINE;
|
||||||
if (ignore_case)
|
if (ignore_case)
|
||||||
reflags |= REG_ICASE;
|
reflags |= REG_ICASE;
|
||||||
if (bb_regcomp(®ex, argv[optind], reflags) != 0)
|
xregcomp(®ex, argv[optind], reflags);
|
||||||
exit(1);
|
|
||||||
|
|
||||||
/* argv[(optind+1)..(argc-1)] should be names of file to grep through. If
|
/* argv[(optind+1)..(argc-1)] should be names of file to grep through. If
|
||||||
* there is more than one file to grep, we will print the filenames */
|
* there is more than one file to grep, we will print the filenames */
|
||||||
|
@ -265,7 +265,7 @@ extern int find_real_root_device_name(char* name);
|
|||||||
extern char *get_line_from_file(FILE *file);
|
extern char *get_line_from_file(FILE *file);
|
||||||
extern char process_escape_sequence(char **ptr);
|
extern char process_escape_sequence(char **ptr);
|
||||||
extern char *get_last_path_component(char *path);
|
extern char *get_last_path_component(char *path);
|
||||||
extern int bb_regcomp(regex_t *preg, const char *regex, int cflags);
|
extern void xregcomp(regex_t *preg, const char *regex, int cflags);
|
||||||
|
|
||||||
extern void *xmalloc (size_t size);
|
extern void *xmalloc (size_t size);
|
||||||
extern char *xstrdup (const char *s);
|
extern char *xstrdup (const char *s);
|
||||||
|
14
sed.c
14
sed.c
@ -97,6 +97,7 @@ static const char sed_usage[] =
|
|||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
|
|
||||||
|
#if 0
|
||||||
static void destroy_cmd_strs()
|
static void destroy_cmd_strs()
|
||||||
{
|
{
|
||||||
if (sed_cmds == NULL)
|
if (sed_cmds == NULL)
|
||||||
@ -125,6 +126,7 @@ static void destroy_cmd_strs()
|
|||||||
free(sed_cmds);
|
free(sed_cmds);
|
||||||
sed_cmds = NULL;
|
sed_cmds = NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* trim_str - trims leading and trailing space from a string
|
* trim_str - trims leading and trailing space from a string
|
||||||
@ -199,10 +201,7 @@ static int get_address(const char *str, int *line, regex_t **regex)
|
|||||||
fatalError("unterminated match expression\n");
|
fatalError("unterminated match expression\n");
|
||||||
my_str[idx] = '\0';
|
my_str[idx] = '\0';
|
||||||
*regex = (regex_t *)xmalloc(sizeof(regex_t));
|
*regex = (regex_t *)xmalloc(sizeof(regex_t));
|
||||||
if (bb_regcomp(*regex, my_str+1, REG_NEWLINE) != 0) {
|
xregcomp(*regex, my_str+1, REG_NEWLINE);
|
||||||
free(my_str);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "sed.c:get_address: no address found in string\n");
|
fprintf(stderr, "sed.c:get_address: no address found in string\n");
|
||||||
@ -291,10 +290,7 @@ static void parse_cmd_str(struct sed_cmd *sed_cmd, const char *cmdstr)
|
|||||||
|
|
||||||
/* compile the regex */
|
/* compile the regex */
|
||||||
sed_cmd->sub_match = (regex_t *)xmalloc(sizeof(regex_t));
|
sed_cmd->sub_match = (regex_t *)xmalloc(sizeof(regex_t));
|
||||||
if (bb_regcomp(sed_cmd->sub_match, match, cflags) != 0) {
|
xregcomp(sed_cmd->sub_match, match, cflags);
|
||||||
free(match);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
free(match);
|
free(match);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -460,11 +456,13 @@ extern int sed_main(int argc, char **argv)
|
|||||||
if (argv[1] && (strcmp(argv[1], "--help") == 0))
|
if (argv[1] && (strcmp(argv[1], "--help") == 0))
|
||||||
usage(sed_usage);
|
usage(sed_usage);
|
||||||
|
|
||||||
|
#if 0
|
||||||
/* destroy command strings on exit */
|
/* destroy command strings on exit */
|
||||||
if (atexit(destroy_cmd_strs) == -1) {
|
if (atexit(destroy_cmd_strs) == -1) {
|
||||||
perror("sed");
|
perror("sed");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* do normal option parsing */
|
/* do normal option parsing */
|
||||||
while ((opt = getopt(argc, argv, "Vhne:f:")) > 0) {
|
while ((opt = getopt(argc, argv, "Vhne:f:")) > 0) {
|
||||||
|
@ -1722,18 +1722,15 @@ char *get_last_path_component(char *path)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined BB_GREP || defined BB_SED
|
#if defined BB_GREP || defined BB_SED
|
||||||
int bb_regcomp(regex_t *preg, const char *regex, int cflags)
|
void xregcomp(regex_t *preg, const char *regex, int cflags)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
if ((ret = regcomp(preg, regex, cflags)) != 0) {
|
if ((ret = regcomp(preg, regex, cflags)) != 0) {
|
||||||
int errmsgsz = regerror(ret, preg, NULL, 0);
|
int errmsgsz = regerror(ret, preg, NULL, 0);
|
||||||
char *errmsg = xmalloc(errmsgsz);
|
char *errmsg = xmalloc(errmsgsz);
|
||||||
regerror(ret, preg, errmsg, errmsgsz);
|
regerror(ret, preg, errmsg, errmsgsz);
|
||||||
errorMsg("bb_regcomp: %s\n", errmsg);
|
fatalError("bb_regcomp: %s\n", errmsg);
|
||||||
free(errmsg);
|
|
||||||
regfree(preg);
|
|
||||||
}
|
}
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user