Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

test_si.c File Reference

#include <stdio.h>
#include "gwlib/gwlib.h"
#include "gw/wap_push_si_compiler.h"

Include dependency graph for test_si.c:

Include dependency graph

Go to the source code of this file.

Functions

void help (void)
int main (int argc, char **argv)

Variables

Octstrcharset = NULL
Octstrfile_name = NULL


Function Documentation

void help void   )  [static]
 

Definition at line 71 of file test_si.c.

References info().

00072 {
00073     info(0, "Usage test_si [option] si_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 }

Here is the call graph for this function:

int main int  argc,
char **  argv
 

Definition at line 81 of file test_si.c.

References charset, debug(), error(), file, file_name, getopt(), gwlib_init(), gwlib_shutdown(), help(), log_set_output_level(), octstr_append(), octstr_create, octstr_destroy(), octstr_dump, octstr_format(), octstr_imm(), octstr_pretty_print(), octstr_read_file(), optarg, optind, panic, and si_compile().

00082 {
00083     int opt,
00084         file,
00085         have_charset,
00086         ret;
00087     FILE *fp;
00088     Octstr *output,
00089            *si_doc,
00090            *si_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     si_doc = octstr_read_file(argv[optind]);
00137     if (si_doc == NULL)
00138         panic(0, "Cannot read the si document");
00139 
00140     if (!have_charset)
00141         charset = NULL;
00142     ret = si_compile(si_doc, charset, &si_binary);
00143     output = octstr_format("%s", "si 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, si_binary);
00150     }
00151 
00152     if (file)
00153         octstr_pretty_print(fp, output);
00154     else {
00155         debug("test.si", 0, "si binary was");
00156         octstr_dump(si_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(si_doc);
00167     octstr_destroy(si_binary);
00168     octstr_destroy(output);
00169     gwlib_shutdown();
00170     return 0;
00171 }

Here is the call graph for this function:


Variable Documentation

Octstr* charset = NULL
 

Definition at line 68 of file test_si.c.

Octstr* file_name = NULL
 

Definition at line 69 of file test_si.c.

See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.