comparison src/c/urweb.c @ 916:b873feb3eb52

dragList almost kinda works
author Adam Chlipala <adamc@hcoop.net>
date Tue, 08 Sep 2009 10:18:19 -0400
parents 8e540df3294d
children 321a2d6feb40
comparison
equal deleted inserted replaced
915:5e8b6fa5b48f 916:b873feb3eb52
1151 strcpy(ctx->script.front, s); 1151 strcpy(ctx->script.front, s);
1152 ctx->script.front += len; 1152 ctx->script.front += len;
1153 } 1153 }
1154 1154
1155 const char *uw_Basis_get_script(uw_context ctx, uw_unit u) { 1155 const char *uw_Basis_get_script(uw_context ctx, uw_unit u) {
1156 if (ctx->script_header[0] == 0) 1156 return "<sc>";
1157 return "";
1158 else if (buf_used(&ctx->script) == 0)
1159 return ctx->script_header;
1160 else {
1161 char *r = uw_malloc(ctx, strlen(ctx->script_header) + 42 + buf_used(&ctx->script));
1162 sprintf(r, "%s<script type=\"text/javascript\">%s</script>",
1163 ctx->script_header,
1164 ctx->script.start);
1165 return r;
1166 }
1167 } 1157 }
1168 1158
1169 uw_Basis_string uw_Basis_maybe_onload(uw_context ctx, uw_Basis_string s) { 1159 uw_Basis_string uw_Basis_maybe_onload(uw_context ctx, uw_Basis_string s) {
1170 if (s[0] == 0) 1160 if (s[0] == 0)
1171 return ""; 1161 return "";
2555 if (ctx->client) 2545 if (ctx->client)
2556 release_client(ctx->client); 2546 release_client(ctx->client);
2557 2547
2558 for (i = 0; i < ctx->used_transactionals; ++i) 2548 for (i = 0; i < ctx->used_transactionals; ++i)
2559 ctx->transactionals[i].free(ctx->transactionals[i].data); 2549 ctx->transactionals[i].free(ctx->transactionals[i].data);
2550
2551 // Splice script data into appropriate part of page
2552 if (ctx->script_header[0] == 0)
2553 ;
2554 else if (buf_used(&ctx->script) == 0) {
2555 size_t len = strlen(ctx->script_header);
2556 char *start = strstr(ctx->page.start, "<sc>");
2557 if (start) {
2558 buf_check(&ctx->page, buf_used(&ctx->page) - 4 + len);
2559 memmove(start + len, start + 4, buf_used(&ctx->page) - (start - ctx->page.start) - 3);
2560 ctx->page.front += len - 4;
2561 memcpy(start, ctx->script_header, len);
2562 }
2563 } else {
2564 size_t lenH = strlen(ctx->script_header), len = buf_used(&ctx->script);
2565 size_t lenP = lenH + 40 + len;
2566 char *start = strstr(ctx->page.start, "<sc>");
2567 if (start) {
2568 buf_check(&ctx->page, buf_used(&ctx->page) - 4 + lenP);
2569 memmove(start + lenP, start + 4, buf_used(&ctx->page) - (start - ctx->page.start) - 3);
2570 ctx->page.front += lenP - 4;
2571 memcpy(start, ctx->script_header, lenH);
2572 memcpy(start + lenH, "<script type=\"text/javascript\">", 31);
2573 memcpy(start + lenH + 31, ctx->script.start, len);
2574 memcpy(start + lenH + 31 + len, "</script>", 9);
2575 printf("start=%s\n", start);
2576 }
2577 }
2560 } 2578 }
2561 2579
2562 int uw_rollback(uw_context ctx) { 2580 int uw_rollback(uw_context ctx) {
2563 size_t i; 2581 size_t i;
2564 cleanup *cl; 2582 cleanup *cl;