79 #include <sys/types.h> 96 static void usage(
void);
114 int main(
int argc,
char *argv[])
122 program = strrchr(argv[0],
'/');
130 memset(¶ms, 0,
sizeof(params));
133 while ((opt =
getopt(argc, argv,
"adhsv")) != EOF) {
169 printf(
"Try `%s -h' for a complete list of options.\n",
178 if (compiler == NULL) {
179 fprintf(stderr,
"wsc: could not create compiler\n");
183 for (i =
optind; i < argc; i++) {
187 ifp = fopen(argv[i],
"rb");
189 fprintf(stderr,
"wsc: could not open input file `%s': %s'\n",
190 argv[i], strerror(errno));
195 outname =
malloc(strlen(argv[i]) + 1 + 1);
196 if (outname == NULL) {
197 fprintf(stderr,
"wmlsc: could not create output file name: %s\n",
201 strcpy(outname, argv[i]);
202 strcat(outname,
"c");
204 ofp = fopen(outname,
"wb");
206 fprintf(stderr,
"wsc: could not create output file `%s': %s\n",
207 outname, strerror(errno));
215 unsigned char *output;
218 if (stat(argv[i], &stat_st) == -1) {
219 fprintf(stderr,
"wsc: could not stat input file `%s': %s\n",
220 argv[i], strerror(errno));
225 data =
malloc(stat_st.st_size);
227 fprintf(stderr,
"wsc: could not allocate input buffer: %s\n",
231 if (fread(data, 1, stat_st.st_size, ifp) < (
size_t) stat_st.st_size) {
232 fprintf(stderr,
"wsc: could not read data: %s\n",
237 &output, &output_len);
238 if (result ==
WS_OK) {
240 if (fwrite(output, 1, output_len, ofp) != output_len) {
242 "wsc: could not save output to file `%s': %s\n",
243 outname, strerror(errno));
258 if (result !=
WS_OK) {
260 fprintf(stderr,
"wsc: compilation failed: %s\n",
276 printf(
"Usage: %s OPTION... FILE...\n\ 278 -a disassemble resulting byte-code and print it to the\n\ 280 -d use ws_eval_data() function instead of ws_eval_file()\n\ 281 -h print this help message and exit successfully\n\ 282 -l encode strings in ISO-8859/1 (ISO latin1) instead of using\n\ 285 -s print symbolic byte-code assembler to the standard output\n\ 286 -v print verbose progress messages\n\ 302 fprintf(fp,
"%s: name=\"%s\", content=\"%s\",",
304 property_name_l ? property_name_l :
"",
305 content_l ? content_l :
"");
308 fprintf(fp,
", scheme=\"%s\"",
309 scheme_l ? scheme_l :
"");
static void pragma_meta(const WsUtf8String *property_name, const WsUtf8String *content, const WsUtf8String *scheme, void *context)
unsigned int print_symbolic_assembler
void ws_free_byte_code(unsigned char *byte_code)
WsResult ws_compile_file(WsCompilerPtr compiler, const char *input_name, FILE *input, FILE *output)
WsCompilerPtr ws_create(WsCompilerParams *params)
unsigned int use_latin1_strings
int getopt(int argc, char **argv, char *opts)
void ws_destroy(WsCompilerPtr compiler)
WsResult ws_compile_data(WsCompilerPtr compiler, const char *input_name, const unsigned char *input, size_t input_len, unsigned char **output_return, size_t *output_len_return)
void ws_utf8_free_data(unsigned char *data)
unsigned int print_assembler
void * meta_name_cb_context
WsPragmaMetaProc meta_name_cb
int main(int argc, char *argv[])
WsPragmaMetaProc meta_http_equiv_cb
const char * ws_result_to_string(WsResult result)
void * meta_http_equiv_cb_context
unsigned char * ws_utf8_to_latin1(const WsUtf8String *string, unsigned char unknown_char, size_t *len_return)