Browse Source

Rename macros to be more consistent

master
Daniel 5 months ago
parent
commit
fb9a782075
4 changed files with 22 additions and 18 deletions
  1. +10
    -8
      biblec.c
  2. +8
    -7
      biblec.h
  3. +1
    -0
      compiler.js
  4. +3
    -3
      test.c

+ 10
- 8
biblec.c View File

@@ -14,11 +14,13 @@ int strToInt(char *buf) {
return ret;
}

// Parse BibleC index file, see format.md
// Parse BibleC index file, see
// https://api.heb12.com/translations/biblec/web.i
// TODO: better error detection
int biblec_parse(struct BiblecTranslation *translation, char *indexLocation) {
FILE *index = fopen(indexLocation, "r");
if (index == NULL) {
return FILE_NOT_FOUND;
return BIBLEC_FILE_ERROR;
}

// If location is never filled in, then assume text
@@ -87,7 +89,7 @@ int biblec_parse(struct BiblecTranslation *translation, char *indexLocation) {
return 0;
}
int getBookID(struct BiblecTranslation *translation, char *book) {
int bookID = BOOK_NOT_FOUND;
int bookID = BIBLEC_BOOK_ERROR;
for (int i = 0; i < translation->length; i++) {
if (!strcmp(book, translation->books[i].name)) {
bookID = i;
@@ -121,16 +123,16 @@ int biblec_new(struct BiblecReader *reader, struct BiblecTranslation *translatio

reader->file = fopen(translation->location, "r");
if (reader->file == NULL) {
return FILE_ERROR;
return BIBLEC_FILE_ERROR;
}

int bookID = getBookID(translation, book);
if (bookID == BOOK_NOT_FOUND) {
return BOOK_NOT_FOUND;
if (bookID == BIBLEC_BOOK_ERROR) {
return BIBLEC_BOOK_ERROR;
}

if (translation->books[bookID].length < chapter) {
return BAD_CHAPTER;
return BIBLEC_CHAPTER_ERROR;
}

// Grab start line, and add until specified chapter is reached.
@@ -149,7 +151,7 @@ int biblec_new(struct BiblecReader *reader, struct BiblecTranslation *translatio
}
if (to < 0) {
return VERSE_ERROR;
return BIBLEC_VERSE_ERROR;
}

// Add the line over to the specific verse


+ 8
- 7
biblec.h View File

@@ -1,9 +1,11 @@
#ifndef BIBLEC_H
#define BIBLEC_H

#include <stdio.h>

// Size macros, for internal use only
#define MAX_BOOKS 66
#define MAX_CHAPTERS 151

#define INDEX_MAX_LENGTH 512
#define VERSE_LENGTH 1024
#define MAX_NAME 32
@@ -20,12 +22,11 @@ enum Biblec_error {
BAD_CHAPTER = -5,
VERSE_ERROR = -6,

BIBLEC_BAD_FILE = -1,
BIBLEC_BAD_BOOK = -2,
BIBLEC_FILE_ERROR = -1,
BIBLEC_BOOK_ERROR = -2,
BIBLEC_OVERFLOW = -3,
BIBLEC_FILE_ERROR = -4,
BIBLEC_BAD_CHAPTER = -5,
BIBLEC_VERSE_ERROR = -6
BIBLEC_CHAPTER_ERROR = -4,
BIBLEC_VERSE_ERROR = -5
};

struct BiblecReader {
@@ -46,8 +47,8 @@ struct BiblecTranslation {
struct Book {
char name[MAX_BOOK_NAME];
int start;
int length; // (in chapters)
int chapters[MAX_CHAPTERS];
int length; // (in chapters)
}books[MAX_BOOKS];
};



+ 1
- 0
compiler.js View File

@@ -123,6 +123,7 @@ function loopVerses(linesPassed, verses) {
function generateIndexFile(bibleData, name, lang) {
indexFile += "#name:" + name + "\n";
indexFile += "#lang:" + lang + "\n";
indexFile += "#location:" + "bibles/web.t" + "\n";
indexFile += "#length:" + bibleData.length + "\n";
for (var i = 0; i < bibleData.length; i++) {
indexFile += "@" + bibleData[i].book;


+ 3
- 3
test.c View File

@@ -5,12 +5,12 @@

#include "biblec.h"

struct BiblecTranslation translation;
struct Biblec_translation translation;

void test(char name[], int chapter, int from, int to) {
printf("Parsing: %s %d %d:%d\n", name, chapter, from, to);

struct BiblecReader reader;
struct Biblec_reader reader;
int tryReader = biblec_new(
&reader,
&translation,
@@ -44,7 +44,7 @@ int main() {
return 1;
}

struct BiblecReader reader;
struct Biblec_reader reader;
clock_t start_time = clock();
for (int i = 0; i < 100; i++) {
int tryReader = biblec_new(


Loading…
Cancel
Save