(Something I should have done in the previous checkin...) Also broke out

substitution command execution from do_sed_command() and put it in it's own
do_subst_command() function.
This commit is contained in:
Mark Whitley 2000-07-13 20:01:58 +00:00
parent 06f3529ada
commit 4f7fe77d07
2 changed files with 86 additions and 74 deletions

View File

@ -340,23 +340,10 @@ static void load_cmd_file(char *filename)
}
}
static int do_sed_command(const struct sed_cmd *sed_cmd, const char *line)
static int do_subst_command(const struct sed_cmd *sed_cmd, const char *line)
{
int altered = 0;
switch (sed_cmd->cmd) {
case 'p':
fputs(line, stdout);
break;
case 'd':
altered++;
break;
case 's': /* oo, a fun one :-) */
/* we only substitute if the substitution 'search' expression matches */
if (regexec(sed_cmd->sub_match, line, 0, NULL, 0) == 0) {
regmatch_t regmatch;
@ -392,6 +379,25 @@ static int do_sed_command(const struct sed_cmd *sed_cmd, const char *line)
fputs(ptr, stdout);
}
return altered;
}
static int do_sed_command(const struct sed_cmd *sed_cmd, const char *line)
{
int altered = 0;
switch (sed_cmd->cmd) {
case 'p':
fputs(line, stdout);
break;
case 'd':
altered++;
break;
case 's':
altered = do_subst_command(sed_cmd, line);
break;
}

34
sed.c
View File

@ -340,23 +340,10 @@ static void load_cmd_file(char *filename)
}
}
static int do_sed_command(const struct sed_cmd *sed_cmd, const char *line)
static int do_subst_command(const struct sed_cmd *sed_cmd, const char *line)
{
int altered = 0;
switch (sed_cmd->cmd) {
case 'p':
fputs(line, stdout);
break;
case 'd':
altered++;
break;
case 's': /* oo, a fun one :-) */
/* we only substitute if the substitution 'search' expression matches */
if (regexec(sed_cmd->sub_match, line, 0, NULL, 0) == 0) {
regmatch_t regmatch;
@ -392,6 +379,25 @@ static int do_sed_command(const struct sed_cmd *sed_cmd, const char *line)
fputs(ptr, stdout);
}
return altered;
}
static int do_sed_command(const struct sed_cmd *sed_cmd, const char *line)
{
int altered = 0;
switch (sed_cmd->cmd) {
case 'p':
fputs(line, stdout);
break;
case 'd':
altered++;
break;
case 's':
altered = do_subst_command(sed_cmd, line);
break;
}