Skip to content

Commit 58d03b0

Browse files
committed
don't allow embedded input in composition
1 parent 377569b commit 58d03b0

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ blc: AIT.lhs Lambda.lhs Main.lhs
1515
uni: uni.c
1616
$(CC) -O3 -Wall uni.c -o uni
1717

18-
test: uni.pl uni.js uni.py
18+
test: uni.pl uni.js uni.py uni.rb uni
1919
echo ' hi' | ./uni.py
2020
echo ' hi' | ./uni.js
2121
echo ' hi' | ./uni.pl

uni.c

+11-9
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,14 @@ void showNL(u32 n) {
334334
// Instead of running (cat prog.blc8 -) | ./uni
335335
// or (cat prog.blc -) | ./uni -b
336336
// one can now run these as ./uni [-b] prog
337-
// It's also possible to run multiple programs in sequence:
338-
// uni [options] prog1 prog2 prog3 is equivalent to (cat prog123 -) | uni [options]
339-
// where prog123 is the function composition prog3 . prog2 . prog1
340337

341-
// The final program can have input embedded in its file after its lambda term,
342-
// which will be effectively preprended to stdin
343-
// Earlier programs must have no embedded input (uni will error if they do)
338+
// Any input that prog has embedded in its file after its lambda term
339+
// will be effectively preprended to stdin
340+
341+
// It's also possible to run multiple programs in sequence,
342+
// provided they have no embedded input (uni will error if they do):
343+
// uni [options] prog1 prog2 prog3 is equivalent to ./uni [options] prog123
344+
// where prog123 is the function composition prog3 . prog2 . prog1
344345

345346
// Each prog$i is parsed from file $BLCPATH/prog$i.blc$suff
346347
// where suffix $suff is a substring of "28" depending on the options.
@@ -350,6 +351,7 @@ void showNL(u32 n) {
350351
// in https://www.ioccc.org/2012/tromp/hint.html can be replaced by
351352
/* echo "\a a ((\b b b) (\b \c \d \e d (b b) (\f f c e))) (\b \c c)" | uni parse deflate > rev.blc8
352353
HELP */
354+
// since neither parse nor deflate has embedded input.
353355

354356
int main(int argc, char **argv) {
355357
u32 db, dbgProg;
@@ -375,16 +377,16 @@ int main(int argc, char **argv) {
375377
u32 cl = 0;
376378
char filepath[256];
377379
const char *blcpath = getenv("BLCPATH");
378-
for (; optind < argc; optind++) {
380+
for (int qComp = optind < argc-1; optind < argc; optind++) {
379381
sprintf(filepath, "%s/%s.blc%s%s", blcpath, argv[optind], qBLC2?"2":"", mode?"8":"");
380382
fprintf(stderr, "Opening file %s\n", filepath);
381383
fp = fopen(filepath, "r");
382384
if (!fp) die("file not found.");
383385
u32 fcl = toCLK(db = qBLC2 ? parseBLC2() : parseBLC());
384386
nbits = 0; // skip remaining bits in last lambda term byte
385-
if (optind < argc-1) {
387+
if (qComp) {
386388
getbit(); nbits=0; // check for embedded input following lambda term
387-
if (inbits != EOF) die("program input lost in composition");
389+
if (inbits != EOF) die("program input gets misplaced in composition");
388390
}
389391
cl = !cl ? fcl : app(app('B',fcl), cl);
390392
}

0 commit comments

Comments
 (0)