added comments and cleaned up trailing spaces

This commit is contained in:
Chris Cromer 2016-10-21 18:42:37 -03:00
parent 7012998cfa
commit 11900ca5cc
10 changed files with 86 additions and 15 deletions

View File

@ -13,4 +13,4 @@ generarxml_SOURCES = main.c \
encoding.h
generarxml_CPPFLAGS = $(XML_CPPFLAGS)
generarxml_LDFLAGS= $(XML_LIBS)
generarxml_LDADD = ${libxml2_LIBS}
generarxml_LDADD = ${libxml2_LIBS}

View File

@ -1,2 +1,9 @@
/*
* This function converts the latin1 ISO_8859-1 encoding into utf-8.
*/
char *latin2utf8(char *input);
/*
* This function converts the utf-8 encoding into latin1 ISO_8859-1.
*/
char *utf82latin(char *input);

View File

@ -26,7 +26,7 @@ int main(int argc, char **argv) {
printusage(0);
return 1;
}
/* Read the command line arguments */
#ifdef DEBUG
printf("Arguments:\n");
@ -147,7 +147,7 @@ void cleanup() {
/* Cleanup on aisle 3 */
int i;
int j;
if (config) {
if (config->file) {
free(config->file);
@ -168,7 +168,7 @@ void cleanup() {
free(config);
}
if (book) {
if (book) {
for (i = 0; i < book->chapters; i++) {
for (j = 0; j < book->chapter[i]->verses; j++) {
free(book->chapter[i]->verse[j]);

View File

@ -1,5 +1,14 @@
#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 {
char *file;
char *bible;
@ -8,6 +17,14 @@ struct configuration {
char *chapter_numbers;
} 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 {
int chapter;
int current;
@ -15,14 +32,34 @@ struct chapterdata {
char **verse;
} 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 {
int current;
int chapters;
CHAPTER **chapter;
} 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;
BOOK *book;
/*
* This function is called on exit to clean up the memory usage.
*/
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);

View File

@ -5,8 +5,10 @@
#include <libxml/tree.h>
#include "main.h"
int makexml() {
/*
* This function generates the xml and saves it to the output file.
*/
void makexml() {
int i = 0;
int j = 0;
int length;
@ -19,7 +21,7 @@ int makexml() {
xmlNodePtr versetag = NULL;
xmlNodePtr node = NULL;
xmlNodePtr text = NULL;
LIBXML_TEST_VERSION;
doc = xmlNewDoc(BAD_CAST "1.0");
@ -40,6 +42,7 @@ int makexml() {
xmlAddChild(node, text);
xmlAddChild(booktag, node);
/* add the chapters */
for (i = 0; i < book->chapters; i++) {
chaptertag = xmlNewNode(NULL, BAD_CAST "Capitulo");
xmlAddChild(booktag, chaptertag);
@ -55,6 +58,7 @@ int makexml() {
free(temp);
/* add the verses */
chapter = book->chapter[i];
chapter->current = 0;
for (chapter->current = 0; chapter->current < chapter->verses; chapter->current++) {
@ -90,6 +94,4 @@ int makexml() {
xmlFreeDoc(doc);
xmlCleanupParser();
xmlMemoryDump();
return 0;
}

View File

@ -1 +1,4 @@
int makexml();
/*
* This function generates the xml and saves it to the output file.
*/
void makexml();

View File

@ -15,9 +15,9 @@ int readconfig(char *config_file) {
xmlNodePtr node = NULL;
xmlNodePtr subnode = NULL;
/* Initilize the library */
/* initilize the library */
LIBXML_TEST_VERSION
context = xmlNewParserCtxt();
if (context == NULL) {
fprintf(stderr, "No pudo alocar contexto de analizador!\n");
@ -105,10 +105,10 @@ int readconfig(char *config_file) {
subnode = subnode->next;
}
}
node = node->next;
}
xmlFreeDoc(config_xml);
}
@ -118,7 +118,7 @@ int readconfig(char *config_file) {
xmlFreeParserCtxt(context);
return 1;
}
xmlFreeParserCtxt(context);
return 0;

View File

@ -1 +1,5 @@
/*
* This function reads the designated config file and save into int the
* config struct.
*/
int readconfig(char *config_file);

View File

@ -8,6 +8,10 @@
#include "readfile.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() {
FILE *file = NULL;
CHAPTER *chapter = NULL;
@ -126,6 +130,7 @@ int readfile() {
}
if (line != NULL) {
if (strcmp(line, config->bible) == 0) {
/* found the bible */
matches[0] = true;
matches[1] = false;
matches[2] = false;
@ -134,6 +139,7 @@ int readfile() {
#endif
}
if (strcmp(line, config->book) == 0) {
/* found the book */
matches[1] = true;
matches[2] = false;
#ifdef DEBUG
@ -145,6 +151,7 @@ int readfile() {
temp = (char *) malloc((length + 2) * sizeof(char));
snprintf(temp, length + 2, "%s %d", config->chapter, i);
if (strcmp(line, temp) == 0) {
/* found a chapter */
matches[2] = true;
book->current++;
book->chapter[book->current] = (CHAPTER *) malloc(sizeof(CHAPTER));
@ -160,6 +167,7 @@ int readfile() {
free(temp);
}
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);
temp = (char *) malloc((length + 2) * sizeof(char));
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) {
/* end of a section and we already have 3 matches, no reason to continue */
#ifdef DEBUG
printf("Bible end match: %lu -> %s\n", (long) j + 1, line);
#endif

View File

@ -1,2 +1,11 @@
/*
* This variable controls how much memory is used to start with,
* mesured in bytes.
*/
#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();