home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 8 / CDACTUAL8.iso / install / fips / source / global.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-11  |  6.7 KB  |  228 lines

  1. /* 
  2.     FIPS - the First nondestructive Interactive Partition Splitting program 
  3.  
  4.     Module global.cpp 
  5.  
  6.     RCS - Header: 
  7.     $Header: c:/daten/fips/source/main/RCS/global.cpp 1.1 1994/05/25 22:19:49 schaefer Exp schaefer $ 
  8.  
  9.     Copyright (C) 1993 Arno Schaefer 
  10.  
  11.     This program is free software; you can redistribute it and/or modify 
  12.     it under the terms of the GNU General Public License as published by 
  13.     the Free Software Foundation; either version 2 of the License, or 
  14.     (at your option) any later version. 
  15.  
  16.     This program is distributed in the hope that it will be useful, 
  17.     but WITHOUT ANY WARRANTY; without even the implied warranty of 
  18.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  19.     GNU General Public License for more details. 
  20.  
  21.     You should have received a copy of the GNU General Public License 
  22.     along with this program; if not, write to the Free Software 
  23.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
  24.  
  25.  
  26.     Report problems and direct all questions to: 
  27.  
  28.     schaefer@rbg.informatik.th-darmstadt.de 
  29. */ 
  30.  
  31. #include <stdarg.h> 
  32. #include <conio.h> 
  33. #include <stdlib.h> 
  34. #include <string.h> 
  35. #include "global.h" 
  36.  
  37. #define CTRL_C 3 
  38.  
  39. global_vars global; 
  40.  
  41. /* ----------------------------------------------------------------------- */ 
  42. /* Initialization of global variables                                      */ 
  43. /* ----------------------------------------------------------------------- */ 
  44.  
  45. global_vars::global_vars (void) 
  46.     test_mode = false; 
  47.     verbose_mode = true; 
  48.     debug_mode = false; 
  49.  
  50.     override_multiple_boot = false; 
  51.     override_bootable_flag = false; 
  52.     override_rootdir_entries = false; 
  53.     override_large_fat = false; 
  54.     override_small_fat = false; 
  55.     override_media_descriptor = false; 
  56.  
  57.     drive_number_cmdline = 0; 
  58.     partition_number_cmdline = 0; 
  59.     new_start_cylinder_cmdline = 0; 
  60.  
  61. global_vars::~global_vars (void) 
  62.     if (debug_mode) fclose (debugfile); 
  63.  
  64. void exit_function (void) 
  65.     printx ("\nBye!\n"); 
  66.  
  67. void global_vars::open_debugfile (int argc,char *argv[]) 
  68.     if ((debugfile = fopen ("fipsinfo.dbg","wt")) == NULL) 
  69.     { 
  70.         global.debug_mode = false; 
  71.         warning ("Can't open debugfile"); 
  72.     } 
  73.     else 
  74.     { 
  75.         fprintf (debugfile,"FIPS Debug File\n\n"); 
  76.         fprintf (debugfile,"The command was: "); 
  77.         while (argc--) fprintf (debugfile,argc ? "%s " : "%s", *argv++); 
  78.         fprintf (debugfile,"\n\nTranscript of session:\n"); 
  79.     } 
  80.  
  81. /* ----------------------------------------------------------------------- */ 
  82. /* Replacement for printf - prints to screen and debugfile                 */ 
  83. /* ----------------------------------------------------------------------- */ 
  84.  
  85. void printx (char *fmt,...) 
  86.     va_list ap; 
  87.     va_start (ap,fmt); 
  88.     vprintf (fmt,ap); 
  89.     if (global.debug_mode) vfprintf (global.debugfile,fmt,ap); 
  90.     va_end (ap); 
  91.  
  92. /* ----------------------------------------------------------------------- */ 
  93. /* Replacement for getch - exit when CTRL-C is pressed                     */ 
  94. /* ----------------------------------------------------------------------- */ 
  95.  
  96. int getx (void) 
  97.     int character = getch(); 
  98.     if (character == CTRL_C) 
  99.     { 
  100.         printx ("\n"); 
  101.         exit (0); 
  102.     } 
  103.     return (character); 
  104.  
  105. /* ----------------------------------------------------------------------- */ 
  106. /* Copyright notice and version number                                     */ 
  107. /* ----------------------------------------------------------------------- */ 
  108.  
  109. void notice (void) 
  110.     printx ("\nFIPS version 1.1, Copyright (C) 1993/94 Arno Schaefer\n\n"); 
  111.     printx ("DO NOT use FIPS in a multitasking environment like Windows, OS/2, Desqview,\n"); 
  112.     printx ("Novell Task manager or the Linux DOS emulator: boot from a DOS boot disk first.\n\n"); 
  113.     printx ("If you use OS/2 or a disk compressor, read the relevant sections in FIPS.DOC.\n\n"); 
  114.     printx ("FIPS comes with ABSOLUTELY NO WARRANTY, see file COPYING for details\n"); 
  115.     printx ("This is free software, and you are welcome to redistribute it\n"); 
  116.     printx ("under certain conditions; again see file COPYING for details.\n"); 
  117.  
  118.     printx ("\nPress any Key\n"); 
  119.     getx(); 
  120.  
  121. /* ----------------------------------------------------------------------- */ 
  122. /* Hexdump binary data into a file                                         */ 
  123. /* ----------------------------------------------------------------------- */ 
  124.  
  125. void hexwrite (byte *buffer,int number,FILE *file) 
  126.     for (int i=0;i<number;i++) 
  127.     { 
  128.         fprintf (file,"%02X ",*(buffer+i)); 
  129.         if ((i+1)%16 == 0) fprintf (file,"\n"); 
  130.         else if ((i+1)%8 == 0) fprintf (file,"- "); 
  131.     } 
  132.     fprintf (file,"\n"); 
  133.  
  134. /* ----------------------------------------------------------------------- */ 
  135. /* Error Handling                                                          */ 
  136. /* ----------------------------------------------------------------------- */ 
  137.  
  138. static void print_verbose_message (char *message) 
  139.     char line[256]; 
  140.     int length = 0; 
  141.     FILE *error_msg_file; 
  142.  
  143.     fprintf (stderr,"\n"); 
  144.     if (global.debug_mode) fprintf (global.debugfile,"\n"); 
  145.  
  146.     if ((error_msg_file = fopen ("errors.txt","rt")) == NULL) 
  147.     { 
  148.         fprintf (stderr,"File ERRORS.TXT not found - no verbose messages available\n"); 
  149.         if (global.debug_mode) fprintf (global.debugfile,"File ERRORS.TXT not found - no verbose messages available\n"); 
  150.         global.verbose_mode = false; 
  151.         return; 
  152.     } 
  153.  
  154.     while (message[length] != 0 && message[length] != ':') length++; 
  155.  
  156.     fgets (line,255,error_msg_file); 
  157.     while (strncmp(message,line,length)) if (fgets (line,255,error_msg_file) == NULL) return; 
  158.     fgets (line,255,error_msg_file); 
  159.     while (!strncmp("  ",line,2)) 
  160.     { 
  161.         fprintf (stderr,"%s",line+2); 
  162.         if (global.debug_mode) fprintf (global.debugfile,"%s",line+2); 
  163.         if (fgets (line,255,error_msg_file) == NULL) return; 
  164.     } 
  165.     fclose (error_msg_file); 
  166.  
  167. void error (char *message,...) 
  168.     va_list ap; 
  169.  
  170.     fprintf (stderr,"\nError: "); 
  171.     if (global.debug_mode) fprintf (global.debugfile,"\nError: "); 
  172.  
  173.     va_start (ap,message); 
  174.     vfprintf (stderr,message,ap); 
  175.     if (global.debug_mode) vfprintf (global.debugfile,message,ap); 
  176.     va_end (ap); 
  177.  
  178.     fprintf (stderr,"\n"); 
  179.     if (global.debug_mode) fprintf (global.debugfile,"\n"); 
  180.  
  181.     if (global.verbose_mode) print_verbose_message (message); 
  182.  
  183.     exit (-1); 
  184.  
  185. void warning (char *message,...) 
  186.     va_list ap; 
  187.  
  188.     fprintf (stderr,"\nWarning: "); 
  189.     if (global.debug_mode) fprintf (global.debugfile,"\nWarning: "); 
  190.  
  191.     va_start (ap,message); 
  192.     vfprintf (stderr,message,ap); 
  193.     if (global.debug_mode) vfprintf (global.debugfile,message,ap); 
  194.     va_end (ap); 
  195.  
  196.     fprintf (stderr,"\n"); 
  197.     if (global.debug_mode) fprintf (global.debugfile,"\n"); 
  198.  
  199.     if (global.verbose_mode) print_verbose_message (message); 
  200.  
  201.     fprintf (stderr,"\nPress any key\n"); 
  202.     if (global.debug_mode) fprintf (global.debugfile,"\nPress any key\n"); 
  203.  
  204.     getx(); 
  205.  
  206.