cvs commit: ALFS/nALFS/src/handlers alfs.c

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Sat Mar 13 22:58:36 PST 2004


kpfleming    04/03/13 23:58:36

  Modified:    nALFS/src handlers.c handlers.h libXML-tree.c parser.c
               nALFS/src/handlers alfs.c
  Log:
  fix bugs in find_parent_with_data and callers, make available outside of handlers.c
  provide proper <alfs> syntax version handling (removing extra knowledge from parser as well)
  
  Revision  Changes    Path
  1.29      +30 -23    ALFS/nALFS/src/handlers.c
  
  Index: handlers.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers.c,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- handlers.c	14 Mar 2004 05:40:27 -0000	1.28
  +++ handlers.c	14 Mar 2004 06:58:36 -0000	1.29
  @@ -65,6 +65,21 @@
   	return 1;
   }
   
  +static char *root_data(const element_s * const element,
  +		       const handler_data_e data_requested)
  +{
  +	(void) element;
  +	switch (data_requested) {
  +	case HDATA_SYNTAX_VERSION:
  +		return xstrdup(*opt_default_syntax);
  +		break;
  +	default:
  +		break;
  +	}
  +
  +	return NULL;
  +}
  +
   static int comment_main(const element_s * const el)
   {
   	(void) el;
  @@ -80,6 +95,8 @@
   		.main = root_main,
   		.type = HTYPE_NORMAL,
   		.valid_child = root_valid_child,
  +		.data = HDATA_SYNTAX_VERSION,
  +		.alloc_data = root_data,
   	},
   #if HANDLER_SYNTAX_2_0
   	{
  @@ -327,16 +344,21 @@
   	return el->handler->alloc_data(el, HDATA_COMMAND);
   }
   
  -static const element_s *find_parent_with_data(const element_s * const element,
  -					      const handler_data_e data_requested)
  +const char *find_parent_with_data(const element_s * const element,
  +				  const handler_data_e data_requested)
   {
   	const element_s *s;
  +	char *data;
   
   	for (s = element->parent; s; s = s->parent) {
   		if (!s->handler)
   			continue;
   		if ((s->handler->data & data_requested) == 0)
  -			return s;
  +			continue;
  +
  +		data = s->handler->alloc_data(s, data_requested);
  +		if (data)
  +			return data;
   	}
   
   	return NULL;
  @@ -344,18 +366,7 @@
   
   const char *alloc_base_dir(const element_s * const element)
   {
  -	const element_s *s;	
  -	const char *dir;
  -
  -	s = find_parent_with_data(element, HDATA_BASE);
  -
  -	if (s) {
  -		dir  = s->handler->alloc_data(s, HDATA_BASE);
  -		if (dir)
  -			return dir;
  -	}
  -
  -	return NULL;
  +	return find_parent_with_data(element, HDATA_BASE);
   }
   
   int change_to_base_dir(const element_s * const element,
  @@ -383,16 +394,12 @@
   
   const char *alloc_stage_shell(const element_s * const el)
   {
  -	const element_s *s;
  -	char *shell;
  +	const char *dir;
   
  -	s = find_parent_with_data(el, HDATA_SHELL);
  +	dir = find_parent_with_data(el, HDATA_SHELL);
   
  -	if (s) {
  -		shell = s->handler->alloc_data(s, HDATA_SHELL);
  -		if (shell)
  -			return shell;
  -	}
  +	if (dir)
  +		return dir;
   
   	return xstrdup("sh");
   }
  
  
  
  1.28      +4 -0      ALFS/nALFS/src/handlers.h
  
  Index: handlers.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers.h,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- handlers.h	14 Mar 2004 06:11:07 -0000	1.27
  +++ handlers.h	14 Mar 2004 06:58:36 -0000	1.28
  @@ -52,6 +52,7 @@
   	HDATA_FILE = (1 << 4),
   	HDATA_BASE = (1 << 5),
   	HDATA_SHELL = (1 << 6),
  +	HDATA_SYNTAX_VERSION = (1 << 7),
   } handler_data_e;
   
   struct handler_attribute {
  @@ -146,6 +147,9 @@
   int package_has_name_and_version(element_s *el);
   char *alloc_textdump_file(element_s *el);
   char *alloc_execute_command(element_s *el);
  +
  +const char *find_parent_with_data(const element_s * const element,
  +				  const handler_data_e data_requested);
   
   const char *alloc_base_dir(const element_s * const element);
   
  
  
  
  1.21      +18 -42    ALFS/nALFS/src/libXML-tree.c
  
  Index: libXML-tree.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/libXML-tree.c,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- libXML-tree.c	14 Mar 2004 06:26:02 -0000	1.20
  +++ libXML-tree.c	14 Mar 2004 06:58:36 -0000	1.21
  @@ -90,9 +90,6 @@
    * XML_DOCB_DOCUMENT_NODE=     21
    */
   
  -
  -static char *syntax_version = NULL;
  -
   static unsigned int element_id;
   
   static const struct handler_attribute *find_handler_attribute(const handler_info_s *handler,
  @@ -227,11 +224,6 @@
   			child = child->next;
   			xmlUnlinkNode(free_child);
   			xmlFreeNode(free_child);
  -		} else if (!find_handler(child->name, syntax_version)) {
  -			Nprint_warn("<%s>: <%s> not supported here.", 
  -				    handler->name,
  -				    (const char *) child->name);
  -			child = child->next;
   		} else {
   			child = child->next;
   		}
  @@ -303,44 +295,38 @@
   	xmlChar *c;
   	handler_s *handler;
   	element_s *el = init_new_element();
  +	const char *syntax_version;
   
   
   	el->id = element_id++;
   	el->parent = parent;
  +	syntax_version = find_parent_with_data(el, HDATA_SYNTAX_VERSION);
   
   	switch (node->type) {
   		case XML_ELEMENT_NODE:
   			el->name = xstrdup((const char *)node->name);
  -
  -			/* Change syntax version, if specified. */
  -			if (strcmp(node->name, "alfs") == 0) {
  -				char *version = (char *) xmlGetProp(node,
  -					(const xmlChar *)"version");
  -
  -				if (version && strlen(version)) {
  -					xfree(syntax_version);
  -					syntax_version = version;
  -				}
  -			}
  -
   			if ((handler = find_handler(el->name, syntax_version))) {
   				el->type = TYPE_ELEMENT;
   				el->handler = handler->info;
   				if (make_handler_element(node, el)) {
   					free_element(el);
   					el = NULL;
  -					break;
  -				}
  -			}
  -
  -			/* Add content, if any. */
  -			if (node->children
  -			&& node->children->type == XML_TEXT_NODE
  -			&& node->children->next == NULL) {
  -				if ((c = xmlNodeGetContent(node))) {
  -					el->content = xstrdup((const char *)c);
  -					xfree(c);
  +				} else {
  +					/* Add content, if any. */
  +					if (node->children
  +					    && node->children->type == XML_TEXT_NODE
  +					    && node->children->next == NULL) {
  +						if ((c = xmlNodeGetContent(node))) {
  +							el->content = xstrdup((const char *)c);
  +							xfree(c);
  +						}
  +					}
   				}
  +			} else {
  +				Nprint_err("No handler found for %s (syntax version %s).",
  +					   el->name, syntax_version);
  +				free_element(el);
  +				el = NULL;
   			}
   
   			break;
  @@ -359,6 +345,7 @@
   			break;
   	}
   
  +	xfree(syntax_version);
   	return el;
   }
   
  @@ -442,19 +429,11 @@
   	xmlDocPtr doc;
   	element_s *profile = NULL;
   
  -
  -	/* Set the default syntax version. It will be changed while
  -	 * parsing, if there is version="" inside <alfs>.
  -	 */
  -	syntax_version = xstrdup(*opt_default_syntax);
  -
   	xmlSubstituteEntitiesDefault(1);
   	xmlSetGenericErrorFunc(NULL, handle_error);
   
   	if ((doc = xmlParseFile(filename)) == NULL) {
   		Nprint_err("Parsing \"%s\" failed.", filename);
  -		xfree(syntax_version);
  -		syntax_version = NULL;
   		return NULL;
   	}
   
  @@ -465,9 +444,6 @@
   	profile = convert_doc(doc);
   
   	xmlFreeDoc(doc);
  -
  -	xfree(syntax_version);
  -	syntax_version = NULL;
   
   	return profile;
   }
  
  
  
  1.13      +1 -1      ALFS/nALFS/src/parser.c
  
  Index: parser.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/parser.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- parser.c	14 Mar 2004 06:26:02 -0000	1.12
  +++ parser.c	14 Mar 2004 06:58:36 -0000	1.13
  @@ -82,7 +82,7 @@
   		child = tmp;
   	}
   
  -	if (el->handler->free)
  +	if (el->handler && el->handler->free)
   		el->handler->free(el);
   
   	xfree(el->name);
  
  
  
  1.23      +25 -0     ALFS/nALFS/src/handlers/alfs.c
  
  Index: alfs.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/alfs.c,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- alfs.c	29 Feb 2004 04:24:59 -0000	1.22
  +++ alfs.c	14 Mar 2004 06:58:36 -0000	1.23
  @@ -102,6 +102,23 @@
   				       HTYPE_EXECUTE);
   }
   
  +static char *alfs_data(const element_s * const element,
  +		       const handler_data_e data_requested)
  +{
  +	struct alfs_data *data = (struct alfs_data *) element->handler_data;
  +
  +	switch (data_requested) {
  +	case HDATA_SYNTAX_VERSION:
  +		if (data->version)
  +			return xstrdup(data->version);
  +		break;
  +	default:
  +		break;
  +	}
  +
  +	return NULL;
  +}
  +
   static int alfs_main(const element_s * const el)
   {
   	int status;
  @@ -129,6 +146,8 @@
   		.attributes = alfs_attributes,
   		.attribute = alfs_attribute,
   		.valid_child = alfs_valid_child,
  +		.data = HDATA_SYNTAX_VERSION,
  +		.alloc_data = alfs_data,
   	},
   #endif
   #if HANDLER_SYNTAX_3_0
  @@ -143,6 +162,8 @@
   		.attributes = alfs_attributes,
   		.attribute = alfs_attribute,
   		.valid_child = alfs_valid_child,
  +		.data = HDATA_SYNTAX_VERSION,
  +		.alloc_data = alfs_data,
   	},
   #endif
   #if HANDLER_SYNTAX_3_1
  @@ -157,6 +178,8 @@
   		.attributes = alfs_attributes,
   		.attribute = alfs_attribute,
   		.valid_child = alfs_valid_child,
  +		.data = HDATA_SYNTAX_VERSION,
  +		.alloc_data = alfs_data,
   	},
   #endif
   #if HANDLER_SYNTAX_3_2
  @@ -171,6 +194,8 @@
   		.attributes = alfs_attributes,
   		.attribute = alfs_attribute,
   		.valid_child = alfs_valid_child,
  +		.data = HDATA_SYNTAX_VERSION,
  +		.alloc_data = alfs_data,
   	},
   #endif
   	{
  
  
  



More information about the alfs-log mailing list