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.
This commit is contained in:
1 parent
38e9a954ff
commit
f649e21458
3 files changed
+8
-7
No files matched your search
+1
-1
@@ -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':
|
||||
|
||||
+4
-4
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user