17 #include "EXIParser.h"
18 #include "stringManipulate.h"
19 #include "grammarGenerator.h"
23 static void printfHelp();
24 static void parseSchema(
char** fileNames,
unsigned int schemaFilesCount,
EXIPSchema* schema);
28 #define INPUT_BUFFER_SIZE 200
29 #define MAX_PREFIXES 10
30 #define MAX_XSD_FILES_COUNT 10 // up to 10 XSD files
54 static void destroyElement(
struct element* el);
57 static char lookupPrefix(
struct appData* aData,
String ns,
unsigned char* prxHit,
unsigned char* prefixIndex);
62 static char sample_fatalError(
const char code,
const char* msg,
void* app_data);
63 static char sample_startDocument(
void* app_data);
64 static char sample_endDocument(
void* app_data);
65 static char sample_startElement(
QName qname,
void* app_data);
66 static char sample_endElement(
void* app_data);
67 static char sample_attribute(
QName qname,
void* app_data);
68 static char sample_stringData(
const String value,
void* app_data);
69 static char sample_decimalData(
Decimal value,
void* app_data);
70 static char sample_intData(
Integer int_val,
void* app_data);
71 static char sample_floatData(
Float fl_val,
void* app_data);
72 static char sample_booleanData(
unsigned char bool_val,
void* app_data);
73 static char sample_dateTimeData(
EXIPDateTime dt_val,
void* app_data);
74 static char sample_binaryData(
const char* binary_val,
Index nbytes,
void* app_data);
78 int main(
int argc,
char *argv[])
81 char sourceFileName[100];
85 unsigned int argIndex = 1;
91 if(strcmp(argv[argIndex],
"-help") == 0)
96 else if(strcmp(argv[argIndex],
"-exi") == 0)
107 else if(strcmp(argv[argIndex],
"-xml") == 0)
119 if(strcmp(argv[argIndex],
"-schema") == 0)
121 if(argc <= argIndex + 2)
128 unsigned int schemaFilesCount = 0;
130 schemaFilesCount = argc - argIndex - 2;
134 parseSchema(argv + argIndex, schemaFilesCount, &schema);
137 argIndex += schemaFilesCount;
141 strcpy(sourceFileName, argv[argIndex]);
143 infile = fopen(sourceFileName,
"rb" );
146 fprintf(stderr,
"Unable to open file %s", sourceFileName);
166 tmp_err_code =
initParser(&testParser, buffer, schemaPtr, &parsingData);
206 if(schemaPtr !=
NULL)
214 printf(
"\nError during parsing of the EXI stream: %d", tmp_err_code);
227 static void printfHelp()
230 printf(
" EXIP Copyright (c) 2010 - 2012, EISLAB - LuleƄ University of Technology Version 0.4 \n");
231 printf(
" Authors: Rumen Kyusakov\n");
232 printf(
" Usage: exipd [options] <EXI_FileIn>\n\n");
233 printf(
" Options: [-help | [ -xml | -exi ] -schema <schema_files_in>] \n");
234 printf(
" -schema : uses schema defined in <schema_files_in> for decoding\n");
235 printf(
" -exi : EXI formated output [default]\n");
236 printf(
" -xml : XML formated output\n");
237 printf(
" -help : Prints this help message\n\n");
238 printf(
" Purpose: This program tests the EXIP decoding functionality\n");
242 static char sample_fatalError(
const char code,
const char* msg,
void* app_data)
244 printf(
"\n%d : FATAL ERROR: %s\n", code, msg);
248 static char sample_startDocument(
void* app_data)
254 printf(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
256 return EXIP_HANDLER_OK;
259 static char sample_endDocument(
void* app_data)
267 return EXIP_HANDLER_OK;
270 static char sample_startElement(
QName qname,
void* app_data)
284 unsigned char prefixIndex = 0;
285 unsigned char prxHit = 1;
290 error = lookupPrefix(appD, *qname.
uri, &prxHit, &prefixIndex);
294 sprintf(appD->
nameBuf,
"p%d:", prefixIndex);
311 sprintf(appD->
nameBuf,
" xmlns:p%d=\"", prefixIndex);
320 return EXIP_HANDLER_OK;
323 static char sample_endElement(
void* app_data)
335 el = pop(&(appD->
stack));
336 printf(
"</%s>\n", el->
name);
340 return EXIP_HANDLER_OK;
343 static char sample_attribute(
QName qname,
void* app_data)
367 return EXIP_HANDLER_OK;
370 static char sample_stringData(
const String value,
void* app_data)
406 return EXIP_HANDLER_OK;
409 static char sample_decimalData(
Decimal value,
void* app_data)
416 printf(
"%.1f\"\n", (
double) value);
421 printf(
"CH %.1f \n", (
double) value);
428 printf(
"%.1f \"", (
double) value);
436 printf(
"%.1f \n", (
double) value);
440 return EXIP_HANDLER_OK;
443 static char sample_intData(
Integer int_val,
void* app_data)
451 sprintf(tmp_buf,
"%lld", (
long long int) int_val);
452 printf(
"%s", tmp_buf);
459 sprintf(tmp_buf,
"%lld", (
long long int) int_val);
460 printf(
"%s", tmp_buf);
468 sprintf(tmp_buf,
"%lld", (
long long int) int_val);
469 printf(
"%s", tmp_buf);
478 sprintf(tmp_buf,
"%lld", (
long long int) int_val);
479 printf(
"%s", tmp_buf);
484 return EXIP_HANDLER_OK;
487 static char sample_booleanData(
unsigned char bool_val,
void* app_data)
534 return EXIP_HANDLER_OK;
537 static char sample_floatData(
Float fl_val,
void* app_data)
545 sprintf(tmp_buf,
"%lldE%d", (
long long int) fl_val.mantissa, fl_val.exponent);
546 printf(
"%s", tmp_buf);
553 sprintf(tmp_buf,
"%lldE%d", (
long long int) fl_val.mantissa, fl_val.exponent);
554 printf(
"%s", tmp_buf);
562 sprintf(tmp_buf,
"%lldE%d", (
long long int) fl_val.mantissa, fl_val.exponent);
563 printf(
"%s", tmp_buf);
572 sprintf(tmp_buf,
"%lldE%d", (
long long int) fl_val.mantissa, fl_val.exponent);
573 printf(
"%s", tmp_buf);
578 return EXIP_HANDLER_OK;
581 static char sample_dateTimeData(
EXIPDateTime dt_val,
void* app_data)
597 tmpfValue = tmpfValue / 10;
599 for(i = 0; i < dt_val.
fSecs.
offset + 1 - digitNum; i++)
602 sprintf(fsecBuf + 1 + i,
"%d", dt_val.
fSecs.
value);
613 printf(
"%04d-%02d-%02dT%02d:%02d:%02d%s", dt_val.
dateTime.tm_year + 1900,
623 printf(
"%04d-%02d-%02dT%02d:%02d:%02d%s", dt_val.
dateTime.tm_year + 1900,
634 printf(
"%04d-%02d-%02dT%02d:%02d:%02d%s", dt_val.
dateTime.tm_year + 1900,
646 printf(
"%04d-%02d-%02dT%02d:%02d:%02d%s", dt_val.
dateTime.tm_year + 1900,
654 return EXIP_HANDLER_OK;
657 static char sample_binaryData(
const char* binary_val,
Index nbytes,
void* app_data)
665 printf(
"[binary: %d bytes]", (
int) nbytes);
672 printf(
"[binary: %d bytes]", (
int) nbytes);
680 printf(
"[binary: %d bytes]", (
int) nbytes);
689 printf(
"[binary: %d bytes]", (
int) nbytes);
694 return EXIP_HANDLER_OK;
718 *stack = (*stack)->
next;
726 el = malloc(
sizeof(
struct element));
730 el->
name = malloc(strlen(name)+1);
733 strcpy(el->
name, name);
737 static void destroyElement(
struct element* el)
746 FILE *infile = (FILE*) stream;
747 return fread(buf, 1, readSize, infile);
750 static void parseSchema(
char** fileNames,
unsigned int schemaFilesCount,
EXIPSchema* schema)
759 fprintf(stderr,
"Too many xsd files given as an input: %d", schemaFilesCount);
763 for(i = 0; i < schemaFilesCount; i++)
765 schemaFile = fopen(fileNames[i],
"rb" );
768 fprintf(stderr,
"Unable to open file %s", fileNames[i]);
774 fseek(schemaFile, 0, SEEK_END);
775 buffer[i].
bufLen = ftell(schemaFile) + 1;
776 fseek(schemaFile, 0, SEEK_SET);
779 buffer[i].
buf = (
char *) malloc(buffer[i].bufLen);
782 fprintf(stderr,
"Memory allocation error!");
788 fread(buffer[i].buf, buffer[i].bufLen, 1, schemaFile);
800 printf(
"\n Error occured: %d", tmp_err_code);
804 for(i = 0; i < schemaFilesCount; i++)
810 static char lookupPrefix(
struct appData* aData,
String ns,
unsigned char* prxHit,
unsigned char* prefixIndex)