Bible text I/O library, for retrieving and navigating text in KJV Bible More details at: http://mbed.org/users/davervw/notebook/ebible-abstract/

Dependents:   eBible

Committer:
davervw
Date:
Sun Feb 27 18:49:23 2011 +0000
Revision:
0:1f3d069211cd

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
davervw 0:1f3d069211cd 1 /* Bible I/O Class Definition
davervw 0:1f3d069211cd 2 *
davervw 0:1f3d069211cd 3 * Copyright (c) 2011 David R. Van Wagner davervw@yahoo.com
davervw 0:1f3d069211cd 4 *
davervw 0:1f3d069211cd 5 * Permission is hereby granted, free of charge, to any person obtaining a copy
davervw 0:1f3d069211cd 6 * of this software and associated documentation files (the "Software"), to deal
davervw 0:1f3d069211cd 7 * in the Software without restriction, including without limitation the rights
davervw 0:1f3d069211cd 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
davervw 0:1f3d069211cd 9 * copies of the Software, and to permit persons to whom the Software is
davervw 0:1f3d069211cd 10 * furnished to do so, subject to the following conditions:
davervw 0:1f3d069211cd 11 *
davervw 0:1f3d069211cd 12 * The above copyright notice and this permission notice shall be included in
davervw 0:1f3d069211cd 13 * all copies or substantial portions of the Software.
davervw 0:1f3d069211cd 14 *
davervw 0:1f3d069211cd 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
davervw 0:1f3d069211cd 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
davervw 0:1f3d069211cd 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
davervw 0:1f3d069211cd 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
davervw 0:1f3d069211cd 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
davervw 0:1f3d069211cd 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
davervw 0:1f3d069211cd 21 * THE SOFTWARE.
davervw 0:1f3d069211cd 22 */
davervw 0:1f3d069211cd 23
davervw 0:1f3d069211cd 24 /*
davervw 0:1f3d069211cd 25 * This class assumes bible text file is present and in a specific format extracted from source such as:
davervw 0:1f3d069211cd 26 * http://printkjv.ifbweb.com/AV_txt.zip
davervw 0:1f3d069211cd 27 */
davervw 0:1f3d069211cd 28
davervw 0:1f3d069211cd 29 #ifndef BIBLE_H
davervw 0:1f3d069211cd 30 #define BIBLE_H
davervw 0:1f3d069211cd 31
davervw 0:1f3d069211cd 32 #include "stdio.h"
davervw 0:1f3d069211cd 33
davervw 0:1f3d069211cd 34 class BibleIO
davervw 0:1f3d069211cd 35 {
davervw 0:1f3d069211cd 36
davervw 0:1f3d069211cd 37 public:
davervw 0:1f3d069211cd 38 BibleIO(char* text_filename, void (*indexing_callback)(int, void*), void* indexing_context);
davervw 0:1f3d069211cd 39 ~BibleIO();
davervw 0:1f3d069211cd 40 short get_num_books();
davervw 0:1f3d069211cd 41 short get_num_chapters(short book);
davervw 0:1f3d069211cd 42 short get_num_verses(short book, short chapter);
davervw 0:1f3d069211cd 43 char* title();
davervw 0:1f3d069211cd 44 char* title_book(short book);
davervw 0:1f3d069211cd 45 char* title_chapter(short book, short chapter);
davervw 0:1f3d069211cd 46 char* text_chapter(short book, short chapter);
davervw 0:1f3d069211cd 47 char* text_verse(short book, short chapter, short verse);
davervw 0:1f3d069211cd 48 bool bookmark_add(short book, short chapter, short verse);
davervw 0:1f3d069211cd 49 bool bookmark_del(short book, short chapter, short verse);
davervw 0:1f3d069211cd 50 bool bookmark_prev(short &book, short &chapter, short &verse);
davervw 0:1f3d069211cd 51 bool bookmark_next(short &book, short &chapter, short &verse);
davervw 0:1f3d069211cd 52
davervw 0:1f3d069211cd 53 private:
davervw 0:1f3d069211cd 54 struct chapter_index
davervw 0:1f3d069211cd 55 {
davervw 0:1f3d069211cd 56 long title_offset;
davervw 0:1f3d069211cd 57 long verses_offset[];
davervw 0:1f3d069211cd 58 };
davervw 0:1f3d069211cd 59
davervw 0:1f3d069211cd 60 struct book_index
davervw 0:1f3d069211cd 61 {
davervw 0:1f3d069211cd 62 long title_offset;
davervw 0:1f3d069211cd 63 long num_chapters;
davervw 0:1f3d069211cd 64 };
davervw 0:1f3d069211cd 65
davervw 0:1f3d069211cd 66 struct bible_index
davervw 0:1f3d069211cd 67 {
davervw 0:1f3d069211cd 68 long title_offset;
davervw 0:1f3d069211cd 69 book_index books[];
davervw 0:1f3d069211cd 70 };
davervw 0:1f3d069211cd 71
davervw 0:1f3d069211cd 72 struct position
davervw 0:1f3d069211cd 73 {
davervw 0:1f3d069211cd 74 short book;
davervw 0:1f3d069211cd 75 short chapter;
davervw 0:1f3d069211cd 76 short verse;
davervw 0:1f3d069211cd 77 short rsvd; // for padding
davervw 0:1f3d069211cd 78 };
davervw 0:1f3d069211cd 79
davervw 0:1f3d069211cd 80 char* text_filename;
davervw 0:1f3d069211cd 81 FILE* fp;
davervw 0:1f3d069211cd 82 char* name;
davervw 0:1f3d069211cd 83 bible_index* books;
davervw 0:1f3d069211cd 84 short num_books;
davervw 0:1f3d069211cd 85 position* bookmarks;
davervw 0:1f3d069211cd 86 short num_bookmarks;
davervw 0:1f3d069211cd 87 void (*indexing_callback)(int, void*);
davervw 0:1f3d069211cd 88 void* indexing_context;
davervw 0:1f3d069211cd 89
davervw 0:1f3d069211cd 90 void build_index();
davervw 0:1f3d069211cd 91 void read_name();
davervw 0:1f3d069211cd 92 void format_book_name(char* &book_name);
davervw 0:1f3d069211cd 93 void read_preface();
davervw 0:1f3d069211cd 94 void read_books();
davervw 0:1f3d069211cd 95 bool read_book(FILE* index, short book);
davervw 0:1f3d069211cd 96 bool read_chapter(short book, short chapter);
davervw 0:1f3d069211cd 97 bool read_verse(FILE* index, short book, short chapter, short verse);
davervw 0:1f3d069211cd 98 char* read_line();
davervw 0:1f3d069211cd 99 bool load_index();
davervw 0:1f3d069211cd 100 bool load_bookmarks();
davervw 0:1f3d069211cd 101 bool save_bookmarks();
davervw 0:1f3d069211cd 102 char* index_path();
davervw 0:1f3d069211cd 103 char* index_path(char* name);
davervw 0:1f3d069211cd 104 char* index_path(short chapter);
davervw 0:1f3d069211cd 105 char* index_path(short book, short chapter);
davervw 0:1f3d069211cd 106 };
davervw 0:1f3d069211cd 107
davervw 0:1f3d069211cd 108 #endif