Back to index

tetex-bin  3.0
Functions
pk2bm.c File Reference
#include <stdio.h>
#include "pkin.h"

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
quarterword lsbf (quarterword u)
void dots (quarterword u, int n)
int atoo (char *oct)

Function Documentation

int atoo ( char *  oct)

Definition at line 202 of file pk2bm.c.

{  int octal = 0;
   while (*oct != '\0') octal = 8*octal + (*oct++) - '0';
   return octal & 0xff;
}

Here is the caller graph for this function:

void dots ( quarterword  u,
int  n 
)

Definition at line 190 of file pk2bm.c.

{  unsigned int bit;

   bit=1<<7;
   for ( ;n>0 ;n--) {
      if (u & bit) putchar('*');
      else putchar('.');
      bit>>=1;
   }
}

Here is the caller graph for this function:

Definition at line 174 of file pk2bm.c.

{
       int i; quarterword bit, result = 0;

       for (i=0; i<8; i++) {
          bit = u & 001;
          result = (result<<1) | bit;
          u = u >> 1;
       }
       return result;
}

Here is the caller graph for this function:

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

Definition at line 36 of file pk2bm.c.

{
   int done, C = 0, c, h = 0, w = 0, row, col;
   unsigned int bitmap = 0, hexmap = 0;
   halfword *word;
   quarterword lsbf();
   void dots();
   chardesc cd;
   char *myname = "pk2bm", *pkname;
   int atoo(char *);
       
   while (--argc > 0 && (*++argv)[0] == '-') {
      done=0;
      while ((!done) && (c = *++argv[0])) /* allow -bcK as an option */
         switch (c) {
        case 'c':
           if (*++argv[0] == '\0') {
              argc--;  argv++;
           }
           C = *argv[0];
           done = 1; break;
        case 'o':
           if (*++argv[0] == '\0') {
              argc--;  ++argv;
           }
           C = atoo(argv[0]);
           done = 1; break;
        case 'H':
           if (*++argv[0] == '\0') {
              argc--; argv++;
           }
           h = atoi(argv[0]);
            done=1;
           break;
        case 'W':
           if (*++argv[0] == '\0') {
              argc--; argv++;
           }
           w = atoi(argv[0]);
           done=1;
           break;
        case 'b':
           bitmap = 1;
           break;
        case 'h':
           hexmap = 1;
           break;
        default:
           printf("%s: %c illegal option\n", myname, c);
           exit(1);
        }
   }

   if (argc == 0) {
      printf("Usage: %s [-bh] {-c char|-o octchar} [-W width -H height] pkfile\n", myname);
      exit(1);
   }

   pkname = argv[0];

   if (readchar(pkname, C, &cd)) {
      int H, dh, W, dw, bitsleft;
      halfword nextword; quarterword nextbyte;

      H=cd.cheight; if (h==0) h=H; dh=(h-H)/2;
      W=cd.cwidth; if (w==0) w=W; dw=(w-W)/2;
          
      if (bitmap || hexmap) {
         printf("character : %d (%c)\n", (int) cd.charcode, 
                (char)cd.charcode);
         printf("   height : %d\n", (int) cd.cheight);
         printf("    width : %d\n", (int) cd.cwidth);
         printf("     xoff : %d\n", (int) cd.xoff);
         printf("     yoff : %d\n", (int) cd.yoff);
      }
      else {
         printf("#define %s_%c_width \t %d\n",
              pkname, (char)cd.charcode, (int) w);
         printf("#define %s_%c_height \t %d\n",
              pkname, (char)cd.charcode, (int) h);
         printf("#define %s_%c_xoff \t %d\n",
              pkname, (char)cd.charcode, (int) dw);
         printf("#define %s_%c_yoff \t %d\n",
              pkname, (char)cd.charcode, (int) dh);
         printf("static char %s_%c_bits[] = {", 
             pkname, (char)cd.charcode);
      }
      for (row=0; row<h-H-dh; row++) {
          printf("\n  ");
          for (col=0; col<w; col+=8)
             if (bitmap) dots(0, w-col>7? 8: w-col);
             else if (hexmap) printf("%02x", 0x00);
             else printf(" 0x%02x, ", 0x00);
      }
      word = cd.raster;
      for (row=h-H-dh; row<h-dh; row++) {
         bitsleft = dw; nextword = 0;
         printf("\n  ");
         for (col=0; col<w; col+=8) {
            if (bitsleft>=8) {
               nextbyte = nextword >> (bitsleft-8) & 0xff;
              bitsleft-=8;
              
               if (bitmap) dots(nextbyte, w-col>7? 8: w-col); 
               else if (hexmap) printf("%02x", nextbyte);
               else printf(" 0x%02x, ", lsbf(nextbyte));
           }
           else {
              nextbyte = nextword << (8-bitsleft) & 0xff;
              if (col-dw<W)
                 nextword=(*word++);
              else nextword=0;
              nextbyte = nextbyte | (nextword >> (16-(8-bitsleft))
                                         & 0xff);
              bitsleft = 16 - (8-bitsleft);
              
               if (bitmap) dots(nextbyte, w-col>7? 8: w-col);
               else if (hexmap) printf("%02x", nextbyte);
               else printf(" 0x%02x, ", lsbf(nextbyte));
           }
        }
      }
      for (row=h-dh; row<h; row++) {
          printf("\n  ");
         for (col=0; col<w; col+=8)
             if (bitmap) dots(0, w-col>7? 8: w-col);
             else if (hexmap) printf("%02x", 0x00);
             else printf(" 0x%02x, ", 0x00);
      }
      if ((!bitmap) && (!hexmap)) printf("};\n");
      else putchar('\n');
   }
   return 0;
}

Here is the call graph for this function: