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

  1. /*
  2.     FIPS - the First nondestructive Interactive Partition Splitting program
  3.  
  4.     Module input.cpp
  5.  
  6.     RCS - Header:
  7.     $Header: c:/daten/fips/source/main/RCS/input.cpp 1.4 1995/01/19 00:00:54 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 <ctype.h>
  32. #include <stdlib.h>
  33. #include "types.h"
  34. #include "disk_io.h"
  35. #include "global.h"
  36. #include "input.h"
  37.  
  38. /* ----------------------------------------------------------------------- */
  39. /* User Input                                                              */
  40. /* ----------------------------------------------------------------------- */
  41.  
  42. static void wait_for_key (void)
  43. {
  44.     printx ("\nPress any Key\n");
  45.     getx();
  46. }
  47.  
  48.  
  49. int ask_for_drive_number (void)
  50.  
  51. /*
  52.  * Find Disk Drives - if more than one, ask for drive number. If no drive
  53.  * was found, issue warning, try drive 0x80 anyway
  54.  */
  55.  
  56. {
  57.     int drives_found = 0;
  58.     int drive_table[] = {0,0,0,0,0,0,0,0,0};
  59.  
  60.     int no_of_drives = get_no_of_drives ();
  61.  
  62.     for (int i=0x80; i < 0x80 + no_of_drives; i++)
  63.     {
  64.         if (get_disk_type (i) == 3)
  65.         {
  66.             drive_table[drives_found++] = i;
  67.             if (drives_found == 9)
  68.                 break;
  69.         }
  70.     }
  71.  
  72.     if (drives_found == 0)
  73.     {
  74.         warning (false, "No compatible hard disk found");
  75.         ask_if_continue ();
  76.  
  77.         return (0x80);
  78.     }
  79.  
  80.     if (drives_found == 1)
  81.         return (drive_table[0]);
  82.  
  83.     printx ("Which Drive (");
  84.  
  85.     for (i=0; i<drives_found; i++)
  86.         printx ("%u=0x%02X/", i+1, drive_table[i]);
  87.     printx ("\b)? ");
  88.  
  89.     while (true)
  90.     {
  91.         i = getx ();
  92.  
  93.         if (i >= '1' && i <= '9')
  94.             if (drive_table[i - '1'] != 0) break;
  95.     }
  96.  
  97.     printx ("%c\n",i);
  98.     return (drive_table[i - '1']);
  99. }
  100.  
  101.  
  102. int ask_for_partition_number (partition_info parts[])
  103. {
  104.     int number_of_partitions = (parts[0].system != 0) + (parts[1].system != 0) +
  105.          (parts[2].system != 0) + (parts[3].system != 0);
  106.  
  107.     if (number_of_partitions == 0)
  108.         error ("No valid partition found");
  109.  
  110.     if (number_of_partitions == 4)
  111.         error ("No free partition");
  112.  
  113.     if (number_of_partitions == 1)
  114.     {
  115.         wait_for_key();
  116.         for (int i = 0; i < 4; i++) if (parts[i].system) return i;
  117.     }
  118.  
  119.     printx ("\nWhich Partition do you want to split (");
  120.  
  121.     for (int i = 0; i < 4; i++) if (parts[i].system) printx ("%u/", i + 1);
  122.     printx ("\b)? ");
  123.  
  124.     while (true)
  125.     {
  126.         i = getx ();
  127.         if (isdigit (i)) if (('0' < i) && (i <= '4')) if (parts[i - '1'].system) break;
  128.     }
  129.     printx ("%c\n", i);
  130.     return (i - '1');
  131. }
  132.  
  133.  
  134. dword ask_for_new_start_cylinder (int start_cylinder, int min_cylinder, int max_cylinder, int sectors_per_cylinder)
  135. {
  136.     int akt_cylinder = min_cylinder;
  137.  
  138.     printx ("\nEnter start cylinder for new partition (%u - %u):\n\n",min_cylinder,max_cylinder);
  139.     printx ("Use the cursor keys to choose the cylinder, <enter> to continue\n\n");
  140.     printx ("Old partition      Cylinder       New Partition\n");
  141.  
  142.     while (true)
  143.     {
  144.         double oldsize = (akt_cylinder - start_cylinder) * (double) sectors_per_cylinder / 2048;
  145.         double newsize = (max_cylinder - akt_cylinder + 1) * (double) sectors_per_cylinder / 2048;
  146.  
  147.         printf (" %6.1f MB          %4u           %6.1f MB\r", oldsize, akt_cylinder, newsize);
  148.  
  149.         int input = getx ();
  150.         if (input == '\r')
  151.         {
  152.             printx (" %6.1f MB          %4u           %6.1f MB\n\n", oldsize, akt_cylinder, newsize);
  153.             return (akt_cylinder);
  154.         }
  155.         else if (input != 0) continue;
  156.  
  157.         input = getx ();
  158.         switch (input)
  159.         {
  160.             case 75:
  161.                 if (akt_cylinder > min_cylinder) akt_cylinder--;
  162.                 break;
  163.             case 77:
  164.                 if (akt_cylinder < max_cylinder) akt_cylinder++;
  165.                 break;
  166.             case 72:
  167.                 if (akt_cylinder - 10 >= min_cylinder) akt_cylinder -= 10;
  168.                 break;
  169.             case 80:
  170.                 if (akt_cylinder + 10 <= max_cylinder) akt_cylinder += 10;
  171.                 break;
  172.         }
  173.     }
  174. }
  175.  
  176. char ask_yes_no (void)
  177. {
  178.     int character;
  179.     do character = getx(); while ((character != 'y') && (character != 'n'));
  180.     printx ("%c\n",character);
  181.     return (character);
  182. }
  183.  
  184. char ask_correction (void)
  185. {
  186.     printx ("Do you want to correct this (y/n) ");
  187.     return (ask_yes_no ());
  188. }
  189.  
  190.  
  191. void ask_for_write_permission (void)
  192. {
  193.     printx ("\nReady to write new partition scheme to disk\n");
  194.     printx ("Do you want to proceed (y/n)? ");
  195.  
  196.     if (ask_yes_no () == 'n') exit (0);
  197. }
  198.  
  199. boolean ask_if_continue (void)
  200. {
  201.     printx ("\nDo you want to continue or reedit the partition table (c/r)? ");
  202.  
  203.     int character;
  204.     do character = getx(); while ((character != 'c') && (character != 'r'));
  205.     printx ("%c\n",character);
  206.     if (character == 'r') return (false);
  207.     return (true);
  208. }
  209.  
  210. boolean ask_if_save (void)
  211. {
  212.     int character;
  213.  
  214.     printx ("Do you want to make a backup copy of your root and boot sector before\nproceeding (y/n)? ");
  215.     if (ask_yes_no () == 'n') return (false);
  216.  
  217.     printx ("Do you have a bootable floppy disk in drive A: as described in the\ndocumentation (y/n)? ");
  218.     if (ask_yes_no () == 'n')
  219.     {
  220.         printx ("Please read the file FIPS.DOC!\n");
  221.         exit (0);
  222.     }
  223.  
  224.     return (true);
  225. }
  226.  
  227. void ask_if_proceed (void)
  228. {
  229.     printx ("Do you want to proceed (y/n)? ");
  230.  
  231.     if (ask_yes_no () == 'n') exit (0);
  232. }
  233.