exip  Alpha 0.5.4
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
textOutputUtils.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 
17 #include "schemaOutputUtils.h"
18 #include "sTables.h"
19 
20 static void writeValueTypeString(FILE* out, EXIType exiType);
21 
22 errorCode textGrammarOutput(QNameID qnameid, Index grIndex, EXIGrammar* gr, EXIPSchema* schema, FILE* out)
23 {
24  Index ruleIter, prodIter;
25  Production* tmpProd;
26  EXIType exiType = VALUE_TYPE_NONE;
27 
28  fprintf(out, "Grammar %d [%d:%d] ", (int) grIndex, (int) qnameid.uriId, (int) qnameid.lnId);
29  fwrite(schema->uriTable.uri[qnameid.uriId].uriStr.str, sizeof(CharType), schema->uriTable.uri[qnameid.uriId].uriStr.length, out);
30  fprintf(out, ":");
31  fwrite(GET_LN_URI_QNAME(schema->uriTable, qnameid).lnStr.str, sizeof(CharType), GET_LN_URI_QNAME(schema->uriTable, qnameid).lnStr.length, out);
32  fprintf(out, "\n");
33 
34  for(ruleIter = 0; ruleIter < gr->count; ruleIter++)
35  {
36  fprintf(out, "NT-%d: \n", (int) ruleIter);
37 
38  for(prodIter = 0; prodIter < gr->rule[ruleIter].pCount; prodIter++)
39  {
40  tmpProd = &gr->rule[ruleIter].production[gr->rule[ruleIter].pCount - 1 - prodIter];
41  if(GET_PROD_EXI_EVENT(tmpProd->content) != EVENT_SE_QNAME && tmpProd->typeId != INDEX_MAX)
42  exiType = GET_EXI_TYPE(schema->simpleTypeTable.sType[tmpProd->typeId].content);
43  else
44  exiType = VALUE_TYPE_NONE;
45  switch(GET_PROD_EXI_EVENT(tmpProd->content))
46  {
47  case EVENT_SD:
48  fprintf(out, "\tSD ");
49  break;
50  case EVENT_ED:
51  fprintf(out, "\tED ");
52  break;
53  case EVENT_SE_QNAME:
54  fprintf(out, "\tSE ([%d:%d]", (int) tmpProd->qnameId.uriId, (int) tmpProd->qnameId.lnId);
55  fwrite(schema->uriTable.uri[tmpProd->qnameId.uriId].uriStr.str, sizeof(CharType), schema->uriTable.uri[tmpProd->qnameId.uriId].uriStr.length, out);
56  fprintf(out, ":");
57  fwrite(GET_LN_URI_QNAME(schema->uriTable, tmpProd->qnameId).lnStr.str, sizeof(CharType), GET_LN_URI_QNAME(schema->uriTable, tmpProd->qnameId).lnStr.length, out);
58  fprintf(out, ") ");
59  break;
60  case EVENT_SE_URI:
61  fprintf(out, "\tSE (uri) ");
62  break;
63  case EVENT_SE_ALL:
64  fprintf(out, "\tSE (*) ");
65  break;
66  case EVENT_EE:
67  fprintf(out, "\tEE ");
68  break;
69  case EVENT_AT_QNAME:
70  fprintf(out, "\tAT ([%d:%d]", (int) tmpProd->qnameId.uriId, (int) tmpProd->qnameId.lnId);
71  fwrite(schema->uriTable.uri[tmpProd->qnameId.uriId].uriStr.str, sizeof(CharType), schema->uriTable.uri[tmpProd->qnameId.uriId].uriStr.length, out);
72  fprintf(out, ":");
73  fwrite(GET_LN_URI_QNAME(schema->uriTable, tmpProd->qnameId).lnStr.str, sizeof(CharType), GET_LN_URI_QNAME(schema->uriTable, tmpProd->qnameId).lnStr.length, out);
74  fprintf(out, ") ");
75  writeValueTypeString(out, exiType);
76  break;
77  case EVENT_AT_URI:
78  fprintf(out, "\tAT (uri) ");
79  break;
80  case EVENT_AT_ALL:
81  fprintf(out, "\tAT (*) ");
82  writeValueTypeString(out, exiType);
83  break;
84  case EVENT_CH:
85  fprintf(out, "\tCH ");
86  writeValueTypeString(out, exiType);
87  break;
88  case EVENT_NS:
89  fprintf(out, "\tNS ");
90  break;
91  case EVENT_CM:
92  fprintf(out, "\tCM ");
93  break;
94  case EVENT_PI:
95  fprintf(out, "\tPI ");
96  break;
97  case EVENT_DT:
98  fprintf(out, "\tDT ");
99  break;
100  case EVENT_ER:
101  fprintf(out, "\tER ");
102  break;
103  case EVENT_SC:
104  fprintf(out, "\tSC ");
105  break;
106  case EVENT_VOID:
107  fprintf(out, " ");
108  break;
109  default:
110  return EXIP_UNEXPECTED_ERROR;
111  }
113  {
114  fprintf(out, "\tNT-%u\t", (unsigned int) GET_PROD_NON_TERM(tmpProd->content));
115  }
116  fprintf(out, "%d\n", (int) prodIter);
117  }
118  fprintf(out, "\n");
119  }
120 
121  return EXIP_OK;
122 }
123 
124 static void writeValueTypeString(FILE* out, EXIType exiType)
125 {
126  switch(exiType)
127  {
128  case VALUE_TYPE_NONE:
129  fprintf(out, "[N/A] ");
130  break;
131  case VALUE_TYPE_STRING:
132  fprintf(out, "[str] ");
133  break;
134  case VALUE_TYPE_FLOAT:
135  fprintf(out, "[float] ");
136  break;
137  case VALUE_TYPE_DECIMAL:
138  fprintf(out, "[dec] ");
139  break;
141  case VALUE_TYPE_YEAR:
142  case VALUE_TYPE_DATE:
143  case VALUE_TYPE_MONTH:
144  case VALUE_TYPE_TIME:
145  fprintf(out, "[dateTime] ");
146  break;
147  case VALUE_TYPE_BOOLEAN:
148  fprintf(out, "[bool] ");
149  break;
150  case VALUE_TYPE_BINARY:
151  fprintf(out, "[bin] ");
152  break;
153  case VALUE_TYPE_LIST:
154  fprintf(out, "[list] ");
155  break;
156  case VALUE_TYPE_QNAME:
157  fprintf(out, "[qname] ");
158  break;
159  case VALUE_TYPE_UNTYPED:
160  fprintf(out, "[untyped] ");
161  break;
162  case VALUE_TYPE_INTEGER:
163  fprintf(out, "[int] ");
164  break;
166  fprintf(out, "[short] ");
167  break;
169  fprintf(out, "[uint] ");
170  break;
171  }
172 }
173 
174 errorCode recursiveTextGrammarOutput(QNameID qnameid, Index grIndex, EXIGrammar* gr, EXIPSchema* schema, FILE* out)
175 {
176  errorCode tmp_err_code = EXIP_UNEXPECTED_ERROR;
177  Index r, p;
178 
179  tmp_err_code = textGrammarOutput(qnameid, grIndex, gr, schema, out);
180  if(tmp_err_code != EXIP_OK)
181  return tmp_err_code;
182 
183  for(r = 0; r < gr->count; r++)
184  {
185  for(p = 0; p < gr->rule[r].pCount; p++)
186  {
188  gr->rule[r].production[p].typeId != INDEX_MAX)
189  {
190  tmp_err_code = recursiveTextGrammarOutput(gr->rule[r].production[p].qnameId, gr->rule[r].production[p].typeId, &schema->grammarTable.grammar[gr->rule[r].production[p].typeId], schema, out);
191  if(tmp_err_code != EXIP_OK)
192  return tmp_err_code;
193  }
194  }
195  }
196 
197  return EXIP_OK;
198 }
199