Skip to content

Commit

Permalink
Better handling of multiple -p and/or + command line options.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Dec 4, 2020
1 parent 879c4e5 commit 607c9b6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
65 changes: 44 additions & 21 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ getcc_end_command(VOID_PARAM)
return ('\n');
default:
/* Some other incomplete command. Let user complete it. */
return (getchr());
return ((ungot == NULL) ? getchr() : 0);
}
}

Expand All @@ -850,23 +850,26 @@ getcc_end_command(VOID_PARAM)
static LWCHAR
getccu(VOID_PARAM)
{
LWCHAR c;
if (ungot == NULL)
{
/* Normal case: no ungotten chars.
* Get char from the user. */
c = getchr();
} else
LWCHAR c = 0;
while (c == 0)
{
/* Ungotten chars available:
* Take the top of stack (most recent). */
struct ungot *ug = ungot;
c = ug->ug_char;
ungot = ug->ug_next;
free(ug);

if (c == CHAR_END_COMMAND)
c = getcc_end_command();
if (ungot == NULL)
{
/* Normal case: no ungotten chars.
* Get char from the user. */
c = getchr();
} else
{
/* Ungotten chars available:
* Take the top of stack (most recent). */
struct ungot *ug = ungot;
c = ug->ug_char;
ungot = ug->ug_next;
free(ug);

if (c == CHAR_END_COMMAND)
c = getcc_end_command();
}
}
return (c);
}
Expand Down Expand Up @@ -941,6 +944,28 @@ ungetcc(c)
ungot = ug;
}

/*
* "Unget" a command character.
* If any other chars are already ungotten, put this one after those.
*/
public void
ungetcc_back(c)
LWCHAR c;
{
struct ungot *ug = (struct ungot *) ecalloc(1, sizeof(struct ungot));
ug->ug_char = c;
ug->ug_next = NULL;
if (ungot == NULL)
ungot = ug;
else
{
struct ungot *pu;
for (pu = ungot; pu->ug_next != NULL; pu = pu->ug_next)
continue;
pu->ug_next = ug;
}
}

/*
* Unget a whole string of command characters.
* The next sequence of getcc()'s will return this string.
Expand All @@ -949,10 +974,8 @@ ungetcc(c)
ungetsc(s)
char *s;
{
char *p;

for (p = s + strlen(s) - 1; p >= s; p--)
ungetcc(*p);
while (*s != '\0')
ungetcc_back(*s++);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ edit_ifile(ifile)
#endif
if (every_first_cmd != NULL)
{
ungetcc(CHAR_END_COMMAND);
ungetsc(every_first_cmd);
ungetcc_back(CHAR_END_COMMAND);
}
}

Expand Down
4 changes: 2 additions & 2 deletions optfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,13 @@ opt_p(type, s)
} else
{
plusoption = TRUE;
ungetcc(CHAR_END_COMMAND);
ungetsc(s);
/*
* {{ This won't work if the "/" command is
* changed or invalidated by a .lesskey file. }}
*/
ungetsc("/");
ungetsc(s);
ungetcc_back(CHAR_END_COMMAND);
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion option.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ scan_option(s)
every_first_cmd = save(str+1);
} else
{
ungetcc(CHAR_END_COMMAND);
ungetsc(str);
ungetcc_back(CHAR_END_COMMAND);
}
free(str);
continue;
Expand Down

0 comments on commit 607c9b6

Please sign in to comment.