comparison ParamBag.c @ 9:b80587574901

fixed #include and changed VMS__malloc to VMS_WL__malloc
author Me@portablequad
date Sun, 12 Feb 2012 01:06:02 -0800
parents 1bf28dddc45f
children
comparison
equal deleted inserted replaced
4:64a3fc307549 5:8101db151dfd
11 */ 11 */
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 "ParamBag.h"
17 17
18 void freeParamStruc( ParamStruc * param ); 18 void freeParamStruc( ParamStruc * param );
19 void freeParamBagHashEntry( ParamBagHashEntry *entry ); 19 void freeParamBagHashEntry( ParamBagHashEntry *entry );
20 ParamBagHashEntry * lookupKeyInHash( char *key, ParamBag * bag ); 20 ParamBagHashEntry * lookupKeyInHash( char *key, ParamBag * bag );
21 unsigned int hashThisKey( char *s, int hashSz ); 21 unsigned int hashThisKey( char *s, int hashSz );
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 = VMS__malloc( sizeof( ParamBag ) ); 27 retBag = VMS_WL__malloc( sizeof( ParamBag ) );
28 retBag->entries = VMS__malloc( PARAM_BAG_HASHSIZE * sizeof( ParamBagHashEntry *) ); 28 retBag->entries = VMS_WL__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*) VMS__malloc( sizeof( ParamBagHashEntry ) ); 83 hashEntry = (ParamBagHashEntry*) VMS_WL__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 VMS__free( entry->key ); //was malloc'd above, so free it 121 VMS_WL__free( entry->key ); //was malloc'd above, so free it
122 VMS__free( entry ); 122 VMS_WL__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 ) VMS__free( param->strValue ); 127 { if( param->type == STRING_PARAM_TYPE ) VMS_WL__free( param->strValue );
128 VMS__free( param ); 128 VMS_WL__free( param );
129 } 129 }
130 130
131 ParamStruc * 131 ParamStruc *
132 makeParamStruc() 132 makeParamStruc()
133 { ParamStruc *retStruc; 133 { ParamStruc *retStruc;
134 retStruc = VMS__malloc( sizeof( ParamStruc ) ); 134 retStruc = VMS_WL__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 = VMS__malloc( strlen(value) + 1); 167 retParam->strValue = VMS_WL__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;