comparison src/c/urweb.c @ 565:74800be65591

Creation of sources in server code
author Adam Chlipala <adamc@hcoop.net>
date Fri, 19 Dec 2008 11:47:18 -0500
parents 6daa59a55c43
children a152905c3c3b
comparison
equal deleted inserted replaced
564:803b2f3bb86b 565:74800be65591
30 char *page, *page_front, *page_back; 30 char *page, *page_front, *page_back;
31 char *heap, *heap_front, *heap_back; 31 char *heap, *heap_front, *heap_back;
32 char **inputs; 32 char **inputs;
33 33
34 char *script, *script_front, *script_back; 34 char *script, *script_front, *script_back;
35 int reactive_count; 35 int source_count;
36 36
37 void *db; 37 void *db;
38 38
39 jmp_buf jmp_buf; 39 jmp_buf jmp_buf;
40 40
73 73
74 ctx->error_message[0] = 0; 74 ctx->error_message[0] = 0;
75 75
76 ctx->script_front = ctx->script = malloc(script_len); 76 ctx->script_front = ctx->script = malloc(script_len);
77 ctx->script_back = ctx->script_front + script_len; 77 ctx->script_back = ctx->script_front + script_len;
78 ctx->reactive_count = 0; 78 ctx->source_count = 0;
79 79
80 return ctx; 80 return ctx;
81 } 81 }
82 82
83 void uw_set_db(uw_context ctx, void *db) { 83 void uw_set_db(uw_context ctx, void *db) {
103 ctx->script_front = ctx->script; 103 ctx->script_front = ctx->script;
104 ctx->page_front = ctx->page; 104 ctx->page_front = ctx->page;
105 ctx->heap_front = ctx->heap; 105 ctx->heap_front = ctx->heap;
106 ctx->regions = NULL; 106 ctx->regions = NULL;
107 ctx->cleanup_front = ctx->cleanup; 107 ctx->cleanup_front = ctx->cleanup;
108 ctx->reactive_count = 0; 108 ctx->source_count = 0;
109 } 109 }
110 110
111 void uw_reset_keep_request(uw_context ctx) { 111 void uw_reset_keep_request(uw_context ctx) {
112 uw_reset_keep_error_message(ctx); 112 uw_reset_keep_error_message(ctx);
113 ctx->error_message[0] = 0; 113 ctx->error_message[0] = 0;
372 uw_check_script(ctx, len + 1); 372 uw_check_script(ctx, len + 1);
373 strcpy(ctx->script_front, s); 373 strcpy(ctx->script_front, s);
374 ctx->script_front += len; 374 ctx->script_front += len;
375 } 375 }
376 376
377 int uw_Basis_new_client_reactive(uw_context ctx) { 377 char *uw_Basis_get_script(uw_context ctx, uw_unit u) {
378 if (ctx->script_front == ctx->script) {
379 char *r = uw_malloc(ctx, 1);
380 r[0] = 0;
381 return r;
382 } else {
383 char *r = uw_malloc(ctx, 41 + (ctx->script_front - ctx->script));
384
385 sprintf(r, "<script type=\"text/javascript\">%s</script>", ctx->script);
386 return r;
387 }
388 }
389
390 int uw_Basis_new_client_source(uw_context ctx, uw_unit u) {
378 size_t len; 391 size_t len;
379 392
380 uw_check_script(ctx, 8 + INTS_MAX); 393 uw_check_script(ctx, 8 + INTS_MAX);
381 sprintf(ctx->script_front, "var e%d=0\n%n", ctx->reactive_count, &len); 394 sprintf(ctx->script_front, "var e%d=0\n%n", ctx->source_count, &len);
382 ctx->script_front += len; 395 ctx->script_front += len;
383 396
384 return ctx->reactive_count++; 397 return ctx->source_count++;
385 } 398 }
386 399
387 static void uw_check(uw_context ctx, size_t extra) { 400 static void uw_check(uw_context ctx, size_t extra) {
388 size_t desired = ctx->page_front - ctx->page + extra, next; 401 size_t desired = ctx->page_front - ctx->page + extra, next;
389 char *new_page; 402 char *new_page;