Skip to content

Commit 159d11f

Browse files
committed
DELETE THIS: partial rollback of branch for circleci git bisection (2)
1 parent b8110e9 commit 159d11f

File tree

13 files changed

+221
-170
lines changed

13 files changed

+221
-170
lines changed

Makefile.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ VPATH = $(srcdir)
5656
HFILES = config.h es.h gc.h input.h prim.h print.h sigmsgs.h \
5757
stdenv.h syntax.h term.h var.h
5858
CFILES = access.c closure.c conv.c dict.c eval.c except.c fd.c gc.c glob.c \
59-
glom.c input.c heredoc.c list.c main.c match.c open.c opt.c \
59+
glom.c input.c heredoc.c history.c list.c main.c match.c open.c opt.c \
6060
prim-ctl.c prim-etc.c prim-io.c readline.c prim-sys.c prim.c \
6161
print.c proc.c sigmsgs.c signal.c split.c status.c str.c syntax.c \
6262
term.c token.c tree.c util.c var.c vec.c version.c y.tab.c dump.c
6363
OFILES = access.o closure.o conv.o dict.o eval.o except.o fd.o gc.o glob.o \
64-
glom.o input.o heredoc.o list.o main.o match.o open.o opt.o \
64+
glom.o input.o heredoc.o history.o list.o main.o match.o open.o opt.o \
6565
prim-ctl.o prim-etc.o prim-io.o readline.o prim-sys.o prim.o \
6666
print.o proc.o sigmsgs.o signal.o split.o status.o str.o syntax.o \
6767
term.o token.o tree.o util.o var.o vec.o version.o y.tab.o
@@ -135,6 +135,7 @@ glob.o : glob.c es.h config.h stdenv.h gc.h
135135
glom.o : glom.c es.h config.h stdenv.h gc.h
136136
input.o : input.c es.h config.h stdenv.h input.h
137137
heredoc.o : heredoc.c es.h config.h stdenv.h gc.h input.h syntax.h
138+
history.o : history.c es.h config.h stdenv.h gc.h input.h
138139
list.o : list.c es.h config.h stdenv.h gc.h
139140
main.o : main.c es.h config.h stdenv.h
140141
match.o : match.c es.h config.h stdenv.h

es.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ extern Boolean streq2(const char *s, const char *t1, const char *t2);
291291
/* input.c */
292292

293293
extern char *prompt, *prompt2;
294-
extern Tree *parse(List *);
294+
extern Tree *parse(char *esprompt1, char *esprompt2);
295295
extern Tree *parsestring(const char *str);
296296
extern Boolean isinteractive(void);
297297
extern Boolean isfromfd(void);
@@ -317,10 +317,17 @@ extern void inithistory(void);
317317
extern void sethistory(char *file);
318318
extern void loghistory(char *cmd);
319319
extern void setmaxhistorylength(int length);
320-
extern void rlsetup(void);
320+
extern void rlsetup(Boolean fromprim);
321321
#endif
322322

323323

324+
/* history.c */
325+
326+
extern void newhistbuffer(void);
327+
extern void addhistbuffer(char c);
328+
extern char *dumphistbuffer(void);
329+
330+
324331
/* opt.c */
325332

326333
extern void esoptbegin(List *list, const char *caller, const char *usage, Boolean throws);

gc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ extern void *pseal(void *p) {
471471
if (psize == 0)
472472
return p;
473473

474-
/* TODO: this is an overestimate since it includes garbage */
474+
/* TODO: this is an overestimate since it contains garbage */
475475
gcreserve(psize);
476476
pmode = TRUE;
477477
VERBOSE(("Reserved %d for pspace copy\n", psize));
@@ -483,9 +483,9 @@ extern void *pseal(void *p) {
483483
for (sp = pspace; sp != NULL; sp = sp->next)
484484
VERBOSE(("GC pspace = %ux ... %ux\n", sp->bot, sp->current));
485485
#endif
486-
if (p != NULL) {
487-
VERBOSE(("GC new space = %ux ... %ux\n", new->bot, new->top));
486+
VERBOSE(("GC new space = %ux ... %ux\n", new->bot, new->top));
488487

488+
if (p != NULL) {
489489
p = forward(p);
490490
(*(TAG(p))->scan)(p);
491491
}

heredoc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extern Tree *snarfheredoc(const char *eof, Boolean quoted) {
4747

4848
for (tree = NULL, tailp = &tree, buf = openbuffer(0);;) {
4949
int c;
50-
increment_line();
50+
print_prompt2();
5151
for (s = (unsigned char *) eof; (c = GETC()) == *s; s++)
5252
;
5353
if (*s == '\0' && (c == '\n' || c == EOF)) {

history.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* history.c -- control the history file ($Revision: 1.1.1.1 $) */
2+
3+
#include "es.h"
4+
#include "gc.h"
5+
#include "input.h"
6+
7+
8+
/*
9+
* constants
10+
*/
11+
12+
#define BUFSIZE ((size_t) 4096) /* buffer size to fill reads into */
13+
14+
15+
/*
16+
* globals
17+
*/
18+
19+
static Buffer *histbuffer = NULL;
20+
21+
22+
/*
23+
* histbuffer -- build the history line during input and dump it as a gc-string
24+
*/
25+
26+
extern void newhistbuffer() {
27+
assert(histbuffer == NULL);
28+
histbuffer = openbuffer(BUFSIZE);
29+
}
30+
31+
extern void addhistbuffer(char c) {
32+
if (histbuffer == NULL)
33+
return;
34+
histbuffer = bufputc(histbuffer, c);
35+
}
36+
37+
extern char *dumphistbuffer() {
38+
char *s;
39+
size_t len;
40+
assert(histbuffer != NULL);
41+
42+
s = sealcountedbuffer(histbuffer);
43+
histbuffer = NULL;
44+
45+
len = strlen(s);
46+
if (len > 0 && s[len - 1] == '\n')
47+
s[len - 1] = '\0';
48+
return s;
49+
}

initial.es

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -648,29 +648,10 @@ if {~ <=$&primitives writehistory} {
648648
# The parsed code is executed only if it is non-empty, because otherwise
649649
# result gets set to zero when it should not be.
650650

651+
fn-%parse = $&parse
651652
fn-%batch-loop = $&batchloop
652653
fn-%is-interactive = $&isinteractive
653654

654-
fn %parse {
655-
if %is-interactive {
656-
let (in = (); p = $*(1))
657-
let (code = <={$&parse {
658-
let (r = <={$&readline $p}) {
659-
in = $in $r
660-
p = $*(2)
661-
result $r
662-
}
663-
}}) {
664-
if {!~ $#fn-%write-history 0} {
665-
%write-history <={%flatten \n $in}
666-
}
667-
result $code
668-
}
669-
} {
670-
$&parse $&read
671-
}
672-
}
673-
674655
fn %interactive-loop {
675656
let (result = <=true) {
676657
catch @ e type msg {

input.c

Lines changed: 71 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323

2424
Input *input;
25+
char *prompt, *prompt2;
26+
2527
Boolean ignoreeof = FALSE;
2628

2729

@@ -101,8 +103,11 @@ extern void unget(Input *in, int c) {
101103
/* get -- get a character, filter out nulls */
102104
static int get(Input *in) {
103105
int c;
106+
Boolean uf = (in->fill == ungetfill);
104107
while ((c = (in->buf < in->bufend ? *in->buf++ : (*in->fill)(in))) == '\0')
105108
warn("null character ignored");
109+
if (!uf && c != EOF)
110+
addhistbuffer((char)c);
106111
return c;
107112
}
108113

@@ -126,9 +131,58 @@ static int eoffill(Input UNUSED *in) {
126131
return EOF;
127132
}
128133

134+
#if HAVE_READLINE
135+
/* callreadline -- readline wrapper */
136+
static char *callreadline(char *prompt0) {
137+
char *volatile prompt = prompt0;
138+
char *r;
139+
if (prompt == NULL)
140+
prompt = ""; /* bug fix for readline 2.0 */
141+
rlsetup(FALSE);
142+
interrupted = FALSE;
143+
if (!setjmp(slowlabel)) {
144+
slow = TRUE;
145+
r = interrupted ? NULL : readline(prompt);
146+
if (interrupted)
147+
errno = EINTR;
148+
} else {
149+
r = NULL;
150+
errno = EINTR;
151+
}
152+
slow = FALSE;
153+
SIGCHK();
154+
return r;
155+
}
156+
#endif
157+
129158
/* fdfill -- fill input buffer by reading from a file descriptor */
130159
static int fdfill(Input *in) {
131160
long nread;
161+
assert(in->buf == in->bufend);
162+
assert(in->fd >= 0);
163+
164+
#if HAVE_READLINE
165+
if (in->runflags & run_interactive && in->fd == 0) {
166+
char *rlinebuf = NULL;
167+
do {
168+
rlinebuf = callreadline(prompt);
169+
} while (rlinebuf == NULL && errno == EINTR);
170+
171+
if (rlinebuf == NULL)
172+
nread = 0;
173+
else {
174+
nread = strlen(rlinebuf) + 1;
175+
if (in->buflen < (unsigned int)nread) {
176+
while (in->buflen < (unsigned int)nread)
177+
in->buflen *= 2;
178+
in->bufbegin = erealloc(in->bufbegin, in->buflen);
179+
}
180+
memcpy(in->bufbegin, rlinebuf, nread - 1);
181+
in->bufbegin[nread - 1] = '\n';
182+
efree(rlinebuf);
183+
}
184+
} else
185+
#endif
132186
do {
133187
nread = eread(in->fd, (char *) in->bufbegin, in->buflen);
134188
SIGCHK();
@@ -151,69 +205,13 @@ static int fdfill(Input *in) {
151205
return *in->buf++;
152206
}
153207

154-
static List *fillcmd = NULL;
155-
156-
static int cmdfill(Input *in) {
157-
char *read;
158-
List *result;
159-
size_t nread;
160-
int oldf;
161-
162-
assert(in->buf == in->bufend);
163-
assert(in->fd >= 0);
164-
165-
if (fillcmd == NULL)
166-
return fdfill(in);
167-
168-
oldf = dup(0);
169-
if (dup2(in->fd, 0) == -1)
170-
fail("$&parse", "dup2: %s", esstrerror(errno));
171-
172-
ExceptionHandler
173-
174-
result = eval(fillcmd, NULL, 0);
175-
176-
CatchException (e)
177-
178-
mvfd(oldf, 0);
179-
throw(e);
180-
181-
EndExceptionHandler
182-
183-
mvfd(oldf, 0);
184-
185-
if (result == NULL) { /* eof */
186-
if (!ignoreeof) {
187-
close(in->fd);
188-
in->fd = -1;
189-
in->fill = eoffill;
190-
in->runflags &= ~run_interactive;
191-
}
192-
return EOF;
193-
}
194-
read = str("%L\n", result, " ");
195-
196-
if ((nread = strlen(read)) > in->buflen) {
197-
in->bufbegin = erealloc(in->bufbegin, nread);
198-
in->buflen = nread;
199-
}
200-
memcpy(in->bufbegin, read, nread);
201-
202-
in->buf = in->bufbegin;
203-
in->bufend = &in->buf[nread];
204-
205-
return *in->buf++;
206-
}
207208

208209
/*
209210
* the input loop
210211
*/
211212

212-
213-
static Boolean parsing = FALSE;
214-
215-
/* parse -- call yyparse() and catch errors */
216-
extern Tree *parse(List *fc) {
213+
/* parse -- call yyparse(), but disable garbage collection and catch errors */
214+
extern Tree *parse(char *pr1, char *pr2) {
217215
int result;
218216
assert(error == NULL);
219217

@@ -223,27 +221,17 @@ extern Tree *parse(List *fc) {
223221
if (ISEOF(input))
224222
throw(mklist(mkstr("eof"), NULL));
225223

226-
if (parsing)
227-
fail("$&parse", "cannot perform nested parsing");
228-
229-
fillcmd = fc;
230-
parsing = TRUE;
231-
232-
ExceptionHandler
233-
234-
result = yyparse();
235-
236-
CatchException (e)
237-
238-
parsing = FALSE;
239-
fillcmd = NULL;
240-
pseal(NULL);
241-
throw(e);
242-
243-
EndExceptionHandler
224+
#if HAVE_READLINE
225+
prompt = (pr1 == NULL) ? "" : pr1;
226+
#else
227+
if (pr1 != NULL)
228+
eprint("%s", pr1);
229+
#endif
230+
prompt2 = pr2;
244231

245-
parsing = FALSE;
246-
fillcmd = NULL;
232+
gcdisable();
233+
result = yyparse();
234+
gcenable();
247235

248236
if (result || error != NULL) {
249237
char *e;
@@ -340,7 +328,7 @@ extern List *runfd(int fd, const char *name, int flags) {
340328

341329
memzero(&in, sizeof (Input));
342330
in.lineno = 1;
343-
in.fill = cmdfill;
331+
in.fill = fdfill;
344332
in.cleanup = fdcleanup;
345333
in.fd = fd;
346334
registerfd(&in.fd, TRUE);
@@ -403,7 +391,7 @@ extern Tree *parseinput(Input *in) {
403391
input = in;
404392

405393
ExceptionHandler
406-
result = parse(NULL);
394+
result = parse(NULL, NULL);
407395
if (get(in) != EOF)
408396
fail("$&parse", "more than one value in term");
409397
CatchException (e)
@@ -451,7 +439,7 @@ extern Boolean isinteractive(void) {
451439
}
452440

453441
extern Boolean isfromfd(void) {
454-
return input == NULL ? FALSE : (input->fill == fdfill || input->fill == cmdfill);
442+
return input == NULL ? FALSE : (input->fill == fdfill);
455443
}
456444

457445

@@ -464,6 +452,7 @@ extern void initinput(void) {
464452
input = NULL;
465453

466454
/* declare the global roots */
467-
globalroot(&fillcmd);
468455
globalroot(&error); /* parse errors */
456+
globalroot(&prompt); /* main prompt */
457+
globalroot(&prompt2); /* secondary prompt */
469458
}

input.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extern void yyerror(char *s);
3636
extern const char dnw[];
3737
extern int yylex(void);
3838
extern void inityy(void);
39-
extern void increment_line(void);
39+
extern void print_prompt2(void);
4040

4141

4242
/* parse.y */

0 commit comments

Comments
 (0)