added documentation and fixed memory leak
This commit is contained in:
parent
e37024b041
commit
f2d697f555
19
main.c
19
main.c
@ -7,6 +7,9 @@
|
||||
|
||||
#ifdef LIBXML_TREE_ENABLED
|
||||
|
||||
/*
|
||||
* This program is designed to take a text file and convert part of it into xml.
|
||||
*/
|
||||
int main(int argc, char *argv[]) {
|
||||
atexit(cleanup);
|
||||
|
||||
@ -52,6 +55,10 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* Alternate main designed to prevent problems if the host system does not have
|
||||
* tree support enabled during compile.
|
||||
*/
|
||||
int main(int argc, char *argv[]) {
|
||||
fprintf(stderr, "libxml2 no tiene tree support compilado\n");
|
||||
return 1;
|
||||
@ -59,9 +66,11 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
#endif
|
||||
|
||||
/* Cleanup on aisle 3
|
||||
* */
|
||||
/*
|
||||
* This function is called on exit to clean up the memory usage.
|
||||
*/
|
||||
void cleanup() {
|
||||
/* Cleanup on aisle 3 */
|
||||
if (config != NULL) {
|
||||
if (config->file != NULL) {
|
||||
xmlFree(config->file);
|
||||
@ -83,8 +92,10 @@ void cleanup() {
|
||||
}
|
||||
}
|
||||
|
||||
/* Print how to use the program
|
||||
* */
|
||||
/*
|
||||
* Print information on the program's usage. If the argument is 1, the user
|
||||
* put something incorrect as an argument.
|
||||
*/
|
||||
void printusage(int error) {
|
||||
if (error == 1) {
|
||||
printf("Opcion desconocido!\n\n");
|
||||
|
11
readconfig.c
11
readconfig.c
@ -6,6 +6,10 @@
|
||||
#include <libxml/xinclude.h>
|
||||
#include "main.h"
|
||||
|
||||
/*
|
||||
* This function reads the designated config file and save into int the
|
||||
* config struct.
|
||||
*/
|
||||
int readconfig(char *config_file, CONFIG *config) {
|
||||
/* Initilize the library */
|
||||
LIBXML_TEST_VERSION
|
||||
@ -25,14 +29,19 @@ int readconfig(char *config_file, CONFIG *config) {
|
||||
config_xml = xmlCtxtReadFile(context, config_file, NULL, XML_PARSE_DTDVALID);
|
||||
if (config_xml == NULL) {
|
||||
fprintf(stderr, "Falló analizar %s\n", config_file);
|
||||
xmlFreeParserCtxt(context);
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
if (context->valid == 0) {
|
||||
fprintf(stderr, "Falló validar %s\n", config_file);
|
||||
xmlFreeParserCtxt(context);
|
||||
return 1;
|
||||
}
|
||||
|
||||
root = xmlDocGetRootElement(config_xml);
|
||||
|
||||
/* Run through the nodes to find the config information. */
|
||||
node = root->xmlChildrenNode;
|
||||
while (node != NULL) {
|
||||
if ((!xmlStrcmp(node->name, (const xmlChar *) "output"))){
|
||||
@ -64,8 +73,10 @@ int readconfig(char *config_file, CONFIG *config) {
|
||||
xmlFreeDoc(config_xml);
|
||||
}
|
||||
|
||||
/* If any config info is missing, abort */
|
||||
if (config->file == NULL || config->bible == NULL || config->book == NULL || config->chapter == NULL || config->chapter_numbers == NULL) {
|
||||
printf("El archivo de configuración es invalido!");
|
||||
xmlFreeParserCtxt(context);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user