00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 #include <stdio.h>
00064
00065 #include "gwlib/gwlib.h"
00066 #include "gw/wap_push_sl_compiler.h"
00067
00068 Octstr *charset = NULL;
00069 Octstr *file_name = NULL;
00070
00071 static void help (void)
00072 {
00073 info(0, "Usage test_sl [option] sl_source");
00074 info(0, "where options are");
00075 info(0, "-h print this text");
00076 info(0, "-f file output binary to the file");
00077 info(0, "-c charset charset given by http");
00078 info(0, "-v level set log level for stderr logging");
00079 }
00080
00081 int main(int argc, char **argv)
00082 {
00083 int opt,
00084 file,
00085 have_charset,
00086 ret;
00087 FILE *fp;
00088 Octstr *output,
00089 *sl_doc,
00090 *sl_binary;
00091
00092 gwlib_init();
00093 file = 0;
00094 have_charset = 0;
00095 fp = NULL;
00096
00097 while ((opt = getopt(argc, argv, "hf:c:v:")) != EOF) {
00098 switch (opt) {
00099 case 'h':
00100 help();
00101 exit(1);
00102 break;
00103
00104 case 'f':
00105 file = 1;
00106 file_name = octstr_create(optarg);
00107 fp = fopen(optarg, "a");
00108 if (fp == NULL)
00109 panic(0, "Cannot open output file");
00110 break;
00111
00112 case 'c':
00113 have_charset = 1;
00114 charset = octstr_create(optarg);
00115 break;
00116
00117 case 'v':
00118 log_set_output_level(atoi(optarg));
00119 break;
00120
00121 case '?':
00122 default:
00123 error(0, "Invalid option %c", opt);
00124 help();
00125 panic(0, "Stopping");
00126 break;
00127 }
00128 }
00129
00130 if (optind >= argc) {
00131 error(0, "Missing arguments");
00132 help();
00133 panic(0, "Stopping");
00134 }
00135
00136 sl_doc = octstr_read_file(argv[optind]);
00137 if (sl_doc == NULL)
00138 panic(0, "Cannot read the sl document");
00139
00140 if (!have_charset)
00141 charset = NULL;
00142 ret = sl_compile(sl_doc, charset, &sl_binary);
00143 output = octstr_format("%s", "sl compiler returned %d\n", ret);
00144
00145 if (ret == 0) {
00146 if (fp == NULL)
00147 fp = stdout;
00148 octstr_append(output, octstr_imm("content being\n"));
00149 octstr_append(output, sl_binary);
00150 }
00151
00152 if (file)
00153 octstr_pretty_print(fp, output);
00154 else {
00155 debug("test.sl", 0, "sl binary was");
00156 octstr_dump(sl_binary, 0);
00157 }
00158
00159 if (have_charset)
00160 octstr_destroy(charset);
00161 if (file) {
00162 fclose(fp);
00163 octstr_destroy(file_name);
00164 }
00165
00166 octstr_destroy(sl_doc);
00167 octstr_destroy(sl_binary);
00168 octstr_destroy(output);
00169 gwlib_shutdown();
00170 return 0;
00171 }
00172
00173
00174
00175
00176
See file LICENSE for details about the license agreement for using,
modifying, copying or deriving work from this software.