Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
wserror.h File Reference

Go to the source code of this file.

Macros

#define WS_STREAM(_stream)
 
#define WS_STDOUT   WS_STREAM(stdout)
 
#define WS_STDERR   WS_STREAM(stderr)
 

Functions

void ws_info (WsCompilerPtr compiler, char *message,...)
 
void ws_fatal (char *fmt,...) PRINTFLIKE(1
 
void void ws_error_memory (WsCompilerPtr compiler)
 
void ws_error_syntax (WsCompilerPtr compiler, WsUInt32 line)
 
void ws_src_error (WsCompilerPtr compiler, WsUInt32 line, char *message,...)
 
void ws_src_warning (WsCompilerPtr compiler, WsUInt32 line, char *message,...)
 
void ws_fprintf (WsIOProc io, void *context, const char *fmt,...)
 
void ws_vfprintf (WsIOProc io, void *context, const char *fmt, va_list ap)
 
void ws_puts (WsIOProc io, void *context, const char *str)
 
void ws_fputc (int ch, WsIOProc io, void *context)
 

Macro Definition Documentation

#define WS_STDERR   WS_STREAM(stderr)

Definition at line 114 of file wserror.h.

Referenced by ws_error_memory(), ws_error_syntax(), ws_src_error(), and ws_src_warning().

#define WS_STDOUT   WS_STREAM(stdout)

Definition at line 113 of file wserror.h.

Referenced by ws_asm_dasm(), ws_asm_print(), and ws_info().

#define WS_STREAM (   _stream)
Value:
compiler->params._stream ## _cb, \
compiler->params._stream ## _cb_context

Definition at line 109 of file wserror.h.

Function Documentation

void void ws_error_memory ( WsCompilerPtr  compiler)

Definition at line 107 of file wserror.c.

References COMPILER_MAGIC, WsCompilerRec::errors, gw_assert(), WsCompilerRec::magic, WS_ERROR_B_MEMORY, WS_LINE_TERMINATOR, ws_puts(), and WS_STDERR.

Referenced by asm_alloc(), buffer_to_int(), expr_alloc(), read_float_from_exp(), read_float_from_point(), stmt_alloc(), ws_asm_linearize(), ws_expr_assign(), ws_expr_call(), ws_expr_const_string(), ws_expr_linearize(), ws_expr_postfix_var(), ws_expr_symbol(), ws_expr_unary_var(), ws_formal_parameter(), ws_function(), ws_function_hash(), ws_list_append(), ws_list_new(), ws_pragma_meta_body(), ws_pragma_use(), ws_stmt_linearize(), ws_variable_declaration(), ws_variable_define(), ws_yy_lex(), and yyparse().

108 {
109  gw_assert(compiler->magic == COMPILER_MAGIC);
110 
111  if (compiler->errors & WS_ERROR_B_MEMORY)
112  /* We have already reported this error. */
113  return;
114 
115  compiler->errors |= WS_ERROR_B_MEMORY;
116  ws_puts(WS_STDERR, "wsc: error: out of memory" WS_LINE_TERMINATOR);
117 }
#define WS_STDERR
Definition: wserror.h:114
WsUInt32 magic
Definition: wsint.h:190
WsUInt32 errors
Definition: wsint.h:261
gw_assert(wtls_machine->packet_to_send!=NULL)
#define WS_ERROR_B_MEMORY
Definition: wsint.h:138
void ws_puts(WsIOProc io, void *context, const char *str)
Definition: wserror.c:318
#define WS_LINE_TERMINATOR
Definition: wsint.h:97
#define COMPILER_MAGIC
Definition: wsint.h:185
void ws_error_syntax ( WsCompilerPtr  compiler,
WsUInt32  line 
)

Definition at line 120 of file wserror.c.

References COMPILER_MAGIC, WsCompilerRec::errors, gw_assert(), WsCompilerRec::input_name, WsCompilerRec::last_syntax_error_line, WsCompilerRec::linenum, WsCompilerRec::magic, WS_ERROR_B_MEMORY, WS_ERROR_B_SYNTAX, ws_fprintf(), WS_LINE_TERMINATOR, and WS_STDERR.

Referenced by yyparse().

121 {
122  gw_assert(compiler->magic == COMPILER_MAGIC);
123 
124  if (compiler->errors & WS_ERROR_B_MEMORY)
125  /* It makes no sense to report syntax errors when we have run out
126  of memory. This information is not too valid. */
127  return;
128 
129  if (line == 0)
130  line = compiler->linenum;
131 
132  if (compiler->last_syntax_error_line == line)
133  /* It makes no sense to report multiple syntax errors from the
134  same line. */
135  return;
136 
137  compiler->last_syntax_error_line = line;
138  compiler->errors |= WS_ERROR_B_SYNTAX;
139 
140  ws_fprintf(WS_STDERR, "%s:%u: syntax error" WS_LINE_TERMINATOR,
141  compiler->input_name, line);
142 }
#define WS_STDERR
Definition: wserror.h:114
WsUInt32 magic
Definition: wsint.h:190
#define WS_ERROR_B_SYNTAX
Definition: wsint.h:141
WsUInt32 linenum
Definition: wsint.h:201
const char * input_name
Definition: wsint.h:200
WsUInt32 errors
Definition: wsint.h:261
void ws_fprintf(WsIOProc io, void *context, const char *fmt,...)
Definition: wserror.c:190
gw_assert(wtls_machine->packet_to_send!=NULL)
#define WS_ERROR_B_MEMORY
Definition: wsint.h:138
WsUInt32 last_syntax_error_line
Definition: wsint.h:265
#define WS_LINE_TERMINATOR
Definition: wsint.h:97
#define COMPILER_MAGIC
Definition: wsint.h:185
void ws_fatal ( char *  fmt,
  ... 
)
void ws_fprintf ( WsIOProc  io,
void *  context,
const char *  fmt,
  ... 
)

Definition at line 190 of file wserror.c.

References ws_vfprintf().

Referenced by ws_asm_dasm(), ws_asm_print(), ws_error_syntax(), ws_src_error(), and ws_src_warning().

191 {
192  va_list ap;
193 
194  va_start(ap, fmt);
195  ws_vfprintf(io, context, fmt, ap);
196  va_end(ap);
197 }
Definition: parse.c:65
void ws_vfprintf(WsIOProc io, void *context, const char *fmt, va_list ap)
Definition: wserror.c:200
void ws_fputc ( int  ch,
WsIOProc  io,
void *  context 
)

Definition at line 324 of file wserror.c.

Referenced by ws_vfprintf().

325 {
326  char c = (char) ch;
327 
328  (*io)(&c, 1, context);
329 }
Definition: parse.c:65
void ws_info ( WsCompilerPtr  compiler,
char *  message,
  ... 
)

Definition at line 74 of file wserror.c.

References WsCompilerRec::params, WsCompilerParamsRec::verbose, WS_LINE_TERMINATOR, ws_puts(), WS_STDOUT, and ws_vfprintf().

Referenced by compile_stream(), opt_conv(), opt_dead_code(), opt_jumps_to_jumps(), opt_jumps_to_next_instruction(), and opt_peephole().

75 {
76  va_list ap;
77 
78  if (!compiler->params.verbose)
79  return;
80 
81  ws_puts(WS_STDOUT, "wsc: ");
82 
83  va_start(ap, message);
84  ws_vfprintf(WS_STDOUT, message, ap);
85  va_end(ap);
86 
88 }
void ws_puts(WsIOProc io, void *context, const char *str)
Definition: wserror.c:318
WsCompilerParams params
Definition: wsint.h:193
#define WS_LINE_TERMINATOR
Definition: wsint.h:97
void ws_vfprintf(WsIOProc io, void *context, const char *fmt, va_list ap)
Definition: wserror.c:200
#define WS_STDOUT
Definition: wserror.h:113
unsigned int verbose
Definition: ws.h:151
void ws_puts ( WsIOProc  io,
void *  context,
const char *  str 
)

Definition at line 318 of file wserror.c.

Referenced by ws_error_memory(), ws_info(), ws_src_error(), and ws_src_warning().

319 {
320  (*io)(str, strlen(str), context);
321 }
Definition: parse.c:65
void ws_src_error ( WsCompilerPtr  compiler,
WsUInt32  line,
char *  message,
  ... 
)

Definition at line 145 of file wserror.c.

References COMPILER_MAGIC, WsCompilerRec::errors, gw_assert(), WsCompilerRec::input_name, WsCompilerRec::linenum, WsCompilerRec::magic, WsCompilerRec::num_errors, WS_ERROR_B_SEMANTIC, ws_fprintf(), WS_LINE_TERMINATOR, ws_puts(), WS_STDERR, and ws_vfprintf().

Referenced by buffer_to_int(), read_float_from_exp(), ws_expr_linearize(), ws_function(), ws_pragma_use(), ws_stmt_linearize(), ws_variable_define(), and ws_yy_lex().

146 {
147  va_list ap;
148 
149  gw_assert(compiler->magic == COMPILER_MAGIC);
150 
151  if (line == 0)
152  line = compiler->linenum;
153 
154  compiler->errors |= WS_ERROR_B_SEMANTIC;
155 
156  ws_fprintf(WS_STDERR, "%s:%u: ", compiler->input_name, line);
157 
158  va_start(ap, message);
159  ws_vfprintf(WS_STDERR, message, ap);
160  va_end(ap);
161 
163 
164  compiler->num_errors++;
165 }
#define WS_STDERR
Definition: wserror.h:114
WsUInt32 num_errors
Definition: wsint.h:253
WsUInt32 magic
Definition: wsint.h:190
#define WS_ERROR_B_SEMANTIC
Definition: wsint.h:146
WsUInt32 linenum
Definition: wsint.h:201
const char * input_name
Definition: wsint.h:200
WsUInt32 errors
Definition: wsint.h:261
void ws_fprintf(WsIOProc io, void *context, const char *fmt,...)
Definition: wserror.c:190
gw_assert(wtls_machine->packet_to_send!=NULL)
void ws_puts(WsIOProc io, void *context, const char *str)
Definition: wserror.c:318
#define WS_LINE_TERMINATOR
Definition: wsint.h:97
void ws_vfprintf(WsIOProc io, void *context, const char *fmt, va_list ap)
Definition: wserror.c:200
#define COMPILER_MAGIC
Definition: wsint.h:185
void ws_src_warning ( WsCompilerPtr  compiler,
WsUInt32  line,
char *  message,
  ... 
)

Definition at line 168 of file wserror.c.

References COMPILER_MAGIC, gw_assert(), WsCompilerRec::input_name, WsCompilerRec::linenum, WsCompilerRec::magic, WsCompilerRec::num_errors, ws_fprintf(), WS_LINE_TERMINATOR, ws_puts(), WS_STDERR, and ws_vfprintf().

169 {
170  va_list ap;
171 
172  gw_assert(compiler->magic == COMPILER_MAGIC);
173 
174  if (line == 0)
175  line = compiler->linenum;
176 
177  ws_fprintf(WS_STDERR, "%s:%u: warning: ", compiler->input_name, line);
178 
179  va_start(ap, message);
180  ws_vfprintf(WS_STDERR, message, ap);
181  va_end(ap);
182 
184 
185  compiler->num_errors++;
186 }
#define WS_STDERR
Definition: wserror.h:114
WsUInt32 num_errors
Definition: wsint.h:253
WsUInt32 magic
Definition: wsint.h:190
WsUInt32 linenum
Definition: wsint.h:201
const char * input_name
Definition: wsint.h:200
void ws_fprintf(WsIOProc io, void *context, const char *fmt,...)
Definition: wserror.c:190
gw_assert(wtls_machine->packet_to_send!=NULL)
void ws_puts(WsIOProc io, void *context, const char *str)
Definition: wserror.c:318
#define WS_LINE_TERMINATOR
Definition: wsint.h:97
void ws_vfprintf(WsIOProc io, void *context, const char *fmt, va_list ap)
Definition: wserror.c:200
#define COMPILER_MAGIC
Definition: wsint.h:185
void ws_vfprintf ( WsIOProc  io,
void *  context,
const char *  fmt,
va_list  ap 
)

Definition at line 200 of file wserror.c.

References start, ws_fatal(), and ws_fputc().

Referenced by ws_fprintf(), ws_info(), ws_src_error(), and ws_src_warning().

201 {
202  int start, i;
203 
204  for (start = 0, i = 0; fmt[i]; i++)
205  if (fmt[i] == '%' && fmt[i + 1]) {
206  char buf[256];
207  char *cp;
208  int ival;
209  unsigned int uival;
210  int padder = ' ';
211  int left = 0;
212  unsigned int width = 0;
213 
214  if (fmt[i + 1] == '%') {
215  /* An escaped `%'. Print leading data including the `%'
216  character. */
217  i++;
218  (*io)(fmt + start, i - start, context);
219  start = i + 1;
220  continue;
221  }
222 
223  /* An escape sequence. */
224 
225  /* Print leading data if any. */
226  if (i > start)
227  (*io)(fmt + start, i - start, context);
228 
229  /* We support a minor sub-set of the printf()'s formatting
230  capabilities. Let's see what we got. */
231  i++;
232 
233  /* Alignment? */
234  if (fmt[i] == '-') {
235  left = 1;
236  i++;
237  }
238 
239  /* Padding? */
240  if (fmt[i] == '0') {
241  padder = '0';
242  i++;
243  }
244 
245  /* Width? */
246  while ('0' <= fmt[i] && fmt[i] <= '9') {
247  width *= 10;
248  width += fmt[i++] - '0';
249  }
250 
251  /* Check the format. */
252  cp = buf;
253  switch (fmt[i]) {
254  case 'c': /* character */
255  ival = (int) va_arg(ap, int);
256 
257  snprintf(buf, sizeof(buf), "%c", (char) ival);
258  cp = buf;
259  break;
260 
261  case 's': /* string */
262  cp = va_arg(ap, char *);
263  break;
264 
265  case 'd': /* integer */
266  ival = va_arg(ap, int);
267 
268  snprintf(buf, sizeof(buf), "%d", ival);
269  cp = buf;
270  break;
271 
272  case 'u': /* unsigned integer */
273  uival = va_arg(ap, unsigned int);
274 
275  snprintf(buf, sizeof(buf), "%u", uival);
276  cp = buf;
277  break;
278 
279  case 'x': /* unsigned integer in hexadecimal format */
280  uival = va_arg(ap, unsigned int);
281 
282  snprintf(buf, sizeof(buf), "%x", uival);
283  cp = buf;
284  break;
285 
286  default:
287  ws_fatal("ws_vfprintf(): format %%%c not implemented", fmt[i]);
288  break;
289  }
290 
291  if (left)
292  /* Output the value left-justified. */
293  (*io)(cp, strlen(cp), context);
294 
295  /* Need padding? */
296  if (width > strlen(cp)) {
297  /* Yes we need. */
298  int amount = width - strlen(cp);
299 
300  while (amount-- > 0)
301  ws_fputc(padder, io, context);
302  }
303 
304  if (!left)
305  /* Output the value right-justified. */
306  (*io)(cp, strlen(cp), context);
307 
308  /* Process more. */
309  start = i + 1;
310  }
311 
312  /* Print trailing data if any. */
313  if (i > start)
314  (*io)(fmt + start, i - start, context);
315 }
void ws_fatal(char *fmt,...)
Definition: wserror.c:91
Definition: parse.c:65
static int start
void ws_fputc(int ch, WsIOProc io, void *context)
Definition: wserror.c:324
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.