Browse Source

lexical #13/19, delay `append'

delay its execution, until
    either `wlist' or `cw' will be accessed,
  or
    a return or goto nloop is inevitable
rlar 14 years ago
parent
commit
01df4e9437
  1. 19
      src/frontend/parser/lexical.c

19
src/frontend/parser/lexical.c

@ -84,8 +84,11 @@ static int numeofs = 0;
wlist = cw; \ wlist = cw; \
} }
#define newword cw->wl_word = copy(buf); \
append; \
#define newword \
if (delayed) append; \
delayed = 0; \
cw->wl_word = copy(buf); \
delayed = 1; \
bzero(buf, NEW_BSIZE_SP); \ bzero(buf, NEW_BSIZE_SP); \
i = 0; i = 0;
@ -118,6 +121,7 @@ cp_lexer(char *string)
wordlist *wlist = NULL, *cw = NULL; wordlist *wlist = NULL, *cw = NULL;
char buf[NEW_BSIZE_SP], linebuf[NEW_BSIZE_SP]; char buf[NEW_BSIZE_SP], linebuf[NEW_BSIZE_SP];
int paren; int paren;
int delayed;
if (cp_inp_cur == NULL) if (cp_inp_cur == NULL)
cp_inp_cur = cp_in; cp_inp_cur = cp_in;
@ -133,8 +137,7 @@ nloop:
paren = 0; paren = 0;
bzero(linebuf, NEW_BSIZE_SP); bzero(linebuf, NEW_BSIZE_SP);
bzero(buf, NEW_BSIZE_SP); bzero(buf, NEW_BSIZE_SP);
append;
// from here on cw != NULL and wlist != NULL
delayed = 1;
for (;;) { for (;;) {
if (string) { if (string) {
c = *string++; c = *string++;
@ -172,6 +175,8 @@ gotchar:
if ((c == EOF) && cp_bqflag) if ((c == EOF) && cp_bqflag)
c = '\n'; c = '\n';
if ((c == cp_hash) && !cp_interactive && (j == 1)) { if ((c == cp_hash) && !cp_interactive && (j == 1)) {
if (delayed) append;
delayed = 0;
if (string) if (string)
return (NULL); return (NULL);
while (((c = input(cp_inp_cur)) != '\n') && (c != EOF)) while (((c = input(cp_inp_cur)) != '\n') && (c != EOF))
@ -198,6 +203,8 @@ gotchar:
buf[i] = '\0'; buf[i] = '\0';
newword; newword;
} }
if (delayed) append;
delayed = 0;
if (cw->wl_prev) { if (cw->wl_prev) {
cw->wl_prev->wl_next = NULL; cw->wl_prev->wl_next = NULL;
tfree(cw); tfree(cw);
@ -245,6 +252,8 @@ gotchar:
case '\004': case '\004':
case EOF: case EOF:
if (delayed) append;
delayed = 0;
if (cp_interactive && !cp_nocc && if (cp_interactive && !cp_nocc &&
(string == NULL)) { (string == NULL)) {
if (j == 0) { if (j == 0) {
@ -291,6 +300,8 @@ gotchar:
#else #else
fputc(linebuf[j], cp_out); /* But you can't edit */ fputc(linebuf[j], cp_out); /* But you can't edit */
#endif #endif
if (delayed) append;
delayed = 0;
// cp_ccom doesn't mess wlist, read only access to wlist->wl_word // cp_ccom doesn't mess wlist, read only access to wlist->wl_word
cp_ccom(wlist, buf, TRUE); cp_ccom(wlist, buf, TRUE);
wl_free(wlist); wl_free(wlist);

Loading…
Cancel
Save