cvs commit: ALFS/nALFS/src/lib digest.c

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Sat Mar 13 21:40:27 PST 2004


kpfleming    04/03/13 22:40:27

  Modified:    nALFS/src handlers.c handlers.h libXML-tree.c nalfs.c
                        parser.c parser.h
               nALFS/src/handlers download.c unpack.c
               nALFS/src/include nALFS.h
               nALFS/src/lib digest.c
  Log:
  remove stuff replaced by new parsing system:
  	remove global parameter list and related functions
  	remove unneeded option parsing functions
  	remove unneeded functions to append prefix/parameter elements to a command string
  	remove functions for getting attributes and parameters at execution time
  	remove unneeded alloc_element_digest function
  
  provide generic function to search for parent element that can provide a piece of data
  combine base_dir functions because new handlers can provide data for all syntaxes
  ensure that elements are not added to tree for parameters accepted by handlers
  
  Revision  Changes    Path
  1.28      +16 -229   ALFS/nALFS/src/handlers.c
  
  Index: handlers.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers.c,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- handlers.c	14 Mar 2004 04:47:09 -0000	1.27
  +++ handlers.c	14 Mar 2004 05:40:27 -0000	1.28
  @@ -48,8 +48,6 @@
   	handler_s **list;
   } handlers = { 0, NULL };
   
  -static char **parameters;
  -
   /* Embedded "handlers" for the root (profile) element and comment elements. */
   
   static int root_main(const element_s * const el)
  @@ -144,67 +142,6 @@
   	return NULL;
   }
   
  -/*
  - * Checks if name is a "parameter element".
  - * TODO: Check the syntax version too.
  - */
  -int parameter_exists(const char *name)
  -{
  -	int i;
  -
  -
  -	for (i = 0; parameters[i]; ++i) {
  -		if (strcmp(parameters[i], name) == 0) {
  -			return 1;
  -		}
  -	}
  -
  -	return 0;
  -}
  -
  -
  -
  -static INLINE int add_new_parameters(const struct handler_parameter *params)
  -{
  -	int i, total = 0;
  -	const struct handler_parameter *param;
  -
  -
  -	for (i = 0; (params[i].name); ++i) {
  -		param = &params[i];
  -		int j, param_already_exists = 0;
  -
  -		/* Check if tok already exists in parameters. */
  -		for (j = 0; parameters[j]; ++j) {
  -			if (strcmp(param->name, parameters[j]) == 0) {
  -				++param_already_exists;
  -			}
  -		}
  -
  -		if (! param_already_exists) {
  -			++total;
  -
  -			parameters = xrealloc(
  -				parameters,
  -				(j+2) * sizeof *parameters);
  -			parameters[j] = xstrdup(param->name);
  -			parameters[j+1] = NULL;
  -		}
  -	}
  -
  -	return total;
  -}
  -
  -static INLINE int number_of_parameters(void)
  -{
  -	int i;
  -
  -	for (i = 0; parameters[i]; ++i)
  -		/* Count the number of parameters. */;
  -
  -	return i;
  -}
  -
   static INLINE lt_ptr lookup_symbol(lt_dlhandle handle, const char *symbol_name)
   {
   	lt_ptr result;
  @@ -289,16 +226,6 @@
   	return parse_handler_info(handler_info, handle);
   }
   
  -static INLINE void add_all_parameters(void)
  -{
  -	int i;
  -
  -	for (i = 0; i < handlers.cnt; ++i) {
  -		if (handlers.list[i]->info->parameters)
  -			add_new_parameters(handlers.list[i]->info->parameters);
  -	}
  -}
  -
   #ifndef STATIC_BUILD
   static int foreachfile_callback(const char *filename, lt_ptr data)
   {
  @@ -315,9 +242,6 @@
   
   int load_all_handlers(void)
   {
  -	parameters = xmalloc(sizeof *parameters);
  -	parameters[0] = NULL;
  -
   #ifdef STATIC_BUILD
   	LTDL_SET_PRELOADED_SYMBOLS();
   #endif
  @@ -339,15 +263,11 @@
   	(void) parse_handler_info(embedded_handlers_info, NULL);
   
   	lt_dlforeach(&load_handler, NULL);
  -	add_all_parameters();
   	Nprint("Total %d handlers loaded.", handlers.cnt);
  -	Nprint("Total %d parameters found.", number_of_parameters());
   
   	return 0;
   }
   
  -
  -
   /*
    * Utility functions tied to handlers in some way.
    */
  @@ -407,42 +327,29 @@
   	return el->handler->alloc_data(el, HDATA_COMMAND);
   }
   
  -/* Used by old syntax (2.0). */
  -char *alloc_base_dir(element_s *el)
  +static const element_s *find_parent_with_data(const element_s * const element,
  +					      const handler_data_e data_requested)
   {
  -	element_s *p;
  -	char *dir;
  -
  -
  -	if ((dir = alloc_trimmed_param_value("base", el))) {
  -		return dir;
  -	}
  -
  -	for (p = el->parent; p; p = p->parent) {
  -		if (Is_element_name(p, "package")) {
  -			if ((dir = alloc_trimmed_param_value("base", p))) {
  -				return dir;
  -			}
  +	const element_s *s;
   
  -			break; /* One <package> is enough. */
  -		}
  +	for (s = element->parent; s; s = s->parent) {
  +		if (!s->handler)
  +			continue;
  +		if ((s->handler->data & data_requested) == 0)
  +			return s;
   	}
   
  -	return xstrdup("/");
  +	return NULL;
   }
   
  -/* Used by syntax 3.0+ handlers. */
  -const char *alloc_base_dir_new(const element_s * const element)
  +const char *alloc_base_dir(const element_s * const element)
   {
   	const element_s *s;	
   	const char *dir;
   
  -	for (s = element->parent; s; s = s->parent) {
  -		if (!s->handler)
  -			continue;
  -		if ((s->handler->data & HDATA_BASE) == 0)
  -			continue;
  +	s = find_parent_with_data(element, HDATA_BASE);
   
  +	if (s) {
   		dir  = s->handler->alloc_data(s, HDATA_BASE);
   		if (dir)
   			return dir;
  @@ -461,7 +368,7 @@
   	if (local_base)
   		return change_current_dir(local_base);
   
  -	if ((dir = alloc_base_dir_new(element)) != NULL) {
  +	if ((dir = alloc_base_dir(element)) != NULL) {
   		result = change_current_dir(dir);
   		xfree(dir);
   		return result;
  @@ -474,17 +381,14 @@
   	}
   }
   
  -char *alloc_stage_shell(const element_s * const el)
  +const char *alloc_stage_shell(const element_s * const el)
   {
   	const element_s *s;
   	char *shell;
   
  -	for (s = el->parent; s; s = s->parent) {
  -		if (!s->handler)
  -			continue;
  -		if ((s->handler->data & HDATA_SHELL) == 0)
  -			continue;
  +	s = find_parent_with_data(el, HDATA_SHELL);
   
  +	if (s) {
   		shell = s->handler->alloc_data(s, HDATA_SHELL);
   		if (shell)
   			return shell;
  @@ -506,120 +410,3 @@
   	xfree(tmp);
   	return tok ? 1 : 0;
   }
  -
  -/* Used by the old syntax (2.0). */
  -int option_exists(const char *option, element_s *element)
  -{
  -	int exists = 0;
  -	char *option_string = alloc_trimmed_param_value("options", element);
  -
  -
  -	if (option_string && strstr(option_string, option)) {
  -		exists = 1;
  -	}
  -
  -	xfree(option_string);
  -
  -	return exists;
  -}
  -
  -/* Used by new syntax (3.0). */
  -void check_options(int total, int *opts, const char *string_, element_s *el)
  -{
  -	int i;
  -	char *str, *string;
  -	element_s *p;
  -
  -
  -	for (i = 0; i < total; ++i) {
  -		opts[i] = 0;
  -	}
  -
  -	for (p = first_param("option", el); p; p = next_param(p)) {
  -		int unknown_option = 1;
  -		char *o;
  -
  -
  -		if ((o = alloc_trimmed_str(p->content)) == NULL) {
  -			Nprint_warn("Skipping empty option.");
  -			continue;
  -		}
  -
  -		string = xstrdup(string_);
  -		for (str = strtok(string, WHITE_SPACE), i = 0;
  -		     str;
  -		     str = strtok(NULL, WHITE_SPACE), ++i) {
  -			if (strcmp(o, str) == 0) {
  -				unknown_option = 0;
  -				opts[i] = 1;
  -				break;
  -			}
  -		}
  -		xfree(string);
  -
  -		if (unknown_option) {
  -			Nprint_warn("Ignoring unknown option (%s).", o);
  -		}
  -
  -		xfree(o);
  -	}
  -}
  -
  -/* Used by both syntaxes. */
  -char *append_param_elements(char **string, element_s *el)
  -{
  -	element_s *tmp;
  -
  -
  -	for (tmp = first_param("param", el); tmp; tmp = next_param(tmp)) {
  -		char *content;
  -
  -		if ((content = alloc_trimmed_str(tmp->content))) {
  -			if (*string) {
  -				append_str(string, " ");
  -			}
  -			append_str(string, content);
  -
  -			xfree(content);
  -
  -		} else if (opt_be_verbose) {
  -			Nprint_warn("Skipping empty parameter.");
  -		}
  -	}
  -
  -	return *string;
  -}
  -
  -char *append_prefix_elements(char **string, element_s *el)
  -{
  -	element_s *tmp;
  -
  -
  -	for (tmp = first_param("prefix", el); tmp; tmp = next_param(tmp)) {
  -		char *content;
  -
  -		if ((content = alloc_trimmed_str(tmp->content))) {
  -			append_str(string, content);
  -			append_str(string, " ");
  -
  -			xfree(content);
  -
  -		} else if (opt_be_verbose) {
  -			Nprint_warn("Skipping empty prefix.");
  -		}
  -	}
  -
  -	return *string;
  -}
  -
  -char *parse_string_content(const char * const value,
  -			   const char * const message)
  -{
  -	if (strlen(value)) {
  -		return xstrdup(value);
  -	} else {
  -		Nprint_err(message);
  -		return NULL;
  -	}
  -}
  -
  
  
  
  1.26      +2 -11     ALFS/nALFS/src/handlers.h
  
  Index: handlers.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers.h,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- handlers.h	14 Mar 2004 04:46:17 -0000	1.25
  +++ handlers.h	14 Mar 2004 05:40:27 -0000	1.26
  @@ -145,21 +145,12 @@
   char *alloc_textdump_file(element_s *el);
   char *alloc_execute_command(element_s *el);
   
  -char *alloc_base_dir(element_s *el);
  -
  -const char *alloc_base_dir_new(const element_s * const element);
  +const char *alloc_base_dir(const element_s * const element);
   
   int change_to_base_dir(const element_s * const element, const char * const local_base, 
   		       const int default_root);
   
  -char *alloc_stage_shell(const element_s * const el);
  +const char *alloc_stage_shell(const element_s * const el);
   int option_in_string(const char * const option, const char * const string);
  -int option_exists(const char *option, element_s *element);
  -void check_options(int total, int *opts, const char *string_, element_s *el);
  -char *append_param_elements(char **string, element_s *el);
  -char *append_prefix_elements(char **string, element_s *el);
  -
  -char *parse_string_content(const char * const value,
  -			   const char * const message);
   
   #endif /* H_HANDLER_ */
  
  
  
  1.18      +14 -6     ALFS/nALFS/src/libXML-tree.c
  
  Index: libXML-tree.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/libXML-tree.c,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- libXML-tree.c	14 Mar 2004 04:46:36 -0000	1.17
  +++ libXML-tree.c	14 Mar 2004 05:40:27 -0000	1.18
  @@ -200,15 +200,18 @@
   	   elements with known handlers.
   	*/
   
  -	for (child = node->children; child; child = child->next) {
  -		if (!USED_NODE(child))
  +	for (child = node->children; child; ) {
  +		if (!USED_NODE(child)) {
  +			child = child->next;
   			continue;
  +		}
   
   		param = find_handler_parameter(handler,
   					       (const char *) child->name);
   
   		if (param) {
   			const char *content = NULL;
  +			xmlNodePtr free_child;
   
   			if (child->children && child->children->content)
   				content = (const char *) child->children->content;
  @@ -222,10 +225,19 @@
   			result = handler->parameter(element, param, content);
   			if (result)
   				return result;
  +			/* remove the child node from the DOM tree and free it,
  +			   it has been handled */
  +			free_child = child;
  +			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;
   		}
   	}
   
  @@ -323,10 +335,6 @@
   					el = NULL;
   					break;
   				}
  -
  -			} else if (parameter_exists(el->name)) {
  -				el->type = TYPE_PARAMETER;
  -
   			}
   
   			/* Add content, if any. */
  
  
  
  1.43      +7 -5      ALFS/nALFS/src/nalfs.c
  
  Index: nalfs.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/nalfs.c,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- nalfs.c	24 Feb 2004 04:21:14 -0000	1.42
  +++ nalfs.c	14 Mar 2004 05:40:27 -0000	1.43
  @@ -1368,7 +1368,8 @@
   	} else if (Is_element_name(el, "stage")) {
   		char *s;
   
  -		if ((s = attr_value("description", el))) {
  +/* TODO: get description/name from handler */
  +/*		if ((s = attr_value("description", el))) {
   			append_str(line, s);
   
   		} else {
  @@ -1376,6 +1377,7 @@
   				append_str(line, s);
   			}
   		}
  +*/
   
   	} else if (Is_element_name(el, "check")) {
   		char *s;
  @@ -2820,9 +2822,6 @@
   		case TYPE_ELEMENT:
   			Xwaddstr(windows.main->name, "Element\n");
   			break;
  -		case TYPE_PARAMETER:
  -			Xwaddstr(windows.main->name, "Parameter\n");
  -			break;
   		case TYPE_COMMENT:
   			Xwaddstr(windows.main->name, "Comment\n");
   			break;
  @@ -2991,7 +2990,8 @@
   	 * Print content (if any).
   	 */
   
  -	if (Is_parameter_name(el, "description")
  +/* TODO: get data from handler */
  +/*	if (Is_parameter_name(el, "description")
   	&& el->parent && Is_parameter_name(el->parent, "packageinfo")) {
   		char *s = build_description(el);
   
  @@ -3002,6 +3002,8 @@
   		xfree(s);
   
   	} else if (el->content) {
  +*/
  +	if (el->content) {
   		Xwprintw(windows.main->name,
   			"Full content\n------------\n%s",
   			el->content);
  
  
  
  1.11      +0 -73     ALFS/nALFS/src/parser.c
  
  Index: parser.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/parser.c,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- parser.c	23 Feb 2004 18:18:12 -0000	1.10
  +++ parser.c	14 Mar 2004 05:40:27 -0000	1.11
  @@ -180,79 +180,6 @@
    * Different utility funtions.
    */
   
  -char *attr_value(const char * const name, const element_s * const element)
  -{
  -	if (element->attr) {
  -		int i;
  -		char *att_name = NULL;
  -
  -		for (i = 0; (att_name = element->attr[i]); i += 2) {
  -			if (strcmp(att_name, name) == 0) {
  -				return element->attr[i+1];
  -			}
  -		}
  -	}
  -
  -	return NULL;
  -}
  -
  -char *raw_param_value(const char * const name, const element_s * const element)
  -{
  -	element_s *tmp;
  -
  -
  -	for (tmp = element->children; tmp; tmp = tmp->next) {
  -		if (strcmp(tmp->name, name) == 0) {
  -			return tmp->content;
  -		}
  -	}
  -
  -	return NULL;
  -}
  -
  -char *alloc_trimmed_param_value(const char * const name,
  -				const element_s * const element)
  -{
  -	char *tmp;
  -
  -
  -	if ((tmp = raw_param_value(name, element))) {
  -		return alloc_trimmed_str(tmp);
  -	}
  -
  -	return tmp;
  -}
  -
  -element_s *next_param(const element_s * const param)
  -{
  -	element_s *tmp;
  -
  -
  -	for (tmp = param->next; tmp; tmp = tmp->next) {
  -		if (tmp->type == TYPE_PARAMETER
  -		&& strcmp(tmp->name, param->name) == 0) {
  -			return tmp;
  -		}
  -	}
  -
  -	return NULL;
  -}
  -
  -element_s *first_param(const char * const name, const element_s * const element)
  -{
  -	element_s *tmp;
  -
  -
  -	for (tmp = element->children; tmp; tmp = tmp->next) {
  -		if (tmp->type == TYPE_PARAMETER
  -		&& strcmp(tmp->name, name) == 0) {
  -			return tmp;
  -		}
  -	}
  -
  -	return NULL;
  -}
  -
   element_s *get_profile_by_element(element_s *el)
   {
   	return el->profile;
  
  
  
  1.8       +0 -9      ALFS/nALFS/src/parser.h
  
  Index: parser.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/parser.h,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- parser.h	21 Feb 2004 19:03:32 -0000	1.7
  +++ parser.h	14 Mar 2004 05:40:27 -0000	1.8
  @@ -48,7 +48,6 @@
   	TYPE_ROOT,
   	TYPE_PROFILE,
   	TYPE_ELEMENT,
  -	TYPE_PARAMETER,
   	TYPE_COMMENT,
   	TYPE_DOCTYPE,
   	TYPE_ENTITY,
  @@ -86,18 +85,10 @@
   		  element_s *profile);
   element_s *parse_profile(const char *filename);
   
  -char *attr_value(const char * const name, const element_s * const element);
  -char *raw_param_value(const char * const name, const element_s * const element);
  -char *alloc_trimmed_param_value(const char * const name,
  -				const element_s * const element);
  -element_s *next_param(const element_s * const param);
  -element_s *first_param(const char * const name, const element_s * const element);
  -
   element_s *get_profile_by_element(element_s *el);
   element_s *get_profile_by_name(element_s *root, const char *name);
   
   element_s *get_next_element(element_s *el);
   element_s *get_prev_element(element_s *el);
  -
   
   #endif /* H_PARSER_ */
  
  
  
  1.26      +1 -1      ALFS/nALFS/src/handlers/download.c
  
  Index: download.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/download.c,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- download.c	3 Mar 2004 03:56:54 -0000	1.25
  +++ download.c	14 Mar 2004 05:40:27 -0000	1.26
  @@ -282,7 +282,7 @@
   	}
   
   	if (!data->base) {
  -		const char *base = alloc_base_dir_new(element);
  +		const char *base = alloc_base_dir(element);
   
   		if (!base) {
   			Nprint_err("<download>: \"base\" must be specified at or above this element.");
  
  
  
  1.33      +1 -1      ALFS/nALFS/src/handlers/unpack.c
  
  Index: unpack.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/unpack.c,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- unpack.c	3 Mar 2004 03:56:55 -0000	1.32
  +++ unpack.c	14 Mar 2004 05:40:27 -0000	1.33
  @@ -384,7 +384,7 @@
   	}
   
   	if (!data->base) {
  -		const char *base = alloc_base_dir_new(element);
  +		const char *base = alloc_base_dir(element);
   
   		if (!base) {
   			Nprint_err("<unpack>: \"base\" must be specified at or above this element.");
  
  
  
  1.5       +0 -1      ALFS/nALFS/src/include/nALFS.h
  
  Index: nALFS.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/include/nALFS.h,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- nALFS.h	8 Feb 2004 05:57:23 -0000	1.4
  +++ nALFS.h	14 Mar 2004 05:40:27 -0000	1.5
  @@ -35,7 +35,6 @@
   
   /* functions for downloading and verifying file contents */
   extern int verify_digest(const char *type, const char *digest, const char *file);
  -extern void alloc_element_digest(const struct element_s *el, char **digest, char **type);
   extern int load_url(const char *output, const char *url);
   extern int get_url(const char *url, const char *destination,
   		   const char *digest, const char *digest_type);
  
  
  
  1.7       +0 -22     ALFS/nALFS/src/lib/digest.c
  
  Index: digest.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/lib/digest.c,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- digest.c	25 Oct 2003 00:40:01 -0000	1.6
  +++ digest.c	14 Mar 2004 05:40:27 -0000	1.7
  @@ -50,28 +50,6 @@
   #include "parser.h"
   #include "utility.h"
   
  -#define El_unpack_digest(el) alloc_trimmed_param_value("digest", el)
  -
  -void alloc_element_digest(const element_s *el, char **digest, char **type)
  -{
  -	if ((*digest = El_unpack_digest(el)) != NULL) {
  -		element_s *el2 = first_param("digest", el);
  -		char *s;
  -
  -		*type = attr_value("type", el2);
  -		if (! Empty_string(*type)) {
  -			/* make a copy of the attribute value before
  -			   modifying it */
  -			*type = xstrdup(*type);
  -			for (s = *type; *s; s++) {
  -				*s = tolower(*s);
  -			}
  -		} else {
  -			*type = xstrdup("md5");
  -		}
  -	}
  -}
  -
   int verify_digest(const char* type, const char* digest, const char* file)
   {
   	char buffer[4094];
  
  
  



More information about the alfs-log mailing list