home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 12 Font / 12-Font.zip / PFMAFM.ZIP / PFB2PFA.C < prev    next >
Text File  |  1991-09-22  |  2KB  |  90 lines

  1. /*****************************************************************************/
  2. /*                                                                           */
  3. /*                               P F B 2 P F A                               */
  4. /*                                                                           */
  5. /*****************************************************************************/
  6.  
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10.  
  11. #define  TXT_BLOCK           0x180
  12. #define  BIN_BLOCK           0x280
  13. #define  EOF_BLOCK           0x380
  14.  
  15. unsigned long  getl (FILE *);
  16. void           do_block (FILE *, FILE *);
  17.  
  18. void main (int argc, char *argv[])
  19. {
  20.    FILE                      *fp;
  21.    FILE                      *ofp;
  22.  
  23.    if (argc != 2)
  24.    {
  25.       printf ("Error dude\n");
  26.       exit (EXIT_FAILURE);
  27.    }
  28.  
  29.    if (NULL == (fp = fopen (argv[1], "rb")))
  30.    {
  31.       perror (argv[1]);
  32.       exit (EXIT_FAILURE);
  33.    }
  34.  
  35.    ofp                       =  stdout;
  36.  
  37.    while (!feof (fp))
  38.       do_block (ofp, fp);
  39.  
  40.    fclose (fp);
  41.    exit (EXIT_SUCCESS);
  42. }
  43.  
  44. void  do_block (FILE *ofp, FILE *ifp)
  45. {
  46.    int                       block_type;
  47.    unsigned long             blk_len;
  48.    int                       ch;
  49.  
  50.    block_type                =  getw (ifp);
  51.    switch (block_type)
  52.    {
  53.    case  TXT_BLOCK:
  54.       blk_len                =  getl (ifp);
  55.       while (blk_len-- > 0)
  56.          fputc (fgetc (ifp), ofp);
  57.       break;
  58.  
  59.    case  BIN_BLOCK:
  60.       blk_len                =  getl (ifp);
  61.       while (blk_len-- > 0)
  62.       {
  63.          ch                  =  fgetc (ifp);
  64.          fprintf (ofp, "%02x", ch);
  65.          if (blk_len % 40 == 0)
  66.             fprintf (ofp, "\n");
  67.       }
  68.       fprintf (ofp, "\n");
  69.       break;
  70.  
  71.    case  EOF_BLOCK:
  72.       while (! feof (ifp))
  73.          fgetc (ifp); 
  74.       break;
  75.  
  76.    default: 
  77.       fprintf (stderr, "Unknown block type 0x%04x\n", block_type);
  78.       exit (EXIT_FAILURE);
  79.    }
  80. }
  81.  
  82.  
  83. unsigned long  getl (FILE *fp)
  84. {
  85.    unsigned long             ul;
  86.  
  87.    fread (&ul, 1, 4, fp);
  88.    return (ul);
  89. }
  90.