This commit is contained in:
Chris Cromer 2016-10-23 23:17:03 -03:00
parent d176cfbb49
commit f398929260
17 changed files with 104 additions and 99 deletions

View File

@ -1,2 +1,5 @@
23/10/2016
Cleaned up the project a bit.
21/10/2016
Created first version.

View File

@ -3,12 +3,12 @@ ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
SUBDIRS = src
EXTRA_DIST = misc/Biblia.txt \
misc/config.dtd \
misc/generarxml.dtd \
misc/chris.conf \
misc/carlos.conf \
misc/enzo.conf \
misc/erwin.conf \
misc/martin.conf \
misc/pablo.conf \
misc/paula.conf
misc/config.dtd \
misc/generarxml.dtd \
misc/chris.conf \
misc/carlos.conf \
misc/enzo.conf \
misc/erwin.conf \
misc/martin.conf \
misc/pablo.conf \
misc/paula.conf

5
NEWS
View File

@ -1,2 +1,5 @@
23/10/2016
Just some cleanup.
21/10/2016
Version 1.0 is complete.
Version 1.0 is complete.

20
configure vendored
View File

@ -3653,12 +3653,12 @@ fi
# Check whether --with-debug was given.
if test "${with_debug+set}" = set; then :
withval=$with_debug; case $with_debug in
yes) $as_echo "#define DEBUG 1" >>confdefs.h
yes) $as_echo "#define DEBUG 1" >>confdefs.h
;;
no) ;;
*) as_fn_error $? "\"--with-debug does not take an argument.\"" "$LINENO" 5
;;
;;
no) ;;
*) as_fn_error $? "\"--with-debug does not take an argument.\"" "$LINENO" 5
;;
esac
fi
@ -3667,12 +3667,12 @@ fi
# Check whether --with-debug_encoding was given.
if test "${with_debug_encoding+set}" = set; then :
withval=$with_debug_encoding; case $with_debug_encoding in
yes) $as_echo "#define DEBUG_ENCODING 1" >>confdefs.h
yes) $as_echo "#define DEBUG_ENCODING 1" >>confdefs.h
;;
no) ;;
*) as_fn_error $? "\"--with-debug-encoding does not take an argument.\"" "$LINENO" 5
;;
;;
no) ;;
*) as_fn_error $? "\"--with-debug-encoding does not take an argument.\"" "$LINENO" 5
;;
esac
fi

View File

@ -20,20 +20,20 @@ AC_PATH_PROG([M4], [m4])
AC_ARG_WITH(debug, [AS_HELP_STRING([--with-debug], [include debug messages])],
[case $with_debug in
yes) AC_DEFINE(DEBUG)
;;
no) ;;
*) AC_MSG_ERROR(["--with-debug does not take an argument."])
;;
yes) AC_DEFINE(DEBUG)
;;
no) ;;
*) AC_MSG_ERROR(["--with-debug does not take an argument."])
;;
esac])
AC_ARG_WITH(debug_encoding, [AS_HELP_STRING([--with-debug-encoding], [include encoding debug messages])],
[case $with_debug_encoding in
yes) AC_DEFINE(DEBUG_ENCODING)
;;
no) ;;
*) AC_MSG_ERROR(["--with-debug-encoding does not take an argument."])
;;
yes) AC_DEFINE(DEBUG_ENCODING)
;;
no) ;;
*) AC_MSG_ERROR(["--with-debug-encoding does not take an argument."])
;;
esac])
AC_DEFINE(_DEFAULT_SOURCE)
@ -50,5 +50,4 @@ AC_CONFIG_FILES([Makefile
src/Makefile
])
AC_OUTPUT

View File

@ -2,15 +2,15 @@ ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
bin_PROGRAMS = generarxml
generarxml_SOURCES = main.c \
main.h \
readconfig.c \
readconfig.h \
readfile.c \
readfile.h \
makexml.c \
makexml.h \
encoding.c \
encoding.h
main.h \
readconfig.c \
readconfig.h \
readfile.c \
readfile.h \
makexml.c \
makexml.h \
encoding.c \
encoding.h
generarxml_CPPFLAGS = $(XML_CPPFLAGS)
generarxml_LDFLAGS= $(XML_LIBS)
generarxml_LDADD = ${libxml2_LIBS}

View File

@ -261,15 +261,15 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
generarxml_SOURCES = main.c \
main.h \
readconfig.c \
readconfig.h \
readfile.c \
readfile.h \
makexml.c \
makexml.h \
encoding.c \
encoding.h
main.h \
readconfig.c \
readconfig.h \
readfile.c \
readfile.h \
makexml.c \
makexml.h \
encoding.c \
encoding.h
generarxml_CPPFLAGS = $(XML_CPPFLAGS)
generarxml_LDFLAGS = $(XML_LIBS)

View File

@ -6,14 +6,14 @@
/*
* This function converts the latin1 ISO_8859-1 encoding into utf-8.
*/
char *latin2utf8(char *input) {
char *latin_to_utf8(char *input) {
if (input && strlen(input) > 0) {
iconv_t cd = iconv_open("UTF-8", "ISO_8859-1");
char temp[strlen(input)];
memcpy(temp, input, strlen(input) + 1);
char *in_buf = &temp[0];
char *in_buffer = &temp[0];
size_t in_left = sizeof(temp);
/* The more tildes and ñs that the string has, the longer the size needs to be.
@ -21,11 +21,11 @@ char *latin2utf8(char *input) {
* double the size.
*/
char output[strlen(temp) * 2];
char *out_buf = &output[0];
char *out_buffer = &output[0];
size_t out_left = sizeof(output);
do {
if (iconv(cd, &in_buf, &in_left, &out_buf, &out_left) == (size_t) -1) {
if (iconv(cd, &in_buffer, &in_left, &out_buffer, &out_left) == (size_t) -1) {
#ifdef DEBUG
printf("%s\n", input);
perror("iconv");
@ -35,11 +35,11 @@ char *latin2utf8(char *input) {
}
}
while (in_left > 0 && out_left > 0);
*out_buf = 0;
*out_buffer = 0;
#if defined(DEBUG) && defined(DEBUG_ENCODING)
printf("latin2utf8: input: %s\n", input);
printf("latin2utf8: output: %s\n", output);
printf("latin to UTF-8: input: %s\n", input);
printf("latin to UTF-8: output: %s\n", output);
#endif
char *temp2 = (char *) malloc((strlen(output) + 1) * sizeof(char));
@ -55,14 +55,14 @@ char *latin2utf8(char *input) {
/*
* This function converts the utf-8 encoding into latin1 ISO_8859-1.
*/
char *utf82latin(char *input) {
char *utf8_to_latin(char *input) {
if (input && strlen(input) > 0) {
iconv_t cd = iconv_open("ISO_8859-1", "UTF-8");
char temp[strlen(input)];
memcpy(temp, input, strlen(input) + 1);
char *in_buf = &temp[0];
char *in_buffer = &temp[0];
size_t in_left = sizeof(temp);
/* The more tildes and ñs that the string has, the longer the size needs to be.
@ -70,11 +70,11 @@ char *utf82latin(char *input) {
* double the size.
*/
char output[strlen(temp) * 2];
char *out_buf = &output[0];
char *out_buffer = &output[0];
size_t out_left = sizeof(output);
do {
if (iconv(cd, &in_buf, &in_left, &out_buf, &out_left) == (size_t) -1) {
if (iconv(cd, &in_buffer, &in_left, &out_buffer, &out_left) == (size_t) -1) {
#ifdef DEBUG
printf("%s\n", input);
perror("iconv");
@ -84,11 +84,11 @@ char *utf82latin(char *input) {
}
}
while (in_left > 0 && out_left > 0);
*out_buf = 0;
*out_buffer = 0;
#if defined(DEBUG) && defined(DEBUG_ENCODING)
printf("latin2utf8: input: %s\n", input);
printf("latin2utf8: output: %s\n", output);
printf("UTF-8 to latin: input: %s\n", input);
printf("UTF-8 to latin: output: %s\n", output);
#endif
char *temp2 = (char *) malloc((strlen(output) + 1) * sizeof(char));

View File

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

View File

@ -23,7 +23,7 @@ int main(int argc, char **argv) {
if (argc == 1) {
/* No arguments were passed */
printusage(0);
print_usage(0);
return 1;
}
@ -48,7 +48,7 @@ int main(int argc, char **argv) {
if (config_file != NULL) {
free(config_file);
}
printusage(1);
print_usage(1);
return 1;
}
}
@ -60,7 +60,7 @@ int main(int argc, char **argv) {
if (config_file != NULL) {
free(config_file);
}
printusage(1);
print_usage(1);
return 1;
}
}
@ -81,7 +81,7 @@ int main(int argc, char **argv) {
config->chapter = NULL;
config->chapter_numbers = NULL;
status = readconfig(config_file);
status = read_config(config_file);
if (status != 0) {
return 1;
}
@ -108,13 +108,13 @@ int main(int argc, char **argv) {
printf("\tNumeros de capitulo: %s\n", config->chapter_numbers);
book = (BOOK *) malloc(sizeof(BOOK));
status = readfile();
status = read_file();
if (status != 0) {
printf("Falló leer Biblia.txt!\n");
return 1;
}
makexml();
make_xml();
printf("El achivo %s ha sido generado.\n", config->file);
@ -187,7 +187,7 @@ 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 print_usage(int error) {
if (error == 1) {
printf("Opcion desconocido!\n\n");
}

View File

@ -25,7 +25,7 @@ struct configuration {
* verses is the number of verses contained in the verse variable
* verse contains the verses
*/
struct chapterdata {
struct chapter_data {
int chapter;
int current;
int verses;
@ -38,7 +38,7 @@ struct chapterdata {
* chapters is the ammount of chapters that are contained in the chapter variable
* chapter contains all of the chapters
*/
struct bookdata {
struct book_data {
int current;
int chapters;
CHAPTER **chapter;
@ -62,4 +62,4 @@ 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 print_usage(int error);

View File

@ -8,44 +8,44 @@
/*
* This function generates the xml and saves it to the output file.
*/
void makexml() {
void make_xml() {
int i = 0;
int j = 0;
int length;
char *temp = NULL;
CHAPTER *chapter = NULL;
xmlDocPtr doc = NULL;
xmlNodePtr bibletag = NULL;
xmlNodePtr booktag = NULL;
xmlNodePtr chaptertag = NULL;
xmlNodePtr versetag = NULL;
xmlNodePtr bible_tag = NULL;
xmlNodePtr book_tag = NULL;
xmlNodePtr chapter_tag = NULL;
xmlNodePtr verse_tag = NULL;
xmlNodePtr node = NULL;
xmlNodePtr text = NULL;
LIBXML_TEST_VERSION;
doc = xmlNewDoc(BAD_CAST "1.0");
bibletag = xmlNewNode(NULL, BAD_CAST "Biblia");
xmlDocSetRootElement(doc, bibletag);
bible_tag = xmlNewNode(NULL, BAD_CAST "Biblia");
xmlDocSetRootElement(doc, bible_tag);
/* add attribute to bible tag */
xmlNewProp(bibletag, BAD_CAST "nombre", BAD_CAST config->bible);
xmlNewProp(bible_tag, BAD_CAST "nombre", BAD_CAST config->bible);
/* add dtd */
xmlCreateIntSubset(doc, BAD_CAST "Biblia", NULL, BAD_CAST "generarxml.dtd");
booktag = xmlNewNode(NULL, BAD_CAST "Libro");
xmlAddChild(bibletag, booktag);
book_tag = xmlNewNode(NULL, BAD_CAST "Libro");
xmlAddChild(bible_tag, book_tag);
node = xmlNewNode(NULL, BAD_CAST "Nombre");
text = xmlNewText(BAD_CAST config->book);
xmlAddChild(node, text);
xmlAddChild(booktag, node);
xmlAddChild(book_tag, node);
/* add the chapters */
for (i = 0; i < book->chapters; i++) {
chaptertag = xmlNewNode(NULL, BAD_CAST "Capitulo");
xmlAddChild(booktag, chaptertag);
chapter_tag = xmlNewNode(NULL, BAD_CAST "Capitulo");
xmlAddChild(book_tag, chapter_tag);
length = snprintf(NULL, 0, "%d", book->chapter[i]->chapter) + strlen(config->chapter);
temp = (char *) malloc((length + 2) * sizeof(char));
@ -54,7 +54,7 @@ void makexml() {
node = xmlNewNode(NULL, BAD_CAST "Nombre");
text = xmlNewText(BAD_CAST temp);
xmlAddChild(node, text);
xmlAddChild(chaptertag, node);
xmlAddChild(chapter_tag, node);
free(temp);
@ -62,8 +62,8 @@ void makexml() {
chapter = book->chapter[i];
chapter->current = 0;
for (chapter->current = 0; chapter->current < chapter->verses; chapter->current++) {
versetag = xmlNewNode(NULL, BAD_CAST "Versiculo");
xmlAddChild(chaptertag, versetag);
verse_tag = xmlNewNode(NULL, BAD_CAST "Versiculo");
xmlAddChild(chapter_tag, verse_tag);
length = snprintf(NULL, 0, "%d", chapter->current + 1) + strlen("VERSICULO");
temp = (char *) malloc((length + 2) * sizeof(char));
@ -72,14 +72,14 @@ void makexml() {
node = xmlNewNode(NULL, BAD_CAST "Nombre");
text = xmlNewText(BAD_CAST temp);
xmlAddChild(node, text);
xmlAddChild(versetag, node);
xmlAddChild(verse_tag, node);
free(temp);
node = xmlNewNode(NULL, BAD_CAST "Descripcion");
text = xmlNewText(BAD_CAST chapter->verse[chapter->current]);
xmlAddChild(node, text);
xmlAddChild(versetag, node);
xmlAddChild(verse_tag, node);
}
}

View File

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

View File

@ -8,7 +8,7 @@
* This function reads the designated config file and save into int the
* config struct.
*/
int readconfig(char *config_file) {
int read_config(char *config_file) {
xmlParserCtxtPtr context;
xmlDocPtr config_xml = NULL;
xmlNodePtr root = NULL;

View File

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

View File

@ -12,7 +12,7 @@
* 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 read_file() {
FILE *file = NULL;
CHAPTER *chapter = NULL;
int start = 0;
@ -126,7 +126,7 @@ int readfile() {
for (j = 0; j < lines; j++) {
if (array[j] != NULL) {
line = latin2utf8(array[j]);
line = latin_to_utf8(array[j]);
}
if (line != NULL) {
if (strcmp(line, config->bible) == 0) {

View File

@ -8,4 +8,4 @@
* 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 read_file();