| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | Copyright 2022, 2025 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 | */ | ||
| 17 | |||
| 18 | #include <lbm_channel.h> | ||
| 19 | #include <string.h> | ||
| 20 | #include <lbm_defines.h> | ||
| 21 | |||
| 22 | // //////////////////////////////////////////////////////////// | ||
| 23 | // Interface | ||
| 24 | // | ||
| 25 | |||
| 26 | 19437103 | bool lbm_channel_more(lbm_char_channel_t *chan) { | |
| 27 | 19437103 | return chan->more(chan); | |
| 28 | } | ||
| 29 | |||
| 30 | 240206447 | int lbm_channel_peek(lbm_char_channel_t *chan, unsigned int n, char *res) { | |
| 31 | 240206447 | return chan->peek(chan, n, res); | |
| 32 | } | ||
| 33 | |||
| 34 | 190 | bool lbm_channel_read(lbm_char_channel_t *chan, char *res) { | |
| 35 | 190 | return chan->read(chan, res); | |
| 36 | } | ||
| 37 | |||
| 38 | 19387497 | bool lbm_channel_drop(lbm_char_channel_t *chan, unsigned int n) { | |
| 39 | 19387497 | return chan->drop(chan, n); | |
| 40 | } | ||
| 41 | |||
| 42 | 9734536 | bool lbm_channel_comment(lbm_char_channel_t *chan) { | |
| 43 | 9734536 | return chan->comment(chan); | |
| 44 | } | ||
| 45 | |||
| 46 | 51669 | void lbm_channel_set_comment(lbm_char_channel_t *chan, bool comment) { | |
| 47 | 51669 | chan->set_comment(chan, comment); | |
| 48 | 51669 | } | |
| 49 | |||
| 50 | 18207448 | bool lbm_channel_is_empty(lbm_char_channel_t *chan) { | |
| 51 | 18207448 | return chan->channel_is_empty(chan); | |
| 52 | } | ||
| 53 | |||
| 54 | 263 | bool lbm_channel_is_full(lbm_char_channel_t *chan) { | |
| 55 | 263 | return chan->channel_is_full(chan); | |
| 56 | } | ||
| 57 | |||
| 58 | 7111125 | int lbm_channel_write(lbm_char_channel_t *chan, char c) { | |
| 59 | 7111125 | return chan->write(chan, c); | |
| 60 | } | ||
| 61 | |||
| 62 | 14259 | void lbm_channel_writer_close(lbm_char_channel_t *chan) { | |
| 63 | 14259 | chan->writer_close(chan); | |
| 64 | 14259 | } | |
| 65 | |||
| 66 | 433872 | void lbm_channel_reader_close(lbm_char_channel_t *chan) { | |
| 67 | 433872 | chan->reader_close(chan); | |
| 68 | 433872 | } | |
| 69 | |||
| 70 | 3 | bool lbm_channel_reader_is_closed(lbm_char_channel_t *chan) { | |
| 71 | 3 | return chan->reader_is_closed(chan); | |
| 72 | } | ||
| 73 | |||
| 74 | 924662 | unsigned int lbm_channel_row(lbm_char_channel_t *chan) { | |
| 75 | 924662 | return chan->row(chan); | |
| 76 | } | ||
| 77 | |||
| 78 | 4275669 | unsigned int lbm_channel_column(lbm_char_channel_t *chan) { | |
| 79 | 4275669 | return chan->column(chan); | |
| 80 | } | ||
| 81 | |||
| 82 | 36826 | bool lbm_channel_may_block(lbm_char_channel_t *chan) { | |
| 83 | 36826 | return chan->may_block(chan); | |
| 84 | } | ||
| 85 | |||
| 86 | // //////////////////////////////////////////////////////////// | ||
| 87 | // Implementation buffered channel | ||
| 88 | // | ||
| 89 | |||
| 90 | 14221 | bool buffered_may_block(lbm_char_channel_t *chan) { | |
| 91 | (void) chan; | ||
| 92 | 14221 | return true; | |
| 93 | } | ||
| 94 | |||
| 95 | 2429687 | bool buffered_more(lbm_char_channel_t *chan) { | |
| 96 | 2429687 | lbm_buffered_channel_state_t *st = (lbm_buffered_channel_state_t*)chan->state; | |
| 97 | 2429687 | return st->more; | |
| 98 | } | ||
| 99 | |||
| 100 | 14258 | void buffered_writer_close(lbm_char_channel_t *chan) { | |
| 101 | 14258 | lbm_buffered_channel_state_t *st = (lbm_buffered_channel_state_t*)chan->state; | |
| 102 | 14258 | st->more = false; | |
| 103 | 14258 | } | |
| 104 | |||
| 105 | 14194 | void buffered_reader_close(lbm_char_channel_t *chan) { | |
| 106 | 14194 | lbm_buffered_channel_state_t *st = (lbm_buffered_channel_state_t*)chan->state; | |
| 107 | 14194 | st->reader_closed = true; | |
| 108 | 14194 | } | |
| 109 | |||
| 110 | 2 | bool buffered_reader_is_closed(lbm_char_channel_t *chan) { | |
| 111 | 2 | lbm_buffered_channel_state_t *st = (lbm_buffered_channel_state_t*)chan->state; | |
| 112 | 2 | return st->reader_closed; | |
| 113 | } | ||
| 114 | |||
| 115 | 25887701 | int buffered_peek(lbm_char_channel_t *chan, unsigned int n, char *res) { | |
| 116 | 25887701 | lbm_buffered_channel_state_t *st = (lbm_buffered_channel_state_t*)chan->state; | |
| 117 | 25887701 | char *buffer = st->buffer; | |
| 118 | 25887701 | int ret = CHANNEL_MORE; | |
| 119 | 25887701 | lbm_mutex_lock(&st->lock); | |
| 120 | 25887701 | unsigned int peek_pos = (st->read_pos + n) % TOKENIZER_BUFFER_SIZE; | |
| 121 | bool in_data; | ||
| 122 | |||
| 123 |
2/2✓ Branch 0 taken 14576993 times.
✓ Branch 1 taken 11310708 times.
|
25887701 | if (st->write_pos >= st->read_pos) { |
| 124 |
3/4✓ Branch 0 taken 14560161 times.
✓ Branch 1 taken 16832 times.
✓ Branch 2 taken 14560161 times.
✗ Branch 3 not taken.
|
14576993 | in_data = peek_pos < st->write_pos && peek_pos >= st->read_pos; |
| 125 | } else { | ||
| 126 |
4/4✓ Branch 0 taken 11264087 times.
✓ Branch 1 taken 46621 times.
✓ Branch 2 taken 11264075 times.
✓ Branch 3 taken 12 times.
|
11310708 | in_data = !(peek_pos >= st->write_pos && peek_pos < st->read_pos); |
| 127 | } | ||
| 128 | |||
| 129 |
2/2✓ Branch 0 taken 25870857 times.
✓ Branch 1 taken 16844 times.
|
25887701 | if (in_data) { |
| 130 | 25870857 | *res = buffer[peek_pos]; | |
| 131 | 25870857 | ret = CHANNEL_SUCCESS; | |
| 132 |
2/2✓ Branch 1 taken 14093 times.
✓ Branch 2 taken 2751 times.
|
16844 | } else if (!buffered_more(chan)) { |
| 133 | 14093 | ret = CHANNEL_END; | |
| 134 |
1/2✓ Branch 1 taken 2751 times.
✗ Branch 2 not taken.
|
2751 | } else if (buffered_more(chan)) { |
| 135 | 2751 | ret = CHANNEL_MORE; | |
| 136 | } | ||
| 137 | 25887701 | lbm_mutex_unlock(&st->lock); | |
| 138 | 25887701 | return ret; | |
| 139 | } | ||
| 140 | |||
| 141 | 5369921 | bool buffered_channel_is_empty(lbm_char_channel_t *chan) { | |
| 142 | 5369921 | lbm_buffered_channel_state_t *st = (lbm_buffered_channel_state_t*)chan->state; | |
| 143 |
2/2✓ Branch 0 taken 14261 times.
✓ Branch 1 taken 5355660 times.
|
5369921 | if (st->read_pos == st->write_pos) { |
| 144 | 14261 | return true; | |
| 145 | } | ||
| 146 | 5355660 | return false; | |
| 147 | } | ||
| 148 | |||
| 149 | 4216102 | bool buffered_channel_is_full(lbm_char_channel_t *chan) { | |
| 150 | 4216102 | lbm_buffered_channel_state_t *st = (lbm_buffered_channel_state_t*)chan->state; | |
| 151 |
2/2✓ Branch 0 taken 4198656 times.
✓ Branch 1 taken 17446 times.
|
4216102 | if (st->write_pos == st->read_pos - 1 || |
| 152 |
2/2✓ Branch 0 taken 2087861 times.
✓ Branch 1 taken 2110795 times.
|
4198656 | (st->read_pos == 0 && |
| 153 |
2/2✓ Branch 0 taken 8040 times.
✓ Branch 1 taken 2079821 times.
|
2087861 | st->write_pos == TOKENIZER_BUFFER_SIZE-1)) { |
| 154 | 25486 | return true; | |
| 155 | } | ||
| 156 | 4190616 | return false; | |
| 157 | } | ||
| 158 | |||
| 159 | 4189484 | bool buffered_read(lbm_char_channel_t *chan, char *res) { | |
| 160 | 4189484 | lbm_buffered_channel_state_t *st = (lbm_buffered_channel_state_t*)chan->state; | |
| 161 | 4189484 | char *buffer = st->buffer; | |
| 162 | 4189484 | bool ret = false; | |
| 163 | 4189484 | lbm_mutex_lock(&st->lock); | |
| 164 |
2/2✓ Branch 1 taken 4189418 times.
✓ Branch 2 taken 66 times.
|
4189484 | if (!buffered_channel_is_empty(chan)) { |
| 165 | 4189418 | *res = buffer[st->read_pos]; | |
| 166 | 4189418 | st->column++; | |
| 167 |
2/2✓ Branch 0 taken 137888 times.
✓ Branch 1 taken 4051530 times.
|
4189418 | if (*res == '\n') { |
| 168 | 137888 | st->column = 1; | |
| 169 | 137888 | st->row ++; | |
| 170 | } | ||
| 171 | 4189418 | st->read_pos = (st->read_pos + 1) % TOKENIZER_BUFFER_SIZE; | |
| 172 | 4189418 | ret = true; | |
| 173 | } | ||
| 174 | 4189484 | lbm_mutex_unlock(&st->lock); | |
| 175 | 4189484 | return ret; | |
| 176 | } | ||
| 177 | |||
| 178 | 2715342 | bool buffered_drop(lbm_char_channel_t *chan, unsigned int n) { | |
| 179 | 2715342 | bool r = true; | |
| 180 | char c; | ||
| 181 | |||
| 182 |
2/2✓ Branch 0 taken 4189334 times.
✓ Branch 1 taken 2715342 times.
|
6904676 | for (unsigned int i = 0; i < n; i ++) { |
| 183 | 4189334 | r = buffered_read(chan, &c); | |
| 184 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4189334 times.
|
4189334 | if (r == false) break; |
| 185 | } | ||
| 186 | 2715342 | return r; | |
| 187 | } | ||
| 188 | |||
| 189 | 4215845 | int buffered_write(lbm_char_channel_t *chan, char c) { | |
| 190 | 4215845 | lbm_buffered_channel_state_t *st = (lbm_buffered_channel_state_t*)chan->state; | |
| 191 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4215845 times.
|
4215845 | if (st->reader_closed) return CHANNEL_READER_CLOSED; |
| 192 | 4215845 | int ret = CHANNEL_FULL; | |
| 193 | 4215845 | lbm_mutex_lock(&st->lock); | |
| 194 | 4215845 | char *buffer = st->buffer; | |
| 195 |
2/2✓ Branch 1 taken 4190360 times.
✓ Branch 2 taken 25485 times.
|
4215845 | if (!buffered_channel_is_full(chan)) { |
| 196 | 4190360 | buffer[st->write_pos] = c; | |
| 197 | 4190360 | st->write_pos = (st->write_pos + 1) % TOKENIZER_BUFFER_SIZE; | |
| 198 | 4190360 | ret = CHANNEL_SUCCESS; | |
| 199 | } | ||
| 200 | 4215845 | lbm_mutex_unlock(&st->lock); | |
| 201 | 4215845 | return ret; | |
| 202 | } | ||
| 203 | |||
| 204 | 68911 | unsigned int buffered_row(lbm_char_channel_t *chan) { | |
| 205 | 68911 | lbm_buffered_channel_state_t *st = (lbm_buffered_channel_state_t*)chan->state; | |
| 206 | 68911 | return st->row; | |
| 207 | } | ||
| 208 | |||
| 209 | 1 | unsigned int buffered_column(lbm_char_channel_t *chan) { | |
| 210 | 1 | lbm_buffered_channel_state_t *st = (lbm_buffered_channel_state_t*)chan->state; | |
| 211 | 1 | return st->column; | |
| 212 | } | ||
| 213 | |||
| 214 | 1209940 | bool buffered_comment(lbm_char_channel_t *chan) { | |
| 215 | 1209940 | lbm_buffered_channel_state_t *st = (lbm_buffered_channel_state_t*)chan->state; | |
| 216 | 1209940 | return st->comment; | |
| 217 | } | ||
| 218 | |||
| 219 | 8019 | void buffered_set_comment(lbm_char_channel_t *chan, bool comment) { | |
| 220 | 8019 | lbm_buffered_channel_state_t *st = (lbm_buffered_channel_state_t*)chan->state; | |
| 221 | 8019 | st->comment = comment; | |
| 222 | 8019 | } | |
| 223 | |||
| 224 | 14281 | void lbm_create_buffered_char_channel(lbm_buffered_channel_state_t *st, | |
| 225 | lbm_char_channel_t *chan) { | ||
| 226 | |||
| 227 | 14281 | st->write_pos = 0; | |
| 228 | 14281 | st->read_pos = 0; | |
| 229 | 14281 | st->more = true; | |
| 230 | 14281 | st->reader_closed = false; | |
| 231 | 14281 | st->comment = false; | |
| 232 | 14281 | st->row = 1; | |
| 233 | 14281 | st->column = 1; | |
| 234 | |||
| 235 |
2/2✓ Branch 0 taken 14269 times.
✓ Branch 1 taken 12 times.
|
14281 | if (!st->mutex_initialized) { |
| 236 | 14269 | lbm_mutex_init(&st->lock); | |
| 237 | 14269 | st->mutex_initialized = true; | |
| 238 | } | ||
| 239 | |||
| 240 | 14281 | chan->state = st; | |
| 241 | 14281 | chan->more = buffered_more; | |
| 242 | 14281 | chan->peek = buffered_peek; | |
| 243 | 14281 | chan->read = buffered_read; | |
| 244 | 14281 | chan->drop = buffered_drop; | |
| 245 | 14281 | chan->comment = buffered_comment; | |
| 246 | 14281 | chan->set_comment = buffered_set_comment; | |
| 247 | 14281 | chan->channel_is_empty = buffered_channel_is_empty; | |
| 248 | 14281 | chan->channel_is_full = buffered_channel_is_full; | |
| 249 | 14281 | chan->write = buffered_write; | |
| 250 | 14281 | chan->writer_close = buffered_writer_close; | |
| 251 | 14281 | chan->reader_close = buffered_reader_close; | |
| 252 | 14281 | chan->reader_is_closed = buffered_reader_is_closed; | |
| 253 | 14281 | chan->row = buffered_row; | |
| 254 | 14281 | chan->column = buffered_column; | |
| 255 | 14281 | chan->may_block = buffered_may_block; | |
| 256 | 14281 | } | |
| 257 | |||
| 258 | // //////////////////////////////////////////////////////////// | ||
| 259 | // Implementation string channel | ||
| 260 | // | ||
| 261 | |||
| 262 | 22605 | bool string_may_block(lbm_char_channel_t *chan) { | |
| 263 | (void) chan; | ||
| 264 | 22605 | return false; | |
| 265 | } | ||
| 266 | |||
| 267 | 17027011 | bool string_more(lbm_char_channel_t *chan) { | |
| 268 | 17027011 | lbm_string_channel_state_t *st = (lbm_string_channel_state_t*)chan->state; | |
| 269 | 17027011 | return st->more; | |
| 270 | } | ||
| 271 | |||
| 272 | 1 | void string_writer_close(lbm_char_channel_t *chan) { | |
| 273 | 1 | lbm_string_channel_state_t *st = (lbm_string_channel_state_t*)chan->state; | |
| 274 | 1 | st->more = false; | |
| 275 | 1 | } | |
| 276 | |||
| 277 | 419678 | void string_reader_close(lbm_char_channel_t *chan) { | |
| 278 | 419678 | lbm_string_channel_state_t *st = (lbm_string_channel_state_t*)chan->state; | |
| 279 | 419678 | st->reader_closed = true; | |
| 280 | 419678 | } | |
| 281 | |||
| 282 | 1 | bool string_reader_is_closed(lbm_char_channel_t *chan) { | |
| 283 | 1 | lbm_string_channel_state_t *st = (lbm_string_channel_state_t*)chan->state; | |
| 284 | 1 | return st->reader_closed; | |
| 285 | } | ||
| 286 | |||
| 287 | 214318746 | int string_peek(lbm_char_channel_t *chan, unsigned int n, char *res) { | |
| 288 | 214318746 | lbm_string_channel_state_t *st = (lbm_string_channel_state_t*)chan->state; | |
| 289 | 214318746 | char *str = st->str; | |
| 290 | |||
| 291 | 214318746 | unsigned int peek_pos = st->read_pos + n; | |
| 292 | |||
| 293 |
2/2✓ Branch 0 taken 214281812 times.
✓ Branch 1 taken 36934 times.
|
214318746 | if (peek_pos < st->length) { |
| 294 | 214281812 | *res = str[peek_pos]; | |
| 295 | 214281812 | return CHANNEL_SUCCESS; | |
| 296 | } | ||
| 297 | 36934 | return CHANNEL_END; | |
| 298 | } | ||
| 299 | |||
| 300 | 17027011 | bool string_channel_is_empty(lbm_char_channel_t *chan) { | |
| 301 | 17027011 | lbm_string_channel_state_t *st = (lbm_string_channel_state_t*)chan->state; | |
| 302 |
2/2✓ Branch 0 taken 36172 times.
✓ Branch 1 taken 16990839 times.
|
17027011 | if (st->read_pos == st->length) { |
| 303 | 36172 | return true; | |
| 304 | } | ||
| 305 | 16990839 | return false; | |
| 306 | } | ||
| 307 | |||
| 308 | 6 | bool string_channel_is_full(lbm_char_channel_t *chan) { | |
| 309 | 6 | lbm_string_channel_state_t *st = (lbm_string_channel_state_t*)chan->state; | |
| 310 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 5 times.
|
6 | if (st->write_pos == st->length) { |
| 311 | 1 | return true; | |
| 312 | } | ||
| 313 | 5 | return false; | |
| 314 | } | ||
| 315 | |||
| 316 | 22678614 | bool string_read(lbm_char_channel_t *chan, char *res) { | |
| 317 | 22678614 | lbm_string_channel_state_t *st = (lbm_string_channel_state_t*)chan->state; | |
| 318 | 22678614 | char *str = st->str; | |
| 319 | |||
| 320 |
2/2✓ Branch 0 taken 22678612 times.
✓ Branch 1 taken 2 times.
|
22678614 | if (st->read_pos < st->length) { |
| 321 | 22678612 | *res = str[st->read_pos]; | |
| 322 |
2/2✓ Branch 0 taken 450577 times.
✓ Branch 1 taken 22228035 times.
|
22678612 | if (*res == '\n') { |
| 323 | 450577 | st->row ++; | |
| 324 | 450577 | st->column = 1; | |
| 325 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 22228033 times.
|
22228035 | } else if (*res == 0) { |
| 326 | 2 | st->more = false; | |
| 327 | } else { | ||
| 328 | 22228033 | st->column++; | |
| 329 | } | ||
| 330 | 22678612 | st->read_pos = st->read_pos + 1; | |
| 331 | } else { | ||
| 332 | 2 | st->more = false; | |
| 333 | } | ||
| 334 | 22678614 | return true; | |
| 335 | } | ||
| 336 | |||
| 337 | 16672155 | bool string_drop(lbm_char_channel_t *chan, unsigned int n) { | |
| 338 | 16672155 | bool r = true; | |
| 339 | char c; | ||
| 340 | |||
| 341 |
1/2✓ Branch 0 taken 16672155 times.
✗ Branch 1 not taken.
|
16672155 | if (n > 0) { |
| 342 | do { | ||
| 343 | 22678574 | r = string_read(chan, &c); | |
| 344 | 22678574 | n--; | |
| 345 |
3/4✓ Branch 0 taken 6006419 times.
✓ Branch 1 taken 16672155 times.
✓ Branch 2 taken 6006419 times.
✗ Branch 3 not taken.
|
22678574 | } while (n > 0 && r); |
| 346 | } | ||
| 347 | 16672155 | return r; | |
| 348 | } | ||
| 349 | |||
| 350 | 2902165 | int string_write(lbm_char_channel_t *chan, char c) { | |
| 351 | 2902165 | lbm_string_channel_state_t *st = (lbm_string_channel_state_t*)chan->state; | |
| 352 | 2902165 | char *str = st->str; | |
| 353 | |||
| 354 |
2/2✓ Branch 0 taken 2468704 times.
✓ Branch 1 taken 433461 times.
|
2902165 | if (st->write_pos < st->length) { |
| 355 | 2468704 | str[st->write_pos] = c; | |
| 356 | 2468704 | st->write_pos = st->write_pos + 1; | |
| 357 | } else { | ||
| 358 | 433461 | return CHANNEL_FULL; | |
| 359 | } | ||
| 360 | 2468704 | return CHANNEL_SUCCESS; | |
| 361 | } | ||
| 362 | |||
| 363 | 1043111 | unsigned int string_row(lbm_char_channel_t *chan) { | |
| 364 | 1043111 | lbm_string_channel_state_t *st = (lbm_string_channel_state_t*)chan->state; | |
| 365 | 1043111 | return st->row; | |
| 366 | } | ||
| 367 | |||
| 368 | 4275668 | unsigned int string_column(lbm_char_channel_t *chan) { | |
| 369 | 4275668 | lbm_string_channel_state_t *st = (lbm_string_channel_state_t*)chan->state; | |
| 370 | 4275668 | return st->column; | |
| 371 | } | ||
| 372 | |||
| 373 | 8524596 | bool string_comment(lbm_char_channel_t *chan) { | |
| 374 | 8524596 | lbm_string_channel_state_t *st = (lbm_string_channel_state_t*)chan->state; | |
| 375 | 8524596 | return st->comment; | |
| 376 | } | ||
| 377 | |||
| 378 | 43650 | void string_set_comment(lbm_char_channel_t *chan, bool comment) { | |
| 379 | 43650 | lbm_string_channel_state_t *st = (lbm_string_channel_state_t*)chan->state; | |
| 380 | 43650 | st->comment = comment; | |
| 381 | 43650 | } | |
| 382 | |||
| 383 | 424149 | void lbm_create_string_char_channel(lbm_string_channel_state_t *st, | |
| 384 | lbm_char_channel_t *chan, | ||
| 385 | char *str) { | ||
| 386 | |||
| 387 | 424149 | st->str = str; | |
| 388 | 424149 | st->length = (unsigned int)strlen(str); | |
| 389 | 424149 | st->read_pos = 0; | |
| 390 | 424149 | st->write_pos = 0; | |
| 391 | 424149 | st->more = false; | |
| 392 | 424149 | st->comment = false; | |
| 393 | 424149 | st->row = 1; | |
| 394 | 424149 | st->column = 1; | |
| 395 | |||
| 396 | 424149 | chan->dependency = ENC_SYM_NIL; | |
| 397 | 424149 | chan->state = st; | |
| 398 | 424149 | chan->more = string_more; | |
| 399 | 424149 | chan->peek = string_peek; | |
| 400 | 424149 | chan->read = string_read; | |
| 401 | 424149 | chan->drop = string_drop; | |
| 402 | 424149 | chan->comment = string_comment; | |
| 403 | 424149 | chan->set_comment = string_set_comment; | |
| 404 | 424149 | chan->channel_is_empty = string_channel_is_empty; | |
| 405 | 424149 | chan->channel_is_full = string_channel_is_full; | |
| 406 | 424149 | chan->write = string_write; | |
| 407 | 424149 | chan->writer_close = string_writer_close; | |
| 408 | 424149 | chan->reader_close = string_reader_close; | |
| 409 | 424149 | chan->reader_is_closed = string_reader_is_closed; | |
| 410 | 424149 | chan->row = string_row; | |
| 411 | 424149 | chan->column = string_column; | |
| 412 | 424149 | chan->may_block = string_may_block; | |
| 413 | 424149 | } | |
| 414 | |||
| 415 | 418741 | void lbm_create_string_char_channel_size(lbm_string_channel_state_t *st, | |
| 416 | lbm_char_channel_t *chan, | ||
| 417 | char *str, | ||
| 418 | unsigned int size) { | ||
| 419 | 418741 | st->str = str; | |
| 420 | 418741 | st->length = size; | |
| 421 | 418741 | st->read_pos = 0; | |
| 422 | 418741 | st->write_pos = 0; | |
| 423 | 418741 | st->more = false; | |
| 424 | 418741 | st->comment = false; | |
| 425 | 418741 | st->row = 1; | |
| 426 | 418741 | st->column = 1; | |
| 427 | |||
| 428 | 418741 | chan->dependency = ENC_SYM_NIL; | |
| 429 | 418741 | chan->state = st; | |
| 430 | 418741 | chan->more = string_more; | |
| 431 | 418741 | chan->peek = string_peek; | |
| 432 | 418741 | chan->read = string_read; | |
| 433 | 418741 | chan->drop = string_drop; | |
| 434 | 418741 | chan->comment = string_comment; | |
| 435 | 418741 | chan->set_comment = string_set_comment; | |
| 436 | 418741 | chan->channel_is_empty = string_channel_is_empty; | |
| 437 | 418741 | chan->channel_is_full = string_channel_is_full; | |
| 438 | 418741 | chan->write = string_write; | |
| 439 | 418741 | chan->writer_close = string_writer_close; | |
| 440 | 418741 | chan->reader_close = string_reader_close; | |
| 441 | 418741 | chan->reader_is_closed = string_reader_is_closed; | |
| 442 | 418741 | chan->row = string_row; | |
| 443 | 418741 | chan->column = string_column; | |
| 444 | 418741 | chan->may_block = string_may_block; | |
| 445 | 418741 | } | |
| 446 | |||
| 447 | 404806 | void lbm_char_channel_set_dependency(lbm_char_channel_t *chan, lbm_value dep) { | |
| 448 | 404806 | chan->dependency = dep; | |
| 449 | 404806 | } | |
| 450 | |||
| 451 |