Kannel: Open Source WAP and SMS gateway  svn-r5335
ws.h File Reference
#include "wsutf8.h"

Go to the source code of this file.

Data Structures

struct  WsCompilerParamsRec
 

Typedefs

typedef void(* WsIOProc) (const char *data, size_t len, void *context)
 
typedef void(* WsPragmaMetaProc) (const WsUtf8String *property_name, const WsUtf8String *content, const WsUtf8String *scheme, void *context)
 
typedef struct WsCompilerParamsRec WsCompilerParams
 
typedef struct WsCompilerRecWsCompilerPtr
 

Enumerations

enum  WsResult {
  WS_OK, WS_ERROR_OUT_OF_MEMORY, WS_ERROR_SYNTAX, WS_ERROR_SEMANTIC,
  WS_ERROR_IO, WS_ERROR
}
 

Functions

WsCompilerPtr ws_create (WsCompilerParams *params)
 
void ws_destroy (WsCompilerPtr compiler)
 
WsResult ws_compile_file (WsCompilerPtr compiler, const char *input_name, FILE *input, FILE *output)
 
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_free_byte_code (unsigned char *byte_code)
 
const char * ws_result_to_string (WsResult result)
 

Typedef Documentation

◆ WsCompilerParams

Definition at line 182 of file ws.h.

◆ WsCompilerPtr

typedef struct WsCompilerRec* WsCompilerPtr

Definition at line 185 of file ws.h.

◆ WsIOProc

typedef void(* WsIOProc) (const char *data, size_t len, void *context)

Definition at line 84 of file ws.h.

◆ WsPragmaMetaProc

typedef void(* WsPragmaMetaProc) (const WsUtf8String *property_name, const WsUtf8String *content, const WsUtf8String *scheme, void *context)

Definition at line 95 of file ws.h.

Enumeration Type Documentation

◆ WsResult

enum WsResult
Enumerator
WS_OK 
WS_ERROR_OUT_OF_MEMORY 
WS_ERROR_SYNTAX 
WS_ERROR_SEMANTIC 
WS_ERROR_IO 
WS_ERROR 

Definition at line 203 of file ws.h.

204 {
205  /* Successful termination */
206  WS_OK,
207 
208  /* The compiler ran out of memory. */
210 
211  /* The input was not syntactically correct. */
213 
214  /* The input was not semantically correct. */
216 
217  /* IO error. */
218  WS_ERROR_IO,
219 
220  /* A generic `catch-all' error code. This should not be used. More
221  descriptive error messages should be generated instead. */
222  WS_ERROR
223 } WsResult;
WsResult
Definition: ws.h:203
Definition: ws.h:206
Definition: ws.h:222

Function Documentation

◆ ws_compile_data()

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 
)

Definition at line 206 of file ws.c.

References compile_stream(), WS_ERROR_OUT_OF_MEMORY, ws_stream_close(), and ws_stream_new_data_input().

Referenced by convert_wmlscript_to_wmlscriptc(), and main().

210 {
211  WsResult result;
212  WsStream *stream;
213 
214  /* Initialize the input stream. */
215  stream = ws_stream_new_data_input(input, input_len);
216  if (stream == NULL)
217  return WS_ERROR_OUT_OF_MEMORY;
218 
219  result = compile_stream(compiler, input_name, stream, output_return,
220  output_len_return);
221 
222  ws_stream_close(stream);
223 
224  return result;
225 }
WsStream * ws_stream_new_data_input(const unsigned char *data, size_t data_len)
WsResult
Definition: ws.h:203
void ws_stream_close(WsStream *stream)
Definition: wsstream.c:117
static WsResult compile_stream(WsCompilerPtr compiler, const char *input_name, WsStream *input, unsigned char **output_return, size_t *output_len_return)
Definition: ws.c:316

◆ ws_compile_file()

WsResult ws_compile_file ( WsCompilerPtr  compiler,
const char *  input_name,
FILE *  input,
FILE *  output 
)

Definition at line 177 of file ws.c.

References compile_stream(), ws_bc_data_free(), WS_ERROR_IO, WS_ERROR_OUT_OF_MEMORY, WS_FALSE, WS_OK, ws_stream_close(), and ws_stream_new_file().

Referenced by main().

179 {
180  WsResult result;
181  WsStream *stream;
182  unsigned char *bc;
183  size_t bc_len;
184 
185  /* Initialize the input stream. */
186  stream = ws_stream_new_file(input, WS_FALSE, WS_FALSE);
187  if (stream == NULL)
188  return WS_ERROR_OUT_OF_MEMORY;
189 
190  result = compile_stream(compiler, input_name, stream, &bc, &bc_len);
191 
192  ws_stream_close(stream);
193 
194  if (result == WS_OK) {
195  /* Store the result to the file. */
196  if (fwrite(bc, 1, bc_len, output) != bc_len)
197  result = WS_ERROR_IO;
198 
199  ws_bc_data_free(bc);
200  }
201 
202  return result;
203 }
WsResult
Definition: ws.h:203
void ws_stream_close(WsStream *stream)
Definition: wsstream.c:117
Definition: ws.h:206
void ws_bc_data_free(unsigned char *data)
Definition: wsbc.c:426
WsStream * ws_stream_new_file(FILE *fp, WsBool output, WsBool close)
static WsResult compile_stream(WsCompilerPtr compiler, const char *input_name, WsStream *input, unsigned char **output_return, size_t *output_len_return)
Definition: ws.c:316

◆ ws_create()

WsCompilerPtr ws_create ( WsCompilerParams params)

Definition at line 135 of file ws.c.

References COMPILER_MAGIC, WsCompilerRec::magic, WsCompilerRec::params, std_io(), WsCompilerParamsRec::stderr_cb, WsCompilerParamsRec::stderr_cb_context, WsCompilerParamsRec::stdout_cb, WsCompilerParamsRec::stdout_cb_context, and ws_calloc().

Referenced by convert_wmlscript_to_wmlscriptc(), and main().

136 {
137  WsCompilerPtr compiler = ws_calloc(1, sizeof(*compiler));
138 
139  if (compiler == NULL)
140  return NULL;
141 
142  /* Store user params if specified. */
143  if (params)
144  compiler->params = *params;
145 
146  /* Basic initialization. */
147 
148  compiler->magic = COMPILER_MAGIC;
149 
150  if (compiler->params.stdout_cb == NULL) {
151  compiler->params.stdout_cb = std_io;
152  compiler->params.stdout_cb_context = stdout;
153  }
154  if (compiler->params.stderr_cb == NULL) {
155  compiler->params.stderr_cb = std_io;
156  compiler->params.stderr_cb_context = stderr;
157  }
158 
159  return compiler;
160 }
void * ws_calloc(size_t num, size_t size)
Definition: wsalloc.c:83
WsUInt32 magic
Definition: wsint.h:190
void * stdout_cb_context
Definition: ws.h:165
static void std_io(const char *data, size_t len, void *context)
Definition: ws.c:548
WsIOProc stdout_cb
Definition: ws.h:164
WsCompilerParams params
Definition: wsint.h:193
WsIOProc stderr_cb
Definition: ws.h:168
void * stderr_cb_context
Definition: ws.h:169
#define COMPILER_MAGIC
Definition: wsint.h:185

◆ ws_destroy()

void ws_destroy ( WsCompilerPtr  compiler)

Definition at line 163 of file ws.c.

References ws_free().

Referenced by main().

164 {
165  if (compiler == NULL)
166  return;
167 
168  ws_free(compiler);
169 
170 #if WS_MEM_DEBUG
171  if (ws_has_leaks())
172  ws_dump_blocks();
173 #endif /* WS_MEM_DEBUG */
174 }
void ws_free(void *ptr)
Definition: wsalloc.c:139

◆ ws_free_byte_code()

void ws_free_byte_code ( unsigned char *  byte_code)

Definition at line 228 of file ws.c.

References ws_bc_data_free().

Referenced by main().

229 {
230  ws_bc_data_free(byte_code);
231 }
void ws_bc_data_free(unsigned char *data)
Definition: wsbc.c:426

◆ ws_result_to_string()

const char* ws_result_to_string ( WsResult  result)

Definition at line 234 of file ws.c.

References code, and result_codes.

Referenced by convert_wmlscript_to_wmlscriptc(), and main().

235 {
236  int i;
237 
238  for (i = 0; result_codes[i].description; i++) {
239  if (result_codes[i].code == result)
240  return result_codes[i].description;
241  }
242 
243  return "unknown result code";
244 }
static struct @111 result_codes[]
WsResult code
Definition: ws.c:99
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.