Mercurial > urweb
comparison src/c/urweb.c @ 760:21f6d2e65685
Megaform test
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 30 Apr 2009 14:43:55 -0400 |
parents | 67cd8326f743 |
children | c125df6fabfc |
comparison
equal
deleted
inserted
replaced
759:67cd8326f743 | 760:21f6d2e65685 |
---|---|
589 else if (ctx->cur_container->kind == SUBFORM) | 589 else if (ctx->cur_container->kind == SUBFORM) |
590 return ctx->cur_container->data.subform.fields; | 590 return ctx->cur_container->data.subform.fields; |
591 else if (ctx->cur_container->kind == ENTRY) | 591 else if (ctx->cur_container->kind == ENTRY) |
592 return ctx->cur_container->data.entry.fields; | 592 return ctx->cur_container->data.entry.fields; |
593 else | 593 else |
594 uw_error(ctx, FATAL, "INP: Wrong kind"); | 594 uw_error(ctx, FATAL, "INP: Wrong kind (%d, %p)", ctx->cur_container->kind, ctx->cur_container); |
595 } | 595 } |
596 | 596 |
597 static void adjust_input(input *x, size_t offset) { | 597 static void adjust_pointer(input **ptr, input *old_start, input *new_start, size_t len) { |
598 if (*ptr != NULL && *ptr >= old_start && *ptr < old_start + len) | |
599 *ptr += new_start - old_start; | |
600 } | |
601 | |
602 static void adjust_input(input *x, input *old_start, input *new_start, size_t len) { | |
598 switch (x->kind) { | 603 switch (x->kind) { |
599 case SUBFORM: | 604 case SUBFORM: |
600 x->data.subform.fields += offset; | 605 adjust_pointer(&x->data.subform.fields, old_start, new_start, len); |
601 if (x->data.subform.parent != NULL) | 606 adjust_pointer(&x->data.subform.parent, old_start, new_start, len); |
602 x->data.subform.parent += offset; | |
603 break; | 607 break; |
604 case SUBFORMS: | 608 case SUBFORMS: |
605 if (x->data.subforms.entries != NULL) | 609 adjust_pointer(&x->data.subforms.entries, old_start, new_start, len); |
606 x->data.subforms.entries += offset; | 610 adjust_pointer(&x->data.subforms.parent, old_start, new_start, len); |
607 if (x->data.subforms.parent != NULL) | |
608 x->data.subforms.parent += offset; | |
609 break; | 611 break; |
610 case ENTRY: | 612 case ENTRY: |
611 x->data.entry.fields += offset; | 613 adjust_pointer(&x->data.entry.fields, old_start, new_start, len); |
612 if (x->data.entry.next != NULL) | 614 adjust_pointer(&x->data.entry.next, old_start, new_start, len); |
613 x->data.entry.next += offset; | 615 adjust_pointer(&x->data.entry.parent, old_start, new_start, len); |
614 if (x->data.entry.parent != NULL) | |
615 x->data.entry.parent += offset; | |
616 } | 616 } |
617 } | 617 } |
618 | 618 |
619 static input *check_input_space(uw_context ctx, size_t len) { | 619 static input *check_input_space(uw_context ctx, size_t len) { |
620 size_t i; | 620 size_t i; |
622 | 622 |
623 if (ctx->used_subinputs + len >= ctx->n_subinputs) { | 623 if (ctx->used_subinputs + len >= ctx->n_subinputs) { |
624 input *new_subinputs = realloc(ctx->subinputs, sizeof(input) * (ctx->used_subinputs + len)); | 624 input *new_subinputs = realloc(ctx->subinputs, sizeof(input) * (ctx->used_subinputs + len)); |
625 size_t offset = new_subinputs - ctx->subinputs; | 625 size_t offset = new_subinputs - ctx->subinputs; |
626 | 626 |
627 for (i = 0; i < ctx->used_subinputs; ++i) | 627 if (ctx->subinputs != new_subinputs) { |
628 adjust_input(&new_subinputs[i], offset); | 628 for (i = 0; i < ctx->used_subinputs; ++i) |
629 for (i = 0; i < uw_inputs_len; ++i) | 629 adjust_input(&new_subinputs[i], ctx->subinputs, new_subinputs, ctx->used_subinputs); |
630 adjust_input(&ctx->inputs[i], offset); | 630 for (i = 0; i < uw_inputs_len; ++i) |
631 | 631 adjust_input(&ctx->inputs[i], ctx->subinputs, new_subinputs, ctx->used_subinputs); |
632 if (ctx->cur_container >= ctx->subinputs && ctx->cur_container < ctx->subinputs + ctx->n_subinputs) | 632 |
633 ctx->cur_container += offset; | 633 adjust_pointer(&ctx->cur_container, ctx->subinputs, new_subinputs, ctx->used_subinputs); |
634 | 634 |
635 ctx->n_subinputs = ctx->used_subinputs + len; | 635 ctx->n_subinputs = ctx->used_subinputs + len; |
636 ctx->subinputs = new_subinputs; | 636 ctx->subinputs = new_subinputs; |
637 } | |
637 } | 638 } |
638 | 639 |
639 r = &ctx->subinputs[ctx->used_subinputs]; | 640 r = &ctx->subinputs[ctx->used_subinputs]; |
640 | 641 |
641 for (i = 0; i < len; ++i) | 642 for (i = 0; i < len; ++i) |
789 ctx->inputs[n].data.file = f; | 790 ctx->inputs[n].data.file = f; |
790 } | 791 } |
791 | 792 |
792 void *uw_malloc(uw_context ctx, size_t len); | 793 void *uw_malloc(uw_context ctx, size_t len); |
793 | 794 |
795 | |
796 static void parents(input *inp) { | |
797 printf("Stack: %p\n", inp); | |
798 while (inp) { | |
799 switch (inp->kind) { | |
800 case NORMAL: | |
801 printf("Normal(%p)\n", inp); | |
802 break; | |
803 case FIL: | |
804 printf("File(%p)\n", inp); | |
805 break; | |
806 case SUBFORM: | |
807 printf("Subform; fields = %p\n", inp->data.subform.fields); | |
808 inp = inp->data.subform.parent; | |
809 break; | |
810 case SUBFORMS: | |
811 printf("Subforms; entries = %p\n", inp->data.subforms.entries); | |
812 inp = inp->data.subforms.parent; | |
813 break; | |
814 case ENTRY: | |
815 printf("Entry; fields = %p; next = %p\n", inp->data.entry.fields, inp->data.entry.next); | |
816 inp = inp->data.entry.parent; | |
817 break; | |
818 default: | |
819 inp = NULL; | |
820 } | |
821 } | |
822 } | |
823 | |
794 uw_Basis_file uw_get_file_input(uw_context ctx, int n) { | 824 uw_Basis_file uw_get_file_input(uw_context ctx, int n) { |
795 if (n < 0) | 825 if (n < 0) |
796 uw_error(ctx, FATAL, "Negative file input index %d", n); | 826 uw_error(ctx, FATAL, "Negative file input index %d", n); |
797 if (n >= uw_inputs_len) | 827 if (n >= uw_inputs_len) |
798 uw_error(ctx, FATAL, "Out-of-bounds file input index %d", n); | 828 uw_error(ctx, FATAL, "Out-of-bounds file input index %d", n); |
836 uw_error(ctx, FATAL, "Tried to read a subforms form input as subform"); | 866 uw_error(ctx, FATAL, "Tried to read a subforms form input as subform"); |
837 case ENTRY: | 867 case ENTRY: |
838 uw_error(ctx, FATAL, "Tried to read an entry form input as subform"); | 868 uw_error(ctx, FATAL, "Tried to read an entry form input as subform"); |
839 case SUBFORM: | 869 case SUBFORM: |
840 INP(ctx)[n].data.subform.parent = ctx->cur_container; | 870 INP(ctx)[n].data.subform.parent = ctx->cur_container; |
841 ctx->cur_container = INP(ctx)[n].data.subform.fields; | 871 ctx->cur_container = &INP(ctx)[n]; |
842 return; | 872 return; |
843 default: | 873 default: |
844 uw_error(ctx, FATAL, "Impossible input kind"); | 874 uw_error(ctx, FATAL, "Impossible input kind"); |
845 } | 875 } |
846 } | 876 } |