Skip to content

Commit

Permalink
Added warning message boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
otidev committed Dec 30, 2023
1 parent 3116007 commit 1104f8e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Navigation.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ void SearchVerse(Highlight* hl, bool* lookup, Book* books, TTF_Font* font, Bible
}
count++;

if (count != 3) {
fprintf(stderr, "Error: Not enough words!");
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Error", "Search not formatted correctly!\n(format: book chapter verse)", globalWindow->window);
return;
}

token = strtok(globalWindow->textInput, " ");
bool firstToken = true;
for (int i = 0; i < count - 2; i++) {
Expand Down Expand Up @@ -149,6 +155,9 @@ void SearchVerse(Highlight* hl, bool* lookup, Book* books, TTF_Font* font, Bible

if (data->chapter >= books[data->usedBook].numChapters) {
data->chapter = 0;
fprintf(stderr, "Error: Chapter too high!");
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Error", "Chapter of book too high!", globalWindow->window);
return;
}

hl->chapter = atoi(token) - 1;
Expand All @@ -157,12 +166,14 @@ void SearchVerse(Highlight* hl, bool* lookup, Book* books, TTF_Font* font, Bible
ezxml_t xmlBook = ezxml_idx(ezxml_child(xmlBible, "b"), data->usedBook);
if (!xmlBook) {
fprintf(stderr, "Error: No book %d!", data->usedBook);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Error", "Book not found!", globalWindow->window);
(*lookup) = false;
return;
}
ezxml_t xmlChapter = ezxml_idx(ezxml_child(xmlBook, "c"), data->chapter);
if (!xmlChapter) {
fprintf(stderr, "Error: No chapter %d!", data->chapter);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Error", "Chapter not found!", globalWindow->window);
(*lookup) = false;
return;
}
Expand All @@ -173,6 +184,7 @@ void SearchVerse(Highlight* hl, bool* lookup, Book* books, TTF_Font* font, Bible
token = strtok(NULL, " ");
if (atoi(token) - 1 >= numVerses) {
fprintf(stderr, "Error: No verse %d!", atoi(token) - 1);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Error", "Verse not found!", globalWindow->window);
return;
}

Expand Down

0 comments on commit 1104f8e

Please sign in to comment.