diff options
author | Mike Buland <eichlan@xagasoft.com> | 2006-05-26 04:03:24 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2006-05-26 04:03:24 +0000 |
commit | bd5bb1ca60a6a97b110cbf221b3625e6e6200141 (patch) | |
tree | 063b1576b57aba698159f50a04461ddfb7c4dfb6 /src/pproc.cpp | |
parent | bc6f456ef27bdf25bf7a7f677217b9b7204b4241 (diff) | |
download | libbu++-bd5bb1ca60a6a97b110cbf221b3625e6e6200141.tar.gz libbu++-bd5bb1ca60a6a97b110cbf221b3625e6e6200141.tar.bz2 libbu++-bd5bb1ca60a6a97b110cbf221b3625e6e6200141.tar.xz libbu++-bd5bb1ca60a6a97b110cbf221b3625e6e6200141.zip |
Loads of updates to several systems, see each for what really changed, the
biggest are the updates to the exception framework, and to the pproc system,
which is almost a competitor to popt already...
Diffstat (limited to '')
-rw-r--r-- | src/pproc.cpp | 93 |
1 files changed, 91 insertions, 2 deletions
diff --git a/src/pproc.cpp b/src/pproc.cpp index f5cb869..ea836eb 100644 --- a/src/pproc.cpp +++ b/src/pproc.cpp | |||
@@ -2,8 +2,76 @@ | |||
2 | #include <string.h> | 2 | #include <string.h> |
3 | #include "pproc.h" | 3 | #include "pproc.h" |
4 | 4 | ||
5 | void pprocHelp( PPROC *pproc ) | ||
6 | { | ||
7 | for( int j = 0; pproc[j].proc || pproc[j].stateVar; j++ ) | ||
8 | { | ||
9 | printf("%c, %s - %s\n", | ||
10 | pproc[j].cChar, | ||
11 | pproc[j].lpWord, | ||
12 | pproc[j].shortHelp ); | ||
13 | } | ||
14 | } | ||
15 | |||
16 | void grabParamAsData( PPROC *pproc, char *str, int *aind, int *cind ) | ||
17 | { | ||
18 | switch( pproc->cMode & PPROC_TYPE ) | ||
19 | { | ||
20 | case PPROC_BOOL_TRUE: | ||
21 | *((bool *)pproc->stateVar) = true; | ||
22 | break; | ||
23 | |||
24 | case PPROC_BOOL_FALSE: | ||
25 | *((bool *)pproc->stateVar) = false; | ||
26 | break; | ||
27 | |||
28 | case PPROC_BOOL_TOGGLE: | ||
29 | *((bool *)pproc->stateVar) = !(*((bool *)pproc->stateVar)); | ||
30 | break; | ||
31 | |||
32 | case PPROC_CHAR: | ||
33 | (*cind)++; | ||
34 | *((char *)pproc->stateVar) = str[(*cind)]; | ||
35 | break; | ||
36 | |||
37 | case PPROC_SHORT: | ||
38 | break; | ||
39 | |||
40 | case PPROC_LONG: | ||
41 | break; | ||
42 | |||
43 | case PPREC_LONG_LONG: | ||
44 | break; | ||
45 | |||
46 | case PPROC_UCHAR: | ||
47 | break; | ||
48 | |||
49 | case PPROC_USHORT: | ||
50 | break; | ||
51 | |||
52 | case PPROC_ULONG: | ||
53 | break; | ||
54 | |||
55 | case PPREC_ULONG_LONG: | ||
56 | break; | ||
57 | |||
58 | case PPROC_FLOAT: | ||
59 | break; | ||
60 | |||
61 | case PPROC_DOUBLE: | ||
62 | break; | ||
63 | |||
64 | case PPROC_LONG_DOUBLE: | ||
65 | break; | ||
66 | |||
67 | case PPROC_STRING: | ||
68 | break; | ||
69 | } | ||
70 | } | ||
71 | |||
5 | void processParams( int argc, char *argv[], PPROC *pproc ) | 72 | void processParams( int argc, char *argv[], PPROC *pproc ) |
6 | { | 73 | { |
74 | bool bUsed; | ||
7 | // Loop over all the params except the first, no params, no looping! | 75 | // Loop over all the params except the first, no params, no looping! |
8 | for( int j = 1; j < argc; j++ ) | 76 | for( int j = 1; j < argc; j++ ) |
9 | { | 77 | { |
@@ -12,6 +80,7 @@ void processParams( int argc, char *argv[], PPROC *pproc ) | |||
12 | { | 80 | { |
13 | if( argv[j][1] == '-' ) | 81 | if( argv[j][1] == '-' ) |
14 | { | 82 | { |
83 | bUsed = false; | ||
15 | // Proccess a long-word param string | 84 | // Proccess a long-word param string |
16 | for( int k = 0; | 85 | for( int k = 0; |
17 | pproc[k].proc != NULL || pproc[k].stateVar != NULL; | 86 | pproc[k].proc != NULL || pproc[k].stateVar != NULL; |
@@ -19,19 +88,29 @@ void processParams( int argc, char *argv[], PPROC *pproc ) | |||
19 | { | 88 | { |
20 | if( !strcmp( pproc[k].lpWord, &argv[j][2] ) ) | 89 | if( !strcmp( pproc[k].lpWord, &argv[j][2] ) ) |
21 | { | 90 | { |
91 | bUsed = true; | ||
22 | if( pproc[k].proc != NULL ) | 92 | if( pproc[k].proc != NULL ) |
23 | { | 93 | { |
24 | j += pproc[k].proc( argc-j, &argv[j] ); | 94 | j += pproc[k].proc( argc-j, &argv[j] ); |
25 | } | 95 | } |
26 | if( pproc[k].stateVar != NULL ) | 96 | if( pproc[k].stateVar != NULL ) |
27 | { | 97 | { |
28 | (*(pproc[k].stateVar)) = pproc[k].bSetState; | 98 | grabParamAsData( &pproc[k], argv[j+1], &j, &k ); |
29 | } | 99 | } |
100 | break; | ||
101 | } | ||
102 | } | ||
103 | if( !bUsed ) | ||
104 | { | ||
105 | if( !strcmp( "help", &argv[j][2] ) ) | ||
106 | { | ||
107 | pprocHelp( pproc ); | ||
30 | } | 108 | } |
31 | } | 109 | } |
32 | } | 110 | } |
33 | else | 111 | else |
34 | { | 112 | { |
113 | bUsed = false; | ||
35 | // Process a one char param string | 114 | // Process a one char param string |
36 | for( int k = 0; | 115 | for( int k = 0; |
37 | pproc[k].proc != NULL || pproc[k].stateVar != NULL; | 116 | pproc[k].proc != NULL || pproc[k].stateVar != NULL; |
@@ -39,14 +118,24 @@ void processParams( int argc, char *argv[], PPROC *pproc ) | |||
39 | { | 118 | { |
40 | if( pproc[k].cChar == argv[j][1] ) | 119 | if( pproc[k].cChar == argv[j][1] ) |
41 | { | 120 | { |
121 | bUsed = true; | ||
42 | if( pproc[k].proc != NULL ) | 122 | if( pproc[k].proc != NULL ) |
43 | { | 123 | { |
44 | j += pproc[k].proc( argc-j, &argv[j] ); | 124 | j += pproc[k].proc( argc-j, &argv[j] ); |
45 | } | 125 | } |
46 | if( pproc[k].stateVar != NULL ) | 126 | if( pproc[k].stateVar != NULL ) |
47 | { | 127 | { |
48 | (*(pproc[k].stateVar)) = pproc[k].bSetState; | 128 | int tmp = 1; |
129 | grabParamAsData( &pproc[k], argv[j], &j, &tmp ); | ||
49 | } | 130 | } |
131 | break; | ||
132 | } | ||
133 | } | ||
134 | if( !bUsed ) | ||
135 | { | ||
136 | if( argv[j][1] == 'h' ) | ||
137 | { | ||
138 | pprocHelp( pproc ); | ||
50 | } | 139 | } |
51 | } | 140 | } |
52 | } | 141 | } |