58 |
|
// ********************************************************** |
59 |
|
// single: |
60 |
|
|
61 |
< |
char* inName; |
62 |
< |
FILE* inFile; |
61 |
> |
// char* inName; |
62 |
> |
// FILE* inFile; |
63 |
|
|
64 |
|
// *********************************************************** |
65 |
|
// multiple: |
80 |
|
// ******************************************** |
81 |
|
// single input: |
82 |
|
|
83 |
< |
inName = NULL; |
84 |
< |
inFile = NULL; |
83 |
> |
// inName = NULL; |
84 |
> |
// inFile = NULL; |
85 |
|
|
86 |
|
// ********************************************* |
87 |
|
// multiple input: |
108 |
|
rFlag = 0; |
109 |
|
iFlag = 0; |
110 |
|
|
111 |
< |
|
111 |
> |
flag2Val = 0.0; |
112 |
|
iVal = 0; |
113 |
|
|
114 |
|
|
131 |
|
flag1 = 1; // set flag1 to true |
132 |
|
|
133 |
|
i++; |
134 |
+ |
if( i>=argC ){ |
135 |
+ |
fprintf( stderr, |
136 |
+ |
"\n" |
137 |
+ |
"not enough arguments for flag1\n"); |
138 |
+ |
usage(); |
139 |
+ |
exit(0); |
140 |
+ |
} |
141 |
|
strcpy( flag1Arg1, argV[i] ); |
142 |
+ |
|
143 |
|
i++; |
144 |
+ |
if( i>=argC ){ |
145 |
+ |
fprintf( stderr, |
146 |
+ |
"\n" |
147 |
+ |
"not enough arguments for flag1\n"); |
148 |
+ |
usage(); |
149 |
+ |
exit(0); |
150 |
+ |
} |
151 |
|
strcpy( flag1Arg2, argV[i] ); |
152 |
|
} |
153 |
|
|
155 |
|
flag2 = 1; // set the flag2 to true; |
156 |
|
|
157 |
|
i++; |
158 |
+ |
if( i>=argC ){ |
159 |
+ |
fprintf( stderr, |
160 |
+ |
"\n" |
161 |
+ |
"not enough arguments for flag2\n"); |
162 |
+ |
usage(); |
163 |
+ |
exit(0); |
164 |
+ |
} |
165 |
+ |
|
166 |
|
flag2Val = strtod( argV[i], &conversionCheck ); |
167 |
|
if( conversionCheck == argV[i] ) conversionError = 1; |
168 |
|
if( *conversionCheck != '\0' ) conversionError = 1; |
198 |
|
|
199 |
|
done =0; |
200 |
|
j = 1; |
201 |
< |
currentFlag = argv[i][j]; |
202 |
< |
while( (current_flag != '\0') && (!done) ){ |
201 |
> |
currentFlag = argV[i][j]; |
202 |
> |
while( (currentFlag != '\0') && (!done) ){ |
203 |
|
|
204 |
< |
switch(current_flag){ |
204 |
> |
switch(currentFlag){ |
205 |
|
|
206 |
|
case 'h': |
207 |
|
// -h => give the usage help message |
228 |
|
} |
229 |
|
|
230 |
|
i++; |
231 |
+ |
if( i>=argC ){ |
232 |
+ |
fprintf( stderr, |
233 |
+ |
"\n" |
234 |
+ |
"not enough arguments for -o\n"); |
235 |
+ |
usage(); |
236 |
+ |
exit(0); |
237 |
+ |
} |
238 |
+ |
|
239 |
|
outPrefix = argV[i]; |
240 |
|
if( outPrefix[0] == '-' ) optionError = 1; |
241 |
|
|
280 |
|
} |
281 |
|
|
282 |
|
i++; |
283 |
+ |
if( i>=argC ){ |
284 |
+ |
fprintf( stderr, |
285 |
+ |
"\n" |
286 |
+ |
"not enough arguments for -i\n"); |
287 |
+ |
usage(); |
288 |
+ |
exit(0); |
289 |
+ |
} |
290 |
+ |
|
291 |
|
iVal = (int)strtol( argV[i], &conversionCheck, 10 ); |
292 |
|
if( conversionCheck == argV[i] ) conversionError = 1; |
293 |
|
if( *conversionCheck != '\0' ) conversionError = 1; |
308 |
|
|
309 |
|
(void)fprintf(stderr, |
310 |
|
"\n" |
311 |
< |
"Bad option \"-%c\"\n", current_flag); |
311 |
> |
"Bad option \"-%c\"\n", currentFlag); |
312 |
|
usage(); |
313 |
|
} |
314 |
|
j++; |
315 |
< |
current_flag = argv[i][j]; |
315 |
> |
currentFlag = argV[i][j]; |
316 |
|
} |
317 |
|
} |
318 |
|
} |
324 |
|
// for only a single input file, leave this as it is. |
325 |
|
// ******************************************************** |
326 |
|
|
327 |
< |
if( inName != NULL ){ |
328 |
< |
fprintf( stderr, |
329 |
< |
"\n" |
330 |
< |
"Error at \"%s\", program does not currently support\n" |
331 |
< |
"more than one input file.\n" |
332 |
< |
"\n", |
333 |
< |
argV[i]); |
334 |
< |
usage(); |
335 |
< |
exit(0); |
336 |
< |
} |
327 |
> |
// if( inName != NULL ){ |
328 |
> |
// fprintf( stderr, |
329 |
> |
// "\n" |
330 |
> |
// "Error at \"%s\", program does not currently support\n" |
331 |
> |
// "more than one input file.\n" |
332 |
> |
// "\n", |
333 |
> |
// argV[i]); |
334 |
> |
// usage(); |
335 |
> |
// exit(0); |
336 |
> |
// } |
337 |
|
|
338 |
< |
inName = argvV[i]; |
338 |
> |
// inName = argV[i]; |
339 |
|
|
340 |
|
// ************************************************************* |
341 |
|
|
374 |
|
// *********************************************************** |
375 |
|
// single file: |
376 |
|
|
377 |
< |
if(inName == NULL){ |
377 |
> |
// if(inName == NULL){ |
378 |
|
|
379 |
< |
fprintf( stderr, |
380 |
< |
"\n" |
381 |
< |
"Error, no input file was given\n"); |
382 |
< |
usage(); |
383 |
< |
exit(0); |
384 |
< |
} |
379 |
> |
// fprintf( stderr, |
380 |
> |
// "\n" |
381 |
> |
// "Error, no input file was given\n"); |
382 |
> |
// usage(); |
383 |
> |
// exit(0); |
384 |
> |
// } |
385 |
|
|
386 |
< |
inFile = fopen( inName, "r" ); |
387 |
< |
if( inFile == NULL ){ |
386 |
> |
// inFile = fopen( inName, "r" ); |
387 |
> |
// if( inFile == NULL ){ |
388 |
|
|
389 |
< |
fprintf( stderr, |
390 |
< |
"\n" |
391 |
< |
"Error trying to open \"%s\" for reading\n", |
392 |
< |
inName ); |
393 |
< |
exit(0); |
394 |
< |
} |
389 |
> |
// fprintf( stderr, |
390 |
> |
// "\n" |
391 |
> |
// "Error trying to open \"%s\" for reading\n", |
392 |
> |
// inName ); |
393 |
> |
// exit(0); |
394 |
> |
// } |
395 |
|
|
396 |
|
// ************************************************************** |
397 |
|
// multiple files: |
419 |
|
currentName = headName; |
420 |
|
while( currentName != NULL ){ |
421 |
|
|
422 |
< |
strcopy( inputArray[j].fileName, currentName->name ); |
423 |
< |
inputArray[i].filePtr = NULL; |
422 |
> |
strcpy( inputArray[j].fileName, currentName->name ); |
423 |
> |
inputArray[j].filePtr = NULL; |
424 |
|
j--; |
425 |
|
currentName = currentName->next; |
426 |
|
} |
440 |
|
|
441 |
|
for(i=0; i<nInputs; i++){ |
442 |
|
|
443 |
< |
inputArray[i].filePtr = fopen( inName, "r" ); |
443 |
> |
inputArray[i].filePtr = fopen( inputArray[i].fileName, "r" ); |
444 |
|
if( inputArray[i].filePtr == NULL ){ |
445 |
|
|
446 |
|
fprintf( stderr, |
460 |
|
|
461 |
|
|
462 |
|
|
463 |
< |
// or read files here |
425 |
< |
|
463 |
> |
// or read and do stuff here. |
464 |
|
|
465 |
|
|
466 |
|
|
467 |
|
|
468 |
+ |
|
469 |
|
// close files when we are done. |
470 |
|
|
471 |
|
// *********************************************************** |
472 |
|
// single: |
473 |
|
|
474 |
< |
fclose( inFile ); |
474 |
> |
// fclose( inFile ); |
475 |
|
|
476 |
|
// ************************************************************* |
477 |
|
// multiple: |
497 |
|
|
498 |
|
void usage(){ |
499 |
|
(void)fprintf(stdout, |
500 |
+ |
"\n" |
501 |
|
"The proper usage is: %s [options] <input_file>\n" |
502 |
|
"\n" |
503 |
|
"Options:\n" |
518 |
|
|
519 |
|
"\n" |
520 |
|
"\n", |
521 |
< |
program_name) |
521 |
> |
programName); |
522 |
|
exit(0); |
523 |
|
} |