summaryrefslogtreecommitdiff
path: root/src/pproc.cpp
blob: ea836ebbe40957d1a06b9c2e4dc61c960f796418 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <stdio.h>
#include <string.h>
#include "pproc.h"

void pprocHelp( PPROC *pproc )
{
	for( int j = 0; pproc[j].proc || pproc[j].stateVar; j++ )
	{
		printf("%c, %s - %s\n",
			pproc[j].cChar,
			pproc[j].lpWord,
			pproc[j].shortHelp );
	}
}

void grabParamAsData( PPROC *pproc, char *str, int *aind, int *cind )
{
	switch( pproc->cMode & PPROC_TYPE )
	{
		case PPROC_BOOL_TRUE:
			*((bool *)pproc->stateVar) = true;
			break;
			
		case PPROC_BOOL_FALSE:
			*((bool *)pproc->stateVar) = false;
			break;
			
		case PPROC_BOOL_TOGGLE:
			*((bool *)pproc->stateVar) = !(*((bool *)pproc->stateVar));
			break;
			
		case PPROC_CHAR:
			(*cind)++;
			*((char *)pproc->stateVar) = str[(*cind)];
			break;
			
		case PPROC_SHORT:
			break;
			
		case PPROC_LONG:
			break;
			
		case PPREC_LONG_LONG:
			break;
			
		case PPROC_UCHAR:
			break;
			
		case PPROC_USHORT:
			break;
			
		case PPROC_ULONG:
			break;
			
		case PPREC_ULONG_LONG:
			break;
			
		case PPROC_FLOAT:
			break;
			
		case PPROC_DOUBLE:
			break;
			
		case PPROC_LONG_DOUBLE:
			break;
			
		case PPROC_STRING:
			break;
	}
}

void processParams( int argc, char *argv[], PPROC *pproc )
{
	bool bUsed;
	// Loop over all the params except the first, no params, no looping!
	for( int j = 1; j < argc; j++ )
	{
		//printf("Param[%d]: \"%s\"\n", j, argv[j] );
		if( argv[j][0] == '-' )
		{
			if( argv[j][1] == '-' )
			{
				bUsed = false;
				// Proccess a long-word param string
				for( int k = 0;
					pproc[k].proc != NULL || pproc[k].stateVar != NULL;
					k++ )
				{
					if( !strcmp( pproc[k].lpWord, &argv[j][2] ) )
					{
						bUsed = true;
						if( pproc[k].proc != NULL )
						{
							j += pproc[k].proc( argc-j, &argv[j] );
						}
						if( pproc[k].stateVar != NULL )
						{
							grabParamAsData( &pproc[k], argv[j+1], &j, &k );
						}
						break;
					}
				}
				if( !bUsed )
				{
					if( !strcmp( "help", &argv[j][2] ) )
					{
						pprocHelp( pproc );
					}
				}
			}
			else
			{
				bUsed = false;
				// Process a one char param string
				for( int k = 0;
					pproc[k].proc != NULL || pproc[k].stateVar != NULL;
					k++ )
				{
					if( pproc[k].cChar == argv[j][1] )
					{
						bUsed = true;
						if( pproc[k].proc != NULL )
						{
							j += pproc[k].proc( argc-j, &argv[j] );
						}
						if( pproc[k].stateVar != NULL )
						{
							int tmp = 1;
							grabParamAsData( &pproc[k], argv[j], &j, &tmp );
						}
						break;
					}
				}
				if( !bUsed )
				{
					if( argv[j][1] == 'h' )
					{
						pprocHelp( pproc );
					}
				}
			}
		}
		else
		{
			// Handle generic params here.
		}
	}
}