comparison src/c/urweb.c @ 428:3ca00463de20

Make *_w function prototypes match header file
author adamc@hnf.impredicative.com
date Fri, 24 Oct 2008 19:59:17 -0400
parents 2a861b56969c
children 024478c34f4d
comparison
equal deleted inserted replaced
427:0eb7bb4872d0 428:3ca00463de20
138 if (ctx->cleanup_front >= ctx->cleanup_back) { 138 if (ctx->cleanup_front >= ctx->cleanup_back) {
139 int len = ctx->cleanup_back - ctx->cleanup, newLen; 139 int len = ctx->cleanup_back - ctx->cleanup, newLen;
140 if (len == 0) 140 if (len == 0)
141 newLen = 1; 141 newLen = 1;
142 else 142 else
143 newLen *= 2; 143 newLen = len * 2;
144 ctx->cleanup = realloc(ctx->cleanup, newLen); 144 ctx->cleanup = realloc(ctx->cleanup, newLen);
145 ctx->cleanup_front = ctx->cleanup + len; 145 ctx->cleanup_front = ctx->cleanup + len;
146 ctx->cleanup_back = ctx->cleanup + newLen; 146 ctx->cleanup_back = ctx->cleanup + newLen;
147 } 147 }
148 148
277 static void uw_check(uw_context ctx, size_t extra) { 277 static void uw_check(uw_context ctx, size_t extra) {
278 size_t desired = ctx->page_front - ctx->page + extra, next; 278 size_t desired = ctx->page_front - ctx->page + extra, next;
279 char *new_page; 279 char *new_page;
280 280
281 next = ctx->page_back - ctx->page; 281 next = ctx->page_back - ctx->page;
282 if (next == 0) 282 if (next < desired) {
283 next = 1; 283 if (next == 0)
284 for (; next < desired; next *= 2); 284 next = 1;
285 285 for (; next < desired; next *= 2);
286 new_page = realloc(ctx->page, next); 286
287 ctx->page_front = new_page + (ctx->page_front - ctx->page); 287 new_page = realloc(ctx->page, next);
288 ctx->page_back = new_page + next; 288 ctx->page_front = new_page + (ctx->page_front - ctx->page);
289 ctx->page = new_page; 289 ctx->page_back = new_page + next;
290 ctx->page = new_page;
291 }
290 } 292 }
291 293
292 static void uw_writec_unsafe(uw_context ctx, char c) { 294 static void uw_writec_unsafe(uw_context ctx, char c) {
293 *(ctx->page_front)++ = c; 295 *(ctx->page_front)++ = c;
294 } 296 }
367 369
368 sprintf(ctx->page_front, "%lld%n", n, &len); 370 sprintf(ctx->page_front, "%lld%n", n, &len);
369 ctx->page_front += len; 371 ctx->page_front += len;
370 } 372 }
371 373
372 void uw_Basis_attrifyInt_w(uw_context ctx, uw_Basis_int n) { 374 uw_unit uw_Basis_attrifyInt_w(uw_context ctx, uw_Basis_int n) {
373 uw_check(ctx, INTS_MAX); 375 uw_check(ctx, INTS_MAX);
374 uw_Basis_attrifyInt_w_unsafe(ctx, n); 376 uw_Basis_attrifyInt_w_unsafe(ctx, n);
375 } 377
376 378 return uw_unit_v;
377 void uw_Basis_attrifyFloat_w(uw_context ctx, uw_Basis_float n) { 379 }
380
381 uw_unit uw_Basis_attrifyFloat_w(uw_context ctx, uw_Basis_float n) {
378 int len; 382 int len;
379 383
380 uw_check(ctx, FLOATS_MAX); 384 uw_check(ctx, FLOATS_MAX);
381 sprintf(ctx->page_front, "%g%n", n, &len); 385 sprintf(ctx->page_front, "%g%n", n, &len);
382 ctx->page_front += len; 386 ctx->page_front += len;
383 } 387
384 388 return uw_unit_v;
385 void uw_Basis_attrifyString_w(uw_context ctx, uw_Basis_string s) { 389 }
390
391 uw_unit uw_Basis_attrifyString_w(uw_context ctx, uw_Basis_string s) {
386 uw_check(ctx, strlen(s) * 6); 392 uw_check(ctx, strlen(s) * 6);
387 393
388 for (; *s; s++) { 394 for (; *s; s++) {
389 char c = *s; 395 char c = *s;
390 396
398 uw_write_unsafe(ctx, "&#"); 404 uw_write_unsafe(ctx, "&#");
399 uw_Basis_attrifyInt_w_unsafe(ctx, c); 405 uw_Basis_attrifyInt_w_unsafe(ctx, c);
400 uw_writec_unsafe(ctx, ';'); 406 uw_writec_unsafe(ctx, ';');
401 } 407 }
402 } 408 }
409
410 return uw_unit_v;
403 } 411 }
404 412
405 413
406 char *uw_Basis_urlifyInt(uw_context ctx, uw_Basis_int n) { 414 char *uw_Basis_urlifyInt(uw_context ctx, uw_Basis_int n) {
407 int len; 415 int len;
460 468
461 sprintf(ctx->page_front, "%lld%n", n, &len); 469 sprintf(ctx->page_front, "%lld%n", n, &len);
462 ctx->page_front += len; 470 ctx->page_front += len;
463 } 471 }
464 472
465 void uw_Basis_urlifyInt_w(uw_context ctx, uw_Basis_int n) { 473 uw_unit uw_Basis_urlifyInt_w(uw_context ctx, uw_Basis_int n) {
466 uw_check(ctx, INTS_MAX); 474 uw_check(ctx, INTS_MAX);
467 uw_Basis_urlifyInt_w_unsafe(ctx, n); 475 uw_Basis_urlifyInt_w_unsafe(ctx, n);
468 } 476
469 477 return uw_unit_v;
470 void uw_Basis_urlifyFloat_w(uw_context ctx, uw_Basis_float n) { 478 }
479
480 uw_unit uw_Basis_urlifyFloat_w(uw_context ctx, uw_Basis_float n) {
471 int len; 481 int len;
472 482
473 uw_check(ctx, FLOATS_MAX); 483 uw_check(ctx, FLOATS_MAX);
474 sprintf(ctx->page_front, "%g%n", n, &len); 484 sprintf(ctx->page_front, "%g%n", n, &len);
475 ctx->page_front += len; 485 ctx->page_front += len;
476 } 486
477 487 return uw_unit_v;
478 void uw_Basis_urlifyString_w(uw_context ctx, uw_Basis_string s) { 488 }
489
490 uw_unit uw_Basis_urlifyString_w(uw_context ctx, uw_Basis_string s) {
479 uw_check(ctx, strlen(s) * 3); 491 uw_check(ctx, strlen(s) * 3);
480 492
481 for (; *s; s++) { 493 for (; *s; s++) {
482 char c = *s; 494 char c = *s;
483 495
488 else { 500 else {
489 sprintf(ctx->page_front, "%%%02X", c); 501 sprintf(ctx->page_front, "%%%02X", c);
490 ctx->page_front += 3; 502 ctx->page_front += 3;
491 } 503 }
492 } 504 }
493 } 505
494 506 return uw_unit_v;
495 void uw_Basis_urlifyBool_w(uw_context ctx, uw_Basis_bool b) { 507 }
508
509 uw_unit uw_Basis_urlifyBool_w(uw_context ctx, uw_Basis_bool b) {
496 if (b == uw_Basis_False) 510 if (b == uw_Basis_False)
497 uw_writec(ctx, '0'); 511 uw_writec(ctx, '0');
498 else 512 else
499 uw_writec(ctx, '1'); 513 uw_writec(ctx, '1');
514
515 return uw_unit_v;
500 } 516 }
501 517
502 518
503 static char *uw_unurlify_advance(char *s) { 519 static char *uw_unurlify_advance(char *s) {
504 char *new_s = strchr(s, '/'); 520 char *new_s = strchr(s, '/');
595 sprintf(r, "%lld%n", n, &len); 611 sprintf(r, "%lld%n", n, &len);
596 ctx->heap_front += len+1; 612 ctx->heap_front += len+1;
597 return r; 613 return r;
598 } 614 }
599 615
600 void uw_Basis_htmlifyInt_w(uw_context ctx, uw_Basis_int n) { 616 uw_unit uw_Basis_htmlifyInt_w(uw_context ctx, uw_Basis_int n) {
601 int len; 617 int len;
602 618
603 uw_check(ctx, INTS_MAX); 619 uw_check(ctx, INTS_MAX);
604 sprintf(ctx->page_front, "%lld%n", n, &len); 620 sprintf(ctx->page_front, "%lld%n", n, &len);
605 ctx->page_front += len; 621 ctx->page_front += len;
622
623 return uw_unit_v;
606 } 624 }
607 625
608 char *uw_Basis_htmlifyFloat(uw_context ctx, uw_Basis_float n) { 626 char *uw_Basis_htmlifyFloat(uw_context ctx, uw_Basis_float n) {
609 int len; 627 int len;
610 char *r; 628 char *r;
614 sprintf(r, "%g%n", n, &len); 632 sprintf(r, "%g%n", n, &len);
615 ctx->heap_front += len+1; 633 ctx->heap_front += len+1;
616 return r; 634 return r;
617 } 635 }
618 636
619 void uw_Basis_htmlifyFloat_w(uw_context ctx, uw_Basis_float n) { 637 uw_unit uw_Basis_htmlifyFloat_w(uw_context ctx, uw_Basis_float n) {
620 int len; 638 int len;
621 639
622 uw_check(ctx, FLOATS_MAX); 640 uw_check(ctx, FLOATS_MAX);
623 sprintf(ctx->page_front, "%g%n", n, &len); 641 sprintf(ctx->page_front, "%g%n", n, &len);
624 ctx->page_front += len; 642 ctx->page_front += len;
643
644 return uw_unit_v;
625 } 645 }
626 646
627 char *uw_Basis_htmlifyString(uw_context ctx, uw_Basis_string s) { 647 char *uw_Basis_htmlifyString(uw_context ctx, uw_Basis_string s) {
628 char *r, *s2; 648 char *r, *s2;
629 649
655 *s2++ = 0; 675 *s2++ = 0;
656 ctx->heap_front = s2; 676 ctx->heap_front = s2;
657 return r; 677 return r;
658 } 678 }
659 679
660 void uw_Basis_htmlifyString_w(uw_context ctx, uw_Basis_string s) { 680 uw_unit uw_Basis_htmlifyString_w(uw_context ctx, uw_Basis_string s) {
661 uw_check(ctx, strlen(s) * 6); 681 uw_check(ctx, strlen(s) * 6);
662 682
663 for (; *s; s++) { 683 for (; *s; s++) {
664 char c = *s; 684 char c = *s;
665 685
678 uw_Basis_attrifyInt_w_unsafe(ctx, c); 698 uw_Basis_attrifyInt_w_unsafe(ctx, c);
679 uw_writec_unsafe(ctx, ';'); 699 uw_writec_unsafe(ctx, ';');
680 } 700 }
681 } 701 }
682 } 702 }
703
704 return uw_unit_v;
683 } 705 }
684 706
685 uw_Basis_string uw_Basis_htmlifyBool(uw_context ctx, uw_Basis_bool b) { 707 uw_Basis_string uw_Basis_htmlifyBool(uw_context ctx, uw_Basis_bool b) {
686 if (b == uw_Basis_False) 708 if (b == uw_Basis_False)
687 return "False"; 709 return "False";
688 else 710 else
689 return "True"; 711 return "True";
690 } 712 }
691 713
692 void uw_Basis_htmlifyBool_w(uw_context ctx, uw_Basis_bool b) { 714 uw_unit uw_Basis_htmlifyBool_w(uw_context ctx, uw_Basis_bool b) {
693 if (b == uw_Basis_False) { 715 if (b == uw_Basis_False) {
694 uw_check(ctx, 6); 716 uw_check(ctx, 6);
695 strcpy(ctx->page_front, "False"); 717 strcpy(ctx->page_front, "False");
696 ctx->page_front += 5; 718 ctx->page_front += 5;
697 } else { 719 } else {
698 uw_check(ctx, 5); 720 uw_check(ctx, 5);
699 strcpy(ctx->page_front, "True"); 721 strcpy(ctx->page_front, "True");
700 ctx->page_front += 4; 722 ctx->page_front += 4;
701 } 723 }
724
725 return uw_unit_v;
702 } 726 }
703 727
704 uw_Basis_string uw_Basis_strcat(uw_context ctx, uw_Basis_string s1, uw_Basis_string s2) { 728 uw_Basis_string uw_Basis_strcat(uw_context ctx, uw_Basis_string s1, uw_Basis_string s2) {
705 int len = strlen(s1) + strlen(s2) + 1; 729 int len = strlen(s1) + strlen(s2) + 1;
706 char *s; 730 char *s;