43
43
************************************************************************
47
49
#include <stdlib.h>
49
50
#include <string.h>
52
#include "cmdlineargs.h"
52
53
#include "internal.h"
53
#include "cmdlineargs.h"
57
56
* Process command line arguments using getopt_long.
58
57
* @param argc The standard CLA argc.
59
58
* @param argv The standard CLA argv.
60
* @param block_flag Struct for the block flag.
61
* @param lock_flag Struct for the lock flag.
62
* @param release_flag Struct for the release flag.
63
* @param reset_flag Struct for the reset flag.
64
* @param status_flag Struct for the status flag.
65
* @param unblock_flag Struct for the unblock flag.
66
* @param wait_flag Struct for the wait flag.
59
* @param ... Variable number of flag structs.
67
60
* @return 0 on success, on failure standard EX_USAGE (64) command line usage
83
struct option long_options[] = {
84
{"block", no_argument, NULL, 'b'},
85
{"help", no_argument, NULL, 'h'},
86
{"lock", no_argument, NULL, 'l'},
87
{"release", no_argument, NULL, 'r'},
88
{"reset", no_argument, NULL, 'i'},
89
{"status", no_argument, NULL, 's'},
90
{"unblock", no_argument, NULL, 'u'},
91
{"version", no_argument, NULL, 'V'},
92
{"wait", optional_argument, NULL, 'w'},
76
struct option long_options[]
77
= { { "block", no_argument, NULL, 'b' },
78
{ "help", no_argument, NULL, 'h' },
79
{ "lock", no_argument, NULL, 'l' },
80
{ "release", no_argument, NULL, 'r' },
81
{ "reset", no_argument, NULL, 'i' },
82
{ "status", no_argument, NULL, 's' },
83
{ "unblock", no_argument, NULL, 'u' },
84
{ "version", no_argument, NULL, 'V' },
85
{ "wait", optional_argument, NULL, 'w' },
86
{ NULL, 0, NULL, 0 } };
96
88
va_start(ap, argv);
97
89
block_flag = va_arg(ap, struct cla *);
103
95
wait_flag = va_arg(ap, struct cla *);
106
while ((c = getopt_long(argc, argv, "bhilrsuVw::",
107
long_options, &option_index)) != -1) {
98
while ((c = getopt_long(argc, argv, "bhilrsuVw::", long_options,
111
103
if (lock_flag->is_set || release_flag->is_set
112
104
|| reset_flag->is_set || status_flag->is_set
113
105
|| unblock_flag->is_set || wait_flag->is_set) {
114
106
fprintf(stderr, "Options b, i, l, r, s, u and "
115
"w are mutually exclusive.\n");
107
"w are mutually exclusive.\n");
118
110
block_flag->is_set = 1;
122
114
|| release_flag->is_set || status_flag->is_set
123
115
|| unblock_flag->is_set || wait_flag->is_set) {
124
116
fprintf(stderr, "Options b, i, l, r, s, u and "
125
"w are mutually exclusive.\n");
117
"w are mutually exclusive.\n");
128
120
reset_flag->is_set = 1;
131
123
printf("%s %s", argv[0], " - Help option.\n");
132
124
printf("\tLong and short options can be mixed on the "
133
"command line but if an option takes an "
134
"optional argument it is best to enter "
135
"-o\"argument\" or --option=argument.\n");
125
"command line but if an option takes an "
126
"optional argument it is best to enter "
127
"-o\"argument\" or --option=argument.\n");
136
128
printf("-b | --block\tBlock client on server.\n");
137
129
printf("-i | --reset\tSet locks to 0 and unblock "
138
130
"client on server.\n");
139
131
printf("-l | --lock\tSet client lock on server.\n");
140
132
printf("-r | --release\tRelease client lock on "
142
134
printf("-u | --unblock\tUnblock client on server.\n");
143
135
printf("-s | --status\tShow the locking status.\n");
144
136
printf("-V | --version\tDisplay version "
146
138
printf("-w[NumLocks] | --wait[=NumLocks]\tWait until "
147
"this client has NumLocks or fewer locks.\n");
139
"this client has NumLocks or fewer locks.\n");
152
144
|| reset_flag->is_set || status_flag->is_set
153
145
|| unblock_flag->is_set || wait_flag->is_set) {
154
146
fprintf(stderr, "Options b, i, l, r, s, u and "
155
"w are mutually exclusive.\n");
147
"w are mutually exclusive.\n");
158
150
lock_flag->is_set = 1;
163
155
|| reset_flag->is_set || status_flag->is_set
164
156
|| unblock_flag->is_set || wait_flag->is_set) {
165
157
fprintf(stderr, "Options b, i, l, r, s, u and "
166
"w are mutually exclusive.\n");
158
"w are mutually exclusive.\n");
169
161
release_flag->is_set = 1;
173
165
|| release_flag->is_set || reset_flag->is_set
174
166
|| status_flag->is_set || wait_flag->is_set) {
175
167
fprintf(stderr, "Options b, i, l, r, s, u and "
176
"w are mutually exclusive.\n");
168
"w are mutually exclusive.\n");
179
171
unblock_flag->is_set = 1;
183
175
|| release_flag->is_set || reset_flag->is_set
184
176
|| unblock_flag->is_set || wait_flag->is_set) {
185
177
fprintf(stderr, "Options b, i, l, r, s, u and "
186
"w are mutually exclusive.\n");
178
"w are mutually exclusive.\n");
189
181
status_flag->is_set = 1;
192
184
printf("%s %s %s %s", argv[0], "Source version -",
193
swocclient_get_src_version(), "\n");
185
swocclient_get_src_version(), "\n");
194
186
printf("%s %s %s %s", argv[0], "Package version -",
195
swocclient_get_pkg_version(), "\n");
187
swocclient_get_pkg_version(), "\n");
200
192
|| release_flag->is_set || reset_flag->is_set
201
193
|| status_flag->is_set || unblock_flag->is_set) {
202
194
fprintf(stderr, "Options b, i, l, r, s, u and "
203
"w are mutually exclusive.\n");
195
"w are mutually exclusive.\n");
206
198
wait_flag->is_set = 1;