Browse Source

Readme wording

master
Daniel 6 months ago
parent
commit
4a5da42485
4 changed files with 39 additions and 53 deletions
  1. +15
    -0
      Makefile
  2. +10
    -26
      README.md
  3. +13
    -24
      compiler.js
  4. +1
    -3
      test.c

+ 15
- 0
Makefile View File

@@ -0,0 +1,15 @@
t ?= web

all: clean translation compile

compile:
@$(CC) *.c
@valgrind ./a.out

translation:
@mkdir bibles; curl http://api.heb12.com/translations/json/en/$(t).json > bibles/$(t).json
@node compiler.js ./bibles/$(t).json c bibles
@node compiler.js ./bibles/$(t).json i bibles

clean:
@rm -rf *.i *.json *.t bibles *.out

+ 10
- 26
README.md View File

@@ -1,31 +1,20 @@
# BibleC
A minimal Bible format in C.

A minimal Bible format designed for the C language.
It uses a JS script to convert a OSIS JSON file (http://api.heb12.com/translations/json/)
to a minimal format designed with minimalism in mind.

It creates an index file, and then a text file. The index file can be used to calculate
what line a verse starts on in the text file, and it seeks to it.
## Design:
1. First calculates the line of Bible verse, then grabs it (very fast)
2. Support for more than 1 verse (John 3 16-18)
3. Support for getting entire chapter
4. Load an BibleC index file or C header file
5. 1 C file, 1 header file, no complex build system needed
6. No memory allocations

## Usage:
```
mkdir bibles
wget http://api.heb12.com/translations/json/en/web.json
node compiler.js ./web.json web bibles
tcc biblec.c test.c
./a.out
```
*Note: Any C99 compiler should work.

## Features:
1. First calculates line of Bible verse, then grabs it
2. Support for more than 1 verse (John 3 16-18)
3. Support for Getting entire chapter
4. Load an index file or header file
See Makefile

## API:
See test.c for a full example.
```
// Load header translation
struct Biblec_reader reader;
int tryReader = biblec_new(
&reader,
@@ -40,8 +29,3 @@ while (biblec_next(reader)) {
puts(reader.result);
}
```

```
// Load via index file
// (see test.c)
```

+ 13
- 24
compiler.js View File

@@ -21,7 +21,7 @@ function cli() {
BibleC v0.1.1\n
node compile.js <file> <type> <output folder>\n
file: Input file, Ex: ./jubl2000.json\n
type: c or text\n
type: c or i (BibleC index)\n
output folder: Folder to output to. Ex: bibles/data\n
`);

@@ -31,7 +31,7 @@ function cli() {
type = param[3];
folder = param[4];
} else {
console.log("Not enough parameters.\nUse as `node main.js ./jubl2000.json web bible/web`");
console.log("Not enough parameters.\nUse as `node main.js ./jubl2000.json i bible/web`");
process.exit();
}

@@ -56,19 +56,12 @@ function cli() {
// biblec index file
if (type == 'c') {
generateCStruct(bibleData, name);
fs.writeFile(
folder + "/" + name + ".c",
indexFile,
function (err) {error.push(err)}
);

// TODO: Replace 66 with real calculated number
fs.writeFile(
folder + "/" + name + ".h",
`extern struct Translation ` + name + `[66];`,
indexFile,
function (err) {error.push(err)}
);
} else {
} else if (type == 'i') {
generateIndexFile(bibleData, name, lang);
console.log(indexFile);
fs.writeFile(
@@ -76,14 +69,14 @@ function cli() {
indexFile,
function (err) {error.push(err)}
);
} else {
console.log("Error, unknown type ", type);
return;
}

console.log("Done. Errors: ", error);
}




function parseBible(bibleData) {
var linesPassed = [0];
for (var b = 0; b < bible.length; b++) {
@@ -144,18 +137,14 @@ function generateIndexFile(bibleData, name, lang) {
// Convert the JS object into a C struct.
function generateCStruct(bibleData, name) {
// Include main C structs.
indexFile = `
struct Biblec_Translation ` + name + ` = {
` + bible.length + `,
{`;

// indexFileialize the C struct by generating C code
indexFile = `struct Biblec_translation ` + name + ` = {\nMAX_BOOKS,\n{\n`;
for (var i = 0; i < bibleData.length; i++) {
indexFile += ` {`;
indexFile += `"` + bibleData[i].book + `", `;
indexFile += `{`;
indexFile += `"` + bibleData[i].book + `",`;

indexFile += bibleData[i].start + `, `;
indexFile += bibleData[i].end + `, `;
indexFile += bibleData[i].start + `,`;
indexFile += bibleData[i].end + `,`;

indexFile += `{` + bibleData[i].chapters.join(", ") + `}`;
indexFile += `}`;


+ 1
- 3
test.c View File

@@ -1,11 +1,9 @@
// Test:
// cc *.c; valgrind ./a.out
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "main.h"
#include "biblec.h"

struct Biblec_translation translation;



Loading…
Cancel
Save