Browse Source

Update API

master
Daniel 3 weeks ago
parent
commit
17d60735e1
4 changed files with 29 additions and 43 deletions
  1. +20
    -26
      biblec.c
  2. +3
    -8
      compiler.js
  3. +2
    -2
      main.h
  4. +4
    -7
      test.c

+ 20
- 26
biblec.c View File

@@ -14,11 +14,10 @@ int strToInt(char *buf) {
}

// Parse BibleC index file, see format.md
void parseIndexFile(int *error, struct Translation *translation, char *indexLocation) {
int parseIndexFile(struct Translation *translation, char *indexLocation) {
FILE *index = fopen(indexLocation, "r");
if (index == NULL) {
*error = FILE_NOT_FOUND;
return;
return FILE_NOT_FOUND;
}

// If location is never filled in, then assume text
@@ -81,10 +80,11 @@ void parseIndexFile(int *error, struct Translation *translation, char *indexLoca
book++;
}

// Else, it is a "comment"
// Any other line start chars will be skipped
}

fclose(index);
return 0;
}

int getBookID(struct Translation *translation, char *book) {
@@ -116,27 +116,23 @@ int reader_next(struct Reader *reader) {
}

// Create a new reader structure
struct Reader reader_new(int *error, struct Translation *translation, char *book, int chapter, int verse, int to) {
*error = 0;
struct Reader reader;
int reader_new(struct Reader *reader, struct Translation *translation, char *book, int chapter, int verse, int to) {
int c;

// Check book ID
int bookID = getBookID(translation, book);
if (bookID == BOOK_NOT_FOUND) {
*error = bookID;
return reader;
return BOOK_NOT_FOUND;
}

// Check if requested chapter is larger than book length
if (translation->book[bookID].length < chapter) {
*error = CHAPTER_TOO_BIG;
return reader;
return CHAPTER_TOO_BIG;
}

// Grab start line, and add until specified chapter is reached.
int c = 0;
int line = translation->book[bookID].start;
for (; c < chapter - 1; c++) {
for (c = 0; c < chapter - 1; c++) {
line += translation->book[bookID].chapters[c];
}

@@ -152,16 +148,15 @@ struct Reader reader_new(int *error, struct Translation *translation, char *book
// Add the line over to the specific verse
line += verse - 1;

reader.book = book;
reader.chapter = chapter;
reader.verse = verse;
reader.to = to;
reader->book = book;
reader->chapter = chapter;
reader->verse = verse;
reader->to = to;

reader.linesRead = 0;
reader.file = fopen(translation->location, "r");
if (reader.file == NULL) {
*error = FILE_ERROR;
return reader;
reader->linesRead = 0;
reader->file = fopen(translation->location, "r");
if (reader->file == NULL) {
return FILE_ERROR;
}

// Loop through until it gets to the line
@@ -171,11 +166,10 @@ struct Reader reader_new(int *error, struct Translation *translation, char *book
if (i == line) {break;}
i++;

if (fgets(verseText, VERSE_LENGTH, reader.file) == NULL) {
*error = FILE_ERROR;
return reader;
if (fgets(verseText, VERSE_LENGTH, reader->file) == NULL) {
return FILE_ERROR;
}
}

return reader;
return 0;
}

+ 3
- 8
compiler.js View File

@@ -1,4 +1,7 @@
// This script compiles OSIS JSON into BibleC format.
// Why JS? Why not Python, Golang..
// I dunno. It's my goto scripting language, and also
// JS has some nice sorting functions. (I think?)

const fs = require('fs');

@@ -8,9 +11,6 @@ var file, type, folder, bible;
var verseFile = ``;
var indexFile = ``;




// Initial "CLI". Not advanced.
cli();
function cli() {
@@ -123,8 +123,6 @@ function loopVerses(linesPassed, verses) {
}
}



// Generate an index file for C to parse.
// #name:web
// #lang:en
@@ -145,9 +143,6 @@ function generateIndexFile(bibleData, name, lang) {
}
}




// Convert the JS object into a C struct.
function generateCStruct(bibleData, name) {
// Include main C structs.


+ 2
- 2
main.h View File

@@ -38,8 +38,8 @@ struct Translation {
}book[66];
};

struct Reader reader_new(int *error, struct Translation *translation, char *book, int chapter, int verse, int to);
void parseIndexFile(int *error, struct Translation *translation, char *indexLocation);
int parseIndexFile(struct Translation *translation, char *indexLocation);
int reader_new(struct Reader *reader, struct Translation *translation, char *book, int chapter, int verse, int to);
int reader_next(struct Reader *reader);

#endif

+ 4
- 7
test.c View File

@@ -2,15 +2,12 @@
#include <stdlib.h>
#include <string.h>
#include "main.h"
#include "biblec.h"

// Runtime struct
struct Translation loadedTranslations;

int main() {
int tryFile = 0;
parseIndexFile(
&tryFile,
int tryFile = parseIndexFile(
&loadedTranslations,
"../bibles/web.i"
);
@@ -20,9 +17,9 @@ int main() {
return 0;
}

int tryReader;
struct Reader reader = reader_new(
&tryReader,
struct Reader reader;
int tryReader = reader_new(
&reader,
&loadedTranslations,
"John",
3,


Loading…
Cancel
Save