cvs commit: ALFS/nALFS/src/handlers configure.c make.c mkdir.c move.c owner.c ownership.c

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Tue Mar 2 19:57:05 PST 2004


kpfleming    04/03/02 20:57:05

  Modified:    nALFS/src/handlers configure.c make.c mkdir.c move.c owner.c
                        ownership.c
  Log:
  convert to new parsing system
  
  Revision  Changes    Path
  1.20      +122 -66   ALFS/nALFS/src/handlers/configure.c
  
  Index: configure.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/configure.c,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- configure.c	29 Feb 2004 04:24:59 -0000	1.19
  +++ configure.c	3 Mar 2004 03:57:05 -0000	1.20
  @@ -22,10 +22,13 @@
    */
   
   
  +#include <stdio.h>
   #include <stdlib.h>
   #include <string.h>
  -#include <unistd.h>
   #include <errno.h>
  +#include <unistd.h>
  +#include <sys/types.h>
  +#include <sys/stat.h>
   
   #ifdef HAVE_CONFIG_H
   #include <config.h>
  @@ -36,103 +39,141 @@
   
   #include "handlers.h"
   #include "utility.h"
  -#include "parser.h"
   #include "nprint.h"
  +#include "parser.h"
   #include "backend.h"
  +#include "options.h"
   
  -
  -#if HANDLER_SYNTAX_2_0
  -
  -static const struct handler_parameter configure_parameters_ver2[] = {
  -	{ .name = "base" },
  -	{ .name = "command" },
  -	{ .name = "param" },
  -	{ .name = NULL }
  +enum {
  +	CONFIGURE_BASE,
  +	CONFIGURE_PARAM,
  +	CONFIGURE_PREFIX,
   };
   
  -static int configure_main_ver2(const element_s * const el)
  -{
  -	int status;
  -	char *c, *command = NULL;
  +struct configure_data {
   	char *base;
  -       
  +	char *param;
  +	int param_seen;
  +	char *prefix;
  +	int prefix_seen;
  +};
   
  -	base = alloc_base_dir(el);
  +static int configure_setup(element_s * const element)
  +{
  +	struct configure_data *data;
   
  -	if (change_current_dir(base)) {
  -		xfree(base);
  +	if ((data = xmalloc(sizeof(struct configure_data))) == NULL)
   		return -1;
  -	}
   
  -	if ((c = alloc_trimmed_param_value("command", el))) {
  -		append_str(&command, c);
  -	} else {
  -		append_str(&command, "./configure");
  -	}
  -	xfree(c);
  +	data->param = xstrdup(" ");
  +	data->param_seen = 0;
  +	data->prefix = xstrdup("");
  +	data->prefix_seen = 0;
  +	data->base = NULL;
  +	element->handler_data = data;
   
  -	append_param_elements(&command, el);
  +	return 0;
  +}
   
  -	Nprint_h("Executing in %s:", base);
  -	Nprint_h("    %s", command);
  -	status = execute_command(el, "%s", command);
  +static void configure_free(const element_s * const element)
  +{
  +	struct configure_data *data = (struct configure_data *) element->handler_data;
   
  -	xfree(base);
  -	xfree(command);
  +	xfree(data->base);
  +	xfree(data->prefix);
  +	xfree(data->param);
  +	xfree(data);
  +}
   
  -	return status;
  +static int configure_attribute(const element_s * const element,
  +			       const struct handler_attribute * const attr,
  +			       const char * const value)
  +{
  +	struct configure_data *data = (struct configure_data *) element->handler_data;
  +
  +	switch (attr->private) {
  +	case CONFIGURE_BASE:
  +		if (data->base) {
  +			Nprint_err("<%s>: cannot specify \"base\" more than once.", element->handler->name);
  +			return 1;
  +		}
  +		data->base = xstrdup(value);
  +		return 0;
  +	default:
  +		return 1;
  +	}
   }
   
  -#endif /* HANDLER_SYNTAX_2_0 */
  +static int configure_parameter(const element_s * const element,
  +			       const struct handler_parameter * const param,
  +			       const char * const value)
  +{
  +	struct configure_data *data = (struct configure_data *) element->handler_data;
  +
  +	switch (param->private) {
  +	case CONFIGURE_BASE:
  +		if (data->base) {
  +			Nprint_err("<%s>: cannot specify <base> more than once.", element->handler->name);
  +			return 1;
  +		}
  +		data->base = xstrdup(value);
  +		return 0;
  +	case CONFIGURE_PREFIX:
  +		append_str(&data->prefix, value);
  +		append_str(&data->prefix, " ");
  +		data->prefix_seen = 1;
  +		return 0;
  +	case CONFIGURE_PARAM:
  +		append_str(&data->param, value);
  +		append_str(&data->param, " ");
  +		data->param_seen = 1;
  +		return 0;
  +	default:
  +		return 1;
  +	}
  +}
   
  +#if HANDLER_SYNTAX_2_0
  +
  +static const struct handler_parameter configure_parameters_v2[] = {
  +	{ .name = "base", .private = CONFIGURE_BASE },
  +	{ .name = "param", .private = CONFIGURE_PARAM },
  +	{ .name = NULL }
  +};
  +
  +#endif /* HANDLER_SYNTAX_2_0 */
   
   #if HANDLER_SYNTAX_3_0 || HANDLER_SYNTAX_3_1 || HANDLER_SYNTAX_3_2
   
   static const struct handler_parameter configure_parameters_v3[] = {
  -	{ .name = "prefix" },
  -	{ .name = "param" },
  +	{ .name = "prefix", .private = CONFIGURE_PREFIX },
  +	{ .name = "param", .private = CONFIGURE_PARAM },
   	{ .name = NULL }
   };
   
   static const struct handler_attribute configure_attributes_v3[] = {
  -	{ .name = "base" },
  -	{ .name = "command" },
  +	{ .name = "base", .private = CONFIGURE_BASE },
   	{ .name = NULL }
   };
   
  -static int configure_main_ver3(const element_s * const el)
  +#endif /* HANDLER_SYNTAX_3_0 || HANDLER_SYNTAX_3_1 || HANDLER_SYNTAX_3_2 */
  +
  +static int configure_main(const element_s * const element)
   {
  +	struct configure_data *data = (struct configure_data *) element->handler_data;
   	int status;
  -	char *c, *command = NULL;
  -       
   
  -	if (change_to_base_dir(el, attr_value("base", el), 1))
  +	if (change_to_base_dir(element, data->base, 1))
   		return -1;
  +	
  +	Nprint_h("Executing system command");
  +	Nprint_h("    %s configure %s", data->prefix, data->param);
   
  -	command = xstrdup("");
  -
  -	append_prefix_elements(&command, el);
  -
  -	if ((c = attr_value("command", el))) {
  -		append_str(&command, c);
  -	} else {
  -		append_str(&command, "./configure");
  -	}
  -
  -	append_param_elements(&command, el);
  -
  -	Nprint_h("Executing:");
  -	Nprint_h("    %s", command);
  -	status = execute_command(el, "%s", command);
  -
  -	xfree(command);
  +	status = execute_command(element, "%s configure %s", data->prefix, data->param);
   
   	return status;
   }
   
  -#endif /* HANDLER_SYNTAX_3_0 || HANDLER_SYNTAX_3_1 || HANDLER_SYNTAX_3_2 */
  -
  -
   /*
    * Handlers' information.
    */
  @@ -143,10 +184,13 @@
   		.name = "configure",
   		.description = "Configure",
   		.syntax_version = "2.0",
  -		.parameters = configure_parameters_ver2,
  -		.main = configure_main_ver2,
  +		.parameters = configure_parameters_v2,
  +		.main = configure_main,
   		.type = HTYPE_NORMAL,
   		.is_action = 1,
  +		.setup = configure_setup,
  +		.free = configure_free,
  +		.parameter = configure_parameter,
   	},
   #endif
   #if HANDLER_SYNTAX_3_0
  @@ -156,9 +200,13 @@
   		.syntax_version = "3.0",
   		.parameters = configure_parameters_v3,
   		.attributes = configure_attributes_v3,
  -		.main = configure_main_ver3,
  +		.main = configure_main,
   		.type = HTYPE_NORMAL,
   		.is_action = 1,
  +		.setup = configure_setup,
  +		.free = configure_free,
  +		.parameter = configure_parameter,
  +		.attribute = configure_attribute,
   	},
   #endif
   #if HANDLER_SYNTAX_3_1
  @@ -168,9 +216,13 @@
   		.syntax_version = "3.1",
   		.parameters = configure_parameters_v3,
   		.attributes = configure_attributes_v3,
  -		.main = configure_main_ver3,
  +		.main = configure_main,
   		.type = HTYPE_NORMAL,
   		.is_action = 1,
  +		.setup = configure_setup,
  +		.free = configure_free,
  +		.parameter = configure_parameter,
  +		.attribute = configure_attribute,
   	},
   #endif
   #if HANDLER_SYNTAX_3_2
  @@ -180,10 +232,14 @@
   		.syntax_version = "3.2",
   		.parameters = configure_parameters_v3,
   		.attributes = configure_attributes_v3,
  -		.main = configure_main_ver3,
  +		.main = configure_main,
   		.type = HTYPE_NORMAL,
   		.is_action = 1,
   		.alternate_shell = 1,
  +		.setup = configure_setup,
  +		.free = configure_free,
  +		.parameter = configure_parameter,
  +		.attribute = configure_attribute,
   	},
   #endif
   	{
  
  
  
  1.20      +125 -59   ALFS/nALFS/src/handlers/make.c
  
  Index: make.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/make.c,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- make.c	29 Feb 2004 04:24:59 -0000	1.19
  +++ make.c	3 Mar 2004 03:57:05 -0000	1.20
  @@ -22,10 +22,13 @@
    */
   
   
  +#include <stdio.h>
   #include <stdlib.h>
   #include <string.h>
  -#include <unistd.h>
   #include <errno.h>
  +#include <unistd.h>
  +#include <sys/types.h>
  +#include <sys/stat.h>
   
   #ifdef HAVE_CONFIG_H
   #include <config.h>
  @@ -39,90 +42,138 @@
   #include "nprint.h"
   #include "parser.h"
   #include "backend.h"
  +#include "options.h"
   
  -
  -#if HANDLER_SYNTAX_2_0
  -
  -static const struct handler_parameter make_parameters_ver2[] = {
  -	{ .name = "base" },
  -	{ .name = "param" },
  -	{ .name = NULL }
  +enum {
  +	MAKE_BASE,
  +	MAKE_PARAM,
  +	MAKE_PREFIX,
   };
   
  -static int make_main_ver2(const element_s * const el)
  -{
  -	int status;
  +struct make_data {
   	char *base;
  -	char *command = NULL;
  +	char *param;
  +	int param_seen;
  +	char *prefix;
  +	int prefix_seen;
  +};
   
  -	
  -	base = alloc_base_dir(el);
  +static int make_setup(element_s * const element)
  +{
  +	struct make_data *data;
   
  -	if (change_current_dir(base)) {
  -		xfree(base);
  +	if ((data = xmalloc(sizeof(struct make_data))) == NULL)
   		return -1;
  -	}
   
  -	append_str(&command, "make");
  -	append_param_elements(&command, el);
  +	data->param = xstrdup(" ");
  +	data->param_seen = 0;
  +	data->prefix = xstrdup("");
  +	data->prefix_seen = 0;
  +	data->base = NULL;
  +	element->handler_data = data;
   
  -	Nprint_h("Executing in %s:", base);
  -	Nprint_h("    %s", command);
  +	return 0;
  +}
   
  -	status = execute_command(el, "%s", command);
  +static void make_free(const element_s * const element)
  +{
  +	struct make_data *data = (struct make_data *) element->handler_data;
   
  -	xfree(base);
  -	xfree(command);
  +	xfree(data->base);
  +	xfree(data->prefix);
  +	xfree(data->param);
  +	xfree(data);
  +}
   
  -	return status;
  +static int make_attribute(const element_s * const element,
  +			  const struct handler_attribute * const attr,
  +			  const char * const value)
  +{
  +	struct make_data *data = (struct make_data *) element->handler_data;
  +
  +	switch (attr->private) {
  +	case MAKE_BASE:
  +		if (data->base) {
  +			Nprint_err("<%s>: cannot specify \"base\" more than once.", element->handler->name);
  +			return 1;
  +		}
  +		data->base = xstrdup(value);
  +		return 0;
  +	default:
  +		return 1;
  +	}
   }
   
  -#endif /* HANDLER_SYNTAX_2_0 */
  +static int make_parameter(const element_s * const element,
  +			  const struct handler_parameter * const param,
  +			  const char * const value)
  +{
  +	struct make_data *data = (struct make_data *) element->handler_data;
   
  +	switch (param->private) {
  +	case MAKE_BASE:
  +		if (data->base) {
  +			Nprint_err("<%s>: cannot specify <base> more than once.", element->handler->name);
  +			return 1;
  +		}
  +		data->base = xstrdup(value);
  +		return 0;
  +	case MAKE_PREFIX:
  +		append_str(&data->prefix, value);
  +		append_str(&data->prefix, " ");
  +		data->prefix_seen = 1;
  +		return 0;
  +	case MAKE_PARAM:
  +		append_str(&data->param, value);
  +		append_str(&data->param, " ");
  +		data->param_seen = 1;
  +		return 0;
  +	default:
  +		return 1;
  +	}
  +}
  +
  +#if HANDLER_SYNTAX_2_0
  +
  +static const struct handler_parameter make_parameters_v2[] = {
  +	{ .name = "base", .private = MAKE_BASE },
  +	{ .name = "param", .private = MAKE_PARAM },
  +	{ .name = NULL }
  +};
  +
  +#endif /* HANDLER_SYNTAX_2_0 */
   
   #if HANDLER_SYNTAX_3_0 || HANDLER_SYNTAX_3_1 || HANDLER_SYNTAX_3_2
   
   static const struct handler_parameter make_parameters_v3[] = {
  -	{ .name = "prefix" },
  -	{ .name = "param" },
  +	{ .name = "prefix", .private = MAKE_PREFIX },
  +	{ .name = "param", .private = MAKE_PARAM },
   	{ .name = NULL }
   };
   
   static const struct handler_attribute make_attributes_v3[] = {
  -	{ .name = "base" },
  +	{ .name = "base", .private = MAKE_BASE },
   	{ .name = NULL }
   };
   
  -static int make_main_ver3(const element_s * const el)
  +#endif /* HANDLER_SYNTAX_3_0 || HANDLER_SYNTAX_3_1 || HANDLER_SYNTAX_3_2 */
  +
  +static int make_main(const element_s * const element)
   {
  +	struct make_data *data = (struct make_data *) element->handler_data;
   	int status;
  -	char *command;
   
  -	
  -	if (change_to_base_dir(el, attr_value("base", el), 1))
  +	if (change_to_base_dir(element, data->base, 1))
   		return -1;
  +	
  +	Nprint_h("Executing system command");
  +	Nprint_h("    %s make %s", data->prefix, data->param);
   
  -	command = xstrdup("");
  -
  -	append_prefix_elements(&command, el);
  -
  -	append_str(&command, "make");
  -
  -	append_param_elements(&command, el);
  -
  -	Nprint_h("Executing:");
  -	Nprint_h("    %s", command);
  -
  -	status = execute_command(el, "%s", command);
  -
  -	xfree(command);
  +	status = execute_command(element, "%s make %s", data->prefix, data->param);
   
   	return status;
   }
   
  -#endif /* HANDLER_SYNTAX_3_0 || HANDLER_SYNTAX_3_1 || HANDLER_SYNTAX_3_2 */
  -
  -
   /*
    * Handlers' information.
    */
  @@ -131,49 +182,64 @@
   #if HANDLER_SYNTAX_2_0
   	{
   		.name = "make",
  -		.description = "Run make",
  +		.description = "Make",
   		.syntax_version = "2.0",
  -		.parameters = make_parameters_ver2,
  -		.main = make_main_ver2,
  +		.parameters = make_parameters_v2,
  +		.main = make_main,
   		.type = HTYPE_NORMAL,
   		.is_action = 1,
  +		.setup = make_setup,
  +		.free = make_free,
  +		.parameter = make_parameter,
   	},
   #endif
   #if HANDLER_SYNTAX_3_0
   	{
   		.name = "make",
  -		.description = "Run make",
  +		.description = "Make",
   		.syntax_version = "3.0",
   		.parameters = make_parameters_v3,
   		.attributes = make_attributes_v3,
  -		.main = make_main_ver3,
  +		.main = make_main,
   		.type = HTYPE_NORMAL,
   		.is_action = 1,
  +		.setup = make_setup,
  +		.free = make_free,
  +		.parameter = make_parameter,
  +		.attribute = make_attribute,
   	},
   #endif
   #if HANDLER_SYNTAX_3_1
   	{
   		.name = "make",
  -		.description = "Run make",
  +		.description = "Make",
   		.syntax_version = "3.1",
   		.parameters = make_parameters_v3,
   		.attributes = make_attributes_v3,
  -		.main = make_main_ver3,
  +		.main = make_main,
   		.type = HTYPE_NORMAL,
   		.is_action = 1,
  +		.setup = make_setup,
  +		.free = make_free,
  +		.parameter = make_parameter,
  +		.attribute = make_attribute,
   	},
   #endif
   #if HANDLER_SYNTAX_3_2
   	{
   		.name = "make",
  -		.description = "Run make",
  +		.description = "Make",
   		.syntax_version = "3.2",
   		.parameters = make_parameters_v3,
   		.attributes = make_attributes_v3,
  -		.main = make_main_ver3,
  +		.main = make_main,
   		.type = HTYPE_NORMAL,
   		.is_action = 1,
   		.alternate_shell = 1,
  +		.setup = make_setup,
  +		.free = make_free,
  +		.parameter = make_parameter,
  +		.attribute = make_attribute,
   	},
   #endif
   	{
  
  
  
  1.20      +181 -125  ALFS/nALFS/src/handlers/mkdir.c
  
  Index: mkdir.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/mkdir.c,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- mkdir.c	29 Feb 2004 04:24:59 -0000	1.19
  +++ mkdir.c	3 Mar 2004 03:57:05 -0000	1.20
  @@ -41,185 +41,222 @@
   #include "backend.h"
   
   
  -#define El_mkdir_dirs(el) alloc_trimmed_param_value("dir", el)
  -#define El_mkdir_perm(el) alloc_trimmed_param_value("permissions", el)
  +enum {
  +	MKDIR_OPTION,
  +	MKDIR_BASE,
  +	MKDIR_NAME,
  +	MKDIR_NAMES,
  +	MKDIR_PERMISSIONS,
  +};
   
  +struct mkdir_data {
  +	char *base;
  +	int parents;
  +	char *permissions;
  +	int name_count;
  +	char **names;
  +};
   
  -#if HANDLER_SYNTAX_2_0
  +static int mkdir_setup(element_s * const element)
  +{
  +	struct mkdir_data *data;
   
  -static const struct handler_parameter mkdir_parameters_ver2[] = {
  -	{ .name = "options" },
  -	{ .name = "base" },
  -	{ .name = "dir" },
  -	{ .name = "permissions" },
  -	{ .name = NULL }
  +	if ((data = xmalloc(sizeof(struct mkdir_data))) == NULL)
  +		return 1;
  +
  +	data->parents = 0;
  +	data->base = NULL;
  +	data->name_count = 0;
  +	data->names = NULL;
  +	data->permissions = NULL;
  +	element->handler_data = data;
  +
  +	return 0;
   };
   
  -static int mkdir_main_ver2(const element_s * const el)
  +static void mkdir_free(const element_s * const element)
   {
  -	int status = 0;
  -	int parents = option_exists("parents", el);
  -	char *tok;
  -	char *base;
  -	char *directories;
  -	char *perm;
  -
  +	struct mkdir_data *data = (struct mkdir_data *) element->handler_data;
  +	int i;
   
  -	if ((directories = El_mkdir_dirs(el))== NULL) {
  -		Nprint_h_err("No directories specified.");
  -		return -1;
  +	xfree(data->base);
  +	xfree(data->permissions);
  +	if (data->name_count > 0) {
  +		for (i = 0; i < data->name_count; i++)
  +			xfree(data->names[i]);
  +		xfree(data->names);
   	}
  +	xfree(data);
  +}
   
  -	base = alloc_base_dir(el);
  +static int mkdir_attribute(const element_s * const element,
  +			   const struct handler_attribute * const attr,
  +			   const char * const value)
  +{
  +	struct mkdir_data *data = (struct mkdir_data *) element->handler_data;
   
  -	if (change_current_dir(base)) {
  -		xfree(base);
  -		xfree(directories);
  -		return -1;
  +	switch (attr->private) {
  +	case MKDIR_BASE:
  +		if (data->base) {
  +			Nprint_err("<%s>: cannot specify \"base\" more than once.", element->handler->name);
  +			return 1;
  +		}
  +		data->base = xstrdup(value);
  +		return 0;
  +	default:
  +		return 1;
   	}
  +}
   
  -	perm = El_mkdir_perm(el);
  +static int mkdir_parameter(const element_s * const element,
  +			   const struct handler_parameter * const param,
  +			   const char * const value)
  +{
  +	struct mkdir_data *data = (struct mkdir_data *) element->handler_data;
  +	char *tmp;
  +	char *tok;
   
  -	for (tok = strtok(directories, WHITE_SPACE); tok;
  -	     tok = strtok(NULL, WHITE_SPACE)) {
  -		if (perm) {
  -			Nprint_h("Creating directory in %s%s: %s (%s)",
  -				base, parents ? " (parents)" : "", tok, perm);
  -		} else {
  -			Nprint_h("Creating directory in %s%s: %s",
  -				base, parents ? " (parents)" : "", tok);
  +	switch (param->private) {
  +	case MKDIR_BASE:
  +		if (data->base) {
  +			Nprint_err("<%s>: cannot specify <base> more than once.", element->handler->name);
  +			return 1;
   		}
  -
  -		if (parents) {
  -			status = execute_command(el, "mkdir -p %s", tok);
  -		} else {
  -			status = execute_command(el, "mkdir %s", tok);
  +		data->base = xstrdup(value);
  +		return 0;
  +	case MKDIR_PERMISSIONS:
  +		if (data->permissions) {
  +			Nprint_err("<%s>: cannot specify <permissions> more than once.", element->handler->name);
  +			return 1;
   		}
  -
  -		if (status) {
  -			Nprint_h_err("Creating %s failed.", tok);
  -			break;
  +		data->permissions = xstrdup(value);
  +		return 0;
  +	case MKDIR_OPTION:
  +		if (!strcmp("parents", value)) {
  +			data->parents = 1;
  +			return 0;
   		}
  -
  -		if (! perm) {
  -			continue;
  +		Nprint_err("<%s>: invalid option (%s) ignored", element->handler->name, value);
  +		return 1;
  +	case MKDIR_NAME:
  +		data->name_count++;
  +		if ((data->names = xrealloc(data->names,
  +					    sizeof(data->names[0]) * (data->name_count))) == NULL) {
  +			Nprint_err("xrealloc() failed: %s", strerror(errno));
  +			return -1;
   		}
  -
  -		/* Change permissions. */
  -		if ((status = execute_command(el, "chmod %s %s", perm, tok))) {
  -			Nprint_h_err("Changing permissions failed.");
  -			break;
  +		data->names[(data->name_count - 1)] = xstrdup(value);
  +		return 0;
  +	case MKDIR_NAMES:
  +		tmp = xstrdup(value);
  +		for (tok = strtok(tmp, WHITE_SPACE); tok; tok = strtok(NULL, WHITE_SPACE)) {
  +			data->name_count++;
  +			if ((data->names = xrealloc(data->names,
  +						    sizeof(data->names[0]) * (data->name_count))) == NULL) {
  +				Nprint_err("xrealloc() failed: %s", strerror(errno));
  +				return -1;
  +			}
  +			data->names[(data->name_count - 1)] = xstrdup(value);
   		}
  +		xfree(tmp);
  +	default:
  +		return 1;
   	}
  +}
   
  -	xfree(base);
  -	xfree(directories);
  -	xfree(perm);
  -	
  -	return status;
  +#if HANDLER_SYNTAX_2_0
  +
  +static const struct handler_parameter mkdir_parameters_ver2[] = {
  +	{ .name = "options", .private = MKDIR_OPTION },
  +	{ .name = "base", .private = MKDIR_BASE },
  +	{ .name = "dir", .private = OPTION_NAMES },
  +	{ .name = "permissions", .private = OPTION_PERMISSIONS },
  +	{ .name = NULL }
  +};
  +
  +static int mkdir_valid_data_v2(const element_s * const element)
  +{
  +	struct mkdir_data *data = (struct mkdir_data *) element->handler_data;
  +
  +	if (data->name_count == 0) {
  +		Nprint_err("<%s>: \"dir\" must be specified.", element->handler->name);
  +		return 0;
  +	}
  +
  +	return 1;
   }
   
   #endif /* HANDLER_SYNTAX_2_0 */
   
  -
   #if HANDLER_SYNTAX_3_0 || HANDLER_SYNTAX_3_1 || HANDLER_SYNTAX_3_2
   
   static const struct handler_parameter mkdir_parameters_v3[] = {
  -	{ .name = "option" },
  -	{ .name = "name" },
  -	{ .name = "permissions" },
  +	{ .name = "option", .private = MKDIR_OPTION },
  +	{ .name = "name", .private = MKDIR_NAME },
  +	{ .name = "permissions", .private = MKDIR_PERMISSIONS },
   	{ .name = NULL }
   };
   
   static const struct handler_attribute mkdir_attributes_v3[] = {
  -	{ .name = "base" },
  +	{ .name = "base", .private = MKDIR_BASE },
   	{ .name = NULL }
   };
   
  -static int mkdir_main_ver3(const element_s * const el)
  +static int mkdir_valid_data_v3(const element_s * const element)
   {
  -	int options[1], parents;
  -	int status = 0;
  -	char *perm;
  -	element_s *p;
  +	struct mkdir_data *data = (struct mkdir_data *) element->handler_data;
   
  -	if (change_to_base_dir(el, attr_value("base", el), 1))
  -		return -1;
  -
  -	check_options(1, options, "parents", el);
  -	parents = options[0];
  -
  -	if ((first_param("name", el)) == NULL) {
  -		Nprint_h_err("No directories specified.");
  -		return -1;
  +	if (data->name_count == 0) {
  +		Nprint_err("<%s>: <name> must be specified.", element->handler->name);
  +		return 0;
   	}
   
  -	perm = alloc_trimmed_param_value("permissions", el);
  -
  -	for (p = first_param("name", el); p; p = next_param(p)) {
  -		char *dir;
  -		char *command, *message;
  +	return 1;
  +}
   
  +#endif /* HANDLER_SYNTAX_3_0 || HANDLER_SYNTAX_3_1 || HANDLER_SYNTAX_3_2 */
   
  -		if ((dir = alloc_trimmed_str(p->content)) == NULL) {
  -			Nprint_h_warn("Directory name empty, ignoring.");
  -			continue;
  -		}
  +static int mkdir_main(const element_s * const element)
  +{
  +	struct mkdir_data *data = (struct mkdir_data *) element->handler_data;
  +	int status = 0;
  +	int i;
   
  -		command = xstrdup("mkdir ");
  -		message = xstrdup("Creating directory");
  +	if (change_to_base_dir(element, data->base, 1))
  +		return -1;
   
  -		if (parents) {
  -			append_str(&command, " -p ");
  -			append_str(&message, " (parents)");
  +	for (i = 0; i < data->name_count; i++) {
  +		if (data->permissions) {
  +			Nprint_h("Creating directory %s%s: (%s)",
  +				 data->names[i], data->parents ? " (parents)" : "",
  +				 data->permissions);
  +		} else {
  +			Nprint_h("Creating directory %s%s",
  +				 data->names[i], data->parents ? " (parents)" : "");
   		}
   
  -		append_str(&command, dir);
  +		status = execute_command(element, "mkdir %s %s",
  +					 data->parents ? "-p" : "", data->names[i]);
   
  -		append_str(&message, ": ");
  -		append_str(&message, dir);
  -
  -		if (perm) {
  -			append_str(&message, " (");
  -			append_str(&message, perm);
  -			append_str(&message, ")");
  -		}
  -		
  -		Nprint_h("%s", message);
  -
  -		if ((status = execute_command(el, "%s", command))) {
  -			Nprint_h_err("Creating %s failed.", dir);
  -			xfree(dir);
  -			xfree(command);
  -			xfree(message);
  +		if (status) {
  +			Nprint_h_err("Creation failed.");
   			break;
   		}
   
  -		if (perm) {
  +		if (data->permissions) {
   			/* Change permissions. */
  -			if ((status = execute_command(el, "chmod %s %s",
  -			perm, dir))) {
  +			if ((status = execute_command(element, "chmod %s %s",
  +						      data->permissions,
  +						      data->names[i]))) {
   				Nprint_h_err("Changing permissions failed.");
  -				xfree(dir);
  -				xfree(command);
  -				xfree(message);
   				break;
   			}
   		}
  -
  -		xfree(dir);
  -		xfree(command);
  -		xfree(message);
   	}
   
  -	xfree(perm);
  -	
   	return status;
   }
   
  -#endif /* HANDLER_SYNTAX_3_0 || HANDLER_SYNTAX_3_1 || HANDLER_SYNTAX_3_2 */
  -
  -
   /*
    * Handlers' information.
    */
  @@ -231,9 +268,13 @@
   		.description = "Make directories",
   		.syntax_version = "2.0",
   		.parameters = mkdir_parameters_ver2,
  -		.main = mkdir_main_ver2,
  +		.main = mkdir_main,
   		.type = HTYPE_NORMAL,
   		.is_action = 1,
  +		.setup = mkdir_setup,
  +		.free = mkdir_free,
  +		.parameter = mkdir_parameter,
  +		.valid_data = mkdir_valid_data_v2,
   	},
   #endif
   #if HANDLER_SYNTAX_3_0
  @@ -243,9 +284,14 @@
   		.syntax_version = "3.0",
   		.parameters = mkdir_parameters_v3,
   		.attributes = mkdir_attributes_v3,
  -		.main = mkdir_main_ver3,
  +		.main = mkdir_main,
   		.type = HTYPE_NORMAL,
   		.is_action = 1,
  +		.setup = mkdir_setup,
  +		.free = mkdir_free,
  +		.parameter = mkdir_parameter,
  +		.attribute = mkdir_attribute,
  +		.valid_data = mkdir_valid_data_v3,
   	},
   #endif
   #if HANDLER_SYNTAX_3_1
  @@ -255,9 +301,14 @@
   		.syntax_version = "3.1",
   		.parameters = mkdir_parameters_v3,
   		.attributes = mkdir_attributes_v3,
  -		.main = mkdir_main_ver3,
  +		.main = mkdir_main,
   		.type = HTYPE_NORMAL,
   		.is_action = 1,
  +		.setup = mkdir_setup,
  +		.free = mkdir_free,
  +		.parameter = mkdir_parameter,
  +		.attribute = mkdir_attribute,
  +		.valid_data = mkdir_valid_data_v3,
   	},
   #endif
   #if HANDLER_SYNTAX_3_2
  @@ -267,10 +318,15 @@
   		.syntax_version = "3.2",
   		.parameters = mkdir_parameters_v3,
   		.attributes = mkdir_attributes_v3,
  -		.main = mkdir_main_ver3,
  +		.main = mkdir_main,
   		.type = HTYPE_NORMAL,
   		.is_action = 1,
   		.alternate_shell = 1,
  +		.setup = mkdir_setup,
  +		.free = mkdir_free,
  +		.parameter = mkdir_parameter,
  +		.attribute = mkdir_attribute,
  +		.valid_data = mkdir_valid_data_v3,
   	},
   #endif
   	{
  
  
  
  1.20      +173 -103  ALFS/nALFS/src/handlers/move.c
  
  Index: move.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/move.c,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- move.c	29 Feb 2004 04:24:59 -0000	1.19
  +++ move.c	3 Mar 2004 03:57:05 -0000	1.20
  @@ -41,149 +41,200 @@
   #include "backend.h"
   
   
  -#define El_move_source(el) alloc_trimmed_param_value("source", el)
  -#define El_move_destination(el) alloc_trimmed_param_value("destination", el)
  +enum {
  +	MOVE_BASE,
  +	MOVE_OPTION,
  +	MOVE_SOURCES,
  +	MOVE_SOURCE,
  +	MOVE_DESTINATION,
  +};
   
  +struct move_data {
  +	char *base;
  +	int force;
  +	char *destination;
  +	int source_count;
  +	char **sources;
  +};
   
  -#if HANDLER_SYNTAX_2_0
  +static int move_setup(element_s * const element)
  +{
  +	struct move_data *data;
   
  -static const struct handler_parameter move_parameters_ver2[] = {
  -	{ .name = "base" },
  -	{ .name = "options" },
  -	{ .name = "source" },
  -	{ .name = "destination" },
  -	{ .name = NULL }
  +	if ((data = xmalloc(sizeof(struct move_data))) == NULL)
  +		return 1;
  +
  +	data->force = 0;
  +	data->base = NULL;
  +	data->source_count = 0;
  +	data->sources = NULL;
  +	data->destination = NULL;
  +	element->handler_data = data;
  +
  +	return 0;
   };
   
  -static int move_main_ver2(const element_s * const el)
  +static void move_free(const element_s * const element)
   {
  -	int status = 0;
  -	int force = option_exists("force", el);
  -	char *tok;
  -	char *base;
  -	char *source;
  -	char *destination;
  -
  +	struct move_data *data = (struct move_data *) element->handler_data;
  +	int i;
   
  -	if ((source = El_move_source(el))== NULL) {
  -		Nprint_h_err("No source files specified.");
  -		return -1;
  -	}
  -	
  -	if ((destination = El_move_destination(el))== NULL) {
  -		Nprint_h_err("No destination specified.");
  -		xfree(source);
  -		return -1;
  +	xfree(data->base);
  +	xfree(data->destination);
  +	if (data->source_count > 0) {
  +		for (i = 0; i < data->source_count; i++)
  +			xfree(data->sources[i]);
  +		xfree(data->sources);
   	}
  +	xfree(data);
  +}
   
  -	base = alloc_base_dir(el);
  +static int move_attribute(const element_s * const element,
  +			  const struct handler_attribute * const attr,
  +			  const char * const value)
  +{
  +	struct move_data *data = (struct move_data *) element->handler_data;
   
  -	if (change_current_dir(base)) {
  -		xfree(base);
  -		xfree(source);
  -		xfree(destination);
  -		return -1;
  +	switch (attr->private) {
  +	case MOVE_BASE:
  +		if (data->base) {
  +			Nprint_err("<%s>: cannot specify \"base\" more than once.", element->handler->name);
  +			return 1;
  +		}
  +		data->base = xstrdup(value);
  +		return 0;
  +	default:
  +		return 1;
   	}
  +}
   
  -	for (tok = strtok(source, WHITE_SPACE); tok;
  -	     tok = strtok(NULL, WHITE_SPACE)) {
  -		Nprint_h("Moving from %s to %s%s: %s",
  -			base, destination, force ? " (force)" : "", tok);
  -
  -		if (force) {
  -			status = execute_command(el, "mv -f %s %s", tok, destination);
  -		} else {
  -			status = execute_command(el, "mv %s %s", tok, destination);
  -		}
  +static int move_parameter(const element_s * const element,
  +			  const struct handler_parameter * const param,
  +			  const char * const value)
  +{
  +	struct move_data *data = (struct move_data *) element->handler_data;
  +	char *tmp;
  +	char *tok;
   
  -		if (status) {
  -			Nprint_h_err("Moving failed.");
  -			break;
  +	switch (param->private) {
  +	case MOVE_BASE:
  +		if (data->base) {
  +			Nprint_err("<%s>: cannot specify <base> more than once.", element->handler->name);
  +			return 1;
  +		}
  +		data->base = xstrdup(value);
  +		return 0;
  +	case MOVE_DESTINATION:
  +		if (data->destination) {
  +			Nprint_err("<%s>: cannot specify <destination> more than once.", element->handler->name);
  +			return 1;
  +		}
  +		data->destination = xstrdup(value);
  +		return 0;
  +	case MOVE_OPTION:
  +		if (!strcmp("force", value)) {
  +			data->force = 1;
  +			return 0;
   		}
  +		Nprint_err("<%s>: invalid option (%s) ignored", element->handler->name, value);
  +		return 1;
  +	case MOVE_SOURCE:
  +		data->source_count++;
  +		if ((data->sources = xrealloc(data->sources,
  +					      sizeof(data->sources[0]) * (data->source_count))) == NULL) {
  +			Nprint_err("xrealloc() failed: %s", strerror(errno));
  +			return -1;
  +		}
  +		data->sources[(data->source_count - 1)] = xstrdup(value);
  +		return 0;
  +	case MOVE_SOURCES:
  +		tmp = xstrdup(value);
  +		for (tok = strtok(tmp, WHITE_SPACE); tok; tok = strtok(NULL, WHITE_SPACE)) {
  +			data->source_count++;
  +			if ((data->sources = xrealloc(data->sources,
  +						      sizeof(data->sources[0]) * (data->source_count))) == NULL) {
  +				Nprint_err("xrealloc() failed: %s", strerror(errno));
  +				return -1;
  +			}
  +			data->sources[(data->source_count - 1)] = xstrdup(value);
  +		}
  +		xfree(tmp);
  +	default:
  +		return 1;
   	}
  +}
   
  -	xfree(base);
  -	xfree(source);
  -	xfree(destination);
  -	
  -	return status;
  +static int move_valid_data(const element_s * const element)
  +{
  +	struct move_data *data = (struct move_data *) element->handler_data;
  +
  +	if (data->source_count == 0) {
  +		Nprint_err("<%s>: <source> must be specified.", element->handler->name);
  +		return 0;
  +	}
  +
  +	if (!data->destination) {
  +		Nprint_err("<%s>: <destination> must be specified.", element->handler->name);
  +		return 0;
  +	}
  +
  +	return 1;
   }
   
  -#endif /* HANDLER_SYNTAX_2_0 */
  +#if HANDLER_SYNTAX_2_0
   
  +static const struct handler_parameter move_parameters_v2[] = {
  +	{ .name = "base", .private = MOVE_BASE },
  +	{ .name = "options", .private = MOVE_OPTION },
  +	{ .name = "source", .private = MOVE_SOURCES },
  +	{ .name = "destination", .private = MOVE_DESTINATION },
  +	{ .name = NULL }
  +};
  +
  +#endif /* HANDLER_SYNTAX_2_0 */
   
   #if HANDLER_SYNTAX_3_0 || HANDLER_SYNTAX_3_1 || HANDLER_SYNTAX_3_2
   
   static const struct handler_parameter move_parameters_v3[] = {
  -	{ .name = "option" },
  -	{ .name = "source" },
  -	{ .name = "destination" },
  +	{ .name = "option", .private = MOVE_OPTION },
  +	{ .name = "source", .private = MOVE_SOURCE },
  +	{ .name = "destination", .private = MOVE_DESTINATION },
   	{ .name = NULL }
   };
   
   static const struct handler_attribute move_attributes_v3[] = {
  -	{ .name = "base" },
  +	{ .name = "base", .private = MOVE_BASE },
   	{ .name = NULL }
   };
   
  -static int move_main_ver3(const element_s * const el)
  +#endif /* HANDLER_SYNTAX_3_0 || HANDLER_SYNTAX_3_1 || HANDLER_SYNTAX_3_2 */
  +
  +static int move_main(const element_s * const element)
   {
  -	int options[1], force;
  +	struct move_data *data = (struct move_data *) element->handler_data;
   	int status = 0;
  -	char *destination;
  -	element_s *p;
  -
  +	int i;
   
  -	if (change_to_base_dir(el, attr_value("base", el), 1))
  +	if (change_to_base_dir(element, data->base, 1))
   		return -1;
   
  -	check_options(1, options, "force", el);
  -	force = options[0];
  -
  -	if (first_param("source", el) == NULL) {
  -		Nprint_h_err("No source files specified.");
  -		return -1;
  -	}
  -
  -	destination = alloc_trimmed_param_value("destination", el);
  -	if (destination == NULL) {
  -		Nprint_h_err("No destination specified.");
  -		return -1;
  -	}
  -
  -	for (p = first_param("source", el); p; p = next_param(p)) {
  -		char *s;
  -
  -		if ((s = alloc_trimmed_str(p->content)) == NULL) {
  -			Nprint_h_warn("Source empty.");
  -			continue;
  -		}
  -
  -		Nprint_h("Moving to %s%s: %s",
  -			destination, force ? " (force)" : "", s);
  -
  -		if (force) {
  -			status = execute_command(el, "mv -f %s %s", s, destination);
  -		} else {
  -			status = execute_command(el, "mv %s %s", s, destination);
  -		}
  -
  -		xfree(s);
  +	for (i = 0; i < data->source_count; i++) {
  +		Nprint_h("Moving from %s to %s%s",
  +			 data->sources[i], data->destination, data->force ? " (force)" : "");
  +
  +		status = execute_command(element, "mv %s %s %s",
  +					 data->force ? "-f" : "",
  +					 data->sources[i], data->destination);
   
   		if (status) {
   			Nprint_h_err("Moving failed.");
   			break;
   		}
   	}
  -
  -	xfree(destination);
   	
   	return status;
   }
   
  -#endif /* HANDLER_SYNTAX_3_0 || HANDLER_SYNTAX_3_1 || HANDLER_SYNTAX_3_2 */
  -
  -
   /*
    * Handlers' information.
    */
  @@ -194,10 +245,14 @@
   		.name = "move",
   		.description = "Move files",
   		.syntax_version = "2.0",
  -		.parameters = move_parameters_ver2,
  -		.main = move_main_ver2,
  +		.parameters = move_parameters_v2,
  +		.main = move_main,
   		.type = HTYPE_NORMAL,
   		.is_action = 1,
  +		.setup = move_setup,
  +		.free = move_free,
  +		.valid_data = move_valid_data,
  +		.parameter = move_parameter,
   	},
   #endif
   #if HANDLER_SYNTAX_3_0
  @@ -207,9 +262,14 @@
   		.syntax_version = "3.0",
   		.parameters = move_parameters_v3,
   		.attributes = move_attributes_v3,
  -		.main = move_main_ver3,
  +		.main = move_main,
   		.type = HTYPE_NORMAL,
   		.is_action = 1,
  +		.setup = move_setup,
  +		.free = move_free,
  +		.valid_data = move_valid_data,
  +		.parameter = move_parameter,
  +		.attribute = move_attribute,
   	},
   #endif
   #if HANDLER_SYNTAX_3_1
  @@ -219,9 +279,14 @@
   		.syntax_version = "3.1",
   		.parameters = move_parameters_v3,
   		.attributes = move_attributes_v3,
  -		.main = move_main_ver3,
  +		.main = move_main,
   		.type = HTYPE_NORMAL,
   		.is_action = 1,
  +		.setup = move_setup,
  +		.free = move_free,
  +		.valid_data = move_valid_data,
  +		.attribute = move_attribute,
  +		.parameter = move_parameter,
   	},
   #endif
   #if HANDLER_SYNTAX_3_2
  @@ -231,10 +296,15 @@
   		.syntax_version = "3.2",
   		.parameters = move_parameters_v3,
   		.attributes = move_attributes_v3,
  -		.main = move_main_ver3,
  +		.main = move_main,
   		.type = HTYPE_NORMAL,
   		.is_action = 1,
   		.alternate_shell = 1,
  +		.setup = move_setup,
  +		.free = move_free,
  +		.valid_data = move_valid_data,
  +		.parameter = move_parameter,
  +		.attribute = move_attribute,
   	},
   #endif
   	{
  
  
  
  1.19      +149 -119  ALFS/nALFS/src/handlers/owner.c
  
  Index: owner.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/owner.c,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- owner.c	29 Feb 2004 04:24:59 -0000	1.18
  +++ owner.c	3 Mar 2004 03:57:05 -0000	1.19
  @@ -41,150 +41,176 @@
   #include "parser.h"
   #include "backend.h"
   
  +enum {
  +	OWNER_OPTIONS,
  +	OWNER_NAMES,
  +	OWNER_BASE,
  +	OWNER_USER,
  +	OWNER_GROUP,
  +};
   
  -#define El_owner_user(el) alloc_trimmed_param_value("user", el)
  -#define El_owner_group(el) alloc_trimmed_param_value("group", el)
  -#define El_owner_targets(el) alloc_trimmed_param_value("name", el)
  -
  -
  -#if HANDLER_SYNTAX_2_0
  +struct owner_data {
  +	char *base;
  +	char *user;
  +	char *group;
  +	int recursive;
  +	int name_count;
  +	char **names;
  +};
   
   static const struct handler_parameter owner_parameters[] = {
  -	{ .name = "options" },
  -	{ .name = "name" },
  -	{ .name = "base" },
  -	{ .name = "user" },
  -	{ .name = "group" },
  +	{ .name = "options", .private = OWNER_OPTIONS },
  +	{ .name = "name", .private = OWNER_NAMES },
  +	{ .name = "base", .private = OWNER_BASE },
  +	{ .name = "user", .private = OWNER_USER },
  +	{ .name = "group", .private = OWNER_GROUP },
   	{ .name = NULL }
   };
   
  -static int owner_main(const element_s * const el)
  +static int owner_setup(element_s * const element)
   {
  -	int status = 0;
  -	int recursive = option_exists("recursive", el);
  -	char *tok;
  -	char *base;
  -	char *user;
  -	char *group;
  -	char *targets;
  -	char *command = NULL;
  -	char *message = NULL;
  +	struct owner_data *data;
   
  +	if ((data = xmalloc(sizeof(struct owner_data))) == NULL)
  +		return 1;
   
  -	user = El_owner_user(el);
  -	group = El_owner_group(el);
  -
  -	if ((user == NULL) && (group == NULL)) {
  -		Nprint_h_err("No user and/or group specified.");
  -		xfree(user);
  -		xfree(group);
  -		return -1;
  -	}
  +	data->recursive = 0;
  +	data->base = NULL;
  +	data->name_count = 0;
  +	data->names = NULL;
  +	data->user = NULL;
  +	data->group = NULL;
  +	element->handler_data = data;
   
  -	if ((targets = El_owner_targets(el)) == NULL) {
  -		Nprint_h_err("No targets specified.");
  -		xfree(user);
  -		xfree(group);
  -		return -1;
  +	return 0;
  +};
  +
  +static void owner_free(const element_s * const element)
  +{
  +	struct owner_data *data = (struct owner_data *) element->handler_data;
  +	int i;
  +
  +	xfree(data->base);
  +	xfree(data->user);
  +	xfree(data->group);
  +	if (data->name_count > 0) {
  +		for (i = 0; i < data->name_count; i++)
  +			xfree(data->names[i]);
  +		xfree(data->names);
   	}
  +	xfree(data);
  +}
   
  -	base = alloc_base_dir(el);
  +static int owner_parameter(const element_s * const element,
  +			   const struct handler_parameter * const param,
  +			   const char * const value)
  +{
  +	struct owner_data *data = (struct owner_data *) element->handler_data;
  +	char *tmp;
  +	char *tok;
   
  -	if (change_current_dir(base)) {
  -		xfree(base);
  -		xfree(targets);
  -		xfree(user);
  -		xfree(group);
  +	switch (param->private) {
  +	case OWNER_BASE:
  +		if (data->base) {
  +			Nprint_err("<%s>: cannot specify <base> more than once.", element->handler->name);
  +			return 1;
  +		}
  +		data->base = xstrdup(value);
  +		return 0;
  +	case OWNER_USER:
  +		if (data->user) {
  +			Nprint_err("<%s>: cannot specify <user> more than once.", element->handler->name);
  +			return 1;
  +		}
  +		data->user = xstrdup(value);
  +		return 0;
  +	case OWNER_GROUP:
  +		if (data->group) {
  +			Nprint_err("<%s>: cannot specify <group> more than once.", element->handler->name);
  +			return 1;
  +		}
  +		data->group = xstrdup(value);
  +		return 0;
  +	case OWNER_OPTION:
  +		if (!strcmp("recursive", value)) {
  +			data->recursive = 1;
  +			return 0;
  +		}
  +		Nprint_err("<%s>: invalid option (%s) ignored", element->handler->name, value);
  +		return 1;
  +	case OWNER_NAMES:
  +		tmp = xstrdup(value);
  +		for (tok = strtok(tmp, WHITE_SPACE); tok; tok = strtok(NULL, WHITE_SPACE)) {
  +			data->name_count++;
  +			if ((data->names = xrealloc(data->names,
  +						    sizeof(data->names[0]) * (data->name_count))) == NULL) {
  +				Nprint_err("xrealloc() failed: %s", strerror(errno));
  +				return -1;
  +			}
  +			data->names[(data->name_count - 1)] = xstrdup(value);
  +		}
  +		xfree(tmp);
  +	default:
  +		return 1;
  +	}
  +}
   
  -		return -1;
  +static int owner_valid_data(const element_s * const element)
  +{
  +	struct owner_data *data = (struct owner_data *) element->handler_data;
  +
  +	if (data->name_count == 0) {
  +		Nprint_err("<%s>: <name> must be specified.", element->handler->name);
  +		return 0;
   	}
   
  -	for (tok = strtok(targets, WHITE_SPACE); tok;
  -	     tok = strtok(NULL, WHITE_SPACE)) {
  -		if ((user != NULL) && (group != NULL)) {
  -			append_str(&command, "chown ");
  -
  -			append_str(&message, "Changing ownership to ");
  -			append_str(&message, user);
  -			append_str(&message, ":");
  -			append_str(&message, group);
  -			append_str(&message, " ");
  -			if (recursive) {
  -				append_str(&command, "-R ");
  -				append_str(&message, "(recursive) ");
  -			}
  -			append_str(&message, "in ");
  -			append_str(&message, base);
  -			append_str(&message, ": ");
  -			append_str(&message, tok);
  -
  -			append_str(&command, user);
  -			append_str(&command, ":");
  -			append_str(&command, group);
  -		} else if (user != NULL) {
  -			append_str(&command, "chown ");
  -
  -			append_str(&message, "Changing user ownership to ");
  -			append_str(&message, user);
  -			append_str(&message, " ");
  -			if (recursive) {
  -				append_str(&command, "-R ");
  -				append_str(&message, "(recursive) ");
  -			}
  -			append_str(&message, "in ");
  -			append_str(&message, base);
  -			append_str(&message, ": ");
  -			append_str(&message, tok);
  -
  -			append_str(&command, user);
  -		} else {   /* group != NULL */
  -			append_str(&command, "chgrp ");
  -
  -			append_str(&message, "Changing group ownership to ");
  -			append_str(&message, group);
  -			append_str(&message, " ");
  -			if (recursive) {
  -				append_str(&command, "-R ");
  -				append_str(&message, "(recursive) ");
  -			}
  -			append_str(&message, "in ");
  -			append_str(&message, base);
  -			append_str(&message, ": ");
  -			append_str(&message, tok);
  +	if (!(data->user || data->group)) {
  +		Nprint_err("<%s>: <user> or <group> must be specified.", element->handler->name);
  +		return 0;
  +	}
   
  -			append_str(&command, group);
  -		}
  +	return 1;
  +}
   
  -		append_str(&command, " ");
  -		append_str(&command, tok);
  +static int owner_main(const element_s * const element)
  +{
  +	struct owner_data *data = (struct owner_data *) element->handler_data;
  +	int status = 0;
  +	int i;
   
  -		Nprint_h("%s", message);
  +	if (change_to_base_dir(element, data->base, 1))
  +		return -1;
   
  -		if ((status = execute_command(el, command))) {
  -			Nprint_h_err("Changing ownership failed.");
  -			break;
  +	if (data->user) {
  +		for (i = 0; i < data->name_count; i++) {
  +			Nprint_h("Changing user ownership to %s%s: %s", data->user,
  +				 data->recursive ? "(recursive)" : " ", data->names[i]);
  +			status = execute_command(element, "chown %s %s %s",
  +						 data->recursive ? "-R" : "",
  +						 data->user, data->names[i]);
  +			if (status) {
  +				Nprint_h_err("Changing ownership failed.");
  +				break;
  +			}
   		}
  -
  -		xfree(command);
  -		command = NULL;
  -		xfree(message);
  -		message = NULL;
   	}
   
  -	xfree(command);
  -	xfree(message);
  -
  -	xfree(base);
  -	xfree(targets);
  -	xfree(user);
  -	xfree(group);
  -	
  +	if ((status == 0) && data->group) {
  +		for (i = 0; i < data->name_count; i++) {
  +			Nprint_h("Changing group ownership to %s%s: %s", data->group,
  +				 data->recursive ? "(recursive)" : " ", data->names[i]);
  +			status = execute_command(element, "chgrp %s %s %s",
  +						 data->recursive ? "-R" : "",
  +						 data->group, data->names[i]);
  +			if (status) {
  +				Nprint_h_err("Changing ownership failed.");
  +				break;
  +			}
  +		}
  +	}
   	return status;
   }
   
  -#endif /* HANDLER_SYNTAX_2_0 */
  -
  -
   /*
    * Handlers' information.
    */
  @@ -200,7 +226,11 @@
   		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
  -		.priority = 0
  +		.priority = 0,
  +		.setup = owner_setup,
  +		.free = owner_free,
  +		.parameter = owner_parameter,
  +		.valid_data = owner_valid_data,
   	},
   #endif
   	{
  
  
  
  1.18      +157 -86   ALFS/nALFS/src/handlers/ownership.c
  
  Index: ownership.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/ownership.c,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- ownership.c	29 Feb 2004 04:24:59 -0000	1.17
  +++ ownership.c	3 Mar 2004 03:57:05 -0000	1.18
  @@ -24,6 +24,9 @@
   
   
   #include <stdlib.h>
  +#include <string.h>
  +#include <unistd.h>
  +#include <errno.h>
   
   #ifdef HAVE_CONFIG_H
   #include <config.h>
  @@ -38,134 +41,187 @@
   #include "parser.h"
   #include "backend.h"
   
  +enum {
  +	OWNERSHIP_OPTION,
  +	OWNERSHIP_NAME,
  +	OWNERSHIP_BASE,
  +	OWNERSHIP_USER,
  +	OWNERSHIP_GROUP,
  +};
   
  -#if HANDLER_SYNTAX_3_0 || HANDLER_SYNTAX_3_1 || HANDLER_SYNTAX_3_2
  +struct ownership_data {
  +	char *base;
  +	char *user;
  +	char *group;
  +	int recursive;
  +	int name_count;
  +	char **names;
  +};
   
   static const struct handler_parameter ownership_parameters[] = {
  -	{ .name = "option" },
  -	{ .name = "name" },
  +	{ .name = "option", .private = OWNERSHIP_OPTION },
  +	{ .name = "name", .private = OWNERSHIP_NAME },
   	{ .name = NULL }
   };
   
   static const struct handler_attribute ownership_attributes[] = {
  -	{ .name = "base" },
  -	{ .name = "user" },
  -	{ .name = "group" },
  +	{ .name = "base", .private = OWNERSHIP_BASE },
  +	{ .name = "user", .private = OWNERSHIP_USER },
  +	{ .name = "group", .private = OWNERSHIP_GROUP },
   	{ .name = NULL }
   };
   
  -static int ownership_main(const element_s *const el)
  +static int ownership_setup(element_s * const element)
   {
  -	int status = 0;
  -	int options[1], recursive;
  -	char *user, *group;
  -	element_s *p;
  +	struct ownership_data *data;
   
  +	if ((data = xmalloc(sizeof(struct ownership_data))) == NULL)
  +		return 1;
   
  -	if (change_to_base_dir(el, attr_value("base", el), 1))
  -		return -1;
  +	data->recursive = 0;
  +	data->base = NULL;
  +	data->name_count = 0;
  +	data->names = NULL;
  +	data->user = NULL;
  +	data->group = NULL;
  +	element->handler_data = data;
   
  -	check_options(1, options, "recursive", el);
  -	recursive = options[0];
  +	return 0;
  +};
   
  -	user = attr_value("user", el);
  -	group = attr_value("group", el);
  +static void ownership_free(const element_s * const element)
  +{
  +	struct ownership_data *data = (struct ownership_data *) element->handler_data;
  +	int i;
   
  -	if (user == NULL && group == NULL) {
  -		Nprint_h_err("No user and/or group specified.");
  -		return -1;
  +	xfree(data->base);
  +	xfree(data->user);
  +	xfree(data->group);
  +	if (data->name_count > 0) {
  +		for (i = 0; i < data->name_count; i++)
  +			xfree(data->names[i]);
  +		xfree(data->names);
   	}
  +	xfree(data);
  +}
   
  -	for (p = first_param("name", el); p; p = next_param(p)) {
  -		char *s;
  -
  +static int ownership_attribute(const element_s * const element,
  +			       const struct handler_attribute * const attr,
  +			       const char * const value)
  +{
  +	struct ownership_data *data = (struct ownership_data *) element->handler_data;
   
  -		if ((s = alloc_trimmed_str(p->content)) == NULL) {
  -			Nprint_h_warn("Name empty.");
  -			continue;
  +	switch (attr->private) {
  +	case OWNERSHIP_BASE:
  +		if (data->base) {
  +			Nprint_err("<%s>: cannot specify \"base\" more than once.", element->handler->name);
  +			return 1;
   		}
  +		data->base = xstrdup(value);
  +		return 0;
  +	case OWNERSHIP_USER:
  +		if (data->user) {
  +			Nprint_err("<%s>: cannot specify \"user\" more than once.", element->handler->name);
  +			return 1;
  +		}
  +		data->user = xstrdup(value);
  +		return 0;
  +	case OWNERSHIP_GROUP:
  +		if (data->group) {
  +			Nprint_err("<%s>: cannot specify \"group\" more than once.", element->handler->name);
  +			return 1;
  +		}
  +		data->group = xstrdup(value);
  +		return 0;
  +	default:
  +		return 1;
  +	}
  +}
   
  -		if (user) {
  -			char *command = NULL;
  -			char *message = NULL;
  +static int ownership_parameter(const element_s * const element,
  +				 const struct handler_parameter * const param,
  +				 const char * const value)
  +{
  +	struct ownership_data *data = (struct ownership_data *) element->handler_data;
   
  +	switch (param->private) {
  +	case OWNERSHIP_OPTION:
  +		if (!strcmp("recursive", value)) {
  +			data->recursive = 1;
  +			return 0;
  +		}
  +		Nprint_err("<%s>: invalid option (%s) ignored", element->handler->name, value);
  +		return 1;
  +	case OWNERSHIP_NAME:
  +		data->name_count++;
  +		if ((data->names = xrealloc(data->names,
  +					    sizeof(data->names[0]) * (data->name_count))) == NULL) {
  +			Nprint_err("xrealloc() failed: %s", strerror(errno));
  +			return -1;
  +		}
  +		data->names[(data->name_count - 1)] = xstrdup(value);
  +		return 0;
  +	default:
  +		return 1;
  +	}
  +}
   
  -			append_str(&command, "chown ");
  +static int ownership_valid_data(const element_s * const element)
  +{
  +	struct ownership_data *data = (struct ownership_data *) element->handler_data;
   
  -			append_str(&message, "Changing user ownership to ");
  -			append_str(&message, user);
  +	if (data->name_count == 0) {
  +		Nprint_err("<%s>: <name> must be specified.", element->handler->name);
  +		return 0;
  +	}
   
  -			if (recursive) {
  -				append_str(&command, "-R ");
  -				append_str(&message, " (recursive)");
  -			}
  +	if (!(data->user || data->group)) {
  +		Nprint_err("<%s>: \"user\" or \"group\" must be specified.", element->handler->name);
  +		return 0;
  +	}
   
  -			append_str(&message, ": ");
  -			append_str(&message, s);
  +	return 1;
  +}
   
  -			append_str(&command, user);
  -			append_str(&command, " ");
  -			append_str(&command, s);
  +static int ownership_main(const element_s *const element)
  +{
  +	struct ownership_data *data = (struct ownership_data *) element->handler_data;
  +	int status = 0;
  +	int i;
   
  -			Nprint_h("%s", message);
  +	if (change_to_base_dir(element, data->base, 1))
  +		return -1;
   
  -			if ((status = execute_command(el, command))) {
  +	if (data->user) {
  +		for (i = 0; i < data->name_count; i++) {
  +			Nprint_h("Changing user ownership to %s%s: %s", data->user,
  +				 data->recursive ? "(recursive)" : " ", data->names[i]);
  +			status = execute_command(element, "chown %s %s %s",
  +						 data->recursive ? "-R" : "",
  +						 data->user, data->names[i]);
  +			if (status) {
   				Nprint_h_err("Changing ownership failed.");
  -				xfree(s);
  -				xfree(command);
  -				xfree(message);
   				break;
   			}
  -			
  -			xfree(command);
  -			xfree(message);
   		}
  +	}
   
  -		if (group) {
  -			char *command = NULL;
  -			char *message = NULL;
  -
  -
  -			append_str(&command, "chgrp ");
  -
  -			append_str(&message, "Changing group ownership to ");
  -			append_str(&message, group);
  -			append_str(&message, " ");
  -
  -			if (recursive) {
  -				append_str(&command, "-R ");
  -				append_str(&message, "(recursive) ");
  -			}
  -
  -			append_str(&message, ": ");
  -			append_str(&message, s);
  -
  -			append_str(&command, group);
  -			append_str(&command, " ");
  -			append_str(&command, s);
  -
  -			Nprint_h("%s", message);
  -
  -			if ((status = execute_command(el, command))) {
  +	if ((status == 0) && data->group) {
  +		for (i = 0; i < data->name_count; i++) {
  +			Nprint_h("Changing group ownership to %s%s: %s", data->group,
  +				 data->recursive ? "(recursive)" : " ", data->names[i]);
  +			status = execute_command(element, "chgrp %s %s %s",
  +						 data->recursive ? "-R" : "",
  +						 data->group, data->names[i]);
  +			if (status) {
   				Nprint_h_err("Changing ownership failed.");
  -				xfree(s);
  -				xfree(command);
  -				xfree(message);
   				break;
   			}
  -			
  -			xfree(command);
  -			xfree(message);
   		}
  -
  -		xfree(s);
   	}
  -
   	return status;
   }
   
  -#endif /* HANDLER_SYNTAX_3_0 || HANDLER_SYNTAX_3_1 || HANDLER_SYNTAX_3_2 */
  -
   
   /*
    * Handlers' information.
  @@ -182,6 +238,11 @@
   		.main = ownership_main,
   		.type = HTYPE_NORMAL,
   		.is_action = 1,
  +		.setup = ownership_setup,
  +		.free = ownership_free,
  +		.parameter = ownership_parameter,
  +		.attribute = ownership_attribute,
  +		.valid_data = ownership_valid_data,
   	},
   #endif
   #if HANDLER_SYNTAX_3_1
  @@ -194,6 +255,11 @@
   		.main = ownership_main,
   		.type = HTYPE_NORMAL,
   		.is_action = 1,
  +		.setup = ownership_setup,
  +		.free = ownership_free,
  +		.parameter = ownership_parameter,
  +		.attribute = ownership_attribute,
  +		.valid_data = ownership_valid_data,
   	},
   #endif
   #if HANDLER_SYNTAX_3_2
  @@ -207,6 +273,11 @@
   		.type = HTYPE_NORMAL,
   		.is_action = 1,
   		.alternate_shell = 1,
  +		.setup = ownership_setup,
  +		.free = ownership_free,
  +		.parameter = ownership_parameter,
  +		.attribute = ownership_attribute,
  +		.valid_data = ownership_valid_data,
   	},
   #endif
   	{
  
  
  



More information about the alfs-log mailing list