19 #include "grammarGenerator.h"
21 #define MAX_XSD_FILES_COUNT 10 // up to 10 XSD files
23 static void printfHelp();
25 static void parseSchema(
char* xsdList,
EXIPSchema* schema);
27 int main(
int argc,
char *argv[])
30 FILE *outfile = stdout;
36 strcpy(sourceFile,
"stdout");
40 if(strcmp(argv[argIndex],
"-help") == 0)
45 else if(strstr(argv[argIndex],
"-schema") !=
NULL)
49 char* xsdList = argv[argIndex] + 7;
51 parseSchema(xsdList, &schema);
60 strcpy(sourceFile, argv[argIndex]);
62 outfile = fopen(sourceFile,
"wb" );
65 fprintf(stderr,
"Unable to open file %s", sourceFile);
76 printf(
"\nError (code: %d) during encoding of: %s\n", tmp_err_code, sourceFile);
78 printf(
"\nSuccessful encoding in %s\n", sourceFile);
85 static void printfHelp()
88 printf(
" EXIP Copyright (c) 2010 - 2012, EISLAB - LuleƄ University of Technology Version 0.4 \n");
89 printf(
" Author: Rumen Kyusakov\n");
90 printf(
" Usage: exipe [options] [exi_out]\n\n");
91 printf(
" Options: [-help | -schema=<xsd_in>] \n");
92 printf(
" -schema : uses schema defined in <xsd_in> for encoding. All referenced schema files should be included in <xsd_in>\n");
93 printf(
" <xsd_in>: Comma-separated list of schema documents encoded in EXI with Preserve.prefixes. The first schema is the\n");
94 printf(
" main one and the rest are schemas that are referenced from the main one through the <xs:import> statement.\n");
95 printf(
" -help : Prints this help message\n\n");
96 printf(
" exi_out : output file for the EXI stream (stdout if none specified)\n\n");
97 printf(
" Purpose: This program tests the EXIP encoding functionality\n");
103 FILE *outfile = (FILE*) stream;
104 return fwrite(buf, 1, readSize, outfile);
107 static void parseSchema(
char* xsdList,
EXIPSchema* schema)
112 char schemaFileName[500];
113 unsigned int schemaFilesCount = 0;
117 for (token = strtok(xsdList,
"=,"), i = 0; token !=
NULL; token = strtok(
NULL,
"=,"), i++)
122 fprintf(stderr,
"Too many xsd files given as an input: %d", schemaFilesCount);
126 strcpy(schemaFileName, token);
127 schemaFile = fopen(schemaFileName,
"rb" );
130 fprintf(stderr,
"Unable to open file %s", schemaFileName);
136 fseek(schemaFile, 0, SEEK_END);
137 buffer[i].
bufLen = ftell(schemaFile) + 1;
138 fseek(schemaFile, 0, SEEK_SET);
141 buffer[i].
buf = (
char *) malloc(buffer[i].bufLen);
144 fprintf(stderr,
"Memory allocation error!");
150 fread(buffer[i].buf, buffer[i].bufLen, 1, schemaFile);
162 for(i = 0; i < schemaFilesCount; i++)
169 printf(
"\nGrammar generation error occurred: %d", tmp_err_code);