comparison 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
comparison
equal deleted inserted replaced
642:4a125bbc602d 643:aa2290c32ce2
40 40
41 regions *regions; 41 regions *regions;
42 42
43 cleanup *cleanup, *cleanup_front, *cleanup_back; 43 cleanup *cleanup, *cleanup_front, *cleanup_back;
44 44
45 const char *script_header;
46
45 char error_message[ERROR_BUF_LEN]; 47 char error_message[ERROR_BUF_LEN];
46 }; 48 };
47 49
48 extern int uw_inputs_len; 50 extern int uw_inputs_len;
49 51
69 71
70 ctx->regions = NULL; 72 ctx->regions = NULL;
71 73
72 ctx->cleanup_front = ctx->cleanup_back = ctx->cleanup = malloc(0); 74 ctx->cleanup_front = ctx->cleanup_back = ctx->cleanup = malloc(0);
73 75
76 ctx->script_header = "";
77
74 ctx->error_message[0] = 0; 78 ctx->error_message[0] = 0;
75 79
76 ctx->script_front = ctx->script = malloc(script_len); 80 ctx->script_front = ctx->script = malloc(script_len);
77 ctx->script_back = ctx->script_front + script_len; 81 ctx->script_back = ctx->script_front + script_len;
78 ctx->source_count = 0; 82 ctx->source_count = 0;
233 uw_error(ctx, FATAL, "Out-of-bounds input index %d", n); 237 uw_error(ctx, FATAL, "Out-of-bounds input index %d", n);
234 //printf("[%d] = %s\n", n, ctx->inputs[n]); 238 //printf("[%d] = %s\n", n, ctx->inputs[n]);
235 return (ctx->inputs[n] == NULL ? "" : ctx->inputs[n]); 239 return (ctx->inputs[n] == NULL ? "" : ctx->inputs[n]);
236 } 240 }
237 241
242 void uw_set_script_header(uw_context ctx, const char *s) {
243 ctx->script_header = s;
244 }
245
238 static void uw_check_heap(uw_context ctx, size_t extra) { 246 static void uw_check_heap(uw_context ctx, size_t extra) {
239 if (ctx->heap_back - ctx->heap_front < extra) { 247 if (ctx->heap_back - ctx->heap_front < extra) {
240 size_t desired = ctx->heap_front - ctx->heap + extra, next; 248 size_t desired = ctx->heap_front - ctx->heap + extra, next;
241 char *new_heap; 249 char *new_heap;
242 250
378 if (ctx->script_front == ctx->script) { 386 if (ctx->script_front == ctx->script) {
379 char *r = uw_malloc(ctx, 1); 387 char *r = uw_malloc(ctx, 1);
380 r[0] = 0; 388 r[0] = 0;
381 return r; 389 return r;
382 } else { 390 } else {
383 char *r = uw_malloc(ctx, 41 + (ctx->script_front - ctx->script)); 391 char *r = uw_malloc(ctx, 41 + (ctx->script_front - ctx->script) + strlen(ctx->script_header));
384 392
385 sprintf(r, "<script>%s</script>", ctx->script); 393 sprintf(r, "%s<script>%s</script>", ctx->script_header, ctx->script);
386 return r; 394 return r;
387 } 395 }
388 } 396 }
389 397
390 uw_Basis_string uw_Basis_jsifyString(uw_context ctx, uw_Basis_string s) { 398 uw_Basis_string uw_Basis_jsifyString(uw_context ctx, uw_Basis_string s) {