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 free(WC->vars->wcs_value);
55 * Add a substitution variable (local to this session)
57 void svprintf(char *keyname, const char *format,...)
63 va_start(arg_ptr, format);
64 vsprintf(wbuf, format, arg_ptr);
67 ptr = (struct wcsubst *) malloc(sizeof(struct wcsubst));
69 ptr->wcs_type = WCS_STRING;
70 strcpy(ptr->wcs_key, keyname);
71 ptr->wcs_value = malloc(strlen(wbuf)+1);
72 strcpy(ptr->wcs_value, wbuf);
79 * Print the value of a variable
81 void print_value_of(char *keyname) {
84 for (ptr = WC->vars; ptr != NULL; ptr = ptr->next) {
85 if (!strcasecmp(ptr->wcs_key, keyname)) {
86 if (ptr->wcs_type == WCS_STRING) {
87 wprintf("%s", ptr->wcs_value);
96 * Display a variable-substituted template
98 void do_template(void *templatename) {
99 char filename[PATH_MAX];
102 char outbuf[sizeof inbuf];
103 char key[sizeof inbuf];
107 strcpy(filename, "static/");
108 strcat(filename, templatename);
110 fp = fopen(filename, "r");
112 wprintf("<BLINK>ERROR</BLINK> - could not open template ");
113 wprintf("'%s' - %s<BR>\n",
114 templatename, strerror(errno));
120 while (fgets(inbuf, sizeof inbuf, fp) != NULL) {
124 for (i=0; i<strlen(inbuf); ++i) {
125 if (strncmp(&inbuf[i], "<?", 2)) {
126 outbuf[olen] = inbuf[i];
131 for (j=strlen(inbuf); j>=i; --j) {
132 if (inbuf[j]=='>') pos = j;
135 strncpy(key, &inbuf[i+2], pos-i-2);
137 olen = strlen(outbuf);
145 wprintf("%s", outbuf);