Browse Source

Rename r to range

master
Daniel 1 month ago
parent
commit
888ff7bebf
4 changed files with 37 additions and 36 deletions
  1. +3
    -2
      README.md
  2. +5
    -21
      fbrp.c
  3. +18
    -2
      fbrp.h
  4. +11
    -11
      test.c

+ 3
- 2
README.md View File

@@ -2,9 +2,9 @@
"Flexible Bible Reference Parser"

## Features
* No standard C headers used
* No dependencies or standard C headers used
* Tiny and flexible
* One C file, one header file, no complex build system needed.
* One C file, one header file, no complex build system needed
* C99

## Can Parse:
@@ -25,5 +25,6 @@ By design, it cannot parse references like:
Like a compiler, it parses the string into a tokens.
Then, it uses that to run through each token and figure out
exactly what they all mean.

There is currently no algorithm specification, but feel free to
ask if you need any clarification.

+ 5
- 21
fbrp.c View File

@@ -1,21 +1,5 @@
#include "fbrp.h"

// Struct to store read tokens
struct Read {
char text[MAX_WORD];
int length;
int type;
};

enum Types {
DEFAULT,
DIGIT,
ALPHA,
SEPERATOR,
RANGE,
MULTIPLE
};

// Test for a char in a string. Ex: 'c' in "cake"
int testCharString(char test, char *seperators) {
for (int c = 0; seperators[c] != '\0'; c++) {
@@ -64,6 +48,7 @@ int strspt(char *string, char *result) {
}

// Simply make a custom function for strcat
// (for easy embedding programming)
void mstrcat(char *s, char *t) {
while(*s++);
--s;
@@ -75,10 +60,10 @@ void mstrcat(char *s, char *t) {
// but this is overall simpler.
void setInt(struct Reference *ref, int on, int currentlyOn, int value, int append) {
if (currentlyOn == 1) {
ref->chapter[ref->chapterLength].r[on] = value;
ref->chapter[ref->chapterLength].range[on] = value;
ref->chapterLength += append;
} else if (currentlyOn == 2) {
ref->verse[ref->verseLength].r[on] = value;
ref->verse[ref->verseLength].range[on] = value;
ref->verseLength += append;
}
}
@@ -133,20 +118,19 @@ void parseReference(struct Reference *ref, char *string) {
lastType = type;
}

// Null terminate last part
read[readY].text[readX] = '\0';
read[readY].type = partType;

// readY++ for the last part
readY++;

// Now, start interpreting
ref->chapterLength = 0;
ref->verseLength = 0;
ref->book[0] = '\0';

int currentlyOn = 0;
// Now, start interpreting
int jumping = 0;
int currentlyOn = 0;
for (int p = 0; p < readY; p++) {
// Skip range/multiple chars
if (read[p].type == RANGE || read[p].type == MULTIPLE) {


+ 18
- 2
fbrp.h View File

@@ -5,16 +5,32 @@
#define MAX_READ 25
#define MAX_WORD 20

// Struct to store read tokens
struct Read {
char text[MAX_WORD];
int length;
int type;
};

enum Types {
DEFAULT,
DIGIT,
ALPHA,
SEPERATOR,
RANGE,
MULTIPLE
};

struct Reference {
char book[BOOK_LENGTH];
struct Chapter {
int type;
int r[2];
int range[2];
int length;
}chapter[5];
struct Verse {
int type;
int r[2];
int range[2];
int length;
}verse[10];
int chapterLength;


+ 11
- 11
test.c View File

@@ -8,12 +8,12 @@ struct Reference ref;
void debugPrint(struct Reference *ref) {
printf("Book: %s\n", ref->book);

for (size_t c = 0; c < ref->chapterLength; c++) {
printf("Chapter: %d-%d\n", ref->chapter[c].r[0], ref->chapter[c].r[1]);
for (int c = 0; c < ref->chapterLength; c++) {
printf("Chapter: %d-%d\n", ref->chapter[c].range[0], ref->chapter[c].range[1]);
}

for (size_t c = 0; c < ref->verseLength; c++) {
printf("Verse: %d-%d\n", ref->verse[c].r[0], ref->verse[c].r[1]);
for (int c = 0; c < ref->verseLength; c++) {
printf("Verse: %d-%d\n", ref->verse[c].range[0], ref->verse[c].range[1]);
}
}

@@ -21,15 +21,15 @@ void parse(char *text) {
puts(text);
parseReference(&ref, text);
debugPrint(&ref);

putchar('\n');
puts("------");
}

int main() {
char ref1[] = "ABCDEFGHIJKLMNOPQSRTYCUVZ 3 16";
char ref2[] = "John 3 16-20, 17, 18-19";
parse(ref1);
parse(ref2);

parse("ABCDEFGHIJKLMNOPQSRTYCUVZ 3 16");
parse("John 3 16-20, 17, 18-19");
parse("1 John 3-4 16-17-18-19,-,-,-");
parse("2983yr92y8392r839");
parse("8AUW8DQ98DU98SD9W87DUASDJA");
parse("AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH!!!");
return 0;
}

Loading…
Cancel
Save