home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: DFÜ und Kommunikation / SOS-DFUE.ISO / programm / dos / utility / pccp076 / asctosfx.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-25  |  16.3 KB  |  776 lines

  1. #include<stdio.h>
  2. #include<fcntl.h>
  3. #include<sys/types.h>
  4. #include<sys\stat.h>
  5. #include"fxf.h"
  6.  
  7. /* These are kinda historical; see main() near top. */
  8. #define INDENT 64
  9. #define NCOLUMNS 80
  10. #define NPGLINES 66
  11.  
  12. struct
  13.     {
  14.     unsigned bits;
  15.     unsigned mask;
  16.     }
  17.     whites[]=
  18.         {
  19.         {0x00ac, 0x00ff},
  20.         {0x0038, 0x003f},
  21.         {0x000e, 0x000f},
  22.         {0x0001, 0x000f},
  23.         {0x000d, 0x000f},
  24.         {0x0003, 0x000f},
  25.         {0x0007, 0x000f},
  26.         {0x000f, 0x000f},
  27.         {0x0019, 0x001f},
  28.         {0x0005, 0x001f},
  29.         {0x001c, 0x001f},
  30.         {0x0002, 0x001f},
  31.         {0x0004, 0x003f},
  32.         {0x0030, 0x003f},
  33.         {0x000b, 0x003f},
  34.         {0x002b, 0x003f},
  35.         {0x0015, 0x003f},
  36.         {0x0035, 0x003f},
  37.         {0x0072, 0x007f},
  38.         {0x0018, 0x007f},
  39.         {0x0008, 0x007f},
  40.         {0x0074, 0x007f},
  41.         {0x0060, 0x007f},
  42.         {0x0010, 0x007f},
  43.         {0x000a, 0x007f},
  44.         {0x006a, 0x007f},
  45.         {0x0064, 0x007f},
  46.         {0x0012, 0x007f},
  47.         {0x000c, 0x007f},
  48.         {0x0040, 0x00ff},
  49.         {0x00c0, 0x00ff},
  50.         {0x0058, 0x00ff},
  51.         {0x00d8, 0x00ff},
  52.         {0x0048, 0x00ff},
  53.         {0x00c8, 0x00ff},
  54.         {0x0028, 0x00ff},
  55.         {0x00a8, 0x00ff},
  56.         {0x0068, 0x00ff},
  57.         {0x00e8, 0x00ff},
  58.         {0x0014, 0x00ff},
  59.         {0x0094, 0x00ff},
  60.         {0x0054, 0x00ff},
  61.         {0x00d4, 0x00ff},
  62.         {0x0034, 0x00ff},
  63.         {0x00b4, 0x00ff},
  64.         {0x0020, 0x00ff},
  65.         {0x00a0, 0x00ff},
  66.         {0x0050, 0x00ff},
  67.         {0x00d0, 0x00ff},
  68.         {0x004a, 0x00ff},
  69.         {0x00ca, 0x00ff},
  70.         {0x002a, 0x00ff},
  71.         {0x00aa, 0x00ff},
  72.         {0x0024, 0x00ff},
  73.         {0x00a4, 0x00ff},
  74.         {0x001a, 0x00ff},
  75.         {0x009a, 0x00ff},
  76.         {0x005a, 0x00ff},
  77.         {0x00da, 0x00ff},
  78.         {0x0052, 0x00ff},
  79.         {0x00d2, 0x00ff},
  80.         {0x004c, 0x00ff},
  81.         {0x00cc, 0x00ff},
  82.         {0x002c, 0x00ff},
  83.         {0x001b, 0x001f},
  84.         {0x0009, 0x001f},
  85.         {0x003a, 0x003f},
  86.         {0x0076, 0x007f},
  87.         {0x006c, 0x00ff},
  88.         {0x00ec, 0x00ff},
  89.         {0x0026, 0x00ff},
  90.         {0x00a6, 0x00ff},
  91.         {0x0016, 0x00ff},
  92.         {0x00e6, 0x00ff},
  93.         {0x0066, 0x01ff},
  94.         {0x0166, 0x01ff},
  95.         {0x0096, 0x01ff},
  96.         {0x0196, 0x01ff},
  97.         {0x0056, 0x01ff},
  98.         {0x0156, 0x01ff},
  99.         {0x00d6, 0x01ff},
  100.         {0x01d6, 0x01ff},
  101.         {0x0036, 0x01ff},
  102.         {0x0136, 0x01ff},
  103.         {0x00b6, 0x01ff},
  104.         {0x01b6, 0x01ff},
  105.         {0x0032, 0x01ff},
  106.         {0x0132, 0x01ff},
  107.         {0x00b2, 0x01ff},
  108.         {0x0006, 0x003f},
  109.         {0x01b2, 0x01ff}
  110.         },
  111.     blacks[]=
  112.         {
  113.         {0x03b0, 0x03ff},
  114.         {0x0002, 0x0007},
  115.         {0x0003, 0x0003},
  116.         {0x0001, 0x0003},
  117.         {0x0006, 0x0007},
  118.         {0x000c, 0x000f},
  119.         {0x0004, 0x000f},
  120.         {0x0018, 0x001f},
  121.         {0x0028, 0x003f},
  122.         {0x0008, 0x003f},
  123.         {0x0010, 0x007f},
  124.         {0x0050, 0x007f},
  125.         {0x0070, 0x007f},
  126.         {0x0020, 0x00ff},
  127.         {0x00e0, 0x00ff},
  128.         {0x0030, 0x01ff},
  129.         {0x03a0, 0x03ff},
  130.         {0x0060, 0x03ff},
  131.         {0x0040, 0x03ff},
  132.         {0x0730, 0x07ff},
  133.         {0x00b0, 0x07ff},
  134.         {0x01b0, 0x07ff},
  135.         {0x0760, 0x07ff},
  136.         {0x00a0, 0x07ff},
  137.         {0x0740, 0x07ff},
  138.         {0x00c0, 0x07ff},
  139.         {0x0530, 0x0fff},
  140.         {0x0d30, 0x0fff},
  141.         {0x0330, 0x0fff},
  142.         {0x0b30, 0x0fff},
  143.         {0x0160, 0x0fff},
  144.         {0x0960, 0x0fff},
  145.         {0x0560, 0x0fff},
  146.         {0x0d60, 0x0fff},
  147.         {0x04b0, 0x0fff},
  148.         {0x0cb0, 0x0fff},
  149.         {0x02b0, 0x0fff},
  150.         {0x0ab0, 0x0fff},
  151.         {0x06b0, 0x0fff},
  152.         {0x0eb0, 0x0fff},
  153.         {0x0360, 0x0fff},
  154.         {0x0b60, 0x0fff},
  155.         {0x05b0, 0x0fff},
  156.         {0x0db0, 0x0fff},
  157.         {0x02a0, 0x0fff},
  158.         {0x0aa0, 0x0fff},
  159.         {0x06a0, 0x0fff},
  160.         {0x0ea0, 0x0fff},
  161.         {0x0260, 0x0fff},
  162.         {0x0a60, 0x0fff},
  163.         {0x04a0, 0x0fff},
  164.         {0x0ca0, 0x0fff},
  165.         {0x0240, 0x0fff},
  166.         {0x0ec0, 0x0fff},
  167.         {0x01c0, 0x0fff},
  168.         {0x0e40, 0x0fff},
  169.         {0x0140, 0x0fff},
  170.         {0x01a0, 0x0fff},
  171.         {0x09a0, 0x0fff},
  172.         {0x0d40, 0x0fff},
  173.         {0x0340, 0x0fff},
  174.         {0x05a0, 0x0fff},
  175.         {0x0660, 0x0fff},
  176.         {0x0e60, 0x0fff},
  177.         {0x03c0, 0x03ff},
  178.         {0x0130, 0x0fff},
  179.         {0x0930, 0x0fff},
  180.         {0x0da0, 0x0fff},
  181.         {0x0cc0, 0x0fff},
  182.         {0x02c0, 0x0fff},
  183.         {0x0ac0, 0x0fff},
  184.         {0x06c0, 0x1fff},
  185.         {0x16c0, 0x1fff},
  186.         {0x0a40, 0x1fff},
  187.         {0x1a40, 0x1fff},
  188.         {0x0640, 0x1fff},
  189.         {0x1640, 0x1fff},
  190.         {0x09c0, 0x1fff},
  191.         {0x19c0, 0x1fff},
  192.         {0x05c0, 0x1fff},
  193.         {0x15c0, 0x1fff},
  194.         {0x0dc0, 0x1fff},
  195.         {0x1dc0, 0x1fff},
  196.         {0x0940, 0x1fff},
  197.         {0x1940, 0x1fff},
  198.         {0x0540, 0x1fff},
  199.         {0x1540, 0x1fff},
  200.         {0x0b40, 0x1fff},
  201.         {0x1b40, 0x1fff},
  202.         {0x04c0, 0x1fff},
  203.         {0x14c0, 0x1fff}
  204.         };
  205.  
  206. #define SFXBUFSIZ 4096
  207.  
  208. unsigned char sfxbuf[SFXBUFSIZ];
  209.  
  210. int sfxfd, sfxbufi;
  211.  
  212. putbyte(pbb)
  213.     unsigned char pbb;
  214.     {
  215.     sfxbuf[sfxbufi++]=pbb;
  216.     if(sfxbufi>=SFXBUFSIZ)
  217.         {
  218.         if(write(sfxfd, sfxbuf, SFXBUFSIZ)!=SFXBUFSIZ)\
  219.             {
  220.             printf("Write error.\n");
  221.             exit(1);
  222.             }
  223.         sfxbufi=0;
  224.         }
  225.     }
  226.  
  227. flush()
  228.     {
  229.     if(write(sfxfd, sfxbuf, sfxbufi)!=sfxbufi)
  230.         {
  231.         printf("Write error on explicit flush.\n");
  232.         exit(2);
  233.         }
  234.     sfxbufi=0; /* Left this out earlier. Gott in Himmel! */
  235.     }
  236.  
  237. unsigned char wkngbyte, wbmask;
  238.  
  239. putsym(bitsw, maskw)
  240.     unsigned bitsw, maskw;
  241.     {
  242.     unsigned srcmask;
  243.     for(srcmask=1;srcmask&maskw;srcmask<<=1)
  244.         {
  245.         if(bitsw&srcmask)
  246.             wkngbyte|=wbmask;
  247.         if(!(wbmask<<=1))
  248.             {
  249.             if(wkngbyte==0x10)
  250.                 putbyte(0x10); /* Shield DLE */
  251.             putbyte(wkngbyte);
  252.             wkngbyte=0;
  253.             wbmask=0x01;
  254.             }
  255.         }
  256.     }
  257.  
  258. flushsym()
  259.     {
  260.     if(wbmask!=0x01)
  261.         {
  262.         if(wkngbyte==0x10)
  263.             putbyte(0x10); /* Shield DLE */
  264.         putbyte(wkngbyte);
  265.         }
  266.     }
  267.  
  268. initsym()
  269.     {
  270.     wkngbyte=0;
  271.     wbmask=0x01;
  272.     }
  273.  
  274. putwhite(n)
  275.     int n;
  276.     {
  277.     int m;
  278.     if((n<0)||(n>1728))
  279.         {
  280.         printf("\nProbable code error; bad white run length %d.\n", n);
  281.         exit(71);
  282.         }
  283.     if(m=(n&~63))
  284.         {
  285.         m>>=6;
  286.         m+=63;
  287.         putsym(whites[m].bits, whites[m].mask);
  288.         }
  289.     m=n&63;
  290.     putsym(whites[m].bits, whites[m].mask);
  291.     }
  292.  
  293. putblack(n)
  294.     int n;
  295.     {
  296.     int m;
  297.     if((n<0)||(n>1728))
  298.         {
  299.         printf("\nProbable code error, bad black run length %d.\n", n);
  300.         exit(72);
  301.         }
  302.     if(m=(n&~63))
  303.         {
  304.         m>>=6;
  305.         m+=63;
  306.         putsym(blacks[m].bits, blacks[m].mask);
  307.         }
  308.     m=n&63;
  309.     putsym(blacks[m].bits, blacks[m].mask);
  310.     }
  311.  
  312. unsigned char font[FXF_NCHARS][FXF_NROWS][FXF_NBYTES];
  313.  
  314. loadfont(fname)
  315.     {
  316.     int fxffd;
  317.     unsigned fnbytes;
  318.     if((fxffd=open(fname, O_RDONLY|O_BINARY))==-1)
  319.         {
  320.         printf("Error opening font file %s.\n", fname);
  321.         exit(30);
  322.         }
  323.     fnbytes=FXF_NCHARS*FXF_NROWS*FXF_NBYTES;
  324.     if(read(fxffd, font, fnbytes)!=fnbytes)
  325.         {
  326.         printf("Error reading in font file %s.\n", fname);
  327.         exit(31);
  328.         }
  329.     close(fxffd);
  330.     }
  331.  
  332. /* If you look at the arg types, you'll notice "line" means text, not scan */
  333. /* Now remember, you might or might not get the \n in line */
  334.  
  335. convertline(line, indent)
  336.     unsigned char *line;
  337.     int indent;
  338.     {
  339.     int row, byte, white, value, pixcnt, charpixcnt;
  340.     unsigned char *cptr;
  341.     for(row=0;row<FXF_NROWS;row++)
  342.         {
  343.         pixcnt=0;
  344.         white=indent;
  345.         for(cptr=line;(*cptr)!=0xff;cptr++)
  346.             {
  347.             charpixcnt=0;
  348.             if((*cptr)<0xfe);
  349.                 {
  350.                 for(byte=0;byte<FXF_NBYTES;byte++)
  351.                     {
  352.                     if(value=font[*cptr][row][byte])
  353.                         {
  354.                         if(byte&1)
  355.                             {
  356.                             putwhite(white);
  357.                             pixcnt+=white;
  358.                             white=0;
  359.                             putblack(value);
  360.                             pixcnt+=value;
  361.                             charpixcnt+=value;
  362.                             }
  363.                         else
  364.                             {
  365.                             white+=value;
  366.                             charpixcnt+=value;
  367.                             }
  368.                         }
  369.                     else if(byte)
  370.                         break;
  371.                     }
  372.                 }
  373.             white+=FXF_LEADING+FXF_WIDTH-charpixcnt;
  374.             }
  375.         putwhite(1728-pixcnt);
  376.         flushsym();
  377.         putbyte(0x00);
  378.         putbyte(0x80);
  379.         initsym();
  380.         }
  381.     }
  382.  
  383. struct header_s
  384.     {
  385.     unsigned char mfgr;
  386.     unsigned char version;
  387.     unsigned char encoding;
  388.     unsigned char bppix;
  389.     unsigned short xmin;
  390.     unsigned short ymin;
  391.     unsigned short xmax;
  392.     unsigned short ymax;
  393.     unsigned short hdpi;
  394.     unsigned short vdpi;
  395.     unsigned char cmap[48];
  396.     unsigned char reserved;
  397.     unsigned char nplanes;
  398.     unsigned short bypl;
  399.     unsigned short paltinf;
  400.     unsigned short hscrnsz;
  401.     unsigned short vscrnsz;
  402.     unsigned char filler[54];
  403.     };
  404.  
  405. struct header_s header;
  406.  
  407. #define PCXBBUFSIZ 4096
  408.  
  409. unsigned char pcxbbuf[PCXBBUFSIZ];
  410.  
  411. int pcxfd, pcxbi, pcxbn;
  412.  
  413. int getpcxb()
  414.     {
  415.     if(pcxbi>=pcxbn)
  416.         if((pcxbn=read(pcxfd, pcxbbuf, PCXBBUFSIZ))<=0)
  417.             {
  418.             printf("\nPremature end of PCX file. Aborting.\n");
  419.             exit(101);
  420.             }
  421.         else
  422.             pcxbi=0;
  423.     return(pcxbbuf[pcxbi++]);
  424.     }
  425.  
  426. int ncolumns, npglines, toppad, pageline, pagenum;
  427. unsigned char pcxline[256];
  428.  
  429. int convertpcx(char *imagename, int indent) /* "imagename" is historical */
  430.     {
  431.     char *inp;
  432.     int height, width;
  433.     int accum, whitep, pcxindent, bpl, pli, npix, cnt;
  434.     unsigned char b, b1, mask, *bptr, just;
  435.     inp=imagename;
  436.     if(imagename[1]==' ')
  437.         if(imagename[0]=='-')
  438.             {
  439.             inp+=2;
  440.             just='-';
  441.             }
  442.         else if(imagename[0]=='+')
  443.             {
  444.             inp+=2;
  445.             just='+';
  446.             }
  447.         else;
  448.     else
  449.         just='0';
  450.     printf("\nPCX file %s; scan lines remaining: ", imagename);
  451.     if((pcxfd=open(inp, O_RDONLY|O_BINARY))<0)
  452.         {
  453.         printf("Error\nUnable to open PCX file %s. Aborting.\n", inp);
  454.         exit(102);
  455.         }
  456.     pcxbi=pcxbn=0;
  457.     if(read(pcxfd, &header, sizeof(header))!=sizeof(header))
  458.         {
  459.         printf("Error\nError reading PCX header from file %s. Aborting.\n", inp);
  460.         exit(103);
  461.         }
  462.     if(header.nplanes!=1)
  463.         {
  464.         printf("Error\n");
  465.         printf("The PCX image %s has multiple planes.\n", inp);
  466.         printf("Only one is relevant, so only one is permitted.\n");
  467.         printf("When you fix it, make sure it isn't grayscale either.\n");
  468.         printf("Aborting.\n");
  469.         exit(104);
  470.         }
  471.     if(header.bppix!=1)
  472.         {
  473.         printf("Error\nThe PCX image %s is grayscale.\n", inp);
  474.         printf("We don't do grayscale. Aborting.\n");
  475.         exit(105);
  476.         }
  477.     height=header.ymax+1-header.ymin;
  478.     width=header.xmax+1-header.xmin;
  479.     if(height>(npglines*FXF_NROWS))
  480.         {
  481.         printf("Error\nThe PCX image %s is too tall. Aborting.\n", inp);
  482.         exit(106);
  483.         }
  484.     if(width>(ncolumns*(FXF_WIDTH+FXF_LEADING)))
  485.         {
  486.         printf("Error\nThe PCX image %s is too wide. Aborting.\n", inp);
  487.         exit(107);
  488.         }
  489.     if(((npglines+1-pageline)*FXF_NROWS)<height) /* Need page break */
  490.         {
  491.         for(cnt=0;cnt<toppad;cnt++)
  492.             convertline("\377", 0);
  493.         pageline=1;
  494.         flushsym();
  495.         flush();       /* More neat trick */
  496.         putbyte(0x10); /* i.e. we can rewind this here */
  497.         putbyte(0x03); /* Not sure we need to here, actually... */
  498.         putbyte(0x00);
  499.         putbyte(0x80);
  500.         initsym();
  501.         pagenum++;
  502.         for(cnt=0;cnt<toppad;cnt++)
  503.             convertline("\377", 0);
  504.         }
  505.     pageline+=height/FXF_NROWS;
  506.     if(height%FXF_NROWS)
  507.         pageline++;
  508.     if(just=='-')
  509.         pcxindent=indent; /* line up for pretty mode */
  510.     else if(just=='+')
  511.         pcxindent=1728-width;        /* I can't imagine what people */
  512.     else                     /* will do with +, but I'd be */
  513.         pcxindent=(1728-width)/2;    /* a twit to save the 2 lines. */
  514.     bpl=header.bypl;             /* Can't think how to indent. */
  515.     /* Don't think we need to flushsym() */
  516.     pli=0;
  517.     printf("%-5d", height);
  518.     while(1)
  519.         {
  520.         b=getpcxb();
  521.         if((b&0xc0)==0xc0) /* God, I'm getting sick of compression! */
  522.             {
  523.             b1=getpcxb();
  524.             b&=0x3f;
  525.             while(b--)
  526.                 pcxline[pli++]=b1;
  527.             }
  528.         else
  529.             pcxline[pli++]=b;
  530.         if(pli<bpl)
  531.             continue;
  532.         /* EOL */
  533.         accum=pcxindent;
  534.         whitep=1;
  535.         mask=0x80;
  536.         npix=pli=0;
  537.         bptr=pcxline;
  538.         for(cnt=width;--cnt;) /* Really seems wrong but cnt-- gave */
  539.             {             /* a black stripe on the right side */
  540.             if(mask==0x01)
  541.                 {
  542.                 bptr++;
  543.                 mask=0x80;
  544.                 }
  545.             else
  546.                 mask>>=1;
  547.             if(whitep)
  548.                 if((*bptr)&mask) /* 1, therefore white (PCX)*/
  549.                     accum++;
  550.                 else
  551.                     {
  552.                     putwhite(accum);
  553.                     npix+=accum;
  554.                     accum=1; /* Was 0 for a while. Duh! */
  555.                     whitep=0;
  556.                     }
  557.             else
  558.                 if((*bptr)&mask)
  559.                     {
  560.                     putblack(accum);
  561.                     npix+=accum;
  562.                     accum=1;
  563.                     whitep=1;
  564.                     }
  565.                 else
  566.                     accum++;
  567.             }
  568.         if(!whitep)
  569.             {
  570.             putblack(accum);
  571.             npix+=accum;
  572.             }
  573.         putwhite(1728-npix);
  574.         flushsym();
  575.         putbyte(0x00);
  576.         putbyte(0x80);
  577.         initsym();
  578.         printf("\b\b\b\b\b%-5d", height);
  579.         if((--height)<=0) /* Had an amusing fencepost error here; */
  580.             break;    /* we've already done the loop! */
  581.         }
  582.     printf("\n");
  583.     flush();
  584.     close(pcxfd);
  585.     }
  586.  
  587. /* NOTE: We flush before DLE-ETX at page breaks, and assume a
  588.  *       big enough buffer that all initial page overhead fits.
  589.  *       This way, if we later realize that the last page is empty,
  590.  *       we just discard the buffer (sfxbufi=0). Handy, eh what?
  591.  */
  592.  
  593. main(argc, argv)
  594.     int argc;
  595.     char **argv;
  596.     {
  597.     FILE *ascfd;
  598.     unsigned char line[256], ffn[256];
  599.     int column, c;
  600.     int indent, i;
  601.     if(argc<3)
  602.         {
  603.         printf("USAGE: asctosfx <ascii file> <sfx file> [/p]\n");
  604.         printf("/p is pretty, i.e. H & V margins.\n");
  605.         printf("Control-L (FormFeed) is recognized.\n");
  606.         printf("Tabs (Control-I) are modulo 8.\n");
  607.         printf("Control-P <pathname> <newline> inserts PCX. Must occur on a line by itself.\n");
  608.         printf("PCX default is centered.\n");
  609.         printf("<pathname> beginning with -<SP> is flush left, +<SP> is flush right.\n");
  610.         printf("OUTPUT IS HIGH RESOLUTION!!! (Fine / 192 lpi)\n");
  611.         exit(2);
  612.         }
  613.     if((ascfd=fopen(argv[1], "r"))==NULL)
  614.         {
  615.         printf("Error opening text input file %s.\n", argv[1]);
  616.         exit(4);
  617.         }
  618.     if(getenv("PCCPFROM")==NULL)
  619.         {
  620.         printf("\nYour PCCPFROM environment variable is not set, which will result in\n");
  621.         printf("a transmission that we believe may be unlawful under USA FCC regulations.\n");
  622.         printf("\nThis variable is only actually used at send time. See MANUAL.\n\n");
  623.         printf("If you are not in the USA, we apologize for this disgusting display\n");
  624.         printf("of national Chauvinism.\n\n");
  625.         }
  626.     if(getenv("PCCPPATH")==NULL)
  627.         strcpy(ffn, FXF_FILENAME);
  628.     else
  629.         sprintf(ffn, "%s\\%s", getenv("PCCPPATH"), FXF_FILENAME);
  630.     sfxbufi=0;
  631.     loadfont(ffn);
  632.     if((sfxfd=open(argv[2], O_WRONLY|O_BINARY|O_CREAT|O_TRUNC, S_IWRITE))==-1)
  633.         {
  634.         printf("Error opening output file %s.\n", argv[2]);
  635.         exit(3);
  636.         }
  637.     if(argc>3)
  638.         {
  639.         toppad=3;
  640.         indent=INDENT+80;
  641.         ncolumns=NCOLUMNS-8;
  642.         npglines=NPGLINES-6;
  643.         }
  644.     else
  645.         {
  646.         toppad=0;
  647.         indent=INDENT;
  648.         ncolumns=NCOLUMNS;
  649.         npglines=NPGLINES;
  650.         }
  651.     sfxbufi=0;
  652.     pagenum=1;
  653.     putbyte(0x00);
  654.     putbyte(0x80);
  655.     initsym();
  656.     for(i=0;i<toppad;i++)
  657.         convertline("\377", 0);
  658.     printf("\nBeginning to convert %s to %s", argv[1], argv[2]);
  659.     if(argc>3)
  660.         printf(" with pretty margins.\n");
  661.     else
  662.         printf(" in raw mode.\n");
  663.     pageline=1;
  664.     column=0;
  665.     while(1)
  666.         {
  667.         c=getc(ascfd);
  668.         if((c==EOF)||(c==0x0c))
  669.             {
  670.             if(line[0]!=0xff)
  671.                 {
  672.                 /* pageline++ 'cause we use as flag at end. */
  673.                 printf("\rLine %2d of Page %d", pageline++, pagenum);
  674.                 line[column]=0xff;
  675.                 convertline(line, indent);
  676.                 line[0]=0xff;
  677.                 column=0;
  678.                 }
  679.             for(i=0;i<toppad;i++)
  680.                 convertline("\377", 0);
  681.             if(c==EOF)
  682.                 break;
  683.             pageline=1;
  684.             flushsym();
  685.             flush(); /* Above-mentioned neat trick */
  686.             putbyte(0x10); /* i.e. we can rewind this here */
  687.             putbyte(0x03);
  688.             putbyte(0x00);
  689.             putbyte(0x80);
  690.             initsym();
  691.             pagenum++;
  692.             for(i=0;i<toppad;i++)
  693.                 convertline("\377", 0);
  694.             }
  695.         else
  696.             {
  697.             if(c==('P'&31))
  698.                 {
  699.                 /* If this ain't at beginning of line,
  700.                  * you lose the line, 'cause that's
  701.                  * what's easy to code!
  702.                  */
  703.                 fgets(line, 255, ascfd);
  704.                 line[strlen(line)-1]='\0';
  705.                 convertpcx(line, indent);
  706.                 line[0]=0xff;
  707.                 column=0; /* What a pity! */
  708.                 if(pageline>=npglines)
  709.                     {
  710.                     for(i=0;i<toppad;i++)
  711.                         convertline("\377", 0);
  712.                     pageline=1;
  713.                     putbyte(0x10);
  714.                     putbyte(0x03);
  715.                     putbyte(0x00);
  716.                     putbyte(0x80);
  717.                     for(i=0;i<toppad;i++)
  718.                         convertline("\377", 0);
  719.                     printf("\rLine %2d of page %d",
  720.                         1, ++pagenum);
  721.                     }
  722.                 }
  723.             else if(c=='\t')
  724.                 do
  725.                     line[column++]=0xfe;
  726.                 while((column&0x0007)&&(column<ncolumns));
  727.             else if(c==' ')
  728.                 line[column++]=0xfe;
  729.             else if(c!='\n')
  730.                 if((c>=FXF_FIRSTCHAR)&&(c<(FXF_FIRSTCHAR+FXF_NCHARS)))
  731.                     line[column++]=c-FXF_FIRSTCHAR;
  732.                 else
  733.                     printf("\nBad character Hex %02x skipped.\n", c);
  734.             /* DEBUG ONLY *
  735.             if(column>ncolumns)
  736.                 {
  737.                 printf("\nColumn bad value: %d\n", column);
  738.                 exit(99);
  739.                 }
  740.             * END DEBUG ONLY */
  741.             if((c=='\n')||(column>=ncolumns))
  742.                 {
  743.                 line[column]=0xff;
  744.                 printf("\rLine %2d of Page %d", pageline++, pagenum);
  745.                 convertline(line, indent);
  746.                 line[0]=0xff;
  747.                 column=0;
  748.                 if(pageline>=npglines)
  749.                     {
  750.                     for(i=0;i<toppad;i++)
  751.                         convertline("\377", 0);
  752.                     pageline=1;
  753.                     flushsym();
  754.                     flush(); /* More neat trick */
  755.                     putbyte(0x10);
  756.                     putbyte(0x03);
  757.                     putbyte(0x00);
  758.                     putbyte(0x80);
  759.                     initsym();
  760.                     pagenum++;
  761.                     for(i=0;i<toppad;i++)
  762.                         convertline("\377", 0);
  763.                     }
  764.                 }
  765.             }
  766.         }
  767.     flushsym();
  768.     if(pageline==1)
  769.         sfxbufi=0; /* Discard empty page overhead from buffer. */
  770.     putbyte(0x10);
  771.     putbyte(0x04);
  772.     fclose(ascfd);
  773.     flush();
  774.     close(sfxfd);
  775.     }
  776.