Browse Source

Auto detect .t location

master
Daniel 1 week ago
parent
commit
4e6bc6fef8
2 changed files with 14 additions and 6 deletions
  1. +12
    -3
      biblec.c
  2. +2
    -3
      test.c

+ 12
- 3
biblec.c View File

@@ -2,7 +2,7 @@
#include <string.h>
#include "main.h"

// Simple+fast minimal function for atoi
// Split chars and ints from string
int strToInt(char *buf) {
int ret = 0;
for (; *buf != '\0'; buf++) {
@@ -21,6 +21,11 @@ void parseIndexFile(int *error, struct Translation *translation, char *indexLoca
return;
}

// If location is never filled in, then assume text
// file location is in the same folder as the index file.
indexLocation[strlen(indexLocation) - 1] = 't';
strcpy(translation->location, indexLocation);

char line[INDEX_MAX_LENGTH];
int book = 0;
while (fgets(line, INDEX_MAX_LENGTH, index) != NULL) {
@@ -54,7 +59,7 @@ void parseIndexFile(int *error, struct Translation *translation, char *indexLoca
} else if (!strcmp(afterFirst, "location")) {
strcpy(translation->location, contents);
} else if (!strcmp(afterFirst, "length")) {
translation->length = strToInt(contents); // TODO: Fix
translation->length = strToInt(contents);
}
} else if (line[0] == '@') {
char *bookInfo = strtok(afterFirst, " ");
@@ -112,7 +117,7 @@ int reader_next(struct Reader *reader) {
return 0;
}

// Get verses into array
// 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;
@@ -156,6 +161,10 @@ struct Reader reader_new(int *error, struct Translation *translation, char *book

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

// Loop through until it gets to the line
int i = 0;


+ 2
- 3
test.c View File

@@ -12,8 +12,7 @@ int main() {
parseIndexFile(
&tryFile,
&loadedTranslations[0],
"bibles/web.i",
"bibles/web.t"
"bibles/web.i"
);

if (tryFile) {
@@ -28,7 +27,7 @@ int main() {
"John",
3,
1,
0
0 // Get whole chapter
);

if (tryReader) {


Loading…
Cancel
Save