tDOM

Check-in [2596c19c35]
Login
Bounty program for improvements to Tcl and certain Tcl packages.

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 | localkey
Files: files | file ages | folders
SHA3-256: 2596c19c35889c0d16dd9da7dc42371ca9217b991dad7bc6f3b6d59b1cde71d7
User & Date: rolf 2019-05-10 16:05:12
Context
2019-05-11
01:41
Save work. check-in: 3ce85f17a5 user: rolf tags: localkey
2019-05-10
16:05
Save work. check-in: 2596c19c35 user: rolf tags: localkey
13:41
Merge from schema. check-in: 4bf39f2571 user: rolf tags: localkey
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/schema.c.

368
369
370
371
372
373
374



























375
376
377
378
379
380
381
...
404
405
406
407
408
409
410

411
412
413
414
415
416
417
....
3340
3341
3342
3343
3344
3345
3346

3347
3348
3349



3350
3351
3352
3353
3354
3355

3356
3357
3358
3359
3360
3361
3362
....
3366
3367
3368
3369
3370
3371
3372
3373


3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387

3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398










3399







3400
3401
3402
3403
3404
3405
3406


3407
3408
3409
3410
3411
3412
3413
....
3420
3421
3422
3423
3424
3425
3426

3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437








3438

3439


3440
3441






3442
3443








3444
3445
3446
3447
3448
3449
3450
        se = se->down;
    }
    fprintf (stderr, "++++ Stack bottom\n");
}
)

/* DBG end */




























static void freeSchemaCP (
    SchemaCP *pattern
    )
{
    int i;
    SchemaConstraint *sc;
................................................................................
        FREE (pattern->quants);
        if (pattern->attrs) {
            for (i = 0; i < pattern->numAttr; i++) {
                FREE (pattern->attrs[i]);
            }
            FREE (pattern->attrs);
        }

        break;
    }
    FREE (pattern);
}

static SchemaData*
initSchemaData (
................................................................................
    }
    pattern->nc = objc;
    addToContent (sdata, pattern, SCHEMA_CQUANT_ONE, 0, 0);
    return TCL_OK;
}

extern void printAst (int depth, ast t);

static int
processSchemaXPath (
    Tcl_Interp *interp,



    ast t,
    int field,
    int toplevel
    )
{
    ast child;

    
    printAst (0, t);
    while (t) {
        switch (t->type) {
        case GetContextNode:
            if (!toplevel) {
                SetResult ("Not a reduced XPath expression.");
................................................................................
            continue;
        case CombineSets:
            if (!toplevel) {
                SetResult ("Not a reduced XPath expression.");
                return TCL_ERROR;
            }
            for (child = t->child; child != NULL; child = child->next) {
                if (processSchemaXPath (interp, child, field, 0) != TCL_OK) {


                    return TCL_ERROR;
                }
            }
            break;
        case AxisDescendant:
            if (!toplevel) {
                SetResult ("Not a reduced XPath expression.");
                return TCL_ERROR;
            }
            break;
        case IsElement:
        case IsFQElement:
        case IsNSElement:
        case AxisChild:

            break;
        case AxisAttribute:
        case IsNSAttr:
        case IsAttr:
            if (!field) {
                SetResult ("Attribute selection is only possible in reduced "
                           "XPath expression for field selectors.");
                return TCL_ERROR;
            }
            if (t->type == AxisAttribute) {
                break;










            }







            break;
        default:
            SetResult ("Not a reduced XPath expression.");
            return TCL_ERROR;
        }
        if (t->child) {
            if (processSchemaXPath (interp, t->child, field, 0) != TCL_OK) {


                return TCL_ERROR;
            }
        }
        toplevel = 0;
        t = t->next;
    }
    return TCL_OK;
................................................................................
    int objc,
    Tcl_Obj *const objv[]
    )
{
    SchemaData *sdata = GETASI;
    ast s, f;
    char *errMsg = NULL;


    CHECK_SI
    CHECK_TOPLEVEL
    checkNrArgs (3,3,"Expected: <selector> <fieldlist>");

    if (xpathParse (Tcl_GetString (objv[1]), NULL, XPATH_EXPR,
                    sdata->prefixns, NULL, &s, &errMsg) < 0) {
        SetResult3 ("Error in selector xpath: '", errMsg, "");
        FREE (errMsg);
        return TCL_ERROR;
    }








    if (processSchemaXPath (interp, s, 0, 1) != TCL_OK) {

        xpathFreeAst (s);


        return TCL_ERROR;
    }






    
    xpathFreeAst (s);








    return TCL_OK;
}

static int
integerImpl (
    Tcl_Interp *interp,
    void *constraintData,






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







 







>







 







>



>
>
>






>







 







|
>
>









|
<
<
<
<
>

<







|
|
>
>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>






|
>
>







 







>











>
>
>
>
>
>
>
>
|
>

>
>


>
>
>
>
>
>
|

>
>
>
>
>
>
>
>







368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
...
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
....
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
....
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418




3419
3420

3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
....
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
        se = se->down;
    }
    fprintf (stderr, "++++ Stack bottom\n");
}
)

/* DBG end */

static void freeKeyConstraints (
    KeyConstraint *kc
    )
{
    KeyConstraint *knext;
    KeyStep *step, *snext;

    while (kc) {
        knext = kc->next;
        if (kc->name) FREE (kc->name);
        step = kc->selectSteps;
        while (step) {
            snext = step->next;
            FREE (step);
            step = snext;
        }
        step = kc->fieldSteps;
        while (step) {
            snext = step->next;
            FREE (step);
            step = snext;
        }
        FREE (kc);
        kc = knext;
    }
}

static void freeSchemaCP (
    SchemaCP *pattern
    )
{
    int i;
    SchemaConstraint *sc;
................................................................................
        FREE (pattern->quants);
        if (pattern->attrs) {
            for (i = 0; i < pattern->numAttr; i++) {
                FREE (pattern->attrs[i]);
            }
            FREE (pattern->attrs);
        }
        freeKeyConstraints (pattern->localkeys);
        break;
    }
    FREE (pattern);
}

static SchemaData*
initSchemaData (
................................................................................
    }
    pattern->nc = objc;
    addToContent (sdata, pattern, SCHEMA_CQUANT_ONE, 0, 0);
    return TCL_OK;
}

extern void printAst (int depth, ast t);

static int
processSchemaXPath (
    Tcl_Interp *interp,
    KeyConstraint *kc,
    KeyStep *lastStep,
    StepType nextType,
    ast t,
    int field,
    int toplevel
    )
{
    ast child;
    KeyStep *step;
    
    printAst (0, t);
    while (t) {
        switch (t->type) {
        case GetContextNode:
            if (!toplevel) {
                SetResult ("Not a reduced XPath expression.");
................................................................................
            continue;
        case CombineSets:
            if (!toplevel) {
                SetResult ("Not a reduced XPath expression.");
                return TCL_ERROR;
            }
            for (child = t->child; child != NULL; child = child->next) {
                if (processSchemaXPath (interp, kc, NULL, SCHEMA_STEP_NONE,
                                        child, field, 0)
                    != TCL_OK) {
                    return TCL_ERROR;
                }
            }
            break;
        case AxisDescendant:
            if (!toplevel) {
                SetResult ("Not a reduced XPath expression.");
                return TCL_ERROR;
            }
            nextType = SCHEMA_STEP_DESCENDANT_ELEMENT;




            
            break;

        case IsNSAttr:
        case IsAttr:
            if (!field) {
                SetResult ("Attribute selection is only possible in reduced "
                           "XPath expression for field selectors.");
                return TCL_ERROR;
            }
            /* Fall through */
        case IsElement:
        case IsFQElement:
        case IsNSElement:
            step = TMALLOC (KeyStep);
            memset (step, 0, sizeof (KeyStep));
            step->type = nextType;
            if (lastStep) {
                lastStep->next = step;
            } else {
                if (field) kc->fieldSteps = step;
                else kc->selectSteps = step;
            }
            lastStep = step;
            break;
        case AxisChild:
            nextType = SCHEMA_STEP_ELEMENT;
            break;
        case AxisAttribute:
            nextType = SCHEMA_STEP_ATTRIBUTE;
            break;
        default:
            SetResult ("Not a reduced XPath expression.");
            return TCL_ERROR;
        }
        if (t->child) {
            if (processSchemaXPath (interp, kc, lastStep, nextType,
                                    t->child, field, 0)
                != TCL_OK) {
                return TCL_ERROR;
            }
        }
        toplevel = 0;
        t = t->next;
    }
    return TCL_OK;
................................................................................
    int objc,
    Tcl_Obj *const objv[]
    )
{
    SchemaData *sdata = GETASI;
    ast s, f;
    char *errMsg = NULL;
    KeyConstraint *kc, *kc1;

    CHECK_SI
    CHECK_TOPLEVEL
    checkNrArgs (3,3,"Expected: <selector> <fieldlist>");

    if (xpathParse (Tcl_GetString (objv[1]), NULL, XPATH_EXPR,
                    sdata->prefixns, NULL, &s, &errMsg) < 0) {
        SetResult3 ("Error in selector xpath: '", errMsg, "");
        FREE (errMsg);
        return TCL_ERROR;
    }
    if (xpathParse (Tcl_GetString (objv[2]), NULL, XPATH_EXPR,
                    sdata->prefixns, NULL, &f, &errMsg) < 0) {
        SetResult3 ("Error in field xpath: '", errMsg, "");
        FREE (errMsg);
        return TCL_ERROR;
    }
    kc = TMALLOC (KeyConstraint);
    memset (kc, 0, sizeof (KeyConstraint));
    if (processSchemaXPath (interp, kc, NULL, SCHEMA_STEP_NONE, s, 0, 1)
        != TCL_OK) {
        xpathFreeAst (s);
        xpathFreeAst (f);
        freeKeyConstraints (kc);
        return TCL_ERROR;
    }
    if (processSchemaXPath (interp, kc, NULL, SCHEMA_STEP_NONE, f, 1, 1)
        != TCL_OK) {
        xpathFreeAst (s);
        xpathFreeAst (f);
        freeKeyConstraints (kc);
        return TCL_ERROR;
    }
    xpathFreeAst (s);
    xpathFreeAst (f);
    if (sdata->cp->localkeys) {
        kc1 = sdata->cp->localkeys;
        while (kc1->next) kc1 = kc1->next;
        kc1->next = kc;
    } else {
        sdata->cp->localkeys = kc;
    }
    return TCL_OK;
}

static int
integerImpl (
    Tcl_Interp *interp,
    void *constraintData,

Changes to generic/schema.h.

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
..
68
69
70
71
72
73
74














75


76
77



78




79
80
81
82
83
84
85
86
87
..
88
89
90
91
92
93
94
95

96
97
98
99
100
101
102
typedef enum {
  SCHEMA_CQUANT_ONE,
  SCHEMA_CQUANT_OPT,
  SCHEMA_CQUANT_REP,
  SCHEMA_CQUANT_PLUS,
  SCHEMA_CQUANT_NM,
  SCHEMA_CQUANT_ERROR,
} SchemaQuant;

typedef int (*SchemaConstraintFunc) (Tcl_Interp *interp,
                                     void *constraintData, char *text);
typedef void (*SchemaConstraintFreeFunc) (void *constraintData);

typedef struct 
................................................................................
#define FORWARD_PATTERN_DEF     1
#define PLACEHOLDER_PATTERN_DEF 2
#define AMBIGUOUS_PATTERN       4
#define LOCAL_DEFINED_ELEMENT   8
#define CONSTRAINT_TEXT_CHILD  16
#define MIXED_CONTENT          32 















typedef struct keyConstraint {


    char           *name;
    char           *ns;



    struct keyConstraint *child;




    struct keyConstraint *next;
} keyConstraint;

typedef struct SchemaCP
{
    Schema_CP_Type    type;
    char             *namespace;
    char             *name;
    struct SchemaCP  *next;
................................................................................
    SchemaFlags       flags;
    struct SchemaCP **content;
    SchemaQuant      *quants;
    unsigned int      nc;
    SchemaAttr      **attrs;
    unsigned int      numAttr;
    unsigned int      numReqAttr;
    keyConstraint    *localkeys;

} SchemaCP;

typedef struct SchemaValidationStack
{
    SchemaCP *pattern;
    struct SchemaValidationStack *next;
    struct SchemaValidationStack *down;






|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
|
|
>
>
>
|
>
>
>
>
|
|







 







|
>







36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
..
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
...
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
typedef enum {
  SCHEMA_CQUANT_ONE,
  SCHEMA_CQUANT_OPT,
  SCHEMA_CQUANT_REP,
  SCHEMA_CQUANT_PLUS,
  SCHEMA_CQUANT_NM,
  SCHEMA_CQUANT_ERROR
} SchemaQuant;

typedef int (*SchemaConstraintFunc) (Tcl_Interp *interp,
                                     void *constraintData, char *text);
typedef void (*SchemaConstraintFreeFunc) (void *constraintData);

typedef struct 
................................................................................
#define FORWARD_PATTERN_DEF     1
#define PLACEHOLDER_PATTERN_DEF 2
#define AMBIGUOUS_PATTERN       4
#define LOCAL_DEFINED_ELEMENT   8
#define CONSTRAINT_TEXT_CHILD  16
#define MIXED_CONTENT          32 


typedef enum {
  SCHEMA_KEY_UNIQUE,
  SCHEMA_KEY_KEY,
  SCHEMA_KEY_KEYREF
} KeyType;

typedef enum {
  SCHEMA_STEP_NONE,
  SCHEMA_STEP_ELEMENT,
  SCHEMA_STEP_DESCENDANT_ELEMENT,
  SCHEMA_STEP_ATTRIBUTE,
} StepType;

typedef struct KeyStep 
{
    StepType type;
    char    *name;
    char    *ns;
    struct KeyStep *next;
} KeyStep;

typedef struct KeyConstraint {
    char    *name;
    KeyType  type;
    KeyStep *selectSteps;
    KeyStep *fieldSteps;
    struct KeyConstraint *next;
} KeyConstraint;

typedef struct SchemaCP
{
    Schema_CP_Type    type;
    char             *namespace;
    char             *name;
    struct SchemaCP  *next;
................................................................................
    SchemaFlags       flags;
    struct SchemaCP **content;
    SchemaQuant      *quants;
    unsigned int      nc;
    SchemaAttr      **attrs;
    unsigned int      numAttr;
    unsigned int      numReqAttr;
    KeyConstraint    *localkeys;
    int               nrKeys;
} SchemaCP;

typedef struct SchemaValidationStack
{
    SchemaCP *pattern;
    struct SchemaValidationStack *next;
    struct SchemaValidationStack *down;