Browse Source

Working

master
Daniel 1 year ago
parent
commit
d58c647202
8 changed files with 57 additions and 46 deletions
  1. +2
    -0
      .gitignore
  2. +0
    -3
      .gitmodules
  3. +2
    -2
      Makefile
  4. +0
    -1
      biblec
  5. +2
    -3
      biblesearch.h
  6. +15
    -30
      bsearch.c
  7. +15
    -0
      bsearch.h
  8. +21
    -7
      test.c

+ 2
- 0
.gitignore View File

@@ -15,3 +15,5 @@ legacy/data
a.out

_main.c
biblec/*
biblec

+ 0
- 3
.gitmodules View File

@@ -1,3 +0,0 @@
[submodule "biblec"]
path = biblec
url = https://code.heb12.com/heb12/biblec

+ 2
- 2
Makefile View File

@@ -1,8 +1,8 @@
CC := cc
t ?= web
dir ?= ../heb12cli

default:
@$(CC) biblec/biblec.c bsearch.c test.c -o test.out
@$(CC) -I$(dir) $(dir)/biblec/biblec.c bsearch.c test.c -o test.out
@./test.out
@rm -rf *.out



+ 0
- 1
biblec

@@ -1 +0,0 @@
Subproject commit a8cf1c7d280f369a57aca604e7b1f773d4eb8cb3

+ 2
- 3
biblesearch.h View File

@@ -1,13 +1,12 @@
#ifndef BIBLESEARCH_H
#define BIBLESEARCH_H

#define MIN_WORD 2

#define MAX_HITS 100000
#define MAX_WORD 128
#define MAX_RESULT 1000
#define MIN_WORD 2

int bsearch_getVerse(char buffer[], int line);
int bsearch_get(char **words, int length, int result[]);
int bsearch_open(char **words, int length, int result[], struct BibleC_translation translation);

#endif

+ 15
- 30
bsearch.c View File

@@ -1,28 +1,22 @@
// This will find duplicates in a file, sadly
// not accurate searching yet, needs to be fixed

// TODO:
// error system
// bsearch? biblesearch?


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "biblec/main.h"
#include "biblesearch.h"
#include <biblec/main.h>

struct Biblec_translation translation;
#include "bsearch.h"

// Get verse from line number in BibleC file
// (broken)
int bsearch_getVerse(char buffer[], int line) {
int bsearch_getVerse(char buffer[], int line, struct Biblec_translation *translation) {
int result = 0;

// Locate book
int book = 0;
while (translation.books[book].start <= line) {
while (translation->books[book].start <= line) {
if (book >= MAX_BOOKS) {
return -1;
}
@@ -32,34 +26,34 @@ int bsearch_getVerse(char buffer[], int line) {

book--;
result = translation.books[book].start;
result = translation->books[book].start;

// Get right under last chapter
int chapter = 0;
while (result <= line) {
if (chapter > translation.books[book].length) {
if (chapter > translation->books[book].length) {
return -1;
}

result += translation.books[book].chapters[chapter];
result += translation->books[book].chapters[chapter];
chapter++;
}
result -= translation.books[book].chapters[chapter - 1];
result -= translation->books[book].chapters[chapter - 1];
line -= result;

// (verses start at zero)
line++;

sprintf(buffer, "%s %d %d", translation.books[book].name, chapter, line);
sprintf(buffer, "%s %d %d", translation->books[book].name, chapter, line);
return 0;
}

int getHits(int hits[], char string[]) {
int getHits(int hits[], char string[], struct Biblec_translation *translation) {
int hit = 0;
int line = 0;
FILE *verseFile = fopen(translation.location, "r");
FILE *verseFile = fopen(translation->location, "r");
if (verseFile == NULL) {
free(hits);
return -1;
@@ -83,7 +77,6 @@ int getHits(int hits[], char string[]) {
// Quit if no useful data was read
if (wc <= MIN_WORD) {
word[wc] = '\0';
//printf("%d\n", hit);
wc = 0;
continue;
}
@@ -118,17 +111,9 @@ int getHits(int hits[], char string[]) {
return hit;
}

int bsearch_get(char **words, int length, int result[]) {
int tryFile = biblec_parse(
&translation,
"biblec/bibles/web.i"
);

if (tryFile) {
return -1;
}
int hit1 = getHits(result, words[0]);
int bsearch_open(char **words, int length, int result[],
struct Biblec_translation *translation) {
int hit1 = getHits(result, words[0], translation);
if (hit1 == -1) {
return -1;
}
@@ -144,7 +129,7 @@ int bsearch_get(char **words, int length, int result[]) {
}
int *hits2 = malloc(MAX_HITS);
int hit2 = getHits(hits2, words[w]);
int hit2 = getHits(hits2, words[w], translation);
if (hit2 == -1) {
free(hits2);
return -1;


+ 15
- 0
bsearch.h View File

@@ -0,0 +1,15 @@
#ifndef BIBLESEARCH_H
#define BIBLESEARCH_H

#define MAX_HITS 100000
#define MAX_WORD 128
#define MAX_RESULT 1000
#define MIN_WORD 2

int bsearch_getVerse(char buffer[], int line,
struct Biblec_translation *translation);

int bsearch_open(char **words, int length, int result[],
struct Biblec_translation *translation);

#endif

+ 21
- 7
test.c View File

@@ -2,19 +2,33 @@
#include <stdlib.h>
#include <string.h>

#include "biblesearch.h"
#include <biblec/main.h>

#include "bsearch.h"

struct Biblec_translation translation;

int main() {
int tryFile = biblec_parse(
&translation,
"/home/dan/.local/share/heb12/web.i"
);

if (tryFile) {
return -1;
}

char *mySearch[] = {
"created",
"beginning"
};

int *result = malloc(MAX_HITS);
int c = bsearch_get(
mySearch,
int c = bsearch_open(
mySearch,
sizeof(mySearch) / sizeof(mySearch[0]),
result
result,
&translation
);

printf("Result: %d\n", c);
@@ -25,16 +39,16 @@ int main() {

char buffer[128];
for (int i = 0; i < c; i++) {
bsearch_getVerse(buffer, result[i]);
bsearch_getVerse(buffer, result[i], &translation);
printf("%d\t%s\n", result[i], buffer);
}

free(result);

puts("bsearch_getVerse bugs:");
bsearch_getVerse(buffer, 30650);
bsearch_getVerse(buffer, 30650, &translation);
puts(buffer);
bsearch_getVerse(buffer, 31093);
bsearch_getVerse(buffer, 31093, &translation);
puts(buffer);

return 0;


Loading…
Cancel
Save