home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / tools / fips12 / source / global.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-13  |  6.7 KB  |  230 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.1.1 1994/10/13 01:53:30 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.  
  36. #include "version.h"
  37. #include "global.h"
  38.  
  39. #define CTRL_C 3
  40.  
  41. global_vars global;
  42.  
  43. /* ----------------------------------------------------------------------- */
  44. /* Initialization of global variables                                      */
  45. /* ----------------------------------------------------------------------- */
  46.  
  47. global_vars::global_vars (void)
  48. {
  49.     test_mode = false;
  50.     verbose_mode = true;
  51.     debug_mode = false;
  52.  
  53.     override_multiple_boot = false;
  54.     override_bootable_flag = false;
  55.     override_rootdir_entries = false;
  56.     override_large_fat = false;
  57.     override_small_fat = false;
  58.     override_media_descriptor = false;
  59.  
  60.     drive_number_cmdline = 0;
  61.     partition_number_cmdline = 0;
  62.     new_start_cylinder_cmdline = 0;
  63. }
  64.  
  65. global_vars::~global_vars (void)
  66. {
  67.     if (debug_mode) fclose (debugfile);
  68. }
  69.  
  70. void exit_function (void)
  71. {
  72.     printx ("\nBye!\n");
  73. }
  74.  
  75. void global_vars::open_debugfile (int argc,char *argv[])
  76. {
  77.     if ((debugfile = fopen ("fipsinfo.dbg","wt")) == NULL)
  78.     {
  79.         global.debug_mode = false;
  80.         warning ("Can't open debugfile");
  81.     }
  82.     else
  83.     {
  84.         fprintf (debugfile,"FIPS Debug File\n\n");
  85.         fprintf (debugfile,"The command was: ");
  86.         while (argc--) fprintf (debugfile,argc ? "%s " : "%s", *argv++);
  87.         fprintf (debugfile,"\n\nTranscript of session:\n");
  88.     }
  89. }
  90.  
  91. /* ----------------------------------------------------------------------- */
  92. /* Replacement for printf - prints to screen and debugfile                 */
  93. /* ----------------------------------------------------------------------- */
  94.  
  95. void printx (char *fmt,...)
  96. {
  97.     va_list ap;
  98.     va_start (ap,fmt);
  99.     vprintf (fmt,ap);
  100.     if (global.debug_mode) vfprintf (global.debugfile,fmt,ap);
  101.     va_end (ap);
  102. }
  103.  
  104. /* ----------------------------------------------------------------------- */
  105. /* Replacement for getch - exit when CTRL-C is pressed                     */
  106. /* ----------------------------------------------------------------------- */
  107.  
  108. int getx (void)
  109. {
  110.     int character = getch();
  111.     if (character == CTRL_C)
  112.     {
  113.         printx ("\n");
  114.         exit (0);
  115.     }
  116.     return (character);
  117. }
  118.  
  119. /* ----------------------------------------------------------------------- */
  120. /* Copyright notice and version number                                     */
  121. /* ----------------------------------------------------------------------- */
  122.  
  123. void notice (void)
  124. {
  125.     printx ("\nFIPS version " FIPS_VERSION ", Copyright (C) 1993/94 Arno Schaefer\n\n");
  126.     printx ("DO NOT use FIPS in a multitasking environment like Windows, OS/2, Desqview,\n");
  127.     printx ("Novell Task manager or the Linux DOS emulator: boot from a DOS boot disk first.\n\n");
  128.     printx ("If you use OS/2 or a disk compressor, read the relevant sections in FIPS.DOC.\n\n");
  129.     printx ("FIPS comes with ABSOLUTELY NO WARRANTY, see file COPYING for details\n");
  130.     printx ("This is free software, and you are welcome to redistribute it\n");
  131.     printx ("under certain conditions; again see file COPYING for details.\n");
  132.  
  133.     printx ("\nPress any Key\n");
  134.     getx();
  135. }
  136.  
  137. /* ----------------------------------------------------------------------- */
  138. /* Hexdump binary data into a file                                         */
  139. /* ----------------------------------------------------------------------- */
  140.  
  141. void hexwrite (byte *buffer,int number,FILE *file)
  142. {
  143.     for (int i=0;i<number;i++)
  144.     {
  145.         fprintf (file,"%02X ",*(buffer+i));
  146.         if ((i+1)%16 == 0) fprintf (file,"\n");
  147.         else if ((i+1)%8 == 0) fprintf (file,"- ");
  148.     }
  149.     fprintf (file,"\n");
  150. }
  151.  
  152. /* ----------------------------------------------------------------------- */
  153. /* Error Handling                                                          */
  154. /* ----------------------------------------------------------------------- */
  155.  
  156. static void print_verbose_message (char *message)
  157. {
  158.     char line[256];
  159.     int length = 0;
  160.     FILE *error_msg_file;
  161.  
  162.     fprintf (stderr,"\n");
  163.     if (global.debug_mode) fprintf (global.debugfile,"\n");
  164.  
  165.     if ((error_msg_file = fopen ("errors.txt","rt")) == NULL)
  166.     {
  167.         fprintf (stderr,"File ERRORS.TXT not found - no verbose messages available\n");
  168.         if (global.debug_mode) fprintf (global.debugfile,"File ERRORS.TXT not found - no verbose messages available\n");
  169.         global.verbose_mode = false;
  170.         return;
  171.     }
  172.  
  173.     while (message[length] != 0 && message[length] != ':') length++;
  174.  
  175.     fgets (line,255,error_msg_file);
  176.     while (strncmp(message,line,length)) if (fgets (line,255,error_msg_file) == NULL) return;
  177.     fgets (line,255,error_msg_file);
  178.     while (!strncmp("  ",line,2))
  179.     {
  180.         fprintf (stderr,"%s",line+2);
  181.         if (global.debug_mode) fprintf (global.debugfile,"%s",line+2);
  182.         if (fgets (line,255,error_msg_file) == NULL) return;
  183.     }
  184.     fclose (error_msg_file);
  185. }
  186.  
  187. void error (char *message,...)
  188. {
  189.     va_list ap;
  190.  
  191.     fprintf (stderr,"\nError: ");
  192.     if (global.debug_mode) fprintf (global.debugfile,"\nError: ");
  193.  
  194.     va_start (ap,message);
  195.     vfprintf (stderr,message,ap);
  196.     if (global.debug_mode) vfprintf (global.debugfile,message,ap);
  197.     va_end (ap);
  198.  
  199.     fprintf (stderr,"\n");
  200.     if (global.debug_mode) fprintf (global.debugfile,"\n");
  201.  
  202.     if (global.verbose_mode) print_verbose_message (message);
  203.  
  204.     exit (-1);
  205. }
  206.  
  207. void warning (char *message,...)
  208. {
  209.     va_list ap;
  210.  
  211.     fprintf (stderr,"\nWarning: ");
  212.     if (global.debug_mode) fprintf (global.debugfile,"\nWarning: ");
  213.  
  214.     va_start (ap,message);
  215.     vfprintf (stderr,message,ap);
  216.     if (global.debug_mode) vfprintf (global.debugfile,message,ap);
  217.     va_end (ap);
  218.  
  219.     fprintf (stderr,"\n");
  220.     if (global.debug_mode) fprintf (global.debugfile,"\n");
  221.  
  222.     if (global.verbose_mode) print_verbose_message (message);
  223.  
  224.     fprintf (stderr,"\nPress any key\n");
  225.     if (global.debug_mode) fprintf (global.debugfile,"\nPress any key\n");
  226.  
  227.     getx();
  228. }
  229.  
  230.