Refactor redirection data structure, no functional change:
(redir_is_pipe): New. (doredir, dopipe): Set it. (pipe_fp): Remove. Users changed to use redir_fp and redir_is_pipe.
This commit is contained in:
parent
bde3d0c17d
commit
a29a8f43ab
1 changed files with 9 additions and 15 deletions
|
@ -50,7 +50,7 @@ int eight_bit_clean;
|
||||||
FILE *auxfp;
|
FILE *auxfp;
|
||||||
|
|
||||||
static FILE *redir_fp;
|
static FILE *redir_fp;
|
||||||
static FILE *pipe_fp;
|
static int redir_is_pipe;
|
||||||
static int executing;
|
static int executing;
|
||||||
static size_t input_to_forget;
|
static size_t input_to_forget;
|
||||||
|
|
||||||
|
@ -74,11 +74,11 @@ servercmd(int code, char *arg, int len)
|
||||||
snprintf(the_prompt, sizeof(the_prompt), "[%d:%d] Command : ",
|
snprintf(the_prompt, sizeof(the_prompt), "[%d:%d] Command : ",
|
||||||
nmin, nbtu);
|
nmin, nbtu);
|
||||||
if (redir_fp) {
|
if (redir_fp) {
|
||||||
(void)fclose(redir_fp);
|
if (redir_is_pipe)
|
||||||
|
(void)pclose(redir_fp);
|
||||||
|
else
|
||||||
|
(void)fclose(redir_fp);
|
||||||
redir_fp = NULL;
|
redir_fp = NULL;
|
||||||
} else if (pipe_fp) {
|
|
||||||
(void)pclose(pipe_fp);
|
|
||||||
pipe_fp = NULL;
|
|
||||||
}
|
}
|
||||||
if (input_to_forget) {
|
if (input_to_forget) {
|
||||||
forget_input(input_to_forget);
|
forget_input(input_to_forget);
|
||||||
|
@ -113,7 +113,7 @@ servercmd(int code, char *arg, int len)
|
||||||
case C_INFORM:
|
case C_INFORM:
|
||||||
if (*arg) {
|
if (*arg) {
|
||||||
snprintf(teles, sizeof(teles), "(%.*s )", len -1, arg);
|
snprintf(teles, sizeof(teles), "(%.*s )", len -1, arg);
|
||||||
if (!redir_fp && !pipe_fp) {
|
if (!redir_fp) {
|
||||||
putchar('\07');
|
putchar('\07');
|
||||||
prompt(code, the_prompt, teles);
|
prompt(code, the_prompt, teles);
|
||||||
}
|
}
|
||||||
|
@ -176,9 +176,6 @@ redir_authorized(char *arg, char *attempt)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* opens redir_fp if successful
|
|
||||||
*/
|
|
||||||
static void
|
static void
|
||||||
doredir(char *p)
|
doredir(char *p)
|
||||||
{
|
{
|
||||||
|
@ -213,6 +210,7 @@ doredir(char *p)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
redir_is_pipe = 0;
|
||||||
fd = open(p, mode, 0666);
|
fd = open(p, mode, 0666);
|
||||||
redir_fp = fd < 0 ? NULL : fdopen(fd, "w");
|
redir_fp = fd < 0 ? NULL : fdopen(fd, "w");
|
||||||
if (!redir_fp) {
|
if (!redir_fp) {
|
||||||
|
@ -221,9 +219,6 @@ doredir(char *p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* opens "pipe_fp" if successful
|
|
||||||
*/
|
|
||||||
static void
|
static void
|
||||||
dopipe(char *p)
|
dopipe(char *p)
|
||||||
{
|
{
|
||||||
|
@ -240,7 +235,8 @@ dopipe(char *p)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pipe_fp = popen(p, "w")) == NULL) {
|
redir_is_pipe = 1;
|
||||||
|
if ((redir_fp = popen(p, "w")) == NULL) {
|
||||||
fprintf(stderr, "Can't redirect to pipe %s: %s\n",
|
fprintf(stderr, "Can't redirect to pipe %s: %s\n",
|
||||||
p, strerror(errno));
|
p, strerror(errno));
|
||||||
}
|
}
|
||||||
|
@ -276,8 +272,6 @@ outch(char c)
|
||||||
putc(c, auxfp);
|
putc(c, auxfp);
|
||||||
if (redir_fp)
|
if (redir_fp)
|
||||||
putc(c, redir_fp);
|
putc(c, redir_fp);
|
||||||
else if (pipe_fp)
|
|
||||||
putc(c, pipe_fp);
|
|
||||||
else if (eight_bit_clean) {
|
else if (eight_bit_clean) {
|
||||||
if (c == 14)
|
if (c == 14)
|
||||||
putso();
|
putso();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue