Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Save work.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | wip
Files: files | file ages | folders
SHA3-256: aa6a2926065e80ec5d057d5398a928122b143f2cb2b224eb1cbd41ab0638d449
User & Date: rolf 2019-10-12 01:27:07
Context
2019-10-12
13:29
Save work. check-in: 8d9da46798 user: rolf tags: wip
01:27
Save work. check-in: aa6a292606 user: rolf tags: wip
2019-10-11
11:54
Merged from schema. check-in: 6165f6c203 user: rolf tags: wip
Changes

Changes to generic/schema.c.

553
554
555
556
557
558
559





560
561
562
563
564
565
566
...
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798




799
800
801
802
803
804

805

806
807
808
809
810
811
812
813

814







815
816



























817
818


819
820
821
822
823
824
825
...
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
....
2680
2681
2682
2683
2684
2685
2686

2687
2688
2689
2690
2691
2692
2693
    }
    FREE (sdata->quants);
    while (sdata->stack) {
        down = sdata->stack->down;
        FREE (sdata->stack);
        sdata->stack = down;
    }





    while (sdata->stackPool) {
        down = sdata->stackPool->down;
        FREE (sdata->stackPool);
        sdata->stackPool = down;
    }
    Tcl_DecrRefCount (sdata->evalStub[0]);
    Tcl_DecrRefCount (sdata->evalStub[1]);
................................................................................
static void
pushToStack (
    SchemaData *sdata,
    SchemaCP *pattern,
    int ac
    )
{
    SchemaValidationStack *stackElm, *se;

    DBG(fprintf(stderr, "push to Stack:\n");serializeCP(pattern));
    if (sdata->stackPool) {
        stackElm = sdata->stackPool;
        sdata->stackPool = stackElm->down;
    } else {
        stackElm = TMALLOC (SchemaValidationStack);
    }
    memset (stackElm, 0, sizeof (SchemaValidationStack));
    se = sdata->stack;
    if (se) se->activeChild = ac;
    stackElm->down = se;
    stackElm->pattern = pattern;
    if (pattern->type == SCHEMA_CTYPE_INTERLEAVE) {
        stackElm->interleaveState = MALLOC (sizeof (int) * pattern->nc);
        memset (stackElm->interleaveState, 0, sizeof (int) * pattern->nc);
    }
    sdata->stack = stackElm;
}

static void
repoolStackElement (
    SchemaData *sdata,
    SchemaValidationStack *se
    ) 
{




    se->down = sdata->stackPool;
    sdata->stackPool = se;
}

static void
popStack (

    SchemaData *sdata

    )
{
    SchemaValidationStack *se;
    DBG(fprintf(stderr, "pop from Stack:\n");serializeCP(sdata->stack->pattern));
    if (sdata->stack->interleaveState) {
        FREE (sdata->stack->interleaveState);
        sdata->stack->interleaveState = NULL;
    }

    se = sdata->stack->down;







    sdata->stack->down = sdata->stackPool;
    sdata->stackPool = sdata->stack;



























    sdata->stack = se;
}



static void
finalizeElement (
    SchemaData *sdata,
    int ac
    )
{
................................................................................
    const char *errType,
    int len,
    int popStack,
    int ac
    )
{
    Tcl_Obj *cmdPtr;
    int rc, savedac;

    if (!sdata->reportCmd) return 0;
    cmdPtr = Tcl_DuplicateObj (sdata->reportCmd);
    Tcl_IncrRefCount(cmdPtr);
    Tcl_ListObjAppendElement (interp, cmdPtr,
                              sdata->self);
    Tcl_ListObjAppendElement (
        interp, cmdPtr,
        Tcl_NewStringObj (errType, len)
        );
    sdata->currentEvals++;
    if (sdata->stack) {
        savedac = sdata->stack->activeChild;
        sdata->stack->activeChild = ac;
    }
    rc = Tcl_EvalObjEx (interp, cmdPtr,
                        TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
    if (sdata->stack) {
        sdata->stack->activeChild = savedac;
    }
    sdata->currentEvals--;
    Tcl_DecrRefCount (cmdPtr);
    if (rc != TCL_OK) {
        sdata->evalError = 1;
        return 0;
    }
    if (popStack) {
................................................................................
{
    Tcl_HashEntry *h;
    Tcl_HashSearch search;
    SchemaDocKey *dk;
    SchemaKeySpace *ks;
    
    while (sdata->stack) popStack (sdata);

    sdata->validationState = VALIDATION_READY;
    sdata->skipDeep = 0;
    sdata->evalError = 0;
    Tcl_DStringSetLength (sdata->cdata, 0);
    if (sdata->ids.numEntries) {
        Tcl_DeleteHashTable (&sdata->ids);
        Tcl_InitHashTable (&sdata->ids, TCL_STRING_KEYS);







>
>
>
>
>







 







|


|
|
<
<
<
<
<
|
<
<
<

|
|

|








>
>
>
>





<
>
|
>


|
<
<
<
<
|
>
|
>
>
>
>
>
>
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|

>
>







 







|











<
<
<
<


<
<
<







 







>







553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
...
770
771
772
773
774
775
776
777
778
779
780
781





782



783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804

805
806
807
808
809
810




811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
...
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918




919
920



921
922
923
924
925
926
927
....
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
    }
    FREE (sdata->quants);
    while (sdata->stack) {
        down = sdata->stack->down;
        FREE (sdata->stack);
        sdata->stack = down;
    }
    while (sdata->lastMatchse) {
        down = sdata->lastMatchse->down;
        FREE (sdata->lastMatchse);
        sdata->lastMatchse = down;
    }
    while (sdata->stackPool) {
        down = sdata->stackPool->down;
        FREE (sdata->stackPool);
        sdata->stackPool = down;
    }
    Tcl_DecrRefCount (sdata->evalStub[0]);
    Tcl_DecrRefCount (sdata->evalStub[1]);
................................................................................
static void
pushToStack (
    SchemaData *sdata,
    SchemaCP *pattern,
    int ac
    )
{
    SchemaValidationStack *se;

    DBG(fprintf(stderr, "push to Stack:\n");serializeCP(pattern));
    se = getStackElement (sdata, pattern);
    if (sdata->stack) sdata->stack->activeChild = ac;





    se->down = sdata->stack;



    if (pattern->type == SCHEMA_CTYPE_INTERLEAVE) {
        se->interleaveState = MALLOC (sizeof (int) * pattern->nc);
        memset (se->interleaveState, 0, sizeof (int) * pattern->nc);
    }
    sdata->stack = se;
}

static void
repoolStackElement (
    SchemaData *sdata,
    SchemaValidationStack *se
    ) 
{
    if (se->interleaveState) {
        FREE (se->interleaveState);
        se->interleaveState = NULL;
    }
    se->down = sdata->stackPool;
    sdata->stackPool = se;
}

static void

savelastMatchse (
    SchemaData *sdata,
    int add
    )
{
    SchemaValidationStack *se, *nextse;




    
    if (!add) {
        se = sdata->lastMatchse;
        while (se) {
            nextse = se->down;
            repoolStackElement (sdata, se);
            se = nextse;
        }
    }
    se = getStackElement (sdata, sdata->stack->pattern);
    se->activeChild = sdata->stack->activeChild;
    se->hasMatched = sdata->stack->hasMatched;
    se->down = NULL;
    if (se->pattern->type == SCHEMA_CTYPE_INTERLEAVE) {
        se->interleaveState = MALLOC (sizeof (int) * se->pattern->nc);
        memcpy (se->interleaveState, sdata->stack->interleaveState,
                se->pattern->nc);
    }
    if (sdata->lastMatchse && add) {
        nextse = sdata->lastMatchse;
        while (nextse->down) {
            nextse = nextse->down;
        }
        nextse->down = se;
    } else {
        sdata->lastMatchse = se;
    }
}

static void
popFromStack (
    SchemaData *sdata,
    SchemaValidationStack **stack
    )
{
    SchemaValidationStack *se;
    DBG(fprintf(stderr, "pop from Stack:\n");serializeCP(sdata->stack->pattern));
    se = (*stack)->down;
    repoolStackElement (sdata, *stack);
    *stack = se;
}

#define popStack(sdata) popFromStack (sdata, &sdata->stack)

static void
finalizeElement (
    SchemaData *sdata,
    int ac
    )
{
................................................................................
    const char *errType,
    int len,
    int popStack,
    int ac
    )
{
    Tcl_Obj *cmdPtr;
    int rc;

    if (!sdata->reportCmd) return 0;
    cmdPtr = Tcl_DuplicateObj (sdata->reportCmd);
    Tcl_IncrRefCount(cmdPtr);
    Tcl_ListObjAppendElement (interp, cmdPtr,
                              sdata->self);
    Tcl_ListObjAppendElement (
        interp, cmdPtr,
        Tcl_NewStringObj (errType, len)
        );
    sdata->currentEvals++;




    rc = Tcl_EvalObjEx (interp, cmdPtr,
                        TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);



    sdata->currentEvals--;
    Tcl_DecrRefCount (cmdPtr);
    if (rc != TCL_OK) {
        sdata->evalError = 1;
        return 0;
    }
    if (popStack) {
................................................................................
{
    Tcl_HashEntry *h;
    Tcl_HashSearch search;
    SchemaDocKey *dk;
    SchemaKeySpace *ks;
    
    while (sdata->stack) popStack (sdata);
    while (sdata->lastMatchse) popFromStack (sdata, &sdata->lastMatchse);
    sdata->validationState = VALIDATION_READY;
    sdata->skipDeep = 0;
    sdata->evalError = 0;
    Tcl_DStringSetLength (sdata->cdata, 0);
    if (sdata->ids.numEntries) {
        Tcl_DeleteHashTable (&sdata->ids);
        Tcl_InitHashTable (&sdata->ids, TCL_STRING_KEYS);

Changes to tests/schema.test.

5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111












































5112
5113
5114
5115
5116
5117

5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
    s event start something
    s event end
    lappend result {*}[lsort [s info nextexpected]]
    s delete
    set result
} {{<any> {}} {<any> http://foo.bar} b}

proc schema-17.13 {scmd} {
    global result
    lappend result {*}[lsort [$scmd info pastexpected]]
}
test schema-17.13 {info pastexpected} {
    set defs {
        {












































            group + {
                element c ?
                element a ?
                element b ?
                tcl schema-17.13
            }

            element d
        }
    }
    set result [list]
    foreach def $defs {
        tdom::schema s
        s defelement doc $def
        s event start doc
        puts [s info nextexpected]
        catch {s event start unknownElement}
        s delete
    }
    set result
} {a b c}

proc schema-18 {args} {
    lappend ::result {*}$args
}
test schema-18.1 {reportcmd} {
    tdom::schema s
    s define {







|






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




<

>








<




|







5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159

5160
5161
5162
5163
5164
5165
5166
5167
5168
5169

5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
    s event start something
    s event end
    lappend result {*}[lsort [s info nextexpected]]
    s delete
    set result
} {{<any> {}} {<any> http://foo.bar} b}

proc schema-17.13 {scmd args} {
    global result
    lappend result {*}[lsort [$scmd info pastexpected]]
}
test schema-17.13 {info pastexpected} {
    set defs {
        {
            element a
            element b ?
        }
        {
            element a ?
            element b
        }
        {
            element a ?
            element b ?
        }
    }
    set xmlinput {
        <doc/>
        <doc><a/></doc>
        <doc><b/></doc>
        <doc><a/><b/></doc>
        <doc><unknown/></doc>
        <doc><a/><unknown/></doc>
    }
    set result [list]
    set defnr 0
    foreach def $defs {
        tdom::schema s
        s defelement doc $def
        s reportcmd schema-17.13
        set xmlnr 0
        foreach xml $xmlinput {
            lappend result $defnr/$xmlnr: [s validate $xml errMsg]
            incr xmlnr
        }
        s delete
        incr defnr
    }
    set result
} {}

proc schema-17.14 {scmd} {
    global result
    lappend result {*}[lsort [$scmd info pastexpected]]
}
test schema-17.14 {info pastexpected} {
    set defs {
        {
            group + {
                element c ?
                element a ?
                element b ?

            }
            tcl schema-17.14
            element d
        }
    }
    set result [list]
    foreach def $defs {
        tdom::schema s
        s defelement doc $def
        s event start doc

        catch {s event start unknownElement}
        s delete
    }
    set result
} {a b c d}

proc schema-18 {args} {
    lappend ::result {*}$args
}
test schema-18.1 {reportcmd} {
    tdom::schema s
    s define {