Skip to content

Commit

Permalink
implement MORE [fixes #17]
Browse files Browse the repository at this point in the history
  • Loading branch information
stsp committed Mar 12, 2024
1 parent cf949fa commit 8ec37d6
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ static char pipe_file[2][MAX_CMD_BUFLEN] = {"",""};
static int pipe_file_redir_count[2];
static char pipe_to_cmd[MAX_CMD_BUFLEN] = "";
static int pipe_to_cmd_redir_count;
static FILE *bkp_stdin;

/*
* Command interpreter/executor defines/variables
Expand Down Expand Up @@ -3291,9 +3292,23 @@ static void perform_md(const char *arg)

static void perform_more(const char *arg)
{
int c;
while ((c = getchar()) != EOF)
putchar(c);
struct text_info txinfo;

gettextinfo(&txinfo);
int c, cnt = 0;
while ((c = getchar()) != EOF)
{
putchar(c);
if (c == '\n')
{
if (++cnt == txinfo.winbottom - 1)
{
cnt = 0;
printf("--More--");
fgetc(bkp_stdin);
}
}
}
}

static void perform_move(const char *arg)
Expand Down Expand Up @@ -4234,6 +4249,8 @@ static void exec_cmd(int call)
pipe_fno[pipe_index] = -1;
}
}
if (old_std_fno[STDIN_INDEX] >= 0)
bkp_stdin = fdopen(old_std_fno[STDIN_INDEX], "r");

while (cmd[0] != '\0')
{
Expand Down Expand Up @@ -4287,7 +4304,7 @@ static void exec_cmd(int call)
cmd_line[0] = '\0';
if (redir_result[STDIN_INDEX] != -1) {
dup2(old_std_fno[STDIN_INDEX], STDIN_INDEX);
close(old_std_fno[STDIN_INDEX]);
fclose(bkp_stdin); // closes also fd
setbuf(stdin, NULL);
clearerr(stdin);
}
Expand Down

0 comments on commit 8ec37d6

Please sign in to comment.