diff options
Diffstat (limited to 'src/pproc.cpp')
-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 | } |