void page::cmdproc() { if (stage->next()) ERROR "more than a single command on bsqueue\n" FATAL; switch (stage->current()->cmdtype()) { case FC: // freeze the current 2-column range and start a new one adddef(stage->dequeue()); twocol->compose(FINAL); adddef(twocol); twocol = new multicol(this); break; case BP: // force a page break adddef(stage->dequeue()); squeue.block(); break; case FL: // flush out all floatables that precede this range: // no more stream input allowed until they're past if (stage->serialno() > ufqueue.serialno() || stage->serialno() > bfqueue.serialno()) { range *r = stage->dequeue(); r->enqueue(ANDBLOCK); } else adddef(stage->dequeue()); break; default: stage->current()->dump(); ERROR "unknown command\n" FATAL; } }
// There are four possibilities for consecutive calls to tryout(). // If we're processing a sequence of single-column ranges, tryout() // uses the original algorithm: (1) conservative test; (2) costly test; // (3) split a breakable item. // If we're processing a sequence of double-column ranges, tryout() // defers to twocol->tryout(), which gradually builds up the contents // of the two columns until they're as tall as they can be without // exceeding twocol->htavail. // If we're processing a sequence of single-column ranges and we // get a double-column range, then we use compose() to build a // skeleton page and set twocol->htavail, the maximum height that // should be occupied by twocol. // If we're processing a sequence of double-column ranges and we // get a single-column range, then we should go back and squish // the double-column chunk as short as possible before we see if // we can fit the single-column range. void page::tryout() { if (!stage->more()) ERROR "empty stage in page::tryout()\n" FATAL; int curnumcol = stage->current()->numcol(); if (dbg & 32) { printf("#page::tryout(): ncol = %d, prevncol = %d; on stage:\n", curnumcol, prevncol); stage->dump(); printf("#END of stage contents\n"); } switch(curnumcol) { default: ERROR "unexpected number of columns in tryout(): %d\n", stage->current()->numcol() FATAL; break; case 1: if (prevncol == 2) compose(FINAL); if (wouldfit(stage, &definite, pagesize - twocol->height())) commit(); else if ((stage->current()->breakable() || blank()) && peeloff(stage, pagesize - (definite.height() + twocol->height()))) { // first add the peeled-off part that fits adddef(stage->dequeue()); // then send the rest back for later stage->current()->setbreaking(); welsh(); } else if (blank()) { stage->current()->rdump(); ERROR "A %s is too big to continue.\n", stage->current()->type_name() FATAL; } else welsh(); break; case 2: if (prevncol == 1) compose(DRAFT); else twocol->tryout(); if (scratch.height() <= pagesize) commit(); else welsh(); break; } prevncol = curnumcol; }
PRIVATE void collectarg(struct Arg *arg) { struct Macro *macro = New(struct Macro); INT quoted = arg->quoted; pbskipspaces(); while( quoted-- ) pbchar(c_quote); getdef(¯o->def); macro->nargs = 0; adddef((INT)s_macro,arg->sym,(INT)macro); }
void page::parmproc() { if (stage->next()) ERROR "more than a single parameter on bsqueue\n" FATAL; switch (stage->current()->parmtype()) { case NP: // page top margin if (blank()) pagetop = stage->current()->parm(); pagesize = pagebot - pagetop; break; case FO: if (blank()) pagebot = stage->current()->parm(); pagesize = pagebot - pagetop; break; case PL: if (blank()) physbot = stage->current()->parm(); break; case MF: minfull = 0.01*stage->current()->parm(); break; case CT: coltol = 0.01*stage->current()->parm(); break; case WARN: wantwarn = stage->current()->parm(); break; case DBG: dbg = stage->current()->parm(); break; default: stage->current()->dump(); ERROR "unknown parameter\n" FATAL; } adddef(stage->dequeue()); }
int main( int argc, char **argv ) { inidef( ); if (argc == 1) { int n; printf("Usage: %s <fn> -d<sym> -u<sym> -p<path> -n<name> -w<wc>\n",argv[0]); printf(" <fn> file from which to extract embedded files\n"); printf(" <sym> symbol to (un)define\n"); printf(" <path> path where to put extracted files\n"); printf(" <name> only file names matching name will be extracted\n"); printf(" Wildcards are allowed. Default extract all files\n"); printf(" <wc> sets wildcard in <name>. Default is *\n"); printf("\n"); printf(" Defined are:"); for (n = 0; n < ndefs; n++) { if (n) { printf(", %s", defs[n].s ); } else { printf(" %s", defs[n].s ); } } printf("\n"); exit(EXIT_SUCCESS); } else { int na; for (na = 1; na < argc; na++) { if (argv[na][0] == '-') switch(argv[na][1]) { case 'd': case 'D': { adddef( &argv[na][2], 1 ); break; } case 'n': case 'N': { int a = 2, t = 0; while ((mask[t++] = argv[na][a++])); break; } case 'p': case 'P': { int a = 2, d = 0; while ((dir[d++] = argv[na][a++])); break; } case 'u': case 'U': { adddef( &argv[na][2], 0 ); break; } case 'w': case 'W': { wild = argv[na][2]; break; } default: fprintf(stderr,"Xfile -- unknown switch %s\n",argv[na]); exit(EXIT_FAILURE); } else if (infile) { fprintf(stderr,"Xfile -- can only Xtract from ONE file\n"); exit(EXIT_FAILURE); } else if (!(infile = fopen(argv[na],"r"))) { fprintf(stderr,"Xfile -- cannot open %s\n",argv[na]); exit(EXIT_FAILURE); } } } if (infile == NULL) { fprintf( stderr, "Xfile -- No input file given!\n" ); status = EXIT_FAILURE; } else { extract(NULL,0); } if (if_curl && status == EXIT_SUCCESS) { fprintf( stderr, "Xfile -- %d ENDIF(s) missing at line %d\n", if_curl, lineno ); status = EXIT_FAILURE; } if (infile != NULL) { fclose(infile); } exit(status); return(status); }