From f3989292606618e041bc1a77c86857c157a10842 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Sun, 23 Oct 2016 23:17:03 -0300 Subject: [PATCH] cleanup --- ChangeLog | 3 +++ Makefile.am | 18 +++++++++--------- NEWS | 5 ++++- configure | 20 ++++++++++---------- configure.ac | 21 ++++++++++----------- src/Makefile.am | 18 +++++++++--------- src/Makefile.in | 18 +++++++++--------- src/encoding.c | 28 ++++++++++++++-------------- src/encoding.h | 4 ++-- src/main.c | 14 +++++++------- src/main.h | 6 +++--- src/makexml.c | 36 ++++++++++++++++++------------------ src/makexml.h | 2 +- src/readconfig.c | 2 +- src/readconfig.h | 2 +- src/readfile.c | 4 ++-- src/readfile.h | 2 +- 17 files changed, 104 insertions(+), 99 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2e20a3a..586dd55 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,2 +1,5 @@ +23/10/2016 + Cleaned up the project a bit. + 21/10/2016 Created first version. diff --git a/Makefile.am b/Makefile.am index 5e568b7..777fea5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/NEWS b/NEWS index 3253aa6..e9cdaf9 100644 --- a/NEWS +++ b/NEWS @@ -1,2 +1,5 @@ +23/10/2016 + Just some cleanup. + 21/10/2016 -Version 1.0 is complete. + Version 1.0 is complete. diff --git a/configure b/configure index abf19f4..7749930 100755 --- a/configure +++ b/configure @@ -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 diff --git a/configure.ac b/configure.ac index 329ffef..5185334 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/src/Makefile.am b/src/Makefile.am index d7f16be..3e19369 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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} diff --git a/src/Makefile.in b/src/Makefile.in index 5012533..3606f3d 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -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) diff --git a/src/encoding.c b/src/encoding.c index c947306..e660dd9 100644 --- a/src/encoding.c +++ b/src/encoding.c @@ -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)); diff --git a/src/encoding.h b/src/encoding.h index a0accc8..8eb5f34 100644 --- a/src/encoding.h +++ b/src/encoding.h @@ -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); diff --git a/src/main.c b/src/main.c index 954e98b..3c5a928 100644 --- a/src/main.c +++ b/src/main.c @@ -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"); } diff --git a/src/main.h b/src/main.h index 28c6bd5..4355cac 100644 --- a/src/main.h +++ b/src/main.h @@ -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); diff --git a/src/makexml.c b/src/makexml.c index ef81474..a4d5243 100644 --- a/src/makexml.c +++ b/src/makexml.c @@ -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); } } diff --git a/src/makexml.h b/src/makexml.h index f9e9132..f3b813d 100644 --- a/src/makexml.h +++ b/src/makexml.h @@ -1,4 +1,4 @@ /* * This function generates the xml and saves it to the output file. */ -void makexml(); +void make_xml(); diff --git a/src/readconfig.c b/src/readconfig.c index 128df07..45daf26 100644 --- a/src/readconfig.c +++ b/src/readconfig.c @@ -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; diff --git a/src/readconfig.h b/src/readconfig.h index ae143bb..d126545 100644 --- a/src/readconfig.h +++ b/src/readconfig.h @@ -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); diff --git a/src/readfile.c b/src/readfile.c index 6dc26ba..c634df9 100644 --- a/src/readfile.c +++ b/src/readfile.c @@ -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) { diff --git a/src/readfile.h b/src/readfile.h index 3f1f80c..6daf250 100644 --- a/src/readfile.h +++ b/src/readfile.h @@ -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();