summaryrefslogtreecommitdiff
path: root/sed
diff options
context:
space:
mode:
authorAssaf Gordon <assafgordon@gmail.com>2018-10-12 14:00:33 -0600
committerAssaf Gordon <assafgordon@gmail.com>2018-10-19 10:37:32 -0600
commitf649e21458328ee1075fc31a49cf0a431f16d21d (patch)
tree08eac753e53474b326718f263d7561ebdb4b18d8 /sed
parent38e9a954ff5bda5c757596084536bff1db503432 (diff)
downloadsed-f649e21458328ee1075fc31a49cf0a431f16d21d.tar.gz
sed: change internal storage for 'R' command
For the 'R' command, keep a pointer to 'struct output' instead of just to FILE*. No change in functionality. This will help future debug code to know the filename of the associated file. As a side effect, fix invalid code in W/w execution: The previous code checked for 'cur_cmd->x.fp' (which was related to R command, not W/w). Since 'x' is a union, 'x.fp' was not relevant to the 'x.outf' (which is the struct associted with W/w commands). * sed/sed.h (struct sed_cmd): Replace 'FILE*' with 'struct *output' for R command. * sed/compile.c (compile_program): Adjust as needed. * sed/execute.c (execute_program): Adjust as needed.
Diffstat (limited to 'sed')
-rw-r--r--sed/compile.c2
-rw-r--r--sed/execute.c8
-rw-r--r--sed/sed.h5
3 files changed, 8 insertions, 7 deletions
diff --git a/sed/compile.c b/sed/compile.c
index 184eeb3..9190b73 100644
--- a/sed/compile.c
+++ b/sed/compile.c
@@ -1195,7 +1195,7 @@ compile_program (struct vector *vector)
break;
case 'R':
- cur_cmd->x.fp = get_openfile (&file_read, read_mode, false)->fp;
+ cur_cmd->x.inf = get_openfile (&file_read, read_mode, false);
break;
case 'W':
diff --git a/sed/execute.c b/sed/execute.c
index 741ed3c..e0c2ee1 100644
--- a/sed/execute.c
+++ b/sed/execute.c
@@ -1433,7 +1433,7 @@ execute_program (struct vector *vec, struct input *input)
break;
case 'R':
- if (cur_cmd->x.fp && !feof (cur_cmd->x.fp))
+ if (cur_cmd->x.inf->fp && !feof (cur_cmd->x.inf->fp))
{
struct append_queue *aq;
size_t buflen;
@@ -1441,7 +1441,7 @@ execute_program (struct vector *vec, struct input *input)
int result;
result = ck_getdelim (&text, &buflen, buffer_delimiter,
- cur_cmd->x.fp);
+ cur_cmd->x.inf->fp);
if (result != EOF)
{
aq = next_append_slot ();
@@ -1483,13 +1483,13 @@ execute_program (struct vector *vec, struct input *input)
break;
case 'w':
- if (cur_cmd->x.fp)
+ if (cur_cmd->x.outf->fp)
output_line (line.active, line.length,
line.chomped, cur_cmd->x.outf);
break;
case 'W':
- if (cur_cmd->x.fp)
+ if (cur_cmd->x.outf->fp)
{
char *p = memchr (line.active, buffer_delimiter, line.length);
output_line (line.active, p ? p - line.active : line.length,
diff --git a/sed/sed.h b/sed/sed.h
index be26511..86c5a8a 100644
--- a/sed/sed.h
+++ b/sed/sed.h
@@ -166,8 +166,9 @@ struct sed_cmd {
/* This is used for the w command. */
struct output *outf;
- /* This is used for the R command. */
- FILE *fp;
+ /* This is used for the R command.
+ (despite the struct name, it is used for both in and out files). */
+ struct output *inf;
/* This is used for the y command. */
unsigned char *translate;