LispBM
lbm_channel.h
Go to the documentation of this file.
1 /*
2  Copyright 2022 Joel Svensson svenssonjoel@yahoo.se
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
19 #ifndef LBM_CHANNEL_H_
20 #define LBM_CHANNEL_H_
21 
22 #include <stdint.h>
23 #include <stdbool.h>
24 #include <platform_mutex.h>
25 
26 #define TOKENIZER_BUFFER_SIZE 257
27 
28 #define CHANNEL_SUCCESS 1
29 #define CHANNEL_MORE 2
30 #define CHANNEL_END 3
31 #define CHANNEL_FULL 4
32 
33 #define CHANNEL_READER_CLOSED 1000
34 
37 typedef struct {
38  char buffer[TOKENIZER_BUFFER_SIZE];
39  unsigned int write_pos;
40  unsigned int read_pos;
41  bool more;
42  bool comment;
43  bool reader_closed;
44  mutex_t lock;
45  bool mutex_initialized;
46  // statistics
47  unsigned int row;
48  unsigned int column;
50 
54 typedef struct {
55  char *str;
56  unsigned int length;
57  unsigned int read_pos;
58  unsigned int write_pos;
59  bool more;
60  bool comment;
61  bool reader_closed;
62  unsigned int row;
63  unsigned int column;
65 
68 typedef struct lbm_char_channel_s {
69 
70  void *state;
71  bool (*more)(struct lbm_char_channel_s *chan);
72  int (*peek)(struct lbm_char_channel_s *chan, unsigned int n, char *res);
73  bool (*read)(struct lbm_char_channel_s *chan, char *res);
74  bool (*drop)(struct lbm_char_channel_s *chan, unsigned int n);
75  bool (*comment)(struct lbm_char_channel_s *chan);
76  void (*set_comment)(struct lbm_char_channel_s *chan, bool comment);
77  void (*reader_close)(struct lbm_char_channel_s *chan);
78 
79  /* Either side */
80  bool (*channel_is_empty)(struct lbm_char_channel_s *chan);
81  bool (*channel_is_full)(struct lbm_char_channel_s *chan);
82  bool (*reader_is_closed)(struct lbm_char_channel_s *chan);
83 
84  /* Write side */
85  int (*write)(struct lbm_char_channel_s *chan, char c);
86  void (*writer_close)(struct lbm_char_channel_s *chan);
87 
88  /* Statistics */
89  unsigned int (*row)(struct lbm_char_channel_s *chan);
90  unsigned int (*column)(struct lbm_char_channel_s *chan);
91 
93 
94 
95 /* Read side */
103 
113 int lbm_channel_peek(lbm_char_channel_t *chan, unsigned int n, char *res);
114 
120 bool lbm_channel_read(lbm_char_channel_t *chan, char *res);
121 
127 bool lbm_channel_drop(lbm_char_channel_t *chan, unsigned int n);
128 
134 
139 void lbm_channel_set_comment(lbm_char_channel_t *chan, bool comment);
140 
145 
151 
152 /* Either side */
153 
159 
165 
166 /* Write side */
167 
177 
182 
183 /* Statistics */
184 
190 
195 
196 
197 /* Interface */
205  lbm_char_channel_t *chan,
206  char *str);
207 
208 void lbm_create_string_char_channel_size(lbm_string_channel_state_t *st,
209  lbm_char_channel_t *chan,
210  char *str,
211  unsigned int size);
212 
213 
219  lbm_char_channel_t *chan);
220 
221 
222 #endif
bool lbm_channel_comment(lbm_char_channel_t *chan)
void lbm_create_string_char_channel(lbm_string_channel_state_t *st, lbm_char_channel_t *chan, char *str)
void lbm_channel_reader_close(lbm_char_channel_t *chan)
bool lbm_channel_reader_is_closed(lbm_char_channel_t *chan)
unsigned int lbm_channel_column(lbm_char_channel_t *chan)
struct lbm_char_channel_s lbm_char_channel_t
int lbm_channel_write(lbm_char_channel_t *chan, char c)
bool lbm_channel_is_full(lbm_char_channel_t *chan)
bool lbm_channel_read(lbm_char_channel_t *chan, char *res)
bool lbm_channel_more(lbm_char_channel_t *chan)
bool lbm_channel_is_empty(lbm_char_channel_t *chan)
void lbm_channel_set_comment(lbm_char_channel_t *chan, bool comment)
void lbm_create_buffered_char_channel(lbm_buffered_channel_state_t *st, lbm_char_channel_t *chan)
bool lbm_channel_drop(lbm_char_channel_t *chan, unsigned int n)
int lbm_channel_peek(lbm_char_channel_t *chan, unsigned int n, char *res)
unsigned int lbm_channel_row(lbm_char_channel_t *chan)
void lbm_channel_writer_close(lbm_char_channel_t *chan)
Definition: lbm_channel.h:37
Definition: lbm_channel.h:68
Definition: lbm_channel.h:54