Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Krush206 committed May 4, 2024
1 parent a574fd6 commit e59e30a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
4 changes: 3 additions & 1 deletion sh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,9 @@ main(int argc, char **argv)
if (adrof(STRedit))
unsetv(STRedit);
editing = 0;
}
pchrs = ";&\n";
} else
pchrs = ";&\n#";
intty |= intact;
#ifndef convex
if (intty || (intact && isatty(SHOUT))) {
Expand Down
1 change: 1 addition & 0 deletions sh.h
Original file line number Diff line number Diff line change
Expand Up @@ -1305,5 +1305,6 @@ extern int filec;
#define TEXP_IGNORE 1 /* in ignore, it means to ignore value, just parse */
#define TEXP_NOGLOB 2 /* in ignore, it means not to globone */

extern char *pchrs;

#endif /* _h_sh */
16 changes: 8 additions & 8 deletions sh.lex.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,15 @@ word(int parsehtime)
goto ret;

case '#':
if (intty || (enterhist && !parsehtime))
if (enterhist && !parsehtime)
break;
if (intty) {
do
Strbuf_append1(&wbuf, c);
while ((c = getC(0)) != CHAR_ERR && c != '\n');
ungetC('\n');
goto ret;
}
c = 0;
h = 0;
do {
Expand Down Expand Up @@ -357,13 +364,6 @@ word(int parsehtime)
default:
break;
}
if (intty && c == '#') {
Strbuf_append1(&wbuf, c);
while ((c = readc(1)) != CHAR_ERR && c != '\n')
Strbuf_append1(&wbuf, c);
unreadc('\n');
goto ret;
}
c1 = 0;
dolflg = DOALL;
for (;;) {
Expand Down
9 changes: 6 additions & 3 deletions sh.parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ freenod(struct wordent *p1, struct wordent *p2)
#define P_OUT 4
#define P_DIAG 8

char *pchrs;

/*
* syntax
* empty
Expand All @@ -205,9 +207,8 @@ freenod(struct wordent *p1, struct wordent *p2)
struct command *
syntax(const struct wordent *p1, const struct wordent *p2, int flags)
{

while (p1 != p2)
if (any(intty ? ";&\n#" : ";&\n", p1->word[0]))
if (any(pchrs, p1->word[0]))
p1 = p1->next;
else
return (syn0(p1, p2, flags));
Expand Down Expand Up @@ -281,11 +282,13 @@ syn0(const struct wordent *p1, const struct wordent *p2, int flags)
p1 = p1->prev = p1->prev->prev;
xfree(p1->next->word);
xfree(p1->next);
p = p1->next = p2->prev;
p1->next = p2->prev;
goto out;
}
default:
break;
}
out:
if (l == 0)
return (syn1(p1, p2, flags));
seterror(ERR_TOOMANYLP);
Expand Down

0 comments on commit e59e30a

Please sign in to comment.