home *** CD-ROM | disk | FTP | other *** search
/ Freelog Special Edition 1: Linux / CD1.iso / dosutils / fips20 / source / input.cpp < prev    next >
C/C++ Source or Header  |  1997-12-19  |  6KB  |  232 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. int ask_for_drive_number (void)
  49.  
  50. /*
  51.  * Find Disk Drives - if more than one, ask for drive number. If no drive
  52.  * was found, issue warning, try drive 0x80 anyway
  53.  */
  54.  
  55. {
  56.     int drives_found = 0;
  57.     int drive_table[] = {0,0,0,0,0,0,0,0,0};
  58.  
  59.     int no_of_drives = get_no_of_drives ();
  60.  
  61.     for (int i=0x80; i < 0x80 + no_of_drives; i++)
  62.     {
  63.         if (get_disk_type (i) == 3)
  64.         {
  65.             drive_table[drives_found++] = i;
  66.             if (drives_found == 9)
  67.                 break;
  68.         }
  69.     }
  70.  
  71.     if (drives_found == 0)
  72.     {
  73.         warning (false, "No compatible hard disk found");
  74.         ask_if_continue ();
  75.  
  76.         return (0x80);
  77.     }
  78.  
  79.     if (drives_found == 1)
  80.         return (drive_table[0]);
  81.  
  82.     printx ("Which Drive (");
  83.  
  84.     for (i=0; i<drives_found; i++)
  85.         printx ("%u=0x%02X/", i+1, drive_table[i]);
  86.     printx ("\b)? ");
  87.  
  88.     while (true)
  89.     {
  90.         i = getx ();
  91.  
  92.         if (i >= '1' && i <= '9')
  93.             if (drive_table[i - '1'] != 0) break;
  94.     }
  95.  
  96.     printx ("%c\n",i);
  97.     return (drive_table[i - '1']);
  98. }
  99.  
  100. int ask_for_partition_number (partition_info parts[])
  101. {
  102.     int number_of_partitions = (parts[0].system != 0) + (parts[1].system != 0) +
  103.          (parts[2].system != 0) + (parts[3].system != 0);
  104.  
  105.     if (number_of_partitions == 0)
  106.         error ("No valid partition found");
  107.  
  108.     if (number_of_partitions == 4)
  109.         error ("No free partition");
  110.  
  111.     if (number_of_partitions == 1)
  112.     {
  113.         wait_for_key();
  114.         for (int i = 0; i < 4; i++) if (parts[i].system) return i;
  115.     }
  116.  
  117.     printx ("\nWhich Partition do you want to split (");
  118.  
  119.     for (int i = 0; i < 4; i++) if (parts[i].system) printx ("%u/", i + 1);
  120.     printx ("\b)? ");
  121.  
  122.     while (true)
  123.     {
  124.         i = getx ();
  125.         if (isdigit (i)) if (('0' < i) && (i <= '4')) if (parts[i - '1'].system) break;
  126.     }
  127.     printx ("%c\n", i);
  128.     return (i - '1');
  129. }
  130.  
  131.  
  132.  
  133. dword ask_for_new_start_cylinder (int start_cylinder, int min_cylinder, int max_cylinder, int sectors_per_cylinder)
  134. {
  135.     int akt_cylinder = min_cylinder;
  136.  
  137.     printx ("\nEnter start cylinder for new partition (%u - %u):\n\n",min_cylinder,max_cylinder);
  138.     printx ("Use the cursor keys to choose the cylinder, <enter> to continue\n\n");
  139.     printx ("Old partition      Cylinder       New Partition\n");
  140.  
  141.     while (true)
  142.     {
  143.         double oldsize = (akt_cylinder - start_cylinder) * (double) sectors_per_cylinder / 2048;
  144.         double newsize = (max_cylinder - akt_cylinder + 1) * (double) sectors_per_cylinder / 2048;
  145.  
  146.         printf (" %6.1f MB          %4u           %6.1f MB\r", oldsize, akt_cylinder, newsize);
  147.  
  148.         int input = getx ();
  149.         if (input == '\r')
  150.         {
  151.             printx (" %6.1f MB          %4u           %6.1f MB\n\n", oldsize, akt_cylinder, newsize);
  152.             return (akt_cylinder);
  153.         }
  154.         else if (input != 0) continue;
  155.  
  156.         input = getx ();
  157.  
  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.     printx ("Do you want to make a backup copy of your root and boot sector before\nproceeding (y/n)? ");
  213.     if (ask_yes_no () == 'n') return (false);
  214.  
  215.     printx ("Do you have a bootable floppy disk in drive A: as described in the\ndocumentation (y/n)? ");
  216.     if (ask_yes_no () == 'n')
  217.     {
  218.         printx ("Please read the file FIPS.DOC!\n");
  219.         exit (0);
  220.     }
  221.  
  222.     return (true);
  223. }
  224.  
  225. void ask_if_proceed (void)
  226. {
  227.     printx ("Do you want to proceed (y/n)? ");
  228.  
  229.     if (ask_yes_no () == 'n') exit (0);
  230. }
  231.  
  232.