|
Last change
on this file since 22 was
1,
checked in by djay, 17 years ago
|
|
Initial ZOO SVN Repository Import.
|
|
File size:
1002 bytes
|
| Line | |
|---|
| 1 | #include "service.h" |
|---|
| 2 | |
|---|
| 3 | map* createMap(char* name,char* value){ |
|---|
| 4 | map* tmp=(map *)malloc(sizeof(map*)); |
|---|
| 5 | tmp->name=strdup(name); |
|---|
| 6 | tmp->value=strdup(value); |
|---|
| 7 | tmp->next=NULL; |
|---|
| 8 | return tmp; |
|---|
| 9 | } |
|---|
| 10 | |
|---|
| 11 | bool hasKey(map* m,char *key){ |
|---|
| 12 | map* tmp=m; |
|---|
| 13 | while(tmp!=NULL){ |
|---|
| 14 | if(strcmp(tmp->name,key)==0) |
|---|
| 15 | return true; |
|---|
| 16 | tmp=tmp->next; |
|---|
| 17 | } |
|---|
| 18 | #ifdef DEBUG_MAP |
|---|
| 19 | printf("NOT FOUND \n"); |
|---|
| 20 | #endif |
|---|
| 21 | return false; |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | map* getMap(map* m,char *key){ |
|---|
| 25 | map* tmp=m; |
|---|
| 26 | while(tmp!=NULL){ |
|---|
| 27 | if(strcmp(tmp->name,key)==0) |
|---|
| 28 | return tmp; |
|---|
| 29 | tmp=tmp->next; |
|---|
| 30 | } |
|---|
| 31 | return NULL; |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | void* addToMap(map* m,char* n,char* v){ |
|---|
| 35 | if(hasKey(m,n)==false){ |
|---|
| 36 | map* _cursor=m; |
|---|
| 37 | while(_cursor->next) |
|---|
| 38 | _cursor=_cursor->next; |
|---|
| 39 | _cursor->next=createMap(n,v); |
|---|
| 40 | } |
|---|
| 41 | else{ |
|---|
| 42 | map *tmp=getMap(m,n); |
|---|
| 43 | tmp->value=strdup(v); |
|---|
| 44 | } |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | void* _dumpMap(map* t){ |
|---|
| 48 | fprintf(stderr,"[%s] => [%s] \n",t->name,t->value); |
|---|
| 49 | fflush(stderr); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | void* dumpMap(map* t){ |
|---|
| 53 | map* tmp=t; |
|---|
| 54 | while(tmp!=NULL){ |
|---|
| 55 | _dumpMap(tmp); |
|---|
| 56 | tmp=tmp->next; |
|---|
| 57 | } |
|---|
| 58 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.