commit | author | age
|
a97daa
|
1 |
#include<stdio.h> |
SP |
2 |
#include<stdlib.h> |
|
3 |
#include<string.h> |
|
4 |
int main(int argv, char *argc[]){ |
|
5 |
|
|
6 |
|
|
7 |
char *commands, *backup, *saveptr, *saveopptr, *command, *operator[2], *operand; |
|
8 |
int i,j; |
|
9 |
commands=(char *)malloc(10000*sizeof(char)); |
|
10 |
backup=commands; |
|
11 |
if(argv!=2){ |
|
12 |
fprintf(stderr, "Error. Usage: parsecmdline cmd1=1,cmd2=2,...\n"); |
|
13 |
exit(1); |
|
14 |
} |
|
15 |
|
|
16 |
strcpy(commands,argc[1]); |
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
for(i=0; ;i++, commands=NULL){ |
|
21 |
//breaks comma separated list of commands into specific commands. |
|
22 |
command=strtok_r(commands,",",&saveptr); |
|
23 |
if(command==NULL) break; |
|
24 |
fprintf(stdout,"Command %d: %s\n",i,command); |
|
25 |
//extracts name of command and value of command into operator[2] array. |
|
26 |
for(j=0; j<2;j++,command=NULL){ |
|
27 |
operator[j]=strtok_r(command,"=",&saveopptr); |
|
28 |
if(operator[j]==NULL) break; |
|
29 |
fprintf(stdout," ---> Operator %d: %s\n",j,operator[j]); |
|
30 |
} |
|
31 |
//1. check: must have 2 operators. |
|
32 |
if(j!=2) fprintf(stderr,"Error. Command no. %d is not formatted properly.\n",i); |
|
33 |
//2. check: must be named properly. |
|
34 |
//3. check: must be of right format (integer, double, string, ...) |
|
35 |
|
|
36 |
|
|
37 |
} |
|
38 |
|
|
39 |
free(backup); |
|
40 |
|
|
41 |
return 0; |
|
42 |
} |