home *** CD-ROM | disk | FTP | other *** search
/ James Briskly's Game Magazine 2 / JBGM002S.ZIP / SOURCE / MAIN.CPP < prev    next >
C/C++ Source or Header  |  1995-08-22  |  4KB  |  172 lines

  1. /*
  2.     FIPS - the First nondestructive Interactive Partition Splitting program
  3.  
  4.     Module main.cpp
  5.  
  6.     RCS - Header:
  7.     $Header: c:/daten/fips/source/main/RCS/main.cpp 1.4 1995/01/19 00:00:55 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 <stdlib.h>
  32. #include "logdr_st.h"
  33. #include "global.h"
  34. #include "input.h"
  35. #include "fat.h"
  36. #include "fipsspec.h"
  37. #include "host_os.h"
  38.  
  39.  
  40. #define FIRST_CHECK false
  41. #define FINAL_CHECK true
  42.  
  43.  
  44. extern unsigned _stklen = 20000U;
  45.  
  46.  
  47. int main (int argc, char *argv[])
  48. {
  49.     // *********************************************************
  50.     // Initialize Program
  51.     // *********************************************************
  52.  
  53.     evaluate_argument_vector (argc, argv);
  54.  
  55.     atexit (exit_function);
  56.  
  57.     if (global.debug_mode)
  58.         global.open_debugfile (argc,argv);
  59.  
  60.     notice ();
  61.  
  62.     host_os os;
  63.     char infostring[256];
  64.  
  65.     if (os.ok () != OK)
  66.     {
  67.         printx ("\nWARNING: FIPS has detected that it is running under %s\n"
  68.             "FIPS should not be used under a multitasking OS. If possible, boot from a DOS\n"
  69.             "disk and then run FIPS. Read FIPS.DOC for more information.\n\n",
  70.             os.information (infostring));
  71.  
  72.         ask_if_proceed ();
  73.     }
  74.  
  75.  
  76.     // *********************************************************
  77.     // Select Drive
  78.     // *********************************************************
  79.  
  80.     int drive_number;
  81.  
  82.     if (global.drive_number_cmdline != 0)
  83.         drive_number = global.drive_number_cmdline;
  84.     else
  85.         drive_number = ask_for_drive_number ();
  86.  
  87.     fips_harddrive harddrive (drive_number);    // reads geometry
  88.  
  89.     if (harddrive.errorcode)
  90.         error
  91.         (
  92.             "Error reading drive geometry: Errorcode %u",
  93.             harddrive.errorcode
  94.         );
  95.  
  96.     harddrive.reset ();
  97.  
  98.     if (harddrive.errorcode)
  99.     {
  100.         warning
  101.         (
  102.             false,
  103.             "Drive initialization failure: Errorcode %u",
  104.             harddrive.errorcode
  105.         );
  106.  
  107.         ask_if_proceed ();
  108.     }
  109.  
  110.  
  111.     // *********************************************************
  112.     // Select partition
  113.     // *********************************************************
  114.  
  115.     if (harddrive.read_root_sector () != 0)
  116.         error ("Error reading root sector");
  117.  
  118.     if (global.debug_mode)
  119.     {
  120.         fprintf
  121.         (
  122.             global.debugfile,
  123.             "\nRoot sector drive %02Xh:\n\n",
  124.             drive_number
  125.         );
  126.  
  127.         hexwrite (harddrive.root_sector->data, 512, global.debugfile);
  128.     }
  129.  
  130.     while (true)
  131.     {
  132.         fips_harddrive hd = harddrive;
  133.  
  134.         hd.get_partition_table();
  135.  
  136.         printx ("\nPartition table:\n\n");
  137.         hd.print_partition_table ();
  138.  
  139.         hd.check (FIRST_CHECK);
  140.  
  141.         int partition_number =
  142.             ask_for_partition_number
  143.             (
  144.                 hd.partition_table().partition_info
  145.             );
  146.  
  147.         int system = hd.partition_table()
  148.             .partition_info[partition_number].system;
  149.  
  150.         switch (system)
  151.         {
  152.             case 5:
  153.                 error ("Can't split extended partitions");
  154.                 break;
  155.             case 1: case 4: case 6:
  156.             {
  157.                 fips_partition* partition =
  158.                     new fips_partition (&hd, partition_number);
  159.  
  160.                 if (partition->split (hd) == true)
  161.                     return (0);
  162.  
  163.                 delete partition;
  164.             }
  165.                 break;
  166.             default:
  167.                 error ("Unknown file system: %02Xh", system);
  168.                 break;
  169.         }
  170.     }
  171. }
  172.