ftp.nice.ch/pub/next/fonts/converters/pcATMfont2Next.s.tar.gz#/pcATMfont2Next/pfb2ps.c

This is pfb2ps.c in view mode; [Download] [Up]

/* pfb2ps.c - Copyright 1991-05-12 Erik Wallin, d87-ewa@nada.kth.se.
   This program may be distributed freely, modified or included in
   other free programs long as this copyright notice is still
   included.

pfb2ps is a filter for converting postscript fonts stored in a binary
format used by PC-programs. (.PFM files) The output will be a plain
text file.

Note that you have to pipe the .PFM file into pfb2ps. 

	pfb2ps <xxx.pfb >xxx.ps
*/
#include <stdio.h>
#include <sys/malloc.h>

#define HEX_PER_LINE 32

int getlen()
{
  int c1,c2,c3,c4;
  c1 = getchar();
  c2 = getchar();
  c3 = getchar();
  c4 = getchar();
  return c1 + (256 * (c2 + 256 * (c3 + 256 * c4)));
}


void main ()
{
 int t, l, i;
 unsigned char *buf;

 while(!feof(stdin))
   {
     if (getchar() != 128)
       {
	 fprintf(stderr, "Magic number (128) not found or no input on stdin.\n");
	 exit (-1);
       }
     t = getchar();
     fprintf(stderr, "Type: %d, ", t);
     switch (t) {
     case 1:
       l = getlen();
       fprintf(stderr, " plain text, length %d\n", l);
       buf = (void *) malloc(l);
       if (fread(buf, sizeof(unsigned char), l, stdin) != l)
	 {
	   fprintf(stderr, "Wrong length of ascii field: %d or could not read file.\n", l);
	   exit (-1);
	 }
       if (fwrite(buf, sizeof(unsigned char), l, stdout) != l)
	 {
	   fprintf(stderr, "Could not write stdout.\n");
	   exit (-1);
	 }
       free(buf);
       break;
     case 2:
       l = getlen();
       fprintf(stderr, " binary data, length %d\n", l);
       buf = (void *) malloc(l);
       if (fread(buf, sizeof(unsigned char), l, stdin) != l)
	 {
	   fprintf(stderr, "Wrong length of binary field: %d or could not read file.\n", l);
	   exit (-1);
	 }
       for(i = 0;i < l ;i++)
	 {
	   printf("%2.2X", buf[i]);
	   if (!((i+1) % HEX_PER_LINE))
	     printf("\n");
	 }
       printf("\n");
       free(buf);
       break;
     case 3:
       fprintf(stderr, "End of file\n");
       exit(0);
       break;
     default:
       {
	 fprintf(stderr, "Unknown field type: %d\n", t);
	 exit(-1);
       }
     }
   }
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.