dav/optparser.c

Thu, 17 Mar 2016 15:06:26 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 17 Mar 2016 15:06:26 +0100
changeset 215
781aee172901
parent 213
cd870d5f8659
child 219
9792cfe63b80
permissions
-rw-r--r--

dav-sync add-directory shows list of repositories

11
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
185
cd42cccee550 updated copyright notice
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
4 * Copyright 2016 Olaf Wintermann. All rights reserved.
11
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <string.h>
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "optparser.h"
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 void cmd_args_free(CmdArgs *args) {
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 ucx_map_free(args->options);
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 free(args->argv);
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
38 free(args);
11
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 }
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 CmdArgs* cmd_parse_args(int argc, char **argv) {
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 CmdArgs *a = malloc(sizeof(CmdArgs));
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 a->options = ucx_map_new(16);
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 a->argv = calloc(argc, sizeof(char*));
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 a->argc = 0;
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46
68
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
47 const char *NOARG = "";
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
48
11
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 char *option = NULL;
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 char optchar = 0;
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 for(int i=0;i<argc;i++) {
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 char *arg = argv[i];
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 size_t len = strlen(arg);
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 if(len > 1 && arg[0] == '-') {
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 for(int c=1;c<len;c++) {
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 switch(arg[c]) {
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 default: {
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 fprintf(stderr, "Unknown option -%c", arg[c]);
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 cmd_args_free(a);
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 return NULL;
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 }
68
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
62 case 'v': {
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
63 ucx_map_cstr_put(a->options, "verbose", NOARG);
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
64 break;
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
65 }
11
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 case 'k': {
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 if(!option) {
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 option = "key";
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 optchar = 'k';
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 } else {
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 fprintf(
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 stderr,
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 "Missing argument for option -%c\n",
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 optchar);
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 cmd_args_free(a);
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 return NULL;
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 }
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 break;
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 }
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 case 'p': {
68
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
81 ucx_map_cstr_put(a->options, "plain", NOARG);
11
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 break;
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 }
45
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
84 case 'c': {
68
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
85 ucx_map_cstr_put(a->options, "crypt", NOARG);
45
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
86 break;
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
87 }
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
88 case 'a': {
68
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
89 ucx_map_cstr_put(a->options, "all", NOARG);
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
90 break;
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
91 }
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
92 case 'l': {
68
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
93 ucx_map_cstr_put(a->options, "list", NOARG);
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
94 break;
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
95 }
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
96 case 't': {
68
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
97 ucx_map_cstr_put(a->options, "type", NOARG);
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
98 break;
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
99 }
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
100 case 'R': {
68
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
101 ucx_map_cstr_put(a->options, "recursive", NOARG);
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
102 break;
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
103 }
182
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
104 case 'O': {
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
105 ucx_map_cstr_put(a->options, "override", NOARG);
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
106 break;
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
107 }
199
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
108 case 'i': {
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
109 ucx_map_cstr_put(a->options, "insecure", NOARG);
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
110 break;
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
111 }
213
cd870d5f8659 added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
112 case 'N': {
212
01e80c7cfe96 added noinput option to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 209
diff changeset
113 ucx_map_cstr_put(a->options, "noinput", NOARG);
01e80c7cfe96 added noinput option to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 209
diff changeset
114 break;
01e80c7cfe96 added noinput option to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 209
diff changeset
115 }
213
cd870d5f8659 added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
116 case 'e': {
cd870d5f8659 added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
117 ucx_map_cstr_put(a->options, "extended", NOARG);
cd870d5f8659 added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
118 break;
cd870d5f8659 added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
119 }
11
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 case 'o': {
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 if(!option) {
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 option = "output";
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 optchar = 'o';
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 } else {
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 fprintf(
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 stderr,
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 "Missing argument for option -%c\n",
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 optchar);
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 cmd_args_free(a);
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 return NULL;
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 }
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 break;
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 }
30
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
134 case 'u': {
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
135 if(!option) {
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
136 option = "update";
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
137 optchar = 'u';
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
138 } else {
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
139 fprintf(
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
140 stderr,
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
141 "Missing argument for option -%c\n",
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
142 optchar);
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
143 cmd_args_free(a);
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
144 return NULL;
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
145 }
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
146 break;
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
147 }
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
148 case 'n': {
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
149 if(!option) {
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
150 option = "namespace";
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
151 optchar = 'n';
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
152 } else {
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
153 fprintf(
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
154 stderr,
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
155 "Missing argument for option -%c\n",
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
156 optchar);
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
157 cmd_args_free(a);
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
158 return NULL;
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
159 }
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
160 break;
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
161 }
209
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
162 case 'L': {
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
163 if(!option) {
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
164 option = "lock";
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
165 optchar = 'L';
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
166 } else {
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
167 fprintf(
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
168 stderr,
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
169 "Missing argument for option -%c\n",
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
170 optchar);
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
171 cmd_args_free(a);
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
172 return NULL;
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
173 }
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
174 break;
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
175 }
11
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 }
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 }
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 } else if(option) {
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 ucx_map_cstr_put(a->options, option, arg);
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 option = NULL;
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 } else {
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 a->argv[a->argc++] = arg;
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 }
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 }
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 return a;
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 }
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 char* cmd_getoption(CmdArgs *arg, char *name) {
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 return ucx_map_cstr_get(arg->options, name);
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 }

mercurial