Browse Source

init

master
Daniel 1 year ago
commit
79da716b48
7 changed files with 250 additions and 0 deletions
  1. +123
    -0
      book.c
  2. +12
    -0
      book.h
  3. +84
    -0
      config.c
  4. +16
    -0
      config.h
  5. +4
    -0
      fbrp_biblec.c
  6. +1
    -0
      fbrp_haplous.c
  7. +10
    -0
      heb12.h

+ 123
- 0
book.c View File

@@ -0,0 +1,123 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#include "book.h"

struct OSISBooks osisbooks[66] = {
{"Gen", {"Genesis", "genesis"}, 2},
{"Exod", {"Exodus", "exodus"}, 2},
{"Lev", {"Leviticus", "leviticus"}, 2},
{"Num", {"Numbers", "numbers"}, 2},
{"Deut", {"Deuteronomy", "deuteronomy"}, 2},
{"Josh", {"Joshua", "joshua"}, 2},
{"Judg", {"Judges", "judges"}, 2},
{"Ruth", {"Ruth", "ruth"}, 2},
{"1Sam", {"1 Samuel", "1samuel"}, 2},
{"2Sam", {"2 Samuel", "2samuel"}, 2},
{"1Kng", {"1 Kings", "1kings"}, 2},
{"2Kng", {"2 Kings", "2kings"}, 2},
{"1Chr", {"1 Chronicles", "1chronicles"}, 2},
{"2Chr", {"2 Chronicles", "2chronicles"}, 2},
{"Ezr", {"Ezra", "ezra"}, 2},
{"Neh", {"Nehemiah", "nehemiah"}, 2},
{"Est", {"Esther", "esther"}, 2},
{"Job", {"Job", "job"}, 2},
{"Ps", {"Psalms", "psalms"}, 2},
{"Pro", {"Proverbs", "proverbs"}, 2},
{"Ecc", {"Ecclesiastes", "ecclesiastes"}, 2},
{"Song", {"Song of Solomon", "songofsolomon", "songs", "sos"}, 4},
{"Isa", {"Isaiah", "isaiah"}, 2},
{"Jer", {"Jeremiah", "jeremiah"}, 2},
{"Lam", {"Lamentations", "lamentations"}, 2},
{"Eze", {"Ezekiel", "ezekiel"}, 2},
{"Dan", {"Daniel", "daniel"}, 2},
{"Hos", {"Hosea", "hosea"}, 2},
{"Joe", {"Joel", "joel"}, 2},
{"Amo", {"Amos", "amos"}, 2},
{"Oba", {"Obadiah", "obadiah"}, 2},
{"Jon", {"Jonah", "jonah"}, 2},
{"Mic", {"Micah", "micah"}, 2},
{"Nah", {"Nahum", "nahum"}, 2},
{"Hab", {"Habakkuk", "habakkuk"}, 2},
{"Zep", {"Zephaniah", "zephaniah"}, 2},
{"Hag", {"Haggai", "haggai"}, 2},
{"Zec", {"Zechariah", "zechariah"}, 2},
{"Mal", {"Malachi", "malachi"}, 2},
{"Mat", {"Matthew", "matthew"}, 2},
{"Mar", {"Mark", "mark"}, 2},
{"Luk", {"Luke", "luke"}, 2},
{"John", {"John", "john"}, 2},
{"Act", {"Acts", "acts"}, 2},
{"Rom", {"Romans", "romans"}, 2},
{"1Cor", {"1 Corinthians", "1corinthians"}, 2},
{"2Cor", {"2 Corinthians", "2corinthians"}, 2},
{"Gal", {"Galatians", "galatians"}, 2},
{"Eph", {"Ephesians", "ephesians"}, 2},
{"Phi", {"Philippians", "philippians"}, 2},
{"Col", {"Colossians", "colossians"}, 2},
{"1The", {"1 Thessalonians", "1thessalonians"}, 2},
{"2The", {"2 Thessalonians", "2thessalonians"}, 2},
{"1Tim", {"1 Timothy", "1timothy"}, 2},
{"2Tim", {"2 Timothy", "2timothy"}, 2},
{"Titus", {"Titus", "titus"}, 2},
{"Phil", {"Philemon", "philemon"}, 2},
{"Heb", {"Hebrews", "hebrews"}, 2},
{"Jam", {"James", "james"}, 2},
{"1Pet", {"1 Peter", "1peter"}, 2},
{"2Pet", {"2 Peter", "2peter"}, 2},
{"1Joh", {"1 John", "1john"}, 2},
{"2Joh", {"2 John", "2john"}, 2},
{"3Joh", {"3 John", "3john"}, 2},
{"Jude", {"Jude", "jude"}, 2},
{"Rev", {"Revelation", "revelation"}, 2}
};

// Case insensitive strcmp
// I wrote this quickly without testing
// it very much, so it may be flawed.
int strcmpcase(char *s1, char *s2) {
int diff = 0;

while (*s1 | *s2) {
s1++;
s2++;

if (tolower(*s1) != tolower(*s2)) {
diff++;
}
}

return diff;
}

int osisbook(char *string, char buffer[]) {
#define BOOKSLEN (int)(sizeof(osisbooks) / sizeof(osisbooks[0]))
// Loop through all the books
for (int b = 0; b < BOOKSLEN; b++) {
if (!strcmpcase(string, osisbooks[b].osis)) {
strcpy(buffer, osisbooks[b].osis);
return 0;
}
// Check alt book names
for (int a = 0; a < osisbooks[b].length; a++) {
if (!strcmpcase(string, osisbooks[b].alt[a])) {
strcpy(buffer, osisbooks[b].osis);
return 0;
}
}
}

return 1;
}

#ifdef TEST
int main() {
char buffer[100];
osisbook("Song", buffer);
puts(buffer);
}
#endif

+ 12
- 0
book.h View File

@@ -0,0 +1,12 @@
#ifndef BOOK_H
#define BOOK_H

int osisbook(char *string, char buffer[]);

struct OSISBooks {
char osis[64];
char *alt[5];
int length;
};

#endif

+ 84
- 0
config.c View File

@@ -0,0 +1,84 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef __WIN32
#define SEPARATOR "\\"
#else
#define SEPARATOR "/"
#endif

// the subdirectory for configuration
#define NAME "heb12"

// TODO: consider a more generic find-and-replace scheme to clean up the code
// and merging the body of heb12_config_dir and heb12_data_dir, and making the
// directories more directly configurable with macros

// Return the configuration directory with an optional subdirectory or file (can
// accept NULL or "" to ignore)
char *heb12_config_dir(const char *subdir, size_t buf_len, char *buf)
{
#ifdef HEB12_CONFIG_DIR
if (HEB12_DATA_DIR[0] != '~') {
strncpy(buf, HEB12_DATA_DIR, buf_len);
} else {
strncpy(buf, getenv("HOME"), buf_len);
strncat(buf, HEB12_DATA_DIR, buf_len);
}
#else
#ifdef _WIN32
strncpy(buf, getenv("\%ProgramFiles\%"), buf_len);
strncat(buf, "\\", buf_len);
strncat(buf, NAME, buf_len);
#elif __unix__
strncpy(buf, getenv("HOME"), buf_len);
strncat(buf, "/.config/", buf_len);
strncat(buf, NAME, buf_len);
#else
#error "Unsupported OS"
#endif
#endif
if (subdir != NULL && strcmp(subdir, "") != 0) {
strncat(buf, SEPARATOR, buf_len);
strncat(buf, subdir, buf_len);
}
return buf;
}

// Return the data directory (for Bibles and similar) with an optional
// subdirectory or file (can accept NULL or "" to ignore)
char *heb12_data_dir(const char *subdir, size_t buf_len, char *buf)
{
#ifdef HEB12_DATA_DIR
if (HEB12_DATA_DIR[0] != '~') {
strncpy(buf, HEB12_DATA_DIR, buf_len);
} else {
strncpy(buf, getenv("HOME"), buf_len);
strncat(buf, HEB12_DATA_DIR, buf_len);
}
#else
#ifdef _WIN32
// should be C:\User\Name\AppData\Roaming
strncpy(buf, getenv("\%APPDATA\%"), buf_len);
strncat(buf, "\\", buf_len);
strncat(buf, NAME, buf_len);
#elif __unix__
char *dir;
if ((dir = getenv("XDG_DATA_HOME")) == NULL) {
strncpy(buf, getenv("HOME"), buf_len);
strncat(buf, "/.local/share/", buf_len);
strncat(buf, NAME, buf_len);
} else {
strncpy(buf, dir, buf_len);
};
#else
#error "Unsupported OS"
#endif
#endif
if (subdir != NULL && strcmp(subdir, "") != 0) {
strncat(buf, SEPARATOR, buf_len);
strncat(buf, subdir, buf_len);
}
return buf;
}

+ 16
- 0
config.h View File

@@ -0,0 +1,16 @@
#ifndef HEB12_CONFIG_H_
#define HEB12_CONFIG_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <stddef.h>

char *heb12_config_dir(const char *, size_t, char *);
char *heb12_data_dir(const char *, size_t, char *);

#ifdef __cplusplus
}
#endif
#endif

+ 4
- 0
fbrp_biblec.c View File

@@ -0,0 +1,4 @@
// Glue for FBRP and BibleC...

#include <fbrp.h>
#include <biblec.h>

+ 1
- 0
fbrp_haplous.c View File

@@ -0,0 +1 @@
// Glue for FBRP and haplous...

+ 10
- 0
heb12.h View File

@@ -0,0 +1,10 @@
#ifndef HEB12_H
#define HEB12_H

// Format verses like so: John 3:16
#define STDVERSE "%s %d:%d"

// If needed: "John 3 16-16"
#define STDVERSETO "%s %d:%d-%d"

#endif

Loading…
Cancel
Save