Browse code

core: helper functions to get str names for kemi types

Daniel-Constantin Mierla authored on 30/04/2016 09:20:33
Showing 2 changed files
... ...
@@ -1014,3 +1014,63 @@ str* sr_kemi_cbname_lookup_idx(int idx)
1014 1014
 	}
1015 1015
 	return &_sr_kemi_cbname_list[idx-1].name;
1016 1016
 }
1017
+
1018
+/**
1019
+ *
1020
+ */
1021
+typedef struct sr_kemi_param_map {
1022
+	int ptype;
1023
+	str pname;
1024
+} sr_kemi_param_map_t;
1025
+
1026
+/**
1027
+ *
1028
+ */
1029
+static sr_kemi_param_map_t _sr_kemi_param_map[] = {
1030
+	{ SR_KEMIP_NONE, str_init("none") },
1031
+	{ SR_KEMIP_INT,  str_init("int") },
1032
+	{ SR_KEMIP_STR,  str_init("str") },
1033
+	{ SR_KEMIP_BOOL, str_init("bool") },
1034
+	{ 0, STR_NULL }
1035
+};
1036
+
1037
+/**
1038
+ *
1039
+ */
1040
+str *sr_kemi_param_map_get_name(int ptype)
1041
+{
1042
+	int i;
1043
+
1044
+	for(i=0; _sr_kemi_param_map[i].pname.s!=NULL; i++) {
1045
+		if(_sr_kemi_param_map[i].ptype==ptype)
1046
+			return &_sr_kemi_param_map[i].pname;
1047
+	}
1048
+	return NULL;
1049
+}
1050
+
1051
+/**
1052
+ *
1053
+ */
1054
+str *sr_kemi_param_map_get_params(int *ptypes)
1055
+{
1056
+	int i;
1057
+	static char pbuf[64];
1058
+	static str sret = STR_NULL;
1059
+	str *pn;
1060
+
1061
+	pbuf[0] = '\0';
1062
+	for(i=0; i<SR_KEMI_PARAMS_MAX; i++) {
1063
+		if(ptypes[i]==SR_KEMIP_NONE) break;
1064
+		if(i>0) strcat(pbuf, ", ");
1065
+		pn = sr_kemi_param_map_get_name(ptypes[i]);
1066
+		if(pn==NULL) return NULL;
1067
+		strcat(pbuf, pn->s);
1068
+	}
1069
+	if(pbuf[0]=='\0') {
1070
+		pn = sr_kemi_param_map_get_name(SR_KEMIP_NONE);
1071
+		strcat(pbuf, pn->s);
1072
+	}
1073
+	sret.s = pbuf;
1074
+	sret.len = strlen(sret.s);
1075
+	return &sret;
1076
+}
... ...
@@ -120,4 +120,7 @@ str* sr_kemi_cbname_lookup_idx(int idx);
120 120
 void sr_kemi_act_ctx_set(run_act_ctx_t *ctx);
121 121
 run_act_ctx_t* sr_kemi_act_ctx_get(void);
122 122
 
123
+str *sr_kemi_param_map_get_name(int ptype);
124
+str *sr_kemi_param_map_get_params(int *ptypes);
125
+
123 126
 #endif