aboutsummaryrefslogtreecommitdiff
path: root/booki.c
diff options
context:
space:
mode:
authorBen Winston2024-05-25 21:22:58 -0400
committerBen Winston2024-05-25 21:22:58 -0400
commit95db49148e6b913ff273b76477a625b4bd5b9cc8 (patch)
tree4adafcb237fe2c4acd0bed341ed20b423259585e /booki.c
parent82126d94b6e08321a44c5d10dd927daa3cd73653 (diff)
refactor: use ATTR_MATCH for simplicity
Diffstat (limited to 'booki.c')
-rw-r--r--booki.c49
1 files changed, 20 insertions, 29 deletions
diff --git a/booki.c b/booki.c
index 7f462eb..d3670ff 100644
--- a/booki.c
+++ b/booki.c
@@ -218,38 +218,29 @@ void parse_book(char* current_pos, struct Book* book) {
}
char* next_book(char* current_pos) {
- char c;
- while(*current_pos) {
- // first opening bracket
- c = *current_pos++;
- if (c != '[') {
- continue;
- }
-
- // second opening bracket
- c = *current_pos++;
- if (c != '[') {
- continue;
- }
-
- if (strncmp(current_pos, "books", 5) != 0) {
- printf("thought i had it, but it's not a book\n");
- continue;
- }
- current_pos += 5;
-
- // seek past the closing brackets and the next newline
- current_pos += 2;
- if (*current_pos != '\n') {
- printf("expecting a newline...\n");
- continue;
+ while (!(ATTR_MATCH(current_pos, "[[books]]"))) {
+ current_pos++;
+ switch(*current_pos) {
+ case '\0':
+ return NULL;
+ case '\n':
+ PARSE_LINE += 1;
+ break;
+ default:
+ break;
}
+ }
- PARSE_LINE += 1;
+ // current_pos is at the beginning of [[books]]
+ // pass it, and any spaces/newlines, then return
+ current_pos += 9; // [[books]]
+ while (*current_pos != '\n')
current_pos++;
- return current_pos;
- }
- return NULL;
+
+ // current_pos is '\n', go past then return
+ PARSE_LINE += 1;
+ current_pos++;
+ return current_pos;
}
bool regex_match(const char* pattern, const struct es text) {