comparison src/c/urweb.c @ 577:3d56940120b1

Setting a source server-side
author Adam Chlipala <adamc@hcoop.net>
date Tue, 30 Dec 2008 10:49:42 -0500
parents ac947e2f29ff
children 8f8771f32909
comparison
equal deleted inserted replaced
576:813f1e78d9d0 577:3d56940120b1
361 361
362 new_script = realloc(ctx->script, next); 362 new_script = realloc(ctx->script, next);
363 ctx->script_front = new_script + (ctx->script_front - ctx->script); 363 ctx->script_front = new_script + (ctx->script_front - ctx->script);
364 ctx->script_back = new_script + next; 364 ctx->script_back = new_script + next;
365 ctx->script = new_script; 365 ctx->script = new_script;
366 printf("new_script = %p\n", new_script);
366 } 367 }
367 } 368 }
368 369
369 void uw_write_script(uw_context ctx, uw_Basis_string s) { 370 void uw_write_script(uw_context ctx, uw_Basis_string s) {
370 int len = strlen(s); 371 int len = strlen(s);
432 433
433 for (; *s; s++) { 434 for (; *s; s++) {
434 char c = *s; 435 char c = *s;
435 436
436 switch (c) { 437 switch (c) {
437 case '"': 438 case '\'':
438 strcpy(s2, "\\\""); 439 strcpy(s2, "\\\"");
439 s2 += 2; 440 s2 += 2;
440 break; 441 break;
441 case '\\': 442 case '\\':
442 strcpy(s2, "\\\\"); 443 strcpy(s2, "\\\\");
455 strcpy(s2, "\""); 456 strcpy(s2, "\"");
456 ctx->script_front = s2 + 1; 457 ctx->script_front = s2 + 1;
457 return r; 458 return r;
458 } 459 }
459 460
460 int uw_Basis_new_client_source(uw_context ctx, uw_Basis_string s) { 461 uw_Basis_int uw_Basis_new_client_source(uw_context ctx, uw_Basis_string s) {
461 size_t len; 462 int len;
462 463 size_t s_len = strlen(s);
463 uw_check_script(ctx, 8 + INTS_MAX); 464
465 uw_check_script(ctx, 12 + INTS_MAX + s_len);
464 sprintf(ctx->script_front, "var s%d=sc(%n", ctx->source_count, &len); 466 sprintf(ctx->script_front, "var s%d=sc(%n", ctx->source_count, &len);
465 ctx->script_front += len; 467 ctx->script_front += len;
466 uw_Basis_jsifyString_ws(ctx, s); 468 strcpy(ctx->script_front, s);
467 uw_write_script(ctx, ");"); 469 ctx->script_front += s_len;
470 strcpy(ctx->script_front, ");");
471 ctx->script_front += 2;
468 472
469 return ctx->source_count++; 473 return ctx->source_count++;
474 }
475
476 uw_unit uw_Basis_set_client_source(uw_context ctx, uw_Basis_int n, uw_Basis_string s) {
477 int len;
478 size_t s_len = strlen(s);
479
480 uw_check_script(ctx, 6 + INTS_MAX + s_len);
481 sprintf(ctx->script_front, "s%d.v=%n", (int)n, &len);
482 ctx->script_front += len;
483 strcpy(ctx->script_front, s);
484 ctx->script_front += s_len;
485 strcpy(ctx->script_front, ";");
486 ctx->script_front++;
487
488 return uw_unit_v;
470 } 489 }
471 490
472 static void uw_check(uw_context ctx, size_t extra) { 491 static void uw_check(uw_context ctx, size_t extra) {
473 size_t desired = ctx->page_front - ctx->page + extra, next; 492 size_t desired = ctx->page_front - ctx->page + extra, next;
474 char *new_page; 493 char *new_page;