bibleverse

Print verse(s) from the Bible
git clone git://git.janpasierb.com/bibleverse.git
Log | Files | Refs | README

commit 19e6d0c5443764b1997ebdae841c8664c6e4a414
parent 6069604942a77d0925fbddd7de873cca255d0289
Author: JP <JP@JP.com>
Date:   Sun, 21 Nov 2021 16:27:08 +0000

Fixed verse-parsing allowing more than one :

Fixed main printing wrong requested verse numbers in the error message

makefile fixes

Diffstat:
MMakefile | 7++++---
Mmain.c | 10+++++++++-
Mverse.c | 7+++++++
3 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile @@ -39,11 +39,12 @@ install: all chmod 555 ${SHAREPREFIX}/bibleverse/bibleverse.db mkdir -p ${MANPREFIX}/man1 sed "s/VERSION/${VERSION}/g" < bibleverse.1 > ${MANPREFIX}/man1/bibleverse.1 - chmod 644 ${MANPREFIX}/man1/bibleverse.1 - gzip ${MANPREFIX}/man1/bibleverse.1 + gzip -f ${MANPREFIX}/man1/bibleverse.1 + rm -f ${MANPREFIX}/man1/bibleverse.1 + chmod 644 ${MANPREFIX}/man1/bibleverse.1.gz uninstall: rm -rf ${PREFIX}/bin/bibleverse ${MANPREFIX}/man1/bibleverse.1\ - ${SHAREPREFIX}/bibleverse/bibleverse.db + ${MANPREFIX}/man1/bibleverse.1.gz ${SHAREPREFIX}/bibleverse/bibleverse.db .PHONY: all options clean dist install uninstall diff --git a/main.c b/main.c @@ -1,6 +1,7 @@ #include<sqlite3.h> #include<stdlib.h> #include<stdio.h> +#include<string.h> #include"bibleverse.h" #define DB_NAME "/usr/local/share/bibleverse/bibleverse.db" @@ -55,10 +56,16 @@ int main(int argc, char** argv) { return 1; } + size_t verse_len = strlen(verse_numbers); + char* orig_verse_numbers = malloc(verse_len * sizeof(char*) + 1); + memcpy(orig_verse_numbers, verse_numbers, verse_len); + orig_verse_numbers[verse_len] = '\0'; + struct verse* ver = parse_verse_numbers(verse_numbers); if(ver == NULL) { - fprintf(stderr, "Failed to parse the verse (range) \"%s\"\n", verse_numbers); + fprintf(stderr, "Failed to parse the verse (range) \"%s\"\n", orig_verse_numbers); + free(orig_verse_numbers); sqlite3_close(db); return 1; @@ -66,6 +73,7 @@ int main(int argc, char** argv) { rc = print_verses(books[0].id, books[0].name, ver, db); + free(orig_verse_numbers); free(books[0].name); free(books); free(ver); diff --git a/verse.c b/verse.c @@ -32,6 +32,13 @@ struct verse* parse_verse_numbers(char* numbers) { if(isNumber(token)) { ver->verse_min = atoi(token); ver->verse_max = 0; + + token = strtok(NULL, book_delim); + + if(token != NULL) { + // too many :'s + return NULL; + } } else { const char verse_delim[2] = "-";