home *** CD-ROM | disk | FTP | other *** search
/ James Briskly's Game Magazine 2 / JBGM002S.ZIP / SOURCE / CMDL_ARG.CPP < prev    next >
C/C++ Source or Header  |  1995-08-22  |  3KB  |  139 lines

  1. /*
  2.     FIPS - the First nondestructive Interactive Partition Splitting program
  3.  
  4.     Module cmdl_arg.cpp
  5.  
  6.     RCS - Header:
  7.     $Header: c:/daten/fips/source/main/RCS/cmdl_arg.cpp 1.4 1995/01/19 00:00:51 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 <stdio.h>
  32. #include <ctype.h>
  33. #include <string.h>
  34. #include <stdlib.h>
  35.  
  36. #include "global.h"
  37. #include "getopt.h"
  38.  
  39.  
  40. /* ----------------------------------------------------------------------- */
  41. /* Replacement for atoi                                                    */
  42. /* ----------------------------------------------------------------------- */
  43.  
  44. static int atoint (char *string)
  45. {
  46.     long int value = 0;
  47.     while (isdigit (*string))
  48.     {
  49.         value = value * 10 + (*string - '0');
  50.         if (value > 32767) return (-1);
  51.         string++;
  52.     }
  53.     if (*string != '\0') return (-1);
  54.     return (int) value;
  55. }
  56.  
  57.  
  58. /* ----------------------------------------------------------------------- */
  59. /* Usage instructions                                                      */
  60. /* ----------------------------------------------------------------------- */
  61.  
  62. static void usage (void)
  63. {
  64.     printf ("\nFIPS [-t] [-d] [-h|-?] [-n<num>]:\n\n");
  65.     printf ("-t        : test mode (no writes to disk)\n");
  66.     printf ("-d        : debug mode\n");
  67.     printf ("-h/-?     : this help page\n");
  68.     printf ("-n<num>   : select drive <num> - valid values: 128 to 255\n");
  69. }
  70.  
  71.  
  72. /* ----------------------------------------------------------------------- */
  73. /* Process commandline parameters                                          */
  74. /* ----------------------------------------------------------------------- */
  75.  
  76. void evaluate_argument_vector (int argc, char *argv[])
  77. {
  78.     int c;
  79.  
  80.     opterr = 0;
  81.  
  82.     while ((c = getopt (argc, argv, ":htdn:")) >= 0)
  83.     {
  84.         switch (c)
  85.         {
  86.             case 't':
  87.                 global.test_mode = true;
  88.                 break;
  89.             case 'd':
  90.                 global.debug_mode = true;
  91.                 break;
  92.             case 'h':
  93.                 usage ();
  94.                 exit (1);
  95.             case 'n':
  96.                 global.drive_number_cmdline = atoint (optarg);
  97.  
  98.                 if
  99.                 (
  100.                     global.drive_number_cmdline < 0x80
  101.                     || global.drive_number_cmdline > 0xff
  102.                 )
  103.                 {
  104.                     fprintf
  105.                     (
  106.                         stderr,
  107.                         "\nInvalid argument: %s\n",
  108.                         optarg
  109.                     );
  110.  
  111.                     usage ();
  112.                     exit (-1);
  113.                 }
  114.                 break;
  115.             case ':':
  116.                 fprintf
  117.                 (
  118.                     stderr,
  119.                     "\nSwitch %c requires an argument\n",
  120.                     optopt
  121.                 );
  122.                 usage ();
  123.                 exit (-1);
  124.             case '?':
  125.                 if (optopt != '?')
  126.                     fprintf
  127.                     (
  128.                         stderr,
  129.                         "\nInvalid Commandline Parameter: %s\n",
  130.                         argv[optind - 1]
  131.                     );
  132.  
  133.                 usage ();
  134.                 exit (-1);
  135.         } /* switch */
  136.  
  137.     } /* while */
  138. }
  139.