home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 8 / CDACTUAL8.iso / install / fips / source / input.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-11  |  5.6 KB  |  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/fips/source/main/RCS/input.cpp 1.1 1994/05/25 22:19:57 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.     printx ("\nPress any Key\n"); 
  44.     getx(); 
  45.  
  46. int ask_for_drive_number (void) 
  47.     int drives_found = 0; 
  48.     int drive_table[] = {0,0,0,0,0,0,0,0,0}; 
  49.  
  50.     int no_of_drives = get_no_of_drives (); 
  51.  
  52.     for (int i=0x80; i<0x80 + no_of_drives; i++) if (get_disk_type(i) == 3) 
  53.     { 
  54.         drive_table[drives_found++] = i; 
  55.         if (drives_found == 10) 
  56.             error ("Too many drives found"); 
  57.     } 
  58.  
  59.     if (drives_found == 0) 
  60.         error ("No Compatible Harddisk found"); 
  61.     if (drives_found == 1) return (drive_table[0]); 
  62.  
  63.     printx ("Which Drive ("); 
  64.  
  65.     for (i=0;i<drives_found;i++) printx ("%u=0x%02X/",i+1,drive_table[i]); 
  66.     printx ("\b)? "); 
  67.  
  68.     while (true) 
  69.     { 
  70.         i = getx (); 
  71.         if (isdigit (i)) if (i > '0') if (drive_table[i - '1']) break; 
  72.     } 
  73.     printx ("%c\n",i); 
  74.     return (drive_table[i - '1']); 
  75.  
  76. int ask_for_partition_number (partition_info parts[]) 
  77.     int number_of_partitions = (parts[0].system != 0) + (parts[1].system != 0) + 
  78.          (parts[2].system != 0) + (parts[3].system != 0); 
  79.  
  80.     if (number_of_partitions == 0) 
  81.         error ("No valid partition found"); 
  82.  
  83.     if (number_of_partitions == 4) 
  84.         error ("No free partition"); 
  85.  
  86.     if (number_of_partitions == 1) 
  87.     { 
  88.         wait_for_key(); 
  89.         for (int i=0;i<4;i++) if (parts[i].system) return i; 
  90.     } 
  91.  
  92.     printx ("\nWhich Partition do you want to split ("); 
  93.  
  94.     for (int i=0;i<4;i++) if (parts[i].system) printx ("%u/",i+1); 
  95.     printx ("\b)? "); 
  96.  
  97.     while (true) 
  98.     { 
  99.         i = getx (); 
  100.         if (isdigit (i)) if (('0' < i) && (i <= '4')) if (parts[i-'1'].system) break; 
  101.     } 
  102.     printx ("%c\n",i); 
  103.     return (i-'1'); 
  104.  
  105. dword ask_for_new_start_cylinder (int start_cylinder, int min_cylinder,int max_cylinder, int sectors_per_cylinder) 
  106.     int akt_cylinder = min_cylinder; 
  107.  
  108.     printx ("Enter start cylinder for new partition (%u - %u):\n\n",min_cylinder,max_cylinder); 
  109.     printx ("Use the cursor keys to choose the cylinder, <enter> to continue\n\n"); 
  110.     printx ("Old partition      Cylinder       New Partition\n"); 
  111.  
  112.     while (true) 
  113.     { 
  114.         double oldsize = (akt_cylinder - start_cylinder) * (double) sectors_per_cylinder / 2048; 
  115.         double newsize = (max_cylinder - akt_cylinder + 1) * (double) sectors_per_cylinder / 2048; 
  116.  
  117.         printf (" %6.1f MB          %4u           %6.1f MB\r", oldsize, akt_cylinder, newsize); 
  118.  
  119.         int input = getx (); 
  120.         if (input == '\r') 
  121.         { 
  122.             printx (" %6.1f MB          %4u           %6.1f MB\n\n", oldsize, akt_cylinder, newsize); 
  123.             return (akt_cylinder); 
  124.         } 
  125.         else if (input != 0) continue; 
  126.  
  127.         input = getx (); 
  128.         switch (input) 
  129.         { 
  130.             case 75: 
  131.                 if (akt_cylinder > min_cylinder) akt_cylinder--; 
  132.                 break; 
  133.             case 77: 
  134.                 if (akt_cylinder < max_cylinder) akt_cylinder++; 
  135.                 break; 
  136.             case 72: 
  137.                 if (akt_cylinder - 10 >= min_cylinder) akt_cylinder -= 10; 
  138.                 break; 
  139.             case 80: 
  140.                 if (akt_cylinder + 10 <= max_cylinder) akt_cylinder += 10; 
  141.                 break; 
  142.         } 
  143.     } 
  144.  
  145. void ask_for_write_permission (void) 
  146.     printx ("\nReady to write new partition scheme to disk\n"); 
  147.     printx ("Do you want to proceed (y/n)? "); 
  148.  
  149.     int character; 
  150.     do character = getx(); while ((character != 'y') && (character != 'n')); 
  151.     printx ("%c\n",character); 
  152.     if (character == 'n') exit (0); 
  153.  
  154. boolean ask_if_continue (void) 
  155.     printx ("\nDo you want to continue or reedit the partition table (c/r)? "); 
  156.  
  157.     int character; 
  158.     do character = getx(); while ((character != 'c') && (character != 'r')); 
  159.     printx ("%c\n",character); 
  160.     if (character == 'r') return (false); 
  161.     return (true); 
  162.  
  163. boolean ask_if_save (void) 
  164.     int character; 
  165.  
  166.     printx ("Do you want to make a backup copy of your root- and bootsector before\nproceeding (y/n)? "); 
  167.     do character = getx(); while ((character != 'y') && (character != 'n')); 
  168.     printx ("%c\n\n",character); 
  169.     if (character == 'n') return (false); 
  170.  
  171.     printx ("Do you have a bootable floppy disk in drive A: as described in the\ndocumentation (y/n)? "); 
  172.     do character = getx(); while ((character != 'y') && (character != 'n')); 
  173.     printx ("%c\n\n",character); 
  174.     if (character == 'n') 
  175.     { 
  176.         printx ("Please read the file FIPS.DOC!\n"); 
  177.         exit (0); 
  178.     } 
  179.  
  180.     return (true); 
  181.  
  182. void ask_if_proceed (void) 
  183.     printx ("Do you want to proceed (y/n)? "); 
  184.  
  185.     int character; 
  186.     do character = getx(); while ((character != 'y') && (character != 'n')); 
  187.     printx ("%c\n",character); 
  188.     if (character == 'n') exit (0); 
  189.