detect chapter
This commit is contained in:
parent
c713995372
commit
af1665c065
@ -6,6 +6,6 @@
|
|||||||
<book>SAN MATEO</book>
|
<book>SAN MATEO</book>
|
||||||
<chapter>
|
<chapter>
|
||||||
<name>MATEO</name>
|
<name>MATEO</name>
|
||||||
<number>1-2</number>
|
<number>16-20</number>
|
||||||
</chapter>
|
</chapter>
|
||||||
</config>
|
</config>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "readfile.h"
|
#include "readfile.h"
|
||||||
@ -10,13 +11,19 @@ int readfile(CONFIG *config) {
|
|||||||
FILE *file = NULL;
|
FILE *file = NULL;
|
||||||
int start = 0;
|
int start = 0;
|
||||||
int end = 0;
|
int end = 0;
|
||||||
|
int length;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
|
char *temp = NULL;
|
||||||
char **array = NULL;
|
char **array = NULL;
|
||||||
ssize_t chars = 0;
|
ssize_t chars = 0;
|
||||||
size_t lines = 0;
|
size_t lines = 0;
|
||||||
size_t j = 0;
|
size_t j = 0;
|
||||||
size_t new_max = MAX_LINES;
|
size_t new_max = MAX_LINES;
|
||||||
|
bool matches[3];
|
||||||
|
matches[0] = false;
|
||||||
|
matches[1] = false;
|
||||||
|
matches[2] = false;
|
||||||
|
|
||||||
char *ch = strtok(config->chapter_numbers, "-");
|
char *ch = strtok(config->chapter_numbers, "-");
|
||||||
while (ch != NULL) {
|
while (ch != NULL) {
|
||||||
@ -101,15 +108,32 @@ int readfile(CONFIG *config) {
|
|||||||
/* printf(" array [%lu] %s\n", (long) j, line); */
|
/* printf(" array [%lu] %s\n", (long) j, line); */
|
||||||
if (line != NULL) {
|
if (line != NULL) {
|
||||||
if (strcmp(line, config->bible) == 0) {
|
if (strcmp(line, config->bible) == 0) {
|
||||||
|
matches[0] = true;
|
||||||
|
matches[1] = false;
|
||||||
|
matches[2] = false;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("Bible match: %lu -> %s\n", (long) j, line);
|
printf("Bible match: %lu -> %s\n", (long) j + 1, line);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (strcmp(line, config->book) == 0) {
|
if (strcmp(line, config->book) == 0) {
|
||||||
|
matches[1] = true;
|
||||||
|
matches[2] = false;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("Book match: %lu -> %s\n", (long) j, line);
|
printf("Book match: %lu -> %s\n", (long) j + 1, line);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
for (i = start; i <=end; i++) {
|
||||||
|
length = snprintf(NULL, 0, "%d", i) + strlen(config->chapter);
|
||||||
|
temp = (char *) malloc((length + 2) * sizeof(char));
|
||||||
|
snprintf(temp, length + 2, "%s %d", config->chapter, i);
|
||||||
|
if (strcmp(line, temp) == 0) {
|
||||||
|
matches[2] = true;
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf("Chapter match: %lu -> %s\n", (long) j + 1, line);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
free(temp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
free(line);
|
free(line);
|
||||||
line = NULL;
|
line = NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user