Rev 4192 | Rev 4332 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4192 | Rev 4197 | ||
---|---|---|---|
Line 98... | Line 98... | ||
98 | 98 | ||
99 | int char_map_add_item( char_map_ref map, const char * identifier, size_t length, const int value ){ |
99 | int char_map_add_item( char_map_ref map, const char * identifier, size_t length, const int value ){ |
100 | if( map->next == ( map->size - 1 )){ |
100 | if( map->next == ( map->size - 1 )){ |
101 | char_map_ref * tmp; |
101 | char_map_ref * tmp; |
102 | 102 | ||
103 | tmp = ( char_map_ref * ) malloc( sizeof( char_map_ref ) * 2 * map->size ); |
103 | tmp = ( char_map_ref * ) realloc( map->items, sizeof( char_map_ref ) * 2 * map->size ); |
104 | if( ! tmp ) return ENOMEM; |
104 | if( ! tmp ) return ENOMEM; |
105 | map->size *= 2; |
105 | map->size *= 2; |
106 | memcpy( tmp, map->items, sizeof( char_map_ref ) * map->next ); |
- | |
107 | free( map->items ); |
- | |
108 | map->items = tmp; |
106 | map->items = tmp; |
109 | } |
107 | } |
110 | map->items[ map->next ] = ( char_map_ref ) malloc( sizeof( char_map_t )); |
108 | map->items[ map->next ] = ( char_map_ref ) malloc( sizeof( char_map_t )); |
111 | if( ! map->items[ map->next ] ) return ENOMEM; |
109 | if( ! map->items[ map->next ] ) return ENOMEM; |
112 | char_map_initialize( map->items[ map->next ] ); |
110 | if( char_map_initialize( map->items[ map->next ] ) != EOK ){ |
- | 111 | free( map->items[ map->next ] ); |
|
- | 112 | map->items[ map->next ] = NULL; |
|
- | 113 | return ENOMEM; |
|
- | 114 | } |
|
113 | map->items[ map->next ]->c = * identifier; |
115 | map->items[ map->next ]->c = * identifier; |
114 | ++ identifier; |
116 | ++ identifier; |
115 | if( length ) -- length; |
117 | if( length ) -- length; |
116 | ++ map->next; |
118 | ++ map->next; |
117 | if( length || ( * identifier )){ |
119 | if( length || ( * identifier )){ |
Line 130... | Line 132... | ||
130 | map->magic = 0; |
132 | map->magic = 0; |
131 | for( index = 0; index < map->next; ++ index ){ |
133 | for( index = 0; index < map->next; ++ index ){ |
132 | char_map_destroy( map->items[ index ] ); |
134 | char_map_destroy( map->items[ index ] ); |
133 | } |
135 | } |
134 | free( map->items ); |
136 | free( map->items ); |
- | 137 | map->items = NULL; |
|
135 | } |
138 | } |
136 | } |
139 | } |
137 | 140 | ||
138 | int char_map_exclude( char_map_ref map, const char * identifier, size_t length ){ |
141 | int char_map_exclude( char_map_ref map, const char * identifier, size_t length ){ |
139 | char_map_ref node; |
142 | char_map_ref node; |
Line 177... | Line 180... | ||
177 | return char_map_is_valid( map ) ? map->value : CHAR_MAP_NULL; |
180 | return char_map_is_valid( map ) ? map->value : CHAR_MAP_NULL; |
178 | } |
181 | } |
179 | 182 | ||
180 | int char_map_initialize( char_map_ref map ){ |
183 | int char_map_initialize( char_map_ref map ){ |
181 | if( ! map ) return EINVAL; |
184 | if( ! map ) return EINVAL; |
182 | map->c = 0; |
185 | map->c = '\0'; |
183 | map->value = CHAR_MAP_NULL; |
186 | map->value = CHAR_MAP_NULL; |
184 | map->size = 2; |
187 | map->size = 2; |
185 | map->next = 0; |
188 | map->next = 0; |
186 | map->items = malloc( sizeof( char_map_ref ) * map->size ); |
189 | map->items = malloc( sizeof( char_map_ref ) * map->size ); |
187 | if( ! map->items ) return ENOMEM; |
190 | if( ! map->items ){ |
- | 191 | map->magic = 0; |
|
- | 192 | return ENOMEM; |
|
- | 193 | } |
|
188 | map->items[ map->next ] = NULL; |
194 | map->items[ map->next ] = NULL; |
189 | map->magic = CHAR_MAP_MAGIC_VALUE; |
195 | map->magic = CHAR_MAP_MAGIC_VALUE; |
190 | return EOK; |
196 | return EOK; |
191 | } |
197 | } |
192 | 198 |