home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 8 / IOPROG_8.ISO / install / fips / source / input.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-25  |  5.9 KB  |  233 lines

  1. /*
  2.  
  3.     FIPS - the First nondestructive Interactive Partition Splitting program
  4.  
  5.  
  6.  
  7.     Module input.cpp
  8.  
  9.  
  10.  
  11.     RCS - Header:
  12.  
  13.     $Header: c:/daten/fips/source/main/RCS/input.cpp 1.4 1995/01/19 00:00:54 schaefer Exp schaefer $
  14.  
  15.  
  16.  
  17.     Copyright (C) 1993 Arno Schaefer
  18.  
  19.  
  20.  
  21.     This program is free software; you can redistribute it and/or modify
  22.  
  23.     it under the terms of the GNU General Public License as published by
  24.  
  25.     the Free Software Foundation; either version 2 of the License, or
  26.  
  27.     (at your option) any later version.
  28.  
  29.  
  30.  
  31.     This program is distributed in the hope that it will be useful,
  32.  
  33.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  34.  
  35.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  36.  
  37.     GNU General Public License for more details.
  38.  
  39.  
  40.  
  41.     You should have received a copy of the GNU General Public License
  42.  
  43.     along with this program; if not, write to the Free Software
  44.  
  45.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  46.  
  47.  
  48.  
  49.  
  50.  
  51.     Report problems and direct all questions to:
  52.  
  53.  
  54.  
  55.     schaefer@rbg.informatik.th-darmstadt.de
  56.  
  57. */
  58.  
  59.  
  60.  
  61. #include <ctype.h>
  62.  
  63. #include <stdlib.h>
  64.  
  65. #include "types.h"
  66.  
  67. #include "disk_io.h"
  68.  
  69. #include "global.h"
  70.  
  71. #include "input.h"
  72.  
  73.  
  74.  
  75. /* ----------------------------------------------------------------------- */
  76.  
  77. /* User Input                                                              */
  78.  
  79. /* ----------------------------------------------------------------------- */
  80.  
  81.  
  82.  
  83. static void wait_for_key (void)
  84.  
  85. {
  86.  
  87.     printx ("\nPress any Key\n");
  88.  
  89.     getx();
  90.  
  91. }
  92.  
  93.  
  94.  
  95.  
  96.  
  97. int ask_for_drive_number (void)
  98.  
  99.  
  100.  
  101. /*
  102.  
  103.  * Find Disk Drives - if more than one, ask for drive number. If no drive
  104.  
  105.  * was found, issue warning, try drive 0x80 anyway
  106.  
  107.  */
  108.  
  109.  
  110.  
  111. {
  112.  
  113.     int drives_found = 0;
  114.  
  115.     int drive_table[] = {0,0,0,0,0,0,0,0,0};
  116.  
  117.  
  118.  
  119.     int no_of_drives = get_no_of_drives ();
  120.  
  121.  
  122.  
  123.     for (int i=0x80; i < 0x80 + no_of_drives; i++)
  124.  
  125.     {
  126.  
  127.         if (get_disk_type (i) == 3)
  128.  
  129.         {
  130.  
  131.             drive_table[drives_found++] = i;
  132.  
  133.             if (drives_found == 9)
  134.  
  135.                 break;
  136.  
  137.         }
  138.  
  139.     }
  140.  
  141.  
  142.  
  143.     if (drives_found == 0)
  144.  
  145.     {
  146.  
  147.         warning (false, "No compatible hard disk found");
  148.  
  149.         ask_if_continue ();
  150.  
  151.  
  152.  
  153.         return (0x80);
  154.  
  155.     }
  156.  
  157.  
  158.  
  159.     if (drives_found == 1)
  160.  
  161.         return (drive_table[0]);
  162.  
  163.  
  164.  
  165.     printx ("Which Drive (");
  166.  
  167.  
  168.  
  169.     for (i=0; i<drives_found; i++)
  170.  
  171.         printx ("%u=0x%02X/", i+1, drive_table[i]);
  172.  
  173.     printx ("\b)? ");
  174.  
  175.  
  176.  
  177.     while (true)
  178.  
  179.     {
  180.  
  181.         i = getx ();
  182.  
  183.  
  184.  
  185.         if (i >= '1' && i <= '9')
  186.  
  187.             if (drive_table[i - '1'] != 0) break;
  188.  
  189.     }
  190.  
  191.  
  192.  
  193.     printx ("%c\n",i);
  194.  
  195.     return (drive_table[i - '1']);
  196.  
  197. }
  198.  
  199.  
  200.  
  201.  
  202.  
  203. int ask_for_partition_number (partition_info parts[])
  204.  
  205. {
  206.  
  207.     int number_of_partitions = (parts[0].system != 0) + (parts[1].system != 0) +
  208.  
  209.          (parts[2].system != 0) + (parts[3].system != 0);
  210.  
  211.  
  212.  
  213.     if (number_of_partitions == 0)
  214.  
  215.         error ("No valid partition found");
  216.  
  217.  
  218.  
  219.     if (number_of_partitions == 4)
  220.  
  221.         error ("No free partition");
  222.  
  223.  
  224.  
  225.     if (number_of_partitions == 1)
  226.  
  227.     {
  228.  
  229.         wait_for_key();
  230.  
  231.         for (int i = 0; i < 4; i++) if (parts[i].system) return i;
  232.  
  233.     }
  234.  
  235.  
  236.  
  237.     printx ("\nWhich Partition do you want to split (");
  238.  
  239.  
  240.  
  241.     for (int i = 0; i < 4; i++) if (parts[i].system) printx ("%u/", i + 1);
  242.  
  243.     printx ("\b)? ");
  244.  
  245.  
  246.  
  247.     while (true)
  248.  
  249.     {
  250.  
  251.         i = getx ();
  252.  
  253.         if (isdigit (i)) if (('0' < i) && (i <= '4')) if (parts[i - '1'].system) break;
  254.  
  255.     }
  256.  
  257.     printx ("%c\n", i);
  258.  
  259.     return (i - '1');
  260.  
  261. }
  262.  
  263.  
  264.  
  265.  
  266.  
  267. dword ask_for_new_start_cylinder (int start_cylinder, int min_cylinder, int max_cylinder, int sectors_per_cylinder)
  268.  
  269. {
  270.  
  271.     int akt_cylinder = min_cylinder;
  272.  
  273.  
  274.  
  275.     printx ("\nEnter start cylinder for new partition (%u - %u):\n\n",min_cylinder,max_cylinder);
  276.  
  277.     printx ("Use the cursor keys to choose the cylinder, <enter> to continue\n\n");
  278.  
  279.     printx ("Old partition      Cylinder       New Partition\n");
  280.  
  281.  
  282.  
  283.     while (true)
  284.  
  285.     {
  286.  
  287.         double oldsize = (akt_cylinder - start_cylinder) * (double) sectors_per_cylinder / 2048;
  288.  
  289.         double newsize = (max_cylinder - akt_cylinder + 1) * (double) sectors_per_cylinder / 2048;
  290.  
  291.  
  292.  
  293.         printf (" %6.1f MB          %4u           %6.1f MB\r", oldsize, akt_cylinder, newsize);
  294.  
  295.  
  296.  
  297.         int input = getx ();
  298.  
  299.         if (input == '\r')
  300.  
  301.         {
  302.  
  303.             printx (" %6.1f MB          %4u           %6.1f MB\n\n", oldsize, akt_cylinder, newsize);
  304.  
  305.             return (akt_cylinder);
  306.  
  307.         }
  308.  
  309.         else if (input != 0) continue;
  310.  
  311.  
  312.  
  313.         input = getx ();
  314.  
  315.         switch (input)
  316.  
  317.         {
  318.  
  319.             case 75:
  320.  
  321.                 if (akt_cylinder > min_cylinder) akt_cylinder--;
  322.  
  323.                 break;
  324.  
  325.             case 77:
  326.  
  327.                 if (akt_cylinder < max_cylinder) akt_cylinder++;
  328.  
  329.                 break;
  330.  
  331.             case 72:
  332.  
  333.                 if (akt_cylinder - 10 >= min_cylinder) akt_cylinder -= 10;
  334.  
  335.                 break;
  336.  
  337.             case 80:
  338.  
  339.                 if (akt_cylinder + 10 <= max_cylinder) akt_cylinder += 10;
  340.  
  341.                 break;
  342.  
  343.         }
  344.  
  345.     }
  346.  
  347. }
  348.  
  349.  
  350.  
  351. char ask_yes_no (void)
  352.  
  353. {
  354.  
  355.     int character;
  356.  
  357.     do character = getx(); while ((character != 'y') && (character != 'n'));
  358.  
  359.     printx ("%c\n",character);
  360.  
  361.     return (character);
  362.  
  363. }
  364.  
  365.  
  366.  
  367. char ask_correction (void)
  368.  
  369. {
  370.  
  371.     printx ("Do you want to correct this (y/n) ");
  372.  
  373.     return (ask_yes_no ());
  374.  
  375. }
  376.  
  377.  
  378.  
  379.  
  380.  
  381. void ask_for_write_permission (void)
  382.  
  383. {
  384.  
  385.     printx ("\nReady to write new partition scheme to disk\n");
  386.  
  387.     printx ("Do you want to proceed (y/n)? ");
  388.  
  389.  
  390.  
  391.     if (ask_yes_no () == 'n') exit (0);
  392.  
  393. }
  394.  
  395.  
  396.  
  397. boolean ask_if_continue (void)
  398.  
  399. {
  400.  
  401.     printx ("\nDo you want to continue or reedit the partition table (c/r)? ");
  402.  
  403.  
  404.  
  405.     int character;
  406.  
  407.     do character = getx(); while ((character != 'c') && (character != 'r'));
  408.  
  409.     printx ("%c\n",character);
  410.  
  411.     if (character == 'r') return (false);
  412.  
  413.     return (true);
  414.  
  415. }
  416.  
  417.  
  418.  
  419. boolean ask_if_save (void)
  420.  
  421. {
  422.  
  423.     int character;
  424.  
  425.  
  426.  
  427.     printx ("Do you want to make a backup copy of your root and boot sector before\nproceeding (y/n)? ");
  428.  
  429.     if (ask_yes_no () == 'n') return (false);
  430.  
  431.  
  432.  
  433.     printx ("Do you have a bootable floppy disk in drive A: as described in the\ndocumentation (y/n)? ");
  434.  
  435.     if (ask_yes_no () == 'n')
  436.  
  437.     {
  438.  
  439.         printx ("Please read the file FIPS.DOC!\n");
  440.  
  441.         exit (0);
  442.  
  443.     }
  444.  
  445.  
  446.  
  447.     return (true);
  448.  
  449. }
  450.  
  451.  
  452.  
  453. void ask_if_proceed (void)
  454.  
  455. {
  456.  
  457.     printx ("Do you want to proceed (y/n)? ");
  458.  
  459.  
  460.  
  461.     if (ask_yes_no () == 'n') exit (0);
  462.  
  463. }
  464.  
  465.