exip  Alpha 0.5.4
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
initSchemaInstance.c
Go to the documentation of this file.
1 /*==================================================================*\
2 | EXIP - Embeddable EXI Processor in C |
3 |--------------------------------------------------------------------|
4 | This work is licensed under BSD 3-Clause License |
5 | The full license terms and conditions are located in LICENSE.txt |
6 \===================================================================*/
7 
18 #include "initSchemaInstance.h"
19 #include "sTables.h"
20 #include "grammars.h"
21 
22 #ifndef DEFAULT_GRAMMAR_TABLE
23 # define DEFAULT_GRAMMAR_TABLE 300
24 #endif
25 
26 #ifndef DEFAULT_SIMPLE_GRAMMAR_TABLE
27 # define DEFAULT_SIMPLE_GRAMMAR_TABLE 75
28 #endif
29 
30 #ifndef DEFAULT_ENUM_TABLE
31 # define DEFAULT_ENUM_TABLE 5
32 #endif
33 
34 errorCode initSchema(EXIPSchema* schema, InitSchemaType initializationType)
35 {
36  errorCode tmp_err_code = EXIP_UNEXPECTED_ERROR;
37 
38  TRY(initAllocList(&schema->memList));
39 
40  schema->staticGrCount = 0;
42  schema->docGrammar.count = 0;
43  schema->docGrammar.props = 0;
44  schema->docGrammar.rule = NULL;
45  schema->simpleTypeTable.count = 0;
46  schema->simpleTypeTable.sType = NULL;
47  schema->grammarTable.count = 0;
48  schema->grammarTable.grammar = NULL;
49  schema->enumTable.count = 0;
50  schema->enumTable.enumDef = NULL;
51 
52  /* Create and initialize initial string table entries */
55 
56  if(initializationType == INIT_SCHEMA_SCHEMA_ENABLED)
57  {
58  /* Create and initialize enumDef table */
60  }
61 
62  /* Create the schema grammar table */
64 
65  if(initializationType != INIT_SCHEMA_SCHEMA_LESS_MODE)
66  {
67  /* Create and initialize simple type table */
70 
71  // Must be done after createBuiltInTypesDefinitions()
74  }
75 
76  return tmp_err_code;
77 }
78 
80 {
81  unsigned int i;
82  QNameID typeQnameID;
83  Index typeId;
84  EXIGrammar grammar;
85  Index dynArrId;
86 
87  // URI id 3 -> http://www.w3.org/2001/XMLSchema
88  typeQnameID.uriId = XML_SCHEMA_NAMESPACE_ID;
89 
90  grammar.count = 2;
91 
92  for(i = 0; i < schema->uriTable.uri[XML_SCHEMA_NAMESPACE_ID].lnTable.count; i++)
93  {
94  typeQnameID.lnId = i;
95  typeId = typeQnameID.lnId;
96 
97  grammar.props = 0;
98  SET_SCHEMA_GR(grammar.props);
101 
102  grammar.rule = (GrammarRule*) memManagedAllocate(&schema->memList, sizeof(GrammarRule)*(grammar.count));
103  if(grammar.rule == NULL)
105 
106  if(typeId == SIMPLE_TYPE_ANY_TYPE)
107  {
108  // <xs:anyType> - The base complex type; complex ur-type
109  SET_CONTENT_INDEX(grammar.props, 1);
110 
111  grammar.rule[0].production = memManagedAllocate(&schema->memList, sizeof(Production)*4);
112  if(grammar.rule[0].production == NULL)
114 
116  SET_PROD_NON_TERM(grammar.rule[0].production[3].content, 0);
117  grammar.rule[0].production[3].typeId = INDEX_MAX;
118  grammar.rule[0].production[3].qnameId.uriId = URI_MAX;
119  grammar.rule[0].production[3].qnameId.lnId = LN_MAX;
120 
122  SET_PROD_NON_TERM(grammar.rule[0].production[2].content, 1);
123  grammar.rule[0].production[2].typeId = INDEX_MAX;
124  grammar.rule[0].production[2].qnameId.uriId = URI_MAX;
125  grammar.rule[0].production[2].qnameId.lnId = LN_MAX;
126 
129  grammar.rule[0].production[1].typeId = INDEX_MAX;
130  grammar.rule[0].production[1].qnameId.uriId = URI_MAX;
131  grammar.rule[0].production[1].qnameId.lnId = LN_MAX;
132 
134  SET_PROD_NON_TERM(grammar.rule[0].production[0].content, 1);
135  grammar.rule[0].production[0].typeId = INDEX_MAX;
136  grammar.rule[0].production[0].qnameId.uriId = URI_MAX;
137  grammar.rule[0].production[0].qnameId.lnId = LN_MAX;
138 
139  grammar.rule[0].pCount = 4;
140  grammar.rule[0].meta = 0;
141  RULE_SET_CONTAIN_EE(grammar.rule[0].meta);
142 
143  grammar.rule[1].production = memManagedAllocate(&schema->memList, sizeof(Production)*3);
144  if(grammar.rule[1].production == NULL)
146 
148  SET_PROD_NON_TERM(grammar.rule[1].production[2].content, 1);
149  grammar.rule[1].production[2].typeId = INDEX_MAX;
150  grammar.rule[1].production[2].qnameId.uriId = URI_MAX;
151  grammar.rule[1].production[2].qnameId.lnId = LN_MAX;
152 
155  grammar.rule[1].production[1].typeId = INDEX_MAX;
156  grammar.rule[1].production[1].qnameId.uriId = URI_MAX;
157  grammar.rule[1].production[1].qnameId.lnId = LN_MAX;
158 
160  SET_PROD_NON_TERM(grammar.rule[1].production[0].content, 1);
161  grammar.rule[1].production[0].typeId = INDEX_MAX;
162  grammar.rule[1].production[0].qnameId.uriId = URI_MAX;
163  grammar.rule[1].production[0].qnameId.lnId = LN_MAX;
164 
165  grammar.rule[1].pCount = 3;
166  grammar.rule[1].meta = 0;
167  RULE_SET_CONTAIN_EE(grammar.rule[1].meta);
168  }
169  else // a regular simple type
170  {
171  grammar.rule[0].production = memManagedAllocate(&schema->memList, sizeof(Production));
172  if(grammar.rule[0].production == NULL)
174 
176  SET_PROD_NON_TERM(grammar.rule[0].production[0].content, 1);
177  grammar.rule[0].production[0].typeId = typeId;
178  grammar.rule[0].production[0].qnameId.uriId = URI_MAX;
179  grammar.rule[0].production[0].qnameId.lnId = LN_MAX;
180  grammar.rule[0].pCount = 1;
181  grammar.rule[0].meta = 0;
182 
183  grammar.rule[1].production = memManagedAllocate(&schema->memList, sizeof(Production));
184  if(grammar.rule[1].production == NULL)
186 
189  grammar.rule[1].production[0].typeId = INDEX_MAX;
190  grammar.rule[1].production[0].qnameId.uriId = URI_MAX;
191  grammar.rule[1].production[0].qnameId.lnId = LN_MAX;
192  grammar.rule[1].pCount = 1;
193  grammar.rule[1].meta = 0;
194  RULE_SET_CONTAIN_EE(grammar.rule[1].meta);
195  }
196 
198  addDynEntry(&schema->grammarTable.dynArray, &grammar, &dynArrId);
199  schema->uriTable.uri[3].lnTable.ln[i].typeGrammar = dynArrId;
200  }
201 
202  return EXIP_OK;
203 }
204 
206 {
207  errorCode tmp_err_code = EXIP_UNEXPECTED_ERROR;
208  SimpleType sType;
209  Index elID;
210 
211  // entities
212  sType.content = 0;
214  sType.max = 0;
215  sType.min = 0;
216  sType.length = SIMPLE_TYPE_ENTITY;
217  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
218 
219  // entity
220  sType.content = 0;
223  sType.max = 0;
224  sType.min = 0;
225  sType.length = 0;
226  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
227 
228  // id
229  sType.content = 0;
231  sType.max = 0;
232  sType.min = 0;
233  sType.length = 0;
234  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
235 
236  // idref
237  sType.content = 0;
240  sType.max = 0;
241  sType.min = 0;
242  sType.length = 0;
243  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
244 
245  // idrefs
246  sType.content = 0;
248  sType.max = 0;
249  sType.min = 0;
250  sType.length = SIMPLE_TYPE_IDREF;
251  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
252 
253  // ncname
254  sType.content = 0;
257  sType.max = 0;
258  sType.min = 0;
259  sType.length = 0;
260  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
261 
262  // nmtoken
263  sType.content = 0;
266  sType.max = 0;
267  sType.min = 0;
268  sType.length = 0;
269  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
270 
271  // nmtokens
272  sType.content = 0;
274  sType.max = 0;
275  sType.min = 0;
276  sType.length = SIMPLE_TYPE_NMTOKEN;
277  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
278 
279  // notation
280  sType.content = 0;
282  sType.max = 0;
283  sType.min = 0;
284  sType.length = 0;
285  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
286 
287  // name
288  sType.content = 0;
291  sType.max = 0;
292  sType.min = 0;
293  sType.length = 0;
294  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
295 
296  // qname
297  sType.content = 0;
299  sType.max = 0;
300  sType.min = 0;
301  sType.length = 0;
302  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
303 
304  // any simple type
305  sType.content = 0;
308  sType.max = 0;
309  sType.min = 0;
310  sType.length = 0;
311  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
312 
313  // any type
314  sType.content = 0;
317  sType.max = 0;
318  sType.min = 0;
319  sType.length = 0;
320  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
321 
322  // any uri
323  sType.content = 0;
325  sType.max = 0;
326  sType.min = 0;
327  sType.length = 0;
328  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
329 
330  // base64 binary
331  sType.content = 0;
333  sType.max = 0;
334  sType.min = 0;
335  sType.length = 0;
336  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
337 
338  // boolean
339  sType.content = 0;
341  sType.max = 0;
342  sType.min = 0;
343  sType.length = 0;
344  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
345 
346  // byte
347  sType.content = 0;
351  sType.max = 127;
352  sType.min = -128;
353  sType.length = 0;
354  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
355 
356  // date
357  sType.content = 0;
359  sType.max = 0;
360  sType.min = 0;
361  sType.length = 0;
362  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
363 
364  // date time
365  sType.content = 0;
367  sType.max = 0;
368  sType.min = 0;
369  sType.length = 0;
370  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
371 
372  // decimal
373  sType.content = 0;
376  sType.max = 0;
377  sType.min = 0;
378  sType.length = 0;
379  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
380 
381  // double
382  sType.content = 0;
384  sType.max = 0;
385  sType.min = 0;
386  sType.length = 0;
387  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
388 
389  // duration
390  sType.content = 0;
392  sType.max = 0;
393  sType.min = 0;
394  sType.length = 0;
395  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
396 
397  // float
398  sType.content = 0;
400  sType.max = 0;
401  sType.min = 0;
402  sType.length = 0;
403  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
404 
405  // gDay
406  sType.content = 0;
408  sType.max = 0;
409  sType.min = 0;
410  sType.length = 0;
411  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
412 
413  // gMonth
414  sType.content = 0;
416  sType.max = 0;
417  sType.min = 0;
418  sType.length = 0;
419  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
420 
421  // gMonthDay
422  sType.content = 0;
424  sType.max = 0;
425  sType.min = 0;
426  sType.length = 0;
427  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
428 
429  // gYear
430  sType.content = 0;
432  sType.max = 0;
433  sType.min = 0;
434  sType.length = 0;
435  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
436 
437  // gYearMonth
438  sType.content = 0;
440  sType.max = 0;
441  sType.min = 0;
442  sType.length = 0;
443  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
444 
445  // hex binary
446  sType.content = 0;
448  sType.max = 0;
449  sType.min = 0;
450  sType.length = 0;
451  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
452 
453  // Int
454  sType.content = 0;
457  sType.max = 0;
458  sType.min = 0;
459  sType.length = 0;
460  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
461 
462  // integer
463  sType.content = 0;
466  sType.max = 0;
467  sType.min = 0;
468  sType.length = 0;
469  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
470 
471  // language
472  sType.content = 0;
474  sType.max = 0;
475  sType.min = 0;
476  sType.length = 0;
477  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
478 
479  // long
480  sType.content = 0;
483  sType.max = 0;
484  sType.min = 0;
485  sType.length = 0;
486  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
487 
488  // negativeInteger
489  sType.content = 0;
492  sType.max = -1;
493  sType.min = 0;
494  sType.length = 0;
495  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
496 
497  // NonNegativeInteger
498  sType.content = 0;
502  sType.max = 0;
503  sType.min = 0;
504  sType.length = 0;
505  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
506 
507  // NonPositiveInteger
508  sType.content = 0;
512  sType.max = 0;
513  sType.min = 0;
514  sType.length = 0;
515  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
516 
517  // normalizedString
518  sType.content = 0;
521  sType.max = 0;
522  sType.min = 0;
523  sType.length = 0;
524  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
525 
526  // Positive Integer
527  sType.content = 0;
530  sType.max = 0;
531  sType.min = 1;
532  sType.length = 0;
533  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
534 
535  // short
536  sType.content = 0;
541  sType.max = 32767;
542  sType.min = -32768;
543  sType.length = 0;
544  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
545 
546  // String
547  sType.content = 0;
550  sType.max = 0;
551  sType.min = 0;
552  sType.length = 0;
553  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
554 
555  // time
556  sType.content = 0;
558  sType.max = 0;
559  sType.min = 0;
560  sType.length = 0;
561  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
562 
563  // token
564  sType.content = 0;
567  sType.max = 0;
568  sType.min = 0;
569  sType.length = 0;
570  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
571 
572  // Unsigned byte
573  sType.content = 0;
577  sType.max = 255;
578  sType.min = 0;
579  sType.length = 0;
580  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
581 
582  // Unsigned int
583  sType.content = 0;
587  sType.max = 0;
588  sType.min = 0;
589  sType.length = 0;
590  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
591 
592  // Unsigned Long
593  sType.content = 0;
597  sType.max = 0;
598  sType.min = 0;
599  sType.length = 0;
600  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
601 
602  // Unsigned short
603  sType.content = 0;
608  sType.max = 65535;
609  sType.min = 0;
610  sType.length = 0;
611  TRY(addDynEntry(&simpleTypeTable->dynArray, &sType, &elID));
612 
613  return EXIP_OK;
614 }