Explorar el Código

added comments and cleaned up trailing spaces

master
Chris Cromer hace 3 años
padre
commit
11900ca5cc
Se han modificado 10 ficheros con 86 adiciones y 15 borrados
  1. +1
    -1
      src/Makefile.am
  2. +7
    -0
      src/encoding.h
  3. +3
    -3
      src/main.c
  4. +37
    -0
      src/main.h
  5. +7
    -5
      src/makexml.c
  6. +4
    -1
      src/makexml.h
  7. +5
    -5
      src/readconfig.c
  8. +4
    -0
      src/readconfig.h
  9. +9
    -0
      src/readfile.c
  10. +9
    -0
      src/readfile.h

+ 1
- 1
src/Makefile.am Ver fichero

@@ -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}

+ 7
- 0
src/encoding.h Ver fichero

@@ -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);

+ 3
- 3
src/main.c Ver fichero

@@ -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]);


+ 37
- 0
src/main.h Ver fichero

@@ -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);

+ 7
- 5
src/makexml.c Ver fichero

@@ -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;
}

+ 4
- 1
src/makexml.h Ver fichero

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

+ 5
- 5
src/readconfig.c Ver fichero

@@ -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;


+ 4
- 0
src/readconfig.h Ver fichero

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

+ 9
- 0
src/readfile.c Ver fichero

@@ -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


+ 9
- 0
src/readfile.h Ver fichero

@@ -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();

Cargando…
Cancelar
Guardar