| 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 | 36302392 | bool lbm_channel_more(lbm_char_channel_t *chan) { | |
| 27 | 36302392 | return chan->more(chan); | |
| 28 | } | ||
| 29 | |||
| 30 | 480386629 | int lbm_channel_peek(lbm_char_channel_t *chan, unsigned int n, char *res) { | |
| 31 | 480386629 | return chan->peek(chan, n, res); | |
| 32 | } | ||
| 33 | |||
| 34 | 189 | bool lbm_channel_read(lbm_char_channel_t *chan, char *res) { | |
| 35 | 189 | return chan->read(chan, res); | |
| 36 | } | ||
| 37 | |||
| 38 | 34929401 | bool lbm_channel_drop(lbm_char_channel_t *chan, unsigned int n) { | |
| 39 | 34929401 | return chan->drop(chan, n); | |
| 40 | } | ||
| 41 | |||
| 42 | 18159705 | bool lbm_channel_comment(lbm_char_channel_t *chan) { | |
| 43 | 18159705 | return chan->comment(chan); | |
| 44 | } | ||
| 45 | |||
| 46 | 50133 | void lbm_channel_set_comment(lbm_char_channel_t *chan, bool comment) { | |
| 47 | 50133 | chan->set_comment(chan, comment); | |
| 48 | 50133 | } | |
| 49 | |||
| 50 | 33477559 | bool lbm_channel_is_empty(lbm_char_channel_t *chan) { | |
| 51 | 33477559 | 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 | 16400803 | int lbm_channel_write(lbm_char_channel_t *chan, char c) { | |
| 59 | 16400803 | return chan->write(chan, c); | |
| 60 | } | ||
| 61 | |||
| 62 | 33056 | void lbm_channel_writer_close(lbm_char_channel_t *chan) { | |
| 63 | 33056 | chan->writer_close(chan); | |
| 64 | 33056 | } | |
| 65 | |||
| 66 | 997488 | void lbm_channel_reader_close(lbm_char_channel_t *chan) { | |
| 67 | 997488 | chan->reader_close(chan); | |
| 68 | 997488 | } | |
| 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 | 1346937 | unsigned int lbm_channel_row(lbm_char_channel_t *chan) { | |
| 75 | 1346937 | return chan->row(chan); | |
| 76 | } | ||
| 77 | |||
| 78 | 1466278 | unsigned int lbm_channel_column(lbm_char_channel_t *chan) { | |
| 79 | 1466278 | return chan->column(chan); | |
| 80 | } | ||
| 81 | |||
| 82 | 83343 | bool lbm_channel_may_block(lbm_char_channel_t *chan) { | |
| 83 | 83343 | return chan->may_block(chan); | |
| 84 | } | ||
| 85 | |||
| 86 | // //////////////////////////////////////////////////////////// | ||
| 87 | // Implementation buffered channel | ||
| 88 | // | ||
| 89 | |||
| 90 | 33055 | bool buffered_may_block(lbm_char_channel_t *chan) { | |
| 91 | (void) chan; | ||
| 92 | 33055 | return true; | |
| 93 | } | ||
| 94 | |||
| 95 | 5650716 | bool buffered_more(lbm_char_channel_t *chan) { | |
| 96 | 5650716 | lbm_buffered_channel_state_t *st = (lbm_buffered_channel_state_t*)chan->state; | |
| 97 | 5650716 | return st->more; | |
| 98 | } | ||
| 99 | |||
| 100 | 33055 | void buffered_writer_close(lbm_char_channel_t *chan) { | |
| 101 | 33055 | lbm_buffered_channel_state_t *st = (lbm_buffered_channel_state_t*)chan->state; | |
| 102 | 33055 | st->more = false; | |
| 103 | 33055 | } | |
| 104 | |||
| 105 | 33007 | void buffered_reader_close(lbm_char_channel_t *chan) { | |
| 106 | 33007 | lbm_buffered_channel_state_t *st = (lbm_buffered_channel_state_t*)chan->state; | |
| 107 | 33007 | st->reader_closed = true; | |
| 108 | 33007 | } | |
| 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 | 60208266 | int buffered_peek(lbm_char_channel_t *chan, unsigned int n, char *res) { | |
| 116 | 60208266 | lbm_buffered_channel_state_t *st = (lbm_buffered_channel_state_t*)chan->state; | |
| 117 | 60208266 | char *buffer = st->buffer; | |
| 118 | 60208266 | int ret = CHANNEL_MORE; | |
| 119 | 60208266 | lbm_mutex_lock(&st->lock); | |
| 120 | 60208266 | unsigned int peek_pos = (st->read_pos + n) % TOKENIZER_BUFFER_SIZE; | |
| 121 | bool in_data; | ||
| 122 | |||
| 123 |
2/2✓ Branch 0 taken 34143327 times.
✓ Branch 1 taken 26064939 times.
|
60208266 | if (st->write_pos >= st->read_pos) { |
| 124 |
3/4✓ Branch 0 taken 34103847 times.
✓ Branch 1 taken 39480 times.
✓ Branch 2 taken 34103847 times.
✗ Branch 3 not taken.
|
34143327 | in_data = peek_pos < st->write_pos && peek_pos >= st->read_pos; |
| 125 | } else { | ||
| 126 |
4/4✓ Branch 0 taken 25956829 times.
✓ Branch 1 taken 108110 times.
✓ Branch 2 taken 25956805 times.
✓ Branch 3 taken 24 times.
|
26064939 | in_data = !(peek_pos >= st->write_pos && peek_pos < st->read_pos); |
| 127 | } | ||
| 128 | |||
| 129 |
2/2✓ Branch 0 taken 60168762 times.
✓ Branch 1 taken 39504 times.
|
60208266 | if (in_data) { |
| 130 | 60168762 | *res = buffer[peek_pos]; | |
| 131 | 60168762 | ret = CHANNEL_SUCCESS; | |
| 132 |
2/2✓ Branch 1 taken 32669 times.
✓ Branch 2 taken 6835 times.
|
39504 | } else if (!buffered_more(chan)) { |
| 133 | 32669 | ret = CHANNEL_END; | |
| 134 |
1/2✓ Branch 1 taken 6835 times.
✗ Branch 2 not taken.
|
6835 | } else if (buffered_more(chan)) { |
| 135 | 6835 | ret = CHANNEL_MORE; | |
| 136 | } | ||
| 137 | 60208266 | lbm_mutex_unlock(&st->lock); | |
| 138 | 60208266 | return ret; | |
| 139 | } | ||
| 140 | |||
| 141 | 12510597 | bool buffered_channel_is_empty(lbm_char_channel_t *chan) { | |
| 142 | 12510597 | lbm_buffered_channel_state_t *st = (lbm_buffered_channel_state_t*)chan->state; | |
| 143 |
2/2✓ Branch 0 taken 33074 times.
✓ Branch 1 taken 12477523 times.
|
12510597 | if (st->read_pos == st->write_pos) { |
| 144 | 33074 | return true; | |
| 145 | } | ||
| 146 | 12477523 | return false; | |
| 147 | } | ||
| 148 | |||
| 149 | 9794813 | bool buffered_channel_is_full(lbm_char_channel_t *chan) { | |
| 150 | 9794813 | lbm_buffered_channel_state_t *st = (lbm_buffered_channel_state_t*)chan->state; | |
| 151 |
2/2✓ Branch 0 taken 9752764 times.
✓ Branch 1 taken 42049 times.
|
9794813 | if (st->write_pos == st->read_pos - 1 || |
| 152 |
2/2✓ Branch 0 taken 4842838 times.
✓ Branch 1 taken 4909926 times.
|
9752764 | (st->read_pos == 0 && |
| 153 |
2/2✓ Branch 0 taken 19503 times.
✓ Branch 1 taken 4823335 times.
|
4842838 | st->write_pos == TOKENIZER_BUFFER_SIZE-1)) { |
| 154 | 61552 | return true; | |
| 155 | } | ||
| 156 | 9733261 | return false; | |
| 157 | } | ||
| 158 | |||
| 159 | 9731053 | bool buffered_read(lbm_char_channel_t *chan, char *res) { | |
| 160 | 9731053 | lbm_buffered_channel_state_t *st = (lbm_buffered_channel_state_t*)chan->state; | |
| 161 | 9731053 | char *buffer = st->buffer; | |
| 162 | 9731053 | bool ret = false; | |
| 163 | 9731053 | lbm_mutex_lock(&st->lock); | |
| 164 |
2/2✓ Branch 1 taken 9730987 times.
✓ Branch 2 taken 66 times.
|
9731053 | if (!buffered_channel_is_empty(chan)) { |
| 165 | 9730987 | *res = buffer[st->read_pos]; | |
| 166 | 9730987 | st->column++; | |
| 167 |
2/2✓ Branch 0 taken 320635 times.
✓ Branch 1 taken 9410352 times.
|
9730987 | if (*res == '\n') { |
| 168 | 320635 | st->column = 1; | |
| 169 | 320635 | st->row ++; | |
| 170 | } | ||
| 171 | 9730987 | st->read_pos = (st->read_pos + 1) % TOKENIZER_BUFFER_SIZE; | |
| 172 | 9730987 | ret = true; | |
| 173 | } | ||
| 174 | 9731053 | lbm_mutex_unlock(&st->lock); | |
| 175 | 9731053 | return ret; | |
| 176 | } | ||
| 177 | |||
| 178 | 6305749 | bool buffered_drop(lbm_char_channel_t *chan, unsigned int n) { | |
| 179 | 6305749 | bool r = true; | |
| 180 | char c; | ||
| 181 | |||
| 182 |
2/2✓ Branch 0 taken 9730904 times.
✓ Branch 1 taken 6305749 times.
|
16036653 | for (unsigned int i = 0; i < n; i ++) { |
| 183 | 9730904 | r = buffered_read(chan, &c); | |
| 184 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9730904 times.
|
9730904 | if (r == false) break; |
| 185 | } | ||
| 186 | 6305749 | return r; | |
| 187 | } | ||
| 188 | |||
| 189 | 9794556 | int buffered_write(lbm_char_channel_t *chan, char c) { | |
| 190 | 9794556 | lbm_buffered_channel_state_t *st = (lbm_buffered_channel_state_t*)chan->state; | |
| 191 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9794556 times.
|
9794556 | if (st->reader_closed) return CHANNEL_READER_CLOSED; |
| 192 | 9794556 | int ret = CHANNEL_FULL; | |
| 193 | 9794556 | lbm_mutex_lock(&st->lock); | |
| 194 | 9794556 | char *buffer = st->buffer; | |
| 195 |
2/2✓ Branch 1 taken 9733005 times.
✓ Branch 2 taken 61551 times.
|
9794556 | if (!buffered_channel_is_full(chan)) { |
| 196 | 9733005 | buffer[st->write_pos] = c; | |
| 197 | 9733005 | st->write_pos = (st->write_pos + 1) % TOKENIZER_BUFFER_SIZE; | |
| 198 | 9733005 | ret = CHANNEL_SUCCESS; | |
| 199 | } | ||
| 200 | 9794556 | lbm_mutex_unlock(&st->lock); | |
| 201 | 9794556 | return ret; | |
| 202 | } | ||
| 203 | |||
| 204 | 159962 | unsigned int buffered_row(lbm_char_channel_t *chan) { | |
| 205 | 159962 | lbm_buffered_channel_state_t *st = (lbm_buffered_channel_state_t*)chan->state; | |
| 206 | 159962 | 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 | 2813550 | bool buffered_comment(lbm_char_channel_t *chan) { | |
| 215 | 2813550 | lbm_buffered_channel_state_t *st = (lbm_buffered_channel_state_t*)chan->state; | |
| 216 | 2813550 | return st->comment; | |
| 217 | } | ||
| 218 | |||
| 219 | 18289 | void buffered_set_comment(lbm_char_channel_t *chan, bool comment) { | |
| 220 | 18289 | lbm_buffered_channel_state_t *st = (lbm_buffered_channel_state_t*)chan->state; | |
| 221 | 18289 | st->comment = comment; | |
| 222 | 18289 | } | |
| 223 | |||
| 224 | 33068 | void lbm_create_buffered_char_channel(lbm_buffered_channel_state_t *st, | |
| 225 | lbm_char_channel_t *chan) { | ||
| 226 | |||
| 227 | 33068 | st->write_pos = 0; | |
| 228 | 33068 | st->read_pos = 0; | |
| 229 | 33068 | st->more = true; | |
| 230 | 33068 | st->reader_closed = false; | |
| 231 | 33068 | st->comment = false; | |
| 232 | 33068 | st->row = 1; | |
| 233 | 33068 | st->column = 1; | |
| 234 | |||
| 235 |
2/2✓ Branch 0 taken 33056 times.
✓ Branch 1 taken 12 times.
|
33068 | if (!st->mutex_initialized) { |
| 236 | 33056 | lbm_mutex_init(&st->lock); | |
| 237 | 33056 | st->mutex_initialized = true; | |
| 238 | } | ||
| 239 | |||
| 240 | 33068 | chan->state = st; | |
| 241 | 33068 | chan->more = buffered_more; | |
| 242 | 33068 | chan->peek = buffered_peek; | |
| 243 | 33068 | chan->read = buffered_read; | |
| 244 | 33068 | chan->drop = buffered_drop; | |
| 245 | 33068 | chan->comment = buffered_comment; | |
| 246 | 33068 | chan->set_comment = buffered_set_comment; | |
| 247 | 33068 | chan->channel_is_empty = buffered_channel_is_empty; | |
| 248 | 33068 | chan->channel_is_full = buffered_channel_is_full; | |
| 249 | 33068 | chan->write = buffered_write; | |
| 250 | 33068 | chan->writer_close = buffered_writer_close; | |
| 251 | 33068 | chan->reader_close = buffered_reader_close; | |
| 252 | 33068 | chan->reader_is_closed = buffered_reader_is_closed; | |
| 253 | 33068 | chan->row = buffered_row; | |
| 254 | 33068 | chan->column = buffered_column; | |
| 255 | 33068 | chan->may_block = buffered_may_block; | |
| 256 | 33068 | } | |
| 257 | |||
| 258 | // //////////////////////////////////////////////////////////// | ||
| 259 | // Implementation string channel | ||
| 260 | // | ||
| 261 | |||
| 262 | 50288 | bool string_may_block(lbm_char_channel_t *chan) { | |
| 263 | (void) chan; | ||
| 264 | 50288 | return false; | |
| 265 | } | ||
| 266 | |||
| 267 | 30698015 | bool string_more(lbm_char_channel_t *chan) { | |
| 268 | 30698015 | lbm_string_channel_state_t *st = (lbm_string_channel_state_t*)chan->state; | |
| 269 | 30698015 | 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 | 964481 | void string_reader_close(lbm_char_channel_t *chan) { | |
| 278 | 964481 | lbm_string_channel_state_t *st = (lbm_string_channel_state_t*)chan->state; | |
| 279 | 964481 | st->reader_closed = true; | |
| 280 | 964481 | } | |
| 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 | 420178363 | int string_peek(lbm_char_channel_t *chan, unsigned int n, char *res) { | |
| 288 | 420178363 | lbm_string_channel_state_t *st = (lbm_string_channel_state_t*)chan->state; | |
| 289 | 420178363 | char *str = st->str; | |
| 290 | |||
| 291 | 420178363 | unsigned int peek_pos = st->read_pos + n; | |
| 292 | |||
| 293 |
2/2✓ Branch 0 taken 420106233 times.
✓ Branch 1 taken 72130 times.
|
420178363 | if (peek_pos < st->length) { |
| 294 | 420106233 | *res = str[peek_pos]; | |
| 295 | 420106233 | return CHANNEL_SUCCESS; | |
| 296 | } | ||
| 297 | 72130 | return CHANNEL_END; | |
| 298 | } | ||
| 299 | |||
| 300 | 30698015 | bool string_channel_is_empty(lbm_char_channel_t *chan) { | |
| 301 | 30698015 | lbm_string_channel_state_t *st = (lbm_string_channel_state_t*)chan->state; | |
| 302 |
2/2✓ Branch 0 taken 70508 times.
✓ Branch 1 taken 30627507 times.
|
30698015 | if (st->read_pos == st->length) { |
| 303 | 70508 | return true; | |
| 304 | } | ||
| 305 | 30627507 | 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 | 35175906 | bool string_read(lbm_char_channel_t *chan, char *res) { | |
| 317 | 35175906 | lbm_string_channel_state_t *st = (lbm_string_channel_state_t*)chan->state; | |
| 318 | 35175906 | char *str = st->str; | |
| 319 | |||
| 320 |
2/2✓ Branch 0 taken 35175904 times.
✓ Branch 1 taken 2 times.
|
35175906 | if (st->read_pos < st->length) { |
| 321 | 35175904 | *res = str[st->read_pos]; | |
| 322 |
2/2✓ Branch 0 taken 428168 times.
✓ Branch 1 taken 34747736 times.
|
35175904 | if (*res == '\n') { |
| 323 | 428168 | st->row ++; | |
| 324 | 428168 | st->column = 1; | |
| 325 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 34747734 times.
|
34747736 | } else if (*res == 0) { |
| 326 | 2 | st->more = false; | |
| 327 | } else { | ||
| 328 | 34747734 | st->column++; | |
| 329 | } | ||
| 330 | 35175904 | st->read_pos = st->read_pos + 1; | |
| 331 | } else { | ||
| 332 | 2 | st->more = false; | |
| 333 | } | ||
| 334 | 35175906 | return true; | |
| 335 | } | ||
| 336 | |||
| 337 | 28623652 | bool string_drop(lbm_char_channel_t *chan, unsigned int n) { | |
| 338 | 28623652 | bool r = true; | |
| 339 | char c; | ||
| 340 | |||
| 341 |
1/2✓ Branch 0 taken 28623652 times.
✗ Branch 1 not taken.
|
28623652 | if (n > 0) { |
| 342 | do { | ||
| 343 | 35175866 | r = string_read(chan, &c); | |
| 344 | 35175866 | n--; | |
| 345 |
3/4✓ Branch 0 taken 6552214 times.
✓ Branch 1 taken 28623652 times.
✓ Branch 2 taken 6552214 times.
✗ Branch 3 not taken.
|
35175866 | } while (n > 0 && r); |
| 346 | } | ||
| 347 | 28623652 | return r; | |
| 348 | } | ||
| 349 | |||
| 350 | 6619291 | int string_write(lbm_char_channel_t *chan, char c) { | |
| 351 | 6619291 | lbm_string_channel_state_t *st = (lbm_string_channel_state_t*)chan->state; | |
| 352 | 6619291 | char *str = st->str; | |
| 353 | |||
| 354 |
2/2✓ Branch 0 taken 5607889 times.
✓ Branch 1 taken 1011402 times.
|
6619291 | if (st->write_pos < st->length) { |
| 355 | 5607889 | str[st->write_pos] = c; | |
| 356 | 5607889 | st->write_pos = st->write_pos + 1; | |
| 357 | } else { | ||
| 358 | 1011402 | return CHANNEL_FULL; | |
| 359 | } | ||
| 360 | 5607889 | return CHANNEL_SUCCESS; | |
| 361 | } | ||
| 362 | |||
| 363 | 1432009 | unsigned int string_row(lbm_char_channel_t *chan) { | |
| 364 | 1432009 | lbm_string_channel_state_t *st = (lbm_string_channel_state_t*)chan->state; | |
| 365 | 1432009 | return st->row; | |
| 366 | } | ||
| 367 | |||
| 368 | 1466277 | unsigned int string_column(lbm_char_channel_t *chan) { | |
| 369 | 1466277 | lbm_string_channel_state_t *st = (lbm_string_channel_state_t*)chan->state; | |
| 370 | 1466277 | return st->column; | |
| 371 | } | ||
| 372 | |||
| 373 | 15346155 | bool string_comment(lbm_char_channel_t *chan) { | |
| 374 | 15346155 | lbm_string_channel_state_t *st = (lbm_string_channel_state_t*)chan->state; | |
| 375 | 15346155 | return st->comment; | |
| 376 | } | ||
| 377 | |||
| 378 | 31844 | void string_set_comment(lbm_char_channel_t *chan, bool comment) { | |
| 379 | 31844 | lbm_string_channel_state_t *st = (lbm_string_channel_state_t*)chan->state; | |
| 380 | 31844 | st->comment = comment; | |
| 381 | 31844 | } | |
| 382 | |||
| 383 | 969004 | void lbm_create_string_char_channel(lbm_string_channel_state_t *st, | |
| 384 | lbm_char_channel_t *chan, | ||
| 385 | char *str) { | ||
| 386 | |||
| 387 | 969004 | st->str = str; | |
| 388 | 969004 | st->length = (unsigned int)strlen(str); | |
| 389 | 969004 | st->read_pos = 0; | |
| 390 | 969004 | st->write_pos = 0; | |
| 391 | 969004 | st->more = false; | |
| 392 | 969004 | st->comment = false; | |
| 393 | 969004 | st->row = 1; | |
| 394 | 969004 | st->column = 1; | |
| 395 | |||
| 396 | 969004 | chan->dependency = ENC_SYM_NIL; | |
| 397 | 969004 | chan->state = st; | |
| 398 | 969004 | chan->more = string_more; | |
| 399 | 969004 | chan->peek = string_peek; | |
| 400 | 969004 | chan->read = string_read; | |
| 401 | 969004 | chan->drop = string_drop; | |
| 402 | 969004 | chan->comment = string_comment; | |
| 403 | 969004 | chan->set_comment = string_set_comment; | |
| 404 | 969004 | chan->channel_is_empty = string_channel_is_empty; | |
| 405 | 969004 | chan->channel_is_full = string_channel_is_full; | |
| 406 | 969004 | chan->write = string_write; | |
| 407 | 969004 | chan->writer_close = string_writer_close; | |
| 408 | 969004 | chan->reader_close = string_reader_close; | |
| 409 | 969004 | chan->reader_is_closed = string_reader_is_closed; | |
| 410 | 969004 | chan->row = string_row; | |
| 411 | 969004 | chan->column = string_column; | |
| 412 | 969004 | chan->may_block = string_may_block; | |
| 413 | 969004 | } | |
| 414 | |||
| 415 | 953740 | 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 | 953740 | st->str = str; | |
| 420 | 953740 | st->length = size; | |
| 421 | 953740 | st->read_pos = 0; | |
| 422 | 953740 | st->write_pos = 0; | |
| 423 | 953740 | st->more = false; | |
| 424 | 953740 | st->comment = false; | |
| 425 | 953740 | st->row = 1; | |
| 426 | 953740 | st->column = 1; | |
| 427 | |||
| 428 | 953740 | chan->dependency = ENC_SYM_NIL; | |
| 429 | 953740 | chan->state = st; | |
| 430 | 953740 | chan->more = string_more; | |
| 431 | 953740 | chan->peek = string_peek; | |
| 432 | 953740 | chan->read = string_read; | |
| 433 | 953740 | chan->drop = string_drop; | |
| 434 | 953740 | chan->comment = string_comment; | |
| 435 | 953740 | chan->set_comment = string_set_comment; | |
| 436 | 953740 | chan->channel_is_empty = string_channel_is_empty; | |
| 437 | 953740 | chan->channel_is_full = string_channel_is_full; | |
| 438 | 953740 | chan->write = string_write; | |
| 439 | 953740 | chan->writer_close = string_writer_close; | |
| 440 | 953740 | chan->reader_close = string_reader_close; | |
| 441 | 953740 | chan->reader_is_closed = string_reader_is_closed; | |
| 442 | 953740 | chan->row = string_row; | |
| 443 | 953740 | chan->column = string_column; | |
| 444 | 953740 | chan->may_block = string_may_block; | |
| 445 | 953740 | } | |
| 446 | |||
| 447 | 931235 | void lbm_char_channel_set_dependency(lbm_char_channel_t *chan, lbm_value dep) { | |
| 448 | 931235 | chan->dependency = dep; | |
| 449 | 931235 | } | |
| 450 | |||
| 451 |