19 #include "grammarGenerator.h"
21 #define MAX_XSD_FILES_COUNT 10 // up to 10 XSD files
25 #define OUT_SRC_STAT 3
27 static void printfHelp();
28 static void parseSchema(
char* xsdList,
EXIPSchema* schema,
unsigned char mask,
EXIOptions maskOpt);
30 int main(
int argc,
char *argv[])
32 FILE *outfile = stdout;
34 unsigned char outputFormat =
OUT_EXIP;
38 unsigned char mask =
FALSE;
53 if(strcmp(argv[argIndex],
"-help") == 0)
58 else if(strcmp(argv[argIndex],
"-exip") == 0)
63 else if(strcmp(argv[argIndex],
"-text") == 0)
68 else if(strcmp(argv[argIndex],
"-dynamic") == 0)
73 else if(strlen(argv[argIndex]) >= 7 &&
74 argv[argIndex][0] ==
'-' &&
75 argv[argIndex][1] ==
's' &&
76 argv[argIndex][2] ==
't' &&
77 argv[argIndex][3] ==
'a' &&
78 argv[argIndex][4] ==
't' &&
79 argv[argIndex][5] ==
'i' &&
80 argv[argIndex][6] ==
'c')
83 if(strlen(argv[argIndex]) >= 15 && argv[argIndex][7] ==
'=' )
87 dvis.
url = (int) strtol (argv[argIndex] + 8, &pEnd, 10);
88 dvis.
ln = (int) strtol (pEnd + 1, &pEnd, 10);
89 dvis.
pfx = (int) strtol (pEnd + 1, &pEnd, 10);
101 if(strlen(argv[argIndex]) >= 5 &&
102 argv[argIndex][0] ==
'-' &&
103 argv[argIndex][1] ==
'p' &&
104 argv[argIndex][2] ==
'f' &&
105 argv[argIndex][3] ==
'x' &&
106 argv[argIndex][4] ==
'=')
108 strcpy(prefix, argv[argIndex] + 5);
113 strcpy(prefix,
"prfx_");
122 if(strlen(argv[argIndex]) >= 5 &&
123 argv[argIndex][0] ==
'-' &&
124 argv[argIndex][1] ==
'o' &&
125 argv[argIndex][2] ==
'p' &&
126 argv[argIndex][3] ==
's' &&
127 argv[argIndex][4] ==
'=')
130 if(argv[argIndex][5] ==
'1')
133 if(argv[argIndex][6] ==
'1')
136 if(argv[argIndex][7] ==
'1')
139 if(argv[argIndex][8] ==
'1')
142 if(argv[argIndex][9] ==
'1')
145 if(argv[argIndex][10] ==
'1')
148 if(argv[argIndex][11] ==
'1')
160 if(strstr(argv[argIndex],
"-schema") !=
NULL)
162 char *xsdList = argv[argIndex] + 7;
164 parseSchema(xsdList, &schema, mask, maskOpt);
176 outfile = fopen(argv[argIndex],
"wb" );
179 fprintf(stderr,
"Unable to open file %s", argv[argIndex]);
188 tmp_err_code =
toText(&schema, outfile);
191 tmp_err_code =
toEXIP(&schema, outfile);
194 tmp_err_code =
toStaticSrc(&schema, prefix, outfile, dvis);
197 tmp_err_code =
toDynSrc(&schema, outfile);
200 printf(
"\nUnsupported output format!");
211 printf(
"\nError during grammar output!");
218 static void printfHelp()
221 printf(
" EXIP Copyright (c) 2010 - 2012, EISLAB - LuleƄ University of Technology Version 0.5.1 \n");
222 printf(
" Author: Rumen Kyusakov\n");
223 printf(
" Usage: exipg [options] -schema=<xsd_in> [grammar_out] \n\n");
224 printf(
" Options: [-help | [[-exip | -text | -dynamic | -static[=<deviations>]] [-pfx=<prefix>] [-ops=<ops_mask>]] ] \n");
225 printf(
" -help : Prints this help message\n");
226 printf(
" -exip : Format the output schema definitions in EXIP-specific format (Default)\n");
227 printf(
" -text : Format the output schema definitions in human readable text format\n");
228 printf(
" -dynamic : Create C code for the grammars defined. The output is a C function that dynamically generates the grammars\n");
229 printf(
" -static : Create C code for the grammars defined. The output is C structures describing the grammars\n");
230 printf(
" deviations : When static C code is chosen for the output, this defines a static size of the possible extensions\n");
231 printf(
" for URI, Local names, prefixes, and build-in grammars. The format is: <uri>:<ln>:<pfx>:<grammars>\n");
232 printf(
" For example deviations -static=2:5:1:10 will allow for two non-schema namespaces, 5 new local names\n");
233 printf(
" per each schema namespace, 1 additional prefix per namespace, and 10 new built-in grammars.\n");
234 printf(
" The larger deviations the more memory is required.\n");
235 printf(
" -pfx : When in -dynamic or -static mode, this option allows you to specify a unique prefix for the\n");
236 printf(
" generated global types. The default is \"prfx_\"\n");
237 printf(
" ops_mask : The format is: <STRICT><SELF_CONTAINED><dtd><prefixes><lexicalValues><comments><pis> := <0|1><0|1><0|1><0|1><0|1><0|1><0|1>\n");
238 printf(
" Use this argument only for specifying out-of-band options. That is if no options are specified in the header of the <xsd_in>\n");
239 printf(
" EXI encoded schema files but some options are used during encoding.\n");
240 printf(
" This argument is useful for generating the \"EXI Options\" grammar where STRICT is set and the rest are default options. \n");
241 printf(
" In this way the bootstrapping of the code is easier. The mask to use for EXIOptions-xsd.exi is -ops=0001000 \n");
242 printf(
" -schema : The source schema definitions - all referenced schema files should be included in <xsd_in>\n");
243 printf(
" xsd_in : Comma-separated list of schema documents encoded in EXI with Preserve.prefixes. The first schema is the main one and\n");
244 printf(
" the rest are schemas that are referenced from the main one through the <xs:import> statement.\n");
245 printf(
" grammar_out : Destination file for the grammar output (Default is the standard output) \n\n");
246 printf(
" Purpose: Manipulation of EXIP schemas\n");
250 static void parseSchema(
char* xsdList,
EXIPSchema* schema,
unsigned char mask,
EXIOptions maskOpt)
255 char schemaFileName[50];
256 unsigned int schemaFilesCount = 0;
264 for (token = strtok(xsdList,
"=,"), i = 0; token !=
NULL; token = strtok(
NULL,
"=,"), i++)
269 fprintf(stderr,
"Too many xsd files given as an input: %d", schemaFilesCount);
273 strcpy(schemaFileName, token);
274 schemaFile = fopen(schemaFileName,
"rb" );
277 fprintf(stderr,
"Unable to open file %s", schemaFileName);
283 fseek(schemaFile, 0, SEEK_END);
284 buffer[i].
bufLen = ftell(schemaFile) + 1;
285 fseek(schemaFile, 0, SEEK_SET);
288 buffer[i].
buf = (
char *) malloc(buffer[i].bufLen);
291 fprintf(stderr,
"Memory allocation error!");
297 fread(buffer[i].buf, buffer[i].bufLen, 1, schemaFile);
309 for(i = 0; i < schemaFilesCount; i++)
316 printf(
"\nGrammar generation error occurred: %d", tmp_err_code);