Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > ParamHelper
comparison ParamBag.c @ 19:740df4b46535
new branch -- for universal -- changed malloc and free -- do PR__start before use
| author | Sean Halle <seanhalle@yahoo.com> |
|---|---|
| date | Tue, 23 Jul 2013 07:20:05 -0700 |
| parents | c6544bc64a7c |
| children | 5837ad792168 |
comparison
equal
deleted
inserted
replaced
| 7:b83a07c79fbe | 8:37c0ed158089 |
|---|---|
| 12 #include <string.h> | 12 #include <string.h> |
| 13 #include <stdio.h> | 13 #include <stdio.h> |
| 14 #include <stdlib.h> | 14 #include <stdlib.h> |
| 15 | 15 |
| 16 #include "Param.h" | 16 #include "Param.h" |
| 17 #include "PR__common_includes/Services_offered_by_PR/Memory_Handling/vmalloc__wrapper_library.h" | |
| 17 | 18 |
| 18 void freeParamStruc( ParamStruc * param ); | 19 void freeParamStruc( ParamStruc * param ); |
| 19 void freeParamBagHashEntry( ParamBagHashEntry *entry ); | 20 void freeParamBagHashEntry( ParamBagHashEntry *entry ); |
| 20 ParamBagHashEntry * lookupKeyInHash( char *key, ParamBag * bag ); | 21 ParamBagHashEntry * lookupKeyInHash( char *key, ParamBag * bag ); |
| 21 unsigned int hashThisKey( char *s, int hashSz ); | 22 unsigned int hashThisKey( char *s, int hashSz ); |
| 23 | 24 |
| 24 //TODO: Bug -- need internal, App/WL, and external versions | 25 //TODO: Bug -- need internal, App/WL, and external versions |
| 25 ParamBag * | 26 ParamBag * |
| 26 makeParamBag() | 27 makeParamBag() |
| 27 { ParamBag * retBag; | 28 { ParamBag * retBag; |
| 28 retBag = malloc( sizeof( ParamBag ) ); | 29 retBag = PR__malloc( sizeof( ParamBag ) ); |
| 29 retBag->entries = malloc( PARAM_BAG_HASHSIZE * sizeof( ParamBagHashEntry *) ); | 30 retBag->entries = PR__malloc( PARAM_BAG_HASHSIZE * sizeof( ParamBagHashEntry *) ); |
| 30 retBag->bagSz = PARAM_BAG_HASHSIZE; | 31 retBag->bagSz = PARAM_BAG_HASHSIZE; |
| 31 nullOutParamBagHashEntries( retBag ); | 32 nullOutParamBagHashEntries( retBag ); |
| 32 | 33 |
| 33 return retBag; | 34 return retBag; |
| 34 } | 35 } |
| 79 { unsigned int hashIdx; | 80 { unsigned int hashIdx; |
| 80 ParamBagHashEntry* hashEntry; | 81 ParamBagHashEntry* hashEntry; |
| 81 hashEntry = lookupKeyInHash( key, bag ); | 82 hashEntry = lookupKeyInHash( key, bag ); |
| 82 if( hashEntry == NULL ) | 83 if( hashEntry == NULL ) |
| 83 { hashIdx = hashKey( key, bag->bagSz ); | 84 { hashIdx = hashKey( key, bag->bagSz ); |
| 84 hashEntry = (ParamBagHashEntry*) malloc( sizeof( ParamBagHashEntry ) ); | 85 hashEntry = (ParamBagHashEntry*) PR__malloc( sizeof( ParamBagHashEntry ) ); |
| 85 if( hashEntry == NULL ) return 0; | 86 if( hashEntry == NULL ) return 0; |
| 86 hashEntry->key = strdup( key ); | 87 hashEntry->key = strdup( key ); |
| 87 if( hashEntry->key == NULL ) return 0; | 88 if( hashEntry->key == NULL ) return 0; |
| 88 hashEntry->next = (bag->entries)[hashIdx]; | 89 hashEntry->next = (bag->entries)[hashIdx]; |
| 89 (bag->entries)[hashIdx] = hashEntry; | 90 (bag->entries)[hashIdx] = hashEntry; |
| 117 | 118 |
| 118 void | 119 void |
| 119 freeParamBagHashEntry( ParamBagHashEntry *entry ) | 120 freeParamBagHashEntry( ParamBagHashEntry *entry ) |
| 120 { | 121 { |
| 121 freeParamStruc( entry->param ); | 122 freeParamStruc( entry->param ); |
| 122 free( entry->key ); //was malloc'd above, so free it | 123 PR__free( entry->key ); //was malloc'd above, so free it |
| 123 free( entry ); | 124 PR__free( entry ); |
| 124 } | 125 } |
| 125 | 126 |
| 126 void | 127 void |
| 127 freeParamStruc( ParamStruc * param ) | 128 freeParamStruc( ParamStruc * param ) |
| 128 { if( param->type == STRING_PARAM_TYPE ) free( param->strValue ); | 129 { if( param->type == STRING_PARAM_TYPE ) PR__free( param->strValue ); |
| 129 free( param ); | 130 PR__free( param ); |
| 130 } | 131 } |
| 131 | 132 |
| 132 ParamStruc * | 133 ParamStruc * |
| 133 makeParamStruc() | 134 makeParamStruc() |
| 134 { ParamStruc *retStruc; | 135 { ParamStruc *retStruc; |
| 135 retStruc = malloc( sizeof( ParamStruc ) ); | 136 retStruc = PR__malloc( sizeof( ParamStruc ) ); |
| 136 retStruc->floatValue = 0.0; | 137 retStruc->floatValue = 0.0; |
| 137 retStruc->intValue = 0; | 138 retStruc->intValue = 0; |
| 138 retStruc->strValue = NULL; | 139 retStruc->strValue = NULL; |
| 139 | 140 |
| 140 return retStruc; | 141 return retStruc; |
| 163 { retParam->type = INT_PARAM_TYPE; | 164 { retParam->type = INT_PARAM_TYPE; |
| 164 retParam->intValue = atoi( value ); | 165 retParam->intValue = atoi( value ); |
| 165 } break; | 166 } break; |
| 166 case 's': | 167 case 's': |
| 167 { retParam->type = STRING_PARAM_TYPE; | 168 { retParam->type = STRING_PARAM_TYPE; |
| 168 retParam->strValue = malloc( strlen(value) + 1); | 169 retParam->strValue = PR__malloc( strlen(value) + 1); |
| 169 strcpy( retParam->strValue, value ); | 170 strcpy( retParam->strValue, value ); |
| 170 removeEndWhtSpaceFromStr( retParam->strValue ); | 171 removeEndWhtSpaceFromStr( retParam->strValue ); |
| 171 } break; | 172 } break; |
| 172 case 'f': | 173 case 'f': |
| 173 { retParam->type = FLOAT_PARAM_TYPE; | 174 { retParam->type = FLOAT_PARAM_TYPE; |
