File: | filelist-parser.c |
Warning: | line 44, column 17 Value stored to 'start' is never read |
[?] Use j/k keys for keyboard navigation
1 | /* |
2 | * blogc: A blog compiler. |
3 | * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br> |
4 | * |
5 | * This program can be distributed under the terms of the BSD License. |
6 | * See the file LICENSE. |
7 | */ |
8 | |
9 | #include "../common/utils.h" |
10 | |
11 | |
12 | typedef enum { |
13 | LINE_START = 1, |
14 | LINE, |
15 | } blogc_filelist_parser_state_t; |
16 | |
17 | |
18 | bc_slist_t* |
19 | blogc_filelist_parse(const char *src, size_t src_len) |
20 | { |
21 | size_t current = 0; |
22 | size_t start = 0; |
23 | bc_slist_t *rv = NULL((void*)0); |
24 | bc_string_t *line = bc_string_new(); |
25 | blogc_filelist_parser_state_t state = LINE_START; |
26 | |
27 | while (current < src_len) { |
28 | char c = src[current]; |
29 | bool_Bool is_last = current == src_len - 1; |
30 | |
31 | switch (state) { |
32 | |
33 | case LINE_START: |
34 | if (c == '#') { |
35 | while (current < src_len) { |
36 | if (src[current] == '\r' || src[current] == '\n') |
37 | break; |
38 | current++; |
39 | } |
40 | break; |
41 | } |
42 | if (c == ' ' || c == '\t' || c == '\r' || c == '\n') |
43 | break; |
44 | start = current; |
Value stored to 'start' is never read | |
45 | state = LINE; |
46 | continue; |
47 | |
48 | case LINE: |
49 | if (c == '\r' || c == '\n' || is_last) { |
50 | if (is_last && c != '\r' && c != '\n') |
51 | bc_string_append_c(line, c); |
52 | rv = bc_slist_append(rv, bc_str_strip(line->str)); |
53 | bc_string_free(line, false0); |
54 | line = bc_string_new(); |
55 | state = LINE_START; |
56 | break; |
57 | } |
58 | bc_string_append_c(line, c); |
59 | break; |
60 | |
61 | } |
62 | |
63 | current++; |
64 | } |
65 | |
66 | bc_string_free(line, true1); |
67 | |
68 | return rv; |
69 | } |