errorCode copyGrammarRule(AllocList* memList, GrammarRule* src, GrammarRule* dest) { unsigned char b; Index j = 0; for(b = 0; b < 3; b++) { dest->part[b].count = src->part[b].count; dest->part[b].bits = src->part[b].bits; if(src->part[b].count != 0) { dest->part[b].prod = (Production*) memManagedAllocate(memList, sizeof(Production)*dest->part[b].count); if(dest->part[b].prod == NULL) return MEMORY_ALLOCATION_ERROR; for(j = 0;j < dest->part[b].count; j++) { dest->part[b].prod[j] = src->part[b].prod[j]; if(src->part[b].prod[j].nonTermID != GR_VOID_NON_TERMINAL) dest->part[b].prod[j].nonTermID = src->part[b].prod[j].nonTermID; } } else { dest->part[b].prod = NULL; } } return ERR_OK; }
errorCode allocateStringMemoryManaged(CharType** str, Index UCSchars, AllocList* memList) { (*str) = (CharType*) memManagedAllocate(memList, sizeof(CharType)*UCSchars); if((*str) == NULL) return EXIP_MEMORY_ALLOCATION_ERROR; return EXIP_OK; }
errorCode convertProtoGrammar(AllocList* memlist, ProtoGrammar* pg, EXIGrammar* exiGrammar) { Index ruleIter; Index prodIter; uint16_t attrCount; boolean hasEE; exiGrammar->props = 0; SET_SCHEMA_GR(exiGrammar->props); SET_CONTENT_INDEX(exiGrammar->props, pg->contentIndex); exiGrammar->count = pg->count; exiGrammar->rule = (GrammarRule*) memManagedAllocate(memlist, sizeof(GrammarRule)*(pg->count)); if(exiGrammar->rule == NULL) return EXIP_MEMORY_ALLOCATION_ERROR; for(ruleIter = 0; ruleIter < pg->count; ruleIter++) { attrCount = 0; hasEE = FALSE; exiGrammar->rule[ruleIter].production = (Production*) memManagedAllocate(memlist, sizeof(Production)*pg->rule[ruleIter].count); if(exiGrammar->rule[ruleIter].production == NULL) return EXIP_MEMORY_ALLOCATION_ERROR; exiGrammar->rule[ruleIter].pCount = pg->rule[ruleIter].count; exiGrammar->rule[ruleIter].meta = 0; for(prodIter = 0; prodIter < pg->rule[ruleIter].count; prodIter++) { if(GET_PROD_EXI_EVENT_CLASS(pg->rule[ruleIter].prod[prodIter].content) == EVENT_AT_CLASS) attrCount++; else if(GET_PROD_EXI_EVENT(pg->rule[ruleIter].prod[prodIter].content) == EVENT_EE) hasEE = TRUE; exiGrammar->rule[ruleIter].production[prodIter] = pg->rule[ruleIter].prod[prodIter]; } RULE_SET_AT_COUNT(exiGrammar->rule[ruleIter].meta, attrCount); if(hasEE) RULE_SET_CONTAIN_EE(exiGrammar->rule[ruleIter].meta); } return EXIP_OK; }
errorCode convertProtoGrammar(AllocList* memlist, ProtoGrammar* pg, EXIGrammar* exiGrammar) { Index ruleIter; Index prodIter; exiGrammar->props = 0; SET_SCHEMA(exiGrammar->props); exiGrammar->contentIndex = pg->contentIndex; exiGrammar->count = pg->count; // #DOCUMENT# one more rule slot is created as it can be needed for addUndeclaredProductions exiGrammar->rule = (GrammarRule*) memManagedAllocate(memlist, sizeof(GrammarRule)*(pg->count + 1)); if(exiGrammar->rule == NULL) return MEMORY_ALLOCATION_ERROR; for(ruleIter = 0; ruleIter < pg->count; ruleIter++) { /* Initialize Part 2 */ exiGrammar->rule[ruleIter].part[1].prod = NULL; exiGrammar->rule[ruleIter].part[1].count = 0; exiGrammar->rule[ruleIter].part[1].bits = 0; /* Initialize Part 3 */ exiGrammar->rule[ruleIter].part[2].prod = NULL; exiGrammar->rule[ruleIter].part[2].count = 0; exiGrammar->rule[ruleIter].part[2].bits = 0; /* Part 1 */ exiGrammar->rule[ruleIter].part[0].prod = (Production*) memManagedAllocate(memlist, sizeof(Production)*pg->rule[ruleIter].count); if(exiGrammar->rule[ruleIter].part[0].prod == NULL) return MEMORY_ALLOCATION_ERROR; exiGrammar->rule[ruleIter].part[0].count = pg->rule[ruleIter].count; exiGrammar->rule[ruleIter].part[0].bits = getBitsNumber(pg->rule[ruleIter].count - 1); for(prodIter = 0; prodIter < pg->rule[ruleIter].count; prodIter++) { exiGrammar->rule[ruleIter].part[0].prod[prodIter] = pg->rule[ruleIter].prod[prodIter]; } } return ERR_OK; }
errorCode cloneStringManaged(const String* src, String* newStr, AllocList* memList) { if(newStr == NULL) return EXIP_NULL_POINTER_REF; newStr->str = memManagedAllocate(memList, sizeof(CharType)*src->length); if(newStr->str == NULL) return EXIP_MEMORY_ALLOCATION_ERROR; newStr->length = src->length; memcpy(newStr->str, src->str, src->length); return EXIP_OK; }
END_TEST START_TEST (test_addValueEntry) { EXIStream testStrm; errorCode tmp_err_code = EXIP_UNEXPECTED_ERROR; String testStr = {"TEST-007", 8}; // IV: Initialize the stream { tmp_err_code = initAllocList(&(testStrm.memList)); testStrm.context.bitPointer = 0; testStrm.buffer.bufLen = 0; testStrm.buffer.bufContent = 0; tmp_err_code += createValueTable(&testStrm.valueTable); testStrm.schema = memManagedAllocate(&testStrm.memList, sizeof(EXIPSchema)); fail_unless (testStrm.schema != NULL, "Memory alloc error"); /* Create and initialize initial string table entries */ tmp_err_code += createDynArray(&testStrm.schema->uriTable.dynArray, sizeof(UriEntry), DEFAULT_URI_ENTRIES_NUMBER); tmp_err_code += createUriTableEntries(&testStrm.schema->uriTable, FALSE); } fail_unless (tmp_err_code == EXIP_OK, "initStream returns an error code %d", tmp_err_code); testStrm.gStack->currQNameID.uriId = 1; // http://www.w3.org/XML/1998/namespace testStrm.gStack->currQNameID.lnId = 2; // lang tmp_err_code = addValueEntry(&testStrm, testStr, testStrm.gStack->currQNameID); fail_unless (tmp_err_code == EXIP_OK, "addValueEntry returns an error code %d", tmp_err_code); #if VALUE_CROSSTABLE_USE fail_unless (testStrm.schema->uriTable.uri[testStrm.gStack->currQNameID.uriId].lnTable.ln[testStrm.gStack->currQNameID.lnId].vxTable != NULL, "addValueEntry does not create vxTable"); fail_unless (testStrm.schema->uriTable.uri[testStrm.gStack->currQNameID.uriId].lnTable.ln[testStrm.gStack->currQNameID.lnId].vxTable->count == 1, "addValueEntry does not create correct vxTable"); #endif fail_unless (testStrm.valueTable.count == 1, "addValueEntry does not create global value entry"); destroyDynArray(&testStrm.valueTable.dynArray); destroyDynArray(&testStrm.schema->uriTable.dynArray); freeAllocList(&testStrm.memList); }
errorCode asciiToString(const char* inStr, String* outStr, AllocList* memList, boolean clone) { outStr->length = strlen(inStr); if(outStr->length > 0) // If == 0 -> empty string { if(clone == FALSE) { outStr->str = (CharType*) inStr; return EXIP_OK; } else { outStr->str = (CharType*) memManagedAllocate(memList, sizeof(CharType)*(outStr->length)); if(outStr->str == NULL) return EXIP_MEMORY_ALLOCATION_ERROR; memcpy(outStr->str, inStr, outStr->length); return EXIP_OK; } } else outStr->str = NULL; return EXIP_OK; }
errorCode generateBuiltInTypesGrammars(EXIPSchema* schema) { unsigned int i; QNameID typeQnameID; Index typeId; EXIGrammar grammar; Index dynArrId; // URI id 3 -> http://www.w3.org/2001/XMLSchema typeQnameID.uriId = XML_SCHEMA_NAMESPACE_ID; grammar.count = 2; for(i = 0; i < schema->uriTable.uri[XML_SCHEMA_NAMESPACE_ID].lnTable.count; i++) { grammar.contentIndex = 0; typeQnameID.lnId = i; typeId = typeQnameID.lnId; grammar.props = 0; SET_SCHEMA(grammar.props); if((schema->simpleTypeTable.sType[typeId].facetPresenceMask & TYPE_FACET_NAMED_SUBTYPE_UNION) > 0) SET_NAMED_SUB_TYPE_OR_UNION(grammar.props); // One more rule slot for grammar augmentation when strict == FASLE grammar.rule = (GrammarRule*)memManagedAllocate(&schema->memList, sizeof(GrammarRule)*(grammar.count + 1)); if(grammar.rule == NULL) return MEMORY_ALLOCATION_ERROR; if(typeId == SIMPLE_TYPE_ANY_TYPE) { // <xs:anyType> - The base complex type; complex ur-type grammar.contentIndex = 1; /* Initialize first rule Part 2 */ grammar.rule[0].part[1].prod = NULL; grammar.rule[0].part[1].count = 0; grammar.rule[0].part[1].bits = 0; /* Initialize first rule Part 3 */ grammar.rule[0].part[2].prod = NULL; grammar.rule[0].part[2].count = 0; grammar.rule[0].part[2].bits = 0; /* Initialize second rule Part 2 */ grammar.rule[1].part[1].prod = NULL; grammar.rule[1].part[1].count = 0; grammar.rule[1].part[1].bits = 0; /* Initialize second rule Part 3 */ grammar.rule[1].part[2].prod = NULL; grammar.rule[1].part[2].count = 0; grammar.rule[1].part[2].bits = 0; grammar.rule[0].part[0].prod = memManagedAllocate(&schema->memList, sizeof(Production)*4); if(grammar.rule[0].part[0].prod == NULL) return MEMORY_ALLOCATION_ERROR; grammar.rule[0].part[0].prod[3].eventType = EVENT_AT_ALL; grammar.rule[0].part[0].prod[3].typeId = INDEX_MAX; grammar.rule[0].part[0].prod[3].nonTermID = 0; grammar.rule[0].part[0].prod[3].qnameId.uriId = URI_MAX; grammar.rule[0].part[0].prod[3].qnameId.lnId = LN_MAX; grammar.rule[0].part[0].prod[2].eventType = EVENT_SE_ALL; grammar.rule[0].part[0].prod[2].typeId = INDEX_MAX; grammar.rule[0].part[0].prod[2].nonTermID = 1; grammar.rule[0].part[0].prod[2].qnameId.uriId = URI_MAX; grammar.rule[0].part[0].prod[2].qnameId.lnId = LN_MAX; grammar.rule[0].part[0].prod[1].eventType = EVENT_EE; grammar.rule[0].part[0].prod[1].typeId = INDEX_MAX; grammar.rule[0].part[0].prod[1].nonTermID = GR_VOID_NON_TERMINAL; grammar.rule[0].part[0].prod[1].qnameId.uriId = URI_MAX; grammar.rule[0].part[0].prod[1].qnameId.lnId = LN_MAX; grammar.rule[0].part[0].prod[0].eventType = EVENT_CH; grammar.rule[0].part[0].prod[0].typeId = INDEX_MAX; grammar.rule[0].part[0].prod[0].nonTermID = 1; grammar.rule[0].part[0].prod[0].qnameId.uriId = URI_MAX; grammar.rule[0].part[0].prod[0].qnameId.lnId = LN_MAX; grammar.rule[0].part[0].count = 4; grammar.rule[0].part[0].bits = 2; grammar.rule[1].part[0].prod = memManagedAllocate(&schema->memList, sizeof(Production)*3); if(grammar.rule[1].part[0].prod == NULL) return MEMORY_ALLOCATION_ERROR; grammar.rule[1].part[0].prod[2].eventType = EVENT_SE_ALL; grammar.rule[1].part[0].prod[2].typeId = INDEX_MAX; grammar.rule[1].part[0].prod[2].nonTermID = 1; grammar.rule[1].part[0].prod[2].qnameId.uriId = URI_MAX; grammar.rule[1].part[0].prod[2].qnameId.lnId = LN_MAX; grammar.rule[1].part[0].prod[1].eventType = EVENT_EE; grammar.rule[1].part[0].prod[1].typeId = INDEX_MAX; grammar.rule[1].part[0].prod[1].nonTermID = GR_VOID_NON_TERMINAL; grammar.rule[1].part[0].prod[1].qnameId.uriId = URI_MAX; grammar.rule[1].part[0].prod[1].qnameId.lnId = LN_MAX; grammar.rule[1].part[0].prod[0].eventType = EVENT_CH; grammar.rule[1].part[0].prod[0].typeId = INDEX_MAX; grammar.rule[1].part[0].prod[0].nonTermID = 1; grammar.rule[1].part[0].prod[0].qnameId.uriId = URI_MAX; grammar.rule[1].part[0].prod[0].qnameId.lnId = LN_MAX; grammar.rule[1].part[0].count = 3; grammar.rule[1].part[0].bits = 2; } else // a regular simple type { /* Initialize first rule Part 2 */ grammar.rule[0].part[1].prod = NULL; grammar.rule[0].part[1].count = 0; grammar.rule[0].part[1].bits = 0; /* Initialize first rule Part 3 */ grammar.rule[0].part[2].prod = NULL; grammar.rule[0].part[2].count = 0; grammar.rule[0].part[2].bits = 0; /* Initialize second rule Part 2 */ grammar.rule[1].part[1].prod = NULL; grammar.rule[1].part[1].count = 0; grammar.rule[1].part[1].bits = 0; /* Initialize second rule Part 3 */ grammar.rule[1].part[2].prod = NULL; grammar.rule[1].part[2].count = 0; grammar.rule[1].part[2].bits = 0; grammar.rule[0].part[0].prod = memManagedAllocate(&schema->memList, sizeof(Production)); if(grammar.rule[0].part[0].prod == NULL) return MEMORY_ALLOCATION_ERROR; grammar.rule[0].part[0].prod[0].eventType = EVENT_CH; grammar.rule[0].part[0].prod[0].typeId = typeId; grammar.rule[0].part[0].prod[0].nonTermID = 1; grammar.rule[0].part[0].prod[0].qnameId.uriId = URI_MAX; grammar.rule[0].part[0].prod[0].qnameId.lnId = LN_MAX; grammar.rule[0].part[0].count = 1; grammar.rule[0].part[0].bits = 0; grammar.rule[1].part[0].prod = memManagedAllocate(&schema->memList, sizeof(Production)); if(grammar.rule[1].part[0].prod == NULL) return MEMORY_ALLOCATION_ERROR; grammar.rule[1].part[0].prod[0].eventType = EVENT_EE; grammar.rule[1].part[0].prod[0].typeId = INDEX_MAX; grammar.rule[1].part[0].prod[0].nonTermID = GR_VOID_NON_TERMINAL; grammar.rule[1].part[0].prod[0].qnameId.uriId = URI_MAX; grammar.rule[1].part[0].prod[0].qnameId.lnId = LN_MAX; grammar.rule[1].part[0].count = 1; grammar.rule[1].part[0].bits = 0; } /** Add the grammar to the schema grammar table */ addDynEntry(&schema->grammarTable.dynArray, &grammar, &dynArrId); schema->uriTable.uri[3].lnTable.ln[i].typeGrammar = dynArrId; } return ERR_OK; }
errorCode parseHeader(Parser* parser) { errorCode tmp_err_code = UNEXPECTED_ERROR; tmp_err_code = decodeHeader(&parser->strm); if(tmp_err_code != ERR_OK) return tmp_err_code; parser->strm.gStack = NULL; if(parser->strm.schema != NULL) { /* Schema enabled mode*/ tmp_err_code = addUndeclaredProductionsToAll(&parser->strm.memList, parser->strm.schema, &parser->strm.header.opts); if(tmp_err_code != ERR_OK) return tmp_err_code; if(WITH_FRAGMENT(parser->strm.header.opts.enumOpt)) { /* Fragment document grammar */ // TODO: create a Schema-informed Fragment Grammar from the EXIP schema object return NOT_IMPLEMENTED_YET; } else { tmp_err_code = augmentDocGrammar(&parser->strm.memList, parser->strm.header.opts.preserve, &parser->strm.schema->docGrammar); if(tmp_err_code != ERR_OK) return tmp_err_code; } } else { parser->strm.schema = memManagedAllocate(&parser->strm.memList, sizeof(EXIPSchema)); if(parser->strm.schema == NULL) return MEMORY_ALLOCATION_ERROR; tmp_err_code = initSchema(parser->strm.schema, INIT_SCHEMA_SCHEMA_LESS_MODE); if(tmp_err_code != ERR_OK) return tmp_err_code; if(WITH_FRAGMENT(parser->strm.header.opts.enumOpt)) { tmp_err_code = createFragmentGrammar(parser->strm.schema, NULL, 0); if(tmp_err_code != ERR_OK) return tmp_err_code; tmp_err_code = augmentFragGrammar(&parser->strm.memList, parser->strm.header.opts.preserve, &parser->strm.schema->docGrammar); if(tmp_err_code != ERR_OK) return tmp_err_code; } else { tmp_err_code = createDocGrammar(parser->strm.schema, NULL, 0); if(tmp_err_code != ERR_OK) return tmp_err_code; tmp_err_code = augmentDocGrammar(&parser->strm.memList, parser->strm.header.opts.preserve, &parser->strm.schema->docGrammar); if(tmp_err_code != ERR_OK) return tmp_err_code; } } tmp_err_code = pushGrammar(&parser->strm.gStack, &parser->strm.schema->docGrammar); if(tmp_err_code != ERR_OK) return tmp_err_code; if(parser->strm.header.opts.valuePartitionCapacity > 0) { tmp_err_code = createValueTable(&parser->strm.valueTable); if(tmp_err_code != ERR_OK) return tmp_err_code; } return ERR_OK; }
errorCode getEmptyTypeGrammar(EXIStream* strm, EXIGrammar* src, EXIGrammar** dest) { SmallIndex i; Index p; Index destProdIndx, partNum; *dest = memManagedAllocate(&strm->memList, sizeof(EXIGrammar)); if(*dest == NULL) return MEMORY_ALLOCATION_ERROR; (*dest)->contentIndex = src->contentIndex; (*dest)->count = src->contentIndex; (*dest)->props = src->props; (*dest)->rule = memManagedAllocate(&strm->memList, sizeof(GrammarRule)*((*dest)->count)); if((*dest)->rule == NULL) return MEMORY_ALLOCATION_ERROR; if(WITH_STRICT(strm->header.opts.enumOpt)) { for(i = 0; i < (*dest)->count - 1; i++) { for(partNum = 0; partNum < 3; partNum++) { // Copy all productions in the rules less than contentIndex i.e. (*dest)->count - 1 // except the AT(xsi:type) and AT(xsi:nil) (*dest)->rule[i].part[partNum].prod = memManagedAllocate(&strm->memList, sizeof(Production)*(src->rule[i].part[partNum].count)); if((*dest)->rule[i].part[partNum].prod == NULL) return MEMORY_ALLOCATION_ERROR; destProdIndx = 0; for(p = 0; p < src->rule[i].part[partNum].count; p++) { if(src->rule[i].part[partNum].prod[p].qnameId.uriId == XML_SCHEMA_INSTANCE_ID && (src->rule[i].part[partNum].prod[p].qnameId.lnId == XML_SCHEMA_INSTANCE_NIL_ID || src->rule[i].part[partNum].prod[p].qnameId.lnId == XML_SCHEMA_INSTANCE_TYPE_ID)) { // In case of AT(xsi:type) and AT(xsi:nil) productions, exclude them continue; } else { (*dest)->rule[i].part[partNum].prod[destProdIndx] = src->rule[i].part[partNum].prod[p]; destProdIndx++; } } (*dest)->rule[i].part[partNum].count = destProdIndx; (*dest)->rule[i].part[partNum].bits = getBitsNumber(destProdIndx - 1); } } /* The last rule is an empty rule with a single EE production */ (*dest)->rule[(*dest)->count - 1].part[0].prod = static_prod_empty_part0; (*dest)->rule[(*dest)->count - 1].part[0].bits = 0; (*dest)->rule[(*dest)->count - 1].part[0].count = 1; (*dest)->rule[(*dest)->count - 1].part[1].prod = NULL; (*dest)->rule[(*dest)->count - 1].part[1].bits = 0; (*dest)->rule[(*dest)->count - 1].part[1].count = 0; (*dest)->rule[(*dest)->count - 1].part[2].prod = NULL; (*dest)->rule[(*dest)->count - 1].part[2].bits = 0; (*dest)->rule[(*dest)->count - 1].part[2].count = 0; } else { // STRICT FALSE mode for(i = 0; i < (*dest)->count - 1; i++) { for(partNum = 0; partNum < 3; partNum++) { // Copy all productions in the rules less than contentIndex i.e. (*dest)->count - 1 // while taking into account that we do not need the Content2 index added during augmentation (*dest)->rule[i].part[partNum].prod = memManagedAllocate(&strm->memList, sizeof(Production)*(src->rule[i].part[partNum].count)); if((*dest)->rule[i].part[partNum].prod == NULL) return MEMORY_ALLOCATION_ERROR; destProdIndx = 0; for(p = 0; p < src->rule[i].part[partNum].count; p++) { if(src->rule[i].part[partNum].prod[p].eventType == EVENT_AT_ALL || src->rule[i].part[partNum].prod[p].eventType == EVENT_AT_QNAME || src->rule[i].part[partNum].prod[p].eventType == EVENT_AT_URI || src->rule[i].part[partNum].prod[p].eventType == EVENT_EE || (partNum > 0 && (src->rule[i].part[partNum].prod[p].eventType == EVENT_NS || src->rule[i].part[partNum].prod[p].eventType == EVENT_SC) ) ) { (*dest)->rule[i].part[partNum].prod[destProdIndx] = src->rule[i].part[partNum].prod[p]; destProdIndx++; } else if(partNum > 0 && (src->rule[i].part[partNum].prod[p].eventType == EVENT_SE_ALL || src->rule[i].part[partNum].prod[p].eventType == EVENT_CH || src->rule[i].part[partNum].prod[p].eventType == EVENT_ER || src->rule[i].part[partNum].prod[p].eventType == EVENT_CM || src->rule[i].part[partNum].prod[p].eventType == EVENT_PI)) { (*dest)->rule[i].part[partNum].prod[destProdIndx] = src->rule[i].part[partNum].prod[p]; (*dest)->rule[i].part[partNum].prod[destProdIndx].nonTermID = (*dest)->count - 1; destProdIndx++; } } (*dest)->rule[i].part[partNum].count = destProdIndx; } (*dest)->rule[i].part[0].bits = getBitsNumber((*dest)->rule[i].part[0].count - 1 + ((*dest)->rule[i].part[1].count > 0)); (*dest)->rule[i].part[1].bits = getBitsNumber((*dest)->rule[i].part[1].count - 1 + ((*dest)->rule[i].part[2].count > 0)); (*dest)->rule[i].part[2].bits = getBitsNumber((*dest)->rule[i].part[2].count - 1); } /* The last rule is: * * NT-contentIndex-1 : * EE 0 * SE (*) NT-contentIndex-1 1.0 * CH [untyped value] NT-contentIndex-1 1.1 * ER NT-contentIndex-1 1.2 * CM NT-contentIndex-1 1.3.0 * PI NT-contentIndex-1 1.3.1 * */ /* Part 1 */ (*dest)->rule[(*dest)->count - 1].part[0].prod = static_prod_empty_part0; (*dest)->rule[(*dest)->count - 1].part[0].bits = 1; (*dest)->rule[(*dest)->count - 1].part[0].count = 1; { /* Part 2 and 3 */ int part2count = 2; int part3count = 0; if(IS_PRESENT(strm->header.opts.preserve, PRESERVE_DTD)) part2count++; if(IS_PRESENT(strm->header.opts.preserve, PRESERVE_COMMENTS)) part3count++; if(IS_PRESENT(strm->header.opts.preserve, PRESERVE_PIS)) part3count++; (*dest)->rule[(*dest)->count - 1].part[1].prod = memManagedAllocate(&strm->memList, sizeof(Production)*part2count); if((*dest)->rule[(*dest)->count - 1].part[1].prod == NULL) return MEMORY_ALLOCATION_ERROR; (*dest)->rule[(*dest)->count - 1].part[1].prod[part2count-1].eventType = EVENT_SE_ALL; (*dest)->rule[(*dest)->count - 1].part[1].prod[part2count-1].nonTermID = (*dest)->count - 1; (*dest)->rule[(*dest)->count - 1].part[1].prod[part2count-1].typeId = INDEX_MAX; (*dest)->rule[(*dest)->count - 1].part[1].prod[part2count-2].eventType = EVENT_CH; (*dest)->rule[(*dest)->count - 1].part[1].prod[part2count-2].nonTermID = (*dest)->count - 1; (*dest)->rule[(*dest)->count - 1].part[1].prod[part2count-2].typeId = INDEX_MAX; if(IS_PRESENT(strm->header.opts.preserve, PRESERVE_DTD)) { (*dest)->rule[(*dest)->count - 1].part[1].prod[0].eventType = EVENT_ER; (*dest)->rule[(*dest)->count - 1].part[1].prod[0].nonTermID = (*dest)->count - 1; (*dest)->rule[(*dest)->count - 1].part[1].prod[0].typeId = INDEX_MAX; } (*dest)->rule[(*dest)->count - 1].part[1].bits = getBitsNumber(part2count - 1 + (part3count > 0)); (*dest)->rule[(*dest)->count - 1].part[1].count = part2count; if(part3count > 0) { (*dest)->rule[(*dest)->count - 1].part[2].prod = memManagedAllocate(&strm->memList, sizeof(Production)*part3count); if((*dest)->rule[(*dest)->count - 1].part[2].prod == NULL) return MEMORY_ALLOCATION_ERROR; if(IS_PRESENT(strm->header.opts.preserve, PRESERVE_COMMENTS)) { (*dest)->rule[(*dest)->count - 1].part[2].prod[part3count - 1].eventType = EVENT_CM; (*dest)->rule[(*dest)->count - 1].part[2].prod[part3count - 1].nonTermID = (*dest)->count - 1; (*dest)->rule[(*dest)->count - 1].part[2].prod[part3count - 1].typeId = INDEX_MAX; } if(IS_PRESENT(strm->header.opts.preserve, PRESERVE_PIS)) { (*dest)->rule[(*dest)->count - 1].part[2].prod[0].eventType = EVENT_PI; (*dest)->rule[(*dest)->count - 1].part[2].prod[0].nonTermID = (*dest)->count - 1; (*dest)->rule[(*dest)->count - 1].part[2].prod[0].typeId = INDEX_MAX; } (*dest)->rule[(*dest)->count - 1].part[2].bits = part3count > 1; (*dest)->rule[(*dest)->count - 1].part[2].count = part3count; } else { (*dest)->rule[(*dest)->count - 1].part[2].prod = NULL; (*dest)->rule[(*dest)->count - 1].part[2].bits = 0; (*dest)->rule[(*dest)->count - 1].part[2].count = 0; } } } #if DEBUG_GRAMMAR == ON { unsigned int r; DEBUG_MSG(INFO, DEBUG_GRAMMAR, (">Empty grammar:\n")); for(r = 0; r < (*dest)->count; r++) { if(printGrammarRule(r, &(*dest)->rule[r], strm->schema) != ERR_OK) DEBUG_MSG(INFO, DEBUG_GRAMMAR, (">Error printing grammar rule\n")); } } #endif return ERR_OK; }
errorCode addValueEntry(EXIStream* strm, String valueStr, QNameID qnameID) { errorCode tmp_err_code = EXIP_UNEXPECTED_ERROR; ValueEntry* valueEntry = NULL; Index valueEntryId; #if VALUE_CROSSTABLE_USE Index vxEntryId; { struct LnEntry* lnEntry; VxEntry vxEntry; // Find the local name entry from QNameID lnEntry = &GET_LN_URI_QNAME(strm->schema->uriTable, qnameID); // Add entry to the local name entry's value cross table (vxTable) if(lnEntry->vxTable == NULL) { lnEntry->vxTable = memManagedAllocate(&strm->memList, sizeof(VxTable)); if(lnEntry->vxTable == NULL) return EXIP_MEMORY_ALLOCATION_ERROR; // First value entry - create the vxTable TRY(createDynArray(&lnEntry->vxTable->dynArray, sizeof(VxEntry), DEFAULT_VX_ENTRIES_NUMBER)); } assert(lnEntry->vxTable->vx); // Set the global ID in the value cross table entry vxEntry.globalId = strm->valueTable.globalId; // Add the entry TRY(addDynEntry(&lnEntry->vxTable->dynArray, (void*) &vxEntry, &vxEntryId)); } #endif // If the global ID is less than the actual array size, we must have wrapped around // In this case, we must reuse an existing entry if(strm->valueTable.globalId < strm->valueTable.count) { // Get the existing value entry valueEntry = &strm->valueTable.value[strm->valueTable.globalId]; #if VALUE_CROSSTABLE_USE assert(GET_LN_URI_QNAME(strm->schema->uriTable, valueEntry->locValuePartition.forQNameId).vxTable); // Null out the existing cross table entry GET_LN_URI_QNAME(strm->schema->uriTable, valueEntry->locValuePartition.forQNameId).vxTable->vx[valueEntry->locValuePartition.vxEntryId].globalId = INDEX_MAX; #endif #if HASH_TABLE_USE // Remove existing value string from hash table (if present) if(strm->valueTable.hashTbl != NULL) { hashtable_remove(strm->valueTable.hashTbl, valueEntry->valueStr); } #endif // Free the memory allocated by the previous string entry EXIP_MFREE(valueEntry->valueStr.str); } else { // We are filling up the array and have not wrapped round yet // See http://www.w3.org/TR/exi/#encodingOptimizedForMisses TRY(addEmptyDynEntry(&strm->valueTable.dynArray, (void**)&valueEntry, &valueEntryId)); } // Set the value entry fields valueEntry->valueStr = valueStr; #if VALUE_CROSSTABLE_USE valueEntry->locValuePartition.forQNameId = qnameID; valueEntry->locValuePartition.vxEntryId = vxEntryId; #endif #if HASH_TABLE_USE // Add value string to hash table (if present) if(strm->valueTable.hashTbl != NULL) { TRY(hashtable_insert(strm->valueTable.hashTbl, valueStr, strm->valueTable.globalId)); } #endif // Increment global ID strm->valueTable.globalId++; // The value table is limited by valuePartitionCapacity. If we have exceeded, we wrap around // to the beginning of the value table and null out existing IDs in the corresponding // cross table IDs if(strm->valueTable.globalId == strm->header.opts.valuePartitionCapacity) strm->valueTable.globalId = 0; return EXIP_OK; }
errorCode createFragmentGrammar(EXIPSchema* schema, QNameID* elQnameArr, Index qnameCount) { GrammarRule* tmp_rule; schema->docGrammar.count = DEF_FRAG_GRAMMAR_RULE_NUMBER; schema->docGrammar.props = 0; schema->docGrammar.contentIndex = 0; schema->docGrammar.rule = (GrammarRule*) memManagedAllocate(&schema->memList, sizeof(GrammarRule)*DEF_FRAG_GRAMMAR_RULE_NUMBER); if(schema->docGrammar.rule == NULL) return MEMORY_ALLOCATION_ERROR; /* Rule for Fragment */ /* Fragment : SD FragmentContent 0 */ tmp_rule = &schema->docGrammar.rule[GR_FRAGMENT]; /* Part 1 */ tmp_rule->part[0].prod = static_prod_start_doc_part0; tmp_rule->part[0].count = 1; tmp_rule->part[0].bits = 0; /* Initialize Part 2 */ tmp_rule->part[1].prod = NULL; tmp_rule->part[1].count = 0; tmp_rule->part[1].bits = 0; /* Initialize Part 3 */ tmp_rule->part[2].prod = NULL; tmp_rule->part[2].count = 0; tmp_rule->part[2].bits = 0; /* Rule for Fragment content */ tmp_rule = &schema->docGrammar.rule[GR_FRAGMENT_CONTENT]; /* Initialize Part 2 */ tmp_rule->part[1].prod = NULL; tmp_rule->part[1].count = 0; tmp_rule->part[1].bits = 0; /* Initialize Part 3 */ tmp_rule->part[2].prod = NULL; tmp_rule->part[2].count = 0; tmp_rule->part[2].bits = 0; /* Part 1 */ if(elQnameArr != NULL) // Creates Schema Informed Grammar { unsigned int e = 0; Index tmp_code1; SET_SCHEMA(schema->docGrammar.props); tmp_code1 = qnameCount + 2; tmp_rule->part[0].prod = (Production*) memManagedAllocate(&schema->memList, sizeof(Production)*tmp_code1); if(tmp_rule->part[0].prod == NULL) return MEMORY_ALLOCATION_ERROR; /* * FragmentContent : * SE (F-0) FragmentContent 0 * SE (F-1) FragmentContent 1 * ⋮ ⋮ ⋮ * SE (F-n−1) FragmentContent n-1 * // SE (*) FragmentContent n // This is created as part of the Build-In grammar further on * // ED n+1 // This is created as part of the Build-In grammar further on */ for(e = 0; e < qnameCount; e++) { tmp_rule->part[0].prod[qnameCount - e].eventType = EVENT_SE_QNAME; tmp_rule->part[0].prod[qnameCount - e].typeId = GET_LN_URI_QNAME(schema->uriTable, elQnameArr[e]).elemGrammar; tmp_rule->part[0].prod[qnameCount - e].nonTermID = GR_FRAGMENT_CONTENT; tmp_rule->part[0].prod[qnameCount - e].qnameId = elQnameArr[e]; } tmp_rule->part[0].count = tmp_code1; tmp_rule->part[0].bits = getBitsNumber(tmp_code1 - 1); } else { tmp_rule->part[0].prod = (Production*) memManagedAllocate(&schema->memList, sizeof(Production)*2); if(tmp_rule->part[0].prod == NULL) return MEMORY_ALLOCATION_ERROR; /* Productions further on... */ tmp_rule->part[0].count = 2; tmp_rule->part[0].bits = 1; } /* * FragmentContent : * SE (*) FragmentContent 0 * ED 1 */ tmp_rule->part[0].prod[0].eventType = EVENT_ED; tmp_rule->part[0].prod[0].typeId = INDEX_MAX; tmp_rule->part[0].prod[0].nonTermID = GR_VOID_NON_TERMINAL; tmp_rule->part[0].prod[0].qnameId.uriId = SMALL_INDEX_MAX; tmp_rule->part[0].prod[0].qnameId.lnId = INDEX_MAX; tmp_rule->part[0].prod[1].eventType = EVENT_SE_ALL; tmp_rule->part[0].prod[1].typeId = INDEX_MAX; tmp_rule->part[0].prod[1].nonTermID = GR_FRAGMENT_CONTENT; tmp_rule->part[0].prod[1].qnameId.uriId = SMALL_INDEX_MAX; tmp_rule->part[0].prod[1].qnameId.lnId = INDEX_MAX; return ERR_OK; }
errorCode createDocGrammar(EXIPSchema* schema, QNameID* elQnameArr, Index qnameCount) { GrammarRule* tmp_rule; schema->docGrammar.count = DEF_DOC_GRAMMAR_RULE_NUMBER; schema->docGrammar.props = 0; schema->docGrammar.contentIndex = 0; schema->docGrammar.rule = (GrammarRule*) memManagedAllocate(&schema->memList, sizeof(GrammarRule)*DEF_DOC_GRAMMAR_RULE_NUMBER); if(schema->docGrammar.rule == NULL) return MEMORY_ALLOCATION_ERROR; /* Rule for Document */ /* * Document : * SD DocContent 0 */ tmp_rule = &schema->docGrammar.rule[GR_DOCUMENT]; /* Part 1 */ tmp_rule->part[0].prod = static_prod_start_doc_part0; tmp_rule->part[0].count = 1; tmp_rule->part[0].bits = 0; /* Initialize Part 2 */ tmp_rule->part[1].prod = NULL; tmp_rule->part[1].count = 0; tmp_rule->part[1].bits = 0; /* Initialize Part 3 */ tmp_rule->part[2].prod = NULL; tmp_rule->part[2].count = 0; tmp_rule->part[2].bits = 0; /* Rule for document content */ tmp_rule = &schema->docGrammar.rule[GR_DOC_CONTENT]; /* Initialize Part 2 */ tmp_rule->part[1].prod = NULL; tmp_rule->part[1].count = 0; tmp_rule->part[1].bits = 0; /* Initialize Part 3 */ tmp_rule->part[2].prod = NULL; tmp_rule->part[2].count = 0; tmp_rule->part[2].bits = 0; /* Part 1 */ if(elQnameArr != NULL) // Creates Schema Informed Grammar { unsigned int e = 0; Index tmp_code1; SET_SCHEMA(schema->docGrammar.props); tmp_code1 = qnameCount + 1; tmp_rule->part[0].prod = (Production*) memManagedAllocate(&schema->memList, sizeof(Production)*tmp_code1); if(tmp_rule->part[0].prod == NULL) return MEMORY_ALLOCATION_ERROR; /* * DocContent : * SE (G-0) DocEnd 0 * SE (G-1) DocEnd 1 * ⋮ ⋮ ⋮ * SE (G-n−1) DocEnd n-1 * // SE (*) DocEnd n // This is created as part of the Built-In grammar further on */ for(e = 0; e < qnameCount; e++) { tmp_rule->part[0].prod[qnameCount - e].eventType = EVENT_SE_QNAME; tmp_rule->part[0].prod[qnameCount - e].typeId = GET_LN_URI_QNAME(schema->uriTable, elQnameArr[e]).elemGrammar; tmp_rule->part[0].prod[qnameCount - e].nonTermID = GR_DOC_END; tmp_rule->part[0].prod[qnameCount - e].qnameId = elQnameArr[e]; } tmp_rule->part[0].count = tmp_code1; tmp_rule->part[0].bits = getBitsNumber(qnameCount); } else { tmp_rule->part[0].prod = (Production*) memManagedAllocate(&schema->memList, sizeof(Production)); if(tmp_rule->part[0].prod == NULL) return MEMORY_ALLOCATION_ERROR; tmp_rule->part[0].count = 1; tmp_rule->part[0].bits = 0; } /* * DocContent : * SE (*) DocEnd 0 */ tmp_rule->part[0].prod[0].eventType = EVENT_SE_ALL; tmp_rule->part[0].prod[0].typeId = INDEX_MAX; tmp_rule->part[0].prod[0].nonTermID = GR_DOC_END; tmp_rule->part[0].prod[0].qnameId.uriId = SMALL_INDEX_MAX; tmp_rule->part[0].prod[0].qnameId.lnId = INDEX_MAX; /* Rule for Document end */ /* * DocEnd : * ED 0 */ tmp_rule = &schema->docGrammar.rule[GR_DOC_END]; /* Part 1 */ tmp_rule->part[0].prod = static_prod_doc_end_part0; tmp_rule->part[0].count = 1; tmp_rule->part[0].bits = 0; /* Initialize Part 2 */ tmp_rule->part[1].prod = NULL; tmp_rule->part[1].count = 0; tmp_rule->part[1].bits = 0; /* Initialize Part 3 */ tmp_rule->part[2].prod = NULL; tmp_rule->part[2].count = 0; tmp_rule->part[2].bits = 0; return ERR_OK; }
errorCode generateBuiltInTypesGrammars(EXIPSchema* schema) { unsigned int i; QNameID typeQnameID; Index typeId; EXIGrammar grammar; Index dynArrId; // URI id 3 -> http://www.w3.org/2001/XMLSchema typeQnameID.uriId = XML_SCHEMA_NAMESPACE_ID; grammar.count = 2; for(i = 0; i < schema->uriTable.uri[XML_SCHEMA_NAMESPACE_ID].lnTable.count; i++) { typeQnameID.lnId = i; typeId = typeQnameID.lnId; grammar.props = 0; SET_SCHEMA_GR(grammar.props); if(HAS_TYPE_FACET(schema->simpleTypeTable.sType[typeId].content, TYPE_FACET_NAMED_SUBTYPE_UNION)) SET_NAMED_SUB_TYPE_OR_UNION(grammar.props); // One more rule slot for grammar augmentation when strict == FASLE grammar.rule = (GrammarRule*)memManagedAllocate(&schema->memList, sizeof(GrammarRule)*(grammar.count + 1)); if(grammar.rule == NULL) return MEMORY_ALLOCATION_ERROR; if(typeId == SIMPLE_TYPE_ANY_TYPE) { // <xs:anyType> - The base complex type; complex ur-type SET_CONTENT_INDEX(grammar.props, 1); grammar.rule[0].production = memManagedAllocate(&schema->memList, sizeof(Production)*4); if(grammar.rule[0].production == NULL) return MEMORY_ALLOCATION_ERROR; SET_PROD_EXI_EVENT(grammar.rule[0].production[3].content, EVENT_AT_ALL); SET_PROD_NON_TERM(grammar.rule[0].production[3].content, 0); grammar.rule[0].production[3].typeId = INDEX_MAX; grammar.rule[0].production[3].qnameId.uriId = URI_MAX; grammar.rule[0].production[3].qnameId.lnId = LN_MAX; SET_PROD_EXI_EVENT(grammar.rule[0].production[2].content, EVENT_SE_ALL); SET_PROD_NON_TERM(grammar.rule[0].production[2].content, 1); grammar.rule[0].production[2].typeId = INDEX_MAX; grammar.rule[0].production[2].qnameId.uriId = URI_MAX; grammar.rule[0].production[2].qnameId.lnId = LN_MAX; SET_PROD_EXI_EVENT(grammar.rule[0].production[1].content, EVENT_EE); SET_PROD_NON_TERM(grammar.rule[0].production[1].content, GR_VOID_NON_TERMINAL); grammar.rule[0].production[1].typeId = INDEX_MAX; grammar.rule[0].production[1].qnameId.uriId = URI_MAX; grammar.rule[0].production[1].qnameId.lnId = LN_MAX; SET_PROD_EXI_EVENT(grammar.rule[0].production[0].content, EVENT_CH); SET_PROD_NON_TERM(grammar.rule[0].production[0].content, 1); grammar.rule[0].production[0].typeId = INDEX_MAX; grammar.rule[0].production[0].qnameId.uriId = URI_MAX; grammar.rule[0].production[0].qnameId.lnId = LN_MAX; grammar.rule[0].pCount = 4; grammar.rule[1].production = memManagedAllocate(&schema->memList, sizeof(Production)*3); if(grammar.rule[1].production == NULL) return MEMORY_ALLOCATION_ERROR; SET_PROD_EXI_EVENT(grammar.rule[1].production[2].content, EVENT_SE_ALL); SET_PROD_NON_TERM(grammar.rule[1].production[2].content, 1); grammar.rule[1].production[2].typeId = INDEX_MAX; grammar.rule[1].production[2].qnameId.uriId = URI_MAX; grammar.rule[1].production[2].qnameId.lnId = LN_MAX; SET_PROD_EXI_EVENT(grammar.rule[1].production[1].content, EVENT_EE); SET_PROD_NON_TERM(grammar.rule[1].production[1].content, GR_VOID_NON_TERMINAL); grammar.rule[1].production[1].typeId = INDEX_MAX; grammar.rule[1].production[1].qnameId.uriId = URI_MAX; grammar.rule[1].production[1].qnameId.lnId = LN_MAX; SET_PROD_EXI_EVENT(grammar.rule[1].production[0].content, EVENT_CH); SET_PROD_NON_TERM(grammar.rule[1].production[0].content, 1); grammar.rule[1].production[0].typeId = INDEX_MAX; grammar.rule[1].production[0].qnameId.uriId = URI_MAX; grammar.rule[1].production[0].qnameId.lnId = LN_MAX; grammar.rule[1].pCount = 3; } else // a regular simple type { grammar.rule[0].production = memManagedAllocate(&schema->memList, sizeof(Production)); if(grammar.rule[0].production == NULL) return MEMORY_ALLOCATION_ERROR; SET_PROD_EXI_EVENT(grammar.rule[0].production[0].content, EVENT_CH); SET_PROD_NON_TERM(grammar.rule[0].production[0].content, 1); grammar.rule[0].production[0].typeId = typeId; grammar.rule[0].production[0].qnameId.uriId = URI_MAX; grammar.rule[0].production[0].qnameId.lnId = LN_MAX; grammar.rule[0].pCount = 1; grammar.rule[1].production = memManagedAllocate(&schema->memList, sizeof(Production)); if(grammar.rule[1].production == NULL) return MEMORY_ALLOCATION_ERROR; SET_PROD_EXI_EVENT(grammar.rule[1].production[0].content, EVENT_EE); SET_PROD_NON_TERM(grammar.rule[1].production[0].content, GR_VOID_NON_TERMINAL); grammar.rule[1].production[0].typeId = INDEX_MAX; grammar.rule[1].production[0].qnameId.uriId = URI_MAX; grammar.rule[1].production[0].qnameId.lnId = LN_MAX; grammar.rule[1].pCount = 1; } /** Add the grammar to the schema grammar table */ addDynEntry(&schema->grammarTable.dynArray, &grammar, &dynArrId); schema->uriTable.uri[3].lnTable.ln[i].typeGrammar = dynArrId; } return ERR_OK; }
errorCode createDocGrammar(EXIPSchema* schema, QNameID* elQnameArr, Index qnameCount) { GrammarRule* tmp_rule; schema->docGrammar.count = DEF_DOC_GRAMMAR_RULE_NUMBER; schema->docGrammar.props = 0; SET_DOCUMENT_GR(schema->docGrammar.props); schema->docGrammar.rule = (GrammarRule*) memManagedAllocate(&schema->memList, sizeof(GrammarRule)*DEF_DOC_GRAMMAR_RULE_NUMBER); if(schema->docGrammar.rule == NULL) return MEMORY_ALLOCATION_ERROR; /* Rule for Document */ /* * Document : * SD DocContent 0 */ // IGNORED! /* Rule for document content */ tmp_rule = &schema->docGrammar.rule[GR_DOC_CONTENT]; if(elQnameArr != NULL) // Creates Schema Informed Grammar { unsigned int e = 0; Index tmp_code1; SET_SCHEMA_GR(schema->docGrammar.props); tmp_code1 = qnameCount + 1; tmp_rule->production = (Production*) memManagedAllocate(&schema->memList, sizeof(Production)*tmp_code1); if(tmp_rule->production == NULL) return MEMORY_ALLOCATION_ERROR; /* * DocContent : * SE (G-0) DocEnd 0 * SE (G-1) DocEnd 1 * ⋮ ⋮ ⋮ * SE (G-n−1) DocEnd n-1 * // SE (*) DocEnd n // This is created as part of the Built-In grammar further on */ for(e = 0; e < qnameCount; e++) { SET_PROD_EXI_EVENT(tmp_rule->production[qnameCount - e].content, EVENT_SE_QNAME); SET_PROD_NON_TERM(tmp_rule->production[qnameCount - e].content, GR_DOC_END); tmp_rule->production[qnameCount - e].typeId = GET_LN_URI_QNAME(schema->uriTable, elQnameArr[e]).elemGrammar; tmp_rule->production[qnameCount - e].qnameId = elQnameArr[e]; } tmp_rule->pCount = tmp_code1; } else { tmp_rule->production = (Production*) memManagedAllocate(&schema->memList, sizeof(Production)); if(tmp_rule->production == NULL) return MEMORY_ALLOCATION_ERROR; tmp_rule->pCount = 1; tmp_rule->meta = 0; } /* * DocContent : * SE (*) DocEnd 0 */ SET_PROD_EXI_EVENT(tmp_rule->production[0].content, EVENT_SE_ALL); SET_PROD_NON_TERM(tmp_rule->production[0].content, GR_DOC_END); tmp_rule->production[0].typeId = INDEX_MAX; tmp_rule->production[0].qnameId.uriId = URI_MAX; tmp_rule->production[0].qnameId.lnId = LN_MAX; /* Rule for Document end */ /* * DocEnd : * ED 0 */ tmp_rule = &schema->docGrammar.rule[GR_DOC_END]; // TODO: consider ignoring this rule as well. In exipg generation as well ... /* Part 1 */ tmp_rule->production = (Production*) memManagedAllocate(&schema->memList, sizeof(Production)); if(tmp_rule->production == NULL) return MEMORY_ALLOCATION_ERROR; SET_PROD_EXI_EVENT(tmp_rule->production[0].content, EVENT_ED); SET_PROD_NON_TERM(tmp_rule->production[0].content, GR_VOID_NON_TERMINAL); tmp_rule->production[0].typeId = INDEX_MAX; tmp_rule->production[0].qnameId.uriId = URI_MAX; tmp_rule->production[0].qnameId.lnId = LN_MAX; tmp_rule->pCount = 1; tmp_rule->meta = 0; return ERR_OK; }
errorCode createFragmentGrammar(EXIPSchema* schema, QNameID* elQnameArr, Index qnameCount) { GrammarRule* tmp_rule; schema->docGrammar.count = DEF_FRAG_GRAMMAR_RULE_NUMBER; schema->docGrammar.props = 0; schema->docGrammar.rule = (GrammarRule*) memManagedAllocate(&schema->memList, sizeof(GrammarRule)*DEF_FRAG_GRAMMAR_RULE_NUMBER); if(schema->docGrammar.rule == NULL) return MEMORY_ALLOCATION_ERROR; /* Rule for Fragment */ /* Fragment : SD FragmentContent 0 */ // IGNORED! /* Rule for Fragment content */ tmp_rule = &schema->docGrammar.rule[GR_FRAGMENT_CONTENT]; /* Part 1 */ if(elQnameArr != NULL) // Creates Schema Informed Grammar { unsigned int e = 0; Index tmp_code1; SET_SCHEMA_GR(schema->docGrammar.props); tmp_code1 = qnameCount + 2; tmp_rule->production = (Production*) memManagedAllocate(&schema->memList, sizeof(Production)*tmp_code1); if(tmp_rule->production == NULL) return MEMORY_ALLOCATION_ERROR; /* * FragmentContent : * SE (F-0) FragmentContent 0 * SE (F-1) FragmentContent 1 * ⋮ ⋮ ⋮ * SE (F-n−1) FragmentContent n-1 * // SE (*) FragmentContent n // This is created as part of the Build-In grammar further on * // ED n+1 // This is created as part of the Build-In grammar further on */ for(e = 0; e < qnameCount; e++) { SET_PROD_EXI_EVENT(tmp_rule->production[qnameCount - e].content, EVENT_SE_QNAME); SET_PROD_NON_TERM(tmp_rule->production[qnameCount - e].content, GR_FRAGMENT_CONTENT); tmp_rule->production[qnameCount - e].typeId = GET_LN_URI_QNAME(schema->uriTable, elQnameArr[e]).elemGrammar; tmp_rule->production[qnameCount - e].qnameId = elQnameArr[e]; } tmp_rule->pCount = tmp_code1; } else { tmp_rule->production = (Production*) memManagedAllocate(&schema->memList, sizeof(Production)*2); if(tmp_rule->production == NULL) return MEMORY_ALLOCATION_ERROR; /* Productions further on... */ tmp_rule->pCount = 2; } /* * FragmentContent : * SE (*) FragmentContent 0 * ED 1 */ SET_PROD_EXI_EVENT(tmp_rule->production[0].content, EVENT_ED); SET_PROD_NON_TERM(tmp_rule->production[0].content, GR_VOID_NON_TERMINAL); tmp_rule->production[0].typeId = INDEX_MAX; tmp_rule->production[0].qnameId.uriId = URI_MAX; tmp_rule->production[0].qnameId.lnId = LN_MAX; SET_PROD_EXI_EVENT(tmp_rule->production[1].content, EVENT_SE_ALL); SET_PROD_NON_TERM(tmp_rule->production[1].content, GR_FRAGMENT_CONTENT); tmp_rule->production[1].typeId = INDEX_MAX; tmp_rule->production[1].qnameId.uriId = URI_MAX; tmp_rule->production[1].qnameId.lnId = LN_MAX; return ERR_OK; }