Browse Source

Set the range values for chapter or verses

master
Daniel 2 weeks ago
parent
commit
e55f7bab3a
3 changed files with 15 additions and 10 deletions
  1. +2
    -3
      README.md
  2. +12
    -7
      fbrp.c
  3. +1
    -0
      test.c

+ 2
- 3
README.md View File

@@ -1,9 +1,9 @@
# FBRP
"Flexible Bible Reference Parser"
FBRP is a tiny Bible reference parser written in C99. It parses
references like:
references like:
- "2 Kings 1, 3-5:2-4, 3-6, 1-2"
Into structures like this:
Into structures like this:
```
Book: 2Kings
Chapter: [1]-[1]
@@ -13,7 +13,6 @@ Verse: [3]-[6]
Verse: [1]-[2]
```


## Features
* No dependencies or even standard C headers
* One C file, one header file, no complex build system needed


+ 12
- 7
fbrp.c View File

@@ -48,16 +48,16 @@ int strspt(char *string, char *result) {
}

// Simply make a custom function for strcat
// (for easy embedding programming)
// (in case of no strings.h)
void mstrcat(char *s, char *t) {
while(*s++);
--s;
while((*s++ = *t++));
}

// A simple function to increment a the next verse or chapter.
// Set the range values for chapter or verses
// A complicated use of pointers could have been used,
// but this is overall simpler.
// but this is overall simpler. (and safer?)
void setInt(struct Reference *ref, int on, int currentlyOn, int value, int append) {
if (currentlyOn == 1) {
ref->chapter[ref->chapterLength].range[on] = value;
@@ -142,24 +142,29 @@ void parseReference(struct Reference *ref, char *string) {
int tryInt = -1;
tryInt = strspt(read[p].text, tryString);

// If text encountered after chapter, then continue
if (ref->chapterLength > 0 && tryString[0] != '\0') {
continue;
}

// If chapter added and not jumping, then set verse
if (ref->chapterLength >= 1 && jumping == 0) {
currentlyOn = 2;
}

// if book and str undefined and p != 0 then SET chapter
if (currentlyOn == 0 && *tryString == '\0' && p != 0) {
// if book and str undefined and p != 0 then set chapter
if (currentlyOn == 0 && tryString[0] == '\0' && p != 0) {
currentlyOn = 1;
}

// if book and str undefined and p == 0 then assume part of book (Ex: [3] John)
if (currentlyOn == 0 && *tryString == '\0' && p == 0) {
if (currentlyOn == 0 && tryString[0] == '\0' && p == 0) {
mstrcat(ref->book, read[p].text);
continue;
}

// if book and str valid then assume book
if (currentlyOn == 0 && *tryString != '\0') {
if (currentlyOn == 0 && tryString[0] != '\0') {
mstrcat(ref->book, read[p].text);
continue;
}


+ 1
- 0
test.c View File

@@ -32,5 +32,6 @@ int main() {
parse("8AUW8DQ98DU98SD9W87DUASDJA");
parse("AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH!!!");
parse("John 3 4294967312"); // == John 3 16 (uint overflow)
parse("John 3 v16");
return 0;
}

Loading…
Cancel
Save