Back to index

tetex-bin  3.0
Defines | Functions
pfb2pfa.c File Reference
#include <stdarg.h>
#include <stdio.h>
#include "basics.h"
#include "filenames.h"

Go to the source code of this file.

Defines

#define NEWLINE   '\n'
#define HEX_PER_LINE   30

Functions

int main (int argc, char *argv[])

Define Documentation

#define HEX_PER_LINE   30

Definition at line 31 of file pfb2pfa.c.

#define NEWLINE   '\n'

Definition at line 28 of file pfb2pfa.c.


Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 33 of file pfb2pfa.c.

{  unsigned int t, l, i;
 unsigned int l1, l2, l3, l4; 
   short c, done, verbose = 0;
   FILE *pfb, *pfa;
   char *pfbname, *pfaname = NULL, *myname = "pfb2pfa";

   /* prototypes */
   void fatal(char *fmt, ...);

   while (--argc > 0 && (*++argv)[0] == '-') {
      done=0;
      while ((!done) && (c = *++argv[0]))  /* allow -bcK like options */
        switch (c) {
        case 'v':
           verbose = 1; break;
        default:
           fatal("%s: %c illegal option\n", myname, c);
        }
      }

   if (argc < 1) fatal("Usage: %s [-v] pfbfile [pfafile]\n", myname);
   
   pfbname = argv[0]; argc--; argv++;
   if (argc < 1) pfaname = newname(pfbname, ".pfa");
   else if (argc == 1) pfaname = argv[0];
   else fatal("Usage: %s [-v] pfbfile [pfafile]\n", myname);

   pfb = fopen(pfbname, RB);
   if (pfb == NULL) fatal("Can't open %s\n", pfbname);
   
   pfa = fopen(pfaname, WB);
   if (pfa == NULL) fatal("Can't open %s\n", pfaname);
   
   while(!feof(pfb)) {
      if (getc(pfb) != 128)
        fatal("%s: not a pfb file.\n", pfbname);
      t = getc(pfb);
      if (verbose) printf("Type: %d, ", t);
      switch (t) {
      case 1:
#if 1
       l1 = getc(pfb); l2 = getc(pfb); l3 = getc(pfb); l4 = getc(pfb); 
       l = l1 | l2 << 8 | l3 << 16 | l4 << 24;
       /* printf("%2x %2x %2x %2x -> %x\n", l1, l2, l3, l4, l); */
#else
       l = (getc(pfb)) | (getc(pfb)<<8) | (getc(pfb)<<16) | (getc(pfb)<<24);
#endif
         if (verbose) printf(" plain text, length %d\n", l);
        for (i=0; i < l ; i++) {
            c = getc(pfb);
            if (c == '\r') putc(NEWLINE, pfa);
            else putc(c, pfa);
         }
         break;
      case 2:
#if 1
       l1 = getc(pfb); l2 = getc(pfb); l3 = getc(pfb); l4 = getc(pfb); 
       l = l1 | l2 << 8 | l3 << 16 | l4 << 24;
       /* printf("%2x %2x %2x %2x -> %x\n", l1, l2, l3, l4, l); */
#else
       l = (getc(pfb)) | (getc(pfb)<<8) | (getc(pfb)<<16) | (getc(pfb)<<24);
#endif
         if (verbose) printf(" binary data, length %d\n", l);
         for(i = 0; i < l ;i++) {
           fprintf(pfa, "%02x", getc(pfb));
           if ((i+1) % HEX_PER_LINE == 0) putc(NEWLINE, pfa);
        }
        putc(NEWLINE, pfa);
         break;
      case 3:
         if (verbose) printf("End of file\n");
         exit(0);
         break;
      default:
        fatal("Unknown field type: %d\n", t);
      }
   }
   fclose(pfa); fclose(pfb);
   return 0;
}

Here is the call graph for this function: