summaryrefslogtreecommitdiff
path: root/src/pproc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/pproc.cpp')
-rw-r--r--src/pproc.cpp169
1 files changed, 0 insertions, 169 deletions
diff --git a/src/pproc.cpp b/src/pproc.cpp
deleted file mode 100644
index eb52913..0000000
--- a/src/pproc.cpp
+++ /dev/null
@@ -1,169 +0,0 @@
1#include <stdio.h>
2#include <string.h>
3#include "pproc.h"
4
5void pprocHelp( PPROC *pproc )
6{
7 int maxlen = 0;
8 for( int j = 0; pproc[j].proc || pproc[j].stateVar; j++ )
9 {
10 int len = strlen( pproc[j].lpWord );
11 if( len > maxlen ) maxlen = len;
12 }
13
14 char fmt[100];
15 sprintf( fmt, " -%%c, --%%-%ds %%s\n", maxlen );
16
17 for( int j = 0; pproc[j].proc || pproc[j].stateVar; j++ )
18 {
19 printf( fmt,
20 pproc[j].cChar,
21 pproc[j].lpWord,
22 pproc[j].shortHelp );
23 }
24}
25
26void grabParamAsData( PPROC *pproc, char *str, int *aind, int *cind )
27{
28 switch( pproc->cMode & PPROC_TYPE )
29 {
30 case PPROC_BOOL_TRUE:
31 *((bool *)pproc->stateVar) = true;
32 break;
33
34 case PPROC_BOOL_FALSE:
35 *((bool *)pproc->stateVar) = false;
36 break;
37
38 case PPROC_BOOL_TOGGLE:
39 *((bool *)pproc->stateVar) = !(*((bool *)pproc->stateVar));
40 break;
41
42 case PPROC_CHAR:
43 (*cind)++;
44 *((char *)pproc->stateVar) = str[(*cind)];
45 break;
46
47 case PPROC_SHORT:
48 break;
49
50 case PPROC_LONG:
51 break;
52
53 case PPREC_LONG_LONG:
54 break;
55
56 case PPROC_UCHAR:
57 break;
58
59 case PPROC_USHORT:
60 break;
61
62 case PPROC_ULONG:
63 break;
64
65 case PPREC_ULONG_LONG:
66 break;
67
68 case PPROC_FLOAT:
69 break;
70
71 case PPROC_DOUBLE:
72 break;
73
74 case PPROC_LONG_DOUBLE:
75 break;
76
77 case PPROC_STRING:
78 strcpy( (char *)(pproc->stateVar), str );
79 (*aind)++;
80 break;
81 }
82}
83
84void processParams( int argc, char *argv[], PPROC *pproc )
85{
86 bool bUsed;
87 // Loop over all the params except the first, no params, no looping!
88 for( int j = 1; j < argc; j++ )
89 {
90 //printf("Param[%d]: \"%s\"\n", j, argv[j] );
91 if( argv[j][0] == '-' )
92 {
93 if( argv[j][1] == '-' )
94 {
95 bUsed = false;
96 // Proccess a long-word param string
97 for( int k = 0;
98 pproc[k].proc != NULL || pproc[k].stateVar != NULL;
99 k++ )
100 {
101 if( !strcmp( pproc[k].lpWord, &argv[j][2] ) )
102 {
103 bUsed = true;
104 if( pproc[k].proc != NULL )
105 {
106 j += pproc[k].proc( argc-j, &argv[j] );
107 }
108 if( pproc[k].stateVar != NULL )
109 {
110 grabParamAsData( &pproc[k], argv[j+1], &j, &k );
111 }
112 break;
113 }
114 }
115 if( !bUsed )
116 {
117 if( !strcmp( "help", &argv[j][2] ) )
118 {
119 pprocHelp( pproc );
120 }
121 }
122 }
123 else
124 {
125 bUsed = false;
126 // Process a one char param string
127 for( int k = 0;
128 pproc[k].proc != NULL || pproc[k].stateVar != NULL;
129 k++ )
130 {
131 if( pproc[k].cChar == argv[j][1] )
132 {
133 bUsed = true;
134 if( pproc[k].proc != NULL )
135 {
136 j += pproc[k].proc( argc-j, &argv[j] );
137 }
138 if( pproc[k].stateVar != NULL )
139 {
140 int tmp = 1;
141 if( argv[j][2] == '\0' )
142 {
143 grabParamAsData( &pproc[k], argv[j+1], &j, &tmp );
144 }
145 else
146 {
147 j--;
148 grabParamAsData( &pproc[k], (&argv[j+1][2]), &j, &tmp );
149 }
150 }
151 break;
152 }
153 }
154 if( !bUsed )
155 {
156 if( argv[j][1] == 'h' )
157 {
158 pprocHelp( pproc );
159 }
160 }
161 }
162 }
163 else
164 {
165 // Handle generic params here.
166 }
167 }
168}
169