cvs commit: ALFS/nALFS/src libXML-tree.c libXML-tree.h nalfs.c parser.c parser.h

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Sun Mar 21 10:40:32 PST 2004


kpfleming    04/03/21 11:40:32

  Modified:    nALFS/src libXML-tree.c libXML-tree.h nalfs.c parser.c
                        parser.h
  Log:
  push parser and libXML-tree initialization into those modules
  check runtime libxml2 version and report it, warn if not the version nALFS was compiled against
  call LIBXML_TEST_VERSION to catch major version incompatibilities
  
  Revision  Changes    Path
  1.26      +48 -3     ALFS/nALFS/src/libXML-tree.c
  
  Index: libXML-tree.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/libXML-tree.c,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- libXML-tree.c	21 Mar 2004 03:40:51 -0000	1.25
  +++ libXML-tree.c	21 Mar 2004 18:40:32 -0000	1.26
  @@ -343,9 +343,6 @@
   	xmlDocPtr doc;
   	element_s *profile = NULL;
   
  -	xmlSubstituteEntitiesDefault(1);
  -	xmlSetGenericErrorFunc(NULL, handle_error);
  -
   	if ((doc = xmlParseFile(filename)) == NULL) {
   		Nprint_err("Parsing \"%s\" failed.", filename);
   		return NULL;
  @@ -360,6 +357,54 @@
   	xmlFreeDoc(doc);
   
   	return profile;
  +}
  +
  +static const char *make_dotted_version(const char * const version)
  +{
  +	char *dotted_version = NULL;
  +	int version_num = atoi(version);
  +	int major, minor, patch;
  +	
  +	patch = version_num % 100;
  +	minor = (version_num / 100) % 100;
  +	major = (version_num / 10000) % 100;
  +	append_str_format(&dotted_version, "%d.%d.%d", major, minor, patch);
  +
  +	return dotted_version;
  +}
  +
  +static const char *get_libxml_version(void)
  +{
  +	if (strcmp(xmlParserVersion, LIBXML_VERSION_STRING) == 0) {
  +		return make_dotted_version(xmlParserVersion);
  +	} else {
  +		const char *compiled;
  +		const char *installed;
  +		char *result = NULL;
  +
  +		compiled = make_dotted_version(LIBXML_VERSION_STRING);
  +		installed = make_dotted_version(xmlParserVersion);
  +		append_str_format(&result, "%s (compiled against %s)",
  +				  installed, compiled);
  +		xfree(compiled);
  +		xfree(installed);
  +		return result;
  +	}
  +}
  +
  +void init_libXML_tree(void)
  +{
  +	const char *xml_version;
  +
  +	xmlSetGenericErrorFunc(NULL, handle_error);
  +
  +	LIBXML_TEST_VERSION;
  +
  +	xmlSubstituteEntitiesDefault(1);
  +
  +	xml_version = get_libxml_version();
  +	Nprint("Using libXML2, version %s.", xml_version);
  +	xfree(xml_version);
   }
   
   /*
  
  
  
  1.4       +2 -0      ALFS/nALFS/src/libXML-tree.h
  
  Index: libXML-tree.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/libXML-tree.h,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- libXML-tree.h	25 Oct 2003 22:29:48 -0000	1.3
  +++ libXML-tree.h	21 Mar 2004 18:40:32 -0000	1.4
  @@ -27,6 +27,8 @@
   
   #include "parser.h"
   
  +void init_libXML_tree(void);
  +
   element_s *parse_with_libxml2_tree(const char *filename);
   
   /*
  
  
  
  1.51      +2 -2      ALFS/nALFS/src/nalfs.c
  
  Index: nalfs.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/nalfs.c,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- nalfs.c	21 Mar 2004 04:54:33 -0000	1.50
  +++ nalfs.c	21 Mar 2004 18:40:32 -0000	1.51
  @@ -4466,7 +4466,6 @@
   {
   	int i;
   
  -
   	nprint = nprint_init;
   
   	/* Load all handlers (before options, so handlers can provide options). */
  @@ -4511,8 +4510,9 @@
   
   	/* Print some useful information. */
   	Nprint("Using \"%s\" directory.", *opt_alfs_directory);
  -	Nprint("Using libxml2, version %s.", LIBXML_DOTTED_VERSION);
   	Nprint("Total %d handlers loaded.", get_handler_count());
  +
  +	init_parser();
   
   	/* Add profiles from command line. */
   	for (i = optind; i < argc; ++i) {
  
  
  
  1.19      +7 -2      ALFS/nALFS/src/parser.c
  
  Index: parser.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/parser.c,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- parser.c	21 Mar 2004 04:38:52 -0000	1.18
  +++ parser.c	21 Mar 2004 18:40:32 -0000	1.19
  @@ -73,8 +73,7 @@
   {
   	ASSERT(profile->type == TYPE_PROFILE);
   
  -	if (root_element == NULL) {
  -		create_root_element();
  +	if (root_element->children == NULL) {
   		root_element->children = profile;
   	} else {
   		element_s *last_profile = root_element->children;
  @@ -235,6 +234,12 @@
   	print_unknown_elements(profile);
   
   	return profile;
  +}
  +
  +void init_parser(void)
  +{
  +	init_libXML_tree();
  +	create_root_element();
   }
   
   /*
  
  
  
  1.13      +2 -0      ALFS/nALFS/src/parser.h
  
  Index: parser.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/parser.h,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- parser.h	21 Mar 2004 04:38:52 -0000	1.12
  +++ parser.h	21 Mar 2004 18:40:32 -0000	1.13
  @@ -73,6 +73,8 @@
   
   element_s *root_element;
   
  +void init_parser(void);
  +
   void add_profile(element_s * const profile);
   void remove_profile(element_s * const profile);
   
  
  
  



More information about the alfs-log mailing list