Kannel: Open Source WAP and SMS gateway  svn-r5335
wsstream.c File Reference
#include "wsint.h"

Go to the source code of this file.

Functions

WsBool ws_stream_getc (WsStream *stream, WsUInt32 *ch_return)
 
void ws_stream_ungetc (WsStream *stream, WsUInt32 ch)
 
WsBool ws_stream_flush (WsStream *stream)
 
void ws_stream_close (WsStream *stream)
 
WsStreamws_stream_new (void *context, WsStreamIOProc io, WsStreamFlushProc flush, WsStreamCloseProc close)
 

Function Documentation

◆ ws_stream_close()

void ws_stream_close ( WsStream stream)

Definition at line 117 of file wsstream.c.

References WsStreamRec::close, WsStreamRec::context, and ws_free().

Referenced by ws_compile_data(), and ws_compile_file().

118 {
119  if (stream->close)
120  (*stream->close)(stream->context);
121 
122  ws_free(stream);
123 }
void ws_free(void *ptr)
Definition: wsalloc.c:139
WsStreamCloseProc close
Definition: wsstream.h:103
void * context
Definition: wsstream.h:106

◆ ws_stream_flush()

WsBool ws_stream_flush ( WsStream stream)

Definition at line 108 of file wsstream.c.

References WsStreamRec::context, WsStreamRec::flush, and WS_TRUE.

109 {
110  if (stream->flush)
111  return (*stream->flush)(stream->context);
112 
113  return WS_TRUE;
114 }
Definition: wsint.h:131
void * context
Definition: wsstream.h:106
WsStreamFlushProc flush
Definition: wsstream.h:102

◆ ws_stream_getc()

WsBool ws_stream_getc ( WsStream stream,
WsUInt32 ch_return 
)

Definition at line 74 of file wsstream.c.

References WsStreamRec::buffer, WsStreamRec::buffer_pos, WsStreamRec::context, WsStreamRec::data_in_buffer, WsStreamRec::io, WsStreamRec::ungetch, WsStreamRec::ungetch_valid, WS_FALSE, WS_STREAM_BUFFER_SIZE, and WS_TRUE.

Referenced by read_float_from_exp(), read_float_from_point(), and ws_yy_lex().

75 {
76  if (stream->ungetch_valid) {
77  *ch_return = stream->ungetch;
78  stream->ungetch_valid = WS_FALSE;
79 
80  return WS_TRUE;
81  }
82 
83  if (stream->buffer_pos >= stream->data_in_buffer) {
84  /* Read more data to the buffer. */
85  stream->buffer_pos = 0;
86  stream->data_in_buffer = (*stream->io)(stream->context,
87  stream->buffer,
89  if (stream->data_in_buffer == 0)
90  /* EOF reached. */
91  return WS_FALSE;
92  }
93 
94  /* Return the next character. */
95  *ch_return = stream->buffer[stream->buffer_pos++];
96 
97  return WS_TRUE;
98 }
WsUInt32 buffer[WS_STREAM_BUFFER_SIZE]
Definition: wsstream.h:109
Definition: wsint.h:131
#define WS_STREAM_BUFFER_SIZE
Definition: wsstream.h:78
WsBool ungetch_valid
Definition: wsstream.h:114
size_t data_in_buffer
Definition: wsstream.h:111
WsStreamIOProc io
Definition: wsstream.h:101
size_t buffer_pos
Definition: wsstream.h:110
void * context
Definition: wsstream.h:106
WsUInt32 ungetch
Definition: wsstream.h:115

◆ ws_stream_new()

WsStream* ws_stream_new ( void *  context,
WsStreamIOProc  io,
WsStreamFlushProc  flush,
WsStreamCloseProc  close 
)

Definition at line 126 of file wsstream.c.

References WsStreamRec::close, WsStreamRec::context, WsStreamRec::flush, WsStreamRec::io, and ws_calloc().

Referenced by ws_stream_new_data_input(), and ws_stream_new_file().

128 {
129  WsStream *stream = ws_calloc(1, sizeof(*stream));
130 
131  if (stream == NULL)
132  return NULL;
133 
134  stream->io = io;
135  stream->flush = flush;
136  stream->close = close;
137  stream->context = context;
138 
139  return stream;
140 }
void * ws_calloc(size_t num, size_t size)
Definition: wsalloc.c:83
Definition: parse.c:65
WsStreamIOProc io
Definition: wsstream.h:101
WsStreamCloseProc close
Definition: wsstream.h:103
void * context
Definition: wsstream.h:106
WsStreamFlushProc flush
Definition: wsstream.h:102

◆ ws_stream_ungetc()

void ws_stream_ungetc ( WsStream stream,
WsUInt32  ch 
)

Definition at line 101 of file wsstream.c.

References WsStreamRec::ungetch, WsStreamRec::ungetch_valid, and WS_TRUE.

Referenced by read_float_from_exp(), read_float_from_point(), and ws_yy_lex().

102 {
103  stream->ungetch = ch;
104  stream->ungetch_valid = WS_TRUE;
105 }
Definition: wsint.h:131
WsBool ungetch_valid
Definition: wsstream.h:114
WsUInt32 ungetch
Definition: wsstream.h:115
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.