diff src/c/urweb.c @ 643:aa2290c32ce2

Avoid any JavaScript when pages don't need it; update demo prose
author Adam Chlipala <adamc@hcoop.net>
date Tue, 10 Mar 2009 10:44:26 -0400
parents 889dc9fceb3a
children 1b571a05874c
line wrap: on
line diff
--- a/src/c/urweb.c	Sun Mar 08 20:34:21 2009 -0400
+++ b/src/c/urweb.c	Tue Mar 10 10:44:26 2009 -0400
@@ -42,6 +42,8 @@
 
   cleanup *cleanup, *cleanup_front, *cleanup_back;
 
+  const char *script_header;
+
   char error_message[ERROR_BUF_LEN];
 };
 
@@ -71,6 +73,8 @@
 
   ctx->cleanup_front = ctx->cleanup_back = ctx->cleanup = malloc(0);
 
+  ctx->script_header = "";
+  
   ctx->error_message[0] = 0;
 
   ctx->script_front = ctx->script = malloc(script_len);
@@ -235,6 +239,10 @@
   return (ctx->inputs[n] == NULL ? "" : ctx->inputs[n]);
 }
 
+void uw_set_script_header(uw_context ctx, const char *s) {
+  ctx->script_header = s;
+}
+
 static void uw_check_heap(uw_context ctx, size_t extra) {
   if (ctx->heap_back - ctx->heap_front < extra) {
     size_t desired = ctx->heap_front - ctx->heap + extra, next;
@@ -380,9 +388,9 @@
     r[0] = 0;
     return r;
   } else {
-    char *r = uw_malloc(ctx, 41 + (ctx->script_front - ctx->script));
+    char *r = uw_malloc(ctx, 41 + (ctx->script_front - ctx->script) + strlen(ctx->script_header));
 
-    sprintf(r, "<script>%s</script>", ctx->script);
+    sprintf(r, "%s<script>%s</script>", ctx->script_header, ctx->script);
     return r;
   }
 }