test_si.c
资源名称:gateway-1.2.1 [点击查看]
上传用户:gzpyjq
上传日期:2013-01-31
资源大小:1852k
文件大小:2k
源码类别:
手机WAP编程
开发平台:
WINDOWS
- /*
- * test_si.c: A simple program to test si tokenizer
- *
- * By Aarno Syv鋘en for Wiral Ltd
- */
- #include <stdio.h>
- #include "gwlib/gwlib.h"
- #include "gw/wap_push_si_compiler.h"
- Octstr *charset = NULL;
- Octstr *file_name = NULL;
- static void help (void)
- {
- info(0, "Usage test_si [option] si_source");
- info(0, "where options are");
- info(0, "-h print this text");
- info(0, "-f file output binary to the file");
- info(0, "-c charset charset given by http");
- info(0, "-v level set log level for stderr logging");
- }
- int main(int argc, char **argv)
- {
- int opt,
- file,
- have_charset,
- ret;
- FILE *fp;
- Octstr *output,
- *si_doc,
- *si_binary;
- gwlib_init();
- file = 0;
- have_charset = 0;
- fp = NULL;
- while ((opt = getopt(argc, argv, "hf:c:v:")) != EOF) {
- switch (opt) {
- case 'h':
- help();
- exit(1);
- break;
- case 'f':
- file = 1;
- file_name = octstr_create(optarg);
- fp = fopen(optarg, "a");
- if (fp == NULL)
- panic(0, "Cannot open output file");
- break;
- case 'c':
- have_charset = 1;
- charset = octstr_create(optarg);
- break;
- case 'v':
- log_set_output_level(atoi(optarg));
- break;
- case '?':
- default:
- error(0, "Invalid option %c", opt);
- help();
- panic(0, "Stopping");
- break;
- }
- }
- if (optind >= argc) {
- error(0, "Missing arguments");
- help();
- panic(0, "Stopping");
- }
- si_doc = octstr_read_file(argv[optind]);
- if (si_doc == NULL)
- panic(0, "Cannot read the si document");
- if (!have_charset)
- charset = NULL;
- ret = si_compile(si_doc, charset, &si_binary);
- output = octstr_format("%s", "si compiler returned %dn", ret);
- if (ret == 0) {
- if (fp == NULL)
- fp = stdout;
- octstr_append(output, octstr_imm("content beingn"));
- octstr_append(output, si_binary);
- }
- if (file)
- octstr_pretty_print(fp, output);
- else {
- debug("test.si", 0, "si binary was");
- octstr_dump(si_binary, 0);
- }
- if (have_charset)
- octstr_destroy(charset);
- if (file) {
- fclose(fp);
- octstr_destroy(file_name);
- }
- octstr_destroy(si_doc);
- octstr_destroy(si_binary);
- octstr_destroy(output);
- gwlib_shutdown();
- return 0;
- }