Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > ParamHelper
comparison ParamBag.c @ 7:1bf28dddc45f
Created MC_shared branch
| author | Me@portablequad |
|---|---|
| date | Sat, 11 Feb 2012 20:08:58 -0800 |
| parents | d46150af45ad |
| children | b80587574901 |
comparison
equal
deleted
inserted
replaced
| 3:5576551e3f11 | 4:64a3fc307549 |
|---|---|
| 22 void nullOutParamBagHashEntries( ParamBag *bag ); | 22 void nullOutParamBagHashEntries( ParamBag *bag ); |
| 23 | 23 |
| 24 ParamBag * | 24 ParamBag * |
| 25 makeParamBag() | 25 makeParamBag() |
| 26 { ParamBag * retBag; | 26 { ParamBag * retBag; |
| 27 retBag = malloc( sizeof( ParamBag ) ); | 27 retBag = VMS__malloc( sizeof( ParamBag ) ); |
| 28 retBag->entries = malloc( PARAM_BAG_HASHSIZE * sizeof( ParamBagHashEntry *) ); | 28 retBag->entries = VMS__malloc( PARAM_BAG_HASHSIZE * sizeof( ParamBagHashEntry *) ); |
| 29 retBag->bagSz = PARAM_BAG_HASHSIZE; | 29 retBag->bagSz = PARAM_BAG_HASHSIZE; |
| 30 nullOutParamBagHashEntries( retBag ); | 30 nullOutParamBagHashEntries( retBag ); |
| 31 | 31 |
| 32 return retBag; | 32 return retBag; |
| 33 } | 33 } |
| 78 { unsigned int hashIdx; | 78 { unsigned int hashIdx; |
| 79 ParamBagHashEntry* hashEntry; | 79 ParamBagHashEntry* hashEntry; |
| 80 hashEntry = lookupKeyInHash( key, bag ); | 80 hashEntry = lookupKeyInHash( key, bag ); |
| 81 if( hashEntry == NULL ) | 81 if( hashEntry == NULL ) |
| 82 { hashIdx = hashKey( key, bag->bagSz ); | 82 { hashIdx = hashKey( key, bag->bagSz ); |
| 83 hashEntry = (ParamBagHashEntry*) malloc( sizeof( ParamBagHashEntry ) ); | 83 hashEntry = (ParamBagHashEntry*) VMS__malloc( sizeof( ParamBagHashEntry ) ); |
| 84 if( hashEntry == NULL ) return 0; | 84 if( hashEntry == NULL ) return 0; |
| 85 hashEntry->key = strdup( key ); | 85 hashEntry->key = strdup( key ); |
| 86 if( hashEntry->key == NULL ) return 0; | 86 if( hashEntry->key == NULL ) return 0; |
| 87 hashEntry->next = (bag->entries)[hashIdx]; | 87 hashEntry->next = (bag->entries)[hashIdx]; |
| 88 (bag->entries)[hashIdx] = hashEntry; | 88 (bag->entries)[hashIdx] = hashEntry; |
| 116 | 116 |
| 117 void | 117 void |
| 118 freeParamBagHashEntry( ParamBagHashEntry *entry ) | 118 freeParamBagHashEntry( ParamBagHashEntry *entry ) |
| 119 { | 119 { |
| 120 freeParamStruc( entry->param ); | 120 freeParamStruc( entry->param ); |
| 121 free( entry->key ); //was malloc'd above, so free it | 121 VMS__free( entry->key ); //was malloc'd above, so free it |
| 122 free( entry ); | 122 VMS__free( entry ); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void | 125 void |
| 126 freeParamStruc( ParamStruc * param ) | 126 freeParamStruc( ParamStruc * param ) |
| 127 { if( param->type == STRING_PARAM_TYPE ) free( param->strValue ); | 127 { if( param->type == STRING_PARAM_TYPE ) VMS__free( param->strValue ); |
| 128 free( param ); | 128 VMS__free( param ); |
| 129 } | 129 } |
| 130 | 130 |
| 131 ParamStruc * | 131 ParamStruc * |
| 132 makeParamStruc() | 132 makeParamStruc() |
| 133 { ParamStruc *retStruc; | 133 { ParamStruc *retStruc; |
| 134 retStruc = malloc( sizeof( ParamStruc ) ); | 134 retStruc = VMS__malloc( sizeof( ParamStruc ) ); |
| 135 retStruc->floatValue = 0.0; | 135 retStruc->floatValue = 0.0; |
| 136 retStruc->intValue = 0; | 136 retStruc->intValue = 0; |
| 137 retStruc->strValue = NULL; | 137 retStruc->strValue = NULL; |
| 138 | 138 |
| 139 return retStruc; | 139 return retStruc; |
| 162 { retParam->type = INT_PARAM_TYPE; | 162 { retParam->type = INT_PARAM_TYPE; |
| 163 retParam->intValue = atoi( value ); | 163 retParam->intValue = atoi( value ); |
| 164 } break; | 164 } break; |
| 165 case 's': | 165 case 's': |
| 166 { retParam->type = STRING_PARAM_TYPE; | 166 { retParam->type = STRING_PARAM_TYPE; |
| 167 retParam->strValue = malloc( strlen(value) + 1); | 167 retParam->strValue = VMS__malloc( strlen(value) + 1); |
| 168 strcpy( retParam->strValue, value ); | 168 strcpy( retParam->strValue, value ); |
| 169 removeEndWhtSpaceFromStr( retParam->strValue ); | 169 removeEndWhtSpaceFromStr( retParam->strValue ); |
| 170 } break; | 170 } break; |
| 171 case 'f': | 171 case 'f': |
| 172 { retParam->type = FLOAT_PARAM_TYPE; | 172 { retParam->type = FLOAT_PARAM_TYPE; |
