Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
test_sl.c File Reference
#include <stdio.h>
#include "gwlib/gwlib.h"
#include "gw/wap_push_sl_compiler.h"

Go to the source code of this file.

Functions

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

Variables

Octstrcharset = NULL
 
Octstrfile_name = NULL
 

Function Documentation

static void help ( void  )
static

Definition at line 71 of file test_sl.c.

References info().

Referenced by main().

72 {
73  info(0, "Usage test_sl [option] sl_source");
74  info(0, "where options are");
75  info(0, "-h print this text");
76  info(0, "-f file output binary to the file");
77  info(0, "-c charset charset given by http");
78  info(0, "-v level set log level for stderr logging");
79 }
void info(int err, const char *fmt,...)
Definition: log.c:636
int main ( int  argc,
char **  argv 
)

Definition at line 81 of file test_sl.c.

References debug(), error(), file, 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 sl_compile().

82 {
83  int opt,
84  file,
85  have_charset,
86  ret;
87  FILE *fp;
88  Octstr *output,
89  *sl_doc,
90  *sl_binary;
91 
92  gwlib_init();
93  file = 0;
94  have_charset = 0;
95  fp = NULL;
96 
97  while ((opt = getopt(argc, argv, "hf:c:v:")) != EOF) {
98  switch (opt) {
99  case 'h':
100  help();
101  exit(1);
102  break;
103 
104  case 'f':
105  file = 1;
107  fp = fopen(optarg, "a");
108  if (fp == NULL)
109  panic(0, "Cannot open output file");
110  break;
111 
112  case 'c':
113  have_charset = 1;
115  break;
116 
117  case 'v':
119  break;
120 
121  case '?':
122  default:
123  error(0, "Invalid option %c", opt);
124  help();
125  panic(0, "Stopping");
126  break;
127  }
128  }
129 
130  if (optind >= argc) {
131  error(0, "Missing arguments");
132  help();
133  panic(0, "Stopping");
134  }
135 
136  sl_doc = octstr_read_file(argv[optind]);
137  if (sl_doc == NULL)
138  panic(0, "Cannot read the sl document");
139 
140  if (!have_charset)
141  charset = NULL;
142  ret = sl_compile(sl_doc, charset, &sl_binary);
143  output = octstr_format("%s", "sl compiler returned %d\n", ret);
144 
145  if (ret == 0) {
146  if (fp == NULL)
147  fp = stdout;
148  octstr_append(output, octstr_imm("content being\n"));
149  octstr_append(output, sl_binary);
150  }
151 
152  if (file)
153  octstr_pretty_print(fp, output);
154  else {
155  debug("test.sl", 0, "sl binary was");
156  octstr_dump(sl_binary, 0);
157  }
158 
159  if (have_charset)
161  if (file) {
162  fclose(fp);
164  }
165 
166  octstr_destroy(sl_doc);
167  octstr_destroy(sl_binary);
168  octstr_destroy(output);
169  gwlib_shutdown();
170  return 0;
171 }
void error(int err, const char *fmt,...)
Definition: log.c:612
int sl_compile(Octstr *sl_doc, Octstr *charset, Octstr **sl_binary)
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1502
int optind
Definition: attgetopt.c:80
FILE * file
Definition: log.c:133
int getopt(int argc, char **argv, char *opts)
Definition: attgetopt.c:84
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
Octstr * charset
Definition: test_sl.c:68
void log_set_output_level(enum output_level level)
Definition: log.c:217
#define octstr_dump(ostr, level,...)
Definition: octstr.h:564
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2462
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define octstr_create(cstr)
Definition: octstr.h:125
Octstr * octstr_read_file(const char *filename)
Definition: octstr.c:1546
Definition: octstr.c:118
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
char * optarg
Definition: attgetopt.c:82
#define panic
Definition: log.h:87
void gwlib_shutdown(void)
Definition: gwlib.c:94
Octstr * file_name
Definition: test_sl.c:69
void gwlib_init(void)
Definition: gwlib.c:78
int octstr_pretty_print(FILE *f, Octstr *ostr)
Definition: octstr.c:1204
static void help(void)
Definition: test_sl.c:71

Variable Documentation

Octstr* charset = NULL

Definition at line 68 of file test_sl.c.

Octstr* file_name = NULL

Definition at line 69 of file test_sl.c.

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