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

  1. /*
  2.  
  3.     FIPS - the First nondestructive Interactive Partition Splitting program
  4.  
  5.  
  6.  
  7.     Module cmdl_arg.cpp
  8.  
  9.  
  10.  
  11.     RCS - Header:
  12.  
  13.     $Header: c:/daten/fips/source/main/RCS/cmdl_arg.cpp 1.4 1995/01/19 00:00:51 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 <stdio.h>
  62.  
  63. #include <ctype.h>
  64.  
  65. #include <string.h>
  66.  
  67. #include <stdlib.h>
  68.  
  69.  
  70.  
  71. #include "global.h"
  72.  
  73. #include "getopt.h"
  74.  
  75.  
  76.  
  77.  
  78.  
  79. /* ----------------------------------------------------------------------- */
  80.  
  81. /* Replacement for atoi                                                    */
  82.  
  83. /* ----------------------------------------------------------------------- */
  84.  
  85.  
  86.  
  87. static int atoint (char *string)
  88.  
  89. {
  90.  
  91.     long int value = 0;
  92.  
  93.     while (isdigit (*string))
  94.  
  95.     {
  96.  
  97.         value = value * 10 + (*string - '0');
  98.  
  99.         if (value > 32767) return (-1);
  100.  
  101.         string++;
  102.  
  103.     }
  104.  
  105.     if (*string != '\0') return (-1);
  106.  
  107.     return (int) value;
  108.  
  109. }
  110.  
  111.  
  112.  
  113.  
  114.  
  115. /* ----------------------------------------------------------------------- */
  116.  
  117. /* Usage instructions                                                      */
  118.  
  119. /* ----------------------------------------------------------------------- */
  120.  
  121.  
  122.  
  123. static void usage (void)
  124.  
  125. {
  126.  
  127.     printf ("\nFIPS [-t] [-d] [-h|-?] [-n<num>]:\n\n");
  128.  
  129.     printf ("-t        : test mode (no writes to disk)\n");
  130.  
  131.     printf ("-d        : debug mode\n");
  132.  
  133.     printf ("-h/-?     : this help page\n");
  134.  
  135.     printf ("-n<num>   : select drive <num> - valid values: 128 to 255\n");
  136.  
  137. }
  138.  
  139.  
  140.  
  141.  
  142.  
  143. /* ----------------------------------------------------------------------- */
  144.  
  145. /* Process commandline parameters                                          */
  146.  
  147. /* ----------------------------------------------------------------------- */
  148.  
  149.  
  150.  
  151. void evaluate_argument_vector (int argc, char *argv[])
  152.  
  153. {
  154.  
  155.     int c;
  156.  
  157.  
  158.  
  159.     opterr = 0;
  160.  
  161.  
  162.  
  163.     while ((c = getopt (argc, argv, ":htdn:")) >= 0)
  164.  
  165.     {
  166.  
  167.         switch (c)
  168.  
  169.         {
  170.  
  171.             case 't':
  172.  
  173.                 global.test_mode = true;
  174.  
  175.                 break;
  176.  
  177.             case 'd':
  178.  
  179.                 global.debug_mode = true;
  180.  
  181.                 break;
  182.  
  183.             case 'h':
  184.  
  185.                 usage ();
  186.  
  187.                 exit (1);
  188.  
  189.             case 'n':
  190.  
  191.                 global.drive_number_cmdline = atoint (optarg);
  192.  
  193.  
  194.  
  195.                 if
  196.  
  197.                 (
  198.  
  199.                     global.drive_number_cmdline < 0x80
  200.  
  201.                     || global.drive_number_cmdline > 0xff
  202.  
  203.                 )
  204.  
  205.                 {
  206.  
  207.                     fprintf
  208.  
  209.                     (
  210.  
  211.                         stderr,
  212.  
  213.                         "\nInvalid argument: %s\n",
  214.  
  215.                         optarg
  216.  
  217.                     );
  218.  
  219.  
  220.  
  221.                     usage ();
  222.  
  223.                     exit (-1);
  224.  
  225.                 }
  226.  
  227.                 break;
  228.  
  229.             case ':':
  230.  
  231.                 fprintf
  232.  
  233.                 (
  234.  
  235.                     stderr,
  236.  
  237.                     "\nSwitch %c requires an argument\n",
  238.  
  239.                     optopt
  240.  
  241.                 );
  242.  
  243.                 usage ();
  244.  
  245.                 exit (-1);
  246.  
  247.             case '?':
  248.  
  249.                 if (optopt != '?')
  250.  
  251.                     fprintf
  252.  
  253.                     (
  254.  
  255.                         stderr,
  256.  
  257.                         "\nInvalid Commandline Parameter: %s\n",
  258.  
  259.                         argv[optind - 1]
  260.  
  261.                     );
  262.  
  263.  
  264.  
  265.                 usage ();
  266.  
  267.                 exit (-1);
  268.  
  269.         } /* switch */
  270.  
  271.  
  272.  
  273.     } /* while */
  274.  
  275. }
  276.  
  277.