home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / BM2FON20 / BM2FONT.C < prev    next >
C/C++ Source or Header  |  1993-03-01  |  106KB  |  4,640 lines

  1. /* Output from p2c, the Pascal-to-C translator */
  2. /* From input file "bm2font.pas" */
  3.  
  4.  
  5. /*1:*/
  6.  
  7. #include "p2c.h"
  8. /* p2c: bm2font.pas, line 1: 
  9.  * Note: Unexpected name "texfile" in program header [262] */
  10. /* p2c: bm2font.pas, line 1: 
  11.  * Note: Unexpected name "tfmfile" in program header [262] */
  12. /* p2c: bm2font.pas, line 1: 
  13.  * Note: Unexpected name "pxlfile" in program header [262] */
  14. /* p2c: bm2font.pas, line 1: 
  15.  * Note: Unexpected name "bitmap" in program header [262] */
  16. /* p2c: bm2font.pas, line 1: 
  17.  * Note: Unexpected name "tmpfil" in program header [262] */
  18.  
  19.  
  20. /*logfile,*/
  21.  
  22.  
  23. typedef uchar ebts;
  24.  
  25. typedef short halfk;
  26.  
  27. typedef long dynlong[26][129];
  28. typedef unsigned short dynword[26][129];
  29. typedef short korbyte[511];
  30. typedef short spreadbyte[256];
  31. /*55:*/
  32. typedef unsigned short pxlstr;
  33.  
  34. typedef ebts pxla[65522L];
  35. /*:55*/
  36. /*59:*/
  37. typedef short pxlba[32761];
  38. /*:59*/
  39. /*91:*/
  40. typedef uchar dmatrix[7][7];
  41.  
  42. /*:91*/
  43.  
  44.  
  45. #define maxmemsize      32760
  46.  
  47.  
  48. /*92:*/
  49.  
  50. Static dmatrix ditherm = {
  51.   { 1, 3, 6, 10, 18, 26, 38 },
  52.   { 2, 4, 8, 12, 20, 28, 40 },
  53.   { 5, 7, 9, 14, 22, 30, 42 },
  54.   { 11, 13, 15, 16, 24, 32, 44 },
  55.   { 17, 19, 21, 23, 25, 34, 46 },
  56.   { 27, 29, 31, 33, 35, 36, 48 },
  57.   { 37, 39, 41, 43, 45, 47, 49 }
  58. };
  59.  
  60. /*:92*/
  61. /*:1*/
  62. /*2:*/
  63. Static ebts hrep, vrep, xrep, yrep, patswitch, usecol, pminval, pmaxval,
  64.         bufsh, nextbuf, tmpcolor, invbyte, invbit, xratio, yratio;
  65. Static unsigned short tpal[256];
  66. Static long bitspsam, rowspstrip;
  67. Static unsigned short photoinf;
  68. Static short colpos;
  69. Static ebts pxllook[256];
  70. Static ebts lutone[256];
  71. Static ebts lutvga[256];
  72. Static ebts lutsl[256];
  73. Static double spreadcol, patref, greyunit;
  74. Static short greykor;
  75. Static short *gkorh, *gkordivp;
  76. Static short *spreadvals;
  77. Static short hktab[256];
  78. Static boolean cspread;
  79. Static unsigned short pxlcolor;
  80. Static boolean greypxl, egastretch, ledprinter, distribute, giftemp, pcxtemp;
  81. Static short maxcol;
  82. Static long usepxl, vusepxl, brightness;
  83. Static short greypix;
  84. Static ebts pattern[4][197][7];
  85. Static unsigned short tab[64][3];
  86. Static uchar ccol;
  87. Static Char cref[77];
  88. Static ebts b1[3000];
  89. Static ebts b2[3000];
  90. Static ebts b3[3000];
  91. Static ebts b4[3000];
  92. Static long linepos_, posbit;
  93. Static halfk dbuf;
  94. Static boolean zeroline, zerorow, nameok, fok;
  95. Static Char cmd[256];
  96. Static Char bmname[256];
  97. Static Char font[256];
  98. Static Char tmpname[256];
  99. Static Char fontpre[256];
  100. Static Char fontupc[256];
  101. Static ebts curpat[2];
  102. Static short gbufp, gbufpp;
  103. Static halfk pxlinlen, zeropads;
  104. Static short mapwidth, mapheight, maplines, freelines;
  105. Static long mapinlen, newwidth, newheight;
  106. Static short a, b, f, nf, g, ng, ly, lx, minx, maxx, i, nj, j, v, k, pk, pkn;
  107. Static uchar pm, pn;
  108. Static unsigned short pl, pb;
  109. Static uchar c, cb;
  110. Static long fh, sh, fw, sw;
  111. Static unsigned short lf, lh, bc, ec, nw, nh, nd, ni, nl, nk, ne, np;
  112. Static union {
  113.   uchar b[4];
  114.   long i;
  115. } cx;
  116. Static long checksum, dsize;
  117. Static long tabdsize[26];
  118. Static long (*width)[129], (*height)[129];
  119. Static unsigned short (*yoffset)[129], (*pwidth)[129], (*pheight)[129];
  120. Static long dirpoint[129];
  121. Static pxlstr pkpoint[129];
  122. Static long hres, vres;
  123. Static double truehres, truevres;
  124. Static long noffonts, nofchars, mincharpf;
  125. Static uchar charpf[27];
  126. /*logfile,*/
  127. Static FILE *texfile;
  128. Static FILE *bitmap, *pxlfile, *tmpfil;
  129. Static short filestat;
  130. Static unsigned short gi;
  131. Static boolean invert;
  132. Static unsigned short cv, dv, lv;
  133. Static Char comment[256];
  134. Static Char aliasname[256];
  135. Static boolean aliasused;
  136. Static double mapdiv;
  137. Static long pkwidth, pkheight;
  138. Static boolean nowhite, halfinch;
  139. Static pxlstr nextmemfree;
  140. /*25:*/
  141. Static ebts cutrep, outputbyte;
  142. Static halfk cutlen;
  143. Static boolean cutgrey;   /*:25*/
  144. /*53:*/
  145. Static Char tfmstr[256];
  146. Static uchar tfmb;
  147. Static FILE *tfmfile;
  148. /*:53*/
  149. /*56:*/
  150. Static uchar *pxlbm;
  151. Static pxlstr pxlbmi;
  152. /*:56*/
  153. /*58:*/
  154. Static uchar *pkbm;
  155. Static short *repbm;
  156. Static pxlstr pkloc;
  157. /*:58*/
  158. /*62:*/
  159. Static short bitweight;
  160. /*:62*/
  161. /*64:*/
  162. Static ebts car;
  163. /*:64*/
  164. /*69:*/
  165. Static short cxoff, cyoff;
  166. /*:69*/
  167. /*73:*/
  168. Static short power[9];   /*:73*/
  169. /*93:*/
  170. Static double valinc, redval, grx, grxzero;
  171. Static long gradint;
  172. Static uchar *greymem;
  173. Static long pgreymem;
  174. Static boolean randomst, newrandom;
  175. Static Char texfile_NAME[_FNSIZE];
  176. Static Char bitmap_NAME[_FNSIZE];
  177. Static Char pxlfile_NAME[_FNSIZE];
  178. Static Char tmpfil_NAME[_FNSIZE];
  179. Static Char tfmfile_NAME[_FNSIZE];
  180.  
  181.  
  182. /*:93*/
  183. /*:2*/
  184. /*6:*/
  185. Static uchar korrlastb(i, j)
  186. uchar i;
  187. short j;
  188. {
  189.   ebts k;
  190.  
  191.   k = 8 - j;
  192.   if (k > 0) {
  193.     i >>= k;
  194.     i <<= k;
  195.   }
  196.   return i;
  197. }
  198.  
  199.  
  200. /*:6*/
  201. /*7:*/
  202. Static uchar pxladd(i, j, k)
  203. uchar i, j;
  204. short k;
  205. {
  206.   i = (i << k) & 255;
  207.   j >>= k;
  208.   return (i | j);
  209. }
  210.  
  211.  
  212. /*:7*/
  213. /*8:*/
  214. Static unsigned short getcolor()
  215. {
  216.   halfk j, k;
  217.   unsigned short a, o;
  218.   ebts savcol, lcol, rcol, l, r;
  219.  
  220.   if (cutgrey) {
  221.     if ((cutrep & 127) == 0) {
  222.       if (cutrep == 128)
  223.     colpos++;
  224.       cutrep = b1[(halfk)colpos];
  225.       colpos++;
  226.     }
  227.     savcol = b1[(halfk)colpos];
  228.     if (cutrep < 128)
  229.       colpos++;
  230.     cutrep--;
  231.     return savcol;
  232.   }
  233.   a = colpos;
  234.   colpos += bitspsam;
  235.   o = a + bitspsam - 1;
  236.   l = a & 7;
  237.   r = (o + 1) & 7;
  238.   k = o >> 3;
  239.   j = a >> 3;
  240.   lcol = b1[j];
  241.   rcol = b1[k];
  242.   if (k != j) {
  243.     savcol = lcol << l;
  244.     savcol = (savcol >> (l - r)) ^ (rcol >> (8 - r));
  245.     return savcol;
  246.   }
  247.   savcol = lcol << l;
  248.   savcol >>= l;
  249.   if (r > 0)
  250.     savcol >>= 8 - r;
  251.   return savcol;
  252. }
  253.  
  254.  
  255. /*:8*/
  256. /*9:*/
  257. Static Char *numtostr(Result, i)
  258. Char *Result;
  259. long i;
  260. {
  261.   Char nstr[256];
  262.  
  263.   sprintf(nstr, "%ld", i);
  264.   return strcpy(Result, nstr);
  265. }
  266.  
  267.  
  268. /*:9*/
  269. /*10:*/
  270. Static Void korrfont()
  271. {
  272.   uchar i, j;
  273.  
  274.   i = strpos2(font, "/", 1);
  275.   while (i > 0) {
  276.     strdelete((Anyptr)font, 1, i);
  277.     i = strpos2(font, "/", 1);
  278.   }
  279.   j = strlen(font);
  280.   i = strpos2(font, ".", 1);
  281.   if (i != 0)
  282.     strdelete((Anyptr)font, i, j - i + 1);
  283.   if (strlen(font) > 7)
  284.     font[7] = '\0';
  285. }
  286.  
  287.  
  288. /*:10*/
  289. /*11:*/
  290. Static Void whatistrue()
  291. {
  292.   hres = (long)floor(truehres + 0.5);
  293.   vres = (long)floor(truevres + 0.5);
  294.   if (halfinch) {
  295.     hres /= 2;
  296.     vres /= 2;
  297.   }
  298.   hres -= hres & 7;
  299.   if (hres * vres <= 262136L)
  300.     return;
  301.   if (truehres > truevres) {
  302.     hres = (long)sqrt(262136.0) - 31;
  303.     vres = (long)(hres * truevres / truehres);
  304.     return;
  305.   }
  306.   if (truevres > truehres) {
  307.     vres = (long)sqrt(262136.0) - 31;
  308.     hres = (long)(vres * truehres / truevres);
  309.   } else {
  310.     hres = (long)sqrt(262136.0) - 31;
  311.     vres = hres;
  312.   }
  313. }  /*:11*/
  314.  
  315.  
  316. /*12:*/
  317. Static Void outfix(k)
  318. long k;
  319. {
  320.   short a;
  321.   long f;
  322.   char j;
  323.   long delta;
  324.   union {
  325.     ebts b[4];
  326.     long i;
  327.   } ax;
  328.   char dig[12];
  329.  
  330.   ax.i = k;
  331. #ifdef INTEL
  332.   a = (long)ax.b[3] * 16 + ax.b[2] / 16;
  333.   f = ((ax.b[2] & 15) * 256 + ax.b[1]) * 256 + ax.b[0];
  334. #else
  335.   a = (long)ax.b[0] * 16 + ax.b[1] / 16;
  336.   f = ((ax.b[1] & 15) * 256 + ax.b[2]) * 256 + ax.b[3];
  337. #endif
  338.   if (a > 2047) {
  339.     putc('-', texfile);
  340.     a = 4096 - a;
  341.     if (f > 0) {
  342.       f = 1048576L - f;
  343.       a--;
  344.     }
  345.   }
  346.   j = 0;
  347.   do {
  348.     dig[j] = a % 10;
  349.     a /= 10;
  350.     j++;
  351.   } while (a != 0);
  352.   do {
  353.     j--;
  354.     fprintf(texfile, "%d", dig[j]);
  355.   } while (j != 0);
  356.   putc('.', texfile);
  357.   f = f * 10 + 5;
  358.   delta = 10;
  359.   do {
  360.     if (delta > 1048576L)
  361.       f += 524288L - delta / 2;
  362.     fprintf(texfile, "%ld", f / 1048576L);
  363.     f = f % 1048576L * 10;
  364. /* p2c: bm2font.pas, line 89:
  365.  * Note: Using % for possibly-negative arguments [317] */
  366.     delta *= 10;
  367.   } while (f > delta);
  368. }
  369.  
  370.  
  371. /*:12*/
  372. /*13:*/
  373. Static Void fileproblem()
  374. {
  375.   printf("file-error %d : ", filestat);
  376.   switch (filestat) {
  377.  
  378.   case 2:
  379.     printf("file not found");
  380.     break;
  381.  
  382.   case 3:
  383.     printf("path not found");
  384.     break;
  385.  
  386.   case 4:
  387.     printf("too many files open");
  388.     break;
  389.  
  390.   case 5:
  391.     printf("file access denied");
  392.     break;
  393.  
  394.   case 6:
  395.     printf("invalid file handle");
  396.     break;
  397.  
  398.   case 12:
  399.     printf("invalid file access mode");
  400.     break;
  401.  
  402.   case 15:
  403.     printf("invalid drive number");
  404.     break;
  405.  
  406.   case 101:
  407.     printf("disk full");
  408.     break;
  409.  
  410.   default:
  411.     printf("ask a tpc guru");
  412.     break;
  413.   }
  414.   printf("!\n");
  415.   if (pcxtemp)
  416. /* p2c: bm2font.pas, line 99: Note: Called procedure Exec [285] */
  417.     Exec("rm", "pcxtemp.tmp");
  418.   if (giftemp)
  419. /* p2c: bm2font.pas, line 99: Note: Called procedure Exec [285] */
  420.     Exec("rm", "giftemp.tmp");
  421.   if (greypxl)
  422. /* p2c: bm2font.pas, line 99: Note: Called procedure Exec [285] */
  423.     Exec("rm", tmpname);
  424. }
  425.  
  426.  
  427. /*:13*/
  428. /*14:*/
  429. Static Void opentempfile()
  430. {
  431.   strcpy(tmpname, "pcxtemp.tmp");
  432.   strcpy(tmpfil_NAME, "pcxtemp.tmp");
  433.   filestat = P_ioresult;
  434.   if (filestat == 0)
  435.     fok = false;
  436.   else
  437.     fok = true;
  438.   if (fok) {
  439.     printf("tempfile pcxtemp.tmp not accessable, abort\n");
  440.     fileproblem();
  441.     _Escape(0);
  442.   }
  443.   if (tmpfil != NULL)
  444.     tmpfil = freopen(tmpfil_NAME, "w+b", tmpfil);
  445.   else
  446.     tmpfil = fopen(tmpfil_NAME, "w+b");
  447.   _SETIO(tmpfil != NULL, FileNotFound);
  448.   filestat = P_ioresult;
  449.   if (filestat == 0)
  450.     fok = false;
  451.   else
  452.     fok = true;
  453.   if (!fok)
  454.     return;
  455.   printf("Unable to create pcxtmp.tmp, abort\n");
  456.   fileproblem();
  457.   _Escape(0);
  458. }
  459.  
  460.  
  461. /*:14*/
  462. /*15:*/
  463. Static Void picstretch()
  464. {
  465.   short FORLIM;
  466.  
  467.   printf("Stretching the picture because of odd aspect ratio\n");
  468.   posbit = 0;
  469.   giftemp = true;
  470.   strcpy(tmpname, "giftemp.tmp");
  471.   strcpy(tmpfil_NAME, "giftemp.tmp");
  472.   filestat = P_ioresult;
  473.   if (filestat == 0)
  474.     fok = false;
  475.   else
  476.     fok = true;
  477.   if (fok) {
  478.     printf("tempfile giftemp.tmp not accessable, abort\n");
  479.     fileproblem();
  480.     _Escape(0);
  481.   }
  482.   if (tmpfil != NULL)
  483.     tmpfil = freopen(tmpfil_NAME, "w+b", tmpfil);
  484.   else
  485.     tmpfil = fopen(tmpfil_NAME, "w+b");
  486.   if (tmpfil == NULL)
  487.     _EscIO(FileNotFound);
  488.   while (!P_eof(bitmap)) {
  489.     fread(b1, mapinlen, 1, bitmap);
  490.     if (posbit == xratio) {
  491.       if (bitspsam == 8) {
  492.     FORLIM = mapinlen;
  493.     for (gbufp = 0; gbufp < FORLIM; gbufp++)
  494.       b3[gbufp] = ((unsigned)(b3[gbufp] + b1[gbufp])) >> 1;
  495.       } else if (bitspsam == 4) {
  496.     FORLIM = mapinlen;
  497.     for (gbufp = 0; gbufp < FORLIM; gbufp++) {
  498.       b = ((unsigned)((b3[gbufp] >> 4) + (b1[gbufp] >> 4))) >> 1;
  499.       c = ((unsigned)((b3[gbufp] & 15) + (b1[gbufp] & 15))) >> 1;
  500.       b3[gbufp] = (b << 4) + c;
  501.     }
  502.       }
  503. /* p2c: bm2font.pas, line 118:
  504.  * Note: Can't interpret size in BLOCKWRITE [174] */
  505.       _SETIO(fwrite(b3, mapinlen, 1, tmpfil) == 1, FileWriteError);
  506.       filestat = P_ioresult;
  507.       if (filestat != 0) {
  508.     _SETIO(printf("Error occured when writing file %s!\n", tmpname) >= 0,
  509.            FileWriteError);
  510.     fileproblem();
  511.     _Escape(0);
  512.       }
  513.       posbit = 0;
  514.     }
  515.     posbit++;
  516.     if (posbit == xratio) {
  517.       FORLIM = mapinlen;
  518.       for (gbufp = 0; gbufp < FORLIM; gbufp++)
  519.     b3[gbufp] = b1[gbufp];
  520.     }
  521. /* p2c: bm2font.pas, line 122:
  522.  * Note: Can't interpret size in BLOCKWRITE [174] */
  523.     _SETIO(fwrite(b1, mapinlen, 1, tmpfil) == 1, FileWriteError);
  524.     filestat = P_ioresult;
  525.     if (filestat != 0) {
  526.       _SETIO(printf("Error occured when writing file %s!\n", tmpname) >= 0,
  527.          FileWriteError);
  528.       fileproblem();
  529.       _Escape(0);
  530.     }
  531.   }
  532. /* p2c: bm2font.pas, line 113:
  533.  * Note: Can't interpret size in BLOCKREAD [174] */
  534.   if (bitmap != NULL)
  535.     fclose(bitmap);
  536.   bitmap = NULL;
  537.   if (tmpfil != NULL)
  538.     fclose(tmpfil);
  539.   tmpfil = NULL;
  540.   strcpy(bitmap_NAME, "giftemp.tmp");
  541.   if (bitmap != NULL)
  542.     bitmap = freopen(bitmap_NAME, "r+b", bitmap);
  543.   else
  544.     bitmap = fopen(bitmap_NAME, "r+b");
  545.   if (bitmap == NULL)
  546.     _EscIO(FileNotFound);
  547.   posbit = 0;
  548.   cutgrey = false;
  549.   if (pcxtemp) {
  550. /* p2c: bm2font.pas, line 127: Note: Called procedure Exec [285] */
  551.     Exec("rm", "pcxtemp.tmp");
  552.     pcxtemp = false;
  553.   }
  554. }
  555.  
  556.  
  557. /*:15*/
  558. /*16:*/
  559. Static Void scaling()
  560. {  /*17:*/
  561.   long newh, newv, counth, countv;
  562.   double scaleh, scalev, ledfac, repfac;
  563.   boolean grver, grhor, remlast;
  564.   short FORLIM;
  565.  
  566.   if (ledprinter)
  567.     ledfac = 0.5;
  568.   else
  569.     ledfac = 0.0;
  570.   if (hrep != 1)
  571.     repfac = 2.0;
  572.   else
  573.     repfac = 1.0;
  574.   if (!greypxl) {
  575.     usepxl = 1;
  576.     vusepxl = 1;
  577.     bitspsam = 1;
  578.   }
  579.   if (newwidth != 0)
  580.     newwidth = (long)floor(
  581.       newwidth * truehres / 25.4 / (repfac * (usepxl + ledfac)) + 0.5);
  582.   if (newheight != 0)
  583.     newheight = (long)floor(
  584.       newheight * truevres / 25.4 / (repfac * (vusepxl + ledfac)) + 0.5);
  585.   if (newheight == 0)
  586.     newheight = (long)floor((double)mapheight / mapwidth * newwidth + 0.5);
  587.   if (newwidth == 0)
  588.     newwidth = (long)floor((double)mapwidth / mapheight * newheight + 0.5);
  589.   printf("Scaling the picture from %dx%d", mapwidth, mapheight);
  590.   printf(" to %ldx%ld pixels\n", newwidth, newheight);
  591.   grver = (newheight > mapheight);
  592.   grhor = (newwidth > mapwidth);
  593.   if (grhor)
  594.     scaleh = newwidth / (newwidth - mapwidth + 1.0);
  595.   else
  596.     scaleh = mapwidth / (mapwidth - newwidth + 1.0);
  597.   if (grver)   /*:17*/
  598.     scalev = newheight / (newheight - mapheight + 1.0);
  599.   else
  600.     scalev = mapheight / (mapheight - newheight + 1.0);
  601.   /*18:*/
  602.   if (giftemp)
  603.     strcpy(tmpname, "pcxtemp.tmp");
  604.   else
  605.     strcpy(tmpname, "giftemp.tmp");
  606.   strcpy(tmpfil_NAME, tmpname);
  607.   filestat = P_ioresult;
  608.   if (filestat == 0)
  609.     fok = false;
  610.   else
  611.     fok = true;
  612.   if (fok) {
  613.     printf("tempfile %s not accessable, abort\n", tmpname);
  614.     fileproblem();
  615.     _Escape(0);
  616.   }
  617.   if (tmpfil != NULL)
  618.     tmpfil = freopen(tmpfil_NAME, "w+b", tmpfil);
  619.   else
  620.     tmpfil = fopen(tmpfil_NAME, "w+b");
  621.   if (tmpfil == NULL)
  622.     _EscIO(FileNotFound);
  623.   /*:18*/
  624.   pxlinlen = (halfk)(((unsigned long)(mapwidth * bitspsam + 7)) >> 3);
  625.   greypix = mapwidth;
  626.   if (cutgrey) {
  627.     checksum = mapheight;
  628.     pxlinlen = cutlen;
  629.   } else
  630.     checksum = mapheight;
  631.   pl = 0;
  632.   fseek(bitmap, posbit, 0);
  633.   for (pk = 0; pk <= 255; pk++)
  634.     lutsl[pk] = pk << (8 - bitspsam);
  635.   newv = 1;
  636.   countv = 0;
  637.   remlast = false;
  638.   do {
  639.     pxlinlen = fread(b1, 1, pxlinlen, bitmap);
  640.     colpos = 0;
  641.     cutrep = 0;
  642.     gbufpp = (newwidth * bitspsam + 7) / 8;
  643.     memset((Anyptr)b4, invbyte, sizeof(uchar) * 1500L);
  644.     FORLIM = greypix;
  645.     for (pk = 0; pk < FORLIM; pk++)
  646.       b4[pk] = getcolor();
  647.     if (remlast) {
  648.       FORLIM = greypix;
  649.       for (pk = 0; pk < FORLIM; pk++)
  650.     b4[pk] = (b2[pk] * 2 + b4[pk]) / 3;
  651.       remlast = false;
  652.     }
  653.     gbufp = 0;
  654.     cb = 0;
  655. /* p2c: bm2font.pas, line 159:
  656.  * Note: Can't interpret size in FILLCHAR [174] */
  657.     memset((Anyptr)b3, invbyte, (long)gbufpp);
  658.     newh = 1;
  659.     counth = 0;
  660.     pk = 0;
  661.     while (pk < greypix) {   /*19:*/
  662.       cb = lutsl[b4[pk]];
  663.       dbuf = ((unsigned)gbufp) >> 3;
  664.       bufsh = gbufp & 7;
  665.       nextbuf = bufsh + bitspsam;
  666.       switch (bufsh) {
  667.  
  668.       case 0:
  669.     b3[dbuf] = cb;
  670.     break;
  671.  
  672.       default:
  673.     b3[dbuf] ^= cb >> bufsh;
  674.     if (nextbuf > 8)
  675.       b3[dbuf + 1] = cb << (8 - bufsh);
  676.     break;
  677.       }
  678.       gbufp += bitspsam;
  679.       pk++;
  680.       counth++;
  681.       if (counth != (long)floor(newh * scaleh + 0.5))
  682.     continue;
  683.       if (grhor) {
  684.     while (counth >= (long)floor(newh * scaleh + 0.5)) {
  685.       if (pk == greypix)
  686.         cb = lutsl[(b4[pk - 1] * 2 + b4[pk - 2]) / 3];
  687.       else
  688.         cb = lutsl[(b4[pk] * 2 + b4[pk - 1]) / 3];
  689.       dbuf = ((unsigned)gbufp) >> 3;
  690.       bufsh = gbufp & 7;
  691.       nextbuf = bufsh + bitspsam;
  692.       switch (bufsh) {
  693.  
  694.       case 0:
  695.         b3[dbuf] = cb;
  696.         break;
  697.  
  698.       default:
  699.         b3[dbuf] ^= cb >> bufsh;
  700.         if (nextbuf > 8)
  701.           b3[dbuf + 1] = cb << (8 - bufsh);
  702.         break;
  703.       }
  704.       gbufp += bitspsam;
  705.       counth++;
  706.       newh++;
  707.     }
  708.     continue;
  709.       }
  710.       while (counth == (long)floor(newh * scaleh + 0.5)) {
  711.     b4[pk + 1] = (b4[pk + 1] * 2 + b4[pk]) / 3;
  712.     pk++;
  713.     newh++;
  714.     counth++;
  715.       }
  716.     }  /*:19*/
  717.     if (bitspsam == 1) {
  718.       dbuf = ((unsigned)gbufp) >> 3;
  719.       bufsh = gbufp & 7;
  720.       if (dbuf < gbufpp) {
  721.     cb = invbyte;
  722.     b3[dbuf] ^= cb >> bufsh;
  723.       }
  724.     }
  725. /* p2c: bm2font.pas, line 178:
  726.  * Note: Can't interpret size in BLOCKWRITE [174] */
  727.     fwrite(b3, gbufpp, 1, tmpfil);
  728.     checksum--;   /*20:*/
  729.     countv++;
  730.     if (cutgrey)
  731.       pxlinlen = (halfk)(b1[pxlinlen - 1] * 256 + b1[pxlinlen - 2] + 2);
  732.     if (countv == (long)floor(newv * scalev + 0.5)) {   /*:20*/
  733.       if (grver) {
  734.     while (countv >= (long)floor(newv * scalev + 0.5)) {
  735.       fwrite(b3, gbufpp, 1, tmpfil);
  736.       countv++;
  737.       newv++;
  738.     }
  739. /* p2c: bm2font.pas, line 181:
  740.  * Note: Can't interpret size in BLOCKWRITE [174] */
  741.       } else {
  742.     while (countv == (long)floor(newv * scalev + 0.5)) {
  743.       pxlinlen = fread(b1, 1, pxlinlen, bitmap);
  744.       colpos = 0;
  745.       cutrep = 0;
  746.       FORLIM = greypix;
  747.       for (pk = 0; pk < FORLIM; pk++)
  748.         b2[pk] = getcolor();
  749.       remlast = true;
  750.       if (checksum > 0)
  751.         checksum--;
  752.       if (cutgrey)
  753.         pxlinlen = (halfk)(b1[pxlinlen - 1] * 256 + b1[pxlinlen - 2] + 2);
  754.       newv++;
  755.       countv++;
  756.     }
  757. /* p2c: bm2font.pas, line 183:
  758.  * Note: Can't interpret size in BLOCKREAD [174] */
  759.       }
  760.     }
  761.   } while (checksum != 0);
  762. /* p2c: bm2font.pas, line 155:
  763.  * Note: Can't interpret size in BLOCKREAD [174] */
  764.   if (bitmap != NULL)
  765.     fclose(bitmap);
  766.   bitmap = NULL;
  767.   if (tmpfil != NULL)
  768.     fclose(tmpfil);
  769.   tmpfil = NULL;   /*21:*/
  770.   if (giftemp) {   /*:21*/
  771. /* p2c: bm2font.pas, line 193: Note: Called procedure Exec [285] */
  772.     Exec("rm", "giftemp.tmp");
  773.     giftemp = false;
  774.     pcxtemp = true;
  775.   } else {
  776. /* p2c: bm2font.pas, line 193: Note: Called procedure Exec [285] */
  777.     Exec("rm", "pcxtemp.tmp");
  778.     giftemp = true;
  779.     pcxtemp = false;
  780.   }
  781.   strcpy(bitmap_NAME, tmpname);
  782.   if (bitmap != NULL)
  783.     bitmap = freopen(bitmap_NAME, "r+b", bitmap);
  784.   else
  785.     bitmap = fopen(bitmap_NAME, "r+b");
  786.   if (bitmap == NULL)
  787.     _EscIO(FileNotFound);
  788.   posbit = 0;
  789.   cutgrey = false;
  790.   mapheight = newheight;
  791.   mapwidth = newwidth;
  792.   if (bitspsam == 1)
  793.     pxlinlen = (mapwidth + 7) / 8;
  794.   mapheight = P_maxpos(bitmap) / ((mapwidth * bitspsam + 7) / 8);
  795. }  /*:16*/
  796.  
  797.  
  798. /* Local variables for tifint: */
  799. struct LOC_tifint {
  800.   boolean le;
  801.   uchar tb[3000];
  802. } ;
  803.  
  804. /*:22*/
  805. /*23:*/
  806. Local unsigned short tifword(ba, LINK)
  807. unsigned short ba;
  808. struct LOC_tifint *LINK;
  809. {
  810.   if (LINK->le)
  811.     return ((unsigned short)LINK->tb[ba] + (unsigned short)LINK->tb[ba + 1] * 256);
  812.   else
  813.     return ((unsigned short)(LINK->tb[ba] * 256) +
  814.         (unsigned short)LINK->tb[ba + 1]);
  815. }
  816.  
  817. Local long tiflong(ba, LINK)
  818. unsigned short ba;
  819. struct LOC_tifint *LINK;
  820. {
  821.   if (LINK->le)
  822.     return ((long)tifword(ba, LINK) + (long)tifword(ba + 2, LINK) * 65536L);
  823.   else
  824.     return (LINK->tb[ba] * 16777216 + LINK->tb[ba + 1] * 65536 +
  825.         LINK->tb[ba + 2] * 256 + (long)LINK->tb[ba + 3]);
  826. }
  827.  
  828. Local unsigned short tiftwobyte(ba, LINK)
  829. unsigned short ba;
  830. struct LOC_tifint *LINK;
  831. {
  832.   if (LINK->le)
  833.     return ((unsigned short)LINK->tb[ba] + (unsigned short)LINK->tb[ba + 1] * 256);
  834.   else
  835.     return ((unsigned short)(LINK->tb[ba] * 256) +
  836.         (unsigned short)LINK->tb[ba + 1]);
  837. }
  838.  
  839.  
  840. /*22:*/
  841. Static Void tifint()
  842. {   /*:23*/
  843.   struct LOC_tifint V;
  844.   unsigned short i, j, l, m, tl;
  845.   long ll;
  846.   uchar tp;
  847.   boolean strips;
  848.   unsigned short ttype;
  849.   long tiftemp;
  850.   uchar FORLIM1;
  851.  
  852.   /*24:*/
  853.   strips = false;
  854.   tl = fread(V.tb, 1, sizeof(uchar) * 1199, bitmap);
  855.   V.le = (V.tb[1] == 'I');
  856.   ll = tiflong(4, &V);
  857.   if (ll > 900) {
  858.     printf("I can't digest this\n");
  859.     _Escape(0);
  860.   }
  861.   l = ll;
  862.   m = tiftwobyte(l, &V);
  863.   l += 2;
  864.   for (i = 1; i <= m; i++) {
  865.     j = tiftwobyte(l, &V);
  866.     ttype = tiftwobyte(l + 2, &V);
  867.     if (ttype == 3)
  868.       tiftemp = tifword(l + 8, &V);
  869.     else
  870.       tiftemp = tiflong(l + 8, &V);
  871.     switch (j) {
  872.  
  873.     case 256:
  874.       mapwidth = tiftemp;
  875.       break;
  876.  
  877.     case 257:
  878.       mapheight = tiftemp;
  879.       break;
  880.  
  881.     case 258:
  882.       if (tiftemp > 1) {
  883.     greypxl = true;
  884.     bitspsam = tiftemp;
  885.     if (bitspsam > 8) {
  886.       printf("Only up to 256 greyshades supported\n");
  887.       _Escape(0);
  888.     }
  889.     mapdiv = 1.0;
  890.     FORLIM1 = bitspsam;
  891.     for (tp = 1; tp <= FORLIM1; tp++)
  892.       mapdiv *= 2;
  893.     mapdiv /= 16;
  894.       }
  895.       break;
  896.  
  897.     case 259:
  898.       if (tiftemp > 1) {
  899.     printf("No compression supported\n");
  900.     _Escape(0);
  901.       }
  902.       break;
  903.  
  904.     case 262:
  905.       photoinf = tiftemp;
  906.       if (photoinf > 1) {
  907.     printf("No RGB colours supported\n");
  908.     _Escape(0);
  909.       }
  910.       if (photoinf == 0)
  911.     invert = !invert;
  912.       if (invert) {
  913.     invbit = 0;
  914.     invbyte = 0;
  915.       } else {
  916.     invbit = 1;
  917.     invbyte = 255;
  918.       }
  919.       photoinf = 15;
  920.       break;
  921.  
  922.     case 273:
  923.       if (tiflong(l + 4, &V) != 1)
  924.     strips = true;
  925.       posbit = tiftemp;
  926.       break;
  927.  
  928.     case 277:
  929.       if (tiftemp != 1) {
  930.     printf("Only monochrome images supported\n");
  931.     _Escape(0);
  932.       }
  933.       break;
  934.  
  935.     case 278:
  936.       rowspstrip = tiftemp;
  937.       break;
  938.  
  939.     case 290:
  940.       greyunit = 1.0;
  941.       FORLIM1 = tifword(l + 4, &V);
  942.       for (tp = 1; tp <= FORLIM1; tp++)
  943.     greyunit /= 10;
  944.       break;
  945.  
  946.     case 291:
  947.       FORLIM1 = tiflong(l + 4, &V);
  948.       for (tp = 0; tp < FORLIM1; tp++)
  949.     tpal[tp] = V.tb[l + tp + 8];
  950.       break;
  951.     }
  952.     l += 12;
  953.     if (l >= tl) {
  954.       tl = fread(V.tb, 1, sizeof(uchar) * 1199, bitmap);
  955.       l = 0;
  956.     }
  957.   }
  958.   if (!strips)
  959.     return;
  960.   fseek(bitmap, posbit, 0);
  961.   l = fread(V.tb, 1, sizeof(uchar) * 2, bitmap);
  962.   posbit = tiflong(0, &V);
  963. }
  964.  
  965.  
  966. /*:24*/
  967. /*26:*/
  968. Static Void cutint()
  969. {
  970.   long FORLIM;
  971.   short FORLIM1;
  972.  
  973.   pxlinlen = 8;
  974. /* p2c: bm2font.pas, line 228:
  975.  * Note: Can't interpret size in BLOCKREAD [174] */
  976.   pxlinlen = fread(b1, 1, pxlinlen, bitmap);
  977.   if (pxlinlen != 8) {
  978.     printf("CUT file too small!\n");
  979.     _Escape(0);
  980.   }
  981.   mapheight = b1[3] * 256 + b1[2];
  982.   mapwidth = b1[1] * 256 + b1[0];
  983.   photoinf = 15;
  984.   mapdiv = 16.0;
  985.   posbit = 8;
  986.   cutlen = b1[7] * 256 + b1[6] + 2;
  987.   bitspsam = 8;
  988.   cutgrey = true;
  989.   greypxl = true;
  990.   if (!egastretch)
  991.     return;
  992.   mapinlen = mapwidth;
  993.   printf("Shrinking the CUT picture because of odd aspect ratio\n");
  994.   giftemp = true;
  995.   strcpy(tmpname, "giftemp.tmp");
  996.   strcpy(tmpfil_NAME, "giftemp.tmp");
  997.   filestat = P_ioresult;
  998.   if (filestat == 0)
  999.     fok = false;
  1000.   else
  1001.     fok = true;
  1002.   if (fok) {
  1003.     printf("tempfile giftemp.tmp not accessable, abort\n");
  1004.     fileproblem();
  1005.     _Escape(0);
  1006.   }
  1007.   if (tmpfil != NULL)
  1008.     tmpfil = freopen(tmpfil_NAME, "w+b", tmpfil);
  1009.   else
  1010.     tmpfil = fopen(tmpfil_NAME, "w+b");
  1011.   if (tmpfil == NULL)
  1012.     _EscIO(FileNotFound);
  1013.   xratio = 2;
  1014.   posbit = 0;
  1015.   pxlinlen = cutlen;
  1016.   FORLIM = mapheight;
  1017.   for (checksum = 1; checksum <= FORLIM; checksum++) {
  1018.     pxlinlen = fread(b1, 1, pxlinlen, bitmap);
  1019.     colpos = 0;
  1020.     cutrep = 0;
  1021.     FORLIM1 = mapinlen;
  1022.     for (pk = 0; pk < FORLIM1; pk++)
  1023.       b2[pk] = getcolor();
  1024.     posbit++;
  1025.     FORLIM1 = mapinlen;
  1026.     for (gbufp = 0; gbufp < FORLIM1; gbufp++)
  1027.       b3[gbufp] = b2[gbufp];
  1028.     if (posbit < xratio) {
  1029.       _SETIO(fwrite(b2, mapinlen, 1, tmpfil) == 1, FileWriteError);
  1030.       filestat = P_ioresult;
  1031.       if (filestat != 0) {
  1032.     _SETIO(printf("Error occured when writing file %s!\n", tmpname) >= 0,
  1033.            FileWriteError);
  1034.     fileproblem();
  1035.     _Escape(0);
  1036.       }
  1037.     }
  1038. /* p2c: bm2font.pas, line 243:
  1039.  * Note: Can't interpret size in BLOCKWRITE [174] */
  1040.     if (posbit > xratio) {
  1041.       FORLIM1 = mapinlen;
  1042.       for (gbufp = 0; gbufp < FORLIM1; gbufp++)
  1043.     b3[gbufp] = ((unsigned)(b3[gbufp] + b2[gbufp])) >> 1;
  1044. /* p2c: bm2font.pas, line 248:
  1045.  * Note: Can't interpret size in BLOCKWRITE [174] */
  1046.       _SETIO(fwrite(b3, mapinlen, 1, tmpfil) == 1, FileWriteError);
  1047.       filestat = P_ioresult;
  1048.       if (filestat != 0) {
  1049.     _SETIO(printf("Error occured when writing file %s!\n", tmpname) >= 0,
  1050.            FileWriteError);
  1051.     fileproblem();
  1052.     _Escape(0);
  1053.       }
  1054.       posbit = 0;
  1055.       if (xratio == 2)
  1056.     xratio = 3;
  1057.       else
  1058.     xratio = 2;
  1059.     }
  1060.     pxlinlen = (halfk)(b1[pxlinlen - 1] * 256 + b1[pxlinlen - 2] + 2);
  1061.   }
  1062. /* p2c: bm2font.pas, line 240:
  1063.  * Note: Can't interpret size in BLOCKREAD [174] */
  1064.   if (bitmap != NULL)
  1065.     fclose(bitmap);
  1066.   bitmap = NULL;
  1067.   if (tmpfil != NULL)
  1068.     fclose(tmpfil);
  1069.   tmpfil = NULL;
  1070.   strcpy(bitmap_NAME, "giftemp.tmp");
  1071.   if (bitmap != NULL)
  1072.     bitmap = freopen(bitmap_NAME, "r+b", bitmap);
  1073.   else
  1074.     bitmap = fopen(bitmap_NAME, "r+b");
  1075.   if (bitmap == NULL)
  1076.     _EscIO(FileNotFound);
  1077.   cutgrey = false;
  1078.   posbit = 0;
  1079. }
  1080.  
  1081.  
  1082. typedef unsigned short tabcode[4097];
  1083. typedef uchar bytecod[4097];
  1084. typedef uchar ilaced[4];
  1085. typedef uchar ebts_;
  1086.  
  1087.  
  1088. typedef long gifmask[13];
  1089.  
  1090.  
  1091. /* Local variables for gifint: */
  1092. struct LOC_gifint {
  1093.   ilaced ioff, ijump;
  1094.   long lvr, linepos;
  1095.   ebts_ logvr, codesample, modus, gifshift, nextbuf, bufsh;
  1096.   unsigned short maxcode, hh;
  1097.   short ec, ki;
  1098.   unsigned short hell[256];
  1099.   ebts_ gifbuf[3000];
  1100.   unsigned short codepos, gifinlen, gotinlen;
  1101.   long codesav;
  1102.   unsigned short dbuf, linebytes;
  1103. } ;
  1104.  
  1105. /*:27*/
  1106. /*28:*/
  1107. Local uchar getgif(LINK)
  1108. struct LOC_gifint *LINK;
  1109. {
  1110. /* p2c: bm2font.pas, line 266:
  1111.  * Note: Can't interpret size in BLOCKREAD [174] */
  1112.   fread(b1, 1, 1, bitmap);
  1113.   return (b1[0]);
  1114. }
  1115.  
  1116. Local Void gifout(b, LINK)
  1117. unsigned short b;
  1118. struct LOC_gifint *LINK;
  1119. {
  1120.   short i, FORLIM;
  1121.   ebts_ ibits;
  1122.  
  1123.   if (gbufpp < 3000)
  1124.     b2[gbufpp] = LINK->hell[b];
  1125.   gbufpp++;
  1126.   if (gbufpp != LINK->hh)
  1127.     return;
  1128.   LINK->codepos = 0;
  1129. /* p2c: bm2font.pas, line 269:
  1130.  * Note: Can't interpret size in FILLCHAR [174] */
  1131.   memset((Anyptr)LINK->gifbuf, 0, (long)LINK->linebytes);
  1132.   FORLIM = LINK->hh;
  1133.   for (i = 0; i < FORLIM; i++) {
  1134.     LINK->dbuf = LINK->codepos / 8;
  1135.     LINK->bufsh = LINK->codepos & 7;
  1136.     LINK->nextbuf = LINK->bufsh + bitspsam;
  1137.     cb = lutsl[b2[i]];
  1138.     if (LINK->bufsh == 0)
  1139.       LINK->gifbuf[LINK->dbuf] = cb;
  1140.     else {
  1141.       LINK->gifbuf[LINK->dbuf] |= cb >> LINK->bufsh;
  1142.       if (LINK->nextbuf > 8)
  1143.     LINK->gifbuf[LINK->dbuf + 1] = cb << (8 - LINK->bufsh);
  1144.     }
  1145.     LINK->codepos += bitspsam;
  1146.   }
  1147.   if (LINK->modus == 1)
  1148.     fseek(tmpfil, LINK->linepos, 0);
  1149.   if (bitspsam == 1) {
  1150.     i = 8 - (LINK->hh & 7);
  1151.     if (i != 8) {
  1152.       cb = LINK->gifbuf[LINK->dbuf] >> i;
  1153.       cb <<= i;
  1154.       LINK->gifbuf[LINK->dbuf] = cb;
  1155.       cb = invbit;
  1156.       for (ibits = 1; ibits <= i; ibits++) {
  1157.     LINK->gifbuf[LINK->dbuf] ^= cb;
  1158.     cb <<= 1;
  1159.       }
  1160.     }
  1161.   }
  1162. /* p2c: bm2font.pas, line 278:
  1163.  * Note: Can't interpret size in BLOCKWRITE [174] */
  1164.   _SETIO(fwrite(LINK->gifbuf, LINK->linebytes, 1, tmpfil) == 1,
  1165.      FileWriteError);
  1166.   filestat = P_ioresult;
  1167.   if (filestat != 0) {
  1168.     _SETIO(printf("Error occured when writing file %s!\n", tmpname) >= 0,
  1169.        FileWriteError);
  1170.     fileproblem();
  1171.     _Escape(0);
  1172.   }
  1173.   LINK->lvr++;
  1174.   gbufpp = 0;
  1175.   LINK->linepos += LINK->linebytes * LINK->ijump[LINK->logvr];
  1176.   if (LINK->linepos >= P_maxpos(tmpfil)-1) {
  1177.     LINK->logvr++;
  1178.     LINK->linepos = LINK->ioff[LINK->logvr] * LINK->linebytes;
  1179.   }
  1180. }
  1181.  
  1182. Local unsigned short gifcode(LINK)
  1183. struct LOC_gifint *LINK;
  1184. {
  1185.   unsigned short Result;
  1186.  
  1187.   static gifmask codemask = {
  1188.     0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095
  1189.   };
  1190.  
  1191.   long codebyte;
  1192.  
  1193.   while (LINK->gifshift < LINK->codesample) {
  1194.     codebyte = b1[gbufp];
  1195.     gbufp++;
  1196.     if (gbufp == LINK->gifinlen) {
  1197.       LINK->gifinlen = getgif(LINK);
  1198. /* p2c: bm2font.pas, line 290:
  1199.  * Note: Can't interpret size in BLOCKREAD [174] */
  1200.       LINK->gotinlen = fread(b1, 1, LINK->gifinlen, bitmap);
  1201.       gbufp = 0;
  1202.       if (LINK->gifinlen == 0)
  1203.     printf("Code zero, proceeding\n");
  1204.       if (LINK->gotinlen != LINK->gifinlen) {
  1205.     b1[LINK->gotinlen] = LINK->ec;
  1206.     LINK->gifinlen = LINK->gotinlen + 1;
  1207.       }
  1208.     }
  1209.     LINK->codesav |= codebyte << LINK->gifshift;
  1210.     LINK->gifshift += 8;
  1211.   }
  1212.   Result = LINK->codesav & codemask[LINK->codesample];
  1213.   LINK->codesav = ((unsigned long)LINK->codesav) >> LINK->codesample;
  1214.   LINK->gifshift -= LINK->codesample;
  1215.   LINK->ki++;
  1216.   if (LINK->ki > LINK->maxcode && LINK->codesample < 12) {
  1217.     LINK->codesample++;
  1218.     LINK->maxcode = 1 << LINK->codesample;
  1219.   }
  1220.   return Result;
  1221. }
  1222.  
  1223.  
  1224. /*:26*/
  1225. /*27:*/
  1226. Static Void gifint()
  1227. {   /*:28*/
  1228.   struct LOC_gifint V;
  1229.  
  1230.   static ilaced ioff = {
  1231.     0, 4, 2, 1
  1232.   };
  1233.  
  1234.   static ilaced ijump = {
  1235.     8, 8, 4, 2
  1236.   };
  1237.  
  1238.   unsigned short a, g, hi, vi, vh, hr, vr;
  1239.   short merk, ic, codegif, i;
  1240.   ebts_ colmap, b, col, bpp;
  1241.   ebts_ gpal[256][3];
  1242.   unsigned short *codtab;
  1243.   unsigned short folge, minhell, maxhell;
  1244.   uchar *anf;
  1245.   Char hexbyte[7];
  1246.   short FORLIM;
  1247.  
  1248.   /*29:*/
  1249.   memcpy(V.ioff, ioff, sizeof(ilaced));
  1250.   memcpy(V.ijump, ijump, sizeof(ilaced));
  1251.   printf("Decoding GIF file\n");
  1252.   V.logvr = 0;
  1253.   V.codesav = 0;
  1254.   V.lvr = 0;
  1255.   minhell = 9999;
  1256.   maxhell = 0;
  1257.   codtab = (unsigned short *)Malloc(sizeof(tabcode));
  1258.   anf = (uchar *)Malloc(sizeof(bytecod));
  1259.   opentempfile();
  1260.   *hexbyte = '\0';
  1261.   for (i = 1; i <= 3; i++) {
  1262.     sprintf(hexbyte + strlen(hexbyte), "%c", getgif(&V));
  1263. /* p2c: bm2font.pas, line 300:
  1264.  * Note: Possible string truncation in assignment [145] */
  1265.   }
  1266.   if (strcmp(hexbyte, "GIF")) {
  1267.     printf("This file is NOT a gif file!\n");
  1268.     _Escape(0);
  1269.   }
  1270.   for (i = 1; i <= 3; i++) {
  1271.     sprintf(hexbyte + strlen(hexbyte), "%c", getgif(&V));
  1272. /* p2c: bm2font.pas, line 302:
  1273.  * Note: Possible string truncation in assignment [145] */
  1274.   }
  1275.   if (strcmp(hexbyte, "GIF87a") && strcmp(hexbyte, "GIF89a")) {
  1276.     printf("The program only supports version 87a and 89a!\n");
  1277.     _Escape(0);
  1278.   }
  1279.   b = getgif(&V);
  1280.   hr = b;
  1281.   b = getgif(&V);
  1282.   hr += b * 256;
  1283.   b = getgif(&V);
  1284.   vr = b;
  1285.   b = getgif(&V);
  1286.   vr += b * 256;
  1287.   if (hr == 640 && vr == 350) {
  1288.     xratio = 3;
  1289.     yratio = 4;
  1290.   }
  1291.   b = getgif(&V);
  1292.   colmap = b & 128;
  1293.   colmap >>= 7;
  1294.   col = b & 112;
  1295.   col >>= 4;
  1296.   col++;
  1297.   bitspsam = b & 7;
  1298.   bitspsam++;
  1299.   b = getgif(&V);
  1300.   b = getgif(&V);
  1301.   if (colmap == 1) {   /*30:*/
  1302.     g = 1;
  1303.     FORLIM = bitspsam;
  1304.     for (i = 1; i <= FORLIM; i++)
  1305.       g *= 2;
  1306.     for (i = 0; i < g; i++) {
  1307.       for (j = 0; j <= 2; j++)
  1308.     gpal[i][j] = getgif(&V);
  1309.       V.hell[i] = (long)floor(gpal[i][0] * 0.287 + gpal[i][1] * 0.589 + gpal[i]
  1310.                 [2] * 0.114 + 0.5);
  1311.       if (V.hell[i] > maxhell)
  1312.     maxhell = V.hell[i];
  1313.     }
  1314.     for (i = 0; i < g; i++)   /*:30*/
  1315.       V.hell[i] = (long)floor((double)V.hell[i] / maxhell * (g - 1) + 0.5);
  1316.   }
  1317.   b = getgif(&V);
  1318.   if (b != 44) {   /*31:*/
  1319.     while (b != 44) {   /*:31*/
  1320.       b = getgif(&V);
  1321.       switch (b) {
  1322.  
  1323.       case 249:
  1324.     a = getgif(&V);
  1325.     for (g = 0; g <= a; g++)
  1326.       b = getgif(&V);
  1327.     break;
  1328.  
  1329.       case 254:
  1330.     a = getgif(&V);
  1331.     while (a != 0) {
  1332.       for (g = 0; g <= a; g++)
  1333.         b = getgif(&V);
  1334.       a = b;
  1335.       if (P_eof(bitmap)) {
  1336.         printf("file ended while looking for image\n");
  1337.         _Escape(0);
  1338.       }
  1339.     }
  1340.     break;
  1341.  
  1342.       case 1:
  1343.       case 255:
  1344.     a = getgif(&V);
  1345.     for (g = 1; g <= a; g++)
  1346.       b = getgif(&V);
  1347.     a = getgif(&V);
  1348.     while (a != 0) {
  1349.       for (g = 0; g <= a; g++)
  1350.         b = getgif(&V);
  1351.       a = b;
  1352.       if (P_eof(bitmap)) {
  1353.         printf("file ended while looking for image\n");
  1354.         _Escape(0);
  1355.       }
  1356.     }
  1357.     break;
  1358.       }
  1359.       b = getgif(&V);
  1360.       if (P_eof(bitmap)) {
  1361.     printf("file ended while looking for image\n");
  1362.     _Escape(0);
  1363.       }
  1364.     }
  1365.   }
  1366.   b = getgif(&V);
  1367.   hi = b;
  1368.   b = getgif(&V);
  1369.   hi += b * 256;
  1370.   b = getgif(&V);
  1371.   vi = b;
  1372.   b = getgif(&V);
  1373.   vi += b * 256;
  1374.   b = getgif(&V);
  1375.   V.hh = b;
  1376.   b = getgif(&V);
  1377.   V.hh += b * 256;
  1378.   b = getgif(&V);
  1379.   vh = b;
  1380.   b = getgif(&V);
  1381.   vh += b * 256;
  1382.   if (V.hh != hr || vh != vr)
  1383.     printf("No fragments supported!\n");
  1384.   V.linebytes = (V.hh * bitspsam + 7) / 8;
  1385.   if (V.linebytes > 3000) {
  1386.     V.linebytes = 3000;
  1387.     printf("Sorry, had to cut picture to a width of 3000 bytes\n");
  1388.   }
  1389.   b = getgif(&V);
  1390.   col = b & 128;
  1391.   col >>= 7;
  1392.   if (col != 0) {
  1393.     bitspsam = b & 7;
  1394.     bitspsam++;   /*30:*/
  1395.     g = 1;
  1396.     FORLIM = bitspsam;
  1397.     for (i = 1; i <= FORLIM; i++)
  1398.       g *= 2;
  1399.     for (i = 0; i < g; i++) {
  1400.       for (j = 0; j <= 2; j++)
  1401.     gpal[i][j] = getgif(&V);
  1402.       V.hell[i] = (long)floor(gpal[i][0] * 0.287 + gpal[i][1] * 0.589 + gpal[i]
  1403.                 [2] * 0.114 + 0.5);
  1404.       if (V.hell[i] > maxhell)
  1405.     maxhell = V.hell[i];
  1406.     }
  1407.     for (i = 0; i < g; i++)   /*:30*/
  1408.       V.hell[i] = (long)floor((double)V.hell[i] / maxhell * (g - 1) + 0.5);
  1409.   }
  1410.   for (pk = 0; pk <= 255; pk++)
  1411.     lutsl[pk] = pk << (8 - bitspsam);
  1412.   V.modus = b << 1;
  1413.   V.modus >>= 7;
  1414.   if (V.modus == 0)
  1415.     printf("Image is loaded sequentially.\n");
  1416.   else
  1417.     printf("Interlaced mode, loading the image will take more time.\n");
  1418.   if (V.modus != 0) {
  1419.     memset((Anyptr)V.gifbuf, 0, (long)V.linebytes);
  1420.     for (i = 1; i <= vh; i++) {
  1421.       _SETIO(fwrite(V.gifbuf, V.linebytes, 1, tmpfil) == 1, FileWriteError);
  1422.       filestat = P_ioresult;
  1423.       if (filestat != 0) {
  1424.     _SETIO(printf("Error occured when writing file %s!\n", tmpname) >= 0,
  1425.            FileWriteError);
  1426.     fileproblem();
  1427.     _Escape(0);
  1428.       }
  1429.     }
  1430. /* p2c: bm2font.pas, line 342:
  1431.  * Note: Can't interpret size in BLOCKWRITE [174] */
  1432.     V.linepos = 0;
  1433.     V.logvr = 0;
  1434.     fseek(tmpfil, 0L, 0);
  1435.   }
  1436. /* p2c: bm2font.pas, line 341:
  1437.  * Note: Can't interpret size in FILLCHAR [174] */
  1438.   bpp = b << 5;
  1439.   bpp >>= 5;
  1440.   bpp++;
  1441.   bpp = getgif(&V);
  1442.   g = 1 << bpp;
  1443.   ic = 1 << bpp;
  1444.   V.ec = ic + 1;
  1445.   V.codesample = bpp + 1;
  1446.   V.maxcode = 1 << V.codesample;
  1447.   for (i = 0; i <= 4095; i++)
  1448.     codtab[i] = 4098;
  1449.   V.ki = V.ec + 1;
  1450.   a = 4098;
  1451.   gbufpp = 0;
  1452.   V.gifshift = 0;
  1453.   V.gifinlen = getgif(&V);
  1454. /* p2c: bm2font.pas, line 350:
  1455.  * Note: Can't interpret size in BLOCKREAD [174] */
  1456.   fread(b1, V.gifinlen, 1, bitmap);
  1457.   gbufp = 0;
  1458.   if (V.gifinlen == 0)
  1459.     _Escape(0);
  1460.   merk = 0;   /*32:*/
  1461.   while (V.lvr < vh) {   /*:32*/
  1462.     codegif = gifcode(&V);
  1463.     if (codegif == V.ec) {
  1464.       printf("End of code before gif image completed!\n");
  1465.       V.lvr = vh;
  1466.       continue;
  1467.     }
  1468.     if (codegif == ic) {
  1469.       for (i = 0; i <= 4095; i++)
  1470.     codtab[i] = 4098;
  1471.       V.ki = V.ec + 1;
  1472.       V.codesample = bpp + 1;
  1473.       V.maxcode = 1 << V.codesample;
  1474.       a = 4098;
  1475.       continue;
  1476.     }
  1477.     if (codegif < ic)
  1478.       gifout(codegif, &V);
  1479.     else {
  1480.       if (codtab[codegif] == 4098) {
  1481.     if (codegif != V.ki - 2) {
  1482.       printf("Bytes are mangled!\n");
  1483.       _Escape(0);
  1484.     }
  1485.     folge = a;
  1486.     merk++;
  1487.     while (folge > ic)
  1488.       folge = codtab[folge];
  1489.     b3[merk] = folge;
  1490.     anf[V.ki - 2] = folge;
  1491.     folge = a;
  1492.       } else
  1493.     folge = codegif;
  1494.       while (folge > ic && folge <= 4095) {
  1495.     merk++;
  1496.     b3[merk] = anf[folge];
  1497.     folge = codtab[folge];
  1498.       }
  1499.       merk++;
  1500.       b3[merk] = folge;
  1501.       while (merk > 0) {
  1502.     gifout(b3[merk], &V);
  1503.     merk--;
  1504.       }
  1505.     }
  1506.     if (a != 4098) {
  1507.       codtab[V.ki - 2] = a;
  1508.       if (codegif == V.ki - 2) {
  1509.     folge = a;
  1510.     while (folge > ic)
  1511.       folge = codtab[folge];
  1512.     anf[V.ki - 2] = folge;
  1513.       } else {
  1514.     folge = codegif;
  1515.     while (folge > ic)
  1516.       folge = codtab[folge];
  1517.     anf[V.ki - 2] = folge;
  1518.       }
  1519.     }
  1520.     a = codegif;
  1521.   }
  1522.   if (bitmap != NULL)
  1523.     fclose(bitmap);
  1524.   bitmap = NULL;
  1525.   if (tmpfil != NULL)
  1526.     fclose(tmpfil);
  1527.   tmpfil = NULL;
  1528.   if (bitspsam > 1)
  1529.     greypxl = true;
  1530.   mapinlen = V.linebytes;
  1531.   strcpy(bitmap_NAME, "pcxtemp.tmp");
  1532.   if (bitmap != NULL)
  1533.     bitmap = freopen(bitmap_NAME, "r+b", bitmap);
  1534.   else
  1535.     bitmap = fopen(bitmap_NAME, "r+b");
  1536.   if (bitmap == NULL)
  1537.     _EscIO(FileNotFound);
  1538.   pcxtemp = true;
  1539.   if (egastretch) {
  1540.     if (xratio + 1 == yratio)
  1541.       picstretch();
  1542.   }
  1543.   posbit = 0;
  1544.   mapdiv = 1.0;
  1545.   FORLIM = bitspsam;
  1546.   for (i = 1; i <= FORLIM; i++)
  1547.     mapdiv *= 2;
  1548.   mapdiv /= 16;
  1549. }
  1550.  
  1551.  
  1552. /*:29*/
  1553. /*33:*/
  1554. Static uchar getpcx()
  1555. {
  1556.   uchar Result;
  1557.  
  1558.   if (gbufp == pxlinlen) {
  1559.     gbufp = 0;
  1560.     pxlinlen = fread(b1, 1, sizeof(uchar) * 320, bitmap);
  1561.   }
  1562.   Result = b1[gbufp];
  1563.   gbufp++;
  1564.   return Result;
  1565. }
  1566.  
  1567.  
  1568. /*:33*/
  1569. /*34:*/
  1570. Static long longpcx()
  1571. {
  1572.   long bl;
  1573.   ebts pb;
  1574.  
  1575.   pb = getpcx();
  1576.   bl = pb;
  1577.   pb = getpcx();
  1578.   bl += pb * 256;
  1579.   pb = getpcx();
  1580.   bl += pb * 65536;
  1581.   pb = getpcx();
  1582.   bl += pb * 16777216;
  1583.   return bl;
  1584. }
  1585.  
  1586.  
  1587. /*:34*/
  1588. /*35:*/
  1589. Static unsigned short wordpcx()
  1590. {
  1591.   unsigned short bl;
  1592.   ebts pb;
  1593.  
  1594.   pb = getpcx();
  1595.   bl = pb;
  1596.   pb = getpcx();
  1597.   bl += pb * 256;
  1598.   return bl;
  1599. }  /*:35*/
  1600.  
  1601.  
  1602. /*36:*/
  1603. Static Void pcxint()
  1604. {
  1605.   unsigned short i, ki, k, hi, hh, vi, vh, hr, vr, bzf;
  1606.   ebts xb, j, b, a, col, bps, ibits, pcxver, pcxcomp;
  1607.   ebts gpal[256][3];
  1608.   ebts hell[256];
  1609.   unsigned short FORLIM;
  1610.   short FORLIM1;
  1611.  
  1612.   printf("Analysing PCX file %s\n", bmname);
  1613.   gbufp = 640;
  1614.   pxlinlen = 640;
  1615.   b = getpcx();
  1616.   if (b != 10 && b != 205) {
  1617.     printf("What a bad joke!\n");
  1618.     printf("This is NOT a PCX file!\n");
  1619.     _Escape(0);
  1620.   }
  1621.   if (b == 205)
  1622.     printf("First byte 205, file seems to be captured!\n");
  1623.   /*37:*/
  1624.   pcxver = getpcx();
  1625.   pcxcomp = getpcx();
  1626.   bps = getpcx();
  1627.   hi = getpcx();
  1628.   b = getpcx();
  1629.   hi += b * 256;
  1630.   vi = getpcx();
  1631.   b = getpcx();
  1632.   vi += b * 256;
  1633.   hh = getpcx();
  1634.   b = getpcx();
  1635.   hh += b * 256;
  1636.   vh = getpcx();
  1637.   b = getpcx();
  1638.   vh += b * 256;
  1639.   hr = getpcx();
  1640.   b = getpcx();
  1641.   hr += b * 256;
  1642.   vr = getpcx();
  1643.   b = getpcx();
  1644.   vr += b * 256;
  1645.   if (hr == 640 && vr == 350) {
  1646.     xratio = 3;
  1647.     yratio = 4;
  1648.   }
  1649.   if (hr == 320 && vr == 200) {
  1650.     xratio = 5;
  1651.     yratio = 6;
  1652.   }
  1653.   hh += 1 - hi;
  1654.   vh -= vi;
  1655.   mapwidth = hh;
  1656.   for (i = 0; i <= 15; i++) {
  1657.     for (j = 0; j <= 2; j++)
  1658.       gpal[i][j] = getpcx();
  1659.   }
  1660.   b = getpcx();
  1661.   col = getpcx();
  1662.   bzf = getpcx();
  1663.   b = getpcx();
  1664.   bzf += b * 256;
  1665.   hh = bzf;
  1666.   b = getpcx();
  1667.   b = getpcx();
  1668.   for (i = 70; i <= 127; i++)
  1669.     b = getpcx();
  1670.   bitspsam = bps;
  1671.   if (col == 4) {
  1672.     bitspsam = 4;
  1673.     greypxl = true;
  1674.   } else if (bps > 1) {
  1675.     bitspsam = bps;
  1676.     greypxl = true;
  1677.   }
  1678.   mapinlen = ((unsigned long)(mapwidth * bitspsam + 7)) >> 3;   /*:37*/
  1679.   /*38:*/
  1680.   for (i = 0; i <= 15; i++)
  1681.     hell[i] = (long)(gpal[i][0] / 16.0 * 0.287 + gpal[i][1] / 16.0 * 0.589 +
  1682.              gpal[i][2] / 16.0 * 0.114);
  1683.   for (i = 0; i <= 15; i++) {
  1684.     if (hell[i] > 15)
  1685.       hell[i] = 15;
  1686.   }
  1687.   opentempfile();   /*:38*/
  1688.   if (pcxver == 5 && bitspsam > 4) {   /*39:*/
  1689.     gbufp = 640;
  1690.     pxlinlen = 640;
  1691.     posbit = P_maxpos(bitmap);
  1692.     posbit -= 769;
  1693.     fseek(bitmap, posbit, 0);
  1694.     b = getpcx();
  1695.     if (b != 12) {
  1696.       printf("No valid information in 256 colors palette\n");
  1697.       printf("Using standard 16 colors palette\n");
  1698.     } else {
  1699.       for (i = 0; i <= 255; i++) {
  1700.     for (j = 0; j <= 2; j++)
  1701.       gpal[i][j] = getpcx();
  1702.     hell[i] = (long)floor(gpal[i][0] * 0.287 + gpal[i][1] * 0.589 + gpal[i]
  1703.                 [2] * 0.114 + 0.5);
  1704.       }
  1705.     }
  1706.     fseek(bitmap, 128L, 0);
  1707.     gbufp = 640;
  1708.     pxlinlen = 640;
  1709.   }
  1710.   /*:39*/
  1711.   /*40:*/
  1712.   a = 0;
  1713.   for (i = 0; i <= vh; i++) {   /*:40*/
  1714.     FORLIM1 = mapinlen;
  1715.     for (gbufpp = 0; gbufpp < FORLIM1; gbufpp++)
  1716.       b3[gbufpp] = 0;
  1717.     for (j = 0; j < col; j++) {
  1718.       gbufpp = 0;
  1719.       for (k = 1; k <= hh; k++) {
  1720.     if (a == 0) {
  1721.       b = getpcx();
  1722.       if ((b & 0xc0) == 0xc0) {
  1723.         a = (b & 0x3f) - 1;
  1724.         b = getpcx();
  1725.       }
  1726.     } else
  1727.       a--;
  1728.     if (col == 4) {
  1729.       for (ibits = 0; ibits <= 7; ibits++) {
  1730.         ki = gbufpp * 4 + (ibits >> 1);
  1731.         xb = b << ibits;
  1732.         xb >>= 7;
  1733.         xb <<= j;
  1734.         xb <<= (1 - (ibits & 1)) << 2;
  1735.         b3[ki] ^= xb;
  1736.       }
  1737.     } else {
  1738.       b3[gbufpp] = b;
  1739.       if (gbufpp == mapinlen - 1 && bitspsam == 1) {
  1740.         ki = 8 - (mapwidth & 7);
  1741.         if (ki != 8) {
  1742.           xb = b3[gbufpp] >> ki;
  1743.           xb <<= ki;
  1744.           b3[gbufpp] = xb;
  1745.           xb = invbit;
  1746.           for (ibits = 1; ibits <= ki; ibits++) {
  1747.         b3[gbufpp] ^= xb;
  1748.         xb <<= 1;
  1749.           }
  1750.         }
  1751.       }
  1752.     }
  1753.     gbufpp++;
  1754.       }
  1755.     }
  1756.     if (col == 4) {
  1757.       gbufpp = 0;
  1758.       hi = (hh - 1) * 4 + 3;
  1759.       for (k = 0; k <= hi; k++) {
  1760.     b3[gbufpp] = (hell[b3[k] >> 4] << 4) + hell[b3[k] & 15];
  1761.     gbufpp++;
  1762.       }
  1763.     } else if (bps == 8 && pcxver == 5) {
  1764.       hi = hh - 1;
  1765.       for (k = 0; k <= hi; k++)
  1766.     b3[k] = hell[b3[k]];
  1767.       gbufpp = hh;
  1768.     }
  1769. /* p2c: bm2font.pas, line 428:
  1770.  * Note: Can't interpret size in BLOCKWRITE [174] */
  1771.     _SETIO(fwrite(b3, mapinlen, 1, tmpfil) == 1, FileWriteError);
  1772.     filestat = P_ioresult;
  1773.     if (filestat != 0) {
  1774.       _SETIO(printf("Error occured when writing file %s!\n", tmpname) >= 0,
  1775.          FileWriteError);
  1776.       fileproblem();
  1777.       _Escape(0);
  1778.     }
  1779.     if (hr == 640 && vr == 200) {
  1780.       _SETIO(fwrite(b3, mapinlen, 1, tmpfil) == 1, FileWriteError);
  1781.       filestat = P_ioresult;
  1782.       if (filestat != 0) {
  1783.     _SETIO(printf("Error occured when writing file %s!\n", tmpname) >= 0,
  1784.            FileWriteError);
  1785.     fileproblem();
  1786.     _Escape(0);
  1787.       }
  1788.     }
  1789. /* p2c: bm2font.pas, line 431:
  1790.  * Note: Can't interpret size in BLOCKWRITE [174] */
  1791.   }
  1792.   if (bitmap != NULL)
  1793.     fclose(bitmap);
  1794.   bitmap = NULL;
  1795.   if (tmpfil != NULL)
  1796.     fclose(tmpfil);
  1797.   tmpfil = NULL;
  1798.   strcpy(bitmap_NAME, "pcxtemp.tmp");
  1799.   if (bitmap != NULL)
  1800.     bitmap = freopen(bitmap_NAME, "r+b", bitmap);
  1801.   else
  1802.     bitmap = fopen(bitmap_NAME, "r+b");
  1803.   if (bitmap == NULL)
  1804.     _EscIO(FileNotFound);
  1805.   pcxtemp = true;
  1806.   if (egastretch) {
  1807.     if (xratio + 1 == yratio)
  1808.       picstretch();
  1809.   }
  1810.   posbit = 0;
  1811.   mapdiv = 1.0;
  1812.   FORLIM = bitspsam;
  1813.   for (i = 1; i <= FORLIM; i++)
  1814.     mapdiv *= 2;
  1815.   mapdiv /= 16;
  1816. }
  1817.  
  1818.  
  1819. /* Local variables for iffint: */
  1820. struct LOC_iffint {
  1821.   unsigned short hi, hh, vi, vh, compr;
  1822.   uchar a, b, col, bps;
  1823.   uchar gpal[256][3];
  1824.   uchar hell[256];
  1825.   Char bmstr[256];
  1826.   long bmsize, bmoff, bl;
  1827. } ;
  1828.  
  1829. /*:41*/
  1830. /*42:*/
  1831. Local long ifflong(LINK)
  1832. struct LOC_iffint *LINK;
  1833. {
  1834.   ebts k;
  1835.  
  1836.   fread(b1, sizeof(uchar) * 2, 1, bitmap);
  1837.   LINK->bl = b1[0];
  1838.   for (k = 1; k <= 3; k++)
  1839.     LINK->bl = LINK->bl * 256 + b1[k];
  1840.   return LINK->bl;
  1841. }
  1842.  
  1843. /*:42*/
  1844. /*43:*/
  1845. Local unsigned short iffword(LINK)
  1846. struct LOC_iffint *LINK;
  1847. {
  1848.   fread(b1, sizeof(uchar), 1, bitmap);
  1849.   return (b1[0] * 256 + b1[1]);
  1850. }
  1851.  
  1852. /*:43*/
  1853. /*44:*/
  1854. Local Void junkchunk(LINK)
  1855. struct LOC_iffint *LINK;
  1856. {
  1857.   if (LINK->bmsize > P_maxpos(bitmap)) {
  1858.     printf("File endend while reading junk\n");
  1859.     _Escape(0);
  1860.   }
  1861.   while (LINK->bmsize > 0) {
  1862.     fread(&LINK->b, 1, 1, bitmap);
  1863.     LINK->bmsize--;
  1864.   }
  1865. /* p2c: bm2font.pas, line 448:
  1866.  * Note: Can't interpret size in BLOCKREAD [174] */
  1867. }  /*:44*/
  1868.  
  1869. /*45:*/
  1870. Local Void checkchunk(LINK)
  1871. struct LOC_iffint *LINK;
  1872. {
  1873.   short i, j, FORLIM;
  1874.  
  1875.   if (!strcmp(LINK->bmstr, "BMHD")) {
  1876.     LINK->bmsize = ifflong(LINK);
  1877.     if (LINK->bmsize & 1)
  1878.       LINK->bmsize++;
  1879.     LINK->hh = iffword(LINK);
  1880.     LINK->vh = iffword(LINK);
  1881.     LINK->hi = iffword(LINK);
  1882.     LINK->vi = iffword(LINK);
  1883. /* p2c: bm2font.pas, line 452:
  1884.  * Note: Can't interpret size in BLOCKREAD [174] */
  1885.     fread(&LINK->bps, 1, 1, bitmap);
  1886. /* p2c: bm2font.pas, line 452:
  1887.  * Note: Can't interpret size in BLOCKREAD [174] */
  1888.     fread(&LINK->b, 1, 1, bitmap);
  1889. /* p2c: bm2font.pas, line 453:
  1890.  * Note: Can't interpret size in BLOCKREAD [174] */
  1891.     fread(&LINK->b, 1, 1, bitmap);
  1892.     LINK->compr = LINK->b;
  1893.     for (i = 1; i <= 4; i++)
  1894.       fread(&xratio, 1, 1, bitmap);
  1895. /* p2c: bm2font.pas, line 454:
  1896.  * Note: Can't interpret size in BLOCKREAD [174] */
  1897. /* p2c: bm2font.pas, line 454:
  1898.  * Note: Can't interpret size in BLOCKREAD [174] */
  1899.     fread(&yratio, 1, 1, bitmap);
  1900.     LINK->bmsize -= 16;
  1901.     junkchunk(LINK);
  1902.     if (LINK->bps == 1) {
  1903.       LINK->col = 1;
  1904.       return;
  1905.     }
  1906.     if (LINK->bps == 4)
  1907.       LINK->col = 15;
  1908.     else
  1909.       LINK->col = 255;
  1910.     return;
  1911.   }
  1912.   if (!strcmp(LINK->bmstr, "CMAP")) {
  1913.     LINK->bmsize = ifflong(LINK);
  1914.     LINK->col = LINK->bmsize / 3 - 1;
  1915.     FORLIM = LINK->col;
  1916.     for (i = 0; i <= FORLIM; i++) {
  1917.       for (j = 0; j <= 2; j++) {
  1918.     fread(&LINK->b, 1, 1, bitmap);
  1919.     LINK->gpal[i][j] = LINK->b;
  1920.       }
  1921. /* p2c: bm2font.pas, line 458:
  1922.  * Note: Can't interpret size in BLOCKREAD [174] */
  1923.       LINK->hell[i] = (long)floor(LINK->gpal[i][0] * 0.287 + LINK->gpal[i]
  1924.                     [1] * 0.589 + LINK->gpal[i][2] * 0.114 + 0.5);
  1925.     }
  1926.     if (LINK->bmsize & 1)
  1927.       fread(&LINK->b, 1, 1, bitmap);
  1928. /* p2c: bm2font.pas, line 461:
  1929.  * Note: Can't interpret size in BLOCKREAD [174] */
  1930.     return;
  1931.   }
  1932.   if (!strcmp(LINK->bmstr, "CRNG")) {
  1933.     LINK->bmsize = ifflong(LINK);
  1934.     LINK->bmoff = iffword(LINK);
  1935.     LINK->bmoff = iffword(LINK);
  1936.     LINK->bmoff = iffword(LINK);
  1937. /* p2c: bm2font.pas, line 463:
  1938.  * Note: Can't interpret size in BLOCKREAD [174] */
  1939.     fread(&LINK->b, 1, 1, bitmap);
  1940. /* p2c: bm2font.pas, line 464:
  1941.  * Note: Can't interpret size in BLOCKREAD [174] */
  1942.     fread(&LINK->a, 1, 1, bitmap);
  1943.     if (LINK->bps == 4) {
  1944.       if (LINK->b < LINK->a) {
  1945.     FORLIM = LINK->a;
  1946.     for (i = LINK->b; i <= FORLIM; i++)
  1947.       LINK->hell[i] = i;
  1948.       } else if (LINK->b > LINK->a) {
  1949.     FORLIM = LINK->b;
  1950.     for (i = LINK->a; i <= FORLIM; i++)
  1951.       LINK->hell[i] = i;
  1952.       }
  1953.     }
  1954.     if (LINK->bmsize & 1)
  1955.       fread(&LINK->b, 1, 1, bitmap);
  1956. /* p2c: bm2font.pas, line 466:
  1957.  * Note: Can't interpret size in BLOCKREAD [174] */
  1958.     return;
  1959.   }
  1960.   LINK->bmsize = ifflong(LINK);
  1961.   if (LINK->bmsize & 1)
  1962.     LINK->bmsize++;
  1963.   junkchunk(LINK);
  1964. }
  1965.  
  1966.  
  1967. /*:36*/
  1968. /*41:*/
  1969. Static Void iffint()
  1970. {   /*:45*/
  1971.   struct LOC_iffint V;
  1972.   unsigned short ohh;
  1973.   uchar cb;
  1974.   short FORLIM, FORLIM1;
  1975.  
  1976.   /*46:*/
  1977.   printf("Analysing IFF file %s\n", bmname);
  1978.   opentempfile();
  1979.   fread(V.bmstr, 4, 1, bitmap);
  1980.   V.bmstr[4] = '\0';
  1981.   if (strcmp(V.bmstr, "FORM")) {
  1982.     printf("Graphic file not stored as Interchange File Format\n");
  1983.     _Escape(0);
  1984.   }
  1985.   V.bmsize = ifflong(&V) + 8;
  1986.   if (V.bmsize != P_maxpos(bitmap)) {
  1987.     printf("File is incomplete, should contain %ld\n", V.bmsize);
  1988.     _Escape(0);
  1989.   }
  1990.   fread(V.bmstr, 4, 1, bitmap);
  1991.   V.bmstr[4] = '\0';
  1992.   if (strcmp(V.bmstr, "ILBM"))
  1993.     printf("Type of file is %s, should be ILBM\n", V.bmstr);
  1994.   fread(V.bmstr, 4, 1, bitmap);
  1995.   V.bmstr[4] = '\0';
  1996.   while (strcmp(V.bmstr, "BODY")) {
  1997.     if (P_eof(bitmap)) {
  1998.       printf("No graphics information available\n");
  1999.       _Escape(0);
  2000.     }
  2001.     checkchunk(&V);
  2002.     fread(V.bmstr, 4, 1, bitmap);
  2003.     V.bmstr[4] = '\0';
  2004.   }
  2005.   V.bmsize = ifflong(&V);
  2006.   V.hh = (V.hh * V.bps + 7) / 8;
  2007.   ohh = V.hh;
  2008.   if (ohh & 1)
  2009.     ohh++;
  2010.   FORLIM = V.vh;
  2011.   for (i = 1; i <= FORLIM; i++) {
  2012.     if (P_eof(bitmap)) {
  2013.       printf("ende\n");
  2014.       _Escape(0);
  2015.     }
  2016.     if (V.compr == 0)
  2017.       fread(b3, ohh, 1, bitmap);
  2018.     else {   /*47:*/
  2019.       gbufp = 0;
  2020.       while (gbufp < ohh) {
  2021.     fread(&V.b, 1, 1, bitmap);
  2022.     V.bmoff++;
  2023.     if (V.b < 128) {
  2024.       V.b++;
  2025. /* p2c: bm2font.pas, line 484:
  2026.  * Note: Can't interpret size in BLOCKREAD [174] */
  2027.       fread(&b3[gbufp], V.b, 1, bitmap);
  2028.       gbufp += V.b;
  2029.       continue;
  2030.     }
  2031.     if (V.b <= 128)
  2032.       continue;
  2033. /* p2c: bm2font.pas, line 485:
  2034.  * Note: Can't interpret size in BLOCKREAD [174] */
  2035.     fread(&V.a, 1, 1, bitmap);
  2036.     V.b = 257 - V.b;
  2037.     while (V.b > 0) {
  2038.       b3[gbufp] = V.a;
  2039.       gbufp++;
  2040.       V.b--;
  2041.     }
  2042.       }
  2043. /* p2c: bm2font.pas, line 483:
  2044.  * Note: Can't interpret size in BLOCKREAD [174] */
  2045.     }  /*:47*/
  2046. /* p2c: bm2font.pas, line 482:
  2047.  * Note: Can't interpret size in BLOCKREAD [174] */
  2048.     if (V.bps == 4) {   /*48:*/
  2049.       gi = 0;
  2050.       FORLIM1 = V.hh;
  2051.       for (gbufpp = 0; gbufpp < FORLIM1; gbufpp++)
  2052.     b2[gbufpp] = 0;
  2053.       V.a = 0;
  2054.       FORLIM1 = V.hh;
  2055.       for (gbufpp = 0; gbufpp < FORLIM1; gbufpp++) {
  2056.     V.b = b3[gbufpp];
  2057.     for (j = 0; j <= 3; j++) {
  2058.       cb = V.b & 128;
  2059.       cb >>= V.a;
  2060.       b2[gi] ^= cb;
  2061.       V.b <<= 1;
  2062.       cb = V.b & 128;
  2063.       cb >>= V.a + 4;
  2064.       b2[gi] ^= cb;
  2065.       V.b <<= 1;
  2066.       gi++;
  2067.     }
  2068.     if (gi >= V.hh) {
  2069.       gi = 0;
  2070.       V.a++;
  2071.     }
  2072.       }
  2073.       FORLIM1 = V.hh;
  2074.       for (gbufpp = 0; gbufpp < FORLIM1; gbufpp++)
  2075.     b3[gbufpp] = b2[gbufpp];
  2076.       gi = 0;
  2077.       FORLIM1 = V.hh;
  2078.       for (gbufpp = 0; gbufpp < FORLIM1; gbufpp++) {
  2079.     b2[gi] = (V.hell[b3[gbufpp] >> 4] << 4) + V.hell[b3[gbufpp] & 15];
  2080.     gi++;
  2081.       }  /*:48*/
  2082.     } else if (V.bps == 8) {
  2083.       FORLIM1 = V.hh;
  2084.       for (gbufp = 0; gbufp < FORLIM1; gbufp++)
  2085.     b2[gbufp] = V.hell[b3[gbufp]];
  2086.     } else {
  2087.       FORLIM1 = V.hh;
  2088.       for (gbufp = 0; gbufp < FORLIM1; gbufp++)
  2089.     b2[gbufp] = b3[gbufp];
  2090.     }
  2091. /* p2c: bm2font.pas, line 497:
  2092.  * Note: Can't interpret size in BLOCKWRITE [174] */
  2093.     _SETIO(fwrite(b2, V.hh, 1, tmpfil) == 1, FileWriteError);
  2094.     filestat = P_ioresult;
  2095.     if (filestat != 0) {
  2096.       _SETIO(printf("Error occured when writing file %s!\n", tmpname) >= 0,
  2097.          FileWriteError);
  2098.       fileproblem();
  2099.       _Escape(0);
  2100.     }
  2101.   }
  2102.   if (bitmap != NULL)
  2103.     fclose(bitmap);
  2104.   bitmap = NULL;
  2105.   if (tmpfil != NULL)
  2106.     fclose(tmpfil);
  2107.   tmpfil = NULL;
  2108.   mapinlen = V.hh;
  2109.   bitspsam = V.bps;
  2110.   posbit = 0;
  2111.   strcpy(bitmap_NAME, "pcxtemp.tmp");
  2112.   if (bitmap != NULL)
  2113.     bitmap = freopen(bitmap_NAME, "r+b", bitmap);
  2114.   else
  2115.     bitmap = fopen(bitmap_NAME, "r+b");
  2116.   if (bitmap == NULL)
  2117.     _EscIO(FileNotFound);
  2118.   pcxtemp = true;
  2119.   if (egastretch) {
  2120.     if (xratio + 1 == yratio)
  2121.       picstretch();
  2122.   }
  2123.   posbit = 0;
  2124.   if (bitspsam > 1)
  2125.     greypxl = true;
  2126.   mapdiv = 1.0;
  2127.   FORLIM = bitspsam;
  2128.   for (i = 1; i <= FORLIM; i++)
  2129.     mapdiv *= 2;
  2130.   mapdiv /= 16;
  2131. }  /*:46*/
  2132.  
  2133.  
  2134. /*49:*/
  2135. Static Void bmpint()
  2136. {
  2137.   unsigned short i, k, hi, hh, hhl, vi, vh, compr, lcol;
  2138.   uchar j, b, a, col, bps;
  2139.   uchar gpal[256][4];
  2140.   uchar hell[256];
  2141.   Char bmstr[256];
  2142.   long bmsize, bmoff;
  2143.   unsigned short FORLIM;
  2144.  
  2145.   printf("Analysing BMP file %s\n", bmname);
  2146.   opentempfile();
  2147.   fread(bmstr, 2, 1, bitmap);
  2148.   bmstr[2] = '\0';
  2149.   if (strcmp(bmstr, "BM")) {
  2150.     printf("No windows bitmap %s\n", bmstr);
  2151.     _Escape(0);
  2152.   }
  2153.   gbufp = 640;
  2154.   pxlinlen = 640;
  2155.   bmsize = longpcx();
  2156.   for (i = 1; i <= 4; i++)
  2157.     b = getpcx();
  2158.   bmoff = longpcx();
  2159.   bmsize = longpcx();
  2160.   bmoff -= bmsize;
  2161.   if (bmsize > 12) {
  2162.     hi = longpcx();
  2163.     vi = longpcx();
  2164.     b = getpcx();
  2165.     b = getpcx();
  2166.     bps = wordpcx();
  2167.     if (bps > 8) {
  2168.       printf("only up to 256 colors supported\n");
  2169.       _Escape(0);
  2170.     }
  2171.     hh = hi;
  2172.     vh = vi;
  2173.     compr = longpcx();
  2174.     for (i = 1; i <= 4; i++)
  2175.       b = getpcx();
  2176.     xratio = longpcx();
  2177.     yratio = longpcx();
  2178.     lcol = longpcx();
  2179.     lcol--;
  2180.     if (col == 0) {
  2181.       if (bps == 1)
  2182.     col = 1;
  2183.       else if (bps == 4)
  2184.     col = 15;
  2185.       else
  2186.     col = 255;
  2187.     }
  2188.     col = longpcx();
  2189.     col--;
  2190.   } else {
  2191.     hi = wordpcx();
  2192.     vi = wordpcx();
  2193.     b = getpcx();
  2194.     b = getpcx();
  2195.     bps = wordpcx();
  2196.     if (bps > 8) {
  2197.       printf("only up to 256 colors supported\n");
  2198.       _Escape(0);
  2199.     }
  2200.     hh = hi;
  2201.     vh = vi;
  2202.     compr = 0;
  2203.     xratio = 1;
  2204.     yratio = 1;
  2205.     col = 0;
  2206.   }
  2207.   if (lcol == 0) {
  2208.     if (bps == 1)
  2209.       col = 1;
  2210.     else if (bps == 4)
  2211.       col = 15;
  2212.     else
  2213.       col = 255;
  2214.   }
  2215.   if (bps == 1)
  2216.     col = 1;
  2217.   else if (bps == 4)
  2218.     col = 15;
  2219.   else
  2220.     col = 255;
  2221.   for (i = 0; i <= col; i++) {
  2222.     if (bmsize > 12) {
  2223.       for (j = 0; j <= 3; j++)
  2224.     gpal[i][j] = getpcx();
  2225.     } else {
  2226.       for (j = 0; j <= 2; j++)
  2227.     gpal[i][j] = getpcx();
  2228.     }
  2229.     hell[i] = (long)((gpal[i][0] * 0.287 + gpal[i][1] * 0.589 + gpal[i]
  2230.             [2] * 0.114) / (256.0 / (col + 1)));
  2231.   }
  2232.   if (bmsize > 12)
  2233.     bmoff -= (col + 1) * 4;
  2234.   else
  2235.     bmoff -= (col + 1) * 3;
  2236.   if (compr != 0) {
  2237.     printf("compression not supported yet\n");
  2238.     _Escape(0);
  2239.   }
  2240.   hh = (hh * bps + 7) / 8;
  2241.   hhl = (hh + 3) / 4 * 4 - 1;
  2242.   a = 8 - ((hi * bps) & 7);
  2243. /* p2c: bm2font.pas, line 532:
  2244.  * Note: Suspicious mixture of sizes in FILLCHAR [173] */
  2245.   memset((Anyptr)b3, 0, hhl + 1L);
  2246.   for (i = 1; i <= vh; i++) {  /*$I-*/
  2247.     _SETIO(fwrite(b3, hh, 1, tmpfil) == 1, FileWriteError);
  2248.     filestat = P_ioresult;
  2249.     if (filestat != 0) {
  2250.       _SETIO(printf("Error occured when writing file %s!\n", tmpname) >= 0,
  2251.          FileWriteError);
  2252.       fileproblem();
  2253.       _Escape(0);
  2254.     }
  2255.   }
  2256. /* p2c: bm2font.pas, line 533:
  2257.  * Note: Can't interpret size in BLOCKWRITE [174] */
  2258.   if (tmpfil != NULL)
  2259.     fclose(tmpfil);
  2260.   tmpfil = NULL;
  2261.   if (tmpfil != NULL)
  2262.     tmpfil = freopen(tmpfil_NAME, "w+b", tmpfil);
  2263.   else
  2264.     tmpfil = fopen(tmpfil_NAME, "w+b");
  2265.   if (tmpfil == NULL)
  2266.     _EscIO(FileNotFound);
  2267.   bmoff = (vh - 1) * (long)hh;
  2268.   for (i = 0; i < vh; i++) {
  2269.     for (k = 0; k <= hhl; k++)
  2270.       b3[k] = getpcx();
  2271.     if (bps == 4) {
  2272.       gi = 0;
  2273.       for (k = 0; k < hh; k++) {
  2274.     b2[gi] = (hell[b3[k] / 16] << 4) + hell[b3[k] & 15];
  2275.     gi++;
  2276.       }
  2277.     } else if (bps == 8) {
  2278.       for (k = 0; k < hh; k++)
  2279.     b2[k] = hell[b3[k]];
  2280.     } else {
  2281.       for (k = 0; k < hh; k++)
  2282.     b2[k] = b3[k];
  2283.     }
  2284.     if (a < 8) {
  2285.       for (k = 0; k < a; k++)
  2286.     b2[hh - 1] ^= invbit >> k;
  2287.     }
  2288.     fseek(tmpfil, bmoff, 0);
  2289.     bmoff = bmoff - (long)hh;
  2290. /* p2c: bm2font.pas, line 545:
  2291.  * Note: Can't interpret size in BLOCKWRITE [174] */
  2292.     _SETIO(fwrite(b2, hh, 1, tmpfil) == 1, FileWriteError);
  2293.     filestat = P_ioresult;
  2294.     if (filestat != 0) {
  2295.       _SETIO(printf("Error occured when writing file %s!\n", tmpname) >= 0,
  2296.          FileWriteError);
  2297.       fileproblem();
  2298.       _Escape(0);
  2299.     }
  2300.   }
  2301.   if (bitmap != NULL)
  2302.     fclose(bitmap);
  2303.   bitmap = NULL;
  2304.   if (tmpfil != NULL)
  2305.     fclose(tmpfil);
  2306.   tmpfil = NULL;
  2307.   mapinlen = hh;
  2308.   posbit = 0;
  2309.   strcpy(bitmap_NAME, "pcxtemp.tmp");
  2310.   if (bitmap != NULL)
  2311.     bitmap = freopen(bitmap_NAME, "r+b", bitmap);
  2312.   else
  2313.     bitmap = fopen(bitmap_NAME, "r+b");
  2314.   if (bitmap == NULL)
  2315.     _EscIO(FileNotFound);
  2316.   pcxtemp = true;
  2317.   bitspsam = bps;
  2318.   if (bitspsam > 1)
  2319.     greypxl = true;
  2320.   mapdiv = 1.0;
  2321.   FORLIM = bitspsam;
  2322.   for (i = 1; i <= FORLIM; i++)
  2323.     mapdiv *= 2;
  2324.   mapdiv /= 16;
  2325. }
  2326.  
  2327.  
  2328. /*50:*/
  2329. Static Void imgint()
  2330. {
  2331.   unsigned short i, ki, hi, hh, bzf, imgpat;
  2332.   short vh;
  2333.   uchar mi, cb, j, b, a, col, bps;
  2334.   uchar hell[16];
  2335.   uchar linerep;
  2336.   unsigned short FORLIM;
  2337.  
  2338.   printf("Analysing IMG file %s\n", bmname);
  2339.   invert = !invert;
  2340.   if (invert) {   /*51:*/
  2341.     invbit = 0;
  2342.     invbyte = 0;
  2343.   } else {
  2344.     invbit = 1;
  2345.     invbyte = 255;
  2346.   }
  2347.   hell[0] = 0;
  2348.   hell[1] = 1;
  2349.   hell[2] = 6;
  2350.   hell[3] = 8;
  2351.   hell[4] = 3;
  2352.   hell[5] = 2;
  2353.   hell[6] = 7;
  2354.   hell[7] = 11;
  2355.   hell[8] = 4;
  2356.   hell[9] = 5;
  2357.   hell[10] = 12;
  2358.   hell[11] = 13;
  2359.   hell[12] = 10;
  2360.   hell[13] = 9;
  2361.   hell[14] = 14;
  2362.   hell[15] = 15;
  2363.   opentempfile();   /*:51*/
  2364.   gbufp = 640;
  2365.   pxlinlen = 640;
  2366.   a = getpcx();
  2367.   b = getpcx();
  2368.   if (a * 256 + b != 1) {   /*52:*/
  2369.     printf("File does not contain GEM Image File Format\n");
  2370.     _Escape(0);
  2371.   }
  2372.   b = getpcx();
  2373.   bzf = b * 256;
  2374.   b = getpcx();
  2375.   bzf += b;
  2376.   b = getpcx();
  2377.   bps = b * 256;
  2378.   b = getpcx();
  2379.   bps += b;
  2380.   b = getpcx();
  2381.   imgpat = b * 256;
  2382.   b = getpcx();
  2383.   imgpat += b;
  2384.   b = getpcx();
  2385.   xratio = b * 256;
  2386.   b = getpcx();
  2387.   xratio += b;
  2388.   b = getpcx();
  2389.   yratio = b * 256;
  2390.   b = getpcx();
  2391.   yratio += b;
  2392.   if (xratio != yratio) {
  2393.     mapdiv = (double)yratio / xratio;
  2394.     xratio = 0;
  2395.     yratio = 0;
  2396.     while (xratio == yratio) {
  2397.       xratio++;
  2398.       yratio = (long)floor(xratio * mapdiv + 0.5);
  2399.     }
  2400.   }
  2401.   b = getpcx();
  2402.   hi = b * 256;
  2403.   b = getpcx();
  2404.   hi += b;
  2405.   b = getpcx();
  2406.   vh = b * 256;
  2407.   b = getpcx();
  2408.   vh += b;   /*:52*/
  2409.   hh = (hi * bps + 7) / 8;
  2410.   if (bzf > 8) {
  2411.     for (i = 1; i <= (bzf - 8) * 2; i++)
  2412.       b = getpcx();
  2413.   }
  2414.   linerep = 0;
  2415.   gi = 0;
  2416.   while (vh > 0) {
  2417.     for (gi = 0; gi <= hh; gi++)
  2418.       b3[gi] = 0;
  2419.     gi = 0;
  2420.     while (gi < hh) {
  2421.       b = getpcx();
  2422.       if (b != 0 && b != 128) {
  2423.     a = b & 127;
  2424.     cb = ((unsigned)(b - a)) >> 7;
  2425.     if (cb == 1)
  2426.       cb = 255;
  2427.     for (ki = 1; ki <= a; ki++) {
  2428.       b3[gi] = cb;
  2429.       gi++;
  2430.     }
  2431.     continue;
  2432.       }
  2433.       if (b == 128) {
  2434.     a = getpcx();
  2435.     for (ki = 1; ki <= a; ki++) {
  2436.       b3[gi] = getpcx();
  2437.       gi++;
  2438.     }
  2439.     continue;
  2440.       }
  2441.       a = getpcx();
  2442.       if (a <= 0) {
  2443.     b = getpcx();
  2444.     linerep = getpcx();
  2445.     continue;
  2446.       }
  2447.       for (ki = 1; ki <= imgpat; ki++)
  2448.     b2[ki] = getpcx();
  2449.       for (ki = 1; ki <= a; ki++) {
  2450.     for (mi = 1; mi <= imgpat; mi++) {
  2451.       b = b2[mi];
  2452.       b3[gi] = b;
  2453.       gi++;
  2454.     }
  2455.       }
  2456.     }
  2457.     if (bps == 4) {   /*48:*/
  2458.       gi = 0;
  2459.       for (gbufpp = 0; gbufpp < hh; gbufpp++)
  2460.     b2[gbufpp] = 0;
  2461.       a = 0;
  2462.       for (gbufpp = 0; gbufpp < hh; gbufpp++) {
  2463.     b = b3[gbufpp];
  2464.     for (j = 0; j <= 3; j++) {
  2465.       cb = b & 128;
  2466.       cb >>= a;
  2467.       b2[gi] ^= cb;
  2468.       b <<= 1;
  2469.       cb = b & 128;
  2470.       cb >>= a + 4;
  2471.       b2[gi] ^= cb;
  2472.       b <<= 1;
  2473.       gi++;
  2474.     }
  2475.     if (gi >= hh) {
  2476.       gi = 0;
  2477.       a++;
  2478.     }
  2479.       }
  2480.       for (gbufpp = 0; gbufpp < hh; gbufpp++)
  2481.     b3[gbufpp] = b2[gbufpp];
  2482.       gi = 0;
  2483.       for (gbufpp = 0; gbufpp < hh; gbufpp++) {
  2484.     b2[gi] = (hell[b3[gbufpp] >> 4] << 4) + hell[b3[gbufpp] & 15];
  2485.     gi++;
  2486.       }  /*:48*/
  2487.     } else {
  2488.       for (ki = 0; ki < hh; ki++)
  2489.     b2[ki] = b3[ki];
  2490.     }
  2491. /* p2c: bm2font.pas, line 590:
  2492.  * Note: Can't interpret size in BLOCKWRITE [174] */
  2493.     _SETIO(fwrite(b2, hh, 1, tmpfil) == 1, FileWriteError);
  2494.     filestat = P_ioresult;
  2495.     if (filestat != 0) {
  2496.       _SETIO(printf("Error occured when writing file %s!\n", tmpname) >= 0,
  2497.          FileWriteError);
  2498.       fileproblem();
  2499.       _Escape(0);
  2500.     }
  2501.     vh--;
  2502.     if (linerep <= 0)
  2503.       continue;
  2504.     for (i = 1; i <= linerep; i++) {  /*$I-*/
  2505.       _SETIO(fwrite(b2, hh, 1, tmpfil) == 1, FileWriteError);
  2506.       filestat = P_ioresult;
  2507.       if (filestat != 0) {
  2508.     _SETIO(printf("Error occured when writing file %s!\n", tmpname) >= 0,
  2509.            FileWriteError);
  2510.     fileproblem();
  2511.     _Escape(0);
  2512.       }
  2513.     }
  2514. /* p2c: bm2font.pas, line 594:
  2515.  * Note: Can't interpret size in BLOCKWRITE [174] */
  2516.     vh += 1 - linerep;
  2517.     linerep = 0;
  2518.   }
  2519.   if (bitmap != NULL)
  2520.     fclose(bitmap);
  2521.   bitmap = NULL;
  2522.   if (tmpfil != NULL)
  2523.     fclose(tmpfil);
  2524.   tmpfil = NULL;
  2525.   if (col == 4) {
  2526.     bitspsam = 4;
  2527.     greypxl = true;
  2528.   } else if (bps > 1) {
  2529.     bitspsam = bps;
  2530.     greypxl = true;
  2531.   }
  2532.   mapinlen = hh;
  2533.   posbit = 0;
  2534.   strcpy(bitmap_NAME, "pcxtemp.tmp");
  2535.   if (bitmap != NULL)
  2536.     bitmap = freopen(bitmap_NAME, "r+b", bitmap);
  2537.   else
  2538.     bitmap = fopen(bitmap_NAME, "r+b");
  2539.   if (bitmap == NULL)
  2540.     _EscIO(FileNotFound);
  2541.   if (egastretch) {
  2542.     if (xratio + 1 == yratio)
  2543.       picstretch();
  2544.   }
  2545.   posbit = 0;
  2546.   pcxtemp = true;
  2547.   mapdiv = 1.0;
  2548.   FORLIM = bitspsam;
  2549.   for (i = 1; i <= FORLIM; i++)
  2550.     mapdiv *= 2;
  2551.   mapdiv /= 16;
  2552. }
  2553.  
  2554.  
  2555. /*54:*/
  2556. Static Void tfmhword(hword)
  2557. long hword;
  2558. {
  2559.   union {
  2560.     uchar b[4];
  2561.     long i;
  2562.   } ax;
  2563.   short i;
  2564.  
  2565.   ax.i = hword;
  2566. #ifdef INTEL
  2567.   for (i = 1; i >= 0; i--)
  2568.     fwrite(&ax.b[i], sizeof(uchar), 1, tfmfile);
  2569. #else
  2570.   for (i = 2; i <= 3; i++)
  2571.     fwrite(&ax.b[i], sizeof(uchar), 1, tfmfile);
  2572. #endif
  2573. }
  2574.  
  2575.  
  2576. Static Void tfmword(lword)
  2577. long lword;
  2578. {
  2579.   union {
  2580.     uchar b[4];
  2581.     long i;
  2582.   } ax;
  2583.   short i;
  2584.  
  2585.   ax.i = lword;
  2586. #ifdef INTEL
  2587.   for (i = 3; i >= 0; i--)
  2588.     fwrite(&ax.b[i], sizeof(uchar), 1, tfmfile);
  2589. #else
  2590.   for (i = 0; i <= 3; i++)
  2591.     fwrite(&ax.b[i], sizeof(uchar), 1, tfmfile);
  2592. #endif
  2593. }
  2594.  
  2595.  
  2596. /*:54*/
  2597. /*57:*/
  2598. Static Void pxlmap(lword)
  2599. long lword;
  2600. {
  2601.   union {
  2602.     ebts b[4];
  2603.     long i;
  2604.   } ax;
  2605.   uchar i;
  2606.  
  2607.   ax.i = lword;
  2608.   for (i = 0; i <= 3; i++) {
  2609.     pxlbm[pxlbmi] = ax.b[i];
  2610.     pxlbmi++;
  2611.   }
  2612. }  /*:57*/
  2613.  
  2614.  
  2615. /*61:*/
  2616. Static Void pkbyte(b)
  2617. uchar b;
  2618. {
  2619.   pkbm[pkloc] = b;
  2620.   pkloc++;
  2621. }
  2622.  
  2623.  
  2624. Static Void pkhalfword(a)
  2625. short a;
  2626. {
  2627.   union {
  2628.     ebts b[2];
  2629.     short w;
  2630.   } ax;
  2631.  
  2632.   ax.w = a;
  2633. #ifdef INTEL
  2634.   pkbyte(ax.b[1]);
  2635.   pkbyte(ax.b[0]);
  2636. #else
  2637.   pkbyte(ax.b[0]);
  2638.   pkbyte(ax.b[1]);
  2639. #endif
  2640. }
  2641.  
  2642.  
  2643. Static Void pkthreebytes(a)
  2644. long a;
  2645. {
  2646.   union {
  2647.     ebts b[4];
  2648.     long i;
  2649.   } ax;
  2650.  
  2651.   ax.i = a;
  2652. #ifdef INTEL
  2653.   pkbyte(ax.b[2]);
  2654.   pkbyte(ax.b[1]);
  2655.   pkbyte(ax.b[0]);
  2656. #else
  2657.   pkbyte(ax.b[1]);
  2658.   pkbyte(ax.b[2]);
  2659.   pkbyte(ax.b[3]);
  2660. #endif
  2661. }
  2662.  
  2663.  
  2664. Static Void pkword(a)
  2665. long a;
  2666. {
  2667.   union {
  2668.     ebts b[4];
  2669.     long i;
  2670.   } ax;
  2671.  
  2672.   ax.i = a;
  2673. #ifdef INTEL
  2674.   pkbyte(ax.b[3]);
  2675.   pkbyte(ax.b[2]);
  2676.   pkbyte(ax.b[1]);
  2677.   pkbyte(ax.b[0]);
  2678. #else
  2679.   pkbyte(ax.b[0]);
  2680.   pkbyte(ax.b[1]);
  2681.   pkbyte(ax.b[2]);
  2682.   pkbyte(ax.b[3]);
  2683. #endif
  2684. }
  2685.  
  2686.  
  2687. Static Void pknyb(a)
  2688. uchar a;
  2689. {
  2690.   if (bitweight == 16) {
  2691.     outputbyte = a << 4;
  2692.     bitweight = 1;
  2693.   } else {
  2694.     pkbyte(outputbyte + a);
  2695.     bitweight = 16;
  2696.   }
  2697. }
  2698.  
  2699.  
  2700. /*:61*/
  2701. /*63:*/
  2702. Static Void writepreambl()
  2703. {
  2704.   short i;
  2705.   Char nstr[256];
  2706.  
  2707.   sprintf(nstr, "%ld", (long)floor(truehres + 0.5));
  2708.   sprintf(cmd, "%s%c.%spk", font, fontpre[nf], nstr);
  2709.   strcpy(pxlfile_NAME, cmd);
  2710.   if (pxlfile != NULL)
  2711.     pxlfile = freopen(pxlfile_NAME, "w+b", pxlfile);
  2712.   else
  2713.     pxlfile = fopen(pxlfile_NAME, "w+b");
  2714.   _SETIO(pxlfile != NULL, FileNotFound);
  2715.   filestat = P_ioresult;
  2716.   if (filestat == 3 || filestat == 5) {
  2717.     strcpy(cmd, bmname);
  2718.     sprintf(cmd + strlen(cmd), "%c.pk", fontupc[nf]);
  2719.     strcpy(pxlfile_NAME, cmd);
  2720.     if (pxlfile != NULL)
  2721.       pxlfile = freopen(pxlfile_NAME, "w+b", pxlfile);
  2722.     else
  2723.       pxlfile = fopen(pxlfile_NAME, "w+b");
  2724.     _SETIO(pxlfile != NULL, FileNotFound);
  2725.     filestat = P_ioresult;
  2726.   }
  2727.   if (filestat == 0)
  2728.     fok = false;
  2729.   else
  2730.     fok = true;
  2731.   if (fok) {
  2732.     printf("error occurred when ");
  2733.     printf("allocating pkfile ");
  2734.     puts(cmd);
  2735.     fileproblem();
  2736.     _Escape(0);
  2737.   }
  2738.   pkloc = 0;
  2739.   pkbyte(247);
  2740.   pkbyte(89);
  2741.   pkbyte(14);
  2742.   strcpy(comment, "BM2FONT output");
  2743.   for (i = 0; i <= 13; i++)
  2744.     pkbyte(comment[i]);
  2745.   pkword(tabdsize[nf]);
  2746.   pkword(checksum);
  2747.   pkword(floor(truehres * 65536L / 72.27 + 0.5));
  2748.   pkword(floor(truevres * 65536L / 72.27 + 0.5));
  2749.   nextmemfree = 0;
  2750.   printf("Packing font %s\n", cmd);
  2751. }
  2752.  
  2753.  
  2754. /*:63*/
  2755. /*65:*/
  2756. Static Void writepostamb()
  2757. {
  2758.   pkbyte(245);
  2759.   while ((pkloc & 3) != 0)
  2760.     pkbyte(246);
  2761. /* p2c: bm2font.pas, line 697:
  2762.  * Note: Can't interpret size in BLOCKWRITE [174] */
  2763.   _SETIO(fwrite(pkbm, pkloc, 1, pxlfile) == 1, FileWriteError);
  2764.   filestat = P_ioresult;
  2765.   if (filestat != 0) {
  2766.     _SETIO(printf("Error occured when writing font %s!\n", cmd) >= 0,
  2767.        FileWriteError);
  2768.     fileproblem();
  2769.     _Escape(0);
  2770.   }
  2771.   if (pxlfile != NULL)
  2772.     fclose(pxlfile);
  2773.   pxlfile = NULL;
  2774.   printf(" \n");
  2775.   printf("Font %s at %ld dots per inch written\n",
  2776.      cmd, (long)floor(truehres + 0.5));
  2777.   nf++;
  2778.   charpf[nf] = ng;
  2779.   ng = 0;
  2780.   pkloc = 0;
  2781. }
  2782.  
  2783.  
  2784. /*:65*/
  2785. /*67:*/
  2786. Static boolean equal(row1, row2)
  2787. pxlstr row1, row2;
  2788. {
  2789.   short i;
  2790.   boolean temp;
  2791.  
  2792.   i = pkwidth;
  2793.   temp = true;
  2794.   while (i > 0 && temp) {
  2795.     if (pxlbm[row1] != pxlbm[row2])
  2796.       temp = false;
  2797.     row1++;
  2798.     row2++;
  2799.     i -= 8;
  2800.   }
  2801.   return temp;
  2802. }
  2803.  
  2804.  
  2805. /*:67*/
  2806. /*68:*/
  2807. Static boolean equalzo(row1, row2)
  2808. pxlstr row1;
  2809. short row2;
  2810. {
  2811.   short i;
  2812.   boolean temp;
  2813.  
  2814.   i = pkwidth;
  2815.   temp = true;
  2816.   while (i > 0 && temp) {
  2817.     if (pxlbm[row1] != (repbm[row2] & 255))
  2818.       temp = false;
  2819.     row1++;
  2820.     row2++;
  2821.     i -= 8;
  2822.   }
  2823.   return temp;
  2824. }
  2825.  
  2826.  
  2827. /*:68*/
  2828. /*70:*/
  2829. Static Void shipcharacte()
  2830. {   /*:87*/
  2831.   pxlstr crst;
  2832.   short wwid;
  2833.   long compsize;
  2834.   unsigned short horesc;
  2835.   /*72:*/
  2836.   short l;
  2837.   long i, j, k;
  2838.   short rowzero, onesrow, repptr, bitcounts;
  2839.   ebts fillbytes, longind, mixbyte, restbyte, pkshift, dshift;
  2840.   long longtab[20];
  2841.   /*:72*/
  2842.   /*77:*/
  2843.   long count;
  2844.   short test, curptr, bit, repflag; 
  2845.   schar pkkword; 
  2846.   short bitptr, bitmod32, currepeat;
  2847.   pxlstr endraster;   /*:77*/
  2848.   /*80:*/
  2849.   short dynf;
  2850.   long deriv[13];
  2851.   long bcompsize;
  2852.   boolean firston;
  2853.   short flagbyte;
  2854.   /*:80*/
  2855.   /*87:*/
  2856.   unsigned short max2;
  2857.   pxlstr predpkloc;
  2858.   short bytelength;
  2859.  
  2860.   horesc = pwidth[f][car];
  2861.   pkwidth = pwidth[f][car];
  2862.   pkheight = pheight[f][car];
  2863.   pkheight -= yoffset[f][car];
  2864.   cxoff = 0;
  2865.   cyoff = pkheight;
  2866.   crst = pkpoint[car];
  2867.   wwid = (pkwidth + 31) / 32 * 4;
  2868.   fillbytes = wwid - (pkwidth + 7) / 8;   /*71:*/
  2869.   rowzero = nextmemfree;
  2870.   onesrow = nextmemfree + wwid;
  2871.   repptr = onesrow + wwid;
  2872.   bitcounts = repptr + pkheight + 1;
  2873.   for (i = rowzero; i < onesrow; i++)
  2874.     repbm[i] = 0;
  2875.   for (i = onesrow; i <= repptr - 2; i++)
  2876.     repbm[i] = -1;
  2877.   j = onesrow + (((unsigned long)(pkwidth + 7)) >> 3);
  2878.   repbm[j - 1] = power[8] - power[7 - ((pkwidth + 7) & 7)];
  2879.   for (i = j; i < repptr; i++)
  2880.     repbm[i] = 0;
  2881.   i = 0;
  2882.   j = pkheight;
  2883.   while (i < j) {
  2884.     if (equalzo((i * wwid + crst), rowzero))
  2885.       repbm[repptr + i] = 0;
  2886.     else if (equalzo((i * wwid + crst), onesrow))
  2887.       repbm[repptr + i] = 0;
  2888.     else if (i + 1 == j)
  2889.       repbm[repptr + i] = 0;
  2890.     else if (equal((i * wwid + crst), ((i + 1) * wwid + crst)))
  2891.       repbm[repptr + i] = 1;
  2892.     else
  2893.       repbm[repptr + i] = 0;
  2894.     i++;
  2895.   }
  2896.   i = 0;
  2897.   while (i < j) {
  2898.     k = i;
  2899.     while (repbm[repptr + k] == 1)
  2900.       k++;
  2901.     repbm[repptr + i] = k - i;
  2902.     i = k + 1;
  2903.   }
  2904.   repbm[repptr + i] = 0;   /*:71*/
  2905.   /*75:*/
  2906.   repflag = 0;
  2907.   bitptr = pkwidth - 1;
  2908.   currepeat = repptr;
  2909.   endraster = crst + pkheight * wwid;
  2910.   curptr = bitcounts;
  2911.   count = 0;
  2912.   longind = 0;
  2913.   test = 0;
  2914.   do {   /*76:*/
  2915.     bitptr++;
  2916.     if (bitptr == pkwidth) {
  2917.       bitmod32 = 0;
  2918.       bitptr = 0;
  2919.       if (currepeat > repptr)
  2920.     crst += fillbytes;
  2921.       if (repbm[currepeat] > 0) {
  2922.     repflag = repbm[currepeat];
  2923.     currepeat += repflag;
  2924.     crst += wwid * repflag;
  2925.       }
  2926.       currepeat++;
  2927.     }
  2928.     bitmod32--;
  2929.     if (bitmod32 == -1) {
  2930.       bitmod32 = 7;
  2931.       pkkword = pxlbm[crst];
  2932.       crst++;
  2933.     }
  2934.     if (crst > endraster)
  2935.       bit = 2;
  2936.     else if (pkkword < 0)
  2937.       bit = 1;
  2938.     else
  2939.       bit = 0;
  2940.     pkkword <<= 1;   /*:76*/
  2941.     if (bit == test)
  2942.       count++;
  2943.     else {
  2944.       if (count > 32767) {
  2945.     longind++;
  2946.     longtab[longind - 1] = count;
  2947.     count = -longind - 10000;
  2948.       }
  2949.       repbm[curptr] = count;
  2950.       curptr++;
  2951.       if (curptr + 1 > maxmemsize)
  2952.     test = 3;
  2953.       else {
  2954.     count = 1;
  2955.     test = bit;
  2956.     if (repflag > 0) {
  2957.       repbm[curptr] = -repflag;
  2958.       repflag = 0;
  2959.       curptr++;
  2960.     }
  2961.       }
  2962.     }
  2963.   } while (test < 2);
  2964.   repbm[curptr] = 0;
  2965.   repbm[curptr + 1] = 0;   /*:75*/
  2966.   /*78:*/
  2967.   if (test < 3) {
  2968.     for (i = 0; i <= 12; i++)
  2969.       deriv[i] = 0;
  2970.     firston = (repbm[bitcounts] == 0);
  2971.     if (firston)
  2972.       bitcounts++;
  2973.     i = bitcounts;
  2974.     compsize = 0;
  2975.     while (repbm[i] != 0) {   /*79:*/
  2976.       j = repbm[i];
  2977.       if (j < -10000)
  2978.     j = longtab[-j - 10001];
  2979.       if (j == -1)
  2980.     compsize++;
  2981.       else {
  2982.     if (j < 0) {
  2983.       compsize++;
  2984.       j = -j;
  2985.     }
  2986.     if (j < 209)
  2987.       compsize += 2;
  2988.     else {
  2989.       k = j - 193;
  2990.       while (k >= 16) {
  2991.         k = ((unsigned long)k) >> 4;
  2992.         compsize += 2;
  2993.       }
  2994.       compsize++;
  2995.     }
  2996.     if (j < 14)
  2997.       deriv[j - 1]--;
  2998.     else if (j < 209)
  2999.       deriv[(223 - j) / 15 - 1]++;
  3000.     else {
  3001.       k = 16;
  3002.       while (k <= ((unsigned long)(j + 2)) >> 4) {
  3003.         k <<= 4;
  3004.         if (k == 0) {
  3005.           k = 32767;
  3006.           j += 32767;
  3007.         }
  3008.       }
  3009.       if (j - k <= 192)
  3010.         deriv[(k - j + 207) / 15 - 1] += 2;
  3011.     }
  3012.       }
  3013.       i++;
  3014.     }
  3015.     /*:79*/
  3016.     bcompsize = compsize;
  3017.     dynf = 0;
  3018.     for (i = 1; i <= 13; i++) {
  3019.       compsize += deriv[i - 1];
  3020.       if (compsize <= bcompsize) {
  3021.     bcompsize = compsize;
  3022.     dynf = i;
  3023.       }
  3024.     }
  3025.     compsize = (bcompsize + 1) / 2;
  3026.     if (compsize > (pkheight * pkwidth + 7) / 8 || pkheight * pkwidth == 0) {
  3027.       compsize = (pkheight * pkwidth + 7) / 8;
  3028.       dynf = 14;
  3029.     }
  3030.   } else {
  3031.     dynf = 14;
  3032.     firston = (repbm[bitcounts] == 0);
  3033.     compsize = (pkheight * pkwidth + 7) / 8;
  3034.   }
  3035.   if (pkloc + compsize > 65487L || ng > 127) {   /*81:*/
  3036.     writepostamb();
  3037.     if (nf > 26) {
  3038.       printf("Sorry, more than 26 fonts necessary, reduce bitmap\n");
  3039.       _Escape(0);
  3040.     }
  3041.     writepreambl();
  3042.   }
  3043.   flagbyte = dynf * 16;
  3044.   if (firston)
  3045.     flagbyte += 8;
  3046.   if (width[f][car] > 16777215L || width[f][car] < 0 || horesc < 0 ||
  3047.       compsize > 196594L || pkwidth > 65535L || pkheight > 65535L ||
  3048.       cxoff > 32767 || cyoff > 32767 || cxoff < -32768L || cyoff < -32768L)
  3049.   {   /*82:*/
  3050.     flagbyte += 7;
  3051.     pkbyte(flagbyte);
  3052.     compsize += 28;
  3053.     pkword(compsize);
  3054.     pkword(ng);
  3055.     predpkloc = pkloc + compsize;
  3056.     pkword(width[f][car]);
  3057.     pkword(horesc);
  3058.     pkword(0);
  3059.     pkword(pkwidth);
  3060.     pkword(pkheight);
  3061.     pkword(cxoff);
  3062.     pkword(cyoff);
  3063.   }  /*:82*/
  3064.   else if (horesc > 255 || pkwidth > 255 || pkheight > 255 || cxoff > 127 ||
  3065.        cyoff > 127 || cxoff < -128 || cyoff < -128 || compsize > 1015) {
  3066.     compsize += 13;
  3067.     flagbyte += compsize / 65536L + 4;
  3068.     pkbyte(flagbyte);
  3069. /* p2c: bm2font.pas, line 789:
  3070.  * Note: Using % for possibly-negative arguments [317] */
  3071.     pkhalfword((compsize % 65536));
  3072.     pkbyte(ng);
  3073.     predpkloc = pkloc + compsize;
  3074.     pkthreebytes(width[f][car]);
  3075.     pkhalfword(horesc);
  3076.     pkhalfword(pkwidth);
  3077.     pkhalfword(pkheight);
  3078.     pkhalfword(cxoff);
  3079.     pkhalfword(cyoff);
  3080.   } else {
  3081.     compsize += 8;
  3082.     flagbyte += compsize / 256;
  3083.     pkbyte(flagbyte);
  3084.     pkbyte((compsize & 255));
  3085.     pkbyte(ng);
  3086.     predpkloc = pkloc + compsize;
  3087.     pkthreebytes(width[f][car]);
  3088.     pkbyte(horesc & 255);
  3089.     pkbyte(pkwidth);
  3090.     pkbyte(pkheight);
  3091.     pkbyte(cxoff);
  3092.     pkbyte(cyoff);
  3093.   }
  3094.   if (dynf != 14) {   /*85:*/
  3095.     bitweight = 16;
  3096.     max2 = 208 - dynf * 15;
  3097.     i = bitcounts;
  3098.     while (repbm[i] != 0) {
  3099.       j = repbm[i];
  3100.       if (j < -10000)
  3101.     j = longtab[-j - 10001];
  3102.       if (j == -1)
  3103.     pknyb(15);
  3104.       else {
  3105.     if (j < 0) {
  3106.       pknyb(14);
  3107.       j = -j;
  3108.     }
  3109.     if (j <= dynf)
  3110.       pknyb(j);
  3111.     else if (j <= max2) {
  3112.       j += -dynf - 1;
  3113.       pknyb(((j) >> 4) + dynf + 1);
  3114.       pknyb((j & 15));
  3115.     } else {
  3116.       j += 15 - max2;
  3117.       k = 1;
  3118.       while (k <= ((unsigned long)j) >> 4) {
  3119.         k <<= 4;
  3120.         pknyb(0);
  3121.       }
  3122.       while (k > 0) {
  3123.         pknyb((j / k));
  3124.         j %= k;
  3125. /* p2c: bm2font.pas, line 804:
  3126.  * Note: Using % for possibly-negative arguments [317] */
  3127.         k = ((unsigned long)k) >> 4;
  3128.       }
  3129.     }
  3130.       }
  3131.       i++;
  3132.     }
  3133.     if (bitweight != 16)
  3134.       pkbyte(outputbyte);
  3135.   } else  /*86:*/
  3136.   {   /*:86*/
  3137.     crst = pkpoint[car];
  3138.     bytelength = (((unsigned long)(pkwidth + 7)) >> 3) - 1;
  3139.     if ((pkwidth & 7) == 0) {
  3140.       while (crst < endraster) {
  3141.     for (i = 0; i <= bytelength; i++)
  3142.       pkbyte(pxlbm[crst + i]);
  3143.     crst += wwid;
  3144.       }
  3145.     } else {
  3146.       pkshift = 0;
  3147.       dshift = pkwidth & 7;
  3148.       while (crst < endraster) {
  3149.     if (pkshift == 0) {
  3150.       for (i = 0; i < bytelength; i++)
  3151.         pkbyte(pxlbm[crst + i]);
  3152.       mixbyte = pxlbm[crst + bytelength];
  3153.     } else {
  3154.       i = crst;
  3155.       l = pkwidth + pkshift;
  3156.       while (l >= 8) {
  3157.         l -= 8;
  3158.         restbyte = pxlbm[i];
  3159.         i++;
  3160.         pkbyte(mixbyte + (restbyte >> pkshift));
  3161.         mixbyte = restbyte << (8 - pkshift);
  3162.       }
  3163.       if (pkshift < ((pkshift + dshift) & 7))
  3164.         mixbyte += pxlbm[i] >> pkshift;
  3165.     }
  3166.     crst += wwid;
  3167.     pkshift = (pkshift + dshift) & 7;
  3168.       }
  3169.       if (pkshift > 0)
  3170.     pkbyte(mixbyte);
  3171.     }
  3172.   }
  3173.   /*:85*/
  3174.   if (predpkloc != pkloc) {
  3175.     printf("Bad predicted character length: character %d\n", car);
  3176.     printf("pred: %uloc: %u\n", predpkloc, pkloc);
  3177.     _Escape(0);
  3178.   }
  3179.   pkpoint[car] = 0;   /*:78*/
  3180.   putchar('.');
  3181.   if (car == 79)
  3182.     putchar('\n');
  3183.   pwidth[nf][ng] = pwidth[f][car];
  3184.   pheight[nf][ng] = pheight[f][car];
  3185.   width[nf][ng] = width[f][car];
  3186.   height[nf][ng] = height[f][car];
  3187.   yoffset[nf][ng] = yoffset[f][car];
  3188.   ng++;
  3189.   /*:83*/
  3190.   /*:81*/
  3191. }
  3192.  
  3193.  
  3194. /*:70*/
  3195. /*88:*/
  3196. Static Void fonteject()
  3197. {
  3198.   short FORLIM, FORLIM1, FORLIM2;
  3199.  
  3200.   nf = 0;
  3201.   ng = 0;
  3202.   writepreambl();
  3203.   while (maplines > 0) {
  3204.     FORLIM = maxx;
  3205.     for (k = 1; k <= FORLIM; k++) {
  3206.       i = k - 1;
  3207.       dirpoint[g] = pxlbmi / 4;
  3208.       pkpoint[g] = pxlbmi;
  3209.       linepos_ = posbit + i * hres / 8;
  3210.       pxlinlen = (pwidth[f][g] + 7) / 8;
  3211.       zeroline = true;
  3212.       gi = 0;
  3213.       FORLIM1 = pheight[f][g];
  3214.       for (v = 1; v <= FORLIM1; v++) {
  3215.     fseek(bitmap, linepos_, 0);
  3216. /* p2c: bm2font.pas, line 831:
  3217.  * Note: Can't interpret size in BLOCKREAD [174] */
  3218.     j = fread(b1, 1, pxlinlen, bitmap);
  3219.     FORLIM2 = pxlinlen;
  3220.     for (lx = 0; lx < FORLIM2; lx++)
  3221.       b2[lx] = b1[lx];
  3222.     if (invert) {
  3223.       FORLIM2 = pxlinlen;
  3224.       for (lx = 0; lx < FORLIM2; lx++)
  3225.         b2[lx] = 255 - b1[lx];
  3226.     }
  3227.     gi += dv;
  3228.     if (gi >= lv)
  3229.       gi -= cv;
  3230.     if (invbyte == 255) {
  3231.       FORLIM2 = pxlinlen;
  3232.       for (lx = 0; lx < FORLIM2; lx++)
  3233.         b1[lx] = invbyte - b1[lx];
  3234.     }
  3235.     lx = 0;
  3236.     zerorow = true;
  3237.     FORLIM2 = pxlinlen;
  3238.     for (j = 0; j < FORLIM2; j++) {
  3239.       if (b1[j] != 0) {
  3240.         zerorow = false;
  3241.         zeroline = false;
  3242.       }
  3243.     }
  3244.     if (zeroline) {
  3245.       yoffset[f][g]++;
  3246.       if (yoffset[f][g] == pheight[f][g]) {
  3247.         yoffset[f][g]--;
  3248.         zerorow = false;
  3249.         zeroline = false;
  3250.       }
  3251.     }
  3252.     cx.i = 0;
  3253.     if (!zeroline) {
  3254.       FORLIM2 = pxlinlen;
  3255.       for (j = 0; j < FORLIM2; j++) {
  3256.         if (lx > 3) {
  3257.           lx = 0;
  3258.           pxlmap(cx.i);
  3259.           cx.i = 0;
  3260.         }
  3261.         cx.b[lx] = b1[j];
  3262.         lx++;
  3263.       }
  3264.       pxlmap(cx.i);
  3265.     }
  3266.     linepos_ += (mapwidth + 7) / 8 + zeropads;
  3267.       }
  3268.       i += maxx;
  3269.       g++;
  3270.       if (g == mincharpf) {   /*89:*/
  3271.     for (car = 0; car <= 127; car++) {
  3272.       if (pkpoint[car] != 0)
  3273.         shipcharacte();
  3274.     }
  3275.     f++;
  3276.     g = 0;
  3277.     pxlbmi = 4;
  3278.       }
  3279.       /*:89*/
  3280.     }
  3281.     maplines -= vres;
  3282.     posbit += vres * ((mapwidth + 7) / 8 + zeropads);
  3283.   }
  3284.   if (bitmap != NULL)
  3285.     fclose(bitmap);
  3286.   bitmap = NULL;   /*90:*/
  3287.   for (car = 0; car <= 127; car++) {
  3288.     if (pkpoint[car] != 0)
  3289.       shipcharacte();
  3290.   }
  3291.   writepostamb();
  3292.   noffonts = nf;   /*:90*/
  3293. }
  3294.  
  3295.  
  3296. /*:88*/
  3297. /*103:*/
  3298. main(argc, argv)
  3299. int argc;
  3300. Char *argv[];
  3301. {
  3302.   short FORLIM;
  3303.   Char STR2[256];
  3304.   uchar FORLIM1;
  3305.   short FORLIM2, FORLIM3;
  3306.   uchar FORLIM4;
  3307.  
  3308.   PASCAL_MAIN(argc, argv);
  3309.   tfmfile = NULL;
  3310.   tmpfil = NULL;
  3311.   pxlfile = NULL;
  3312.   bitmap = NULL;
  3313.   texfile = NULL;
  3314.   power[0] = 1;
  3315.   for (i = 1; i <= 8; i++)
  3316.     power[i] = power[i - 1] * 2;
  3317.   pxlbm = (uchar *)Malloc(sizeof(pxla));
  3318.   pkbm = (uchar *)Malloc(sizeof(pxla));
  3319.   repbm = (short *)Malloc(sizeof(pxlba));
  3320.   gkorh = (short *)Malloc(sizeof(korbyte));
  3321.   gkordivp = (short *)Malloc(sizeof(korbyte));
  3322.   spreadvals = (short *)Malloc(sizeof(spreadbyte));
  3323.   width = (long(*)[129])Malloc(sizeof(dynlong));
  3324.   height = (long(*)[129])Malloc(sizeof(dynlong));
  3325.   yoffset = (unsigned short(*)[129])Malloc(sizeof(dynword));
  3326.   pwidth = (unsigned short(*)[129])Malloc(sizeof(dynword));
  3327.   pheight = (unsigned short(*)[129])Malloc(sizeof(dynword));
  3328.   greymem = (uchar *)Malloc(sizeof(pxla));   /*104:*/
  3329.   strcpy(cref, "!()+,-./0123456789:;<=>?");
  3330.   strcat(cref, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  3331. /* p2c: bm2font.pas, line 855:
  3332.  * Note: Possible string truncation in assignment [145] */
  3333.   strcat(cref, "abcdefghijklmnopqrstuvwxyz");
  3334. /* p2c: bm2font.pas, line 856:
  3335.  * Note: Possible string truncation in assignment [145] */
  3336.   strcpy(fontupc, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  3337.   strcpy(fontpre, "abcdefghijklmnopqrstuvwxyz");
  3338.   truehres = 0.0;
  3339.   truevres = 0.0;
  3340.   halfinch = false;
  3341.   invert = false;
  3342.   greypxl = false;
  3343.   pcxtemp = false;
  3344.   giftemp = false;
  3345.   cutgrey = false;
  3346.   aliasused = false;
  3347.   xratio = 0;
  3348.   yratio = 0;
  3349.   egastretch = true;
  3350.   ledprinter = false;
  3351.   distribute = true;
  3352.   brightness = 0;
  3353.   bitspsam = 8;
  3354.   nowhite = true;
  3355.   usepxl = 0;
  3356.   vusepxl = 0;
  3357.   hrep = 1;
  3358.   vrep = 1;
  3359.   valinc = 70.0;
  3360.   gradint = 70;
  3361.   newwidth = 0;
  3362.   newheight = 0;
  3363.   printf("This is BitMapTOfont, version 2.0 of january 93, via p2c\n");
  3364.   printf("Converting Bitmap Files to TeX-Fonts\n");
  3365.   /*assign(logfile,'test.log');rewrite(logfile);close(logfile);*/
  3366.   /*107:*/
  3367.   if (P_argc == 1) {
  3368.     printf("usage is BM2FONT filename and parameters\n");
  3369.     printf("-f<name of picture for TeX>     (std filename)\n");
  3370.     printf("-h<horizontal resolution>       (pixel/inch, std 300)\n");
  3371.     printf("-v<vertical resolution>         (pixel/inch, std 300)\n");
  3372.     printf("-l<length of mapline>           (in bytes, only pure bitmaps)\n");
  3373.     printf("-p<height of character 1 inch>  (y or n, std y)\n");
  3374.     printf("-e<stretch EGA pictures>        (y or n, std y)\n");
  3375.     printf("-i<inversion of pixels>         (y or n, std n)\n");
  3376.     printf("-g<greypixels in bitmap>        (y or n, std n)\n");
  3377.     printf("-w<let white be light grey>     (y or n, std y)\n");
  3378.     printf("-d<distribute errors>           (y or n, std y)\n");
  3379.     printf("-s<separation of grey dots>     (y or n, std n)\n");
  3380.     printf("-r<repeat each grey pixel>      (y or n, std n)\n");
  3381.     printf("-u<pixels for grey rectangle>   (less 8)\n");
  3382.     printf("-c<vert. pixels for rectangle>  (less 8)\n");
  3383.     printf("-x<bits per sample>             (0 < x < 9)\n");
  3384.     printf("-b<reduce halftone colors>      (f.e. by 1, less u*c*4, std 0)\n");
  3385.     printf("-t<gradation value>             (in %%, std 70)\n");
  3386.     printf("-z<area of gradation>           (in %%, std 70)\n");
  3387.     printf("-m<width of picture on paper>   (in mm)\n");
  3388.     printf("-n<height of picture on paper>  (in mm)\n");
  3389.     /*readln(comment);
  3390. if length(comment)=0 then goto 9999;j:=ord(comment[0])+1;
  3391. if j<=127 then move(comment[0],mem[prefixseg:$80],j);*/
  3392.     goto _L9999;
  3393.   }
  3394.   /*:107*/
  3395.   /*108:*/
  3396.   for (j = 1; j < P_argc; j++) {
  3397.     strcpy(comment, P_argv[j]);
  3398.     if (comment[0] != '-') {
  3399.       strcpy(font, comment);
  3400.       if (strlen(font) < 1 || !strcmp(font, " ")) {
  3401.     printf("give the name of your bitmap file next time\n");
  3402.     goto _L9999;
  3403.       }
  3404.     } else {
  3405.       switch (comment[1]) {
  3406.  
  3407.       case 'h':
  3408.       case 'H':
  3409.     strdelete((Anyptr)comment, 1, 2);
  3410.     i = (sscanf(comment, "%lg", &truehres) == 0);
  3411.     break;
  3412.  
  3413.       case 'v':
  3414.       case 'V':
  3415.     strdelete((Anyptr)comment, 1, 2);
  3416.     i = (sscanf(comment, "%lg", &truevres) == 0);
  3417.     break;
  3418.  
  3419.       case 'l':
  3420.       case 'L':
  3421.     strdelete((Anyptr)comment, 1, 2);
  3422.     i = (sscanf(comment, "%ld", &mapinlen) == 0);
  3423.     break;
  3424.  
  3425.       case 'm':
  3426.       case 'M':
  3427.     strdelete((Anyptr)comment, 1, 2);
  3428.     i = (sscanf(comment, "%ld", &newwidth) == 0);
  3429.     break;
  3430.  
  3431.       case 'n':
  3432.       case 'N':
  3433.     strdelete((Anyptr)comment, 1, 2);
  3434.     i = (sscanf(comment, "%ld", &newheight) == 0);
  3435.     break;
  3436.  
  3437.       case 'c':
  3438.       case 'C':
  3439.     strdelete((Anyptr)comment, 1, 2);
  3440.     i = (sscanf(comment, "%ld", &vusepxl) == 0);
  3441.     break;
  3442.  
  3443.       case 'b':
  3444.       case 'B':
  3445.     strdelete((Anyptr)comment, 1, 2);
  3446.     i = (sscanf(comment, "%ld", &brightness) == 0);
  3447.     break;
  3448.  
  3449.       case 'x':
  3450.       case 'X':
  3451.     strdelete((Anyptr)comment, 1, 2);
  3452.     i = (sscanf(comment, "%ld", &bitspsam) == 0);
  3453.     break;
  3454.  
  3455.       case 't':
  3456.       case 'T':
  3457.     strdelete((Anyptr)comment, 1, 2);
  3458.     i = (sscanf(comment, "%lg", &valinc) == 0);
  3459.     break;
  3460.  
  3461.       case 'z':
  3462.       case 'Z':
  3463.     strdelete((Anyptr)comment, 1, 2);
  3464.     i = (sscanf(comment, "%ld", &gradint) == 0);
  3465.     break;
  3466.  
  3467.       case 'g':
  3468.       case 'G':
  3469.     strdelete((Anyptr)comment, 1, 2);
  3470.     greypxl = (!strcmp(comment, "y") || !strcmp(comment, "Y"));
  3471.     break;
  3472.  
  3473.       case 'e':
  3474.       case 'E':
  3475.     strdelete((Anyptr)comment, 1, 2);
  3476.     egastretch = (!strcmp(comment, "n") || !strcmp(comment, "N"));
  3477.     egastretch = !egastretch;
  3478.     break;
  3479.  
  3480.       case 'd':
  3481.       case 'D':
  3482.     strdelete((Anyptr)comment, 1, 2);
  3483.     distribute = (!strcmp(comment, "n") || !strcmp(comment, "N"));
  3484.     distribute = !distribute;
  3485.     break;
  3486.  
  3487.       case 'f':
  3488.       case 'F':
  3489.     strdelete((Anyptr)comment, 1, 2);
  3490.     strcpy(aliasname, comment);
  3491.     aliasused = true;
  3492.     break;
  3493.  
  3494.       case 's':
  3495.       case 'S':
  3496.     strdelete((Anyptr)comment, 1, 2);
  3497.     ledprinter = (!strcmp(comment, "y") || !strcmp(comment, "Y"));
  3498.     break;
  3499.  
  3500.       case 'p':
  3501.       case 'P':
  3502.     strdelete((Anyptr)comment, 1, 2);
  3503.     halfinch = (!strcmp(comment, "n") || !strcmp(comment, "N"));
  3504.     break;
  3505.  
  3506.       case 'r':
  3507.       case 'R':
  3508.     strdelete((Anyptr)comment, 1, 2);
  3509.     if (!strcmp(comment, "y")) {
  3510.       hrep = 2;
  3511.       vrep = 2;
  3512.     }
  3513.     break;
  3514.  
  3515.       case 'w':
  3516.       case 'W':
  3517.     strdelete((Anyptr)comment, 1, 2);
  3518.     nowhite = (!strcmp(comment, "n") || !strcmp(comment, "N"));
  3519.     nowhite = !nowhite;
  3520.     break;
  3521.  
  3522.       case 'i':
  3523.       case 'I':
  3524.     strdelete((Anyptr)comment, 1, 2);
  3525.     invert = (!strcmp(comment, "y") || !strcmp(comment, "Y"));
  3526.     break;
  3527.  
  3528.       case 'u':
  3529.       case 'U':
  3530.     strdelete((Anyptr)comment, 1, 2);
  3531.     i = (sscanf(comment, "%ld", &usepxl) == 0);
  3532.     break;
  3533.       }
  3534.     }
  3535.   }
  3536.   /*:108*/
  3537.   /*109:*/
  3538.   if (bitspsam < 1 || bitspsam > 8)
  3539.     bitspsam = 8;
  3540.   if (invert) {
  3541.     invbit = 0;
  3542.     invbyte = 0;
  3543.   } else {
  3544.     invbit = 1;
  3545.     invbyte = 255;
  3546.   }
  3547.   if (usepxl == 0)
  3548.     usepxl = 2;
  3549.   if (vusepxl == 0)
  3550.     vusepxl = usepxl;
  3551.   if (brightness >= usepxl * vusepxl * 4)
  3552.     brightness = 0;
  3553.   if (brightness != 0 && usepxl < 2)
  3554.     brightness = 0;
  3555.   if (valinc > 99)
  3556.     valinc = 99.0;
  3557.   if (valinc > 0) {
  3558.     if (gradint == 0)
  3559.       gradint = 1;
  3560.   }
  3561.   if (gradint > 99)
  3562.     gradint = 99;
  3563.   if (newheight < 0)
  3564.     newheight = 0;
  3565.   if (newwidth < 0)
  3566.     newwidth = 0;
  3567.   if (newwidth > 200) {
  3568.     printf("Sorry, new width set to 200mm\n");
  3569.     newwidth = 200;
  3570.   }
  3571.   if (newheight > 280) {
  3572.     printf("Sorry, new height set to 280mm\n");
  3573.     newheight = 280;
  3574.   }
  3575.   if (truehres == 0)
  3576.     truehres = 300.0;
  3577.   if (truevres == 0)   /*:109*/
  3578.     truevres = truehres;
  3579.   /*:104*/
  3580.   /*105:*/
  3581.   for (j = 0; j <= 25; j++) {
  3582.     for (i = 0; i <= 128; i++) {
  3583.       pwidth[j][i] = 0;
  3584.       width[j][i] = 0;
  3585.       height[j][i] = 0;
  3586.       pheight[j][i] = 0;
  3587.       yoffset[j][i] = 0;
  3588.     }
  3589.   }
  3590.   for (i = 0; i <= 128; i++)
  3591.     dirpoint[i] = 0;
  3592.   for (i = 0; i <= 128; i++)
  3593.     pkpoint[i] = 0;
  3594.   for (i = 0; i <= 26; i++)
  3595.     charpf[i] = 0;
  3596.   maxx = 0;
  3597.   minx = 646;
  3598.   mapheight = 0;   /*:105*/
  3599.   fok = true;
  3600.   strcpy(bmname, font);
  3601.   strcpy(bitmap_NAME, bmname);
  3602.   if (bitmap != NULL)
  3603.     bitmap = freopen(bitmap_NAME, "r+b", bitmap);
  3604.   else
  3605.     bitmap = fopen(bitmap_NAME, "r+b");
  3606.   _SETIO(bitmap != NULL, FileNotFound);
  3607.   filestat = P_ioresult;
  3608.   if (filestat == 0)
  3609.     fok = false;
  3610.   else
  3611.     fok = true;
  3612.   if (fok) {   /*110:*/
  3613.     printf("File %s not found, abort\n", font);
  3614.     fileproblem();
  3615.     goto _L9999;
  3616.   }
  3617.   i = 1;
  3618.   j = 0;
  3619.   strcpy(cmd, " ");
  3620.   while (i <= strlen(bmname)) {
  3621.     if (bmname[i - 1] == '.')
  3622.       j = i;
  3623.     i++;
  3624.   }
  3625.   if (j > 0)
  3626.     strsub(cmd, bmname, j + 1, (strlen(bmname) - j + 1));
  3627.   if (!strcmp(cmd, "tif") || !strcmp(cmd, "TIF") || !strcmp(cmd, "tiff") ||
  3628.       !strcmp(cmd, "TIFF"))
  3629.     tifint();
  3630.   else {
  3631.     if (!strcmp(cmd, "pcx") || !strcmp(cmd, "PCX"))
  3632.       pcxint();
  3633.     else if (!strcmp(cmd, "lbm") || !strcmp(cmd, "LBM") ||
  3634.          !strcmp(cmd, "iff") || !strcmp(cmd, "IFF"))
  3635.       iffint();
  3636.     else if (!strcmp(cmd, "gif") || !strcmp(cmd, "GIF"))
  3637.       gifint();
  3638.     else if (!strcmp(cmd, "bmp") || !strcmp(cmd, "BMP"))
  3639.       bmpint();
  3640.     else if (!strcmp(cmd, "img") || !strcmp(cmd, "IMG"))
  3641.       imgint();
  3642.     else if (!strcmp(cmd, "cut") || !strcmp(cmd, "CUT"))
  3643.       cutint();
  3644.     else
  3645.       posbit = 0;
  3646.   }
  3647.   if (aliasused) {
  3648.     strcpy(font, aliasname);
  3649.     strcpy(bmname, aliasname);
  3650.   }
  3651.   FORLIM = strlen(bmname);
  3652.   for (i = 1; i <= FORLIM; i++) {
  3653.     sprintf(STR2, "%c", bmname[i - 1]);
  3654.     j = strpos2(fontpre, STR2, 1);
  3655.     if (j != 0)
  3656.       bmname[i - 1] = fontupc[j - 1];
  3657.   }
  3658.   FORLIM = strlen(font);
  3659.   for (i = 1; i <= FORLIM; i++) {
  3660.     sprintf(STR2, "%c", font[i - 1]);
  3661.     j = strpos2(fontupc, STR2, 1);
  3662.     if (j != 0)
  3663.       font[i - 1] = fontpre[j - 1];
  3664.   }
  3665.   korrfont();
  3666.   nameok = true;
  3667.   FORLIM = strlen(font);
  3668.   for (i = 1; i <= FORLIM; i++) {
  3669.     if (isdigit(font[i - 1]))
  3670.       nameok = false;
  3671.   }
  3672.   if (!nameok) {
  3673.     printf("no digits allowed in name of font\n");
  3674.     goto _L9999;
  3675.   }
  3676.   strcpy(bmname, font);
  3677.   FORLIM = strlen(bmname);
  3678.   for (i = 1; i <= FORLIM; i++) {   /*:110*/
  3679.     sprintf(STR2, "%c", bmname[i - 1]);
  3680.     j = strpos2(fontpre, STR2, 1);
  3681.     if (j != 0)
  3682.       bmname[i - 1] = fontupc[j - 1];
  3683.   }
  3684.   /*111:*/
  3685.   if (truehres <= 0 || truehres > 2000)
  3686.     truehres = 300.0;
  3687.   if (truevres <= 0 || truevres > 2000)
  3688.     truevres = 300.0;
  3689.   whatistrue();
  3690.   if (hres != (long)floor(truehres + 0.5))
  3691.     printf("maximum width of characters is %ld pixel\n", hres);
  3692.   if (vres != (long)floor(truevres + 0.5))
  3693.     printf("maximum height of characters is %ld pixel\n", vres);
  3694.   if (posbit != 0)
  3695.     pxlinlen = (halfk)((mapwidth + 7) / 8);
  3696.   else {
  3697.     pxlinlen = mapinlen;
  3698.     mapwidth = pxlinlen * 8;
  3699.     if (greypxl)   /*113:*/
  3700.       mapwidth /= bitspsam;
  3701.     if (mapwidth < 1) {
  3702.       printf("Width not correct!\n");
  3703.       goto _L9999;
  3704.     }
  3705.     mapheight = (P_maxpos(bitmap)) / mapinlen;
  3706.     if ((P_maxpos(bitmap)) % mapinlen > 0) {
  3707.       printf("Remainder > 0 when dividing size of file by width!\n");
  3708.       goto _L9999;
  3709.     }
  3710. /* p2c: bm2font.pas, line 973:
  3711.  * Note: Using % for possibly-negative arguments [317] */
  3712.     if (greypxl) {
  3713.       mapdiv = 1.0;
  3714.       photoinf = 15;
  3715.       FORLIM1 = bitspsam;
  3716.       for (cb = 1; cb <= FORLIM1; cb++)
  3717.     mapdiv *= 2;
  3718.       mapdiv /= 16;
  3719.     }  /*:113*/
  3720.   }
  3721.   if (pxlinlen > 3000) {
  3722.     printf("File not processable, width > 3000 bytes\n");
  3723.     goto _L9999;
  3724.   }  /*:111*/
  3725.   if (newwidth != 0 || newheight != 0)
  3726.     scaling();
  3727.   if (greypxl) {  /*94:*/
  3728.     printf("Halftone picture required\n");
  3729.     pxlinlen = (halfk)(((unsigned long)(mapwidth * bitspsam + 7)) >> 3);
  3730.     greypix = mapwidth;
  3731.     mapwidth *= bitspsam;   /*95:*/
  3732.     sprintf(tmpname, "%s.tmp", font);
  3733.     strcpy(tmpfil_NAME, tmpname);
  3734.     filestat = P_ioresult;
  3735.     if (filestat == 0)
  3736.       fok = false;
  3737.     else
  3738.       fok = true;
  3739.     if (fok) {
  3740.       printf("tempfile %s not accessable, abort\n", tmpname);
  3741.       fileproblem();
  3742.       goto _L9999;
  3743.     }
  3744.     if (tmpfil != NULL)
  3745.       tmpfil = freopen(tmpfil_NAME, "w+b", tmpfil);
  3746.     else
  3747.       tmpfil = fopen(tmpfil_NAME, "w+b");
  3748.     _SETIO(tmpfil != NULL, FileNotFound);
  3749.     filestat = P_ioresult;
  3750.     if (filestat == 0)
  3751.       fok = false;
  3752.     else
  3753.       fok = true;
  3754.     if (fok) {   /*:95*/
  3755.       printf("Tempfile for font %s not found, abort\n", font);
  3756.       fileproblem();
  3757.       goto _L9999;
  3758.     }
  3759.     /*101:*/
  3760.     k = 0;
  3761.     if (usepxl != vusepxl) {
  3762.       FORLIM = vusepxl;
  3763.       for (i = 0; i < FORLIM; i++) {
  3764.     FORLIM2 = usepxl;
  3765.     for (j = 0; j < FORLIM2; j++) {
  3766.       k++;
  3767.       tab[k - 1][0] = i + 1;
  3768.       tab[k - 1][1] = j + 1;
  3769.       tab[k - 1][2] = i * i * (usepxl - 1) * (usepxl - 1) +
  3770.               j * j * (vusepxl - 1) * (vusepxl - 1);
  3771.     }
  3772.       }
  3773.       FORLIM = k;
  3774.       for (i = 1; i <= FORLIM; i++) {
  3775.     FORLIM2 = k;
  3776.     for (j = i; j <= FORLIM2; j++) {
  3777.       if (tab[i - 1][2] > tab[j - 1][2]) {
  3778.         lx = tab[i - 1][0];
  3779.         tab[i - 1][0] = tab[j - 1][0];
  3780.         tab[j - 1][0] = lx;
  3781.         lx = tab[i - 1][1];
  3782.         tab[i - 1][1] = tab[j - 1][1];
  3783.         tab[j - 1][1] = lx;
  3784.         lx = tab[i - 1][2];
  3785.         tab[i - 1][2] = tab[j - 1][2];
  3786.         tab[j - 1][2] = lx;
  3787.       }
  3788.     }
  3789.       }
  3790.       FORLIM = k;
  3791.       for (i = 1; i <= FORLIM; i++) {
  3792.     lx = tab[i - 1][0];
  3793.     ly = tab[i - 1][1];
  3794.     ditherm[lx - 1][ly - 1] = i;
  3795.       }
  3796.     }
  3797.     if (usepxl > 7)
  3798.       usepxl = 7;
  3799.     if (vusepxl > 7)
  3800.       vusepxl = 7;
  3801.     maxcol = 1;
  3802.     cb = 0;
  3803.     usecol = usepxl * vusepxl * 4;
  3804.     FORLIM = bitspsam;
  3805.     for (k = 1; k <= FORLIM; k++)
  3806.       maxcol *= 2;
  3807.     maxcol--;
  3808.     for (k = 1; k <= 4; k++) {
  3809.       for (i = 0; i <= 196; i++) {
  3810.     for (j = 1; j <= 7; j++)
  3811.       pattern[k - 1][i][j - 1] = 0;
  3812.       }
  3813.     }
  3814.     FORLIM = vusepxl;
  3815.     for (i = 1; i <= FORLIM; i++) {
  3816.       FORLIM2 = usepxl;
  3817.       for (j = 1; j <= FORLIM2; j++) {
  3818.     if (ditherm[i - 1][j - 1] <= usecol / 4 && ditherm[i - 1][j - 1] > 0) {
  3819.       v = (ditherm[i - 1][j - 1] - 1) * 4 + 1;
  3820.       for (ccol = 1; ccol <= 4; ccol++) {
  3821.         if (ccol == 1)
  3822.           c = 1;
  3823.         else if (ccol == 2)
  3824.           c = 3;
  3825.         else if (ccol == 3)
  3826.           c = 4;
  3827.         else
  3828.           c = 2;
  3829.         FORLIM3 = usecol;
  3830.         for (k = v; k <= FORLIM3; k++) {
  3831.           switch (c) {
  3832.  
  3833.           case 4:
  3834.         if (usepxl > 2 || vusepxl > 2)
  3835.           pattern[0][k][j - 1] |= (cb + 2) << (7 - i);
  3836.         else
  3837.           pattern[0][k][i - 1] |= (cb + 2) << (7 - j);
  3838.         break;
  3839.  
  3840.           case 1:
  3841.         pattern[1][k][vusepxl - i] |= (cb + 1) << (j - usepxl + 7);
  3842.         break;
  3843.  
  3844.           case 2:
  3845.         if (usepxl > 2 || vusepxl > 2)
  3846.           pattern[2][k][vusepxl - j] |= (cb + 2) << (7 - i);
  3847.         else
  3848.           pattern[2][k][vusepxl - i] |= (cb + 2) << (7 - j);
  3849.         break;
  3850.  
  3851.           case 3:
  3852.         pattern[3][k][i - 1] |= (cb + 1) << (j - usepxl + 7);
  3853.         break;
  3854.           }
  3855.         }
  3856.         v++;
  3857.       }
  3858.     }
  3859.       }
  3860.     }
  3861.     if (nowhite)
  3862.       pattern[1][0][usepxl - 1] = 128 >> (usepxl - 1);
  3863.     usecol -= brightness;   /*:101*/
  3864.     /*[102:]append(logfile);
  3865. for k:=0 to usecol do begin for j:=1 to vusepxl do begin for i:=1 to 4
  3866. do begin cb:=pattern[i,k,j];write(logfile,cb:4,' ');
  3867. for pk:=1 to usepxl do begin if cb>127 then write(logfile,'1')else write
  3868. (logfile,'0');cb:=cb shl 1;end;write(logfile,' ');end;
  3869. writeln(logfile,'.');end;writeln(logfile,'---- ',k:1,' ----');end;
  3870. close(logfile);[:102]*/
  3871.     greypix -= greypix & 1;
  3872.     if (ledprinter)
  3873.       gbufpp = ((long)floor(greypix * (usepxl + 0.5) + 0.5) * hrep + 7) / 8;
  3874.     else
  3875.       gbufpp = (greypix * usepxl * hrep + 7) / 8;
  3876.     if (gbufpp > 1280) {
  3877.       printf("Only up to 1280 bytes in one row allowed!\n");
  3878.       printf("Try again by decreasing param <u> or <r=n>\n");
  3879.       _Escape(0);
  3880.     }  /*96:*/
  3881.     printf("Analysing and optimizing the picture\n");
  3882.     pminval = 255;
  3883.     pmaxval = 0;
  3884.     if (cutgrey) {
  3885.       checksum = mapheight;
  3886.       pxlinlen = cutlen;
  3887.     } else
  3888.       checksum = mapheight;
  3889.     pl = 0;
  3890.     fseek(bitmap, posbit, 0);
  3891.     do {
  3892.       pxlinlen = fread(b1, 1, pxlinlen, bitmap);
  3893.       colpos = 0;
  3894.       cutrep = 0;
  3895.       FORLIM = greypix;
  3896.       for (pk = 0; pk < FORLIM; pk++) {
  3897.     tmpcolor = getcolor();
  3898.     if (tmpcolor > pmaxval)
  3899.       pmaxval = tmpcolor;
  3900.     if (tmpcolor < pminval)
  3901.       pminval = tmpcolor;
  3902.       }
  3903.       checksum--;
  3904.       if (cutgrey)
  3905.     pxlinlen = b1[pxlinlen - 1] * 256 + b1[pxlinlen - 2] + 2;
  3906.     } while (checksum != 0);
  3907. /* p2c: bm2font.pas, line 1030:
  3908.  * Note: Can't interpret size in BLOCKREAD [174] */
  3909.     if (pminval == pmaxval) {
  3910.       printf("Only one color (value %d) used by bitmap!\n", pmaxval);
  3911.       printf("It makes no sence to generate a picture!\n");
  3912.       _Escape(0);
  3913.     }  /*:96*/
  3914.     if (brightness == 0) {
  3915.       brightness = (long)floor(
  3916.         (maxcol - pmaxval + pminval + 1.0) * usecol / (maxcol + 1) + 0.5);
  3917.       if (brightness > 0)
  3918.     printf("Best result may be with parameter -b%ld !?\n", brightness);
  3919.     }
  3920.     printf("Dithering the picture\n");
  3921.     memset((Anyptr)greymem, 255, sizeof(uchar) * 32761L);
  3922.     pgreymem = 0;
  3923.     if (cutgrey) {
  3924.       checksum = mapheight;
  3925.       pxlinlen = cutlen;
  3926.     } else
  3927.       checksum = mapheight;
  3928.     pl = 0;
  3929.     fseek(bitmap, posbit, 0);
  3930.     patswitch = 4;
  3931.     spreadcol = (maxcol + 1.0) / (pmaxval - pminval + 1);
  3932.     patref = (double)usecol / maxcol;   /*97:*/
  3933.     for (k = 0; k <= 255; k++)
  3934.       pxllook[k] = k;
  3935.     if (invert) {
  3936.       for (k = 0; k <= 255; k++)
  3937.     pxllook[k] = 255 - k;
  3938.     }
  3939.     if (invert) {
  3940.       FORLIM = pmaxval;
  3941.       for (k = pminval; k <= FORLIM; k++)
  3942.     pxllook[pmaxval - k + pminval] =
  3943.       (long)floor((k - pminval) * spreadcol + 0.5);
  3944.       invbit = 1;
  3945.       invbyte = 255;
  3946.     } else {
  3947.       FORLIM = pmaxval;
  3948.       for (k = pminval; k <= FORLIM; k++)
  3949.     pxllook[k] = (long)floor((k - pminval) * spreadcol + 0.5);
  3950.     }
  3951.     FORLIM = maxcol;
  3952.     for (k = 0; k <= FORLIM; k++)
  3953.       lutone[k] = (long)floor((maxcol - k) * patref + 0.5);
  3954.     if (valinc > 0) {   /*98:*/
  3955.       k = pminval;
  3956.       pk = 0;
  3957.       while (pk <= gradint && k <= pmaxval) {
  3958.     pk = (long)floor(pxllook[k] * 100.0 / maxcol + 0.5);
  3959.     k++;
  3960.       }
  3961.       pkn = pxllook[k - 1];
  3962.       grxzero = pkn;
  3963.       redval = valinc / 100;
  3964.       FORLIM = pmaxval;
  3965.       for (k = pminval; k <= FORLIM; k++) {
  3966.     /*write(logfile,(pxllook[k]/maxcol):1:5
  3967. );*/
  3968.     grx = pxllook[k];
  3969.     if (grx <= pkn) {
  3970.       if (grx > 0)
  3971.         pxllook[k] = (long)
  3972.              floor(0.5 * grx * (exp(redval * log(grx / grxzero)) +
  3973.                  exp(-redval * log(grx / grxzero))) + 0.5);
  3974. /* p2c: bm2font.pas, line 1249: 
  3975.  * Note: Line breaker spent 14.0 seconds, 5000 tries on line 3970 [251] */
  3976.     }
  3977.     /*writeln(logfile,' ',(pxllook[k]/maxcol):1:5);*/
  3978.       }  /*close(logfile);;*/
  3979.       /*:98*/
  3980.     }
  3981.     /*append(logfile);*/
  3982.     FORLIM = maxcol;
  3983.     for (pk = 0; pk <= FORLIM; pk++)
  3984.       hktab[pk] = (long)floor((maxcol - pk) * patref * 100 + 0.5) -
  3985.           (long)(lutone[pk] * 100.0);
  3986.     cspread = false;
  3987.     if (usecol - 1 > maxcol) {
  3988.       pk = usecol;
  3989.       for (k = maxcol; k >= 0; k--) {
  3990.     if (invert)
  3991.       pk = usecol - lutone[pxllook[maxcol - k]];
  3992.     else
  3993.       pk = usecol - lutone[pxllook[k]];
  3994.     while (pk >= k) {
  3995.       lutone[pk] = lutone[pxllook[k]];
  3996.       hktab[pk] = (long)floor(lutone[pk] * 100.0 + 0.5) -
  3997.               (long)floor((usecol - pk) * 100.0 + 0.5);
  3998.       lutone[pk] -= hktab[pk] / 100;
  3999.       pk--;
  4000.     }
  4001.       }
  4002.       if (invert) {
  4003.     FORLIM = usecol;
  4004.     for (k = 0; k <= FORLIM; k++)
  4005.       pxllook[k] = lutone[k];
  4006.       } else {
  4007.     FORLIM = usecol;
  4008.     for (k = 0; k <= FORLIM; k++)
  4009.       pxllook[k] = usecol - lutone[k];
  4010.       }
  4011.       maxcol = usecol;
  4012.       cspread = true;
  4013.     }
  4014.     invert = false;
  4015.     mapdiv = (usecol + 1.0) / 16;
  4016.     FORLIM = usecol;
  4017.     for (k = 0; k <= FORLIM; k++)
  4018.       lutvga[k] = (long)((usecol - k) / mapdiv);
  4019.     for (pk = -255; pk <= 255; pk++) {
  4020.       if (cspread)
  4021.     gkorh[pk + 255] = (long)(pk / 2.0);
  4022.       else
  4023.     gkorh[pk + 255] = (long)floor(pk / 2.0 * spreadcol + 0.5);
  4024.       if (cspread)
  4025.     gkordivp[pk + 255] = (long)(pk / 2.0);
  4026.       else
  4027.     gkordivp[pk + 255] = (long)(pk / 2.0 * patref + hktab[abs(pk)] / 100.0);
  4028.     }
  4029.     for (pk = 0; pk <= 255; pk++)   /*:97*/
  4030.       spreadvals[pk] = (long)floor(pk * patref + 0.5);
  4031.     do {
  4032.       pxlinlen = fread(b1, 1, pxlinlen, bitmap);
  4033.       colpos = 0;
  4034.       cutrep = 0;
  4035.       FORLIM = greypix;
  4036.       for (pk = 0; pk < FORLIM; pk++)
  4037.     b4[pk] = getcolor();
  4038.       if (cspread) {
  4039.     FORLIM = greypix;
  4040.     for (pk = 0; pk < FORLIM; pk++)
  4041.       b4[pk] = spreadvals[b4[pk]];
  4042.       }
  4043.       if (distribute) {   /*99:*/
  4044.     pk = 1;
  4045.     pkn = 1;
  4046.     while (pk < greypix) {
  4047.       pkn++;
  4048.       greykor = 0;
  4049.       if (b4[pk] != b4[pkn]) {
  4050.         greykor = gkorh[b4[pk] - b4[pkn] + 255];
  4051.         greykor = gkordivp[greykor + 255];
  4052.       }
  4053.       if (greykor != 0) {
  4054.         tmpcolor = lutone[pxllook[b4[pkn]]];
  4055.         if (abs(tmpcolor + greykor) <= usecol &&
  4056.         abs(tmpcolor + greykor) >= 0)
  4057.           b4[pkn] += greykor;
  4058.       }
  4059.       pk++;
  4060.     }
  4061.     pk = greypix - 1;
  4062.     pkn = pk;
  4063.     while (pk > 0) {   /*:99*/
  4064.       pkn--;
  4065.       greykor = 0;
  4066.       if (b4[pk] != b4[pkn]) {
  4067.         greykor = gkorh[b4[pk] - b4[pkn] + 255];
  4068.         greykor = gkordivp[greykor + 255];
  4069.       }
  4070.       if (greykor != 0) {
  4071.         tmpcolor = lutone[pxllook[b4[pkn]]];
  4072.         if (abs(tmpcolor + greykor) <= usecol &&
  4073.         abs(tmpcolor + greykor) >= 0)
  4074.           b4[pkn] += greykor;
  4075.       }
  4076.       pk--;
  4077.     }
  4078.       }
  4079.       FORLIM = greypix;
  4080.       for (pk = 0; pk < FORLIM; pk++)
  4081.     b4[pk] = lutone[pxllook[b4[pk]]];
  4082.       FORLIM1 = vrep;
  4083.       for (yrep = 1; yrep <= FORLIM1; yrep++) {   /*100:*/
  4084.     FORLIM = vusepxl;
  4085.     for (k = 1; k <= FORLIM; k++) {
  4086.       gbufp = 0;
  4087.       cb = 0;
  4088.       pn = 0;
  4089.       switch (patswitch) {
  4090.  
  4091.       case 1:
  4092.         curpat[0] = 2;
  4093.         curpat[1] = 3;
  4094.         break;
  4095.  
  4096.       case 2:
  4097.         curpat[0] = 4;
  4098.         curpat[1] = 1;
  4099.         break;
  4100.  
  4101.       case 3:
  4102.         curpat[0] = 3;
  4103.         curpat[1] = 2;
  4104.         break;
  4105.  
  4106.       case 4:
  4107.         curpat[0] = 1;
  4108.         curpat[1] = 4;
  4109.         break;
  4110.       }
  4111. /* p2c: bm2font.pas, line 1098:
  4112.  * Note: Can't interpret size in FILLCHAR [174] */
  4113.       memset((Anyptr)b3, 0, (long)gbufpp);
  4114.       FORLIM2 = greypix;
  4115.       for (pk = 0; pk < FORLIM2; pk++) {
  4116.         FORLIM4 = hrep;
  4117.         for (xrep = 1; xrep <= FORLIM4; xrep++) {
  4118.           cb = pattern[curpat[pn] - 1][b4[pk]][k - 1];
  4119.           dbuf = ((unsigned)gbufp) >> 3;
  4120.           bufsh = gbufp & 7;
  4121.           nextbuf = bufsh + usepxl;
  4122.           switch (bufsh) {
  4123.  
  4124.           case 0:
  4125.         b3[dbuf] = cb;
  4126.         break;
  4127.  
  4128.           default:
  4129.         b3[dbuf] |= cb >> bufsh;
  4130.         if (nextbuf > 8)
  4131.           b3[dbuf + 1] = cb << (8 - bufsh);
  4132.         break;
  4133.           }
  4134.           gbufp += usepxl;
  4135.           if (ledprinter) {
  4136.         if (curpat[pn] == 1 || curpat[pn] == 3)
  4137.           gbufp++;
  4138.           }
  4139.           pn = abs(pn - 1);
  4140.         }
  4141.       }
  4142.       FORLIM2 = gbufpp;
  4143.       for (pk = 0; pk <= FORLIM2; pk++)
  4144.         b3[pk] = ~b3[pk];
  4145.       if (pgreymem + gbufpp > 65522L) {
  4146.         _SETIO(fwrite(greymem, pgreymem, 1, tmpfil) == 1, FileWriteError);
  4147.         filestat = P_ioresult;
  4148.         if (filestat != 0) {
  4149.           _SETIO(printf("Error occured when writing file %s!\n", tmpname) >= 0,
  4150.              FileWriteError);
  4151.           fileproblem();
  4152.           _Escape(0);
  4153.         }
  4154.         pgreymem = 0;
  4155.       }
  4156. /* p2c: bm2font.pas, line 1107:
  4157.  * Note: Can't interpret size in BLOCKWRITE [174] */
  4158. /* p2c: bm2font.pas, line 1110: Note: Can't interpret size in MOVE [174] */
  4159.       memmove((Anyptr)(&greymem[pgreymem]), (Anyptr)b3, (long)gbufpp);
  4160.       pgreymem += gbufpp;
  4161.     }
  4162. /* p2c: bm2font.pas, line 1111:
  4163.  * Note: Can't interpret size in FILLCHAR [174] */
  4164.     memset((Anyptr)b3, 255, (long)gbufpp);
  4165.     if (ledprinter) {
  4166.       if (patswitch == 2 || patswitch == 4) {
  4167.         if (pgreymem + gbufpp > 65522L) {
  4168.           _SETIO(fwrite(greymem, pgreymem, 1, tmpfil) == 1,
  4169.              FileWriteError);
  4170.           filestat = P_ioresult;
  4171.           if (filestat != 0) {
  4172.         _SETIO(printf("Error occured when writing file %s!\n",
  4173.                   tmpname) >= 0, FileWriteError);
  4174.         fileproblem();
  4175.         _Escape(0);
  4176.           }
  4177.           pgreymem = 0;
  4178.         }
  4179. /* p2c: bm2font.pas, line 1114:
  4180.  * Note: Can't interpret size in BLOCKWRITE [174] */
  4181. /* p2c: bm2font.pas, line 1117: Note: Can't interpret size in MOVE [174] */
  4182.         memmove((Anyptr)(&greymem[pgreymem]), (Anyptr)b3, (long)gbufpp);
  4183.         pgreymem += gbufpp;
  4184.       }  /*:100*/
  4185.     }
  4186.     patswitch++;
  4187.     if (patswitch > 4)
  4188.       patswitch = 1;
  4189.       }
  4190.       pm = 128;
  4191.       pb = pl;
  4192.       FORLIM = greypix;
  4193.       for (pk = 0; pk < FORLIM; pk++) {
  4194.     pxlcolor = lutvga[b4[pk]];
  4195.     pm >>= 1;
  4196.     if (pm == 0) {
  4197.       pm = 128;
  4198.       pb++;
  4199.     }
  4200.       }
  4201.       pl += 80;
  4202.       if (pl >= 38400L)
  4203.     pl = 0;
  4204.       checksum--;
  4205.       if (cutgrey)
  4206.     pxlinlen = (halfk)(b1[pxlinlen - 1] * 256 + b1[pxlinlen - 2] + 2);
  4207.     } while (checksum != 0);
  4208. /* p2c: bm2font.pas, line 1078:
  4209.  * Note: Can't interpret size in BLOCKREAD [174] */
  4210.     if (pgreymem != 0) {  /*$I-*/
  4211.       _SETIO(fwrite(greymem, pgreymem, 1, tmpfil) == 1, FileWriteError);
  4212.       filestat = P_ioresult;
  4213.       if (filestat != 0) {
  4214.     _SETIO(printf("Error occured when writing file %s!\n", tmpname) >= 0,
  4215.            FileWriteError);
  4216.     fileproblem();
  4217.     _Escape(0);
  4218.       }
  4219.     }
  4220. /* p2c: bm2font.pas, line 1124:
  4221.  * Note: Can't interpret size in BLOCKWRITE [174] */
  4222.     posbit = 0;
  4223.     if (ledprinter)
  4224.       mapwidth = (long)floor(greypix * (usepxl + 0.5) + 0.5) * hrep;
  4225.     else
  4226.       mapwidth = greypix * usepxl * hrep;
  4227.     pxlinlen = (mapwidth + 7) / 8;
  4228.     mapinlen = pxlinlen;
  4229.     if (ledprinter)
  4230.       mapheight = (long)floor(mapheight * (vusepxl + 0.5) + 0.5) * vrep;
  4231.     else
  4232.       mapheight *= vusepxl * vrep;
  4233.     if (tmpfil != NULL)
  4234.       fclose(tmpfil);
  4235.     tmpfil = NULL;
  4236.     if (bitmap != NULL)
  4237.       fclose(bitmap);
  4238.     bitmap = NULL;
  4239.     strcpy(bitmap_NAME, tmpname);
  4240.     if (bitmap != NULL)
  4241.       bitmap = freopen(bitmap_NAME, "r+b", bitmap);
  4242.     else
  4243.       bitmap = fopen(bitmap_NAME, "r+b");
  4244.     if (bitmap == NULL)
  4245.       _EscIO(FileNotFound);
  4246.   }  /*112:*/
  4247.   checksum = mapheight * ((mapwidth + 7) / 8);
  4248.   mapheight = 0;
  4249.   freelines = 0;
  4250.   fseek(bitmap, posbit, 0);
  4251.   while (checksum >= pxlinlen) {
  4252.     fread(b1, pxlinlen, 1, bitmap);
  4253.     mapwidth = pxlinlen * 8;
  4254.     j = pxlinlen - 1;
  4255.     while (b1[j] == invbyte && j >= 0)
  4256.       j--;
  4257.     if (j >= 0) {
  4258.       i = 0;
  4259.       while (b1[i] == invbyte && i <= j)
  4260.     i++;
  4261.       if (i < minx)
  4262.     minx = i;
  4263.       lx = j * 8 + 8;
  4264.       cb = b1[j];
  4265.       for (i = 1; i <= 8; i++) {
  4266.     if ((cb & 1) == invbit) {
  4267.       cb >>= 1;
  4268.       lx--;
  4269.     } else
  4270.       i = 8;
  4271.       }
  4272.       if (lx > maxx)
  4273.     maxx = lx;
  4274.       freelines++;
  4275.       mapheight += freelines;
  4276.       freelines = 0;
  4277.     } else if (mapheight == 0)
  4278.       posbit += pxlinlen;
  4279.     else
  4280.       freelines++;
  4281.     checksum -= pxlinlen;
  4282.   }
  4283. /* p2c: bm2font.pas, line 1135:
  4284.  * Note: Can't interpret size in BLOCKREAD [174] */
  4285.   mapwidth = maxx - minx * 8;
  4286.   zeropads = pxlinlen - (mapwidth + 7) / 8;
  4287.   maplines = mapheight;
  4288.   posbit += minx;   /*:112*/
  4289.   /*114:*/
  4290.   i = (mapwidth + hres - 1) / hres;
  4291.   j = (mapheight + vres - 1) / vres;
  4292.   nj = j;
  4293.   nofchars = i * j;
  4294.   mincharpf = 515832L / (vres * ((hres + 31) / 32) * 32);
  4295.   noffonts = (nofchars + mincharpf - 1) / mincharpf;
  4296.   if (mincharpf > 128) {   /*:114*/
  4297.     mincharpf = 128;
  4298.     noffonts = (nofchars + 127) / 128;
  4299.   }
  4300.   /*118:*/
  4301.   k = 0;
  4302.   c = 0;
  4303.   while (mapheight > 0) {   /*:118*/
  4304.     maxx = mapwidth;
  4305.     while (maxx > 0) {
  4306.       if (maxx > hres)
  4307.     pwidth[k][c] = hres;
  4308.       else
  4309.     pwidth[k][c] = maxx;
  4310.       if (mapheight > vres)
  4311.     pheight[k][c] = vres;
  4312.       else
  4313.     pheight[k][c] = mapheight;
  4314.       dsize = floor(vres / truehres * 72.27 * 65536L * 16 + 0.5);
  4315.       tabdsize[k] = dsize;
  4316.       c++;
  4317.       if (c == mincharpf || (mapheight <= vres && maxx <= hres)) {
  4318.     FORLIM1 = mincharpf;
  4319.     for (c = 0; c < FORLIM1; c++) {
  4320.       height[k][c] = floor(pheight[k][c] / truevres * 4736286.7227 /
  4321.                      dsize * 16777215L + 0.5);
  4322.       width[k][c] = floor(pwidth[k][c] / truehres * 4736286.7227 / dsize *
  4323.                   16777215L + 0.5);
  4324.     }
  4325.     k++;
  4326.     c = 0;
  4327.       }
  4328.       maxx -= hres;
  4329.     }
  4330.     mapheight -= vres;
  4331.   }
  4332.   maxx = (mapwidth + hres - 1) / hres;
  4333.   f = 0;
  4334.   g = 0;
  4335.   pxlbmi = 4;
  4336.   if (fok) {
  4337.     printf("error occurred when allocating pxlfile ");
  4338.     puts(cmd);
  4339.     fileproblem();
  4340.     goto _L9999;
  4341.   }
  4342.   if (bitmap != NULL)
  4343.     fclose(bitmap);
  4344.   bitmap = NULL;
  4345.   if (bitmap != NULL)
  4346.     bitmap = freopen(bitmap_NAME, "r+b", bitmap);
  4347.   else
  4348.     bitmap = fopen(bitmap_NAME, "r+b");
  4349.   if (bitmap == NULL)
  4350.     _EscIO(FileNotFound);
  4351.   fonteject();   /*119:*/
  4352.   FORLIM = noffonts;
  4353.   for (a = 0; a < FORLIM; a++) {   /*:119*/
  4354.     lh = 17;
  4355.     bc = 0;
  4356.     ec = 127;
  4357.     while (pheight[a][ec] == 0)   /*120:*/
  4358.       ec--;
  4359.     sprintf(cmd, "%s%c.tfm", font, fontpre[a]);
  4360.     strcpy(tfmfile_NAME, cmd);
  4361.     if (tfmfile != NULL)
  4362.       tfmfile = freopen(tfmfile_NAME, "w+b", tfmfile);
  4363.     else
  4364.       tfmfile = fopen(tfmfile_NAME, "w+b");
  4365.     _SETIO(tfmfile != NULL, FileNotFound);
  4366.     filestat = P_ioresult;
  4367.     if (filestat == 3 || filestat == 5) {
  4368.       strcpy(cmd, bmname);
  4369.       sprintf(cmd + strlen(cmd), "%c.tfm", fontupc[a]);
  4370.       strcpy(tfmfile_NAME, cmd);
  4371.       if (tfmfile != NULL)
  4372.     tfmfile = freopen(tfmfile_NAME, "w+b", tfmfile);
  4373.       else
  4374.     tfmfile = fopen(tfmfile_NAME, "w+b");
  4375.       _SETIO(tfmfile != NULL, FileNotFound);
  4376.       filestat = P_ioresult;
  4377.     }
  4378.     if (filestat == 0)
  4379.       fok = false;
  4380.     else
  4381.       fok = true;
  4382.     if (fok) {
  4383.       printf("error occurred when allocating tfmfile ");
  4384.       puts(cmd);
  4385.       fileproblem();
  4386.       goto _L9999;
  4387.     }
  4388.     printf("Generating tfmfile %s\n", cmd);   /*:120*/
  4389.     dsize = floor(vres / truehres * 72.27 * 65536L * 16 + 0.5);
  4390.     tabdsize[a] = dsize;
  4391.     FORLIM2 = ec;
  4392.     for (k = bc; k <= FORLIM2; k++) {
  4393.       height[a][k] = floor(
  4394.         pheight[ a][k] / truevres * 4736286.7227 / dsize * 16777215L + 0.5);
  4395.       width[a][k] = floor(
  4396.         pwidth[ a][k] / truehres * 4736286.7227 / dsize * 16777215L + 0.5);
  4397.     }
  4398.     fh = height[a][bc];
  4399.     fw = width[a][bc];
  4400.     sh = fh;
  4401.     sw = fw;
  4402.     nw = 2;
  4403.     nh = 2;
  4404.     FORLIM2 = ec;
  4405.     for (k = bc; k <= FORLIM2; k++) {
  4406.       if (height[a][k] != 0 && height[a][k] != fh && height[a][k] != sh) {
  4407.     sh = height[a][k];
  4408.     nh++;
  4409.       }
  4410.       if (width[a][k] != 0 && width[a][k] != fw && width[a][k] != sw) {
  4411.     sw = width[a][k];
  4412.     nw++;
  4413.       }
  4414.     }
  4415.     if (nh > 3) {
  4416.       printf("more than 2 heights, should be impossible\n");
  4417.       goto _L9999;
  4418.     }
  4419.     if (nw > 3) {
  4420.       printf("more than 2 widths, should be impossible\n");
  4421.       goto _L9999;
  4422.     }
  4423.     nd = 2;
  4424.     ni = 2;
  4425.     nl = 0;
  4426.     nk = 0;
  4427.     ne = 0;
  4428.     np = 0;
  4429.     lf = lh + ec - bc + nw + nh + nd + ni + nk + nl + ne + np + 7;
  4430.     checksum = 0;
  4431.     tfmhword(lf);
  4432.     tfmhword(lh);
  4433.     tfmhword(bc);
  4434.     tfmhword(ec);
  4435.     tfmhword(nw);
  4436.     tfmhword(nh);
  4437.     tfmhword(nd);
  4438.     tfmhword(ni);
  4439.     tfmhword(nl);
  4440.     tfmhword(nk);
  4441.     tfmhword(ne);
  4442.     tfmhword(np);
  4443.     tfmword(checksum);
  4444.     tfmword(dsize);
  4445.     strcpy(tfmstr, "0Graphic");
  4446.     tfmstr[0] = '\007';
  4447.     FORLIM2 = strlen(tfmstr);
  4448.     for (i = 1; i <= FORLIM2; i++) {
  4449.       tfmb = tfmstr[i - 1];
  4450.       fwrite(&tfmb, sizeof(uchar), 1, tfmfile);
  4451.     }
  4452.     tfmb = 0;
  4453.     for (i = 1; i <= 32; i++)
  4454.       fwrite(&tfmb, sizeof(uchar), 1, tfmfile);
  4455.     strcpy(tfmstr, "0Bitmap");
  4456.     tfmstr[0] = '\006';
  4457.     FORLIM2 = strlen(tfmstr);
  4458.     for (i = 1; i <= FORLIM2; i++) {
  4459.       tfmb = tfmstr[i - 1];
  4460.       fwrite(&tfmb, sizeof(uchar), 1, tfmfile);
  4461.     }
  4462.     tfmb = 0;
  4463.     for (i = 1; i <= 13; i++)
  4464.       fwrite(&tfmb, sizeof(uchar), 1, tfmfile);
  4465.     FORLIM2 = ec;
  4466.     for (i = bc; i <= FORLIM2; i++) {
  4467.       if (width[a][i] == 0) {
  4468.     tfmb = 0;
  4469.     fwrite(&tfmb, sizeof(uchar), 1, tfmfile);
  4470.       } else if (width[a][i] == fw) {
  4471.     tfmb = 1 ;
  4472.     fwrite(&tfmb, sizeof(uchar), 1, tfmfile);
  4473.       } else {
  4474.     tfmb = 2;
  4475.     fwrite(&tfmb, sizeof(uchar), 1, tfmfile);
  4476.       }
  4477.       if (height[a][i] == 0) {
  4478.     tfmb = 0;
  4479.     fwrite(&tfmb, sizeof(uchar), 1, tfmfile);
  4480.       } else if (height[a][i] == fh) {
  4481.     tfmb = 16;
  4482.     fwrite(&tfmb, sizeof(uchar), 1, tfmfile);
  4483.       } else {
  4484.     tfmb = 32;
  4485.     fwrite(&tfmb, sizeof(uchar), 1, tfmfile);
  4486.       }
  4487.       tfmhword(0);
  4488.     }
  4489.     tfmword(0);
  4490.     tfmword(fw);
  4491.     if (nw > 2)
  4492.       tfmword(sw);
  4493.     tfmword(0);
  4494.     tfmword(fh);
  4495.     if (nh > 2)
  4496.       tfmword(sh);
  4497.     tfmword(0);
  4498.     tfmword(0);
  4499.     tfmword(0);
  4500.     tfmword(0);
  4501.     if (tfmfile != NULL)
  4502.       fclose(tfmfile);
  4503.     tfmfile = NULL;
  4504.   }
  4505.   /*115:*/
  4506.   sprintf(cmd, "%s.tex", font);
  4507.   strcpy(texfile_NAME, cmd);
  4508.   if (texfile != NULL)
  4509.     texfile = freopen(texfile_NAME, "w", texfile);
  4510.   else
  4511.     texfile = fopen(texfile_NAME, "w");
  4512.   _SETIO(texfile != NULL, FileNotFound);
  4513.   filestat = P_ioresult;
  4514.   if (filestat == 0)
  4515.     fok = false;
  4516.   else
  4517.     fok = true;
  4518.   if (filestat == 5) {
  4519.     *cmd = '\0';
  4520.     sprintf(cmd + strlen(cmd), "%s.tex", font);
  4521.     strcpy(texfile_NAME, cmd);
  4522.     if (texfile != NULL)
  4523.       texfile = freopen(texfile_NAME, "w", texfile);
  4524.     else
  4525.       texfile = fopen(texfile_NAME, "w");
  4526.     _SETIO(texfile != NULL, FileNotFound);
  4527.     filestat = P_ioresult;
  4528.     if (filestat == 0)
  4529.       fok = false;
  4530.     else
  4531.       fok = true;
  4532.   }
  4533.   if (fok) {   /*:115*/
  4534.     printf("%s error occured when allocating TeXfile %s\n", cmd, cmd);
  4535.     fileproblem();
  4536.     goto _L9999;
  4537.   }
  4538.   /*116:*/
  4539.   fprintf(texfile, "\\newbox\\%sbox\n", font);
  4540.   fprintf(texfile, "\\newdimen\\%swd\n", font);
  4541.   FORLIM = noffonts;
  4542.   for (a = 1; a <= FORLIM; a++) {
  4543.     fprintf(texfile, "\\font\\%s%c=%s%c at ",
  4544.         font, fontpre[a - 1], font, fontpre[a - 1]);
  4545.     outfix(tabdsize[a - 1]);
  4546.     fprintf(texfile, "truept\n");
  4547.   }
  4548.   fprintf(texfile, "\\setbox\\%sbox=\\vbox{\\hbox{%%\n", font);
  4549.   a = 0;
  4550.   k = 1;
  4551.   c = 0;
  4552.   i = (mapwidth + hres - 1) / hres;
  4553.   FORLIM = i;
  4554.   for (b = 1; b <= FORLIM; b++) {
  4555.     if (a != k) {
  4556.       fprintf(texfile, "\\%s%c", font, fontpre[k - 1]);
  4557.       a = k;
  4558.     }
  4559.     fprintf(texfile, "\\char%d", c);
  4560.     if ((b & 7) == 0 && b != i)
  4561.       fprintf(texfile, "%%\n");
  4562.     c++;
  4563.     if (c == charpf[k]) {
  4564.       k++;
  4565.       c = 0;
  4566.     }
  4567.   }
  4568.   fprintf(texfile, "}}\n");
  4569.   /*:116*/
  4570.   /*117:*/
  4571.   fprintf(texfile, "\\%swd=\\wd\\%sbox\n", font, font);
  4572.   fprintf(texfile, "\\setbox\\%sbox=\\hbox{\\vbox{\\hsize=\\%swd\n",
  4573.       font, font);
  4574.   fprintf(texfile, "\\parskip=0pt\\offinterlineskip\\parindent0pt\n");
  4575.   v = 1;
  4576.   k = 1;
  4577.   c = 0;
  4578.   FORLIM = nj;
  4579.   for (a = 0; a < FORLIM; a++) {
  4580.     fprintf(texfile, "\\hbox{\\%s%c", font, fontpre[k - 1]);
  4581.     v = k;
  4582.     FORLIM2 = i;
  4583.     for (b = 0; b < FORLIM2; b++) {
  4584.       if (v != k) {
  4585.     fprintf(texfile, "\\%s%c", font, fontpre[k - 1]);
  4586.     v = k;
  4587.       }
  4588.       fprintf(texfile, "\\char%d", c);
  4589.       if (((b + 1) & 7) == 0 && b + 1 != i)
  4590.     fprintf(texfile, "%%\n");
  4591.       c++;
  4592.       if (c == charpf[k]) {
  4593.     k++;
  4594.     c = 0;
  4595.       }
  4596.     }
  4597.     if (a < nj - 1)
  4598.       fprintf(texfile, "}\n");
  4599.   }
  4600.   fprintf(texfile, "}}}\n");
  4601.   fprintf(texfile, "\\ifx\\parbox\\undefined\n");
  4602.   fprintf(texfile, "    \\def\\set%s{\\box\\%sbox}\n", font, font);
  4603.   fprintf(texfile, "\\else\n");
  4604.   fprintf(texfile, "    \\def\\set%s{\\parbox{\\wd\\%sbox}", font, font);
  4605.   fprintf(texfile, "{\\box\\%sbox}}\n", font);
  4606.   fprintf(texfile, "\\fi\n");
  4607.   if (texfile != NULL)
  4608.     fclose(texfile);
  4609.   texfile = NULL;
  4610.   printf("File %s written\n", cmd);   /*:117*/
  4611.   /*106:*/
  4612.   if (pcxtemp)
  4613. /* p2c: bm2font.pas, line 1249: Note: Called procedure Exec [285] */
  4614.     Exec("rm", "pcxtemp.tmp");
  4615.   if (giftemp)
  4616. /* p2c: bm2font.pas, line 1249: Note: Called procedure Exec [285] */
  4617.     Exec("rm", "giftemp.tmp");
  4618.   if (greypxl)
  4619. /* p2c: bm2font.pas, line 1249: Note: Called procedure Exec [285] */
  4620.     Exec("rm", tmpname);
  4621.   printf("input %s.tex into your document", font);
  4622.   printf(" and set the picture with \\set%s\n", font);   /*:106*/
  4623. _L9999:
  4624.   if (texfile != NULL)
  4625.     fclose(texfile);
  4626.   if (bitmap != NULL)
  4627.     fclose(bitmap);
  4628.   if (pxlfile != NULL)
  4629.     fclose(pxlfile);
  4630.   if (tmpfil != NULL)
  4631.     fclose(tmpfil);
  4632.   if (tfmfile != NULL)
  4633.     fclose(tfmfile);
  4634.   exit(EXIT_SUCCESS);
  4635. }  /*:103*/
  4636.  
  4637.  
  4638.  
  4639. /* End. */
  4640.