home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / smallinf.zip / smallinf.c < prev    next >
C/C++ Source or Header  |  1994-05-16  |  3KB  |  87 lines

  1. #include <io.h>
  2. #include <fcntl.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8.  
  9. int patchINF(char *fn)
  10. {
  11.     int fh;
  12.     long nlsstart;        /* 32 bit file offset of NLS table */
  13.     long nlslen;        /* size of NLS table */
  14.     long pos;            /* position in file */
  15.     
  16.     struct            /* subset of FONTMETRICS */
  17.     {
  18.     char fontname[31];    /* szFacename[31] */
  19.     int foo1;        /* unknown - probably registry identifier */
  20.     int height;        /* lXHeight */
  21.     int width;        /* lAveCharWidth */
  22.     int cPage;        /* code Page */
  23.     } fontinfo;
  24.         
  25.     fh=open(fn,O_RDWR | O_BINARY);
  26.     lseek(fh, 0x53, SEEK_SET);    /* offset of nlsstart in .INF header */
  27.     read(fh, &nlsstart, 4);
  28.     read(fh, &nlslen, 4);
  29.     pos = nlsstart+nlslen;
  30.     lseek(fh, pos, SEEK_SET);   /* seeking to end of NLS table */
  31.     read(fh, &fontinfo, sizeof(fontinfo));
  32.     /* sometimes links to other .INF files come after the NLS-table */
  33.     /* format is: 1-byte lenght of Filename to be linked            */
  34.     /*            filename (_not_ null-terminated                   */
  35.     /* so if we meet an unprintable character here we expect this   */
  36.     while (fontinfo.fontname[0]<=0x1a)/* read over one link-filename */
  37.     {
  38.     pos += fontinfo.fontname[0];
  39.     lseek(fh, pos, SEEK_SET);
  40.     read(fh, &fontinfo, fontinfo.fontname[0]);
  41.     }
  42.     /* now we should have the first real fontinfo - usually System Proportional (default size) */
  43.     while (1)
  44.     {
  45.     lseek(fh, pos, SEEK_SET);
  46.     read(fh, &fontinfo, sizeof(fontinfo));
  47.     if ((!(strcmp(fontinfo.fontname, "System Proportional")) ||
  48.          !(strcmp(fontinfo.fontname, "Helv")) ||
  49.          !(strcmp(fontinfo.fontname, "System VIO")) ||
  50.          !(strcmp(fontinfo.fontname, "System Monospaced")) ||
  51.          !(strcmp(fontinfo.fontname, "Tms Rmn"))))
  52.         printf("found font: %s (%ux%u) - no change\n", fontinfo.fontname, fontinfo.height, fontinfo.width);
  53.     else
  54.         if (!(strcmp(fontinfo.fontname, "Courier")))
  55.         {
  56.         printf("found font: %s (%ux%u) - changing to System Vio 9x6 (4pt)\n", fontinfo.fontname,
  57.                fontinfo.height, fontinfo.width);
  58.         strcpy(fontinfo.fontname, "System VIO");
  59.         fontinfo.height=0x09;    /*  */
  60.         fontinfo.width=0x06;
  61.         lseek(fh, pos, SEEK_SET);
  62.         write(fh, &fontinfo, sizeof(fontinfo));
  63.         }
  64.         else
  65.         {
  66.         printf("no more fontinfos found - exiting\n");
  67.         close(fh);
  68.         return (0);
  69.         }
  70.     pos += sizeof(fontinfo);
  71.     }
  72. }
  73.     
  74.  
  75. int main (int argc, char *argv[], char *envp[])
  76. {
  77.     printf("SmallInf v.0.5 - 1994 by albe.\n");
  78.     if (argc==2)
  79.     PatchINF(argv[1]);
  80.     else
  81.     {
  82.     printf("usage: SmallInf Filename\n");
  83.     printf("changes every Courier Font in an INF-File to System VIO 9x6\n");
  84.     }
  85.     return(0);
  86. }
  87.