exip  Alpha 0.5.4
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
createGrammars.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 "procTypes.h"
19 #include "schemaOutputUtils.h"
20 #include "grammars.h"
21 #include "sTables.h"
22 #include <stdio.h>
23 #include <time.h>
24 #include "createGrammars.h"
25 
26 errorCode toText(EXIPSchema* schemaPtr, FILE *outfile)
27 {
28  EXIGrammar* tmpGrammar;
29  QNameID qnameId = {0, 0};
30 
31  fprintf(outfile, "\n/** GLOBAL ELEMENT GRAMMARS **/\n\n");
32  for(qnameId.uriId = 0; qnameId.uriId < schemaPtr->uriTable.count; qnameId.uriId++)
33  {
34  for(qnameId.lnId = 0; qnameId.lnId < schemaPtr->uriTable.uri[qnameId.uriId].lnTable.count; qnameId.lnId++)
35  {
36  tmpGrammar = GET_ELEM_GRAMMAR_QNAMEID(schemaPtr, qnameId);
37  if(tmpGrammar != NULL)
38  {
39  if(EXIP_OK != recursiveTextGrammarOutput(qnameId, GET_LN_URI_QNAME(schemaPtr->uriTable, qnameId).elemGrammar, tmpGrammar, schemaPtr, outfile))
40  {
41  printf("\n ERROR: OUT_TEXT output format!");
42  return EXIP_UNEXPECTED_ERROR;
43  }
44  }
45  }
46  }
47 
48  fprintf(outfile, "\n/** GLOBAL TYPE GRAMMARS **/\n\n");
49  for(qnameId.uriId = 0; qnameId.uriId < schemaPtr->uriTable.count; qnameId.uriId++)
50  {
51  for(qnameId.lnId = 0; qnameId.lnId < schemaPtr->uriTable.uri[qnameId.uriId].lnTable.count; qnameId.lnId++)
52  {
53  tmpGrammar = GET_TYPE_GRAMMAR_QNAMEID(schemaPtr, qnameId);
54  if(tmpGrammar != NULL)
55  {
56  if(EXIP_OK != textGrammarOutput(qnameId, GET_LN_URI_QNAME(schemaPtr->uriTable, qnameId).typeGrammar, tmpGrammar, schemaPtr, outfile))
57  {
58  printf("\n ERROR: OUT_TEXT output format!");
59  return EXIP_UNEXPECTED_ERROR;
60  }
61  }
62  }
63  }
64 
65  return EXIP_OK;
66 }
67 
68 errorCode toStaticSrc(EXIPSchema* schemaPtr, char* prefix, FILE *outfile, Deviations dvis)
69 {
70  time_t now;
71  Index count;
72  Index uriId;
73  Index stId, stIdMax;
74  Index grIter;
75  EXIGrammar* tmpGrammar;
76 
77  time(&now);
78  fprintf(outfile, "/** AUTO-GENERATED: %.24s\n * Copyright (c) 2010 - 2011, Rumen Kyusakov, EISLAB, LTU\n * $Id$ */\n\n", ctime(&now));
79 
80  fprintf(outfile, "/** Compilation parameters:\n");
81  if(dvis.grammar != 0 || dvis.ln != 0 || dvis.url != 0 || dvis.pfx != 0)
82  {
83  fprintf(outfile, " * Compiled for possible deviations from the schema:\n * URLs: %d\n * Local names: %d\n * Prefixes: %d\n * Built-in grammars: %d */\n\n", dvis.url, dvis.ln, dvis.pfx, dvis.grammar);
84  }
85  else
86  fprintf(outfile, " * Compiled for no deviations from the schema! (lower memory usage) */\n\n");
87 
88 
89  fprintf(outfile, "#include \"procTypes.h\"\n\n");
90  fprintf(outfile, "#define CONST\n\n");
91 
92  staticStringTblDefsOutput(&schemaPtr->uriTable, prefix, outfile);
93 
94  for(grIter = 0; grIter < schemaPtr->grammarTable.count; grIter++)
95  {
96  staticProductionsOutput(&schemaPtr->grammarTable.grammar[grIter], prefix, grIter, outfile);
97  staticRulesOutput(&schemaPtr->grammarTable.grammar[grIter], prefix, grIter, outfile);
98  }
99 
100  /* The array of schema-informed EXI grammars in the EXIPSchema object */
101  fprintf(outfile, "static CONST EXIGrammar %sgrammarTable[%u] =\n{\n", prefix, (unsigned int) schemaPtr->grammarTable.count + dvis.grammar);
102  for(grIter = 0; grIter < schemaPtr->grammarTable.count; grIter++)
103  {
104  tmpGrammar = &schemaPtr->grammarTable.grammar[grIter];
105  fprintf(outfile," {%srule_%u, %u, %u},\n",
106  prefix,
107  (unsigned int) grIter,
108  (unsigned int) tmpGrammar->props,
109  (unsigned int) tmpGrammar->count);
110  }
111  // Reserving space for built-in grammar deviations
112  for(grIter = 0; grIter < dvis.grammar; grIter++)
113  {
114  fprintf(outfile," {NULL, 0, 0},\n");
115  }
116 
117  fprintf(outfile, "};\n\n");
118 
119  /* Build the Prefix and LN table structures */
120  for(uriId = 0; uriId < schemaPtr->uriTable.count; uriId++)
121  {
122  /* Prefix table */
123  staticPrefixOutput(&schemaPtr->uriTable.uri[uriId].pfxTable, prefix, uriId, dvis, outfile);
124  /* Ln table */
125  staticLnEntriesOutput(&schemaPtr->uriTable.uri[uriId].lnTable, prefix, uriId, dvis, outfile);
126  }
127 
128  /* Build the URI table structure */
129  staticUriTableOutput(&schemaPtr->uriTable, prefix, dvis, outfile);
130 
131  /* Build the document grammar */
132  staticDocGrammarOutput(&schemaPtr->docGrammar, prefix, outfile);
133 
134  /* Build the simple types structure */
135  fprintf(outfile, "static CONST SimpleType %ssimpleTypes[%u] =\n{\n", prefix, (unsigned int) schemaPtr->simpleTypeTable.count);
136 
137  if(schemaPtr->simpleTypeTable.sType != NULL)
138  {
139  stIdMax = schemaPtr->simpleTypeTable.count;
140  for(stId = 0; stId < stIdMax; stId++)
141  {
142  fprintf(outfile,
143  " {%d, %d, 0x%016lX, 0x%016lX}%s",
144  schemaPtr->simpleTypeTable.sType[stId].content,
145  schemaPtr->simpleTypeTable.sType[stId].length,
146  (long unsigned) schemaPtr->simpleTypeTable.sType[stId].max,
147  (long unsigned) schemaPtr->simpleTypeTable.sType[stId].min,
148  stId==(stIdMax-1) ? "\n};\n\n" : ",\n");
149  }
150  }
151 
152  /* Enum table entries */
153  staticEnumTableOutput(schemaPtr, prefix, outfile);
154 
155  /* Finally, build the schema structure */
156  fprintf(outfile,
157  "CONST EXIPSchema %sschema =\n{\n",
158  prefix);
159 
160 
161  fprintf(outfile, " {NULL, NULL},\n");
162 
163  count = schemaPtr->uriTable.count;
164  fprintf(outfile,
165  " {{sizeof(UriEntry), %u, %u}, %suriEntry, %u},\n",
166  (unsigned int) count,
167  (unsigned int) count + dvis.url,
168  prefix,
169  (unsigned int) count);
170 
171  fprintf(outfile,
172  " {%sdocGrammarRule, %u, %u},\n",
173  prefix,
174  (unsigned int) schemaPtr->docGrammar.props,
175  (unsigned int) schemaPtr->docGrammar.count);
176 
177  count = schemaPtr->simpleTypeTable.count;
178  fprintf(outfile,
179  " {{sizeof(SimpleType), %u, %u}, %ssimpleTypes, %u},\n",
180  (unsigned int) count,
181  (unsigned int) count,
182  prefix,
183  (unsigned int) count);
184 
185  count = schemaPtr->grammarTable.count;
186  fprintf(outfile,
187  " {{sizeof(EXIGrammar), %u, %u}, %sgrammarTable, %u},\n %u,\n",
188  (unsigned int) count,
189  (unsigned int) count + dvis.grammar,
190  prefix,
191  (unsigned int) count,
192  (unsigned int) count);
193 
194  count = schemaPtr->enumTable.count;
195  fprintf(outfile,
196  " {{sizeof(EnumDefinition), %u, %u}, %s%s, %u}\n};\n\n",
197 
198  (unsigned int) count,
199  (unsigned int) count,
200  count == 0?"":prefix, count == 0?"NULL":"enumTable",
201  (unsigned int) count);
202 
203  return EXIP_OK;
204 }
205 
206 errorCode toDynSrc(EXIPSchema* schemaPtr, FILE *outfile)
207 {
209 }
210 
211 errorCode toEXIP(EXIPSchema* schemaPtr, FILE *outfile)
212 {
214 }