00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 static int expmem_udef(struct udef_struct *ul)
00026 {
00027 int i = 0;
00028
00029 for (; ul; ul = ul->next) {
00030 i += sizeof(struct udef_struct);
00031 i += strlen(ul->name) + 1;
00032 i += expmem_udef_chans(ul->type, ul->values);
00033 }
00034 return i;
00035 }
00036
00037 static int expmem_udef_chans(int type, struct udef_chans *ul)
00038 {
00039 int i = 0;
00040
00041 for (; ul; ul = ul->next) {
00042 i += sizeof(struct udef_chans);
00043 i += strlen(ul->chan) + 1;
00044 if (type == UDEF_STR && ul->value)
00045 i += strlen((char *) ul->value) + 1;
00046 }
00047 return i;
00048 }
00049
00050 static intptr_t getudef(struct udef_chans *ul, char *name)
00051 {
00052 intptr_t val = 0;
00053
00054 for (; ul; ul = ul->next)
00055 if (!egg_strcasecmp(ul->chan, name)) {
00056 val = ul->value;
00057 break;
00058 }
00059 return val;
00060 }
00061
00062 static intptr_t ngetudef(char *name, char *chan)
00063 {
00064 struct udef_struct *l;
00065 struct udef_chans *ll;
00066
00067 for (l = udef; l; l = l->next)
00068 if (!egg_strcasecmp(l->name, name)) {
00069 for (ll = l->values; ll; ll = ll->next)
00070 if (!egg_strcasecmp(ll->chan, chan))
00071 return ll->value;
00072 break;
00073 }
00074 return 0;
00075 }
00076
00077 static void setudef(struct udef_struct *us, char *name, intptr_t value)
00078 {
00079 struct udef_chans *ul, *ul_last = NULL;
00080
00081 for (ul = us->values; ul; ul_last = ul, ul = ul->next)
00082 if (!egg_strcasecmp(ul->chan, name)) {
00083 ul->value = value;
00084 return;
00085 }
00086
00087 ul = nmalloc(sizeof(struct udef_chans));
00088 ul->chan = nmalloc(strlen(name) + 1);
00089 strcpy(ul->chan, name);
00090 ul->value = value;
00091 ul->next = NULL;
00092 if (ul_last)
00093 ul_last->next = ul;
00094 else
00095 us->values = ul;
00096 }
00097
00098 static void initudef(int type, char *name, int defined)
00099 {
00100 struct udef_struct *ul, *ul_last = NULL;
00101
00102 if (strlen(name) < 1)
00103 return;
00104
00105 for (ul = udef; ul; ul_last = ul, ul = ul->next)
00106 if (ul->name && !egg_strcasecmp(ul->name, name)) {
00107 if (defined) {
00108 debug1("UDEF: %s defined", ul->name);
00109 ul->defined = 1;
00110 }
00111 return;
00112 }
00113
00114 debug2("Creating %s (type %d)", name, type);
00115 ul = nmalloc(sizeof(struct udef_struct));
00116 ul->name = nmalloc(strlen(name) + 1);
00117 strcpy(ul->name, name);
00118 if (defined)
00119 ul->defined = 1;
00120 else
00121 ul->defined = 0;
00122 ul->type = type;
00123 ul->values = NULL;
00124 ul->next = NULL;
00125 if (ul_last)
00126 ul_last->next = ul;
00127 else
00128 udef = ul;
00129 }
00130
00131 static void free_udef(struct udef_struct *ul)
00132 {
00133 struct udef_struct *ull;
00134
00135 for (; ul; ul = ull) {
00136 ull = ul->next;
00137 free_udef_chans(ul->values, ul->type);
00138 nfree(ul->name);
00139 nfree(ul);
00140 }
00141 }
00142
00143 static void free_udef_chans(struct udef_chans *ul, int type)
00144 {
00145 struct udef_chans *ull;
00146
00147 for (; ul; ul = ull) {
00148 ull = ul->next;
00149 if (type == UDEF_STR && ul->value)
00150 nfree((void *) ul->value);
00151 nfree(ul->chan);
00152 nfree(ul);
00153 }
00154 }