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 24 #include <tdom.h>
25 25 #include <tcldom.h>
26 26 #include <domxpath.h>
27 27 #include <schema.h>
28 28
29 29 #ifndef TDOM_NO_SCHEMA
30 30
31 -#include <inttypes.h>
31 +#include <stdint.h>
32 32 #include <fcntl.h>
33 33
34 34 #ifdef _MSC_VER
35 35 #include <io.h>
36 36 #else
37 37 #include <unistd.h>
38 38 #endif
................................................................................
500 500 }
501 501 if (pattern->flags & ELEMENTTYPE_DEF) {
502 502 fprintf (stderr, "\tElementtype '%s'\n", pattern->typeName);
503 503 }
504 504 /* Fall through. */
505 505 case SCHEMA_CTYPE_CHOICE:
506 506 case SCHEMA_CTYPE_INTERLEAVE:
507 - fprintf (stderr, "\t%d children\n", pattern->nc);
507 + fprintf (stderr, "\t%d childs\n", pattern->nc);
508 508 break;
509 509 case SCHEMA_CTYPE_ANY:
510 510 if (pattern->namespace) {
511 511 fprintf (stderr, "\tNamespace: '%s'\n",
512 512 pattern->namespace);
513 513 }
514 514 break;
................................................................................
904 904 savedCP = sdata->cp;
905 905 savedContenSize = sdata->contentSize;
906 906 sdata->cp = wrapperCP;
907 907 sdata->contentSize = CONTENT_ARRAY_SIZE_INIT;
908 908 }
909 909 }
910 910 if (quant == SCHEMA_CQUANT_NM) {
911 - int i, newChilds, thisquant;
912 - if (m == -1) {
913 - m = n + 1;
914 - newChilds = m;
915 - thisquant = SCHEMA_CQUANT_REP;
916 - } else {
917 - newChilds = (n >= m) ? n : m;
918 - thisquant = SCHEMA_CQUANT_OPT;
919 - }
911 + int i;
912 + int newChilds = (n >= m) ? n : m;
920 913 while (sdata->cp->nc + newChilds >= sdata->contentSize) {
921 914 sdata->cp->content =
922 915 REALLOC (sdata->cp->content,
923 916 2 * sdata->contentSize
924 917 * sizeof (SchemaCP*));
925 918 sdata->cp->quants =
926 919 REALLOC (sdata->cp->quants,
................................................................................
930 923 }
931 924 for (i = 0; i < n; i++) {
932 925 sdata->cp->content[sdata->cp->nc+i] = pattern;
933 926 sdata->cp->quants[sdata->cp->nc+i] = SCHEMA_CQUANT_ONE;
934 927 }
935 928 for (i = n; i < m; i++) {
936 929 sdata->cp->content[sdata->cp->nc+i] = pattern;
937 - sdata->cp->quants[sdata->cp->nc+i] = thisquant;
930 + sdata->cp->quants[sdata->cp->nc+i] = SCHEMA_CQUANT_OPT;
938 931 }
939 932 sdata->cp->nc = sdata->cp->nc + newChilds;
940 933 } else {
941 934 if (sdata->cp->nc == sdata->contentSize) {
942 935 sdata->cp->content =
943 936 REALLOC (sdata->cp->content,
944 937 2 * sdata->contentSize
................................................................................
2234 2227 -1 means a pattern or an interleave ended may end, look further at
2235 2228 parents next sibling.
2236 2229
2237 2230 0 means rewind with validation error.
2238 2231
2239 2232 1 means element content may end here.
2240 2233
2241 - 2 means recovering requested further error reporting about missing children
2234 + 2 means recovering requested further error reporting about missing childs
2242 2235 in the current element. To be able to answer a [info expected] on
2243 2236 the occasion of the next error, we update the stack in this case
2244 2237 and let tDOM_probeElementEnd restart checkElementEnd again with this
2245 2238 stack state.
2246 2239 */
2247 2240 static int checkElementEnd (
2248 2241 Tcl_Interp *interp,
................................................................................
5432 5425 return SCHEMA_CQUANT_ERROR;
5433 5426 }
5434 5427 if (*n < 0) {
5435 5428 SetResult ("Invalid quant specifier");
5436 5429 return SCHEMA_CQUANT_ERROR;
5437 5430 }
5438 5431 Tcl_ListObjIndex (interp, quantObj, 1, &thisObj);
5439 - if (Tcl_GetIntFromObj (interp, thisObj, m) == TCL_OK) {
5440 - if (*n > *m) {
5441 - SetResult ("Invalid quant specifier");
5442 - return SCHEMA_CQUANT_ERROR;
5443 - }
5444 - if (*n == 0 && *m == 1) {
5445 - return SCHEMA_CQUANT_OPT;
5446 - }
5447 - if (*n == 1 && *m == 1) {
5448 - return SCHEMA_CQUANT_ONE;
5449 - }
5450 - return SCHEMA_CQUANT_NM;
5451 - } else {
5452 - quantStr = Tcl_GetStringFromObj (thisObj, &len);
5453 - if (len == 1 && quantStr[0] == '*') {
5454 - if (*n == 0) {
5455 - return SCHEMA_CQUANT_REP;
5456 - }
5457 - *m = -1;
5458 - return SCHEMA_CQUANT_NM;
5459 - } else {
5460 - SetResult ("Invalid quant specifier");
5461 - return SCHEMA_CQUANT_ERROR;
5462 - }
5432 + if (Tcl_GetIntFromObj (interp, thisObj, m) != TCL_OK) {
5433 + SetResult ("Invalid quant specifier");
5434 + return SCHEMA_CQUANT_ERROR;
5463 5435 }
5436 + if (*n > *m) {
5437 + SetResult ("Invalid quant specifier");
5438 + return SCHEMA_CQUANT_ERROR;
5439 + }
5440 + if (*n == 0 && *m == 1) {
5441 + return SCHEMA_CQUANT_OPT;
5442 + }
5443 + if (*n == 1 && *m == 1) {
5444 + return SCHEMA_CQUANT_ONE;
5445 + }
5446 + return SCHEMA_CQUANT_NM;
5464 5447 }
5465 5448
5466 5449 /* Implements the schema definition command "any" */
5467 5450 static int
5468 5451 AnyPatternObjCmd (
5469 5452 ClientData clientData,
5470 5453 Tcl_Interp *interp,
................................................................................
8518 8501 SchemaConstraint *sc;
8519 8502 Tcl_HashEntry *h;
8520 8503
8521 8504 CHECK_TI
8522 8505 checkNrArgs (2,2,"Expected: <text type name>");
8523 8506 h = Tcl_FindHashEntry (&sdata->textDef, Tcl_GetString (objv[1]));
8524 8507 if (!h) {
8525 - SetResult3 ("Unknown text type \"", Tcl_GetString (objv[1]), "\"");
8508 + SetResult3 ("Unknown text type \"", Tcl_GetString (objv[2]), "\"");
8526 8509 return TCL_ERROR;
8527 8510 }
8528 8511 ADD_CONSTRAINT (sdata, sc)
8529 8512 sc->constraint = typeImpl;
8530 8513 sc->constraintData = Tcl_GetHashValue (h);
8531 8514 return TCL_OK;
8532 8515 }