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

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Mon Feb 23 11:02:11 PST 2004


kpfleming    04/02/23 12:02:11

  Modified:    nALFS/src libXML-tree.c
               nALFS/src/handlers stage.c
  Log:
  implement basic semantic checking in <stage> and related handlers
  
  Revision  Changes    Path
  1.11      +1 -1      ALFS/nALFS/src/libXML-tree.c
  
  Index: libXML-tree.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/libXML-tree.c,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- libXML-tree.c	21 Feb 2004 23:09:17 -0000	1.10
  +++ libXML-tree.c	23 Feb 2004 19:02:11 -0000	1.11
  @@ -231,7 +231,7 @@
   	if (parent->invalid_child) {
   		result = parent->invalid_child(element->parent, element);
   		if (result) {
  -			Nprint_warn("<%s>: <%s> is not supported.", element->parent->handler->name, handler->name);
  +			Nprint_warn("<%s>: <%s> not valid here.", parent->name, handler->name);
   			return result;
   		}
   	}
  
  
  
  1.23      +89 -23    ALFS/nALFS/src/handlers/stage.c
  
  Index: stage.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/stage.c,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- stage.c	23 Feb 2004 18:16:21 -0000	1.22
  +++ stage.c	23 Feb 2004 19:02:11 -0000	1.23
  @@ -48,6 +48,11 @@
   #include "backend.h"
   #include "options.h"
   
  +/* Forward declarations for cross-handler references */
  +static int environment_main(element_s * const element);
  +static int variable_main(element_s * const element);
  +
  +
   extern char **environ;
   
   
  @@ -209,18 +214,14 @@
   	return 0;
   }
   
  -static const element_s *find_stageinfo(const element_s *element)
  -{
  -	const element_s *child;
  +/* <stage> handler */
   
  -	for (child = element->children; child; child = child->next) {
  -		if (child->handler->type & HTYPE_STAGEINFO) {
  -			return child;
  -		}
  -	}
  +static const char *stage_attributes[] = { "name", NULL};
   
  -	return NULL;
  -}
  +struct stage_data {
  +	char *name;
  +	const element_s *stageinfo;
  +};
   
   /* common function used by all stage-like handlers to actually execute
      the element's children
  @@ -228,12 +229,13 @@
   
   static int process_stage(element_s *element)
   {
  +	struct stage_data *data = (struct stage_data *) element->handler_data;
   	int status;
   	pid_t pid, got_pid;
   
   	/* if no <stageinfo> found, simply execute children */
   
  -	if (!find_stageinfo(element))
  +	if (!data->stageinfo)
   		return execute_children(element);
   
   	/* found <stageinfo>, assume that a fork() is necessary */
  @@ -284,15 +286,6 @@
   	return status;
   }
   
  -
  -/* <stage> handler */
  -
  -static const char *stage_attributes[] = { "name", NULL};
  -
  -struct stage_data {
  -	char *name;
  -};
  -
   static int stage_setup(element_s * const element)
   {
   	struct stage_data *data;
  @@ -301,6 +294,7 @@
   		return 1;
   
   	data->name = NULL;
  +	data->stageinfo = NULL;
   	element->handler_data = data;
   
   	return 0;
  @@ -328,6 +322,28 @@
   	return 1;
   }
   
  +static int stage_invalid_child(const element_s * const element,
  +			       const element_s * const child)
  +{
  +	struct stage_data *data = (struct stage_data *) element->handler_data;
  +
  +	if (child->handler->type & HTYPE_STAGEINFO) {
  +		if (data->stageinfo) {
  +			Nprint_err("<stage>: only one <stageinfo> allowed.");
  +			return 1;
  +		}
  +
  +		data->stageinfo = child;
  +		return 0;
  +	}
  +
  +	return !(child->handler->type & (HTYPE_NORMAL |
  +			 HTYPE_TEXTDUMP |
  +			 HTYPE_PACKAGE |
  +			 HTYPE_EXECUTE |
  +			 HTYPE_STAGE));
  +}
  +
   static int stage_main(element_s * const element)
   {
   	int status;
  @@ -361,17 +377,17 @@
   static char *stage_data(const element_s * const element,
   			const handler_data_e data_requested)
   {
  -	const element_s *stageinfo;
  +	struct stage_data *data = (struct stage_data *) element->handler_data;
   
   	/* the only data elements currently supported by the <stage>
   	   element are HDATA_BASE and HDATA_SHELL, which actually
   	   are supplied by an HTYPE_STAGEINFO child, if it exists
   	*/
   
  -	if (!(stageinfo = find_stageinfo(element)))
  +	if (!data->stageinfo)
   		return NULL;
   	
  -	return stageinfo->handler->alloc_data(stageinfo, data_requested);
  +	return data->stageinfo->handler->alloc_data(data->stageinfo, data_requested);
   }
   
   #if HANDLER_SYNTAX_3_1 || HANDLER_SYNTAX_3_2
  @@ -490,6 +506,18 @@
   	return 1;
   }
   
  +static int stageinfo_invalid_child(const element_s * const element,
  +				   const element_s * const child)
  +{
  +	(void) element;
  +
  +	if (child->handler->main != environment_main) {
  +		return 1;
  +	}
  +
  +	return 0;
  +}
  +
   static int stageinfo_main(element_s * const element)
   {
   	struct stageinfo_data *data = (struct stageinfo_data *) element->handler_data;
  @@ -540,8 +568,21 @@
   	return NULL;
   }
   
  +
   /* <environment> handler */
   
  +static int environment_invalid_child(const element_s * const element,
  +				     const element_s * const child)
  +{
  +	(void) element;
  +
  +	if (child->handler->main != variable_main) {
  +		return 1;
  +	}
  +
  +	return 0;
  +}
  +
   static int environment_main(element_s * const element)
   {
   	return execute_children(element);
  @@ -641,6 +682,15 @@
   	return 0;
   }
   
  +static int variable_invalid_child(const element_s * const element,
  +				  const element_s * const child)
  +{
  +	(void) element;
  +	(void) child;
  +
  +	return 1;
  +}
  +
   static int variable_main(element_s * const element)
   {
   	struct variable_data *data = (struct variable_data *) element->handler_data;
  @@ -679,6 +729,7 @@
   		.free = stage_free,
   		.attributes = stage_attributes,
   		.parse_attribute = stage_attribute,
  +		.invalid_child = stage_invalid_child,
   	},
   	{
   		.name = "stageinfo",
  @@ -691,6 +742,7 @@
   		.free = stageinfo_free,
   		.parameters = stageinfo_parameters,
   		.parse_parameter = stageinfo_parameter,
  +		.invalid_child = stageinfo_invalid_child,
   	},
   	{
   		.name = "environment",
  @@ -698,6 +750,7 @@
   		.syntax_version = "3.0",
   		.type = HTYPE_NORMAL,
   		.main = environment_main,
  +		.invalid_child = environment_invalid_child,
   	},
   	{
   		.name = "variable",
  @@ -711,6 +764,7 @@
   		.parse_attribute = variable_attribute,
   		.parse_content = variable_content,
   		.invalid_data = variable_invalid_data,
  +		.invalid_child = variable_invalid_child,
   	},
   #endif
   #if HANDLER_SYNTAX_3_1
  @@ -726,6 +780,7 @@
   		.free = stage_free,
   		.attributes = stage_attributes,
   		.parse_attribute = stage_attribute,
  +		.invalid_child = stage_invalid_child,
   	},
   	{
   		.name = "then",
  @@ -739,6 +794,7 @@
   		.free = stage_free,
   		.attributes = stage_attributes,
   		.parse_attribute = stage_attribute,
  +		.invalid_child = stage_invalid_child,
   	},
   	{
   		.name = "else",
  @@ -752,6 +808,7 @@
   		.free = stage_free,
   		.attributes = stage_attributes,
   		.parse_attribute = stage_attribute,
  +		.invalid_child = stage_invalid_child,
   	},
   	{
   		.name = "stageinfo",
  @@ -764,6 +821,7 @@
   		.free = stageinfo_free,
   		.parameters = stageinfo_parameters,
   		.parse_parameter = stageinfo_parameter,
  +		.invalid_child = stageinfo_invalid_child,
   	},
   	{
   		.name = "environment",
  @@ -771,6 +829,7 @@
   		.syntax_version = "3.1",
   		.type = HTYPE_NORMAL,
   		.main = environment_main,
  +		.invalid_child = environment_invalid_child,
   	},
   	{
   		.name = "variable",
  @@ -784,6 +843,7 @@
   		.parse_attribute = variable_attribute,
   		.parse_content = variable_content,
   		.invalid_data = variable_invalid_data,
  +		.invalid_child = variable_invalid_child,
   	},
   #endif
   #if HANDLER_SYNTAX_3_2
  @@ -799,6 +859,7 @@
   		.free = stage_free,
   		.attributes = stage_attributes,
   		.parse_attribute = stage_attribute,
  +		.invalid_child = stage_invalid_child,
   	},
   	{
   		.name = "then",
  @@ -812,6 +873,7 @@
   		.free = stage_free,
   		.attributes = stage_attributes,
   		.parse_attribute = stage_attribute,
  +		.invalid_child = stage_invalid_child,
   	},
   	{
   		.name = "else",
  @@ -825,6 +887,7 @@
   		.free = stage_free,
   		.attributes = stage_attributes,
   		.parse_attribute = stage_attribute,
  +		.invalid_child = stage_invalid_child,
   	},
   	{
   		.name = "stageinfo",
  @@ -837,6 +900,7 @@
   		.alloc_data = stageinfo_data,
   		.parameters = stageinfo_parameters_3_2,
   		.parse_parameter = stageinfo_parameter,
  +		.invalid_child = stageinfo_invalid_child,
   	},
   	{
   		.name = "environment",
  @@ -844,6 +908,7 @@
   		.syntax_version = "3.2",
   		.type = HTYPE_NORMAL,
   		.main = environment_main,
  +		.invalid_child = environment_invalid_child,
   	},
   	{
   		.name = "variable",
  @@ -857,6 +922,7 @@
   		.parse_attribute = variable_attribute,
   		.parse_content = variable_content,
   		.invalid_data = variable_invalid_data,
  +		.invalid_child = variable_invalid_child,
   	},
   #endif
   	{
  
  
  



More information about the alfs-log mailing list