Differences From Artifact [aa6cde837a]:

  • File generic/schema.c — part of check-in [049f31fab5] at 2021-02-03 22:53:46 on branch trunk — Added a way to express "at least n times and then unbound" in tdom schemas. (user: rolf size: 265698)

To Artifact [2aa1c1e8ce]:

  • File generic/schema.c — part of check-in [e3086ac247] at 2020-11-14 02:38:02 on branch trunk — Added text constaint command type. (user: rolf size: 265156) [more...]

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <tdom.h>
#include <tcldom.h>
#include <domxpath.h>
#include <schema.h>

#ifndef TDOM_NO_SCHEMA

#include <inttypes.h>
#include <fcntl.h>

#ifdef _MSC_VER
#include <io.h>
#else
#include <unistd.h>
#endif







|







24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <tdom.h>
#include <tcldom.h>
#include <domxpath.h>
#include <schema.h>

#ifndef TDOM_NO_SCHEMA

#include <stdint.h>
#include <fcntl.h>

#ifdef _MSC_VER
#include <io.h>
#else
#include <unistd.h>
#endif
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
        }
        if (pattern->flags & ELEMENTTYPE_DEF) {
            fprintf (stderr, "\tElementtype '%s'\n", pattern->typeName);
        }
        /* Fall through. */
    case SCHEMA_CTYPE_CHOICE:
    case SCHEMA_CTYPE_INTERLEAVE:
        fprintf (stderr, "\t%d children\n", pattern->nc);
        break;
    case SCHEMA_CTYPE_ANY:
        if (pattern->namespace) {
            fprintf (stderr, "\tNamespace: '%s'\n",
                     pattern->namespace);
        }
        break;







|







500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
        }
        if (pattern->flags & ELEMENTTYPE_DEF) {
            fprintf (stderr, "\tElementtype '%s'\n", pattern->typeName);
        }
        /* Fall through. */
    case SCHEMA_CTYPE_CHOICE:
    case SCHEMA_CTYPE_INTERLEAVE:
        fprintf (stderr, "\t%d childs\n", pattern->nc);
        break;
    case SCHEMA_CTYPE_ANY:
        if (pattern->namespace) {
            fprintf (stderr, "\tNamespace: '%s'\n",
                     pattern->namespace);
        }
        break;
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
            savedCP = sdata->cp;
            savedContenSize = sdata->contentSize;
            sdata->cp = wrapperCP;
            sdata->contentSize = CONTENT_ARRAY_SIZE_INIT;
        }
    }
    if (quant == SCHEMA_CQUANT_NM) {
        int i, newChilds, thisquant;
        if (m == -1) {
            m = n + 1;
            newChilds = m;
            thisquant = SCHEMA_CQUANT_REP;
        } else {
            newChilds = (n >= m) ? n : m;
            thisquant = SCHEMA_CQUANT_OPT;
        }
        while (sdata->cp->nc + newChilds >= sdata->contentSize) {
            sdata->cp->content =
                REALLOC (sdata->cp->content,
                         2 * sdata->contentSize
                         * sizeof (SchemaCP*));
            sdata->cp->quants =
                REALLOC (sdata->cp->quants,
                         2 * sdata->contentSize
                         * sizeof (SchemaQuant));
            sdata->contentSize *= 2;
        }
        for (i = 0; i < n; i++) {
            sdata->cp->content[sdata->cp->nc+i] = pattern;
            sdata->cp->quants[sdata->cp->nc+i] = SCHEMA_CQUANT_ONE;
        }
        for (i = n; i < m; i++) {
            sdata->cp->content[sdata->cp->nc+i] = pattern;
            sdata->cp->quants[sdata->cp->nc+i] = thisquant;
        }
        sdata->cp->nc = sdata->cp->nc + newChilds;
    } else {
        if (sdata->cp->nc == sdata->contentSize) {
            sdata->cp->content =
                REALLOC (sdata->cp->content,
                         2 * sdata->contentSize







|
<
<
<
<
<
|
<
<

















|







904
905
906
907
908
909
910
911





912


913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
            savedCP = sdata->cp;
            savedContenSize = sdata->contentSize;
            sdata->cp = wrapperCP;
            sdata->contentSize = CONTENT_ARRAY_SIZE_INIT;
        }
    }
    if (quant == SCHEMA_CQUANT_NM) {
        int i;





        int newChilds = (n >= m) ? n : m;


        while (sdata->cp->nc + newChilds >= sdata->contentSize) {
            sdata->cp->content =
                REALLOC (sdata->cp->content,
                         2 * sdata->contentSize
                         * sizeof (SchemaCP*));
            sdata->cp->quants =
                REALLOC (sdata->cp->quants,
                         2 * sdata->contentSize
                         * sizeof (SchemaQuant));
            sdata->contentSize *= 2;
        }
        for (i = 0; i < n; i++) {
            sdata->cp->content[sdata->cp->nc+i] = pattern;
            sdata->cp->quants[sdata->cp->nc+i] = SCHEMA_CQUANT_ONE;
        }
        for (i = n; i < m; i++) {
            sdata->cp->content[sdata->cp->nc+i] = pattern;
            sdata->cp->quants[sdata->cp->nc+i] = SCHEMA_CQUANT_OPT;
        }
        sdata->cp->nc = sdata->cp->nc + newChilds;
    } else {
        if (sdata->cp->nc == sdata->contentSize) {
            sdata->cp->content =
                REALLOC (sdata->cp->content,
                         2 * sdata->contentSize
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
   -1 means a pattern or an interleave ended may end, look further at
   parents next sibling.

   0 means rewind with validation error.

   1 means element content may end here.

   2 means recovering requested further error reporting about missing children
   in the current element. To be able to answer a [info expected] on
   the occasion of the next error, we update the stack in this case
   and let tDOM_probeElementEnd restart checkElementEnd again with this
   stack state.
*/
static int checkElementEnd (
    Tcl_Interp *interp,







|







2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
   -1 means a pattern or an interleave ended may end, look further at
   parents next sibling.

   0 means rewind with validation error.

   1 means element content may end here.

   2 means recovering requested further error reporting about missing childs
   in the current element. To be able to answer a [info expected] on
   the occasion of the next error, we update the stack in this case
   and let tDOM_probeElementEnd restart checkElementEnd again with this
   stack state.
*/
static int checkElementEnd (
    Tcl_Interp *interp,
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444

5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
        return SCHEMA_CQUANT_ERROR;
    }
    if (*n < 0) {
        SetResult ("Invalid quant specifier");
        return SCHEMA_CQUANT_ERROR;
    }
    Tcl_ListObjIndex (interp, quantObj, 1, &thisObj);
    if (Tcl_GetIntFromObj (interp, thisObj, m) == TCL_OK) {
        if (*n > *m) {
            SetResult ("Invalid quant specifier");
            return SCHEMA_CQUANT_ERROR;
        }
        if (*n == 0 && *m == 1) {

            return SCHEMA_CQUANT_OPT;
        }
        if (*n == 1 && *m == 1) {
            return SCHEMA_CQUANT_ONE;
        }
        return SCHEMA_CQUANT_NM;
    } else {
        quantStr = Tcl_GetStringFromObj (thisObj, &len);
        if (len == 1 && quantStr[0] == '*') {
            if (*n == 0) {
                return SCHEMA_CQUANT_REP;
            }
            *m = -1;
            return SCHEMA_CQUANT_NM;
        } else {
            SetResult ("Invalid quant specifier");
            return SCHEMA_CQUANT_ERROR;
        }
    }
}

/* Implements the schema definition command "any" */
static int
AnyPatternObjCmd (
    ClientData clientData,
    Tcl_Interp *interp,







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







5425
5426
5427
5428
5429
5430
5431
5432

5433
5434
5435
5436
5437
5438
5439
5440
5441
5442




5443
5444
5445

5446





5447
5448
5449
5450
5451
5452
5453
        return SCHEMA_CQUANT_ERROR;
    }
    if (*n < 0) {
        SetResult ("Invalid quant specifier");
        return SCHEMA_CQUANT_ERROR;
    }
    Tcl_ListObjIndex (interp, quantObj, 1, &thisObj);
    if (Tcl_GetIntFromObj (interp, thisObj, m) != TCL_OK) {

        SetResult ("Invalid quant specifier");
        return SCHEMA_CQUANT_ERROR;
    }
    if (*n > *m) {
        SetResult ("Invalid quant specifier");
        return SCHEMA_CQUANT_ERROR;
    }
    if (*n == 0 && *m == 1) {
        return SCHEMA_CQUANT_OPT;
    }




    if (*n == 1 && *m == 1) {
        return SCHEMA_CQUANT_ONE;
    }

    return SCHEMA_CQUANT_NM;





}

/* Implements the schema definition command "any" */
static int
AnyPatternObjCmd (
    ClientData clientData,
    Tcl_Interp *interp,
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
    SchemaConstraint *sc;
    Tcl_HashEntry *h;

    CHECK_TI
    checkNrArgs (2,2,"Expected: <text type name>");
    h = Tcl_FindHashEntry (&sdata->textDef, Tcl_GetString (objv[1]));
    if (!h) {
        SetResult3 ("Unknown text type \"", Tcl_GetString (objv[1]), "\"");
        return TCL_ERROR;
    }
    ADD_CONSTRAINT (sdata, sc)
    sc->constraint = typeImpl;
    sc->constraintData = Tcl_GetHashValue (h);
    return TCL_OK;
}







|







8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
    SchemaConstraint *sc;
    Tcl_HashEntry *h;

    CHECK_TI
    checkNrArgs (2,2,"Expected: <text type name>");
    h = Tcl_FindHashEntry (&sdata->textDef, Tcl_GetString (objv[1]));
    if (!h) {
        SetResult3 ("Unknown text type \"", Tcl_GetString (objv[2]), "\"");
        return TCL_ERROR;
    }
    ADD_CONSTRAINT (sdata, sc)
    sc->constraint = typeImpl;
    sc->constraintData = Tcl_GetHashValue (h);
    return TCL_OK;
}