Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00030 #include <stdlib.h>
00031 #include "cr_map.h"
00032 #include "../../mem/shm_mem.h"
00033 #include "../../ut.h"
00034
00035
00036
00046 int map_name2id(struct name_map_t * map, int size, const str * name) {
00047 int i;
00048
00049 if ((!name) || (name->len <= 0)) {
00050 return -1;
00051 }
00052
00053 for (i=0; i<size; i++) {
00054 if (str_strcmp(&map[i].name, name) == 0) return map[i].id;
00055 }
00056 return -1;
00057 }
00058
00059
00069 str * map_id2name(struct name_map_t * map, int size, int id) {
00070 struct name_map_t key;
00071 struct name_map_t * tmp;
00072
00073 key.id = id;
00074 tmp = bsearch(&key, map, size, sizeof(struct name_map_t), compare_name_map);
00075 if (tmp == NULL) return NULL;
00076 return &tmp->name;
00077 }
00078
00079
00085 int compare_name_map(const void *v1, const void *v2) {
00086 if (((struct name_map_t *)v1)->id < ((struct name_map_t *)v2)->id) return -1;
00087 else if (((struct name_map_t *)v1)->id > ((struct name_map_t *)v2)->id) return 1;
00088 else return 0;
00089 }