Changeset b5e68c8 in mainline for uspace/lib/c/generic/adt/char_map.c
- Timestamp:
- 2011-05-12T16:49:44Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f36787d7
- Parents:
- e80329d6 (diff), 750636a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/adt/char_map.c
re80329d6 rb5e68c8 60 60 * @param[in] value The integral value to be stored for the key character 61 61 * string. 62 * @return sEOK on success.63 * @return sENOMEM if there is not enough memory left.64 * @return sEEXIST if the key character string is already used.62 * @return EOK on success. 63 * @return ENOMEM if there is not enough memory left. 64 * @return EEXIST if the key character string is already used. 65 65 */ 66 66 static int 67 char_map_add_item(char_map_ ref map, const char*identifier, size_t length,67 char_map_add_item(char_map_t *map, const uint8_t *identifier, size_t length, 68 68 const int value) 69 69 { 70 70 if (map->next == (map->size - 1)) { 71 char_map_ ref*tmp;72 73 tmp = (char_map_ ref*) realloc(map->items,74 sizeof(char_map_ ref) * 2 * map->size);71 char_map_t **tmp; 72 73 tmp = (char_map_t **) realloc(map->items, 74 sizeof(char_map_t *) * 2 * map->size); 75 75 if (!tmp) 76 76 return ENOMEM; … … 80 80 } 81 81 82 map->items[map->next] = (char_map_ ref) malloc(sizeof(char_map_t));82 map->items[map->next] = (char_map_t *) malloc(sizeof(char_map_t)); 83 83 if (!map->items[map->next]) 84 84 return ENOMEM; … … 90 90 } 91 91 92 map->items[map->next]->c = * 93 ++ identifier;94 ++ map->next;95 if ((length > 1) || ((length == 0) && (*identifier))) {92 map->items[map->next]->c = *identifier; 93 identifier++; 94 map->next++; 95 if ((length > 1) || ((length == 0) && *identifier)) { 96 96 map->items[map->next - 1]->value = CHAR_MAP_NULL; 97 97 return char_map_add_item(map->items[map->next - 1], identifier, … … 107 107 * 108 108 * @param[in] map The character string to integer map. 109 * @return sTRUE if the map is valid.110 * @return sFALSE otherwise.111 */ 112 static int char_map_is_valid(const char_map_ refmap)109 * @return TRUE if the map is valid. 110 * @return FALSE otherwise. 111 */ 112 static int char_map_is_valid(const char_map_t *map) 113 113 { 114 114 return map && (map->magic == CHAR_MAP_MAGIC_VALUE); … … 127 127 * @param[in] value The integral value to be stored for the key character 128 128 * string. 129 * @return sEOK on success.130 * @return sEINVAL if the map is not valid.131 * @return sEINVAL if the identifier parameter is NULL.132 * @return sEINVAL if the length parameter zero (0) and the129 * @return EOK on success. 130 * @return EINVAL if the map is not valid. 131 * @return EINVAL if the identifier parameter is NULL. 132 * @return EINVAL if the length parameter zero (0) and the 133 133 * identifier parameter is an empty character string (the 134 134 * first character is the terminating zero ('\0') 135 135 * character. 136 * @return sEEXIST if the key character string is already used.137 * @return sOther error codes as defined for the136 * @return EEXIST if the key character string is already used. 137 * @return Other error codes as defined for the 138 138 * char_map_add_item() function. 139 139 */ 140 140 int 141 char_map_add(char_map_ ref map, const char*identifier, size_t length,141 char_map_add(char_map_t *map, const uint8_t *identifier, size_t length, 142 142 const int value) 143 143 { 144 if (char_map_is_valid(map) && (identifier) && 145 ((length) || (*identifier))) { 144 if (char_map_is_valid(map) && identifier && (length || *identifier)) { 146 145 int index; 147 146 148 for (index = 0; index < map->next; ++ index) {147 for (index = 0; index < map->next; index++) { 149 148 if (map->items[index]->c != *identifier) 150 149 continue; 151 150 152 ++ identifier;153 if((length > 1) || ((length == 0) && (*identifier))) {151 identifier++; 152 if((length > 1) || ((length == 0) && *identifier)) { 154 153 return char_map_add(map->items[index], 155 154 identifier, length ? length - 1 : 0, value); … … 172 171 * @param[in,out] map The character string to integer map. 173 172 */ 174 void char_map_destroy(char_map_ refmap)173 void char_map_destroy(char_map_t *map) 175 174 { 176 175 if (char_map_is_valid(map)) { … … 178 177 179 178 map->magic = 0; 180 for (index = 0; index < map->next; ++index)179 for (index = 0; index < map->next; index++) 181 180 char_map_destroy(map->items[index]); 182 181 … … 196 195 * zero (0) which means that the string is processed until 197 196 * the terminating zero ('\0') character is found. 198 * @return sThe node holding the integral value assigned to the key197 * @return The node holding the integral value assigned to the key 199 198 * character string. 200 * @return sNULL if the key is not assigned a node.201 */ 202 static char_map_ ref203 char_map_find_node(const char_map_ ref map, const char*identifier,199 * @return NULL if the key is not assigned a node. 200 */ 201 static char_map_t * 202 char_map_find_node(const char_map_t *map, const uint8_t *identifier, 204 203 size_t length) 205 204 { … … 207 206 return NULL; 208 207 209 if (length || (*identifier)) {208 if (length || *identifier) { 210 209 int index; 211 210 212 for (index = 0; index < map->next; ++index) {211 for (index = 0; index < map->next; index++) { 213 212 if (map->items[index]->c == *identifier) { 214 ++identifier;213 identifier++; 215 214 if (length == 1) 216 215 return map->items[index]; … … 224 223 } 225 224 226 return map;225 return (char_map_t *) map; 227 226 } 228 227 … … 239 238 * zero (0) which means that the string is processed until 240 239 * the terminating zero ('\0') character is found. 241 * @return sThe integral value assigned to the key character string.242 * @return sCHAR_MAP_NULL if the key is not assigned a value.243 */ 244 int char_map_exclude(char_map_ ref map, const char*identifier, size_t length)245 { 246 char_map_ refnode;240 * @return The integral value assigned to the key character string. 241 * @return CHAR_MAP_NULL if the key is not assigned a value. 242 */ 243 int char_map_exclude(char_map_t *map, const uint8_t *identifier, size_t length) 244 { 245 char_map_t *node; 247 246 248 247 node = char_map_find_node(map, identifier, length); … … 267 266 * zero (0) which means that the string is processed until 268 267 * the terminating zero ('\0') character is found. 269 * @return sThe integral value assigned to the key character string.270 * @return sCHAR_MAP_NULL if the key is not assigned a value.271 */ 272 int char_map_find(const char_map_ ref map, const char*identifier, size_t length)273 { 274 char_map_ refnode;268 * @return The integral value assigned to the key character string. 269 * @return CHAR_MAP_NULL if the key is not assigned a value. 270 */ 271 int char_map_find(const char_map_t *map, const uint8_t *identifier, size_t length) 272 { 273 char_map_t *node; 275 274 276 275 node = char_map_find_node(map, identifier, length); … … 281 280 * 282 281 * @param[in,out] map The character string to integer map. 283 * @return sEOK on success.284 * @return sEINVAL if the map parameter is NULL.285 * @return sENOMEM if there is not enough memory left.286 */ 287 int char_map_initialize(char_map_ refmap)282 * @return EOK on success. 283 * @return EINVAL if the map parameter is NULL. 284 * @return ENOMEM if there is not enough memory left. 285 */ 286 int char_map_initialize(char_map_t *map) 288 287 { 289 288 if (!map) … … 295 294 map->next = 0; 296 295 297 map->items = malloc(sizeof(char_map_ ref) * map->size);296 map->items = malloc(sizeof(char_map_t *) * map->size); 298 297 if (!map->items) { 299 298 map->magic = 0; … … 319 318 * @param[in] value The integral value to be stored for the key character 320 319 * string. 321 * @return sEOK on success.322 * @return sEINVAL if the map is not valid.323 * @return sEINVAL if the identifier parameter is NULL.324 * @return sEINVAL if the length parameter zero (0) and the320 * @return EOK on success. 321 * @return EINVAL if the map is not valid. 322 * @return EINVAL if the identifier parameter is NULL. 323 * @return EINVAL if the length parameter zero (0) and the 325 324 * identifier parameter is an empty character string (the 326 325 * first character is the terminating zero ('\0) character. 327 * @return sEEXIST if the key character string is already used.328 * @return sOther error codes as defined for the char_map_add_item()326 * @return EEXIST if the key character string is already used. 327 * @return Other error codes as defined for the char_map_add_item() 329 328 * function. 330 329 */ 331 330 int 332 char_map_update(char_map_ ref map, const char*identifier, const size_t length,331 char_map_update(char_map_t *map, const uint8_t *identifier, const size_t length, 333 332 const int value) 334 333 { 335 char_map_ refnode;334 char_map_t *node; 336 335 337 336 node = char_map_find_node(map, identifier, length);
Note:
See TracChangeset
for help on using the changeset viewer.