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

  1.  
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <vga.h>
  5. #include "../src/driver.h"
  6.  
  7.  
  8. /*
  9.  * Note: Observe that when writing the font to a file, the file to write is
  10.  * opened after vga_init has been called (so that root permissions have been
  11.  * given up). This means that there is no major security hole lurking here.
  12.  */
  13.  
  14. unsigned char regs[MAX_REGS];
  15.  
  16. void main( int argc, char *argv[]) {
  17.     vga_init();
  18.     if (argc == 1) {
  19.         printf("Save/restore textmode registers.\n");
  20.         printf("Syntax: restoretextmode option filename\n");
  21.         printf("    -r filename    Restore registers from file.\n");
  22.         printf("    -w filename    Write registers 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("restoretextmode");
  47.             exit(1);
  48.         }
  49.         if(1!=fread(regs, MAX_REGS, 1, f))
  50.             {
  51.             if(errno)
  52.                 goto error;
  53.             puts("restoretextmode: input file corrupted.");
  54.             exit(1);
  55.             }
  56.         fclose(f);
  57.     }
  58.     vga_setmode(G640x350x16);
  59.     switch (argv[1][1]) {
  60.     case 'r' :
  61.         vga_settextmoderegs(regs);
  62.         break;
  63.     case 'w' :
  64.         vga_gettextmoderegs(regs);
  65.         break;
  66.     }
  67.     vga_setmode(TEXT);
  68.     if (argv[1][1] == 'w') {
  69.         FILE *f;
  70.         f = fopen(argv[2], "wb");
  71.         if (f == NULL)
  72.             goto error;
  73.         if(1 != fwrite(regs, MAX_REGS, 1, f))
  74.             goto error;
  75.         if(fclose(f))
  76.             goto error;
  77.     }
  78.     exit(0);
  79. }
  80.