home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / SVGALIB / SVGALIB1.TAR / svgalib / utils / restorefont.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-17  |  1.7 KB  |  83 lines

  1.  
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <vga.h>
  5.  
  6.  
  7. /*
  8.  * Note: Observer that when writing the font to a file, the file to write is
  9.  * opened after vga_init has been called (so that root permissions have been
  10.  * given up). This means that there is no major security hole lurking here.
  11.  */
  12.  
  13. #define FONT_SIZE 8192
  14.  
  15. unsigned char font[FONT_SIZE];
  16.  
  17. void main( int argc, char *argv[]) {
  18.     if (argc == 1) {
  19.         printf("Restore corrupted textmode font.\n");
  20.         printf("Syntax: restorefont option filename\n");
  21.         printf("    -r filename    Restore VGA font from file.\n");
  22.         printf("    -w filename    Write current VGA font to file.\n");
  23.         exit(0);
  24.     }
  25.     if (argv[1][0] != '-') {
  26.         printf("Must specify -r or -w.\n");
  27.         exit(1);
  28.     }
  29.     switch (argv[1][1]) {
  30.         case 'r' :
  31.         case 'w' :
  32.             if (argc != 3) {
  33.                 printf("Must specify filename.\n");
  34.                 exit(1);
  35.             }
  36.             break;
  37.         default :
  38.             printf("Invalid option. Must specify -r or -w.\n");
  39.             exit(1);
  40.     }
  41.     if (argv[1][1] == 'r') {
  42.         FILE *f;
  43.         f = fopen(argv[2], "rb");
  44.         if (f == NULL) {
  45.             error:
  46.             perror("restorefont");
  47.             exit(1);
  48.         }
  49.         if(1!=fread(font, FONT_SIZE, 1, f))
  50.             {
  51.             if(errno)
  52.                 goto error;
  53.             puts("restorefont: input file corrupted.");
  54.             exit(1);
  55.             }
  56.         fclose(f);
  57.     }
  58.     vga_disabledriverreport();
  59.     vga_setchipset(VGA);        /* avoid SVGA detection */
  60.     vga_init();
  61.     vga_setmode(G640x350x16);
  62.     switch (argv[1][1]) {
  63.     case 'r' :
  64.         vga_puttextfont(font);
  65.         break;
  66.     case 'w' :    /* this line was missing */
  67.         vga_gettextfont(font);
  68.         break;
  69.     }
  70.     vga_setmode(TEXT);
  71.     if (argv[1][1] == 'w') {
  72.         FILE *f;
  73.         f = fopen(argv[2], "wb");
  74.         if (f == NULL)
  75.             goto error;
  76.         if(1 != fwrite(font, FONT_SIZE, 1, f))
  77.             goto error;
  78.         if(fclose(f))
  79.             goto error;
  80.     }
  81.     exit(0);
  82. }
  83.