Browse Source

started xml output

Chris Cromer 2 years ago
parent
commit
62e8ad9afd
14 changed files with 133 additions and 54 deletions
  1. 1
    0
      .gitignore
  2. 1
    0
      Makefile.am
  3. 16
    0
      misc/generarxml.dtd
  4. 2
    0
      src/Makefile.am
  5. 18
    1
      src/Makefile.in
  6. 21
    6
      src/main.c
  7. 1
    0
      src/main.h
  8. 67
    0
      src/makexml.c
  9. 1
    0
      src/makexml.h
  10. 0
    39
      src/oldmakefile
  11. 1
    1
      src/readconfig.c
  12. 1
    1
      src/readconfig.h
  13. 2
    5
      src/readfile.c
  14. 1
    1
      src/readfile.h

+ 1
- 0
.gitignore View File

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

+ 1
- 0
Makefile.am View File

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

+ 16
- 0
misc/generarxml.dtd View File

@@ -0,0 +1,16 @@
1
+<?xml encoding="UTF-8"?>
2
+
3
+<!ELEMENT Biblia (Libro) >
4
+<!ATTLIST Biblia xmlns CDATA #FIXED ''>
5
+
6
+<!ELEMENT Libro (Nombre,Capitulo)>
7
+<!ATTLIST Libro xmlns CDATA #FIXED ''>
8
+
9
+<!ELEMENT Capitulo (Nombre,Versiculo)>
10
+<!ATTLIST Capitulo xmlns CDATA #FIXED ''>
11
+
12
+<!ELEMENT Nombre (#PCDATA)>
13
+<!ATTLIST Nombre xmlns CDATA #FIXED ''>
14
+
15
+<!ELEMENT Versiculo (#PCDATA)>
16
+<!ATTLIST Versiculo xmlns CDATA #FIXED ''>

+ 2
- 0
src/Makefile.am View File

@@ -7,6 +7,8 @@ generarxml_SOURCES = main.c \
7 7
 	readconfig.h \
8 8
 	readfile.c \
9 9
 	readfile.h \
10
+	makexml.c \
11
+	makexml.h \
10 12
 	encoding.c \
11 13
 	encoding.h
12 14
 generarxml_CPPFLAGS = $(XML_CPPFLAGS)

+ 18
- 1
src/Makefile.in View File

@@ -100,7 +100,7 @@ am__installdirs = "$(DESTDIR)$(bindir)"
100 100
 PROGRAMS = $(bin_PROGRAMS)
101 101
 am_generarxml_OBJECTS = generarxml-main.$(OBJEXT) \
102 102
 	generarxml-readconfig.$(OBJEXT) generarxml-readfile.$(OBJEXT) \
103
-	generarxml-encoding.$(OBJEXT)
103
+	generarxml-makexml.$(OBJEXT) generarxml-encoding.$(OBJEXT)
104 104
 generarxml_OBJECTS = $(am_generarxml_OBJECTS)
105 105
 am__DEPENDENCIES_1 =
106 106
 generarxml_DEPENDENCIES = $(am__DEPENDENCIES_1)
@@ -266,6 +266,8 @@ generarxml_SOURCES = main.c \
266 266
 	readconfig.h \
267 267
 	readfile.c \
268 268
 	readfile.h \
269
+	makexml.c \
270
+	makexml.h \
269 271
 	encoding.c \
270 272
 	encoding.h
271 273
 
@@ -360,6 +362,7 @@ distclean-compile:
360 362
 
361 363
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/generarxml-encoding.Po@am__quote@
362 364
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/generarxml-main.Po@am__quote@
365
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/generarxml-makexml.Po@am__quote@
363 366
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/generarxml-readconfig.Po@am__quote@
364 367
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/generarxml-readfile.Po@am__quote@
365 368
 
@@ -419,6 +422,20 @@ generarxml-readfile.obj: readfile.c
419 422
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
420 423
 @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`
421 424
 
425
+generarxml-makexml.o: makexml.c
426
+@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
427
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/generarxml-makexml.Tpo $(DEPDIR)/generarxml-makexml.Po
428
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='makexml.c' object='generarxml-makexml.o' libtool=no @AMDEPBACKSLASH@
429
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
430
+@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
431
+
432
+generarxml-makexml.obj: makexml.c
433
+@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`
434
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/generarxml-makexml.Tpo $(DEPDIR)/generarxml-makexml.Po
435
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='makexml.c' object='generarxml-makexml.obj' libtool=no @AMDEPBACKSLASH@
436
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
437
+@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`
438
+
422 439
 generarxml-encoding.o: encoding.c
423 440
 @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
424 441
 @am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/generarxml-encoding.Tpo $(DEPDIR)/generarxml-encoding.Po

+ 21
- 6
src/main.c View File

@@ -6,8 +6,9 @@
6 6
 #include "main.h"
7 7
 #include "readconfig.h"
8 8
 #include "readfile.h"
9
+#include "makexml.h"
9 10
 
10
-#ifdef LIBXML_TREE_ENABLED
11
+#if defined(LIBXML_TREE_ENABLED) && defined(LIBXML_OUTPUT_ENABLED)
11 12
 
12 13
 /*
13 14
  * 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) {
80 81
     config->chapter = NULL;
81 82
     config->chapter_numbers = NULL;
82 83
 
83
-    status = readconfig(config_file, config);
84
-    free(config_file);
85
-    config_file = NULL;
84
+    status = readconfig(config_file);
86 85
     if (status != 0) {
87 86
         return 1;
88 87
     }
89 88
 
89
+    if (strcmp(config->file, argv[0]) == 0 ||
90
+            strcmp(config->file, config_file) == 0 ||
91
+            strcmp(config->file, "Biblia.txt") == 0 ||
92
+            strcmp(config->file, "config.dtd") == 0 ||
93
+            strcmp(config->file, "generarxml.dtd") == 0) {
94
+        free(config_file);
95
+        config_file = NULL;
96
+        printf("Nombre de archivo de salida invalido!\n");
97
+        return 1;
98
+    }
99
+
100
+    free(config_file);
101
+    config_file = NULL;
102
+
90 103
     printf("Configuración:\n");
91 104
     printf("\tArchivo: %s\n", config->file);
92 105
     printf("\tBiblia: %s\n", config->bible);
@@ -95,12 +108,14 @@ int main(int argc, char **argv) {
95 108
     printf("\tNumeros de capitulo: %s\n", config->chapter_numbers);
96 109
 
97 110
     book = (BOOK *) malloc(sizeof(BOOK));
98
-    status = readfile(config, book);
111
+    status = readfile();
99 112
     if (status != 0) {
100 113
         printf("Falló leer Biblia.txt!\n");
101 114
         return 1;
102 115
     }
103 116
 
117
+    makexml();
118
+
104 119
     free(config->file);
105 120
     free(config->bible);
106 121
     free(config->book);
@@ -119,7 +134,7 @@ int main(int argc, char **argv) {
119 134
  * tree support enabled during compile.
120 135
  */
121 136
 int main(int argc, char *argv[]) {
122
-    fprintf(stderr, "libxml2 no tiene tree support compilado\n");
137
+    fprintf(stderr, "libxml2 no está configurado correctamente\n");
123 138
     return 1;
124 139
 }
125 140
 

+ 1
- 0
src/main.h View File

@@ -9,6 +9,7 @@ struct configuration {
9 9
 } typedef CONFIG;
10 10
 
11 11
 struct chapterdata {
12
+    int chapter;
12 13
     int current;
13 14
     int verses;
14 15
     char **verse;

+ 67
- 0
src/makexml.c View File

@@ -0,0 +1,67 @@
1
+#include <stdio.h>
2
+#include <string.h>
3
+#include <unistd.h>
4
+#include <libxml/parser.h>
5
+#include <libxml/tree.h>
6
+#include "main.h"
7
+
8
+int makexml() {
9
+    int i = 0;
10
+    int length;
11
+    char *temp = NULL;
12
+    xmlDocPtr doc = NULL;
13
+    xmlNodePtr bibletag = NULL;
14
+    xmlNodePtr booktag  = NULL;
15
+    xmlNodePtr chaptertag = NULL;
16
+    xmlNodePtr versetag = NULL;
17
+    xmlNodePtr node = NULL;
18
+    xmlNodePtr text = NULL;
19
+    
20
+    LIBXML_TEST_VERSION;
21
+
22
+    doc = xmlNewDoc(BAD_CAST "1.0");
23
+    bibletag = xmlNewNode(NULL, BAD_CAST "Biblia");
24
+    xmlDocSetRootElement(doc, bibletag);
25
+
26
+    /* add dtd */
27
+    xmlCreateIntSubset(doc, BAD_CAST "Biblia", NULL, BAD_CAST "generarxml.dtd");
28
+
29
+    booktag = xmlNewNode(NULL, BAD_CAST "Libro");
30
+    xmlAddChild(bibletag, booktag);
31
+
32
+    node = xmlNewNode(NULL, BAD_CAST "Nombre");
33
+    text = xmlNewText(BAD_CAST config->book);
34
+    xmlAddChild(node, text);
35
+    xmlAddChild(booktag, node);
36
+
37
+    for (i = 0; i < book->chapters; i++) {
38
+        chaptertag = xmlNewNode(NULL, BAD_CAST "Capitulo");
39
+        xmlAddChild(booktag, chaptertag);
40
+
41
+        length = snprintf(NULL, 0, "%d", book->chapter[i]->chapter) + strlen(config->chapter);
42
+        temp = (char *) malloc((length + 2) * sizeof(char));
43
+        snprintf(temp, length + 2, "%s %d", config->chapter, book->chapter[i]->chapter);
44
+
45
+        node = xmlNewNode(NULL, BAD_CAST "Nombre");
46
+        text = xmlNewText(BAD_CAST temp);
47
+        xmlAddChild(node, text);
48
+        xmlAddChild(chaptertag, node);
49
+
50
+        versetag = xmlNewNode(NULL, BAD_CAST "Versiculo");
51
+        xmlAddChild(chaptertag, versetag);
52
+    }
53
+
54
+    #ifdef DEBUG
55
+        printf("XML output:\n");
56
+        xmlSaveFormatFileEnc("-", doc, "UTF-8", 1);
57
+    #endif
58
+
59
+    xmlSaveFormatFileEnc(config->file, doc, "UTF-8", 1);
60
+
61
+    /* cleanup on aisle 3 */
62
+    xmlFreeDoc(doc);
63
+    xmlCleanupParser();
64
+    xmlMemoryDump();
65
+    
66
+    return 0;
67
+}

+ 1
- 0
src/makexml.h View File

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

+ 0
- 39
src/oldmakefile View File

@@ -1,39 +0,0 @@
1
-# Este makefile es el antiguo y mas limitado, no puede detectar el entorno para verificar que la compilación va a funcionar
2
-
3
-CC=gcc
4
-BINDIR=out
5
-SRCDIR=.
6
-EXTRADIR=../misc
7
-DEBUG_FLAGS=-Wall -Werror
8
-
9
-CFLAGS=$(DEBUG_FLAGS) -ggdb -Wconversion -std=c11 -D_DEFAULT_SOURCE $(shell pkg-config libxml-2.0 --cflags) -ansi
10
-LDFLAGS=$(shell pkg-config libxml-2.0 --libs)
11
-
12
-#CPPFLAGS
13
-#	DEBUG:			show debug information during runtime
14
-#	DEBUG_ENCODING:	show debug information related to encoding at runtime
15
-
16
-CPPFLAGS=-DDEBUG
17
-	
18
-BINARY=generarxml
19
-
20
-OBJS = \
21
-	$(SRCDIR)/main.o \
22
-	$(SRCDIR)/readconfig.o \
23
-	$(SRCDIR)/readfile.o \
24
-	$(SRCDIR)/encoding.o
25
-
26
-all:	bin
27
-
28
-bin:	$(OBJS)
29
-	[ -d "out" ] && echo ¨out already exists¨ || mkdir -v out
30
-	$(CC)$(xml2-config --cflags --libs) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $(BINDIR)/$(BINARY)
31
-	cp $(EXTRADIR)/*.conf $(BINDIR)/
32
-	cp $(EXTRADIR)/*.dtd $(BINDIR)/
33
-	cp $(EXTRADIR)/*.txt $(BINDIR)/
34
-
35
-clean:
36
-	rm -fR $(BINDIR) $(SRCDIR)/*.o
37
-
38
-%.o:	%.c
39
-	$(CC)$(xml2-config --cflags --libs) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -c $< -o $@

+ 1
- 1
src/readconfig.c View File

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

+ 1
- 1
src/readconfig.h View File

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

+ 2
- 5
src/readfile.c View File

@@ -8,7 +8,7 @@
8 8
 #include "readfile.h"
9 9
 #include "encoding.h"
10 10
 
11
-int readfile(CONFIG *config, BOOK *book) {
11
+int readfile() {
12 12
     FILE *file = NULL;
13 13
     CHAPTER *chapter = NULL;
14 14
     int start = 0;
@@ -124,7 +124,6 @@ int readfile(CONFIG *config, BOOK *book) {
124 124
         if (array[j] != NULL) {
125 125
             line = latin2utf8(array[j]);
126 126
         }
127
-        /* printf("  array [%lu]  %s\n", (long) j, line); */
128 127
         if (line != NULL) {
129 128
             if (strcmp(line, config->bible) == 0) {
130 129
                 matches[0] = true;
@@ -150,6 +149,7 @@ int readfile(CONFIG *config, BOOK *book) {
150 149
                     book->current++;
151 150
                     book->chapter[book->current] = (CHAPTER *) malloc(sizeof(CHAPTER));
152 151
                     chapter = book->chapter[book->current];
152
+                    chapter->chapter = i;
153 153
                     chapter->current = -1;
154 154
                     chapter->verses = 0;
155 155
                     chapter->verse = (char **) malloc(sizeof(char *));
@@ -187,7 +187,6 @@ int readfile(CONFIG *config, BOOK *book) {
187 187
                         l = 0;
188 188
                         temp = (char *) malloc((strlen(line) + 1) * sizeof(char));
189 189
                         for (k = i + 1; k < strlen(line) - 1; (k++)) {
190
-                            /*printf("i: %d k: %d chars: %d\n", i, k, strlen(line));*/
191 190
                             temp[l] = line[k];
192 191
                             l++;
193 192
                         }
@@ -199,8 +198,6 @@ int readfile(CONFIG *config, BOOK *book) {
199 198
                         chapter->verse[chapter->current] = (char *) malloc((strlen(temp) + 1) * sizeof(char));
200 199
                         memcpy(chapter->verse[chapter->current], temp, strlen(temp) + 1);
201 200
 
202
-                        /*printf("%d - %s\n", verse, chapter->verses[chapter->current]);*/
203
-
204 201
                         if (temp) {
205 202
                             free(temp);
206 203
                         }

+ 1
- 1
src/readfile.h View File

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

Loading…
Cancel
Save