started xml output

This commit is contained in:
Chris Cromer 2016-10-20 23:08:33 -03:00
parent 7d2791db88
commit 62e8ad9afd
14 changed files with 133 additions and 54 deletions

1
.gitignore vendored
View File

@ -43,3 +43,4 @@ src/Makefile
src/generarxml
autom4te.cache
*.tar.gz
*.xml

View File

@ -4,4 +4,5 @@ SUBDIRS = src
EXTRA_DIST = misc/Biblia.txt \
misc/config.dtd \
misc/generarxml.dtd \
misc/chris.conf

16
misc/generarxml.dtd Normal file
View File

@ -0,0 +1,16 @@
<?xml encoding="UTF-8"?>
<!ELEMENT Biblia (Libro) >
<!ATTLIST Biblia xmlns CDATA #FIXED ''>
<!ELEMENT Libro (Nombre,Capitulo)>
<!ATTLIST Libro xmlns CDATA #FIXED ''>
<!ELEMENT Capitulo (Nombre,Versiculo)>
<!ATTLIST Capitulo xmlns CDATA #FIXED ''>
<!ELEMENT Nombre (#PCDATA)>
<!ATTLIST Nombre xmlns CDATA #FIXED ''>
<!ELEMENT Versiculo (#PCDATA)>
<!ATTLIST Versiculo xmlns CDATA #FIXED ''>

View File

@ -7,6 +7,8 @@ generarxml_SOURCES = main.c \
readconfig.h \
readfile.c \
readfile.h \
makexml.c \
makexml.h \
encoding.c \
encoding.h
generarxml_CPPFLAGS = $(XML_CPPFLAGS)

View File

@ -100,7 +100,7 @@ am__installdirs = "$(DESTDIR)$(bindir)"
PROGRAMS = $(bin_PROGRAMS)
am_generarxml_OBJECTS = generarxml-main.$(OBJEXT) \
generarxml-readconfig.$(OBJEXT) generarxml-readfile.$(OBJEXT) \
generarxml-encoding.$(OBJEXT)
generarxml-makexml.$(OBJEXT) generarxml-encoding.$(OBJEXT)
generarxml_OBJECTS = $(am_generarxml_OBJECTS)
am__DEPENDENCIES_1 =
generarxml_DEPENDENCIES = $(am__DEPENDENCIES_1)
@ -266,6 +266,8 @@ generarxml_SOURCES = main.c \
readconfig.h \
readfile.c \
readfile.h \
makexml.c \
makexml.h \
encoding.c \
encoding.h
@ -360,6 +362,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/generarxml-encoding.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/generarxml-main.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/generarxml-makexml.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/generarxml-readconfig.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/generarxml-readfile.Po@am__quote@
@ -419,6 +422,20 @@ generarxml-readfile.obj: readfile.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(generarxml_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o generarxml-readfile.obj `if test -f 'readfile.c'; then $(CYGPATH_W) 'readfile.c'; else $(CYGPATH_W) '$(srcdir)/readfile.c'; fi`
generarxml-makexml.o: makexml.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(generarxml_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT generarxml-makexml.o -MD -MP -MF $(DEPDIR)/generarxml-makexml.Tpo -c -o generarxml-makexml.o `test -f 'makexml.c' || echo '$(srcdir)/'`makexml.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/generarxml-makexml.Tpo $(DEPDIR)/generarxml-makexml.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='makexml.c' object='generarxml-makexml.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(generarxml_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o generarxml-makexml.o `test -f 'makexml.c' || echo '$(srcdir)/'`makexml.c
generarxml-makexml.obj: makexml.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(generarxml_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT generarxml-makexml.obj -MD -MP -MF $(DEPDIR)/generarxml-makexml.Tpo -c -o generarxml-makexml.obj `if test -f 'makexml.c'; then $(CYGPATH_W) 'makexml.c'; else $(CYGPATH_W) '$(srcdir)/makexml.c'; fi`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/generarxml-makexml.Tpo $(DEPDIR)/generarxml-makexml.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='makexml.c' object='generarxml-makexml.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(generarxml_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o generarxml-makexml.obj `if test -f 'makexml.c'; then $(CYGPATH_W) 'makexml.c'; else $(CYGPATH_W) '$(srcdir)/makexml.c'; fi`
generarxml-encoding.o: encoding.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(generarxml_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT generarxml-encoding.o -MD -MP -MF $(DEPDIR)/generarxml-encoding.Tpo -c -o generarxml-encoding.o `test -f 'encoding.c' || echo '$(srcdir)/'`encoding.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/generarxml-encoding.Tpo $(DEPDIR)/generarxml-encoding.Po

View File

@ -6,8 +6,9 @@
#include "main.h"
#include "readconfig.h"
#include "readfile.h"
#include "makexml.h"
#ifdef LIBXML_TREE_ENABLED
#if defined(LIBXML_TREE_ENABLED) && defined(LIBXML_OUTPUT_ENABLED)
/*
* This program is designed to take a text file and convert part of it into xml.
@ -80,13 +81,25 @@ int main(int argc, char **argv) {
config->chapter = NULL;
config->chapter_numbers = NULL;
status = readconfig(config_file, config);
free(config_file);
config_file = NULL;
status = readconfig(config_file);
if (status != 0) {
return 1;
}
if (strcmp(config->file, argv[0]) == 0 ||
strcmp(config->file, config_file) == 0 ||
strcmp(config->file, "Biblia.txt") == 0 ||
strcmp(config->file, "config.dtd") == 0 ||
strcmp(config->file, "generarxml.dtd") == 0) {
free(config_file);
config_file = NULL;
printf("Nombre de archivo de salida invalido!\n");
return 1;
}
free(config_file);
config_file = NULL;
printf("Configuración:\n");
printf("\tArchivo: %s\n", config->file);
printf("\tBiblia: %s\n", config->bible);
@ -95,12 +108,14 @@ int main(int argc, char **argv) {
printf("\tNumeros de capitulo: %s\n", config->chapter_numbers);
book = (BOOK *) malloc(sizeof(BOOK));
status = readfile(config, book);
status = readfile();
if (status != 0) {
printf("Falló leer Biblia.txt!\n");
return 1;
}
makexml();
free(config->file);
free(config->bible);
free(config->book);
@ -119,7 +134,7 @@ int main(int argc, char **argv) {
* tree support enabled during compile.
*/
int main(int argc, char *argv[]) {
fprintf(stderr, "libxml2 no tiene tree support compilado\n");
fprintf(stderr, "libxml2 no está configurado correctamente\n");
return 1;
}

View File

@ -9,6 +9,7 @@ struct configuration {
} typedef CONFIG;
struct chapterdata {
int chapter;
int current;
int verses;
char **verse;

67
src/makexml.c Normal file
View File

@ -0,0 +1,67 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include "main.h"
int makexml() {
int i = 0;
int length;
char *temp = NULL;
xmlDocPtr doc = NULL;
xmlNodePtr bibletag = NULL;
xmlNodePtr booktag = NULL;
xmlNodePtr chaptertag = NULL;
xmlNodePtr versetag = 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);
/* add dtd */
xmlCreateIntSubset(doc, BAD_CAST "Biblia", NULL, BAD_CAST "generarxml.dtd");
booktag = xmlNewNode(NULL, BAD_CAST "Libro");
xmlAddChild(bibletag, booktag);
node = xmlNewNode(NULL, BAD_CAST "Nombre");
text = xmlNewText(BAD_CAST config->book);
xmlAddChild(node, text);
xmlAddChild(booktag, node);
for (i = 0; i < book->chapters; i++) {
chaptertag = xmlNewNode(NULL, BAD_CAST "Capitulo");
xmlAddChild(booktag, chaptertag);
length = snprintf(NULL, 0, "%d", book->chapter[i]->chapter) + strlen(config->chapter);
temp = (char *) malloc((length + 2) * sizeof(char));
snprintf(temp, length + 2, "%s %d", config->chapter, book->chapter[i]->chapter);
node = xmlNewNode(NULL, BAD_CAST "Nombre");
text = xmlNewText(BAD_CAST temp);
xmlAddChild(node, text);
xmlAddChild(chaptertag, node);
versetag = xmlNewNode(NULL, BAD_CAST "Versiculo");
xmlAddChild(chaptertag, versetag);
}
#ifdef DEBUG
printf("XML output:\n");
xmlSaveFormatFileEnc("-", doc, "UTF-8", 1);
#endif
xmlSaveFormatFileEnc(config->file, doc, "UTF-8", 1);
/* cleanup on aisle 3 */
xmlFreeDoc(doc);
xmlCleanupParser();
xmlMemoryDump();
return 0;
}

1
src/makexml.h Normal file
View File

@ -0,0 +1 @@
int makexml();

View File

@ -1,39 +0,0 @@
# Este makefile es el antiguo y mas limitado, no puede detectar el entorno para verificar que la compilación va a funcionar
CC=gcc
BINDIR=out
SRCDIR=.
EXTRADIR=../misc
DEBUG_FLAGS=-Wall -Werror
CFLAGS=$(DEBUG_FLAGS) -ggdb -Wconversion -std=c11 -D_DEFAULT_SOURCE $(shell pkg-config libxml-2.0 --cflags) -ansi
LDFLAGS=$(shell pkg-config libxml-2.0 --libs)
#CPPFLAGS
# DEBUG: show debug information during runtime
# DEBUG_ENCODING: show debug information related to encoding at runtime
CPPFLAGS=-DDEBUG
BINARY=generarxml
OBJS = \
$(SRCDIR)/main.o \
$(SRCDIR)/readconfig.o \
$(SRCDIR)/readfile.o \
$(SRCDIR)/encoding.o
all: bin
bin: $(OBJS)
[ -d "out" ] && echo ¨out already exists¨ || mkdir -v out
$(CC)$(xml2-config --cflags --libs) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $(BINDIR)/$(BINARY)
cp $(EXTRADIR)/*.conf $(BINDIR)/
cp $(EXTRADIR)/*.dtd $(BINDIR)/
cp $(EXTRADIR)/*.txt $(BINDIR)/
clean:
rm -fR $(BINDIR) $(SRCDIR)/*.o
%.o: %.c
$(CC)$(xml2-config --cflags --libs) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -c $< -o $@

View File

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

View File

@ -1 +1 @@
int readconfig(char *config_file, CONFIG *config);
int readconfig(char *config_file);

View File

@ -8,7 +8,7 @@
#include "readfile.h"
#include "encoding.h"
int readfile(CONFIG *config, BOOK *book) {
int readfile() {
FILE *file = NULL;
CHAPTER *chapter = NULL;
int start = 0;
@ -124,7 +124,6 @@ int readfile(CONFIG *config, BOOK *book) {
if (array[j] != NULL) {
line = latin2utf8(array[j]);
}
/* printf(" array [%lu] %s\n", (long) j, line); */
if (line != NULL) {
if (strcmp(line, config->bible) == 0) {
matches[0] = true;
@ -150,6 +149,7 @@ int readfile(CONFIG *config, BOOK *book) {
book->current++;
book->chapter[book->current] = (CHAPTER *) malloc(sizeof(CHAPTER));
chapter = book->chapter[book->current];
chapter->chapter = i;
chapter->current = -1;
chapter->verses = 0;
chapter->verse = (char **) malloc(sizeof(char *));
@ -187,7 +187,6 @@ int readfile(CONFIG *config, BOOK *book) {
l = 0;
temp = (char *) malloc((strlen(line) + 1) * sizeof(char));
for (k = i + 1; k < strlen(line) - 1; (k++)) {
/*printf("i: %d k: %d chars: %d\n", i, k, strlen(line));*/
temp[l] = line[k];
l++;
}
@ -199,8 +198,6 @@ int readfile(CONFIG *config, BOOK *book) {
chapter->verse[chapter->current] = (char *) malloc((strlen(temp) + 1) * sizeof(char));
memcpy(chapter->verse[chapter->current], temp, strlen(temp) + 1);
/*printf("%d - %s\n", verse, chapter->verses[chapter->current]);*/
if (temp) {
free(temp);
}

View File

@ -1,2 +1,2 @@
#define MAX_LINES 100
int readfile(CONFIG *config, BOOK *book);
int readfile();