/*
* read this room's info file (set v to 1 for verbose mode)
*/
-void readinfo(int v)
+void readinfo(void)
{
char buf[256];
fmout(NULL);
wprintf("</FONT>");
}
- else {
- if (v == 1)
- wprintf("<EM>%s</EM><BR>\n", &buf[4]);
- }
}
-void embed_room_banner(char *got) {
- char buf[256];
- char fakegot[256];
- static int remember_new_mail = (-1);
- /* We need to have the information returned by a GOTO server command.
- * If it isn't supplied, we fake it by issuing our own GOTO.
- */
- if (got == NULL) {
- serv_printf("GOTO %s", WC->wc_roomname);
- serv_gets(fakegot);
- got = fakegot;
- }
-
- /* Check for new mail. */
- WC->new_mail = extract_int(&got[4], 9);
-
- /* Now start spewing HTML. */
- wprintf("<CENTER><TABLE width=100%% border=0 cellpadding=5><TR>");
+/* Display room graphic. The server doesn't actually
+ * need the room name, but we supply it in order to
+ * keep the browser from using a cached graphic from
+ * another room.
+ */
+void embed_room_graphic(void) {
+ char buf[256];
- if ((strlen(WC->ugname) > 0) && (strcasecmp(WC->ugname, WC->wc_roomname))) {
- wprintf("<TD VALIGN=TOP><A HREF=\"/ungoto\">");
- wprintf("<IMG SRC=\"/static/back.gif\" BORDER=0>");
- wprintf("<BR><FONT SIZE=-2>Previous room</FONT></A></TD>");
- }
- wprintf("<TD VALIGN=TOP BGCOLOR=444455>");
- wprintf("<FONT SIZE=+2 COLOR=FFFFEE>%s</FONT><BR>", WC->wc_roomname);
- wprintf("<FONT COLOR=DDDDCC>%d new of %d messages</FONT></TD>\n",
- extract_int(&got[4], 1),
- extract_int(&got[4], 2));
-
- /* Display room graphic. The server doesn't actually
- * need the room name, but we supply it in order to
- * keep the browser from using a cached graphic from
- * another room.
- */
serv_puts("OIMG _roompic_");
serv_gets(buf);
if (buf[0] == '2') {
serv_puts("CLOS");
serv_gets(buf);
}
- wprintf("<TD VALIGN=TOP>");
- readinfo(0);
- wprintf("</TD>");
- /* Let the user know if new mail has arrived */
- if ( (WC->new_mail > remember_new_mail) && (WC->new_mail>0) ) {
+}
+
+
+/* Let the user know if new mail has arrived
+ */
+void embed_newmail_button(void) {
+ if ( (WC->new_mail > WC->remember_new_mail) && (WC->new_mail>0) ) {
wprintf("<TD VALIGN=TOP>"
"<IMG SRC=\"/static/mail.gif\" border=0 "
"ALT=\"You have new mail\">"
"<BR><BLINK>%d</BLINK>", WC->new_mail);
wprintf("<FONT SIZE=-2> new mail messages</FONT></TD>");
- remember_new_mail = WC->new_mail;
+ WC->remember_new_mail = WC->new_mail;
+ }
+}
+
+
+
+void embed_room_banner(char *got) {
+ char fakegot[256];
+
+ /* We need to have the information returned by a GOTO server command.
+ * If it isn't supplied, we fake it by issuing our own GOTO.
+ */
+ if (got == NULL) {
+ serv_printf("GOTO %s", WC->wc_roomname);
+ serv_gets(fakegot);
+ got = fakegot;
}
- wprintf("<TD VALIGN=TOP><A HREF=\"/gotonext\">");
- wprintf("<IMG SRC=\"/static/forward.gif\" border=0>");
- wprintf("<BR><FONT SIZE=-2>Next room</FONT></A></TD>");
- wprintf("</TR></TABLE></CENTER>\n");
+ /* Check for new mail. */
+ WC->new_mail = extract_int(&got[4], 9);
+
+ svprintf("ROOMNAME", WCS_STRING, "%s", WC->wc_roomname);
+ svprintf("NEWMSGS", WCS_STRING, "%d", extract_int(&got[4], 1));
+ svprintf("TOTALMSGS", WCS_STRING, "%d", extract_int(&got[4], 2));
+ svcallback("ROOMPIC", embed_room_graphic);
+ svcallback("ROOMINFO", readinfo);
+ svcallback("YOUHAVEMAIL", embed_newmail_button);
+
+
+ do_template("roombanner.html");
+ clear_local_substs();
}
WC->vars = ptr;
}
+/*
+ * Add a substitution variable (local to this session) that does a callback
+ */
+void svcallback(char *keyname, void (*fcn_ptr)() )
+{
+ struct wcsubst *ptr;
+
+ ptr = (struct wcsubst *) malloc(sizeof(struct wcsubst));
+ ptr->next = WC->vars;
+ ptr->wcs_type = WCS_FUNCTION;
+ strcpy(ptr->wcs_key, keyname);
+ ptr->wcs_function = fcn_ptr;
+ WC->vars = ptr;
+}
+
/*
*/
void print_value_of(char *keyname) {
struct wcsubst *ptr;
+ void *fcn();
for (ptr = WC->vars; ptr != NULL; ptr = ptr->next) {
if (!strcasecmp(ptr->wcs_key, keyname)) {
else if (ptr->wcs_type == WCS_SERVCMD) {
pvo_do_cmd(ptr->wcs_value);
}
+ else if (ptr->wcs_type == WCS_FUNCTION) {
+ (*ptr->wcs_function) ();
+ }
}
}
}
char inbuf[1024];
char outbuf[sizeof inbuf];
char key[sizeof inbuf];
- int i, j, pos;
- int olen;
+ int i, pos;
strcpy(filename, "static/");
strcat(filename, templatename);
while (fgets(inbuf, sizeof inbuf, fp) != NULL) {
strcpy(outbuf, "");
- olen = 0;
- for (i=0; i<strlen(inbuf); ++i) {
- if (strncmp(&inbuf[i], "<?", 2)) {
- outbuf[olen] = inbuf[i];
- outbuf[++olen] = 0;
+ while (strlen(inbuf) > 0) {
+ pos = (-1);
+ for (i=strlen(inbuf); i>=0; --i) {
+ if ((inbuf[i]=='<')&&(inbuf[i+1]=='?')) pos = i;
+ }
+ if (pos < 0) {
+ wprintf("%s", inbuf);
+ strcpy(inbuf, "");
}
else {
- pos = (-1);
- for (j=strlen(inbuf); j>=i; --j) {
- if (inbuf[j]=='>') pos = j;
- }
- if (pos > 0) {
- wprintf("%s", outbuf);
- strcpy(outbuf, "");
- olen = 0;
- strncpy(key, &inbuf[i+2], pos-i-2);
- print_value_of(key);
- i = pos;
- }
- else {
- i = i + 2;
+ strncpy(outbuf, inbuf, pos);
+ outbuf[pos] = 0;
+ wprintf("%s", outbuf);
+ strcpy(inbuf, &inbuf[pos]);
+ pos = 1;
+ for (i=strlen(inbuf); i>=0; --i) {
+ if (inbuf[i]=='>') pos = i;
}
+ strncpy(key, &inbuf[2], pos-2);
+ key[pos-2] = 0;
+ print_value_of(key);
+ strcpy(inbuf, &inbuf[pos+1]);
}
}
- wprintf("%s", outbuf);
}
fclose(fp);