home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 531.lha / conv / conv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-04  |  4.0 KB  |  131 lines

  1. /*
  2.  
  3.    This program reads an Adobe Font file and unpacks it so that it can be
  4.    loaded into a PostScript printer.  Note that it does not decrypt the file.
  5.    If you want to save some time downloading and you have an eight bit
  6.    connection to the printer, you may not need to convert the font to hex.
  7.  
  8.    To use it you will either need to compile the program on an IBM PC or
  9.    Macintosh system, convert the fonts and bring them to the system you
  10.    wish to use them on or bring the fonts to the system you wish to use
  11.    them on and unpack them there.  I don't beleive that unpacking
  12.    (as opposed to decrypting) should be a violation of the license 
  13.    agreement, but then again, I am not a lawyer.  In short, as far as the
  14.    legalities go, you are on your own.
  15.  
  16.    This program was compiled and tested on a Commodore Amiga 2500 with
  17.    Manx C 5.0.  It should build with little trouble using any ANSI C
  18.    compiler.
  19.  
  20. */
  21.  
  22.  
  23. #include <ctype.h>
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26.  
  27. /*
  28.    Define error codes
  29. */
  30. #define E_IPO 1
  31. #define E_COI 2                        /* Can't open input */
  32. #define E_COO 3                        /* Can't open output */
  33. #define E_BIF 4                       /* Bad input file format */
  34.  
  35.  
  36. const char *errmsg[] = {
  37.    "Success",
  38.    "Can't Open Input file %s\n",
  39.    "Can't open Output file %s\n",
  40.    "Bad Input Format"};
  41.  
  42. void EXIT(code,text)
  43. int code;
  44. char *text;
  45. {
  46.    if (code > 0) printf(errmsg[code],text);
  47.    exit(code);
  48. }
  49.  
  50. char tohex[] = {"0123456789ABCDEF"};       /* Array to convert to hex */
  51.  
  52. #define vgetb(buffer,size,stream) fread(buffer,(size_t) 1, \
  53. (size_t) size, stream)
  54.  
  55. main (argc,argv)
  56. int argc;                             /* Command line argument count */
  57. char *argv[];                          /* Command line argument pointers */
  58. {
  59.  
  60.    int result;                        /* Command line result */
  61.    unsigned char line[7];                       /* block header */
  62.    int linlen;                        /* length of current line */
  63.    int i;                             /* loop counter */
  64.    FILE *ifcb;                        /* Input file */
  65.    FILE *ofcb;                        /* Output file */
  66.    FILE *fopen();                     /* Open a file */
  67.    unsigned char ch;                            /* a character */
  68.    unsigned long blksiz;               /* size of data block */
  69.    int blktyp;                         /* block type */
  70.    int numred;                         /* number of bytes read */
  71.  
  72.  
  73. /* Open the input file and output file */
  74.  
  75.    if (argc != 3) EXIT(E_IPO,"");
  76.    if ((ifcb = fopen(*++argv,"r")) == NULL) EXIT(E_COI,*argv);
  77.    if ((ofcb = fopen(*++argv,"w")) == NULL) EXIT(E_COO,*argv);
  78.  
  79.    numred = vgetb(line,2,ifcb);
  80.    if (numred != 2 || line[0] != 128) {
  81.       printf("PostScript font program not in correct format\n");
  82.       EXIT(E_BIF,"");
  83.    };
  84.  
  85. /*
  86.    load the server dictionary password code here
  87. */
  88.    fputs("%!",ofcb);
  89.    fputs("serverdict begin 0 exitserver ",ofcb);
  90.  
  91.    while (line[0] == 128 && line[1] < 3) {
  92.        blktyp = line[1];
  93.        numred = vgetb(line,4,ifcb);
  94.        for (blksiz=0,i=0;i<4;i++)
  95.              blksiz = blksiz | (((unsigned long)line[i])<<(8*i));
  96.        switch (blktyp) {
  97.          case 1:
  98.             for (;blksiz>0;blksiz--) {
  99.                  ch = fgetc(ifcb);
  100.                  if (ch != '\015') fputc(ch,ofcb);
  101.                  else fputs("\n",ofcb);
  102.             }
  103.             break;
  104.          case 2:
  105.             for (linlen=78;blksiz>0;blksiz--,linlen-=2) {
  106.                  if (linlen <= 0) {
  107.                     fputs("",ofcb);
  108.                     linlen=78;
  109.                  };
  110.                  ch = fgetc(ifcb);
  111.                  fputc(tohex[(ch>>4)&15],ofcb);
  112.                  fputc(tohex[ch&15],ofcb);
  113.             };
  114.             fputs("",ofcb);
  115.             break;
  116.         };
  117.    numred = vgetb(line,2,ifcb);
  118.    if (numred != 2 || line[0] != 128) {
  119.       printf("PostScript font program not in correct format\n");
  120.       EXIT(E_BIF,"");
  121.    };
  122. };
  123.  
  124.  
  125.  
  126. /* Close the output file and return success */
  127.    fclose(ifcb);
  128.    fclose(ofcb);
  129.    EXIT(0,"");
  130. }
  131.