Browse Source

Initial C demo commit

master
Daniel 1 year ago
parent
commit
f146ece076
5 changed files with 94 additions and 2 deletions
  1. +2
    -0
      .gitignore
  2. +3
    -0
      .gitmodules
  3. +2
    -2
      LICENSE
  4. +1
    -0
      biblec
  5. +86
    -0
      test.c

+ 2
- 0
.gitignore View File

@@ -9,3 +9,5 @@ words

data/
data
*.out
a.out

+ 3
- 0
.gitmodules View File

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

+ 2
- 2
LICENSE View File

@@ -1,4 +1,4 @@
MIT License Copyright (c) 2020- Daniel
MIT License Copyright (c) 2020 - Daniel C

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -16,4 +16,4 @@ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 1
- 0
biblec

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

+ 86
- 0
test.c View File

@@ -0,0 +1,86 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "biblec/main.h"
#include "biblec/biblec.h"

struct Search {
char *word[20];
int hits[20];
int wordsLength;
};

struct Search mySearch = {
{"for", "god", "so", "loved"},
{0, 0, 0, 0},
4
};

int findWords(struct Search *search, char *word) {
for (int w = 0; w < search->wordsLength; w++) {
if (!strcmp(search->word[w], word)) {
search->hits[w]++;
}
}
}

int main() {
struct Translation translation;
int tryFile = 0;
parseIndexFile(
&tryFile,
&translation,
"biblec/bibles/web.i",
"biblec/bibles/web.t"
);

if (tryFile) {
puts("Index parsing error");
return 0;
}

FILE *verseFile = fopen(translation.location, "r");
if (verseFile == NULL) {
puts("err");
return -1;
}

char word[50];
int wordC = 0;

char buffer[VERSE_LENGTH];
while (fgets(buffer, VERSE_LENGTH, verseFile) != 0) {
for (int c = 0; buffer[c] != '\0'; c++) {
// Make sure this is an alphabetical character
if (buffer[c] >= 'a' && buffer[c] <= 'z') {
word[wordC] = buffer[c];
wordC++;
} else if (buffer[c] >= 'A' && buffer[c] <= 'Z') {
word[wordC] = buffer[c] + ('a' - 'A'); // Make character lowercase
wordC++;
} else if (buffer[c] == ' ' || buffer[c] == '-') {
// Reset once we encounter new line
word[wordC] = '\0';
wordC = 0;

findWords(&mySearch, word);
}
}
}

for (int i = 0; i < mySearch.wordsLength; i++) {
printf("%d ", mySearch.hits[i]);
}

fclose(verseFile);
}

/*
Hits:
John 3 16 for, god, so, loved
Heb 4 12 for, god, so




*/

Loading…
Cancel
Save