#define HIRES
#include "mf.h"
#include "mf_vars.h"

/*
 * main() plus other necessary routines for mf
 *
 * Tim Morgan 12/19/85
 */
#include <stdio.h>
#include <string.h>

char *gfname;

void mf(void);

int main(argc, argv)
int argc;
char *argv[];
{
    if (argc != 2) {
        fprintf(stderr, "Usage: %s gffile\n", *argv);
        exit(1);
    }
    gfname = argv[1];

    mf();
    return(0);
}

/* Simulate eoln function */
boolean eoln(f)
FILE *f;
{
    int c;

    if (feof(f)) return(true);  /* Fulfill "weaker" requirement */
    c = getc(f);
    (void) ungetc(c, f);
    return(c == '\n');
}

/* Exit */
void cexit(h)
int h;
{
    putchar('\n');
    exit(h);
}

integer getbyte(void);
integer gettwobytes(void);
integer getthreebytes(void);
integer signedquad(void);

/* Hand-coded to avoid compiler deficiency */
integer firstpar(o)
eightbits o;
{
    if (o <= 63)
        return(o);
    if (o == 64 || o == 71 || o == 245 || o == 246 || o == 239)
        return(getbyte());
    if (o == 65 || o == 72 || o == 240)
        return(gettwobytes());
    if (o == 66 || o == 73 || o == 241)
        return(getthreebytes());
    if (o == 242 || o == 243)
        return(signedquad());
    if (o == 70 || o == 244 || o == 67 || o == 68 || o == 69 ||
        (o >= 248 && o <= 255)) return(0);
    return(o - 74);
}

void opengffile(void)
{
    gffile = fopen(gfname, "r");
    if (!gffile) {
        fprintf(stderr, "GF file does not exist!\n");
        exit(1);
    }
    curloc = 0;
}

void input_ln(void)
{
    if (gets((char *)buffer) == NULL) {
        fprintf(stderr, "Unexpected EOF!\n");
        exit(1);
    }
    (void) strcat((char *)buffer, " ");
}


FILE *output;

void initialize(void)
{
    integer i;

#if 0
    fprintf(stderr, "%s\n", "This is GFtype, C Version 2.2");
#endif
    for (i = 0; i <= 31; i++) 
        xchr[i] = '?';
    xchr[32] = ' ';
    xchr[33] = '!';
    xchr[34] = '"';
    xchr[35] = '#';
    xchr[36] = '$';
    xchr[37] = '%';
    xchr[38] = '&';
    xchr[39] = '\'';
    xchr[40] = '(';
    xchr[41] = ')';
    xchr[42] = '*';
    xchr[43] = '+';
    xchr[44] = ',';
    xchr[45] = '-';
    xchr[46] = '.';
    xchr[47] = '/';
    xchr[48] = '0';
    xchr[49] = '1';
    xchr[50] = '2';
    xchr[51] = '3';
    xchr[52] = '4';
    xchr[53] = '5';
    xchr[54] = '6';
    xchr[55] = '7';
    xchr[56] = '8';
    xchr[57] = '9';
    xchr[58] = ':';
    xchr[59] = ';';
    xchr[60] = '<';
    xchr[61] = '=';
    xchr[62] = '>';
    xchr[63] = '?';
    xchr[64] = '@';
    xchr[65] = 'A';
    xchr[66] = 'B';
    xchr[67] = 'C';
    xchr[68] = 'D';
    xchr[69] = 'E';
    xchr[70] = 'F';
    xchr[71] = 'G';
    xchr[72] = 'H';
    xchr[73] = 'I';
    xchr[74] = 'J';
    xchr[75] = 'K';
    xchr[76] = 'L';
    xchr[77] = 'M';
    xchr[78] = 'N';
    xchr[79] = 'O';
    xchr[80] = 'P';
    xchr[81] = 'Q';
    xchr[82] = 'R';
    xchr[83] = 'S';
    xchr[84] = 'T';
    xchr[85] = 'U';
    xchr[86] = 'V';
    xchr[87] = 'W';
    xchr[88] = 'X';
    xchr[89] = 'Y';
    xchr[90] = 'Z';
    xchr[91] = '[';
    xchr[92] = '\\';
    xchr[93] = ']';
    xchr[94] = '^';
    xchr[95] = '_';
    xchr[96] = '`';
    xchr[97] = 'a';
    xchr[98] = 'b';
    xchr[99] = 'c';
    xchr[100] = 'd';
    xchr[101] = 'e';
    xchr[102] = 'f';
    xchr[103] = 'g';
    xchr[104] = 'h';
    xchr[105] = 'i';
    xchr[106] = 'j';
    xchr[107] = 'k';
    xchr[108] = 'l';
    xchr[109] = 'm';
    xchr[110] = 'n';
    xchr[111] = 'o';
    xchr[112] = 'p';
    xchr[113] = 'q';
    xchr[114] = 'r';
    xchr[115] = 's';
    xchr[116] = 't';
    xchr[117] = 'u';
    xchr[118] = 'v';
    xchr[119] = 'w';
    xchr[120] = 'x';
    xchr[121] = 'y';
    xchr[122] = 'z';
    xchr[123] = '{';
    xchr[124] = '|';
    xchr[125] = '}';
    xchr[126] = '~';
    for (i = 127; i <= 255; i++) 
        xchr[i] = '?';
    for (i = 0; i <= 127; i++) 
        xord[chr(i)] = 32;
    for (i = 32; i <= 126; i++) 
        xord[xchr[i]] = i;
    wantsmnemonics = true;
    wantspixels = true;
    for (i = 0; i <= 255; i++) 
        charptr[i] = -1;
    totalchars = 0;
    minmoverall = maxint;
    maxmoverall = -maxint;
    minnoverall = maxint;
    maxnoverall = -maxint;
}
void jumpout(void)
{
    cexit(0);
}
integer getbyte(void)
{
    integer _result;
    eightbits b;
    if (eof(gffile))
        _result = 0;
    else {
        read(gffile, b);
        curloc = curloc + 1;
        _result = b;
    }
    return(_result);
}
integer gettwobytes(void)
{
    integer _result;
    eightbits a, b;
    read(gffile, a);
    read(gffile, b);
    curloc = curloc + 2;
    _result = (a * 256) + b;
    return(_result);
}
integer getthreebytes(void)
{
    integer _result;
    eightbits a, b, c;
    read(gffile, a);
    read(gffile, b);
    read(gffile, c);
    curloc = curloc + 3;
    _result = (((a * 256) + b) * 256) + c;
    return(_result);
}
integer signedquad(void)
{
    integer _result;
    eightbits a, b, c, d;
    read(gffile, a);
    read(gffile, b);
    read(gffile, c);
    read(gffile, d);
    curloc = curloc + 4;
    if (a < 128)
        _result = (((((a * 256) + b) * 256) + c) * 256) + d;
    else
        _result = ((((((a - 256) * 256) + b) * 256) + c) * 256) + d;
    return(_result);
}
ASCIIcode lowercasify(c)
ASCIIcode c;
{
    ASCIIcode _result;
    if ((c >= 65) && (c <= 90))
        _result = c + 32;
    else
        _result = c;
    return(_result);
}
void dialog(void)
{
L1:
    buffer[0] = 'n';
    if (buffer[0] != 63)
        wantsmnemonics = 
          (((buffer[0] == 121)
         || (buffer[0] == 49))
         || (buffer[0] == 116))
         || (buffer[0] == 32);
    else {
        printf("%s", "Type Y for complete listing,");
        printf("%s\n", " N for errors/images only.");
        goto L1;
    }
L2:
    buffer[0] = 'y';
    if (buffer[0] != 63)
        wantspixels = 
          (((buffer[0] == 121)
         || (buffer[0] == 49))
         || (buffer[0] == 116))
         || (buffer[0] == 32);
    else {
        printf("%s", "Type Y to list characters pictorially");
        printf("%s\n", " with *\'s, N to omit this option.");
        goto L2;
    }
    fprintf(stderr, "%s", "Options selected: Mnemonic output = ");
    if (wantsmnemonics)
        fprintf(stderr, "%s", "true");
    else
        fprintf(stderr, "%s", "false");
    fprintf(stderr, "%s", "; pixel output = ");
    if (wantspixels)
        fprintf(stderr, "%s", "true");
    else
        fprintf(stderr, "%s", "false");
    fprintf(stderr, "%c\n", '.');
}
void printscaled(s)
integer s;
{
    integer delta;
    if (s < 0) {
        fprintf(stderr, "%c", '-');
        s = -s;
    }
    fprintf(stderr, "%d", s / 65536);
    s = (10 * (s%65536)) + 5;
    if (s != 5) {
        delta = 10;
        fprintf(stderr, "%c", '.');
        do {
            if (delta > 65536)
                s = (s + 32768) - (delta/2);
            fprintf(stderr, "%c", chr(ord('0') + (s / 65536)));
            s = 10 * (s%65536);
            delta = delta * 10;
        } while (! (s <= delta));
    }
}
boolean dochar(void)
{
    boolean _result;
    eightbits o;
    integer p, q;
    boolean aok;
    aok = true;

    select_char(c,
                minmstated, maxmstated,
                minnstated, maxnstated); /* TeX character we are defining */
                                         /* and limits of pixels */
    while (true){
        a = curloc;
        o = getbyte();
        p = firstpar(o);
        if (eof(gffile)) {
            fprintf(stderr, "%c%s%s%c",
              ' ', "Bad GF file: ", "the file ended prematurely", '!');
            jumpout();
        }
        if (o <= 67) {
            if (wantsmnemonics)
                fprintf(stderr, "%s", " paint ");
            do {
                if (wantsmnemonics) {
                    if (paintswitch == 0)
                        fprintf(stderr, "%c%d%c", '(', p, ')');
                    else
                        fprintf(stderr, "%d", p);
                }
                m = m + p;
                if (m > maxmobserved)
                    maxmobserved = m - 1;
                if (wantspixels)
                    if (paintswitch == 1)
                        if (n <= maxsubrow) {
                            l = m - p;
                            r = m - 1;
                            if (r > maxsubcol)
                                r = maxsubcol;
                            m = l;
                            while (m <= r){
#ifdef NEVER
                                imagearray[m][n] = 1;
#endif
                                set_pixel(n, m);
                                m = m + 1;
                            }
                            m = l + p;
                        }
                paintswitch = 1 - paintswitch;
                a = curloc;
                o = getbyte();
                p = firstpar(o);
                if (eof(gffile)) {
                    fprintf(stderr, "%c%s%s%c",
                      ' ', "Bad GF file: ", "the file ended prematurely", '!');
                    jumpout();
                }
            } while (! (o > 67));
        }
        if (o >= 70 && o <= 73) {
                {
                    if (wantsmnemonics) {
                        fprintf(stderr, "\n");
                        fprintf(stderr, "%d%s%s%d%c%d",
                          a, ": ", "skip", (o - 70) % 4, ' ', p);
                    }
                    n = (n + p) + 1;
                    m = 0;
                    paintswitch = 0;
                    if (wantsmnemonics)
                        fprintf(stderr, "%s%d%c", " (n=", maxnstated - n, ')');
                }
        } else if (o >= 74 && o <= 238) {
                {
                    if (wantsmnemonics) {
                        fprintf(stderr, "\n");
                        fprintf(stderr, "%d%s%s%d", a, ": ", "newrow ", p);
                    }
                    n = n + 1;
                    m = p;
                    paintswitch = 1;
                    if (wantsmnemonics)
                        fprintf(stderr, "%s%d%c", " (n=", maxnstated - n, ')');
                }
        } else if (o == 244) {
                if (wantsmnemonics) {
                    fprintf(stderr, "\n");
                    fprintf(stderr, "%d%s%s", a, ": ", "no op");
                }
        } else if (o == 247) {
                {
                    {
                        fprintf(stderr, "%d%s%s%s",
                          a, ": ", "! ",
                          "preamble command within a character!");
                        fprintf(stderr, "\n");
                    }
                    goto L9998;
                }
        } else if (o == 248 || o == 249) {
                {
                    {
                        fprintf(stderr, "%d%s%s%s",
                          a, ": ", "! ",
                          "postamble command within a character!");
                        fprintf(stderr, "\n");
                    }
                    goto L9998;
                }
                break;
        } else if (o == 67 || o == 68) {
                {
                    {
                        fprintf(stderr, "%d%s%s%s",
                          a, ": ", "! ", "boc occurred before eoc!");
                        fprintf(stderr, "\n");
                    }
                    goto L9998;
                }
        } else if (o == 69) {
                {
                    if (wantsmnemonics) {
                        fprintf(stderr, "\n");
                        fprintf(stderr, "%d%s%s", a, ": ", "eoc");
                    }
#ifdef NEVER
                    fprintf(stderr, "\n");
#endif
                    goto L9999;
                }
        } else if (o >= 239 && o <= 242) {
                {
                    if (wantsmnemonics) {
                        fprintf(stderr, "\n");
                        fprintf(stderr, "%d%s%s", a, ": ", "xxx \'");
                    }
                    badchar = false;
                    b = 16;
                    if (p < 0) {
                        fprintf(stderr, "\n");
                        fprintf(stderr, "%d%s%s%s",
                          a, ": ", "! ", "string of negative length!");
                        fprintf(stderr, "\n");
                    }
                    while (p > 0){
                        q = getbyte();
                        if ((q < 32) || (q > 126))
                            badchar = true;
                        if (wantsmnemonics) {
                            fprintf(stderr, "%c", xchr[q]);
                            if (b < linelength)
                                b = b + 1;
                            else {
                                fprintf(stderr, "\n");
                                b = 2;
                            }
                        }
                        p = p - 1;
                    }
                    if (wantsmnemonics)
                        fprintf(stderr, "%c", '\'');
                    if (badchar) {
                        fprintf(stderr, "\n");
                        fprintf(stderr, "%d%s%s%s",
                          a, ": ", "! ",
                          "non-ASCII character in xxx command!");
                        fprintf(stderr, "\n");
                    }
                }
        } else if (o == 243) {
                {
                    if (wantsmnemonics) {
                        fprintf(stderr, "\n");
                        fprintf(stderr, "%d%s%s%d%s",
                          a, ": ", "yyy ", p, " (");
                    }
                    if (wantsmnemonics) {
                        printscaled(p);
                        fprintf(stderr, "%c", ')');
                    }
                }
                break;
        } else {
                {
                    fprintf(stderr, "%d%s%s%s%d%c",
                      a, ": ", "! ", "undefined command ", o, '!');
                    fprintf(stderr, "\n");
                }
        }
    }
L9998:
    fprintf(stderr, "%c\n", '!');
    aok = false;
L9999:
    _result = aok;
    dump_char();
    return(_result);
}
void readpostamble(void)
{
    integer k;
    integer p, q, m, u, v, w, c;
    postloc = curloc - 1;
    fprintf(stderr, "%s%d", "Postamble starts at byte ", postloc);
    if (postloc == gfprevptr)
        fprintf(stderr, "%c\n", '.');
    else
        fprintf(stderr, "%s%d%c\n",
          ", after special info at byte ", gfprevptr, '.');
    p = signedquad();
    if (p != gfprevptr) {
        fprintf(stderr, "%d%s%s%s%d%s%d%s%d%c",
          a, ": ", "! ",
          "backpointer in byte ", curloc - 4,
          " should be ", gfprevptr, " not ", p, '!');
        fprintf(stderr, "\n");
    }
    designsize = signedquad();
    checksum = signedquad();
    fprintf(stderr, "%s%d%s", "design size = ", designsize, " (");
    printscaled(designsize / 16);
    fprintf(stderr, "%s\n", "pt)");
    fprintf(stderr, "%s%d\n", "check sum = ", checksum);
    hppp = signedquad();
    vppp = signedquad();
    fprintf(stderr, "%s%d%s", "hppp = ", hppp, " (");
    printscaled(hppp);
    fprintf(stderr, "%c\n", ')');
    fprintf(stderr, "%s%d%s", "vppp = ", vppp, " (");
    printscaled(vppp);
    fprintf(stderr, "%c\n", ')');
    pixratio = (designsize / 1048576.0) * (hppp / 1048576.0);
    minmstated = signedquad();
    maxmstated = signedquad();
    minnstated = signedquad();
    maxnstated = signedquad();
    fprintf(stderr, "%s%d%s%d\n",
      "min m = ", minmstated, ", max m = ", maxmstated);
    if (minmstated > minmoverall) {
        fprintf(stderr, "%d%s%s%s%d%c",
          a, ": ", "! ", "min m should be <=", minmoverall, '!');
        fprintf(stderr, "\n");
    }
    if (maxmstated < maxmoverall) {
        fprintf(stderr, "%d%s%s%s%d%c",
          a, ": ", "! ", "max m should be >=", maxmoverall, '!');
        fprintf(stderr, "\n");
    }
    fprintf(stderr, "%s%d%s%d\n",
      "min n = ", minnstated, ", max n = ", maxnstated);
    if (minnstated > minnoverall) {
        fprintf(stderr, "%d%s%s%s%d%c",
          a, ": ", "! ", "min n should be <=", minnoverall, '!');
        fprintf(stderr, "\n");
    }
    if (maxnstated < maxnoverall) {
        fprintf(stderr, "%d%s%s%s%d%c",
          a, ": ", "! ", "max n should be >=", maxnoverall, '!');
        fprintf(stderr, "\n");
    }
    do {
        a = curloc;
        k = getbyte();
        if ((k == 245) || (k == 246)) {
            c = firstpar(k);
            if (k == 245) {
                u = signedquad();
                v = signedquad();
            }
            else {
                u = getbyte() * 65536;
                v = 0;
            }
            w = signedquad();
            p = signedquad();
            fprintf(stderr, "%s%d%s%d%s", "Character ", c, ": dx ", u, " (");
            printscaled(u);
            if (v != 0) {
                fprintf(stderr, "%s%d%s", "), dy ", v, " (");
                printscaled(v);
            }
            fprintf(stderr, "%s%d%s", "), width ", w, " (");
            w = round(w * pixratio);
            select_char2(c, w, 1);
            fprintf (stderr, "%d", w);
            fprintf(stderr, "%s%d\n", "), loc ", p);
            if (p != charptr[c]) {
                fprintf(stderr, "%d%s%s%s%d%c",
                  a, ": ", "! ",
                  "character location should be ", charptr[c], '!');
                fprintf(stderr, "\n");
            }
            k = 244;
        }
    } while (! (k != 244));
    if (k != 249) {
        fprintf(stderr, "%d%s%s%s", a, ": ", "! ", "should be postpost!");
        fprintf(stderr, "\n");
    }
    q = signedquad();
    if (q != postloc) {
        fprintf(stderr, "%d%s%s%s%d%s%d",
          a, ": ", "! ", "postamble pointer should be ", postloc, " not ", q);
        fprintf(stderr, "\n");
    }
    m = getbyte();
    if (m != 131) {
        fprintf(stderr, "%d%s%s%s%d%s%d",
          a, ": ", "! ", "identification byte should be ", 131, ", not ", m);
        fprintf(stderr, "\n");
    }
    k = curloc;
    m = 223;
    while ((m == 223) && (! eof(gffile)))
        m = getbyte();
    if (! eof(gffile)) {
        fprintf(stderr, "%c%s%s%d%s%c",
          ' ', "Bad GF file: ", "signature in byte ", curloc - 1,
          " should be 223", '!');
        jumpout();
    }
    else if (curloc < (k + 4)) {
        fprintf(stderr, "%d%s%s%s",
          a, ": ", "! ", "not enough signature bytes at end of file!");
        fprintf(stderr, "\n");
    }
}
void mf(void)
{
    initialize();
    make_sprites(gfname);
    begin_dump_sprites();
    dialog();
    opengffile();
    o = getbyte();
    if (o != 247) {
        fprintf(stderr, "%c%s%s%c",
          ' ', "Bad GF file: ", "First byte isn\'t start of preamble!", '!');
        jumpout();
    }
    o = getbyte();
    if (o != 131) {
        fprintf(stderr, "%c%s%s%d%s%d%c",
          ' ', "Bad GF file: ", "identification byte should be ", 131,
          " not ", o, '!');
        jumpout();
    }
    o = getbyte();
    fprintf(stderr, "%c", '\'');
    while (o > 0){
        o = o - 1;
        fprintf(stderr, "%c", xchr[getbyte()]);
    }
    fprintf(stderr, "%c\n", '\'');
    do {
        gfprevptr = curloc;
        do {
            a = curloc;
            o = getbyte();
            p = firstpar(o);
            if (eof(gffile)) {
                fprintf(stderr, "%c%s%s%c",
                  ' ', "Bad GF file: ", "the file ended prematurely", '!');
                jumpout();
            }
            if (o == 243) {
                {
                    if (wantsmnemonics) {
                        fprintf(stderr, "\n");
                        fprintf(stderr, "%d%s%s%d%s",
                          a, ": ", "yyy ", p, " (");
                    }
                    if (wantsmnemonics) {
                        printscaled(p);
                        fprintf(stderr, "%c", ')');
                    }
                }
                o = 244;
            }
            else if ((o >= 239) && (o <= 242)) {
                {
                    if (wantsmnemonics) {
                        fprintf(stderr, "\n");
                        fprintf(stderr, "%d%s%s", a, ": ", "xxx \'");
                    }
                    badchar = false;
                    b = 16;
                    if (p < 0) {
                        fprintf(stderr, "\n");
                        fprintf(stderr, "%d%s%s%s",
                          a, ": ", "! ", "string of negative length!");
                        fprintf(stderr, "\n");
                    }
                    while (p > 0){
                        q = getbyte();
                        if ((q < 32) || (q > 126))
                            badchar = true;
                        if (wantsmnemonics) {
                            fprintf(stderr, "%c", xchr[q]);
                            if (b < linelength)
                                b = b + 1;
                            else {
                                fprintf(stderr, "\n");
                                b = 2;
                            }
                        }
                        p = p - 1;
                    }
                    if (wantsmnemonics)
                        fprintf(stderr, "%c", '\'');
                    if (badchar) {
                        fprintf(stderr, "\n");
                        fprintf(stderr, "%d%s%s%s",
                          a, ": ", "! ",
                          "non-ASCII character in xxx command!");
                        fprintf(stderr, "\n");
                    }
                }
                o = 244;
            }
            else if (o == 244)
                if (wantsmnemonics) {
                    fprintf(stderr, "\n");
                    fprintf(stderr, "%d%s%s", a, ": ", "no op");
                }
        } while (! (o != 244));
        if (o != 248) {
            if (o != 67)
                if (o != 68) {
                    fprintf(stderr, "%c%s%s%d%s%d%c%c",
                      ' ', "Bad GF file: ", "byte ", curloc - 1,
                      " is not boc (", o, ')', '!');
                    jumpout();
                }
#if 0
            fprintf(stderr, "\n");
            fprintf(stderr, "%d%s", curloc - 1, ": beginning of char ");
#endif
            a = curloc - 1;
            totalchars = totalchars + 1;
            if (o == 67) {
                charactercode = signedquad();
                p = signedquad();
                c = charactercode%256;
                if (c < 0)
                    c = c + 256;
                minmstated = signedquad();
                maxmstated = signedquad();
                minnstated = signedquad();
                maxnstated = signedquad();
            }
            else {
                charactercode = getbyte();
                p = -1;
                c = charactercode;
                q = getbyte();
                maxmstated = getbyte();
                minmstated = maxmstated - q;
                q = getbyte();
                maxnstated = getbyte();
                minnstated = maxnstated - q;
            }
#if 0
            fprintf(stderr, "%d", c);
            if (charactercode != c)
                fprintf(stderr, "%s%d",
                  " with extension ", (charactercode - c) / 256);
            if (wantsmnemonics)
                fprintf(stderr, "%s%d%s%d%c%d%s%d\n",
                  ": ", minmstated, "<=m<=", maxmstated, ' ', minnstated,
                  "<=n<=", maxnstated);
#endif
            maxmobserved = -1;
            if (charptr[c] != p) {
                fprintf(stderr, "%d%s%s%s%d%s%d%c",
                  a, ": ", "! ", "previous character pointer should be ",
                  charptr[c], ", not ", p, '!');
                fprintf(stderr, "\n");
            }
            else if (p > 0)
                if (wantsmnemonics)
                    fprintf(stderr, "%s%d%c\n",
                     "(previous character with the same code started at byte ",
                     p, ')');
            charptr[c] = gfprevptr;
            if (wantsmnemonics)
                fprintf(stderr, "%s%d%c", "(initially n=", maxnstated, ')');
            if (wantspixels) {
                maxsubcol = (maxmstated - minmstated) - 1;
                if (maxsubcol > maxcol)
                    maxsubcol = maxcol;
                maxsubrow = maxnstated - minnstated;
                if (maxsubrow > maxrow)
                    maxsubrow = maxrow;
                n = 0;
                while (n <= maxsubrow){
                    m = 0;
                    while (m <= maxsubcol){
#ifdef NEVER
                        imagearray[m][n] = 0;
#endif
                        m = m + 1;
                    }
                    n = n + 1;
                }
            }
            m = 0;
            n = 0;
            paintswitch = 0;
            if (! dochar()) {
                fprintf(stderr, "%c%s%s%c",
                  ' ', "Bad GF file: ", "char ended unexpectedly", '!');
                jumpout();
            }
            maxnobserved = n;
            if (wantspixels) {
                if ((maxmobserved > maxcol) || (maxnobserved > maxrow))
                    fprintf(stderr, "%s\n",
                      "(The character is too large to be displayed in full.)");
                if (maxsubcol > maxmobserved)
                    maxsubcol = maxmobserved;
                if (maxsubrow > maxnobserved)
                    maxsubrow = maxnobserved;
                if (maxsubcol >= 0) {
#if 0
                    fprintf(stderr, "%s%d%c%d%s\n",
                      ".<--This pixel\'s lower left corner is at (",
                      minmstated, ',', maxnstated + 1,
                      ") in METAFONT coordinates");
#endif
#ifdef NEVER
                    n = 0;
                    while (n <= maxsubrow){
                        m = 0;
                        b = 0;
                        while (m <= maxsubcol){
                            if (imagearray[m][n] == 0)
                                b = b + 1;
                            else {
                                while (b > 0){
                                    fprintf(stderr, "%c", ' ');
                                    b = b - 1;
                                }
                                fprintf(stderr, "%c", '*');
                            }
                            m = m + 1;
                        }
                        fprintf(stderr, "\n");
                        n = n + 1;
                    }
#endif
#if 0
                    fprintf(stderr, "%s%d%c%d%s\n",
                      ".<--This pixel\'s upper left corner is at (",
                      minmstated, ',', maxnstated - maxsubrow,
                      ") in METAFONT coordinates");
#endif
                }
#if 0
                else
                    fprintf(stderr, "%s\n",
                      "(The character is entirely blank.)");
#endif
            }
            maxmobserved = (minmstated + maxmobserved) + 1;
            n = maxnstated - maxnobserved;
            if (minmstated < minmoverall)
                minmoverall = minmstated;
            if (maxmobserved > maxmoverall)
                maxmoverall = maxmobserved;
            if (n < minnoverall)
                minnoverall = n;
            if (maxnstated > maxnoverall)
                maxnoverall = maxnstated;
            if (maxmobserved > maxmstated)
                fprintf(stderr, "%s%d\n",
                  "The previous character should have had max m >= ",
                  maxmobserved);
            if (n < minnstated)
                fprintf(stderr, "%s%d\n",
                  "The previous character should have had min n <= ", n);
        }
    } while (! (o == 248));
    fprintf(stderr, "\n");
    readpostamble();
    fprintf(stderr, "%s%d%s", "The file had ", totalchars, " character");
    if (totalchars != 1)
        fprintf(stderr, "%c", 's');
    fprintf(stderr, "%s", " altogether.\n");
    end_dump_sprites();
}
