4 * Variable substitution type stuff
16 #include <sys/types.h>
18 #include <sys/socket.h>
22 #include <netinet/in.h>
32 struct wcsubst *global_subst = NULL;
36 * Clear out the list of substitution variables local to this session
38 void clear_local_substs(void) {
41 while (WC->vars != NULL) {
44 if ((WC->vars->wcs_type == WCS_STRING)
45 || (WC->vars->wcs_type == WCS_SERVCMD)) {
46 free(WC->vars->wcs_value);
56 * Add a substitution variable (local to this session)
58 void svprintf(char *keyname, int keytype, const char *format,...)
64 va_start(arg_ptr, format);
65 vsprintf(wbuf, format, arg_ptr);
68 ptr = (struct wcsubst *) malloc(sizeof(struct wcsubst));
70 ptr->wcs_type = keytype;
71 strcpy(ptr->wcs_key, keyname);
72 ptr->wcs_value = malloc(strlen(wbuf)+1);
73 strcpy(ptr->wcs_value, wbuf);
80 * back end for print_value_of() ... does a server command
82 void pvo_do_cmd(char *servcmd) {
92 wprintf("%s\n", &buf[4]);
98 wprintf("%s\n", &buf[4]);
107 * Print the value of a variable
109 void print_value_of(char *keyname) {
112 for (ptr = WC->vars; ptr != NULL; ptr = ptr->next) {
113 if (!strcasecmp(ptr->wcs_key, keyname)) {
114 if (ptr->wcs_type == WCS_STRING) {
115 wprintf("%s", ptr->wcs_value);
117 else if (ptr->wcs_type == WCS_SERVCMD) {
118 pvo_do_cmd(ptr->wcs_value);
127 * Display a variable-substituted template
129 void do_template(void *templatename) {
130 char filename[PATH_MAX];
133 char outbuf[sizeof inbuf];
134 char key[sizeof inbuf];
138 strcpy(filename, "static/");
139 strcat(filename, templatename);
141 fp = fopen(filename, "r");
143 wprintf("<BLINK>ERROR</BLINK> - could not open template ");
144 wprintf("'%s' - %s<BR>\n",
145 templatename, strerror(errno));
151 while (fgets(inbuf, sizeof inbuf, fp) != NULL) {
155 for (i=0; i<strlen(inbuf); ++i) {
156 if (strncmp(&inbuf[i], "<?", 2)) {
157 outbuf[olen] = inbuf[i];
162 for (j=strlen(inbuf); j>=i; --j) {
163 if (inbuf[j]=='>') pos = j;
166 wprintf("%s", outbuf);
169 strncpy(key, &inbuf[i+2], pos-i-2);
178 wprintf("%s", outbuf);