19 #include "grammarGenerator.h"
21 #define MAX_XSD_FILES_COUNT 10 // up to 10 XSD files
23 static void printfHelp();
24 static void parseSchema(
char* xsdList,
EXIPSchema* schema);
25 static void parseOpsMask(
char* mask,
EXIOptions* ops);
29 int main(
int argc,
char *argv[])
32 char sourceFileName[500];
37 boolean outOfBandOpts =
FALSE;
38 unsigned char outFlag =
OUT_EXI;
39 unsigned int argIndex = 1;
42 strcpy(sourceFileName,
"stdin");
47 if(strcmp(argv[argIndex],
"-help") == 0)
52 else if(strcmp(argv[argIndex],
"-exi") == 0)
63 else if(strcmp(argv[argIndex],
"-xml") == 0)
75 if(strstr(argv[argIndex],
"-ops") !=
NULL)
77 char *mask = argv[argIndex] + 4;
80 parseOpsMask(mask, &ops);
86 if(strstr(argv[argIndex],
"-schema") !=
NULL)
88 char *xsdList = argv[argIndex] + 7;
90 parseSchema(xsdList, &schema);
99 strcpy(sourceFileName, argv[argIndex]);
101 infile = fopen(sourceFileName,
"rb" );
104 fprintf(stderr,
"Unable to open file %s\n", sourceFileName);
111 if(schemaPtr !=
NULL)
117 printf(
"\nError (code: %d) during parsing of the EXI stream: %s\n", tmp_err_code, sourceFileName);
122 printf(
"\nSuccessful parsing of the EXI stream: %s\n", sourceFileName);
127 static void printfHelp()
130 printf(
" EXIP Copyright (c) 2010 - 2012, EISLAB - LuleƄ University of Technology Version 0.4 \n");
131 printf(
" Author: Rumen Kyusakov\n");
132 printf(
" Usage: exipd [options] [exi_in]\n\n");
133 printf(
" Options: [-help | [ -xml | -exi ] [-ops=<ops_mask>] -schema=<xsd_in>] \n");
134 printf(
" -schema : uses schema defined in <xsd_in> for decoding. All referenced schema files should be included in <xsd_in>\n");
135 printf(
" <xsd_in>: Comma-separated list of schema documents encoded in EXI with Preserve.prefixes. The first schema is the\n");
136 printf(
" main one and the rest are schemas that are referenced from the main one through the <xs:import> statement.\n");
137 printf(
" ops_mask: Specify out-of-band options used for encoding. Fields are delimited by %%.\n");
138 printf(
" Use this argument only for specifying out-of-band options. That is if no options are specified in the header of the <exi_in>\n");
139 printf(
" The format is: <1>%%<2>%%<3>%%<4>%%<5> where:\n");
140 printf(
" <1> - Preservation Options: c - comments, d - dtds, l - lexicalvalues, p - pis, x- prefixes. If none set then \"-\" \n");
141 printf(
" <2> - Other options: v - strict interpretation of schema, f - fragments\n");
142 printf(
" r - selfContained, c - compression, p - pre-compression, a - aligned to bytes. If none set then \"-\"\n");
143 printf(
" <3> - valuePartitionCapacity. If not set then \"-\"\n");
144 printf(
" <4> - valueMaxLength. If not set then \"-\"\n");
145 printf(
" <5> - blockSize. If not set then \"-\"\n");
146 printf(
" For example: cx%%v%%0%%-%%- sets the folowing options: Preservation of comments and prefixes, strict schema informed\n");
147 printf(
" and valuePartitionCapacity = 0\n");
148 printf(
" -exi : EXI formated output [default]\n");
149 printf(
" -xml : XML formated output\n");
150 printf(
" -help : Prints this help message\n\n");
151 printf(
" exi_in : input file containing the EXI stream (stdin if none specified)\n\n");
152 printf(
" Purpose: This program tests the EXIP decoding functionality. The result is printed on the stdout.\n");
158 FILE *infile = (FILE*) stream;
159 return fread(buf, 1, readSize, infile);
162 static void parseSchema(
char* xsdList,
EXIPSchema* schema)
167 char schemaFileName[500];
168 unsigned int schemaFilesCount = 0;
172 for (token = strtok(xsdList,
"=,"), i = 0; token !=
NULL; token = strtok(
NULL,
"=,"), i++)
177 fprintf(stderr,
"Too many xsd files given as an input: %d", schemaFilesCount);
181 strcpy(schemaFileName, token);
182 schemaFile = fopen(schemaFileName,
"rb" );
185 fprintf(stderr,
"Unable to open file %s", schemaFileName);
191 fseek(schemaFile, 0, SEEK_END);
192 buffer[i].
bufLen = ftell(schemaFile) + 1;
193 fseek(schemaFile, 0, SEEK_SET);
196 buffer[i].
buf = (
char *) malloc(buffer[i].bufLen);
199 fprintf(stderr,
"Memory allocation error!");
205 fread(buffer[i].buf, buffer[i].bufLen, 1, schemaFile);
217 for(i = 0; i < schemaFilesCount; i++)
224 printf(
"\nGrammar generation error occurred: %d", tmp_err_code);
229 static void parseOpsMask(
char* mask,
EXIOptions* ops)
234 for (token = strtok(mask,
"=%"), i = 0; token !=
NULL; token = strtok(
NULL,
"=%"), i++)
239 if(strcmp(token,
"-"))
242 if(strstr(token,
"c") !=
NULL)
244 if(strstr(token,
"d") !=
NULL)
246 if(strstr(token,
"l") !=
NULL)
248 if(strstr(token,
"p") !=
NULL)
250 if(strstr(token,
"x") !=
NULL)
255 if(strcmp(token,
"-"))
259 if(strstr(token,
"v") !=
NULL)
261 if(strstr(token,
"f") !=
NULL)
263 if(strstr(token,
"r") !=
NULL)
265 if(strstr(token,
"c") !=
NULL)
267 if(strstr(token,
"p") !=
NULL)
269 else if(strstr(token,
"a") !=
NULL)
274 if(strcmp(token,
"-"))
281 if(strcmp(token,
"-"))
288 if(strcmp(token,
"-"))
296 fprintf(stderr,
"Wrong options mask: %s", mask);