Mercurial > hg > dmlib
annotate src/dmargs.c @ 1743:bcdea45a14cb
Adjust indentation output of commandline help printing.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 10 Jun 2018 02:54:51 +0300 |
parents | ddec147d1f90 |
children | c801995cbb13 |
rev | line source |
---|---|
1742
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1 /* |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
2 * Simple commandline argument processing |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
3 * Programmed and designed by Matti 'ccr' Hamalainen |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
4 * (C) Copyright 2002-2018 Tecnic Software productions (TNSP) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
5 * |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
6 * Please read file 'COPYING' for information on license and distribution. |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
7 */ |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
8 /// @file |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
9 /// @brief Simple commandline argument processing functions |
0 | 10 #include "dmargs.h" |
1742
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
11 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
12 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
13 /** |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
14 * Parse and optionally handle the given long or short option argument. |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
15 * @param currArg current argument string |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
16 * @param argIndex pointer to index of current argument in argv[] |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
17 * @param argc number of arguments |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
18 * @param argv argument string array |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
19 * @param opts options list array |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
20 * @param nopts number of elements in options list array |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
21 * @param handle_option function pointer to callback that handles option arguments |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
22 * @param doProcess if TRUE, actually handle the argument, aka call the handle_option() function. if FALSE, only validity of options are checked. |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
23 * @param isLong TRUE if the option is a --long-format one |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
24 */ |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
25 static BOOL dmArgsProcessOpt( |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
26 char *currArg, int *argIndex, |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
27 int argc, char *argv[], |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
28 const DMOptArg opts[], int nopts, |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
29 BOOL (*handle_option)(int id, char *, char *), |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
30 BOOL doProcess, BOOL isLong) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
31 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
32 const DMOptArg *opt = NULL; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
33 char *optArg = NULL; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
34 int optIndex; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
35 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
36 for (optIndex = 0; optIndex < nopts; optIndex++) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
37 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
38 const DMOptArg *node = &opts[optIndex]; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
39 if (isLong && node->o_long != NULL) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
40 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
41 if (strcmp(currArg, node->o_long) == 0) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
42 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
43 opt = node; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
44 optArg = NULL; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
45 break; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
46 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
47 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
48 size_t len = strlen(node->o_long); |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
49 if (strncmp(currArg, node->o_long, len) == 0 && |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
50 currArg[len] == '=') |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
51 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
52 opt = node; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
53 optArg = (&currArg[len+1] != 0) ? &currArg[len+1] : NULL; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
54 break; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
55 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
56 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
57 else |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
58 if (!isLong && node->o_short != 0) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
59 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
60 if (*currArg == node->o_short) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
61 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
62 opt = node; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
63 optArg = (currArg[1] != 0) ? &currArg[1] : NULL; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
64 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
65 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
66 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
67 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
68 if (opt != NULL) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
69 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
70 // Check for the possible option argument |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
71 if ((opt->flags & OPT_ARGMASK) == OPT_ARGREQ && optArg == NULL) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
72 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
73 if (*argIndex < argc) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
74 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
75 (*argIndex)++; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
76 optArg = argv[*argIndex]; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
77 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
78 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
79 if (optArg == NULL) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
80 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
81 dmErrorMsg("Option '%s%s' requires an argument.\n", |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
82 isLong ? "--" : "-", |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
83 currArg); |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
84 return FALSE; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
85 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
86 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
87 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
88 // Option was given succesfully, try to process it |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
89 if (doProcess && !handle_option(opt->id, optArg, currArg)) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
90 return FALSE; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
91 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
92 else |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
93 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
94 dmErrorMsg("Unknown %s option '%s%s'\n", |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
95 isLong ? "long" : "short", |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
96 isLong ? "--" : "-", |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
97 currArg); |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
98 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
99 return FALSE; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
100 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
101 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
102 return TRUE; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
103 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
104 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
105 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
106 /** |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
107 * Process given array of commandline arguments, handling short |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
108 * and long options by calling the respective callback functions. |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
109 * |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
110 * @param argc number of arguments |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
111 * @param argv argument list |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
112 * @param opts supported option list array |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
113 * @param nopts number of elements in the option list array |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
114 * @param handle_option callback function |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
115 * @param handle_other callback function |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
116 * @param flags processing flags |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
117 * @return return TRUE if all is well |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
118 */ |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
119 BOOL dmArgsProcess(int argc, char *argv[], |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
120 const DMOptArg *opts, const int nopts, |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
121 BOOL(*handle_option)(int id, char *, char *), |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
122 BOOL(*handle_other)(char *), const int flags) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
123 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
124 int argIndex, handleFlags = flags & OPTH_ONLY_MASK; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
125 BOOL optionsOK = TRUE, endOfOptions = FALSE; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
126 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
127 for (argIndex = 1; argIndex < argc; argIndex++) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
128 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
129 char *str = argv[argIndex]; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
130 if (*str == '-' && !endOfOptions) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
131 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
132 // Should we process options? |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
133 BOOL doProcess = (handleFlags & OPTH_ONLY_OPTS) || handleFlags == 0; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
134 BOOL isLong; |
0 | 135 |
1742
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
136 str++; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
137 if (*str == '-') |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
138 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
139 // Check for "--", which ends the options-list |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
140 str++; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
141 if (*str == 0) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
142 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
143 endOfOptions = TRUE; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
144 continue; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
145 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
146 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
147 // We have a long option |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
148 isLong = TRUE; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
149 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
150 else |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
151 isLong = FALSE; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
152 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
153 if (!dmArgsProcessOpt(str, &argIndex, argc, argv, |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
154 opts, nopts, handle_option, doProcess, isLong)) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
155 optionsOK = FALSE; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
156 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
157 else |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
158 if (handleFlags == OPTH_ONLY_OTHER || handleFlags == 0) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
159 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
160 // Was not option argument |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
161 if (handle_other == NULL || |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
162 (handle_other != NULL && !handle_other(str))) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
163 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
164 dmErrorMsg("Invalid argument '%s'\n", str); |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
165 optionsOK = FALSE; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
166 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
167 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
168 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
169 // Check if we bail out on invalid argument |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
170 if (!optionsOK && (flags & OPTH_BAILOUT)) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
171 return FALSE; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
172 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
173 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
174 return optionsOK; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
175 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
176 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
177 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
178 static void dmPad(FILE *outFile, int count) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
179 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
180 while (count--) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
181 fputc(' ', outFile); |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
182 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
183 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
184 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
185 static void dmPrintWrap(FILE *fh, const char *str, int spad, int rpad, int width) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
186 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
187 size_t pos = 0; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
188 BOOL first = TRUE; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
189 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
190 while (str[pos]) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
191 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
192 // Pre-pad line |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
193 int linelen = first ? spad : rpad; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
194 dmPad(fh, first ? 0 : rpad); |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
195 first = FALSE; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
196 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
197 // Skip whitespace at line start |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
198 while (isspace(str[pos]) || str[pos] == '\n') pos++; |
0 | 199 |
1742
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
200 // Handle each word |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
201 while (str[pos] && str[pos] != '\n') |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
202 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
203 size_t next; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
204 int wlen; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
205 for (wlen = 0, next = pos; str[next] && !isspace(str[next]) && str[next] != '\n'; next++, wlen++); |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
206 // fprintf(stdout, "X '%c', %d .. linelen=%d/%d, wlen=%d\n", str[pos], pos, linelen, width, wlen); |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
207 if (linelen + wlen < width) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
208 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
209 for (;pos < next; pos++, linelen++) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
210 fputc(str[pos], fh); |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
211 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
212 if (str[next] == '\n' || str[next] == 0) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
213 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
214 fprintf(fh, "\n"); |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
215 break; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
216 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
217 else |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
218 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
219 fputc(str[pos], fh); |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
220 pos++; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
221 linelen++; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
222 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
223 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
224 else |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
225 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
226 fprintf(fh, "\n"); |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
227 break; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
228 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
229 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
230 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
231 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
232 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
233 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
234 /** |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
235 * Print help for commandline arguments/options |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
236 * @param fh stdio file handle to output to |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
237 * @param opts options list array |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
238 * @param nopts number of elements in options list array |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
239 * @param flags flags (currently unused) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
240 */ |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
241 void dmArgsPrintHelp(FILE *fh, |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
242 const DMOptArg *opts, const int nopts, |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
243 const int flags) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
244 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
245 int index; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
246 (void) flags; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
247 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
248 // Print out option list |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
249 for (index = 0; index < nopts; index++) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
250 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
251 const DMOptArg *opt = &opts[index]; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
252 char tmpStr[128]; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
253 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
254 // Print short option |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
255 if (opt->o_short != 0) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
256 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
257 snprintf(tmpStr, sizeof(tmpStr), |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
258 "-%c,", opt->o_short); |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
259 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
260 else |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
261 tmpStr[0] = 0; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
262 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
263 fprintf(fh, " %-5s", tmpStr); |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
264 |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
265 // Print long option |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
266 if (opt->o_long != NULL) |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
267 { |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
268 snprintf(tmpStr, sizeof(tmpStr), "--%s%s", |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
269 opt->o_long, |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
270 (opt->flags & OPT_ARGREQ) ? "=ARG" : ""); |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
271 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
272 else |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
273 tmpStr[0] = 0; |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
274 |
1743
bcdea45a14cb
Adjust indentation output of commandline help printing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1742
diff
changeset
|
275 fprintf(fh, "%-18s", tmpStr); |
1742
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
276 |
1743
bcdea45a14cb
Adjust indentation output of commandline help printing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1742
diff
changeset
|
277 dmPrintWrap(fh, opt->desc, 24, 24, 79); |
1742
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
278 } |
ddec147d1f90
Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
279 } |