home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / getfont.zip / getfont.c next >
Text File  |  1994-07-06  |  2KB  |  87 lines

  1. /* getfont.c -- extract embedded PostScript font */
  2. /* Peter Flass -- NYS LBDC -- July, 1994         */
  3.  
  4. #include <stdio.h>
  5. #include <string.h>
  6.  
  7. main(int argc, char *argv[], char *envp[])
  8. {
  9.    char outfile[64];
  10.    char infile[64];
  11.    char buf[512], *b, *e;
  12.    int arg;
  13.    FILE *in,*out;
  14.    int InFont=0;
  15.    int AllFonts=0;
  16.    int eq;
  17.    const char BeginFont[] = "%%BeginFont: ";
  18.    const char EndFont[]   = "%%EndFont";
  19.  
  20.    if(argc<2) {
  21.       fprintf(stderr,"Usage: getfont infile [font ...]\n");
  22.       exit(1);
  23.    }
  24.    strcpy(infile,argv[1]);
  25.    in=fopen(infile,"r");
  26.    if(in==NULL) {
  27.       fprintf(stderr,"Unable to open input file %s\n",infile);
  28.       exit(1);
  29.    }
  30.    if(argc<3) {
  31.       AllFonts=1;
  32.    }
  33.    for(;;) {
  34.       b=fgets(buf,512,in);
  35.       if(feof(in)) break;
  36.       if(b==NULL) {
  37.          fprintf(stderr,"Error reading input file %s\n",infile);
  38.          exit(1);
  39.       }
  40.       eq=strncmp(buf,EndFont,strlen(EndFont));
  41.       if(eq==0) {
  42.          if(InFont==1) {
  43.             fputs(buf,out);
  44.             InFont=0;
  45.             fclose(out);
  46.             fprintf(stderr,"Done\n");
  47.          }
  48.          continue;
  49.       }
  50.  
  51.       if(InFont==1) {
  52.          fputs(buf,out);
  53.          continue;
  54.       }
  55.  
  56.       eq=strncmp(buf,BeginFont,strlen(BeginFont));
  57.       if(eq!=0) continue;
  58.       b=&buf[0]+strlen(BeginFont);
  59.       e=strpbrk(b," \r\n");
  60.       if(e==NULL) e=b+strlen(b)+1;
  61.       strncpy(outfile,b,e-b);
  62.       *(outfile+(int)(e-b))='\0';
  63.       for(arg=2;arg<argc;arg++) {
  64.          if( (strcmp(argv[arg],outfile)==0) ) {
  65.             InFont=1;
  66.             break;
  67.          }
  68.       }
  69.       if(AllFonts==1) InFont=1;
  70.       if(InFont==1) {
  71.          fprintf(stderr,"%s ...",outfile);
  72.          strcat(outfile,".pfa");
  73.          out=fopen(outfile,"w");
  74.          if(out==NULL) {
  75.             fprintf(stderr,"Unable to open output file %s\n",
  76.                     outfile);
  77.             exit(1);
  78.          } /* endif */
  79.          fputs(buf,out);
  80.       } /* endif */
  81.   } /* endfor */
  82.  
  83. fprintf(stderr,"Fini!\n");
  84. exit(0);
  85.  
  86. }
  87.