queue_buffer.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | |||
| 2 | #include <ctype.h> | ||
| 3 | #include <stdio.h> | ||
| 4 | #include <string.h> | ||
| 5 | |||
| 6 | #include "global_data.h" | ||
| 7 | #include "queue_buffer.h" | ||
| 8 | |||
| 9 | typedef struct i360_queue_buffer i360_queue_buffer_t; | ||
| 10 | |||
| 11 | struct i360_queue_buffer { | ||
| 12 | size_t skip_anyop; | ||
| 13 | size_t cnt, opcnt; | ||
| 14 | size_t size; | ||
| 15 | char *current; | ||
| 16 | size_t data_size; | ||
| 17 | char data[]; | ||
| 18 | }; | ||
| 19 | |||
| 20 | #define I360_QUEUE_SIZE 512 | ||
| 21 | #define I360_QUEUE_BUFFER_SIZE 4096 | ||
| 22 | static char _i360_queue_buffer_space_static[I360_QUEUE_BUFFER_SIZE]; | ||
| 23 | static i360_queue_buffer_t *_i360_queue_buffer_static = (i360_queue_buffer_t *)_i360_queue_buffer_space_static; | ||
| 24 | |||
| 25 | 48 | static void _i360_queue_buffer_init(i360_queue_buffer_t *qb, size_t size, size_t skip_anyop) { | |
| 26 | 48 | qb->skip_anyop = skip_anyop; | |
| 27 | 48 | qb->data_size = size - sizeof(i360_queue_buffer_t); | |
| 28 | 48 | *(qb->current = qb->data + (qb->data_size - 1)) = 0; | |
| 29 | 48 | qb->cnt = qb->opcnt = 0; | |
| 30 | 48 | qb->size = 1; | |
| 31 | 48 | } | |
| 32 | |||
| 33 | 78 | static void _i360_queue_buffer_anyop(i360_queue_buffer_t *qb) { | |
| 34 | 78 | qb->opcnt++; | |
| 35 | 78 | } | |
| 36 | |||
| 37 | ✗ | static void _i360_queue_buffer_uppercase_last(i360_queue_buffer_t *qb) { | |
| 38 | ✗ | if (qb->size > 0) { | |
| 39 | ✗ | qb->current[0] = toupper(qb->current[0]); | |
| 40 | } | ||
| 41 | ✗ | } | |
| 42 | |||
| 43 | 650 | static void _i360_queue_buffer_prepend(i360_queue_buffer_t *qb, const char c) { | |
| 44 |
4/4✓ Branch 2 → 3 taken 6 times.
✓ Branch 2 → 5 taken 644 times.
✓ Branch 3 → 4 taken 5 times.
✓ Branch 3 → 5 taken 1 time.
|
650 | if (*qb->current == c && qb->opcnt < qb->skip_anyop) { |
| 45 | 5 | qb->opcnt = 0; | |
| 46 | 5 | return; | |
| 47 | } | ||
| 48 |
2/2✓ Branch 5 → 6 taken 88 times.
✓ Branch 5 → 7 taken 557 times.
|
645 | if (qb->cnt == I360_QUEUE_SIZE) |
| 49 | 88 | qb->current[(qb->size -= 2)] = 0; | |
| 50 | else | ||
| 51 | 557 | qb->cnt++; | |
| 52 |
1/2✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 645 times.
|
645 | if (qb->current < qb->data + 2) { |
| 53 | ✗ | char *current = qb->data + (qb->data_size - qb->size); | |
| 54 | ✗ | memmove(current, qb->current, qb->size); | |
| 55 | ✗ | qb->current = current; | |
| 56 | } | ||
| 57 | 645 | qb->opcnt = 0; | |
| 58 | 645 | qb->size += 2; | |
| 59 | 645 | qb->current -= 2; | |
| 60 | 645 | qb->current[0] = c; | |
| 61 | 645 | qb->current[1] = '|'; | |
| 62 | } | ||
| 63 | |||
| 64 | 48 | void i360_queue_buffer_init(size_t skip_anyop) { | |
| 65 | 48 | _i360_queue_buffer_init(_i360_queue_buffer_static, I360_QUEUE_BUFFER_SIZE, skip_anyop); | |
| 66 | 48 | } | |
| 67 | |||
| 68 | 78 | void i360_queue_buffer_anyop() { | |
| 69 | 78 | _i360_queue_buffer_anyop(_i360_queue_buffer_static); | |
| 70 | 78 | } | |
| 71 | |||
| 72 | 650 | void i360_queue_buffer_add(const char c) { | |
| 73 | 650 | _i360_queue_buffer_prepend(_i360_queue_buffer_static, c); | |
| 74 | 650 | } | |
| 75 | |||
| 76 | 640 | const char *i360_queue_buffer_string() { | |
| 77 | 640 | return _i360_queue_buffer_static->current; | |
| 78 | } | ||
| 79 | |||
| 80 | ✗ | void i360_queue_buffer_uppercase_last() { | |
| 81 | ✗ | _i360_queue_buffer_uppercase_last(_i360_queue_buffer_static); | |
| 82 | ✗ | } | |
| 83 | |||
| 84 | 632 | size_t i360_queue_buffer_string_len() { | |
| 85 |
1/2✓ Branch 2 → 3 taken 632 times.
✗ Branch 2 → 4 not taken.
|
632 | return _i360_queue_buffer_static->size ? _i360_queue_buffer_static->size - 1 : 0; |
| 86 | } | ||
| 87 |