home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / misc / input.cpp < prev    next >
C/C++ Source or Header  |  1993-11-17  |  5KB  |  205 lines

  1. /*
  2.     FIPS - the First nondestructive Interactive Partition Splitting program
  3.  
  4.     Module input.cpp
  5.  
  6.     RCS - Header:
  7.     $Header: c:/daten/c/fips/source/cpp/RCS/input.cpp 0.9.1.1 1993/11/17 17:51:08 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.     int number_of_drives = 0;
  51.     int drive_table[] = {0,0,0,0,0,0,0,0,0};
  52.  
  53.     for (int i=128;i<256;i++) if (get_disk_type(i))
  54.     {
  55.         drive_table[number_of_drives++] = i;
  56.         if (number_of_drives == 10)
  57.             error ("Too many drives found");
  58.     }
  59.  
  60.     if (number_of_drives == 0)
  61.         error ("No Compatible Harddisk found");
  62.     if (number_of_drives == 1) return (drive_table[0]);
  63.  
  64.     printx ("Which Drive (");
  65.  
  66.     for (i=0;i<number_of_drives;i++) printx ("%u/",i+1);
  67.     printx ("\b)? ");
  68.  
  69.     while (true)
  70.     {
  71.         i = getx ();
  72.         if (isdigit (i)) if (i > '0') if (drive_table[i - '1']) break;
  73.     }
  74.     printx ("%c\n",i);
  75.     return (drive_table[i - '1']);
  76. }
  77.  
  78. int ask_for_partition_number (partition_info parts[])
  79. {
  80.     int number_of_partitions = (parts[0].system != 0) + (parts[1].system != 0) +
  81.          (parts[2].system != 0) + (parts[3].system != 0);
  82.  
  83.     if (number_of_partitions == 0)
  84.         error ("No valid partition found");
  85.  
  86.     if (number_of_partitions == 4)
  87.         error ("No free partition");
  88.  
  89.     if (number_of_partitions == 1)
  90.     {
  91.         if (!global.quiet_mode) wait_for_key();
  92.         for (int i=0;i<4;i++) if (parts[i].system) return i;
  93.     }
  94.  
  95.     printx ("\nWhich Partition do you want to split (");
  96.  
  97.     for (int i=0;i<4;i++) if (parts[i].system) printx ("%u/",i+1);
  98.     printx ("\b)? ");
  99.  
  100.     while (true)
  101.     {
  102.         i = getx ();
  103.         if (isdigit (i)) if (('0' < i) && (i <= '4')) if (parts[i-'1'].system) break;
  104.     }
  105.     printx ("%c\n",i);
  106.     return (i-'1');
  107. }
  108.  
  109. static int readnumber (int max_length)
  110. {
  111.     int number = 0;
  112.     int length = 0;
  113.  
  114.     while (true)
  115.     {
  116.         int character = getx();
  117.         if (isdigit(character))
  118.         {
  119.             if (length < max_length)
  120.             {
  121.                 printx ("%c",character);
  122.                 number = 10 * number + character - '0';
  123.                 length++;
  124.             }
  125.         }
  126.         else if (character == '\b')
  127.         {
  128.             if (length > 0)
  129.             {
  130.                 printx ("\b \b");
  131.                 number = number / 10;
  132.                 length--;
  133.             }
  134.         }
  135.         else if (character == '\r') return (number);
  136.     }
  137. }
  138.  
  139. dword ask_for_new_start_cylinder (int min_cylinder,int max_cylinder)
  140. {
  141.     while (true)
  142.     {
  143.         printx ("Enter start cylinder for new partition (%u - %u):     \b\b\b\b",min_cylinder,max_cylinder);
  144.         int cylinder=readnumber((max_cylinder > 99) ? ((max_cylinder > 999) ? 4 : 3) : 2);
  145.         printx("\r");
  146.         if ((cylinder >= min_cylinder) && (cylinder <= max_cylinder))
  147.         {
  148.             printx("\n\n");
  149.             return (cylinder);
  150.         }
  151.     }
  152. }
  153.  
  154. void ask_for_write_permission (void)
  155. {
  156.     if (global.quiet_mode) return;
  157.  
  158.     printx ("\nReady to write new partition scheme to disk\n");
  159.     printx ("Do you want to proceed (y/n)? ");
  160.  
  161.     int character;
  162.     do character = getx(); while ((character != 'y') && (character != 'n'));
  163.     printx ("%c\n",character);
  164.     if (character == 'n') exit (0);
  165. }
  166.  
  167. boolean ask_if_continue (void)
  168. {
  169.     if (global.quiet_mode) return (true);
  170.  
  171.     printx ("\nDo you want to continue or reedit the partition table (c/r)? ");
  172.  
  173.     int character;
  174.     do character = getx(); while ((character != 'c') && (character != 'r'));
  175.     printx ("%c\n",character);
  176.     if (character == 'r') return (false);
  177.     return (true);
  178. }
  179.  
  180. boolean ask_if_save (void)
  181. {
  182.     if (global.ask_if_backup)
  183.     {
  184.         int character;
  185.  
  186.         printx ("Do you want to make a backup copy of your root- and bootsector before\nproceeding (y/n)? ");
  187.         do character = getx(); while ((character != 'y') && (character != 'n'));
  188.         printx ("%c\n\n",character);
  189.         if (character == 'n') return (false);
  190.  
  191.         printx ("Do you have a bootable floppy disk in drive A: as described in the\ndocumentation (y/n)? ");
  192.         do character = getx(); while ((character != 'y') && (character != 'n'));
  193.         printx ("%c\n\n",character);
  194.         if (character == 'n')
  195.         {
  196.             printx ("Please read the file FIPS.DOC!\n");
  197.             exit (0);
  198.         }
  199.     }
  200.  
  201.     if (!global.backup_root) return (false);
  202.  
  203.     return (true);
  204. }
  205.