40 #include "procTypes.h"
41 #include "EXISerializer.h"
42 #include "EXIParser.h"
43 #include "stringManipulate.h"
44 #include "grammarGenerator.h"
46 #define OUTPUT_BUFFER_SIZE 64*1024
47 #define check(str) if (tmp_err_code != EXIP_OK) { printf (" =====> Err line %d (%s) code:%d\n", __LINE__, str, tmp_err_code); exit(0); }
49 static int parseSchema(
char* xsdList,
EXIPSchema* schema);
51 char *
XSI =
"http://www.w3.org/2001/XMLSchema-instance";
52 char *
XS =
"http://www.w3.org/2001/XMLSchema";
53 char *
M2M =
"http://uri.etsi.org/m2m";
56 static errorCode sample_fatalError(
const errorCode code,
const char* msg,
void* app_data);
57 static errorCode sample_startDocument(
void* app_data);
58 static errorCode sample_endDocument(
void* app_data);
60 static errorCode sample_endElement(
void* app_data);
66 static errorCode sample_booleanData(
boolean bool_val,
void* app_data);
68 static errorCode sample_binaryData(
const char* binary_val,
Index nbytes,
void* app_data);
69 static errorCode sample_qnameData(
const QName qname,
void* app_data);
71 int main(
int ac,
char **av) {
76 QName qname= {&uri, &ln};
90 if (ac == 2 && !strcmp(av[1],
"-s")) {
91 strcpy (files,
"common.exs,subscription.exs,contentInstances.exs,contentInstance.exs,mime.exs");
94 if (*files && parseSchema(files, &schema) == 0) {
105 printf (
"schemaId %s\n",
"subscription");
115 printf (
"### startElement %s:%s\n",
M2M,
"subscription");
120 printf (
"### startElement %s:%s\n",
M2M,
"filterCriteria");
125 printf (
"### attribute %s:%s\n",
XSI,
"type");
130 printf (
"### qnameData %s:%s\n",
M2M,
"ContentInstanceFilterCriteriaType");
133 tmp_err_code +=
serialize.
qnameData(&testStrm, qname);
check(
"qnameData m2m:ContentInstanceFilterCriteriaType")
136 printf (
"### startElement %s:%s valueType=%d\n",
"",
"creator", valueType);
141 printf (
"### stringData %s\n",
"http://www.creator.org");
159 printf (
"START PARSING\n");
202 printf (
"PARSING SUCCESS\n");
204 printf (
"tmp_err_code = %d\n", tmp_err_code);
209 static void printURI(
const String *str) {
221 printURI (qname.
uri);
226 static errorCode sample_fatalError(
const errorCode code,
const char* msg,
void* app_data)
228 printf(
"\n%d : FATAL ERROR: %s\n", code, msg);
232 static errorCode sample_startDocument(
void* app_data)
238 static errorCode sample_endDocument(
void* app_data)
252 static errorCode sample_endElement(
void* app_data)
265 expectAttributeData = 1;
271 if(expectAttributeData)
275 expectAttributeData = 0;
294 if(expectAttributeData)
296 sprintf(tmp_buf,
"%lld", (
long long int) int_val);
297 printf(
"intData %s", tmp_buf);
299 expectAttributeData = 0;
304 sprintf(tmp_buf,
"%lld", (
long long int) int_val);
305 printf(
"%s", tmp_buf);
311 static errorCode sample_booleanData(
boolean bool_val,
void* app_data)
326 static errorCode sample_binaryData(
const char* binary_val,
Index nbytes,
void* app_data)
331 static errorCode sample_qnameData(
const QName qname,
void* app_data)
335 printf (
"qnameData : ");
338 expectAttributeData = 0;
344 #define MAX_XSD_FILES_COUNT 10 // up to 10 XSD files
346 static int parseSchema(
char* xsdList,
EXIPSchema* schema)
351 char schemaFileName[50];
352 unsigned int schemaFilesCount = 0;
356 for (token = strtok(xsdList,
"=,"), i = 0; token !=
NULL; token = strtok(
NULL,
"=,"), i++)
358 printf (
"%d %s\n", i, token);
362 fprintf(stderr,
"Too many xsd files given as an input: %d", schemaFilesCount);
366 strcpy(schemaFileName, token);
367 schemaFile = fopen(schemaFileName,
"rb" );
370 fprintf(stderr,
"Unable to open file %s", schemaFileName);
376 fseek(schemaFile, 0, SEEK_END);
377 buffer[i].
bufLen = ftell(schemaFile) + 1;
378 fseek(schemaFile, 0, SEEK_SET);
381 buffer[i].
buf = (
char *) malloc(buffer[i].bufLen);
384 fprintf(stderr,
"Memory allocation error!");
390 fread(buffer[i].buf, buffer[i].bufLen, 1, schemaFile);
402 for(i = 0; i < schemaFilesCount; i++)
408 printf(
"\nGrammar generation error occurred: %d\n", tmp_err_code);
410 printf(
"Grammar generation SUCCESS\n");