home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 8 / CDACTUAL8.iso / install / fips / source / cmdl_arg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-11  |  4.6 KB  |  129 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.1 1994/05/25 22:19:40 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. #include "global.h" 
  36.  
  37. /* ----------------------------------------------------------------------- */ 
  38. /* Replacement for atoi                                                    */ 
  39. /* ----------------------------------------------------------------------- */ 
  40.  
  41. static int atoint (char *string) 
  42.     long int value = 0; 
  43.     while (isdigit (*string)) 
  44.     { 
  45.         value = value * 10 + (*string - '0'); 
  46.         if (value > 32767) return (-1); 
  47.         string++; 
  48.     } 
  49.     if (*string != '\0') return (-1); 
  50.     return (int) value; 
  51.  
  52. /* ----------------------------------------------------------------------- */ 
  53. /* Usage instructions                                                      */ 
  54. /* ----------------------------------------------------------------------- */ 
  55.  
  56. static void usage (void) 
  57.     printf ("\nFIPS {[-t][-d][-h|-?][-d<num>][-p<num>][-c<num>][-o<error>]}:\n\n"); 
  58.     printf ("-t        : test mode (no writes to disk)\n"); 
  59.     printf ("-d        : debug mode\n"); 
  60.     printf ("-h/-?     : this help page\n"); 
  61.     printf ("-d<num>   : select drive <num>\n"); 
  62.     printf ("-p<num>   : select partition <num>\n"); 
  63.     printf ("-c<num>   : new start cylinder = <num>\n"); 
  64.     printf ("-o<error> : override error message\n\n"); 
  65.     printf ("where <error> is\n\n"); 
  66.     printf ("mb - more than one bootable partition\t"); 
  67.     printf ("bf - invalid bootable-flag\n"); 
  68.     printf ("lf - FAT too large\t\t\t"); 
  69.     printf ("sf - FAT too small\n"); 
  70.     printf ("md - wrong media descriptor byte\t"); 
  71.     printf ("re - rootdir entries not multiple of 16\n"); 
  72.  
  73. /* ----------------------------------------------------------------------- */ 
  74. /* Process commandline parameters                                          */ 
  75. /* ----------------------------------------------------------------------- */ 
  76.  
  77. void evaluate_argument_vector (int argc,char *argv[]) 
  78.     while (--argc > 0) 
  79.     { 
  80.         int switchar = (*++argv)[0]; 
  81.         char *sw = *argv + 1; 
  82.  
  83.         if (switchar != '/' && switchar != '-') error ("Invalid Commandline Parameter: %s",*argv); 
  84.  
  85.         else if (!strcmp (sw,"t") || !strcmp (sw,"test")) global.test_mode = true; 
  86.         else if (!strcmp (sw,"d") || !strcmp (sw,"debug")) global.debug_mode = true; 
  87.         else if (!strcmp (sw,"h") || !strcmp (sw,"help") || !strcmp (sw,"?")) 
  88.         { 
  89.             usage (); 
  90.             exit (0); 
  91.         } 
  92.         else if (!strcmp (sw,"omb")) global.override_multiple_boot = true; 
  93.         else if (!strcmp (sw,"obf")) global.override_bootable_flag = true; 
  94.         else if (!strcmp (sw,"ore")) global.override_rootdir_entries = true; 
  95.         else if (!strcmp (sw,"olf")) global.override_large_fat = true; 
  96.         else if (!strcmp (sw,"osf")) global.override_small_fat = true; 
  97.         else if (!strcmp (sw,"omd")) global.override_media_descriptor = true; 
  98.  
  99.         else switch ((*argv)[1]) 
  100.         { 
  101.             case 'd': 
  102.             { 
  103.                 if ((global.drive_number_cmdline = atoint (*argv + 2)) == -1) error ("Invalid Argument: %s",*argv); 
  104.                 if ((global.drive_number_cmdline < 0x80) || (global.drive_number_cmdline > 0xff)) error ("Invalid Drive number: %d",global.drive_number_cmdline); 
  105.                 break; 
  106.             } 
  107.             case 'p': 
  108.             { 
  109.                 if ((global.partition_number_cmdline = atoint (*argv + 2)) == -1) error ("Invalid Argument: %s",*argv); 
  110.                 if ((global.partition_number_cmdline < 1) || (global.partition_number_cmdline > 4)) error ("Invalid Partition number: %d",global.partition_number_cmdline); 
  111.                 break; 
  112.             } 
  113.             case 'c': 
  114.             { 
  115.                 int h = atoint (*argv + 2); 
  116.                 if (h == -1) error ("Invalid Argument: %s",*argv); 
  117.                 global.new_start_cylinder_cmdline = h; 
  118.                 break; 
  119.             } 
  120.             default: error ("Invalid Commandline Parameter: %s",*argv); 
  121.         } 
  122.     } 
  123.