@@ -334,13 +334,14 @@ void showNL(u32 n) {
334
334
// Instead of running (cat prog.blc8 -) | ./uni
335
335
// or (cat prog.blc -) | ./uni -b
336
336
// 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
340
337
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
344
345
345
346
// Each prog$i is parsed from file $BLCPATH/prog$i.blc$suff
346
347
// where suffix $suff is a substring of "28" depending on the options.
@@ -350,6 +351,7 @@ void showNL(u32 n) {
350
351
// in https://www.ioccc.org/2012/tromp/hint.html can be replaced by
351
352
/* 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
352
353
HELP */
354
+ // since neither parse nor deflate has embedded input.
353
355
354
356
int main (int argc , char * * argv ) {
355
357
u32 db , dbgProg ;
@@ -375,16 +377,16 @@ int main(int argc, char **argv) {
375
377
u32 cl = 0 ;
376
378
char filepath [256 ];
377
379
const char * blcpath = getenv ("BLCPATH" );
378
- for (; optind < argc ; optind ++ ) {
380
+ for (int qComp = optind < argc - 1 ; optind < argc ; optind ++ ) {
379
381
sprintf (filepath , "%s/%s.blc%s%s" , blcpath , argv [optind ], qBLC2 ?"2" :"" , mode ?"8" :"" );
380
382
fprintf (stderr , "Opening file %s\n" , filepath );
381
383
fp = fopen (filepath , "r" );
382
384
if (!fp ) die ("file not found." );
383
385
u32 fcl = toCLK (db = qBLC2 ? parseBLC2 () : parseBLC ());
384
386
nbits = 0 ; // skip remaining bits in last lambda term byte
385
- if (optind < argc - 1 ) {
387
+ if (qComp ) {
386
388
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" );
388
390
}
389
391
cl = !cl ? fcl : app (app ('B' ,fcl ), cl );
390
392
}
0 commit comments