added comments and cleaned up trailing spaces
This commit is contained in:
parent
7012998cfa
commit
11900ca5cc
@ -1,2 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* This function converts the latin1 ISO_8859-1 encoding into utf-8.
|
||||||
|
*/
|
||||||
char *latin2utf8(char *input);
|
char *latin2utf8(char *input);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function converts the utf-8 encoding into latin1 ISO_8859-1.
|
||||||
|
*/
|
||||||
char *utf82latin(char *input);
|
char *utf82latin(char *input);
|
||||||
|
37
src/main.h
37
src/main.h
@ -1,5 +1,14 @@
|
|||||||
#define MEANING 30 + 12
|
#define MEANING 30 + 12
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This struct houses all the information from the .conf file.
|
||||||
|
*
|
||||||
|
* file is the output xml file
|
||||||
|
* bible is the bible we are searching for
|
||||||
|
* book is the book we are searching for
|
||||||
|
* chapter contains the name of the chapter
|
||||||
|
* chapter_numbers contains the specific chapter numbers to search for
|
||||||
|
*/
|
||||||
struct configuration {
|
struct configuration {
|
||||||
char *file;
|
char *file;
|
||||||
char *bible;
|
char *bible;
|
||||||
@ -8,6 +17,14 @@ struct configuration {
|
|||||||
char *chapter_numbers;
|
char *chapter_numbers;
|
||||||
} typedef CONFIG;
|
} typedef CONFIG;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This struct houses all the data for a specific chapter.
|
||||||
|
*
|
||||||
|
* chapter is the chapter number of the struct
|
||||||
|
* current is used to track iteration in the struct
|
||||||
|
* verses is the number of verses contained in the verse variable
|
||||||
|
* verse contains the verses
|
||||||
|
*/
|
||||||
struct chapterdata {
|
struct chapterdata {
|
||||||
int chapter;
|
int chapter;
|
||||||
int current;
|
int current;
|
||||||
@ -15,14 +32,34 @@ struct chapterdata {
|
|||||||
char **verse;
|
char **verse;
|
||||||
} typedef CHAPTER;
|
} typedef CHAPTER;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This struct contains the data for the book and it's chapters.
|
||||||
|
* current is used for iteration in the struct
|
||||||
|
* chapters is the ammount of chapters that are contained in the chapter variable
|
||||||
|
* chapter contains all of the chapters
|
||||||
|
*/
|
||||||
struct bookdata {
|
struct bookdata {
|
||||||
int current;
|
int current;
|
||||||
int chapters;
|
int chapters;
|
||||||
CHAPTER **chapter;
|
CHAPTER **chapter;
|
||||||
} typedef BOOK;
|
} typedef BOOK;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Global variables.
|
||||||
|
*
|
||||||
|
* config contains the configuration that has been loaded from the .conf file
|
||||||
|
* book contains all the information read from Biblia.txt
|
||||||
|
*/
|
||||||
CONFIG *config;
|
CONFIG *config;
|
||||||
BOOK *book;
|
BOOK *book;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function is called on exit to clean up the memory usage.
|
||||||
|
*/
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Print information on the program's usage. If the argument is 1, the user
|
||||||
|
* put something incorrect as an argument.
|
||||||
|
*/
|
||||||
void printusage(int error);
|
void printusage(int error);
|
||||||
|
@ -5,8 +5,10 @@
|
|||||||
#include <libxml/tree.h>
|
#include <libxml/tree.h>
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
/*
|
||||||
int makexml() {
|
* This function generates the xml and saves it to the output file.
|
||||||
|
*/
|
||||||
|
void makexml() {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
int length;
|
int length;
|
||||||
@ -40,6 +42,7 @@ int makexml() {
|
|||||||
xmlAddChild(node, text);
|
xmlAddChild(node, text);
|
||||||
xmlAddChild(booktag, node);
|
xmlAddChild(booktag, node);
|
||||||
|
|
||||||
|
/* add the chapters */
|
||||||
for (i = 0; i < book->chapters; i++) {
|
for (i = 0; i < book->chapters; i++) {
|
||||||
chaptertag = xmlNewNode(NULL, BAD_CAST "Capitulo");
|
chaptertag = xmlNewNode(NULL, BAD_CAST "Capitulo");
|
||||||
xmlAddChild(booktag, chaptertag);
|
xmlAddChild(booktag, chaptertag);
|
||||||
@ -55,6 +58,7 @@ int makexml() {
|
|||||||
|
|
||||||
free(temp);
|
free(temp);
|
||||||
|
|
||||||
|
/* add the verses */
|
||||||
chapter = book->chapter[i];
|
chapter = book->chapter[i];
|
||||||
chapter->current = 0;
|
chapter->current = 0;
|
||||||
for (chapter->current = 0; chapter->current < chapter->verses; chapter->current++) {
|
for (chapter->current = 0; chapter->current < chapter->verses; chapter->current++) {
|
||||||
@ -90,6 +94,4 @@ int makexml() {
|
|||||||
xmlFreeDoc(doc);
|
xmlFreeDoc(doc);
|
||||||
xmlCleanupParser();
|
xmlCleanupParser();
|
||||||
xmlMemoryDump();
|
xmlMemoryDump();
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -1 +1,4 @@
|
|||||||
int makexml();
|
/*
|
||||||
|
* This function generates the xml and saves it to the output file.
|
||||||
|
*/
|
||||||
|
void makexml();
|
||||||
|
@ -15,7 +15,7 @@ int readconfig(char *config_file) {
|
|||||||
xmlNodePtr node = NULL;
|
xmlNodePtr node = NULL;
|
||||||
xmlNodePtr subnode = NULL;
|
xmlNodePtr subnode = NULL;
|
||||||
|
|
||||||
/* Initilize the library */
|
/* initilize the library */
|
||||||
LIBXML_TEST_VERSION
|
LIBXML_TEST_VERSION
|
||||||
|
|
||||||
context = xmlNewParserCtxt();
|
context = xmlNewParserCtxt();
|
||||||
|
@ -1 +1,5 @@
|
|||||||
|
/*
|
||||||
|
* This function reads the designated config file and save into int the
|
||||||
|
* config struct.
|
||||||
|
*/
|
||||||
int readconfig(char *config_file);
|
int readconfig(char *config_file);
|
||||||
|
@ -8,6 +8,10 @@
|
|||||||
#include "readfile.h"
|
#include "readfile.h"
|
||||||
#include "encoding.h"
|
#include "encoding.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function reads Biblia.txt, searches for the information in config,
|
||||||
|
* and stores it into an array of strings to be used later to create the xml.
|
||||||
|
*/
|
||||||
int readfile() {
|
int readfile() {
|
||||||
FILE *file = NULL;
|
FILE *file = NULL;
|
||||||
CHAPTER *chapter = NULL;
|
CHAPTER *chapter = NULL;
|
||||||
@ -126,6 +130,7 @@ int readfile() {
|
|||||||
}
|
}
|
||||||
if (line != NULL) {
|
if (line != NULL) {
|
||||||
if (strcmp(line, config->bible) == 0) {
|
if (strcmp(line, config->bible) == 0) {
|
||||||
|
/* found the bible */
|
||||||
matches[0] = true;
|
matches[0] = true;
|
||||||
matches[1] = false;
|
matches[1] = false;
|
||||||
matches[2] = false;
|
matches[2] = false;
|
||||||
@ -134,6 +139,7 @@ int readfile() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (strcmp(line, config->book) == 0) {
|
if (strcmp(line, config->book) == 0) {
|
||||||
|
/* found the book */
|
||||||
matches[1] = true;
|
matches[1] = true;
|
||||||
matches[2] = false;
|
matches[2] = false;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -145,6 +151,7 @@ int readfile() {
|
|||||||
temp = (char *) malloc((length + 2) * sizeof(char));
|
temp = (char *) malloc((length + 2) * sizeof(char));
|
||||||
snprintf(temp, length + 2, "%s %d", config->chapter, i);
|
snprintf(temp, length + 2, "%s %d", config->chapter, i);
|
||||||
if (strcmp(line, temp) == 0) {
|
if (strcmp(line, temp) == 0) {
|
||||||
|
/* found a chapter */
|
||||||
matches[2] = true;
|
matches[2] = true;
|
||||||
book->current++;
|
book->current++;
|
||||||
book->chapter[book->current] = (CHAPTER *) malloc(sizeof(CHAPTER));
|
book->chapter[book->current] = (CHAPTER *) malloc(sizeof(CHAPTER));
|
||||||
@ -160,6 +167,7 @@ int readfile() {
|
|||||||
free(temp);
|
free(temp);
|
||||||
}
|
}
|
||||||
if (matches[0] == true && matches[1] == true && matches[2] == true) {
|
if (matches[0] == true && matches[1] == true && matches[2] == true) {
|
||||||
|
/* 3 matches, start getting the verses */
|
||||||
length = snprintf(NULL, 0, "%d", end + 1) + strlen(config->chapter);
|
length = snprintf(NULL, 0, "%d", end + 1) + strlen(config->chapter);
|
||||||
temp = (char *) malloc((length + 2) * sizeof(char));
|
temp = (char *) malloc((length + 2) * sizeof(char));
|
||||||
snprintf(temp, length + 2, "%s %d", config->chapter, end + 1);
|
snprintf(temp, length + 2, "%s %d", config->chapter, end + 1);
|
||||||
@ -215,6 +223,7 @@ int readfile() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (matches[0] == true && matches[1] == true && matches[2] == true && strcmp(line, "------------------------------------------------------------------------") == 0) {
|
if (matches[0] == true && matches[1] == true && matches[2] == true && strcmp(line, "------------------------------------------------------------------------") == 0) {
|
||||||
|
/* end of a section and we already have 3 matches, no reason to continue */
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("Bible end match: %lu -> %s\n", (long) j + 1, line);
|
printf("Bible end match: %lu -> %s\n", (long) j + 1, line);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,2 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This variable controls how much memory is used to start with,
|
||||||
|
* mesured in bytes.
|
||||||
|
*/
|
||||||
#define MAX_LINES 100
|
#define MAX_LINES 100
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function reads Biblia.txt, searches for the information in config,
|
||||||
|
* and stores it into an array of strings to be used later to create the xml.
|
||||||
|
*/
|
||||||
int readfile();
|
int readfile();
|
||||||
|
Loading…
Reference in New Issue
Block a user