cvs commit: ALFS/nALFS/src/handlers log.c postbuild.c prebuild.c stamp.c

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Sat Feb 28 20:16:03 PST 2004


kpfleming    04/02/28 21:16:03

  Modified:    nALFS/src/handlers log.c postbuild.c prebuild.c stamp.c
  Log:
  convert to new parsing system
  
  Revision  Changes    Path
  1.17      +58 -6     ALFS/nALFS/src/handlers/log.c
  
  Index: log.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/log.c,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- log.c	24 Feb 2004 06:30:11 -0000	1.16
  +++ log.c	29 Feb 2004 04:16:03 -0000	1.17
  @@ -32,20 +32,64 @@
   
   #include "handlers.h"
   #include "nprint.h"
  +#include "utility.h"
   
  +struct log_data {
  +	char *content;
  +};
   
  -#if HANDLER_SYNTAX_2_0 || HANDLER_SYNTAX_3_0
  +static int log_setup(element_s * const element)
  +{
  +	struct log_data *data;
  +
  +	if ((data = xmalloc(sizeof(struct log_data))) == NULL)
  +		return 1;
  +
  +	data->content = NULL;
  +	element->handler_data = data;
  +
  +	return 0;
  +}
   
  +static void log_free(const element_s * const element)
  +{
  +	struct log_data *data = (struct log_data *) element->handler_data;
   
  -static int log_main(const element_s * const el)
  +	xfree(data->content);
  +	xfree(data);
  +}
  +
  +static int log_content(const element_s * const element,
  +		       const char * const content)
   {
  -	Nprint_h("%s", el->content ? el->content : "");
  +	struct log_data *data = (struct log_data *) element->handler_data;
  +
  +	if (strlen(content))
  +		data->content = xstrdup(content);
   
   	return 0;
   }
   
  -#endif /* HANDLER_SYNTAX_2_0 || HANDLER_SYNTAX_3_0 */
  +static int log_valid_data(const element_s * const element)
  +{
  +	struct log_data *data = (struct log_data *) element->handler_data;
  +
  +	if (!data->content) {
  +		Nprint_err("<log>: content cannot be empty.");
  +		return 0;
  +	}
   
  +	return 1;
  +}
  +
  +static int log_main(const element_s * const element)
  +{
  +	struct log_data *data = (struct log_data *) element->handler_data;
  +
  +	Nprint_h("%s", data->content);
  +
  +	return 0;
  +}
   
   /*
    * Handlers' information.
  @@ -61,7 +105,11 @@
   		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 0,
  -		.priority = 0
  +		.priority = 0,
  +		.setup = log_setup,
  +		.free = log_free,
  +		.content = log_content,
  +		.valid_data = log_valid_data,
   	},
   #endif
   #if HANDLER_SYNTAX_3_0
  @@ -73,7 +121,11 @@
   		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 0,
  -		.priority = 0
  +		.priority = 0,
  +		.setup = log_setup,
  +		.free = log_free,
  +		.content = log_content,
  +		.valid_data = log_valid_data,
   	},
   #endif
   	{
  
  
  
  1.17      +5 -5      ALFS/nALFS/src/handlers/postbuild.c
  
  Index: postbuild.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/postbuild.c,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- postbuild.c	24 Feb 2004 06:30:11 -0000	1.16
  +++ postbuild.c	29 Feb 2004 04:16:03 -0000	1.17
  @@ -34,8 +34,10 @@
   #include "backend.h"
   #include "logging.h"
   
  -
  -#if HANDLER_SYNTAX_2_0
  +static int postbuild_setup(const element_s * element)
  +{
  +	return 0;
  +}
   
   static int postbuild_main(const element_s * const el)
   {
  @@ -50,9 +52,6 @@
   	return i;
   }
   
  -#endif /* HANDLER_SYNTAX_2_0 */
  -
  -
   /*
    * Handlers' information.
    */
  @@ -66,6 +65,7 @@
   		.main = postbuild_main,
   		.type = HTYPE_NORMAL,
   		.is_action = 0,
  +		.setup = postbuild_setup,
   	},
   #endif
   	{
  
  
  
  1.17      +5 -5      ALFS/nALFS/src/handlers/prebuild.c
  
  Index: prebuild.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/prebuild.c,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- prebuild.c	24 Feb 2004 06:30:11 -0000	1.16
  +++ prebuild.c	29 Feb 2004 04:16:03 -0000	1.17
  @@ -34,8 +34,10 @@
   #include "backend.h"
   #include "logging.h"
   
  -
  -#if HANDLER_SYNTAX_2_0
  +static int prebuild_setup(const element_s * element)
  +{
  +	return 0;
  +}
   
   static int prebuild_main(const element_s * const el)
   {
  @@ -50,9 +52,6 @@
   	return i;
   }
   
  -#endif /* HANDLER_SYNTAX_2_0 */
  -
  -
   /*
    * Handlers' information.
    */
  @@ -67,6 +66,7 @@
   		.main = prebuild_main,
   		.type = HTYPE_NORMAL,
   		.is_action = 1,
  +		.setup = prebuild_setup,
   	},
   #endif
   	{
  
  
  
  1.16      +77 -17    ALFS/nALFS/src/handlers/stamp.c
  
  Index: stamp.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/stamp.c,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- stamp.c	24 Feb 2004 06:30:11 -0000	1.15
  +++ stamp.c	29 Feb 2004 04:16:03 -0000	1.16
  @@ -34,38 +34,94 @@
   #include "parser.h"
   #include "backend.h"
   
  +enum {
  +	STAMP_NAME,
  +	STAMP_VERSION,
  +};
   
  -#if HANDLER_SYNTAX_2_0
  +struct stamp_data {
  +	char *name;
  +	char *version;
  +};
   
   static const struct handler_attribute stamp_attributes[] = {
  -	{ .name = "name" },
  -	{ .name = "version" },
  +	{ .name = "name", .private = STAMP_NAME },
  +	{ .name = "version", .private = STAMP_VERSION },
   	{ .name = NULL }
   };
   
  -static int stamp_main(const element_s * const el)
  +static int stamp_setup(element_s * const element)
   {
  -	int status = 0;
  -	char *name;
  -	char *version;
  +	struct stamp_data *data;
  +
  +	if ((data = xmalloc(sizeof(struct stamp_data))) == NULL)
  +		return 1;
  +
  +	data->name = NULL;
  +	data->version = NULL;
  +	element->handler_data = data;
   
  -	if ((name = attr_value("name", el)) == NULL) {
  -		Nprint_h_err("No name specified.");
  -		return -1;
  +	return 0;
  +}
  +
  +static void stamp_free(const element_s * const element)
  +{
  +	struct stamp_data *data = (struct stamp_data *) element->handler_data;
  +
  +	xfree(data->name);
  +	xfree(data->version);
  +	xfree(data);
  +}
  +
  +static int stamp_attribute(const element_s * const element,
  +			   const struct handler_attribute * const attr,
  +			   const char * const value)
  +{
  +	struct stamp_data *data = (struct stamp_data *) element->handler_data;
  +
  +	switch (attr->private) {
  +	case STAMP_NAME:
  +		if (data->name) {
  +			Nprint_err("<stamp>: cannot specify \"name\" more than once.");
  +			return 1;
  +		}
  +		data->name = xstrdup(value);
  +		return 0;
  +	case STAMP_VERSION:
  +		if (data->version) {
  +			Nprint_err("<stamp>: cannot specify \"version\" more than once.");
  +			return 1;
  +		}
  +		data->version = xstrdup(value);
  +		return 0;
  +	default:
  +		return 1;
   	}
  +}
   
  -	if ((version = attr_value("version", el)) == NULL) {
  -		Nprint_h_err("No version specified.");
  -		return -1;
  +static int stamp_valid_data(const element_s * const element)
  +{
  +	struct stamp_data *data = (struct stamp_data *) element->handler_data;
  +
  +	if (!data->name) {
  +		Nprint_err("<stamp>: \"name\" cannot be empty.");
  +		return 0;
   	}
   
  -	status = stamp_package_installed(1, name, version);
  +	if (!data->version) {
  +		Nprint_err("<stamp>: \"version\" cannot be empty.");
  +		return 0;
  +	}
   
  -	return status;
  +	return 1;
   }
   
  -#endif /* HANDLER_SYNTAX_2_0 */
  +static int stamp_main(const element_s * const element)
  +{
  +	struct stamp_data *data = (struct stamp_data *) element->handler_data;
   
  +	return stamp_package_installed(1, data->name, data->version);
  +}
   
   /*
    * Handlers' information.
  @@ -76,10 +132,14 @@
   	{
   		.name = "stamp",
   		.description = "Produce a stamp",
  -		.syntax_version = "3.0",
  +		.syntax_version = "2.0",
   		.main = stamp_main,
   		.type = HTYPE_NORMAL,
  +		.setup = stamp_setup,
  +		.free = stamp_free,
   		.attributes = stamp_attributes,
  +		.attribute = stamp_attribute,
  +		.valid_data = stamp_valid_data,
   	},
   #endif
   	{
  
  
  



More information about the alfs-log mailing list