/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */ /* From input file "biglet.p" */ #include /* biglet: text enlargement program by Matthew Yarus module libraries required: delman, prgmods */ /* used to halt program */ /* begin module version */ #define version 1.69 /* of biglet.p 2003 Mar 27 2003 Mar 27, 1.69: give actual example. 1999 aug 5, 1.68: see font file. 1997 Dec 12: made page size large 1986 dec 15: previous changes 1982: origin */ /* end module version */ /* begin module describe.biglet */ /* name biglet: text enlargement program synopsis biglet( fin: in, font: in, bigletp: in, fout: out, output: out ) files fin: contains user's text to be enlarged. font: the first line contains the actual height and width of characters in the font. The following lines contain character images. A character image has two parts, a reference character and the letter image. Characters in the image that match the reference character are printed, while a mismatch prints a space. bigletp: contains parameters to control enlargement. If the file is empty the fonts are not enlarged. otherwise, each line contains the height and width enlargement factors. The line may also contain a character inside quote marks (single or double) to substitute for the matched characters of the font images. Each line of bigletp corresponds to a fin text line. If there are no further lines, previously set values are used. fout: each line of fin is expanded by bigletp parameters and printed out in the form of the font images. output: messages to the user. description Each letter of text (in file fin) is expanded and printed as a larger letter which is composed of many smaller letters. The expansion can be set for each text line or for all lines with one parameter setting. There is an optional parameter which allows all the large letters of a specified line to be composed of a single character. The larger letters are based on a file called font which can contain any sort of images. examples For a font file whose first line is a left justified 5 4: f (sixth letter) (a space) - (a dash) fff- ---- xxxx Note: in the file each f--- ---- xxxx character image must be fff- ---- ---x left justified and be f--- ---- xxxx directly below the ---- ---- xxxx previous image. Also, each image has mismatches at its right and below used for spacing. for bigletp: example 1) 2 1 example 2) 3 2 'r' 1 2 'w' The first example magnifies the first and all subsequent text lines twice in height. The second example magnifies the first line at 3 by 2 and composes it out of 'r's. The next line will be twice as wide as the font and composed of 'w's. All subsequent fout text will be also be twice as wide but made up of the usual font characters. The phont file is a demonstration font file, while the font file is a working font. For this fin file: biglet is fun! we get this fout file: bbbbbbb iiiiiiii gggggg ll eeeeeeee tttttttt bb bb ii gg gg ll ee tt bb bb ii gg ll ee tt bbbbbbb ii gg ll eeeeeee tt bb bb ii gg ll ee tt bb bb ii gg gggg ll ee tt bb bb ii gg gg ll ee tt bb bb ii gg gg ll ee tt bbbbbbb iiiiiiii gggggg llllllll eeeeeeee tt iiiiiiii ssssss ii ss ss ii ss ii ssssss ii ss ii ss ii ss ii ss ss iiiiiiii ssssss ffffffff uu uu n nn !! ff uu uu nn nn !!!! ff uu uu nnn nn !!!! fffffff uu uu nnnn nn !!!! ff uu uu nn nn nn !! ff uu uu nn nnnn !! ff uu uu nn nnn ff uu uu nn nn !! ff uuuuuu nn nn !! see also {a set of fonts: } font {programs to remove blanks at the end of the line: } rembla.p rb.p {A script for automating the process is in the toolkit: } http://www.lecb.ncifcrf.gov/~toms/toolkit.html author Matthew A. Yarus bugs none known technical notes If your font images are larger than program allows change constants letmaxhi and letmaxwi in biglet source code. */ /* end module describe.biglet */ /* begin module biglet.constant */ /* more constants */ #define letmaxhi 40 /* height limit of letter image, originally 20 */ #define letmaxwi 40 /* width limit of letter image, originally 10 */ #define pagemaxhi 2000 /* printout limit of standard paper height, originally 60 */ #define pagemaxwi 2000 /* printout limit of standard paper width, originally 132 */ /* end module biglet.constant */ /* begin module biglet.type */ /* a pointer to fontrec */ typedef struct fontrec { /* each letter font is stored as a record */ Char letter; /* used as a reference point for letter images */ uchar image[letmaxhi][(letmaxwi + 7) / 8]; /* this array holds the letter image. 'true' represents a match with the reference character, 'false' a mismatch */ struct fontrec *next; /* letter images are linked into a list */ } fontrec; typedef fontrec *loadtype[pagemaxwi]; /* keeps fin text line characters in proper order */ /* end module biglet.type */ /* begin module biglet.var */ Static _TEXT fin; /* user's text to be enlarged */ Static _TEXT font; /* multiple letter images used for enlargement */ Static _TEXT bigletp; /* enlargement and optional letter parameters */ Static _TEXT fout; /* fin text after enlargement */ Static jmp_buf _JL1; /* end module biglet.var */ /* begin module halt */ Static Void halt() { /* stop the program. the procedure performs a goto to the end of the program. you must have a label: label 1; declared, and also the end of the program must have this label: 1: end. examples are in the module libraries. this is the only goto in the delila system. */ printf(" program halt.\n"); longjmp(_JL1, 1); } /* end module halt version = 'prgmod 3.96 85 mar 18 tds'; */ /* begin module biglet.fontload */ Static Void fontload(font, height, width, first) _TEXT *font; long *height, *width; fontrec **first; { /* see global variables */ /* innate height of letter image */ /* innate width */ /* starting point of fontrec list */ /* fontload converts font input file into linked list of font records */ long counthi; /* index of for loop 1 to height */ long countwi; /* index of for loop 1 to width */ Char letterhold; /* holds character for conversion into letter image boolean value */ fontrec *p; /* used to build linked list of fontrec */ long FORLIM, FORLIM1; if (*font->name != '\0') { if (font->f != NULL) font->f = freopen(font->name, "r", font->f); else font->f = fopen(font->name, "r"); } else rewind(font->f); if (font->f == NULL) _EscIO2(FileNotFound, font->name); RESETBUF(font->f, Char); if (BUFEOF(font->f)) { /* check for fonts */ printf(" font file is empty\n"); halt(); } /* check for fonts */ fscanf(font->f, "%ld%ld%*[^\n]", height, width); getc(font->f); /* innate parameters */ if (*height > letmaxhi) { printf(" font images are too tall for biglet use. you\n"); printf(" should change biglet source code constant letmaxhi.\n"); halt(); } if (*width > letmaxwi) { printf(" font images are too wide for biglet use. you\n"); printf(" should change biglet source code constant letmaxwi.\n"); halt(); } *first = (fontrec *)Malloc(sizeof(fontrec)); p = *first; while (!BUFEOF(font->f)) { fscanf(font->f, "%c%*[^\n]", &p->letter); getc(font->f); if (p->letter == '\n') p->letter = ' '; FORLIM = *height; for (counthi = 0; counthi < FORLIM; counthi++) { FORLIM1 = *width; for (countwi = 0; countwi < FORLIM1; countwi++) { if (P_eoln(font->f)) { printf(" either font of \"%c\" or previous\n", p->letter); printf(" font has a line that is too short, is missing\n"); printf(" a line, or is missing a matching letter above\n"); printf(" the letter image. it is also possible that\n"); printf(" height and width parameters at the top of the\n"); printf(" font file are improperly set.\n"); halt(); } letterhold = getc(font->f); if (letterhold == '\n') letterhold = ' '; if (letterhold == ' ') { printf(" font character image of \"%c\"\n", p->letter); printf(" contains a space which will cause\n"); printf(" transportation errors.\n"); halt(); } P_clrbits_B(p->image[counthi], countwi, 0, 3); P_putbits_UB(p->image[counthi], countwi, letterhold == p->letter, 0, 3); } /* puts file cursor onto next line of font except in final case where it goes to next font */ fscanf(font->f, "%*[^\n]"); getc(font->f); } if (BUFEOF(font->f)) p->next = NULL; /* marks end of list */ else { p->next = (fontrec *)Malloc(sizeof(fontrec)); p = p->next; } } } /* fontload */ /* end module biglet.fontload */ /* begin module biglet.double */ Static Void double_(first) fontrec *first; { /* marks start of fontrec list */ /* halts biglet if there is more than one font for a given character */ fontrec *pt = first; /* points to fonts other than one being checked for duplication */ fontrec *pt2 = first; /* pointer to font that other fonts are compared to */ boolean double_; /* 'true' when font is duplicated */ long index = 1; /* counter for while loop */ long index2; /* counter for two small loops */ /* both index variables are used to number the two positions of the duplicate font records within the list */ while (pt->next != NULL || pt2->next != NULL) { /* nil marks end of font list */ index2 = 1; pt = first; do { /* while loop above grabs font others are compared to, this loop grabs other fonts */ /* folowing while loop advances pt to one font past the one being checked because if any previous fonts were duplicated double would have already halted biglet */ while (index2 <= index) { index2++; pt = pt->next; } double_ = (pt->letter == pt2->letter); /* the duplication check */ if (double_) { printf(" font number %ld(%c)\n", index, pt2->letter); printf(" has a duplicate at font number %ld\n", index2); halt(); } index2++; if (pt->next != NULL) pt = pt->next; } while (pt->next != NULL); pt2 = pt2->next; /* fonts others are compared to is advanced */ index++; } } /* double */ /* end module biglet.double */ /* begin module biglet.paraload */ Static Void paraload(bigletp, parahi, parawi, linechar, lctest) _TEXT *bigletp; long *parahi, *parawi; Char *linechar; boolean *lctest; { /* see global variables */ /* user provided parameter of height expansion */ /* width expansion */ /* holds bigletp optional character, see describe module,'examples' */ /* 'true' indicates that optional character is to be used */ /* paraload assigns expansion values to each line of text or the same values to every line and decides if each line is to be written using font characters or written with one optional character */ Char quotehold; /* holds first quote mark for comparison to second mark */ boolean done = false; /* tests for completion of optional letter loop */ *lctest = false; if (BUFEOF(bigletp->f)) return; /* if eof is 'true' than default or previous parameters are used */ fscanf(bigletp->f, "%ld%ld", parahi, parawi); if (P_eoln(bigletp->f)) { /* no optional character used in current line */ fscanf(bigletp->f, "%*[^\n]"); getc(bigletp->f); return; } /* loop initialization value */ do { /* search for non-blank */ getc(bigletp->f); if (P_eoln(bigletp->f)) done = true; /* no linechar given by user */ else { if (P_peek(bigletp->f) == '"' || P_peek(bigletp->f) == '\'') { /* holds initial quote */ quotehold = getc(bigletp->f); /* pick up the first quote */ if (P_eoln(bigletp->f)) { printf(" bigletp optional letter missing\n"); halt(); } *linechar = getc(bigletp->f); *lctest = true; /* 'true' tells makebig procedure to use optional character linechar in fout result */ done = true; if (P_peek(bigletp->f) != quotehold) { /* compares terminal quote to initial */ printf(" bigletp letter %c poorly quoted\n", *linechar); halt(); } } else if (P_peek(bigletp->f) != ' ') { printf(" quote marks required around bigletp\n"); printf(" optional character\n"); halt(); } } } while (!done); fscanf(bigletp->f, "%*[^\n]"); getc(bigletp->f); /* obtain optional character linechar */ } /* paraload */ /* end module biglet.paraload */ /* begin module biglet.textcheck */ Static Void textcheck(bigletp, fin, height, width) _TEXT *bigletp, *fin; long height, width; { /* see global variables */ /* global variable */ /* innate height of font image */ /* innate width */ /* textcheck verifies the presence of a fin file. then it decides if fin is too tall or too wide for page. */ long countchar; /* counts number of characters in each text line */ Char charhold; /* holds each character so that it may advance countchar*/ long parahi = 1; /* user provided parameter of height expansion */ long parawi = 1; /* width parameter */ long totalhi = 0; /* running total on projected height of output */ if (*fin->name != '\0') { if (fin->f != NULL) fin->f = freopen(fin->name, "r", fin->f); else fin->f = fopen(fin->name, "r"); } else rewind(fin->f); if (fin->f == NULL) _EscIO2(FileNotFound, fin->name); RESETBUF(fin->f, Char); if (BUFEOF(fin->f)) { printf(" no fin, no fout\n"); halt(); /* default values */ } if (*bigletp->name != '\0') { if (bigletp->f != NULL) bigletp->f = freopen(bigletp->name, "r", bigletp->f); else bigletp->f = fopen(bigletp->name, "r"); } else { /* loop initialization value */ rewind(bigletp->f); } if (bigletp->f == NULL) _EscIO2(FileNotFound, bigletp->name); RESETBUF(bigletp->f, Char); do { if (!BUFEOF(bigletp->f)) { fscanf(bigletp->f, "%ld%ld%*[^\n]", ¶hi, ¶wi); getc(bigletp->f); } if (parahi <= 0 || parawi <= 0) { printf(" expansion parameters of 0 or less\n"); printf(" are not permitted\n"); halt(); } countchar = 0; /* loop initialization value */ do { countchar++; charhold = getc(fin->f); if (charhold == '\n') charhold = ' '; } while (!P_eoln(fin->f)); fscanf(fin->f, "%*[^\n]"); getc(fin->f); /* 'until eoln' above does not do carriage return */ totalhi += height * parahi; if (totalhi > pagemaxhi) { printf(" text is too tall for page. you may want to\n"); printf(" alter constant pagemaxhi(%ld lines)\n", (long)pagemaxhi); printf(" in biglet source code.\n"); halt(); } if (parawi * countchar * width > pagemaxwi) { printf(" text is too wide for page. you may want to\n"); printf(" alter constant pagemaxwi(%ld", (long)pagemaxwi); printf(" characters)\n"); printf(" in biglet source code.\n"); halt(); } } while (!BUFEOF(fin->f)); } /* textcheck */ /* end module biglet.textcheck */ /* begin module biglet.charptr */ Static Void charptr(charhold, first, pt) Char charhold; fontrec *first, **pt; { /* holds character for conversion into pointer location */ /* beginning of linked list */ /* points to font locations */ /* charptr converts a character into a pointer representing the position of the character in the linked list of fontrec letter images */ *pt = first; while ((*pt)->next != NULL && (*pt)->letter != charhold) *pt = (*pt)->next; /* if pt^.letter never equals charhold then next section halts biglet */ if ((*pt)->letter != charhold) { printf(" font not found for character '%c'\n", charhold); halt(); } } /* charptr */ /* end module biglet.charptr */ /* begin module biglet.lineload */ Static Void lineload(fin, textcount, loadl, first) _TEXT *fin; long *textcount; fontrec **loadl; fontrec *first; { /* see global variables */ /* holds number of characters in each line as it is read */ /* holds font locations of fin characters */ /* marks beginning of list */ /* lineload converts line of text into an array of integers so that makebig procedure can maintain the letter order of fin */ Char lethold; /* holds character for conversion into pointer by call of procedure charptr */ *textcount = 0; /* loop initialization value */ do { /* 'eoln fin' does not go to next fin line */ (*textcount)++; lethold = getc(fin->f); if (lethold == '\n') lethold = ' '; charptr(lethold, first, &loadl[*textcount - 1]); /* loadl is an array of pointers */ } while (!P_eoln(fin->f)); fscanf(fin->f, "%*[^\n]"); getc(fin->f); } /* lineload */ /* end module biglet.lineload */ /* begin module biglet.makebig */ Static Void makebig(fout, textcount, height, width, parahi, parawi, linechar, lctest, loadl, first) _TEXT *fout; long textcount, height, width, parahi, parawi; Char linechar; boolean lctest; fontrec **loadl; fontrec *first; { /* see global variables */ /* passed from lineload, number of characters in each line */ /* innate height of letter image */ /* innate width */ /* user provided(in bigletp) height expansion parameter */ /* width parameter */ /* holds bigletp optional character */ /* 'true' indicates that linechar option is to be used */ /* holds fin line in proper order */ /* points to beginning of fontrec list */ /* makebig enlarges fin and writes it in fout */ long countph; /* for loop index up to parahi */ long countpw; /* for loop index up to parawi */ long countext; /* for loop index up to textcount */ long counthi; /* for loop index up to height of letter image*/ long countwi; /* for loop index up to width of letter image*/ Char optionlet; /* holds either linechar or pt^.letter depending on which one is to be used */ Char ch; /* holds actual character to be printed in fout */ fontrec *pt; /* points to font image for given fin character */ for (counthi = 0; counthi < height; counthi++) { /* next two loops ensure that fout lines divided by fin lines = hidth*parahi */ for (countph = 1; countph <= parahi; countph++) { for (countext = 0; countext < textcount; countext++) { pt = loadl[countext]; if (lctest == false) optionlet = pt->letter; else optionlet = linechar; for (countwi = 0; countwi < width; countwi++) { /* this for loop and one below ensure that width of fout line is equal to width*parawi */ switch (P_getbits_UB(pt->image[counthi], countwi, 0, 3)) { case true: ch = optionlet; break; case false: ch = ' '; break; } for (countpw = 1; countpw <= parawi; countpw++) putc(ch, fout->f); } } putc('\n', fout->f); } } } /* makebig */ /* end module biglet.makebig */ /* begin module biglet.bletorder */ Static Void bletorder(fin, font, bigletp, fout) _TEXT *fin, *font, *bigletp, *fout; { /* see global variables */ /* global variable */ /* global variable */ /* global variable */ /* structures biglet by ordering other procedures and aids reading of code by placing variable declarations next to where they are used */ long height, width; /* innate font and font list dimensions */ long parahi = 1, parawi = 1; /* user provided height and width parameters */ long textcount; /* holds number of characters in each line */ loadtype loadl; /* holds pointer locations of fonts for fin characters */ Char linechar; /* holds optional parameter charracter */ boolean lctest; /* 'true' indicates that linechar is to be used */ fontrec *first; /* points to beginning of the fontrec list */ fontload(font, &height, &width, &first); double_(first); textcheck(bigletp, fin, height, width); /* default expansion parameters */ if (*fout->name != '\0') { if (fout->f != NULL) fout->f = freopen(fout->name, "w", fout->f); else fout->f = fopen(fout->name, "w"); } else { if (fout->f != NULL) rewind(fout->f); else fout->f = tmpfile(); } if (fout->f == NULL) _EscIO2(FileNotFound, fout->name); SETUPBUF(fout->f, Char); if (*fin->name != '\0') { if (fin->f != NULL) fin->f = freopen(fin->name, "r", fin->f); else fin->f = fopen(fin->name, "r"); } else rewind(fin->f); if (fin->f == NULL) _EscIO2(FileNotFound, fin->name); RESETBUF(fin->f, Char); if (*bigletp->name != '\0') { if (bigletp->f != NULL) bigletp->f = freopen(bigletp->name, "r", bigletp->f); else bigletp->f = fopen(bigletp->name, "r"); } else rewind(bigletp->f); if (bigletp->f == NULL) _EscIO2(FileNotFound, bigletp->name); RESETBUF(bigletp->f, Char); do { paraload(bigletp, ¶hi, ¶wi, &linechar, &lctest); lineload(fin, &textcount, loadl, first); makebig(fout, textcount, height, width, parahi, parawi, linechar, lctest, loadl, first); } while (!BUFEOF(fin->f)); } /* bletorder */ /* end module biglet.bletorder */ main(argc, argv) int argc; Char *argv[]; { PASCAL_MAIN(argc, argv); if (setjmp(_JL1)) goto _L1; fout.f = NULL; strcpy(fout.name, "fout"); bigletp.f = NULL; strcpy(bigletp.name, "bigletp"); font.f = NULL; strcpy(font.name, "font"); fin.f = NULL; strcpy(fin.name, "fin"); printf(" biglet %4.2f\n", version); bletorder(&fin, &font, &bigletp, &fout); printf(" text has been enlarged\n"); _L1: if (fin.f != NULL) fclose(fin.f); if (font.f != NULL) fclose(font.f); if (bigletp.f != NULL) fclose(bigletp.f); if (fout.f != NULL) fclose(fout.f); exit(EXIT_SUCCESS); } /* biglet */ /* End. */