1 kumpf 1.2 /*
|
2 martin 1.4 //%LICENSE////////////////////////////////////////////////////////////////
|
3 martin 1.5 //
|
4 martin 1.4 // Licensed to The Open Group (TOG) under one or more contributor license
5 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
6 // this work for additional information regarding copyright ownership.
7 // Each contributor licenses this file to you under the OpenPegasus Open
8 // Source License; you may not use this file except in compliance with the
9 // License.
|
10 martin 1.5 //
|
11 martin 1.4 // Permission is hereby granted, free of charge, to any person obtaining a
12 // copy of this software and associated documentation files (the "Software"),
13 // to deal in the Software without restriction, including without limitation
14 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 // and/or sell copies of the Software, and to permit persons to whom the
16 // Software is furnished to do so, subject to the following conditions:
|
17 martin 1.5 //
|
18 martin 1.4 // The above copyright notice and this permission notice shall be included
19 // in all copies or substantial portions of the Software.
|
20 martin 1.5 //
|
21 martin 1.4 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
22 martin 1.5 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
23 martin 1.4 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
25 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
28 martin 1.5 //
|
29 martin 1.4 //////////////////////////////////////////////////////////////////////////
|
30 kumpf 1.2 */
31
32 #include "Options.h"
33 #include <string.h>
34
35 /*
36 **==============================================================================
37 **
38 ** _TestFlagOption()
39 **
40 ** Check whether argv contains the given option. Return 0 if so. Else
41 ** return -1. Remove the argument from the list if the *remove* argument
42 ** is non-zero.
43 **
44 ** if (_TestFlagOption(&argc, &argv, "--help", 0) == 0)
45 ** {
46 ** }
47 **
48 **==============================================================================
49 */
50
51 kumpf 1.2 static int _TestFlagOption(
52 int* argc_, char*** argv_, const char* option, int remove)
53 {
54 int argc = *argc_;
55 char** argv = *argv_;
56 int i;
57
58 for (i = 0; i < argc; i++)
59 {
60 if (strcmp(argv[i], option) == 0)
61 {
62 if (remove)
63 {
|
64 kumpf 1.3 memmove(&argv[i], &argv[i + 1], (argc-i-1) * sizeof(char*));
|
65 kumpf 1.2 argc--;
66 }
67
68 *argc_ = argc;
69 *argv_ = argv;
70 return 0;
71 }
72 }
73
74 /* Not found */
75 return -1;
76 }
77
78 /*
79 **==============================================================================
80 **
81 ** GetOptions()
82 **
83 ** Get all "minus" options from the command line. Place corresponding flags
84 ** into Options structure.
85 **
86 kumpf 1.2 **==============================================================================
87 */
88
89 void GetOptions(int* argc, char*** argv, struct Options* options)
90 {
91 memset(options, 0, sizeof(struct Options));
92
93 if (_TestFlagOption(argc, argv, "--dump", 1) == 0)
94 options->dump = 1;
95
|
96 denise.eckstein 1.6 if (_TestFlagOption(argc, argv, "--status", 1) == 0)
97 options->status = 1;
98
|
99 kumpf 1.2 if (_TestFlagOption(argc, argv, "--version", 0) == 0)
100 options->version = 1;
101
102 if (_TestFlagOption(argc, argv, "-v", 0) == 0)
103 options->version = 1;
104
105 if (_TestFlagOption(argc, argv, "--help", 0) == 0)
106 options->help = 1;
107
108 if (_TestFlagOption(argc, argv, "-h", 0) == 0)
109 options->help = 1;
110
111 if (_TestFlagOption(argc, argv, "-s", 0) == 0)
112 options->shutdown = 1;
113
114 if (_TestFlagOption(argc, argv, "-X", 0) == 0)
115 options->bindVerbose = 1;
116 }
|