home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / sprint / spfonts4.zip / SPFONTLD.C < prev   
C/C++ Source or Header  |  1989-06-24  |  2KB  |  107 lines

  1. /* SPFONTLD - load binary font table into SPFONT program */
  2.  
  3. #include <stdio.h>
  4. #include <alloc.h>
  5. #include <string.h>
  6. #include <fcntl.h>
  7. #include <sys\stat.h>
  8.  
  9. #define MAXFONTS    8
  10. #define CHARSPERFONT    224
  11. #define MAXCHARHEIGHT    16
  12.  
  13. struct fontinfo
  14.     {
  15.     char anchor[8];
  16.     unsigned int fonttablesize;
  17.     char fonttablevalid;
  18.     } ;
  19.  
  20. main(int ac, char *av[])
  21.     {
  22.     int comfd, fntfd;
  23.     struct fontinfo finfo;
  24.     unsigned int infoaddr;
  25.     long infopointer;
  26.     struct stat fntstat;
  27.     unsigned fontsize;
  28.     char *fonttable;
  29.  
  30.     comfd = fntfd = -1;
  31.     if (ac != 3)
  32.         {
  33.         fprintf(stderr, "usage: SPFONTLD comfile fontfile\n");
  34.         exit(1);
  35.         }
  36.  
  37.     if ((comfd = open(av[1], O_RDWR|O_BINARY)) < 0)
  38.         {
  39.         fprintf(stderr, "can't open SPFONT com file: %s\n", av[1]);
  40.         exit(2);
  41.         }
  42.     lseek(comfd, 3L, SEEK_SET);    /* skip "jmp Init" */
  43.     if (read(comfd, &infoaddr, sizeof(int)) != sizeof(int))
  44.         {
  45.         fprintf(stderr, "can't read SPFONT com file\n");
  46.         exit(3);
  47.         }
  48.     infopointer = (long)(infoaddr - 0x100);    /* since ORG'ed at 100h */
  49.     lseek(comfd, infopointer, SEEK_SET);
  50.     if (read(comfd, &finfo, sizeof(struct fontinfo)) != sizeof(struct fontinfo))
  51.         {
  52.         fprintf(stderr, "can't read SPFONT com file\n");
  53.         exit(3);
  54.         }
  55.     if (memcmp(finfo.anchor, "<SPFONT>", 8) != 0)
  56.         {
  57.         fprintf(stderr, "wrong format for SPFONT com file\n");
  58.         exit(3);
  59.         }
  60.  
  61.     if ((fntfd = open(av[2], O_RDONLY|O_BINARY)) < 0)
  62.         {
  63.         fprintf(stderr, "can't open SPFONT font file: %s\n", av[2]);
  64.         exit(4);
  65.         }
  66.     fstat(fntfd, &fntstat);
  67.     fontsize = fntstat.st_size;
  68.     if ((fontsize % (MAXFONTS*CHARSPERFONT)) != 0)
  69.         {
  70.         fprintf(stderr, "SPFONT font file is wrong size\n");
  71.         exit(5);
  72.         }
  73.     if (finfo.fonttablesize != fontsize)
  74.         {
  75.         fprintf(stderr, "wrong font table size for SPFONT com file\n");
  76.         exit(3);
  77.         }
  78.     if ((fonttable = malloc(fontsize)) == NULL)
  79.         {
  80.         fprintf(stderr, "cannot allocate font table\n");
  81.         exit(3);
  82.         }
  83.     if (read(fntfd, fonttable, fontsize) != fontsize)
  84.         {
  85.         fprintf(stderr, "can't read SPFONT font file");
  86.         exit(5);
  87.         }
  88.     close(fntfd);
  89.  
  90.     finfo.fonttablevalid = 0xff;
  91.     lseek(comfd, infopointer, SEEK_SET);
  92.     if (write(comfd, &finfo, sizeof(struct fontinfo)) != sizeof(struct fontinfo))
  93.         {
  94.         fprintf(stderr, "can't write SPFONT com file\n");
  95.         exit(3);
  96.         }
  97.     if (write(comfd, fonttable, fontsize) != fontsize)
  98.         {
  99.         fprintf(stderr, "can't write SPFONT com file\n");
  100.         exit(3);
  101.         }
  102.     close(comfd);
  103.  
  104.     fprintf(stderr, "Font table loaded.\n");
  105.     exit(0);
  106.     }
  107.