| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/gnulib/lib/readtokens.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | - | |||||||||||||
| 7 | - | |||||||||||||
| 8 | - | |||||||||||||
| 9 | - | |||||||||||||
| 10 | void | - | ||||||||||||
| 11 | init_tokenbuffer (token_buffer *tokenbuffer) | - | ||||||||||||
| 12 | { | - | ||||||||||||
| 13 | tokenbuffer->size = 0; | - | ||||||||||||
| 14 | tokenbuffer->buffer = | - | ||||||||||||
| 15 | ((void *)0) | - | ||||||||||||
| 16 | ; | - | ||||||||||||
| 17 | } executed 15 times by 2 tests: end of blockExecuted by:
| 15 | ||||||||||||
| 18 | - | |||||||||||||
| 19 | typedef size_t word; | - | ||||||||||||
| 20 | enum { bits_per_word = sizeof (word) * 8 }; | - | ||||||||||||
| 21 | - | |||||||||||||
| 22 | static | - | ||||||||||||
| 23 | _Bool | - | ||||||||||||
| 24 | - | |||||||||||||
| 25 | get_nth_bit (size_t n, word const *bitset) | - | ||||||||||||
| 26 | { | - | ||||||||||||
| 27 | return executed 3944754 times by 2 tests: bitset[n / bits_per_word] >> n % bits_per_word & 1;return bitset[n / bits_per_word] >> n % bits_per_word & 1;Executed by:
executed 3944754 times by 2 tests: return bitset[n / bits_per_word] >> n % bits_per_word & 1;Executed by:
| 3944754 | ||||||||||||
| 28 | } | - | ||||||||||||
| 29 | - | |||||||||||||
| 30 | static void | - | ||||||||||||
| 31 | set_nth_bit (size_t n, word *bitset) | - | ||||||||||||
| 32 | { | - | ||||||||||||
| 33 | size_t one = 1; | - | ||||||||||||
| 34 | bitset[n / bits_per_word] |= one << n % bits_per_word; | - | ||||||||||||
| 35 | } executed 1500336 times by 2 tests: end of blockExecuted by:
| 1500336 | ||||||||||||
| 36 | size_t | - | ||||||||||||
| 37 | readtoken (FILE *stream, | - | ||||||||||||
| 38 | const char *delim, | - | ||||||||||||
| 39 | size_t n_delim, | - | ||||||||||||
| 40 | token_buffer *tokenbuffer) | - | ||||||||||||
| 41 | { | - | ||||||||||||
| 42 | char *p; | - | ||||||||||||
| 43 | int c; | - | ||||||||||||
| 44 | size_t i, n; | - | ||||||||||||
| 45 | word isdelim[( | - | ||||||||||||
| 46 | (0x7f * 2 + 1) | - | ||||||||||||
| 47 | + bits_per_word) / bits_per_word]; | - | ||||||||||||
| 48 | - | |||||||||||||
| 49 | memset (isdelim, 0, sizeof isdelim); | - | ||||||||||||
| 50 | for (i = 0; i < n_delim
| 500112-1500336 | ||||||||||||
| 51 | { | - | ||||||||||||
| 52 | unsigned char ch = delim[i]; | - | ||||||||||||
| 53 | set_nth_bit (ch, isdelim); | - | ||||||||||||
| 54 | } executed 1500336 times by 2 tests: end of blockExecuted by:
| 1500336 | ||||||||||||
| 55 | - | |||||||||||||
| 56 | - | |||||||||||||
| 57 | for (c = getc_unlocked (stream); c >= 0
| 0-500097 | ||||||||||||
| 58 | { | - | ||||||||||||
| 59 | - | |||||||||||||
| 60 | } never executed: end of block | 0 | ||||||||||||
| 61 | - | |||||||||||||
| 62 | p = tokenbuffer->buffer; | - | ||||||||||||
| 63 | n = tokenbuffer->size; | - | ||||||||||||
| 64 | i = 0; | - | ||||||||||||
| 65 | for (;;) | - | ||||||||||||
| 66 | { | - | ||||||||||||
| 67 | if (c < 0
| 0-3444657 | ||||||||||||
| 68 | return executed 15 times by 2 tests: -1;return -1;Executed by:
executed 15 times by 2 tests: return -1;Executed by:
| 15 | ||||||||||||
| 69 | - | |||||||||||||
| 70 | if (i == n
| 15-3444642 | ||||||||||||
| 71 | p = x2nrealloc (p, &n, sizeof *p); executed 15 times by 2 tests: p = x2nrealloc (p, &n, sizeof *p);Executed by:
| 15 | ||||||||||||
| 72 | - | |||||||||||||
| 73 | if (c < 0
| 0-3444657 | ||||||||||||
| 74 | { | - | ||||||||||||
| 75 | p[i] = 0; | - | ||||||||||||
| 76 | break; never executed: break; | 0 | ||||||||||||
| 77 | } | - | ||||||||||||
| 78 | if (get_nth_bit (c, isdelim)
| 500097-2944560 | ||||||||||||
| 79 | { | - | ||||||||||||
| 80 | p[i] = 0; | - | ||||||||||||
| 81 | break; executed 500097 times by 2 tests: break;Executed by:
| 500097 | ||||||||||||
| 82 | } | - | ||||||||||||
| 83 | p[i++] = c; | - | ||||||||||||
| 84 | c = getc_unlocked (stream); | - | ||||||||||||
| 85 | } executed 2944560 times by 2 tests: end of blockExecuted by:
| 2944560 | ||||||||||||
| 86 | - | |||||||||||||
| 87 | tokenbuffer->buffer = p; | - | ||||||||||||
| 88 | tokenbuffer->size = n; | - | ||||||||||||
| 89 | return executed 500097 times by 2 tests: i;return i;Executed by:
executed 500097 times by 2 tests: return i;Executed by:
| 500097 | ||||||||||||
| 90 | } | - | ||||||||||||
| 91 | size_t | - | ||||||||||||
| 92 | readtokens (FILE *stream, | - | ||||||||||||
| 93 | size_t projected_n_tokens, | - | ||||||||||||
| 94 | const char *delim, | - | ||||||||||||
| 95 | size_t n_delim, | - | ||||||||||||
| 96 | char ***tokens_out, | - | ||||||||||||
| 97 | size_t **token_lengths) | - | ||||||||||||
| 98 | { | - | ||||||||||||
| 99 | token_buffer tb, *token = &tb; | - | ||||||||||||
| 100 | char **tokens; | - | ||||||||||||
| 101 | size_t *lengths; | - | ||||||||||||
| 102 | size_t sz; | - | ||||||||||||
| 103 | size_t n_tokens; | - | ||||||||||||
| 104 | - | |||||||||||||
| 105 | if (projected_n_tokens == 0
| 0 | ||||||||||||
| 106 | projected_n_tokens = 64; never executed: projected_n_tokens = 64; | 0 | ||||||||||||
| 107 | else | - | ||||||||||||
| 108 | projected_n_tokens++; never executed: projected_n_tokens++; | 0 | ||||||||||||
| 109 | - | |||||||||||||
| 110 | sz = projected_n_tokens; | - | ||||||||||||
| 111 | tokens = xnmalloc (sz, sizeof *tokens); | - | ||||||||||||
| 112 | lengths = xnmalloc (sz, sizeof *lengths); | - | ||||||||||||
| 113 | - | |||||||||||||
| 114 | n_tokens = 0; | - | ||||||||||||
| 115 | init_tokenbuffer (token); | - | ||||||||||||
| 116 | for (;;) | - | ||||||||||||
| 117 | { | - | ||||||||||||
| 118 | char *tmp; | - | ||||||||||||
| 119 | size_t token_length = readtoken (stream, delim, n_delim, token); | - | ||||||||||||
| 120 | if (n_tokens >= sz
| 0 | ||||||||||||
| 121 | { | - | ||||||||||||
| 122 | tokens = x2nrealloc (tokens, &sz, sizeof *tokens); | - | ||||||||||||
| 123 | lengths = xnrealloc (lengths, sz, sizeof *lengths); | - | ||||||||||||
| 124 | } never executed: end of block | 0 | ||||||||||||
| 125 | - | |||||||||||||
| 126 | if (token_length == (size_t) -1
| 0 | ||||||||||||
| 127 | { | - | ||||||||||||
| 128 | - | |||||||||||||
| 129 | tokens[n_tokens] = | - | ||||||||||||
| 130 | ((void *)0) | - | ||||||||||||
| 131 | ; | - | ||||||||||||
| 132 | lengths[n_tokens] = 0; | - | ||||||||||||
| 133 | break; never executed: break; | 0 | ||||||||||||
| 134 | } | - | ||||||||||||
| 135 | tmp = xnmalloc (token_length + 1, sizeof *tmp); | - | ||||||||||||
| 136 | lengths[n_tokens] = token_length; | - | ||||||||||||
| 137 | tokens[n_tokens] = memcpy (tmp, token->buffer, token_length + 1); | - | ||||||||||||
| 138 | n_tokens++; | - | ||||||||||||
| 139 | } never executed: end of block | 0 | ||||||||||||
| 140 | - | |||||||||||||
| 141 | free (token->buffer); | - | ||||||||||||
| 142 | *tokens_out = tokens; | - | ||||||||||||
| 143 | if (token_lengths !=
| 0 | ||||||||||||
| 144 | ((void *)0)
| 0 | ||||||||||||
| 145 | ) | - | ||||||||||||
| 146 | * never executed: token_lengths = lengths;*token_lengths = lengths;never executed: *token_lengths = lengths; | 0 | ||||||||||||
| 147 | else | - | ||||||||||||
| 148 | free (lengths); never executed: free (lengths); | 0 | ||||||||||||
| 149 | return never executed: n_tokens;return n_tokens;never executed: return n_tokens; | 0 | ||||||||||||
| 150 | } | - | ||||||||||||
| Switch to Source code | Preprocessed file |