(file) Return to Options.c CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Executor

  1 kumpf 1.2 /*
  2           //%2006////////////////////////////////////////////////////////////////////////
  3           //
  4           // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  5           // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  6           // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  7           // IBM Corp.; EMC Corporation, The Open Group.
  8           // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  9           // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
 10           // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 11           // EMC Corporation; VERITAS Software Corporation; The Open Group.
 12           // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 13           // EMC Corporation; Symantec Corporation; The Open Group.
 14           //
 15           // Permission is hereby granted, free of charge, to any person obtaining a copy
 16           // of this software and associated documentation files (the "Software"), to
 17           // deal in the Software without restriction, including without limitation the
 18           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 19           // sell copies of the Software, and to permit persons to whom the Software is
 20           // furnished to do so, subject to the following conditions:
 21           // 
 22 kumpf 1.2 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 23           // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 24           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 25           // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 26           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 27           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 28           // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 29           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 30           //
 31           //%/////////////////////////////////////////////////////////////////////////////
 32           */
 33           
 34           #include "Options.h"
 35           #include <string.h>
 36           
 37           /*
 38           **==============================================================================
 39           **
 40           ** _TestFlagOption()
 41           **
 42           **     Check whether argv contains the given option. Return 0 if so. Else
 43 kumpf 1.2 **     return -1. Remove the argument from the list if the *remove* argument
 44           **     is non-zero.
 45           **
 46           **         if (_TestFlagOption(&argc, &argv, "--help", 0) == 0)
 47           **         {
 48           **         }
 49           **
 50           **==============================================================================
 51           */
 52           
 53           static int _TestFlagOption(
 54               int* argc_, char*** argv_, const char* option, int remove)
 55           {
 56               int argc = *argc_;
 57               char** argv = *argv_;
 58               int i;
 59           
 60               for (i = 0; i < argc; i++)
 61               {
 62                   if (strcmp(argv[i], option) == 0)
 63                   {
 64 kumpf 1.2             if (remove)
 65                       {
 66                           memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
 67                           argc--;
 68                       }
 69           
 70                       *argc_ = argc;
 71                       *argv_ = argv;
 72                       return 0;
 73                   }
 74               }
 75           
 76               /* Not found */
 77               return -1;
 78           }
 79           
 80           /*
 81           **==============================================================================
 82           **
 83           ** GetOptions()
 84           **
 85 kumpf 1.2 **     Get all "minus" options from the command line. Place corresponding flags
 86           **     into Options structure.
 87           **
 88           **==============================================================================
 89           */
 90           
 91           void GetOptions(int* argc, char*** argv, struct Options* options)
 92           {
 93               memset(options, 0, sizeof(struct Options));
 94           
 95               if (_TestFlagOption(argc, argv, "--dump", 1) == 0)
 96                   options->dump = 1;
 97           
 98               if (_TestFlagOption(argc, argv, "--version", 0) == 0)
 99                   options->version = 1;
100           
101               if (_TestFlagOption(argc, argv, "-v", 0) == 0)
102                   options->version = 1;
103           
104               if (_TestFlagOption(argc, argv, "--help", 0) == 0)
105                   options->help = 1;
106 kumpf 1.2 
107               if (_TestFlagOption(argc, argv, "-h", 0) == 0)
108                   options->help = 1;
109           
110               if (_TestFlagOption(argc, argv, "-s", 0) == 0)
111                   options->shutdown = 1;
112           
113               if (_TestFlagOption(argc, argv, "-X", 0) == 0)
114                   options->bindVerbose = 1;
115           }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2