comparison src/c/urweb.c @ 574:ac947e2f29ff

Trivial use of a source
author Adam Chlipala <adamc@hcoop.net>
date Sun, 21 Dec 2008 12:56:39 -0500
parents a152905c3c3b
children 3d56940120b1
comparison
equal deleted inserted replaced
572:57018f21cd5c 574:ac947e2f29ff
385 sprintf(r, "<script type=\"text/javascript\">%s</script>", ctx->script); 385 sprintf(r, "<script type=\"text/javascript\">%s</script>", ctx->script);
386 return r; 386 return r;
387 } 387 }
388 } 388 }
389 389
390 int uw_Basis_new_client_source(uw_context ctx, uw_unit u) { 390 uw_Basis_string uw_Basis_jsifyString(uw_context ctx, uw_Basis_string s) {
391 char *r, *s2;
392
393 uw_check_heap(ctx, strlen(s) * 4 + 2);
394
395 r = s2 = ctx->heap_front;
396 *s2++ = '"';
397
398 for (; *s; s++) {
399 char c = *s;
400
401 switch (c) {
402 case '"':
403 strcpy(s2, "\\\"");
404 s2 += 2;
405 break;
406 case '\\':
407 strcpy(s2, "\\\\");
408 s2 += 2;
409 break;
410 default:
411 if (isprint(c))
412 *s2++ = c;
413 else {
414 sprintf(s2, "\\%3o", c);
415 s2 += 4;
416 }
417 }
418 }
419
420 strcpy(s2, "\"");
421 ctx->heap_front = s2 + 1;
422 return r;
423 }
424
425 uw_Basis_string uw_Basis_jsifyString_ws(uw_context ctx, uw_Basis_string s) {
426 char *r, *s2;
427
428 uw_check_script(ctx, strlen(s) * 4 + 2);
429
430 r = s2 = ctx->script_front;
431 *s2++ = '"';
432
433 for (; *s; s++) {
434 char c = *s;
435
436 switch (c) {
437 case '"':
438 strcpy(s2, "\\\"");
439 s2 += 2;
440 break;
441 case '\\':
442 strcpy(s2, "\\\\");
443 s2 += 2;
444 break;
445 default:
446 if (isprint(c))
447 *s2++ = c;
448 else {
449 sprintf(s2, "\\%3o", c);
450 s2 += 4;
451 }
452 }
453 }
454
455 strcpy(s2, "\"");
456 ctx->script_front = s2 + 1;
457 return r;
458 }
459
460 int uw_Basis_new_client_source(uw_context ctx, uw_Basis_string s) {
391 size_t len; 461 size_t len;
392 462
393 uw_check_script(ctx, 8 + INTS_MAX); 463 uw_check_script(ctx, 8 + INTS_MAX);
394 sprintf(ctx->script_front, "var e%d=0\n%n", ctx->source_count, &len); 464 sprintf(ctx->script_front, "var s%d=sc(%n", ctx->source_count, &len);
395 ctx->script_front += len; 465 ctx->script_front += len;
466 uw_Basis_jsifyString_ws(ctx, s);
467 uw_write_script(ctx, ");");
396 468
397 return ctx->source_count++; 469 return ctx->source_count++;
398 } 470 }
399 471
400 static void uw_check(uw_context ctx, size_t extra) { 472 static void uw_check(uw_context ctx, size_t extra) {
1052 1124
1053 if (b == uw_Basis_False) 1125 if (b == uw_Basis_False)
1054 return (char *)&false; 1126 return (char *)&false;
1055 else 1127 else
1056 return (char *)&true; 1128 return (char *)&true;
1057 }
1058
1059 uw_Basis_string uw_Basis_jsifyString(uw_context ctx, uw_Basis_string s) {
1060 char *r, *s2;
1061
1062 uw_check_heap(ctx, strlen(s) * 4 + 2);
1063
1064 r = s2 = ctx->heap_front;
1065 *s2++ = '"';
1066
1067 for (; *s; s++) {
1068 char c = *s;
1069
1070 switch (c) {
1071 case '"':
1072 strcpy(s2, "\\\"");
1073 s2 += 2;
1074 break;
1075 case '\\':
1076 strcpy(s2, "\\\\");
1077 s2 += 2;
1078 break;
1079 default:
1080 if (isprint(c))
1081 *s2++ = c;
1082 else {
1083 sprintf(s2, "\\%3o", c);
1084 s2 += 4;
1085 }
1086 }
1087 }
1088
1089 strcpy(s2, "\"");
1090 ctx->heap_front = s2 + 1;
1091 return r;
1092 } 1129 }
1093 1130
1094 uw_Basis_string uw_Basis_intToString(uw_context ctx, uw_Basis_int n) { 1131 uw_Basis_string uw_Basis_intToString(uw_context ctx, uw_Basis_int n) {
1095 int len; 1132 int len;
1096 char *r; 1133 char *r;