home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / glview.sit / glview.src / readfiles.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-30  |  31.3 KB  |  1,341 lines

  1. /*
  2.  * Mac hack of
  3.  * readfiles.c - routines to load images, fonts, and execution files.
  4.  *
  5.  * Copyright (c) 1991 by Patrick J. Naughton
  6.  */
  7.  
  8. #pragma segment Readfiles
  9.  
  10. #include "grasp.h"
  11.  
  12. ImageStruct *image[MAXIMAGES];
  13. int         numimages = 0;
  14. FontStruct *font[MAXFONTS];
  15. int         numfonts = 0;
  16. ExecStruct *exec[MAXEXECS];
  17. int         numexecs = 0;
  18.  
  19. extern ImageStruct *readgifimage();
  20.  
  21. void
  22. lowerstr(s)
  23.     char       *s;
  24. {
  25.     while (*s) {
  26.     if (*s >= 'A' && *s <= 'Z')
  27.         *s = *s + 'a' - 'A';
  28.     s++;
  29.     }
  30. }
  31.  
  32. void
  33. hexdump(fp, n)
  34.     FILE       *fp;
  35.     int         n;
  36. {
  37.     long        ofs = ftell(fp);
  38.     int         i, j;
  39.     u_char      b[16];
  40.  
  41.     for (j = 0; j < n; j++) {
  42.     for (i = 0; i < 16; i++) {
  43.         b[i] = GetByte(fp);
  44.         fprintf(stderr,"%02x ", b[i]);
  45.     }
  46.     fprintf(stderr," ");
  47.     for (i = 0; i < 16; i++)
  48.         fprintf(stderr,"%c ", isprint(b[i]) ? b[i] : '.');
  49.     fprintf(stderr,"\n");
  50.     }
  51.     fseek(fp, ofs, 0);
  52. }
  53.  
  54. /*-
  55.         Border                                 Color Table
  56.         Color    Color       Palette   1            2              3
  57.         -----    -----       ------- -----------------------------------
  58.           0      Black          0    Green        Red             Brown
  59.           1      Blue           1    Cyan         Magenta         White
  60.           2      Green          2    Cyan         Red             White
  61.           3      Cyan           3    Bright Green Bright Red      Yellow
  62.           4      Red            4    Bright Cyan  Bright Magenta  White
  63.           5      Magenta        5    Bright Cyan  Bright Red      White
  64.           6      Brown       -------------------------------------------
  65.           7      Grey
  66.           8      Dark Grey (Bright Black)
  67.           9      Bright Blue
  68.          10      Bright Green
  69.          11      Bright Cyan
  70.          12      Bright Red
  71.          13      Bright Magenta
  72.          14      Yellow (Bright Brown)
  73.          15      White (Bright Grey)
  74. */
  75.  
  76. u_short     egapal[16][3] = {
  77.     {0x0000, 0x0000, 0x0000}, {0x0000, 0x0000, 0xaaaa},
  78.     {0x0000, 0xaaaa, 0x0000}, {0x0000, 0xaaaa, 0xaaaa},
  79.     {0xaaaa, 0x0000, 0x0000}, {0xaaaa, 0x0000, 0xaaaa},
  80.     {0xaaaa, 0x5555, 0x0000}, {0xaaaa, 0xaaaa, 0xaaaa},
  81.     {0x5555, 0x5555, 0x5555}, {0x5555, 0x5555, 0xffff},
  82.     {0x5555, 0xffff, 0x5555}, {0x5555, 0xffff, 0xffff},
  83.     {0xffff, 0x5555, 0x5555}, {0xffff, 0x5555, 0xffff},
  84.     {0xffff, 0xffff, 0x5555}, {0xffff, 0xffff, 0xffff}
  85. };
  86.  
  87. int         cgapal[3][6] = {
  88.     {2, 3, 3, 10, 11, 11},
  89.     {4, 5, 4, 12, 13, 12},
  90.     {6, 15, 15, 14, 15, 15}
  91. };
  92.  
  93.  
  94. Colormap CreateEGAcmap()
  95. {
  96.     Colormap    cmap;
  97.     XColor      colors[16];
  98.     u_long      pixels[16];
  99.     u_long      pmasks;
  100.     int         i;
  101.  
  102.     cmap = XCreateColormap(dsp, win, vis, AllocNone);
  103.     XAllocColorCells(dsp, cmap, True, &pmasks, 0, pixels, 16);
  104.  
  105.      for (i = 0; i < 16; i++) {
  106.     colors[i].pixel = pixels[i];
  107.     colors[i].red = egapal[i][0];
  108.     colors[i].green = egapal[i][1];
  109.     colors[i].blue = egapal[i][2];
  110.     colors[i].flags = DoRed | DoGreen | DoBlue;
  111.     }
  112.     XStoreColors(dsp, cmap, colors, 16);
  113.     return cmap;
  114. }
  115.  
  116. int
  117. findext(s)
  118.     char       *s;
  119. {
  120.     int         i;
  121.     static char *exts[] = {
  122.     "pic", "pcx", "pal", "clp", "gif", "set", "fnt", "txt"
  123.     };
  124.     static int  extcodes[] = {
  125.     EXT_PIC, EXT_PCX, EXT_PAL, EXT_CLP, EXT_GIF, EXT_SET, EXT_FNT, EXT_TXT
  126.     };
  127.  
  128.     ++s;   /* get past the dot */
  129.     for (i = 0; i < (sizeof exts / sizeof exts[0]); i++)
  130.     if (!strcmp(s, exts[i]))
  131.         return extcodes[i];
  132.     return -1;
  133. }
  134.  
  135. void
  136. stringtofont(ex, i)
  137.     ExecStruct *ex;
  138. {
  139.     int         k;
  140.     char       *s = strtok(ex->Code[i].val.s, ".");
  141.     lowerstr(s);
  142.     for (k = 0; k < numfonts; k++) {
  143.     if (!strcmp(font[k]->name, s)) {
  144.         free(ex->Code[i].val.s);
  145.         ex->Code[i].token = FONTTYPE;
  146.         ex->Code[i].val.font = font[k];
  147.         break;
  148.     }
  149.     }
  150.     if (k == numfonts) {
  151.     fprintf(stderr,"font \"%s\" referenced but not in directory.\n", s);
  152.     ex->Code[i].token = FONTTYPE;
  153.     ex->Code[i].val.font = 0;
  154.     }
  155. }
  156.  
  157. void
  158. stringtoimage(ex, i, deftype)
  159.     ExecStruct *ex;
  160.     int         i;
  161.     int         deftype;
  162. {
  163.     int         k;
  164.     char       *s = strtok(ex->Code[i].val.s, ".");
  165.     char       *ext = strrchr(ex->Code[i].val.s, '.');
  166.     if (ext) {
  167.     int         extcode = findext(ext);
  168.     for (k = 0; k < numimages; k++) {
  169.         if (!strcmp(image[k]->name, s) && image[k]->type == extcode) {
  170.         free(ex->Code[i].val.s);
  171.         ex->Code[i].token = IMAGE;
  172.         ex->Code[i].val.image = image[k];
  173.         break;
  174.         }
  175.     }
  176.     } else {
  177.     for (k = 0; k < numimages; k++) {
  178.         if (!strcmp(image[k]->name, s)) {
  179.         /*
  180.          * this might be the second time through here, so don't free
  181.          * the string more than once...
  182.          */
  183.         if (ex->Code[i].token == STRING) {
  184.             free(ex->Code[i].val.s);
  185.             ex->Code[i].token = IMAGE;
  186.         }
  187.         ex->Code[i].val.image = image[k];
  188.         if (image[k]->type == deftype)
  189.             break;
  190.         }
  191.     }
  192.     }
  193.     if (ex->Code[i].token != IMAGE)
  194.     error("%s: image \"%s\" referenced but not in directory.\n", s);
  195. }
  196.  
  197. void
  198. stringtolabel(ex, i)
  199.     ExecStruct *ex;
  200.     int         i;
  201. {
  202.     int         k;
  203.     char       *s = strtok(ex->Code[i].val.s, ".");
  204.     lowerstr(s);
  205.     for (k = 0; k < ex->numlabels; k++) {
  206.     if (!strcmp(s, ex->label[k].string)) {
  207.         free(ex->Code[i].val.s);
  208.         ex->Code[i].token = INTEGER;
  209.         ex->Code[i].val.i = ex->label[k].ipaddr;
  210.         break;
  211.     }
  212.     if (k == ex->numlabels)
  213.         error("%s: label \"%s\" referenced but not found.\n", s);
  214.     }
  215. }
  216.  
  217. void
  218. stringtoexec(ex, i)
  219.     ExecStruct *ex;
  220.     int         i;
  221. {
  222.     int         k;
  223.     char       *s = strtok(ex->Code[i].val.s, ".");
  224.     lowerstr(s);
  225.     for (k = 0; k < numexecs; k++) {
  226.     if (!strcmp(exec[k]->name, s)) {
  227.         free(ex->Code[i].val.s);
  228.         ex->Code[i].token = EXECTYPE;
  229.         ex->Code[i].val.exec = exec[k];
  230.         break;
  231.     }
  232.     }
  233.     if (k == numexecs)
  234.     error("%s: exec \"%s\" referenced but not in directory.\n", s);
  235. }
  236.  
  237.  
  238. int
  239. calcwidth(data, width, height, left)
  240.     u_char     *data;
  241.     int         width;
  242.     int         height;
  243.     int        *left;
  244. {
  245.     int         bpsl = (width + 7) >> 3;
  246.     int         right;
  247.     int         mask;
  248.     int         i;
  249.     int         j;
  250.  
  251. /*find left */
  252.     *left = 0;
  253.     for (i = 0; i < bpsl; i++) {
  254.     for (mask = 0x80; mask > 0; mask >>= 1) {
  255.         for (j = 0; j < height; j++) {
  256.         if (data[j * bpsl + i] & mask)
  257.             goto calcright;
  258.         }
  259.         (*left)++;
  260.     }
  261.     }
  262.     *left = 0;
  263.     return width / 2;    /* must be the space char... */
  264.  
  265. calcright:/* find right */
  266.  
  267.     right = bpsl * 8;
  268.     for (i = bpsl - 1; i >= 0; i--) {
  269.     for (mask = 0x01; mask < 0x100; mask <<= 1) {
  270.         for (j = 0; j < height; j++) {
  271.         if (data[j * bpsl + i] & mask)
  272.             return right - *left;
  273.         }
  274.         right--;
  275.     }
  276.     }
  277.     error("%s: bad width calc.");
  278. }
  279.  
  280.  
  281. FontStruct *
  282. readfont(fp, dirent)
  283.     FILE       *fp;
  284.     FilenameStruct *dirent;
  285. {
  286.     FontStruct *font;
  287.     XImage      xim;
  288.     int         first;
  289.     int         num;
  290.     int         datasize;
  291.     int         i;
  292.     char       *data;
  293.  
  294.     fseek(fp, dirent->offset, 0);
  295.     font = (FontStruct *) malloc(sizeof(FontStruct));
  296.     font->name = strtok(strdup(dirent->fname), ".");
  297.     (void) GetLong(fp);    /* skip file length */
  298.     (void) GetWord(fp);    /* skip length */
  299.     if (imverbose)
  300.     hexdump(fp, 4);
  301.     num = GetByte(fp);
  302. /* hack for trashed fonts... */
  303.     if (num == -1) {
  304.     free(font->name);
  305.     free(font);
  306.     return (FontStruct *) 0;
  307.     }
  308.     first = GetByte(fp);
  309.     font->width = GetByte(fp);
  310.     font->height = GetByte(fp);
  311.     datasize = GetByte(fp);
  312.     data = (char *) malloc(datasize);
  313.     if (!data)
  314.     error("%s: couldn't malloc glyph memory\n");
  315.     if (verbose)
  316.     fprintf(stderr, "%s: (FNT) %d %dx%d,%d(%d) glyphs, from %d to %d\n",
  317.         font->name, num, font->width, font->height,
  318.         datasize, font->height * ((font->width + 7) >> 3),
  319.         first, first + num - 1);
  320.  
  321.  
  322.     xim.height = font->height;
  323.     xim.width = font->width;
  324.     xim.depth = 1;
  325.     xim.xoffset = 0;
  326.     xim.format = XYBitmap;
  327.     xim.data = data;
  328.     xim.byte_order = MSBFirst;
  329.     xim.bitmap_unit = 8;
  330.     xim.bitmap_bit_order = MSBFirst;
  331.     xim.bitmap_pad = 8;
  332.     xim.bytes_per_line = (font->width + 7) / 8;
  333.  
  334.     for (i = 0; i < 256; i++) {
  335.     if (i >= first && i < first + num) {
  336.         fread(data, datasize, 1, fp);
  337.         font->glyphs[i].width = calcwidth(data, font->width, font->height,
  338.                           &font->glyphs[i].lbearing);
  339.         font->glyphs[i].pix = XCreatePixmap(dsp, win,
  340.                         font->width, font->height, 1);
  341.         XPutImage(dsp, font->glyphs[i].pix, gc1, &xim, 0, 0, 0, 0,
  342.               font->width, font->height);
  343.     } else {
  344.         font->glyphs[i].pix = (Pixmap) 0;
  345.         font->glyphs[i].width = 0;
  346.         font->glyphs[i].lbearing = 0;
  347.     }
  348.     }
  349.  
  350.  
  351.     free(data);
  352.  
  353.     return font;
  354. }
  355.  
  356.  
  357. FontStruct *
  358. readset(fp, dirent)
  359.     FILE       *fp;
  360.     FilenameStruct *dirent;
  361. {
  362.     FontStruct *font;
  363.     XImage      xim;
  364.     int         first;
  365.     int         num;
  366.     int         datasize;
  367.     int         i;
  368.     char       *data;
  369.     char        fontname[14];
  370.     int         type;
  371.     int         checktype;
  372.     int         fontascent;
  373.     int         proportional;
  374.     int         bpsl;
  375.     int         lfgap;
  376.     int         italics;
  377.     int         fntinvert;
  378.     int         fnthbold;
  379.     int         fntvbold;
  380.     int         fnthmag;
  381.     int         fntvmag;
  382.     int         fnthfract;
  383.     int         fntvfract;
  384.     int         fntdirection;
  385.     int         fntrot90;
  386.     int         fnthflip;
  387.     int         fntvflip;
  388.     int         fntcolor;
  389.     int         fntsubtype;
  390.     char        unused[18];
  391.     int         dataofs;
  392.  
  393.     int         celloffs[256];
  394.     int         cellwidth[256];
  395.  
  396.     fseek(fp, dirent->offset, 0);
  397.  
  398.     (void) GetLong(fp);    /* skip file length */
  399.  
  400.     if (imverbose)
  401.     hexdump(fp, 4);
  402.  
  403.     /* non-compressed type = 0x10 or compressed type = 0x14 */
  404.     type = GetByte(fp);
  405.     if (type != 0x10 && type != 0x14)
  406.     return readfont(fp, dirent);
  407.  
  408.     fread(fontname, 13, 1, fp);
  409.     fontname[13] = 0;
  410.     /* non-compressed font = 0xba, compressed font = 0xdc */
  411.     checktype = GetByte(fp);
  412.  
  413.     font = (FontStruct *) malloc(sizeof(FontStruct));
  414.     font->name = strtok(strdup(dirent->fname), ".");
  415.  
  416.     fontascent = GetByte(fp);
  417.     num = GetByte(fp);
  418.     /* limited to the lower 94 ASCII characters: 0x21 - 0x7E */
  419.     first = GetByte(fp) + 0x20;
  420.     proportional = GetByte(fp);    /* 0 = non-proportional */
  421.     font->width = GetByte(fp);
  422.     font->height = GetByte(fp);
  423.     bpsl = GetByte(fp);
  424.     datasize = font->height * bpsl;
  425.     spacegap = GetByte(fp);
  426.     chargap = GetByte(fp);
  427.     lfgap = GetByte(fp);
  428.     (void) GetWord(fp);    /* skip file length */
  429.     italics = GetByte(fp);
  430.  
  431.     fntinvert = GetByte(fp);    /* 0 = dont invert, 1 = invert */
  432.     fnthbold = GetByte(fp);    /* number of overlapping bits horizontal */
  433.     fntvbold = GetByte(fp);    /* number of overlapping bits vertical */
  434.     fnthmag = GetByte(fp);    /* integral horizontal bit magnification */
  435.     fntvmag = GetByte(fp);    /* integral vertical bit magnification */
  436.     fnthfract = GetByte(fp);    /* fractional horizontal bit magnification */
  437.     fntvfract = GetByte(fp);    /* fractional vertical bit magnification */
  438.     fntdirection = GetByte(fp);    /* Print direction 0 = left to right, 1...3 =
  439.                  * counterclock 1...3 */
  440.     fntrot90 = GetByte(fp);    /* rotation 0 = up, 1...3 = counterclock 1...3 */
  441.     fnthflip = GetByte(fp);    /* horizontal flip 0 = no, 1 = yes */
  442.     fntvflip = GetByte(fp);    /* vertical flip 0 = no, 1 = yes */
  443.     fntcolor = GetByte(fp);    /* color of font */
  444.     fntsubtype = GetByte(fp);    /* subcategory type of this font */
  445.     fread(unused, 18, 1, fp);
  446.  
  447.     if (verbose)
  448.     fprintf(stderr, "%s[%s]: (SET) %d %dx%d,%d %sglyphs, from %d to %d\n",
  449.         font->name, fontname, num, font->width, font->height, datasize,
  450.         proportional ? "var-" : "fixed-", first, first + num - 1);
  451.  
  452.     if (type == 0x10) {
  453.     for (i = 0; i <= num; i++)
  454.         celloffs[i] = GetWord(fp);
  455.     if (proportional) {
  456.         for (i = 0; i <= num; i++)
  457.         cellwidth[i] = GetByte(fp);
  458.     }
  459.     dataofs = ftell(fp) - dirent->offset + 4;
  460.     data = (char *) malloc(datasize * num);
  461.     if (!data)
  462.         error("%s: couldn't malloc glyph memory\n");
  463.     fread(data, num, datasize, fp);
  464.  
  465.     xim.width = font->width;
  466.     xim.height = font->height;
  467.     xim.depth = 1;
  468.     xim.xoffset = 0;
  469.     xim.format = XYBitmap;
  470.     xim.data = 0;
  471.     xim.byte_order = MSBFirst;
  472.     xim.bitmap_unit = 8;
  473.     xim.bitmap_bit_order = MSBFirst;
  474.     xim.bitmap_pad = 8;
  475.     xim.bytes_per_line = bpsl;
  476.  
  477.     for (i = 0; i < 256; i++) {
  478.         font->glyphs[i].pix = (Pixmap) 0;
  479.         font->glyphs[i].width = 0;
  480.         font->glyphs[i].lbearing = 0;
  481.     }
  482.  
  483.     for (i = 0; i <= num; i++) {
  484.         int         j = first + i - 1;
  485.  
  486.         font->glyphs[j].lbearing = 0;
  487.         font->glyphs[j].width = proportional ? cellwidth[i] : font->width;
  488.         font->glyphs[j].pix = XCreatePixmap(dsp, win,
  489.                       font->glyphs[j].width, font->height, 1);
  490.         xim.data = &data[celloffs[i] - dataofs];
  491.         XPutImage(dsp, font->glyphs[j].pix, gc1, &xim, 0, 0, 0, 0,
  492.               font->glyphs[j].width, font->height);
  493.     }
  494.  
  495.     free(data);
  496.  
  497.     } else {
  498.     fprintf(stderr,"dont do compressed SET's yet.\n");
  499.     }
  500.     return font;
  501. }
  502.  
  503.  
  504. ImageStruct *
  505. readimage(fp, dirent, filetype)
  506.     FILE       *fp;
  507.     FilenameStruct *dirent;
  508.     int         filetype;
  509. {
  510.     ImageStruct *im;
  511.     XImage     *xim;
  512.     int         i;
  513.     int         j;
  514.     int         format;
  515.     int         bpsl;
  516.     int         blocks;
  517.     int         datasize;
  518.     long        blockoffset;
  519.     u_char     *ptr;
  520.     int         bpp;
  521.     int         planes;
  522.     int         idx;
  523.     int         magic;
  524.     int         unknown;
  525.     int         type;
  526.     int         edesc;
  527.     int         exsize;
  528.     short         maxcolorval;
  529.     u_long      pixels[256];
  530.     u_long      pmasks;
  531.     int         filelen;
  532.  
  533.     im = (ImageStruct *) malloc(sizeof(ImageStruct));
  534.  
  535.     fseek(fp, dirent->offset, 0);
  536.  
  537.     filelen = GetLong(fp);    /* length of whole image file... */
  538.  
  539.     if (imverbose)
  540.     hexdump(fp, 4);
  541.  
  542.     im->name = strtok(strdup(dirent->fname), ".");
  543.     im->type = filetype;
  544.  
  545.     magic = GetWord(fp);
  546.     if (magic != 0x1234) {    /* I'm guessing here */
  547.     im->w = GetWord(fp);
  548.     im->h = GetWord(fp);
  549.     fprintf(stderr,"\nstrange magic, maybe bad data\n");
  550.     fprintf(stderr,"%dx%d %d, %d, %d, %d\n", im->w, im->h, im->w * im->h / 4,
  551.            magic - 6, ((im->w + 3) >> 2) * im->h, filelen - 6);
  552.  
  553.     return NULL;
  554.  
  555. /* found in magic.gl
  556. "15934x16190 64492865, 15928, 64500960, 1044266552"
  557. im->w  im->h  w*h/4   magic-6  (w+3)>>2)*h  filelen-6
  558.  
  559. magic == im.w
  560.  
  561. */
  562.     im->xoff = 0;
  563.     im->yoff = 0;
  564.     bpp = 2;
  565.     planes = 1;
  566.     type = 'a';
  567.     edesc = 1;
  568.     exsize = 0;
  569.     } else {
  570.     im->w = GetWord(fp);
  571.     im->h = GetWord(fp);
  572.     im->xoff = GetWord(fp);
  573.     im->yoff = GetWord(fp);
  574.     bpp = GetByte(fp);
  575.     planes = ((bpp & 0xf0) >> 4) + 1;
  576.     bpp &= 0x0f;
  577.     if (GetByte(fp) != 0xff)
  578.         error("%s: %s is corrupt\n", im->name);
  579.     type = GetByte(fp);
  580.     edesc = GetWord(fp);
  581.     exsize = GetWord(fp);
  582.     }
  583.  
  584.     if (bpp == 1 && planes == 1) {
  585.     im->d = 1;
  586.     format = XYBitmap;
  587.     bpsl = (im->w + 7) >> 3;
  588.     XSetForeground(dsp, gc, white);
  589.     XSetBackground(dsp, gc, black);
  590.     } else {
  591.     im->d = 8;
  592.     format = ZPixmap;
  593.     bpsl = im->w;
  594.     }
  595.     datasize = bpsl * im->h;
  596.     ptr = (u_char *) malloc(datasize);
  597.     if (!ptr)
  598.     error("%s: readimage: malloc failed on image data.\n");
  599.  
  600.     if (verbose)
  601.     fprintf(stderr,
  602.      "%s: (PIC) %dx%dx%d(%1x:%1x) [%d,%d] sz=%d t=%c edesc=%02x ext=%d\n",
  603.            im->name,
  604.            im->w,
  605.            im->h,
  606.            im->d,
  607.            bpp, planes,
  608.            im->xoff,
  609.            im->yoff,
  610.            datasize,
  611.            type,
  612.            edesc,
  613.            exsize);
  614.  
  615.     if (edesc != 0)
  616.       im->cmap = XCreateColormap(dsp, win, vis, AllocNone);
  617.  
  618.     switch (edesc) {
  619.     case 0:
  620.     im->cmaplen = 0;
  621.     im->cmap = (Colormap) 0;
  622.     break;
  623.     case 1:
  624.     im->cmaplen = 4;
  625.     break;
  626.     case 2:
  627.     im->cmaplen = 16;
  628.     maxcolorval = 15;
  629.     break;
  630.     case 3:
  631.     im->cmaplen = 16;
  632.     maxcolorval = 63;
  633.     break;
  634.     case 4:
  635.     im->cmaplen = 256;
  636.     maxcolorval = 63;
  637.     break;
  638.     case 5:
  639.     im->cmaplen = 16;
  640.     maxcolorval = 63;
  641.     break;
  642.     default:
  643.     error("%s: bad edesc: %d\n", edesc);
  644.     }
  645.  
  646.    if (im->cmaplen > 0)
  647.      XAllocColorCells(dsp, im->cmap, True, &pmasks, 0, pixels, im->cmaplen);
  648.  
  649.     switch (edesc) {
  650.     case 0:
  651.     break;
  652.     case 1:
  653.     {
  654.         char        pal;
  655.  
  656.         if (exsize != 2)
  657.         error("%s: unexpected esize: %d\n", exsize);
  658.         pal = GetByte(fp);
  659.         j = GetByte(fp);
  660.         i = 0;
  661.  
  662.         im->colors[i].pixel = pixels[i];
  663.         im->colors[i].red = egapal[j][0];
  664.         im->colors[i].green = egapal[j][1];
  665.         im->colors[i].blue = egapal[j][2];
  666.         im->colors[i].flags = DoRed | DoGreen | DoBlue;
  667.         for (i = 1; i < im->cmaplen; i++) {
  668.         j = cgapal[i - 1][pal];
  669.         im->colors[i].pixel = pixels[i];
  670.         im->colors[i].red = egapal[j][0];
  671.         im->colors[i].green = egapal[j][1];
  672.         im->colors[i].blue = egapal[j][2];
  673.         im->colors[i].flags = DoRed | DoGreen | DoBlue;
  674.         }
  675.  
  676.     }
  677.     break;
  678.     case 2:
  679.     case 3:
  680.     if (exsize != im->cmaplen)
  681.         error("%s: bad exsize: %d\n", exsize);
  682.     for (i = 0; i < im->cmaplen; i++) {
  683.         int         pal = GetByte(fp);
  684.         im->colors[i].pixel = pixels[i];
  685.         im->colors[i].red = decodepal(pal, 0x20, 0x04) << 8;
  686.         im->colors[i].green = decodepal(pal, 0x10, 0x02) << 8;
  687.         im->colors[i].blue = decodepal(pal, 0x08, 0x01) << 8;
  688.         im->colors[i].flags = DoRed | DoGreen | DoBlue;
  689.     }
  690.     break;
  691.     case 4:
  692.     case 5:
  693. #define fixcolr( c)   ((c*255/maxcolorval) << 8)
  694.  
  695.     if (exsize != 0 && exsize != im->cmaplen * 3)
  696.         fprintf(stderr,"bad exsize: %d\n", exsize);
  697.     for (i = 0; i < im->cmaplen; i++) {
  698.         unsigned short r,g,b;
  699.         im->colors[i].pixel = pixels[i];
  700.         im->colors[i].red = fixcolr(r=GetByte(fp));
  701.         im->colors[i].green = fixcolr(g=GetByte(fp));
  702.         im->colors[i].blue = fixcolr(b=GetByte(fp));
  703.     }
  704.     break;
  705.     }
  706.  
  707.     if (edesc > 0) {
  708.     if (verbose) {
  709.         fprintf(stderr,"%d colors\n", im->cmaplen);
  710.         /*----
  711.         for (i = 0; i < im->cmaplen; i++) {
  712.         fprintf(stderr,"%02x%02x%02x ",
  713.                im->colors[i].red >> 8,
  714.                im->colors[i].green >> 8,
  715.                im->colors[i].blue >> 8);
  716.         if (!((i + 1) % 8))
  717.             fprintf(stderr,"\n");
  718.         }
  719.         -----*/
  720.     }
  721.     XStoreColors(dsp, im->cmap, im->colors, im->cmaplen);
  722.     }
  723.     if (magic != 0x1234) {    /* BSAVE */
  724.     fread(ptr, filelen - 6, 1, fp);
  725.     } else {
  726.     blocks = GetWord(fp);
  727.     if (blocks == 0) {
  728.         if (imverbose)
  729.         fprintf(stderr,"unpacked data\n");
  730.         fread(ptr, datasize, 1, fp);
  731.     } else {
  732.  
  733.         if (imverbose) {
  734.         fprintf(stderr,"%d image blocks\n", blocks);
  735.         hexdump(fp, 4);
  736.         }
  737.         blockoffset = ftell(fp);
  738.         idx = 0;
  739.         for (i = 0; i < blocks; i++) {
  740.         u_char      esc;
  741.         int         rlebytes;
  742.         int         bufsize;
  743.  
  744.         fseek(fp, blockoffset, 0);
  745.  
  746.         rlebytes = GetWord(fp);
  747.         bufsize = GetWord(fp);
  748.         esc = GetByte(fp);
  749.  
  750.         blockoffset += rlebytes;
  751.  
  752.         if (imverbose) {
  753.             fprintf(stderr,"block: %d (len = %d) (bufsize = %d) (esc = %d)\n",
  754.                i, rlebytes, bufsize, esc);
  755.             hexdump(fp, 4);
  756.         }
  757.         rlebytes -= 5;
  758.         while (rlebytes) {
  759.             u_char      c = GetByte(fp);
  760.             rlebytes--;
  761.             if (c == esc) {
  762.             u_int       count = GetByte(fp);
  763.             rlebytes--;
  764.             if (count == 0) {
  765.                 count = GetWord(fp);
  766.                 rlebytes -= 2;
  767.             }
  768.             c = GetByte(fp);
  769.             rlebytes--;
  770. #if 1
  771.             if (idx + count > datasize) {
  772.                 fprintf(stderr, "*");
  773.                 goto bailimage;
  774.             }
  775. #endif
  776.             memset(&ptr[idx], c, count);
  777.             idx += count;
  778.             } else {
  779. #if 1
  780.             if (idx + 1 > datasize) {
  781.                 fprintf(stderr, "*");
  782.                 goto bailimage;
  783.             }
  784. #endif
  785.             ptr[idx] = c;
  786.             idx++;
  787.             }
  788.         }
  789.         }
  790.     }
  791.     }
  792. bailimage:
  793.  
  794.     switch (bpp) {
  795.     case 1:
  796.     switch (planes) {
  797.     case 1:
  798.         break;
  799.     case 2:
  800.     case 3:
  801.         error("%s: %d plane decoding not implemented\n", planes);
  802.         break;
  803.     case 4:
  804.         {
  805.         u_char     *dst;
  806.         u_char     *src;
  807.         u_char     *old;
  808.         int         srcbpsl = (im->w + 7) >> 3;
  809.         int         plane0 = srcbpsl * 0 * im->h;
  810.         int         plane1 = srcbpsl * 1 * im->h;
  811.         int         plane2 = srcbpsl * 2 * im->h;
  812.         int         plane3 = srcbpsl * 3 * im->h;
  813.  
  814.         src = old = ptr;
  815.         dst = ptr = (u_char *) malloc(datasize);
  816.  
  817.         if (!dst)
  818.             error("%s: readimage:4: malloc failed on image data.\n");
  819.  
  820.         for (j = 0; j < im->h; j++) {
  821.             int         mask = 0x80;
  822.             int         addr = j * srcbpsl;
  823.             for (i = 0; i < im->w; i++, mask >>= 1) {
  824.             if (mask == 0) {
  825.                 mask = 0x80;
  826.                 addr++;
  827.             }
  828.             *dst++ = ((src[plane0 + addr] & mask) != 0) +
  829.                 2 * ((src[plane1 + addr] & mask) != 0) +
  830.                 4 * ((src[plane2 + addr] & mask) != 0) +
  831.                 8 * ((src[plane3 + addr] & mask) != 0);
  832.             }
  833.         }
  834.         free(old);
  835.         }
  836.         break;
  837.     }
  838.     break;
  839.     case 2:
  840.     switch (planes) {
  841.     case 1:
  842.         {
  843.         u_char     *dst;
  844.         u_char     *src;
  845.         u_char     *old;
  846.         int         rem;
  847.  
  848.         src = old = ptr;
  849.         dst = ptr = (u_char *) malloc(datasize);
  850.  
  851.         if (!dst)
  852.             error("%s: readimage:2: malloc failed on image data.\n");
  853.  
  854.         rem = im->w & 3;
  855.         for (i = 0; i < im->h; i++) {
  856.             for (j = 0; j < im->w >> 2; j++) {
  857.             *dst++ = *src >> 6 & 3;
  858.             *dst++ = *src >> 4 & 3;
  859.             *dst++ = *src >> 2 & 3;
  860.             *dst++ = *src >> 0 & 3;
  861.             src++;
  862.             }
  863.             switch (rem) {
  864.             case 3:
  865.             dst[2] = *src >> 2 & 3;
  866.             case 2:
  867.             dst[1] = *src >> 4 & 3;
  868.             case 1:
  869.             dst[0] = *src >> 6 & 3;
  870.             src++;
  871.             dst += rem;
  872.             case 0:
  873.             break;
  874.             }
  875.         }
  876.         free(old);
  877.         }
  878.         break;
  879.     default:
  880.         error("%s: %d plane decoding not implemented\n", planes);
  881.         break;
  882.     }
  883.     break;
  884.     case 4:
  885.     {
  886.         u_char     *dst;
  887.         u_char     *src;
  888.         u_char     *old;
  889.  
  890.         src = old = ptr;
  891.         dst = ptr = (u_char *) malloc(datasize);
  892.  
  893.         if (!dst)
  894.         error("%s: readimage:4b: malloc failed on image data.\n");
  895.  
  896.         for (i = 0; i < im->h; i++) {
  897.         for (j = 0; j < im->w / 2; j++) {
  898.             *dst++ = *src >> 4 & 0xf;
  899.             *dst++ = *src >> 0 & 0xf;
  900.             src++;
  901.         }
  902.         }
  903.         free(old);
  904.     }
  905.     break;
  906.     case 8:
  907.     break;
  908.     }
  909.  
  910. /* invert the image top to bottom */
  911. // is this where we mess up left edge -> right edge ??
  912.    {
  913.     u_char     *buffer;
  914.     buffer = (u_char *) malloc(bpsl);
  915.     for (i = 0; i < im->h / 2; i++) {
  916.         memcpy(buffer, ptr + (im->h - i - 1) * bpsl, bpsl);
  917.         memcpy(ptr + (im->h - i - 1) * bpsl, ptr + i * bpsl, bpsl);
  918.         memcpy(ptr + i * bpsl, buffer, bpsl);
  919.     }
  920.     free(buffer);
  921.     }
  922.     
  923.     xim = XCreateImage(dsp, vis, im->d, format, 0, ptr, im->w, im->h, 8, bpsl);
  924.     //im->pix = XCreatePixmap(dsp, win, im->w, im->h, 8);
  925.     //XPutImage(dsp, im->pix, gc, xim, 0, 0, 0, 0, im->w, im->h);
  926.     //XSync(dsp, False);
  927.     // mac, non-X fix
  928.     im->w= xim->width; // patch in case CreateImage needed to change size
  929.     im->h= xim->height;
  930.     im->pix = (Pixmap) xim;
  931.     
  932.     return im;
  933. }
  934.  
  935.  
  936. ImageStruct *
  937. readpcximage(fp, dirent)
  938.     FILE       *fp;
  939.     FilenameStruct *dirent;
  940. {
  941.     ImageStruct *im;
  942.     XImage     *xim;
  943.     int         i;
  944.     int         j;
  945.     u_char      pcxhd[128];
  946.     int         magic;
  947.     int         version;
  948.     int         encoded;
  949.     int         bpp;
  950.     int         xmin, ymin, xmax, ymax;
  951.     int         planes;
  952.     int         bpsl;
  953.  
  954.     int         datasize;
  955.     u_char     *ptr;
  956.     int         maxcolorval;
  957.     u_long      pixels[256];
  958.     u_long      pmasks;
  959.     int         filelen;
  960.     int         format;
  961.  
  962.     im = (ImageStruct *) malloc(sizeof(ImageStruct));
  963.  
  964.     fseek(fp, dirent->offset, 0);
  965.  
  966.     filelen = GetLong(fp);    /* length of whole image file... */
  967.  
  968.     if (imverbose)
  969.     hexdump(fp, 4);
  970.  
  971.     im->name = strtok(strdup(dirent->fname), ".");
  972.     im->type = EXT_PCX;
  973.  
  974.     fread(pcxhd, 128, 1, fp);
  975.     magic = pcxhd[0];
  976.     if (magic != 0x0a)
  977.     fprintf(stderr,"I don't think this is really a .pcx file!\n");
  978.     version = pcxhd[1];
  979.     encoded = pcxhd[2];
  980.     xmin = pcxhd[4] + (256 * pcxhd[5]);
  981.     ymin = pcxhd[6] + (256 * pcxhd[7]);
  982.     xmax = pcxhd[8] + (256 * pcxhd[9]);
  983.     ymax = pcxhd[10] + (256 * pcxhd[11]);
  984.     im->w = xmax - xmin + 1;
  985.     im->h = ymax - ymin + 1;
  986.     im->xoff = im->yoff = 0;
  987.     bpsl = pcxhd[66] + (256 * pcxhd[67]);
  988.     bpp = pcxhd[3];
  989.     planes = pcxhd[65];
  990.  
  991.     if (bpp == 1 && planes == 1) {
  992.     im->d = 1;
  993.     format = XYBitmap;
  994.     XSetForeground(dsp, gc, white);
  995.     XSetBackground(dsp, gc, black);
  996.     } else {
  997.     im->d = 8;
  998.     format = ZPixmap;
  999.     bpsl = im->w;
  1000.     }
  1001.     datasize = bpsl * im->h;
  1002.     ptr = (u_char *) malloc(datasize);
  1003.     if (!ptr)
  1004.     error("%s: readpcximage: malloc failed on image data.\n");
  1005.  
  1006.     if (verbose)
  1007.     fprintf(stderr,"%s: (PCX) %dx%dx%d(%1x:%1x) [%d,%d] sz=%d ver=%d enc=%d\n",
  1008.            im->name,
  1009.            im->w,
  1010.            im->h,
  1011.            im->d,
  1012.            bpp, planes,
  1013.            im->xoff,
  1014.            im->yoff,
  1015.            datasize,
  1016.            version,
  1017.            encoded);
  1018.  
  1019.     if (version != 0)
  1020.     im->cmap = XCreateColormap(dsp, win, vis, AllocNone);
  1021.  
  1022.     switch (version) {
  1023.     case 0:
  1024.     case 3:
  1025.     im->cmaplen = 0;
  1026.     im->cmap = (Colormap) 0;
  1027.     break;
  1028.     case 2:
  1029.     im->cmaplen = 16;
  1030.     maxcolorval = 255;
  1031.     break;
  1032.     case 5:
  1033.     im->cmaplen = 256;
  1034.     maxcolorval = 255;
  1035.     break;
  1036.     case 1:
  1037.     case 4:
  1038.     default:
  1039.     error("%s: bad pcx version: %d\n", version);
  1040.     }
  1041.  
  1042.     if (im->cmaplen > 0)
  1043.     XAllocColorCells(dsp, im->cmap, True, &pmasks, 0, pixels, im->cmaplen);
  1044.  
  1045.     switch (version) {
  1046.     case 0:
  1047.     case 3:
  1048.     break;
  1049.     case 2:    /* I'm guessing here! */
  1050.     for (i = 0; i < im->cmaplen; i++) {
  1051.         im->colors[i].pixel = pixels[i];
  1052.         im->colors[i].red = pcxhd[16 + i + 0] << 8;
  1053.         im->colors[i].green = pcxhd[16 + i + 1] << 8;
  1054.         im->colors[i].blue = pcxhd[16 + i + 2] << 8;
  1055.         im->colors[i].flags = DoRed | DoGreen | DoBlue;
  1056.     }
  1057.     break;
  1058.     case 5:
  1059.     fseek(fp, dirent->offset + filelen + 4 - 769, 0);
  1060.     if (GetByte(fp) != 12)
  1061.         fprintf(stderr,"I don't think this is a VGA palette.\n");
  1062.     for (i = 0; i < im->cmaplen; i++) {
  1063.         im->colors[i].pixel = pixels[i];
  1064.         im->colors[i].red = GetByte(fp) << 8;
  1065.         im->colors[i].green = GetByte(fp) << 8;
  1066.         im->colors[i].blue = GetByte(fp) << 8;
  1067.         im->colors[i].flags = DoRed | DoGreen | DoBlue;
  1068.     }
  1069.     fseek(fp, dirent->offset + 4 + 128, 0);
  1070.     break;
  1071.     }
  1072.  
  1073.     if (version > 0) {
  1074.     if (imverbose) {
  1075.         fprintf(stderr,"%d colors\n", im->cmaplen);
  1076.         /*---
  1077.         for (i = 0; i < im->cmaplen; i++) {
  1078.         fprintf(stderr,"%02x%02x%02x ",
  1079.                im->colors[i].red >> 8,
  1080.                im->colors[i].green >> 8,
  1081.                im->colors[i].blue >> 8);
  1082.         if (!((i + 1) % 8))
  1083.             fprintf(stderr,"\n");
  1084.         }
  1085.        ---*/
  1086.     }
  1087.         XStoreColors(dsp, im->cmap, im->colors, im->cmaplen);
  1088.     }
  1089.     if (encoded) {
  1090.     /*
  1091.      * Goes like this: Read a byte.  If the two high bits are set, then the
  1092.      * low 6 bits contain a repeat count, and the byte to repeat is the
  1093.      * next byte in the file.  If the two high bits are not set, then this
  1094.      * is the byte to write.
  1095.      */
  1096.  
  1097.     int         i = 0;
  1098.  
  1099.     while (i < datasize) {
  1100.         int         byte = GetByte(fp);
  1101.         if ((byte & 0xc0) == 0xc0) {
  1102.         int         count = byte & 0x3f;
  1103.         int value = GetByte(fp);
  1104.         if (i + count > datasize)
  1105.             count = datasize - i - 1;    /* catch overflow */
  1106.         memset(ptr + i, value, count);
  1107.         i += count;
  1108.         } else {
  1109.         ptr[i++] = byte;
  1110.         }
  1111.     }
  1112.     } else
  1113.     fread(ptr, datasize, 1, fp);
  1114.  
  1115.     /*
  1116.      * need to do planar -> chunky conversion here if we support > 1 plane pcx
  1117.      * files.
  1118.      */
  1119.  
  1120.     xim = XCreateImage(dsp, vis, im->d, format, 0, ptr, im->w, im->h, 8, bpsl);
  1121. /*****
  1122.     im->pix = XCreatePixmap(dsp, win, im->w, im->h, 8);
  1123.     XPutImage(dsp, im->pix, gc, xim, 0, 0, 0, 0, im->w, im->h);
  1124.     XSync(dsp, False);
  1125. *****/
  1126.     // mac, non-X fix
  1127.     im->w= xim->width; // patch in case CreateImage needed to change size
  1128.     im->h= xim->height;
  1129.     im->pix = (Pixmap) xim;
  1130.     
  1131.     return im;
  1132. }
  1133.  
  1134.  
  1135. void
  1136. printcodes(ex)
  1137.     ExecStruct *ex;
  1138. {
  1139.     int         i;
  1140.     for (i = 0; i < ex->numcodes; i++) {
  1141.     fprintf(stderr,"%4d: ", i);
  1142.     if (ex->Code[i].token < NTOKENS)
  1143.         fprintf(stderr,"[TOK] %s (%d) (%d args)\n",
  1144.            tokens[ex->Code[i].token], ex->Code[i].token,
  1145.            ex->Code[i].val.i);
  1146.     else {
  1147.         switch (ex->Code[i].token) {
  1148.         case INTEGER:
  1149.         fprintf(stderr,"[INT] %d\n", ex->Code[i].val.i);
  1150.         break;
  1151.         case STRING:
  1152.         fprintf(stderr,"[STR] \"%s\"\n", ex->Code[i].val.s);
  1153.         break;
  1154.         case IMAGE:
  1155.         fprintf(stderr,"[IMG] \"%s\"\n", ex->Code[i].val.image->name);
  1156.         break;
  1157.         case FONTTYPE:
  1158.         fprintf(stderr,"[FNT] \"%s\"\n", ex->Code[i].val.font->name);
  1159.         break;
  1160.         case EXECTYPE:
  1161.         fprintf(stderr,"[EXC] \"%s\"\n", ex->Code[i].val.exec->name);
  1162.         break;
  1163.         case WILDTYPE:
  1164.         fprintf(stderr,"[WLD] \"@\"\n");
  1165.         break;
  1166.         default:
  1167.         error("%s: printcodes bogosity (%d)\n", ex->Code[i].token);
  1168.         }
  1169.     }
  1170.     }
  1171.     fprintf(stderr,"labels:\n");
  1172.     for (i = 0; i < ex->numlabels; i++)
  1173.     fprintf(stderr,"[LABEL] \"%s\" %d\n", ex->label[i].string, ex->label[i].ipaddr);
  1174. }
  1175.  
  1176.  
  1177. /* turn all cload and pload args into pointers to the
  1178.  * actual image structure instead of the filename
  1179.  * turn all fload args into pointers to the font structure
  1180.  * instead of the filename, and change the '@' string to a WILDTYPE.
  1181.  */
  1182. void
  1183. converttypes(ex)
  1184.     ExecStruct *ex;
  1185. {
  1186.     int         i, j;
  1187.     for (i = 0; i < ex->numcodes; i++) {
  1188.     int         t = ex->Code[i].token;
  1189.     char       *s = ex->Code[i].val.s;
  1190.     char        nargs = ex->Code[i].val.i;
  1191.  
  1192.     switch (t) {
  1193.     case STRING:
  1194.         if (s[0] == '@' && s[1] == 0) {
  1195.         ex->Code[i].token = WILDTYPE;
  1196.         ex->Code[i].val.i = 0;
  1197.         }
  1198.         break;
  1199.     case FLOAD:
  1200.         stringtofont(ex, i + 1);
  1201.         break;
  1202.     case CLOAD:
  1203.         stringtoimage(ex, i + 1, EXT_CLP);
  1204.         break;
  1205.     case PLOAD:
  1206.         stringtoimage(ex, i + 1, EXT_PIC);
  1207.         break;
  1208.     case LINK:
  1209.     case CALL:
  1210.         stringtoexec(ex, i + 1);
  1211.         if (nargs > 1)
  1212.         stringtolabel(ex, i + 2);
  1213.         break;
  1214.     case DATABEGIN:
  1215.     case GOTO:
  1216.     case GOSUB:
  1217.         stringtolabel(ex, i + 1);
  1218.         break;
  1219.     case IFKEY:
  1220.         for (j = 2; j <= nargs; j += 2)
  1221.         stringtolabel(ex, i + j);
  1222.         break;
  1223.     case IFMEM:
  1224.     case IFVIDEO:
  1225.     case WAITKEY:
  1226.         if (nargs > 1)
  1227.         stringtolabel(ex, i + 2);
  1228.         break;
  1229.     }
  1230.     }
  1231. }
  1232.  
  1233. ExecStruct *
  1234. readtxt(fp, dir)
  1235.     FILE       *fp;
  1236.     FilenameStruct *dir;
  1237. {
  1238.     ExecStruct *ex;
  1239.     int         len;
  1240.     char       *txt;
  1241.     int         i;
  1242.  
  1243.     ex = (ExecStruct *) malloc(sizeof(ExecStruct));
  1244.     ex->name = strtok(strdup(dir->fname), ".");
  1245.  
  1246.     fseek(fp, dir->offset, 0);
  1247.     len = GetLong(fp);
  1248.     len &= 0x00ffffff;    /* hack */
  1249.     ex->txt = (char *) malloc(len + 1);
  1250.     fread(ex->txt, len, 1, fp);
  1251.     ex->txt[len] = 26;
  1252.     if (showtext)
  1253.     puts(ex->txt);
  1254.     return ex;
  1255. }
  1256.  
  1257.  
  1258. void
  1259. readfiles(fp, dir, count)
  1260.     FILE       *fp;
  1261.     FilenameStruct *dir;
  1262.     int         count;
  1263. {
  1264.     int         i;
  1265.     ImageStruct *im;
  1266.     
  1267.     for (i = 0; i < count; i++) {
  1268.     char       *p = strrchr(dir[i].fname, '.');
  1269.     int         extcode;
  1270.     if (!p)
  1271.         error("%s: %s has no extension.\n", dir[i].fname);
  1272.     extcode = findext(p);
  1273.     switch (extcode) {
  1274.     case EXT_PCX:
  1275.         image[numimages++] = readpcximage(fp, &dir[i]);
  1276.         break;
  1277.     case EXT_PIC:
  1278.     case EXT_CLP:
  1279.     case EXT_PAL:
  1280.         im = readimage(fp, &dir[i], extcode);
  1281.         if ((im==NULL) && (numimages>0)) im= image[numimages-1]; /* klugde fix */
  1282.         image[numimages++] = im;
  1283.         break;
  1284.     case EXT_GIF:
  1285.         image[numimages++] = readgifimage(fp, &dir[i]);
  1286.         break;
  1287.     case EXT_SET:
  1288.         font[numfonts++] = readset(fp, &dir[i]);
  1289.         if (font[numfonts - 1] == (FontStruct *) 0)
  1290.         --numfonts;
  1291.         break;
  1292.     case EXT_FNT:
  1293.         font[numfonts++] = readfont(fp, &dir[i]);
  1294.         if (font[numfonts - 1] == (FontStruct *) 0)
  1295.         --numfonts;
  1296.         break;
  1297.     case EXT_TXT:
  1298.         exec[numexecs++] = readtxt(fp, &dir[i]);
  1299.         break;
  1300.     default:
  1301.         fprintf(stderr,"skipping %s: unknown extension.\n", dir[i].fname);
  1302.     }
  1303.     }
  1304.  
  1305.     for (i = 0; i < numexecs; i++) {
  1306.     ExecStruct *ex = exec[i];
  1307.     parsefile(ex, ex->txt);
  1308.     converttypes(ex);
  1309.     if (printthecodes)
  1310.         printcodes(ex);
  1311.     }
  1312.  
  1313. /********
  1314.      if (imageloop) {
  1315.     int         im = 0;
  1316.  
  1317. //    XMapWindow(dsp, win);
  1318. //    XSync(dsp, False);
  1319.  
  1320.     while (1) {
  1321. //        XEvent      ev;
  1322. //        XNextEvent(dsp, &ev);
  1323.         if (ev.type == ButtonPress) {
  1324.         if (++im >= numimages)
  1325.             im = 0;
  1326. //        if (((XButtonEvent *) & ev)->button == Button3)
  1327. //            break;
  1328.         XStoreName(dsp, win, image[im]->name);
  1329.         XSetWindowColormap(dsp, win, image[im]->cmap);
  1330.         XCopyArea(dsp, image[im]->pix, win, gc,
  1331.               0, 0,
  1332.               image[im]->w,
  1333.               image[im]->h,
  1334.               0, 0);
  1335.  
  1336.         }
  1337.     }
  1338.     }
  1339. **********/
  1340. }
  1341.