Skip to content

Commit

Permalink
Clean up some more stuff related to char types.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Nov 14, 2023
1 parent 2a79e5c commit 0c39562
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
27 changes: 21 additions & 6 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ static char pipec;
struct ungot {
struct ungot *ug_next;
char ug_char;
lbool ug_end_command;
};
static struct ungot* ungot = NULL;

Expand Down Expand Up @@ -817,7 +818,7 @@ static void prompt(void)
{
constant char *p;

if (ungot != NULL && ungot->ug_char != CHAR_END_COMMAND)
if (ungot != NULL && !ungot->ug_end_command)
{
/*
* No prompt necessary if commands are from
Expand Down Expand Up @@ -940,10 +941,12 @@ static LWCHAR getcc_end_command(void)
/*
* Get a command character from the ungotten stack.
*/
static char get_ungot(void)
static char get_ungot(lbool *p_end_command)
{
struct ungot *ug = ungot;
char c = ug->ug_char;
if (p_end_command != NULL)
*p_end_command = ug->ug_end_command;
ungot = ug->ug_next;
free(ug);
return c;
Expand All @@ -955,7 +958,7 @@ static char get_ungot(void)
public void getcc_clear(void)
{
while (ungot != NULL)
(void) get_ungot();
(void) get_ungot(NULL);
}

/*
Expand All @@ -978,8 +981,9 @@ static char getccu(void)
{
/* Ungotten chars available:
* Take the top of stack (most recent). */
c = get_ungot();
if (c == CHAR_END_COMMAND)
lbool end_command;
c = get_ungot(&end_command);
if (end_command)
c = getcc_end_command();
}
}
Expand Down Expand Up @@ -1052,10 +1056,11 @@ public void ungetcc(char c)
* "Unget" a command character.
* If any other chars are already ungotten, put this one after those.
*/
public void ungetcc_back(char c)
static void ungetcc_back1(char c, lbool end_command)
{
struct ungot *ug = (struct ungot *) ecalloc(1, sizeof(struct ungot));
ug->ug_char = c;
ug->ug_end_command = end_command;
ug->ug_next = NULL;
if (ungot == NULL)
ungot = ug;
Expand All @@ -1068,6 +1073,16 @@ public void ungetcc_back(char c)
}
}

public void ungetcc_back(char c)
{
ungetcc_back1(c, FALSE);
}

public void ungetcc_end_command(void)
{
ungetcc_back1('\0', TRUE);
}

/*
* Unget a whole string of command characters.
* The next sequence of getcc()'s will return this string.
Expand Down
2 changes: 1 addition & 1 deletion edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ public int edit_ifile(IFILE ifile)
if (every_first_cmd != NULL)
{
ungetsc(every_first_cmd);
ungetcc_back(CHAR_END_COMMAND);
ungetcc_end_command();
}
}

Expand Down
1 change: 0 additions & 1 deletion less.h
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,6 @@ typedef enum {
#define ESC CONTROL('[')
#define ESCS "\33"
#define CSI ((unsigned char)'\233')
#define CHAR_END_COMMAND ((char)0377) /*{{ Is this safe? }}*/

#if _OSK_MWC32
#define LSIGNAL(sig,func) os9_signal(sig,func)
Expand Down
2 changes: 1 addition & 1 deletion optfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ public void opt_p(int type, constant char *s)
*/
ungetsc("/");
ungetsc(s);
ungetcc_back(CHAR_END_COMMAND);
ungetcc_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 @@ -154,7 +154,7 @@ public void scan_option(constant char *s)
} else
{
ungetsc(str);
ungetcc_back(CHAR_END_COMMAND);
ungetcc_end_command();
}
free(str);
continue;
Expand Down

0 comments on commit 0c39562

Please sign in to comment.