[srvx-commits] CVS: services/src common.h,1.82,1.83 tools.c,1.117,1.118
Brought to you by:
entrope
|
From: Entrope <en...@us...> - 2002-09-24 19:19:48
|
Update of /cvsroot/srvx/services/src
In directory usw-pr-cvs1:/tmp/cvs-serv30044/src
Modified Files:
common.h tools.c
Log Message:
add strtab() utility function
Index: common.h
===================================================================
RCS file: /cvsroot/srvx/services/src/common.h,v
retrieving revision 1.82
retrieving revision 1.83
diff -C2 -r1.82 -r1.83
*** common.h 14 Sep 2002 03:48:58 -0000 1.82
--- common.h 24 Sep 2002 19:19:43 -0000 1.83
***************
*** 154,157 ****
--- 154,158 ----
const char *preposition(const char *word);
int set_policer_param(const char *param, void *data, void *extra);
+ const char *strtab(unsigned int ii);
void tools_init(void);
Index: tools.c
===================================================================
RCS file: /cvsroot/srvx/services/src/tools.c,v
retrieving revision 1.117
retrieving revision 1.118
diff -C2 -r1.117 -r1.118
*** tools.c 14 Sep 2002 03:48:59 -0000 1.117
--- tools.c 24 Sep 2002 19:19:43 -0000 1.118
***************
*** 694,697 ****
--- 694,715 ----
}
+ struct string_list str_tab;
+
+ const char *
+ strtab(unsigned int ii) {
+ if (ii > 65536) return NULL;
+ if (ii > str_tab.size) {
+ unsigned int old_size = str_tab.size;
+ while (ii >= str_tab.size) str_tab.size <<= 1;
+ str_tab.list = realloc(str_tab.list, str_tab.size*sizeof(str_tab.list[0]));
+ memset(str_tab.list+old_size, 0, (str_tab.size-old_size)*sizeof(str_tab.list[0]));
+ }
+ if (!str_tab.list[ii]) {
+ str_tab.list[ii] = malloc(12);
+ sprintf(str_tab.list[ii], "%u", ii);
+ }
+ return str_tab.list[ii];
+ }
+
void
tools_init(void)
***************
*** 705,708 ****
--- 723,728 ----
for (upr=0xd8, lwr=0xf8; lwr <= 0xfe; ++upr, ++lwr) irc_tolower[upr] = lwr;
#endif
+ str_tab.size = 1001;
+ str_tab.list = calloc(str_tab.size, sizeof(str_tab.list[0]));
}
***************
*** 710,713 ****
tools_cleanup(void)
{
! /* NOOP */
}
--- 730,737 ----
tools_cleanup(void)
{
! unsigned int ii;
! for (ii=0; ii<str_tab.size; ++ii) {
! if (str_tab.list[ii]) free(str_tab.list[ii]);
! }
! free(str_tab.list);
}
|