comparison src/c/urweb.c @ 286:ffe5b01908ae

'show' type class; htmlification optimizations
author Adam Chlipala <adamc@hcoop.net>
date Sun, 07 Sep 2008 10:48:51 -0400
parents e89076c41c39
children 4260ad920c36
comparison
equal deleted inserted replaced
285:e89076c41c39 286:ffe5b01908ae
504 ctx->heap_front = lw_unurlifyString_to(ctx, ctx->heap_front, *s); 504 ctx->heap_front = lw_unurlifyString_to(ctx, ctx->heap_front, *s);
505 *s = new_s; 505 *s = new_s;
506 return r; 506 return r;
507 } 507 }
508 508
509
510 char *lw_Basis_htmlifyInt(lw_context ctx, lw_Basis_int n) {
511 int len;
512 char *r;
513
514 lw_check_heap(ctx, INTS_MAX);
515 r = ctx->heap_front;
516 sprintf(r, "%lld%n", n, &len);
517 ctx->heap_front += len+1;
518 return r;
519 }
520
521 void lw_Basis_htmlifyInt_w(lw_context ctx, lw_Basis_int n) {
522 int len;
523
524 lw_check(ctx, INTS_MAX);
525 sprintf(ctx->page_front, "%lld%n", n, &len);
526 ctx->page_front += len;
527 }
528
529 char *lw_Basis_htmlifyFloat(lw_context ctx, lw_Basis_float n) {
530 int len;
531 char *r;
532
533 lw_check_heap(ctx, FLOATS_MAX);
534 r = ctx->heap_front;
535 sprintf(r, "%g%n", n, &len);
536 ctx->heap_front += len+1;
537 return r;
538 }
539
540 void lw_Basis_htmlifyFloat_w(lw_context ctx, lw_Basis_float n) {
541 int len;
542
543 lw_check(ctx, FLOATS_MAX);
544 sprintf(ctx->page_front, "%g%n", n, &len);
545 ctx->page_front += len;
546 }
509 547
510 char *lw_Basis_htmlifyString(lw_context ctx, lw_Basis_string s) { 548 char *lw_Basis_htmlifyString(lw_context ctx, lw_Basis_string s) {
511 char *r, *s2; 549 char *r, *s2;
512 550
513 lw_check_heap(ctx, strlen(s) * 5 + 1); 551 lw_check_heap(ctx, strlen(s) * 5 + 1);
563 } 601 }
564 } 602 }
565 } 603 }
566 } 604 }
567 605
606 lw_Basis_string lw_Basis_htmlifyBool(lw_context ctx, lw_Basis_bool b) {
607 if (b == lw_Basis_False)
608 return "False";
609 else
610 return "True";
611 }
612
613 void lw_Basis_htmlifyBool_w(lw_context ctx, lw_Basis_bool b) {
614 if (b == lw_Basis_False) {
615 lw_check(ctx, 6);
616 strcpy(ctx->page_front, "False");
617 ctx->page_front += 5;
618 } else {
619 lw_check(ctx, 5);
620 strcpy(ctx->page_front, "True");
621 ctx->page_front += 4;
622 }
623 }
624
568 lw_Basis_string lw_Basis_strcat(lw_context ctx, lw_Basis_string s1, lw_Basis_string s2) { 625 lw_Basis_string lw_Basis_strcat(lw_context ctx, lw_Basis_string s1, lw_Basis_string s2) {
569 int len = strlen(s1) + strlen(s2) + 1; 626 int len = strlen(s1) + strlen(s2) + 1;
570 char *s; 627 char *s;
571 628
572 lw_check_heap(ctx, len); 629 lw_check_heap(ctx, len);