16 #include "procTypes.h"
17 #include "EXISerializer.h"
18 #include "EXIParser.h"
19 #include "stringManipulate.h"
20 #include "grammarGenerator.h"
22 #define OUTPUT_BUFFER_SIZE 2000
23 #define check(str) if (tmp_err_code != EXIP_OK) { printf (" =====> Err line %d (%s) code:%d\n", __LINE__, str, tmp_err_code); exit(0); }
25 static int parseSchema(
char* xsdList,
EXIPSchema* schema);
27 char *
XSI =
"http://www.w3.org/2001/XMLSchema-instance";
28 char *
XS =
"http://www.w3.org/2001/XMLSchema";
29 char *
EXEMPLE =
"http://www.exemple.com/XMLNameSpace";
32 static errorCode sample_fatalError(
const errorCode code,
const char* msg,
void* app_data);
33 static errorCode sample_startDocument(
void* app_data);
34 static errorCode sample_endDocument(
void* app_data);
36 static errorCode sample_endElement(
void* app_data);
42 static errorCode sample_booleanData(
boolean bool_val,
void* app_data);
44 static errorCode sample_binaryData(
const char* binary_val,
Index nbytes,
void* app_data);
45 static errorCode sample_qnameData(
const QName qname,
void* app_data);
47 int main(
int ac,
char **av) {
52 QName qname= {&uri, &ln};
59 char files[1000] =
"";
61 while ((opt = getopt(ac, av,
"s")) != -1) {
64 strcpy (files,
"Product.exs");
69 printf (
"### %s\n", av[0]);
77 if (*files && parseSchema(files, &schema) == 0) {
90 printf (
"### schemaId %s\n",
"product");
97 printf (
"### startElement %s:%s\n",
EXEMPLE,
"product");
102 printf (
"### startElement %s:%s\n",
EXEMPLE,
"subproduct");
107 printf (
"### attribute %s:%s\n",
XSI,
"type");
112 printf (
"### qnameData %s:%s\n",
EXEMPLE,
"ShirtType");
117 printf (
"### startElement %s:%s valueType=%d\n",
"",
"number", valueType);
123 printf (
"### intData %s\n",
"12345");
127 printf (
"### stringData %s\n",
"12345");
135 printf (
"### startElement %s:%s valueType=%d\n",
"",
"size", valueType);
141 printf (
"### intData %s\n",
"33");
145 printf (
"### stringData %s\n",
"33");
168 printf (
"### START PARSING\n");
211 printf (
"### PARSING SUCCESS\n");
213 printf (
"### tmp_err_code = %d\n", tmp_err_code);
218 static void printURI(
const String *str) {
230 printURI (qname.
uri);
235 static errorCode sample_fatalError(
const errorCode code,
const char* msg,
void* app_data)
237 printf(
"\n### %d : FATAL ERROR: %s\n", code, msg);
241 static errorCode sample_startDocument(
void* app_data)
247 static errorCode sample_endDocument(
void* app_data)
261 static errorCode sample_endElement(
void* app_data)
274 expectAttributeData = 1;
280 if(expectAttributeData)
284 expectAttributeData = 0;
303 if(expectAttributeData)
305 sprintf(tmp_buf,
"%lld", (
long long int) int_val);
306 printf(
"### intData %s", tmp_buf);
308 expectAttributeData = 0;
312 printf(
"### intData ");
313 sprintf(tmp_buf,
"%lld", (
long long int) int_val);
314 printf(
"%s", tmp_buf);
320 static errorCode sample_booleanData(
boolean bool_val,
void* app_data)
335 static errorCode sample_binaryData(
const char* binary_val,
Index nbytes,
void* app_data)
340 static errorCode sample_qnameData(
const QName qname,
void* app_data)
344 printf (
"### qnameData : ");
347 expectAttributeData = 0;
353 #define MAX_XSD_FILES_COUNT 10 // up to 10 XSD files
355 static int parseSchema(
char* xsdList,
EXIPSchema* schema)
360 char schemaFileName[50];
361 unsigned int schemaFilesCount = 0;
365 for (token = strtok(xsdList,
"=,"), i = 0; token !=
NULL; token = strtok(
NULL,
"=,"), i++)
367 printf (
"### %d %s\n", i, token);
371 fprintf(stderr,
"Too many xsd files given as an input: %d", schemaFilesCount);
375 strcpy(schemaFileName, token);
376 schemaFile = fopen(schemaFileName,
"rb" );
379 fprintf(stderr,
"Unable to open file %s", schemaFileName);
385 fseek(schemaFile, 0, SEEK_END);
386 buffer[i].
bufLen = ftell(schemaFile) + 1;
387 fseek(schemaFile, 0, SEEK_SET);
390 buffer[i].
buf = (
char *) malloc(buffer[i].bufLen);
393 fprintf(stderr,
"Memory allocation error!");
399 fread(buffer[i].buf, buffer[i].bufLen, 1, schemaFile);
411 for(i = 0; i < schemaFilesCount; i++)
417 printf(
"\n### Grammar generation error occurred: %d\n", tmp_err_code);
419 printf(
"### Grammar generation SUCCESS\n");