cvs commit: ALFS/nALFS/src/handlers check.c configure.c copy.c download.c execute.c link.c make.c patch.c permissions.c

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Wed Mar 17 17:30:47 PST 2004


kpfleming    04/03/17 18:30:47

  Modified:    nALFS/src/handlers check.c configure.c copy.c download.c
                        execute.c link.c make.c patch.c permissions.c
  Log:
  convert handlers to use append_str_format where appropriate to reduce memory allocations
  
  Revision  Changes    Path
  1.19      +4 -6      ALFS/nALFS/src/handlers/check.c
  
  Index: check.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/check.c,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- check.c	16 Mar 2004 04:21:59 -0000	1.18
  +++ check.c	18 Mar 2004 01:30:47 -0000	1.19
  @@ -104,13 +104,11 @@
   	switch (data_requested) {
   	case HDATA_DISPLAY_NAME:
   	{
  -		char *display;
  +		char *display = NULL;
   
  -		display = xstrdup("Check for installed package");
  -		if (data->content) {
  -			append_str(&display, ": ");
  -			append_str(&display, data->content);
  -		}
  +		append_str_format(&display, "Check for installed package%s%s",
  +				  data->content ? ": " : "",
  +				  data->content ? data->content : "");
   
   		return display;
   	}
  
  
  
  1.23      +2 -4      ALFS/nALFS/src/handlers/configure.c
  
  Index: configure.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/configure.c,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- configure.c	8 Mar 2004 18:46:24 -0000	1.22
  +++ configure.c	18 Mar 2004 01:30:47 -0000	1.23
  @@ -130,13 +130,11 @@
   		data->base = xstrdup(value);
   		return 0;
   	case CONFIGURE_PREFIX:
  -		append_str(&data->prefix, value);
  -		append_str(&data->prefix, " ");
  +		append_str_format(&data->prefix, "%s ", value);
   		data->prefix_seen = 1;
   		return 0;
   	case CONFIGURE_PARAM:
  -		append_str(&data->param, value);
  -		append_str(&data->param, " ");
  +		append_str_format(&data->param, "%s ", value);
   		data->param_seen = 1;
   		return 0;
   	case CONFIGURE_COMMAND:
  
  
  
  1.26      +24 -41    ALFS/nALFS/src/handlers/copy.c
  
  Index: copy.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/copy.c,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- copy.c	2 Mar 2004 05:20:20 -0000	1.25
  +++ copy.c	18 Mar 2004 01:30:47 -0000	1.26
  @@ -235,33 +235,26 @@
   	int status = 0;
   	char *tok;
   	char *tmp;
  -	char *common_command;
  +	char *common_command = NULL;
   
   	if (change_to_base_dir(el, data->base, 1))
   		return -1;
   
  -	common_command = xstrdup("cp");
  -
  -	/* Options. */
  -	if (data->archive)
  -		append_str(&common_command, " -a");
  -	if (data->force)
  -		append_str(&common_command, " -f");
  -	if (data->no_dereference)
  -		append_str(&common_command, " -d");
  -	if (data->preserve)
  -		append_str(&common_command, " -p");
  -	if (data->recursive)
  -		append_str(&common_command, " -R");
  +	append_str_format(&common_command, "cp %s%s%s%s%s",
  +			  data->archive ? " -a" : "",
  +			  data->force ? " -f" : "",
  +			  data->no_dereference ? " -d" : "",
  +			  data->preserve ? " -p" : "",
  +			  data->recursive ? " -R" : "");
   
   	tmp = xstrdup(data->sources[0]);
   	for (tok = strtok(tmp, WHITE_SPACE); tok; tok = strtok(NULL, WHITE_SPACE)) {
  -		char *command = xstrdup(common_command);
  +		char *command = NULL;
   
  -		append_str(&command, " ");
  -		append_str(&command, tok);
  -		append_str(&command, " ");
  -		append_str(&command, data->destination);
  +		append_str_format(&command, "%s %s %s",
  +				  common_command,
  +				  tok,
  +				  data->destination);
   
   		Nprint_h("Executing:");
   		Nprint_h("    %s", command);
  @@ -303,35 +296,25 @@
   	struct copy_data *data = (struct copy_data *) el->handler_data;
   	int status = 0;
   	int i;
  -	char *common_command;
  +	char *common_command = NULL;
   
   	if (change_to_base_dir(el, data->base, 1))
   		return -1;
   
  -	common_command = xstrdup("cp");
  -
  -	/* Options. */
  -	if (data->archive)
  -		append_str(&common_command, " -a");
  -	if (data->force)
  -		append_str(&common_command, " -f");
  -	if (data->no_dereference)
  -		append_str(&common_command, " -d");
  -	if (data->preserve)
  -		append_str(&common_command, " -p");
  -	if (data->recursive)
  -		append_str(&common_command, " -R");
  +	append_str_format(&common_command, "cp %s%s%s%s%s",
  +			  data->archive ? " -a" : "",
  +			  data->force ? " -f" : "",
  +			  data->no_dereference ? " -d" : "",
  +			  data->preserve ? " -p" : "",
  +			  data->recursive ? " -R" : "");
   
   	for (i = 0; i < data->source_count; i++) {
  -		const char *source = data->sources[i];
  -		char *command;
  +		char *command = NULL;
   
  -		command = xstrdup(common_command);
  -		
  -		append_str(&command, " ");
  -		append_str(&command, source);
  -		append_str(&command, " ");
  -		append_str(&command, data->destination);
  +		append_str_format(&command, "%s %s %s",
  +				  common_command,
  +				  data->sources[i],
  +				  data->destination);
   
   		Nprint_h("Executing:");
   		Nprint_h("    %s", command);
  
  
  
  1.27      +4 -3      ALFS/nALFS/src/handlers/download.c
  
  Index: download.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/download.c,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- download.c	14 Mar 2004 05:40:27 -0000	1.26
  +++ download.c	18 Mar 2004 01:30:47 -0000	1.27
  @@ -188,10 +188,11 @@
   			Nprint_h("Trying to fetch it from <url>...");
   
   			for (i = 0; i < data->url_count; i++) {
  -				char *tmp;
  +				char *tmp = NULL;
   
  -				tmp = xstrdup(data->urls[i]);
  -				append_str(&tmp, data->file);
  +				append_str_format(&tmp, "%s%s",
  +						  data->urls[i],
  +						  data->file);
   				if (!get_url(tmp, data->file, digest, digest_type))
   					found = 1;
   				xfree(tmp);
  
  
  
  1.30      +5 -8      ALFS/nALFS/src/handlers/execute.c
  
  Index: execute.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/execute.c,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- execute.c	18 Mar 2004 01:03:03 -0000	1.29
  +++ execute.c	18 Mar 2004 01:30:47 -0000	1.30
  @@ -148,13 +148,11 @@
   		data->content = xstrdup(value);
   		return 0;
   	case EXECUTE_PREFIX:
  -		append_str(&data->prefix, value);
  -		append_str(&data->prefix, " ");
  +		append_str_format(&data->prefix, "%s ", value);
   		data->prefix_seen = 1;
   		return 0;
   	case EXECUTE_PARAM:
  -		append_str(&data->param, value);
  -		append_str(&data->param, " ");
  +		append_str_format(&data->param, "%s ", value);
   		data->param_seen = 1;
   		return 0;
   	default:
  @@ -313,12 +311,11 @@
   	} else {
   		FILE *temp_script;
   		char *tok;
  -		char *temp_file_name;
  +		char *temp_file_name = NULL;
   		char *args[2];
   
  -		temp_file_name = xstrdup(*opt_alfs_directory);
  -		append_str(&temp_file_name, "/");
  -		append_str(&temp_file_name, ".nALFS.XXXXXX");
  +		append_str_format(&temp_file_name, "%s/.nALFS.XXXXXX",
  +				  *opt_alfs_directory);
   		if (!create_temp_file(temp_file_name)) {
   			if ((temp_script = fopen(temp_file_name, "w"))) {
   				char *tmp = xstrdup(data->content);
  
  
  
  1.22      +1 -2      ALFS/nALFS/src/handlers/link.c
  
  Index: link.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/link.c,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- link.c	8 Mar 2004 17:21:43 -0000	1.21
  +++ link.c	18 Mar 2004 01:30:47 -0000	1.22
  @@ -266,8 +266,7 @@
   		return -1;
   
   	for (i = 0; i < data->target_count; i++) {
  -		append_str(&targets, data->targets[i]);
  -		append_str(&targets, " ");
  +		append_str_format(&targets, "%s ", data->targets[i]);
   	}
   
   	if (data->name) {
  
  
  
  1.21      +2 -4      ALFS/nALFS/src/handlers/make.c
  
  Index: make.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/make.c,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- make.c	3 Mar 2004 03:57:05 -0000	1.20
  +++ make.c	18 Mar 2004 01:30:47 -0000	1.21
  @@ -119,13 +119,11 @@
   		data->base = xstrdup(value);
   		return 0;
   	case MAKE_PREFIX:
  -		append_str(&data->prefix, value);
  -		append_str(&data->prefix, " ");
  +		append_str_format(&data->prefix, "%s ", value);
   		data->prefix_seen = 1;
   		return 0;
   	case MAKE_PARAM:
  -		append_str(&data->param, value);
  -		append_str(&data->param, " ");
  +		append_str_format(&data->param, "%s ", value);
   		data->param_seen = 1;
   		return 0;
   	default:
  
  
  
  1.25      +3 -7      ALFS/nALFS/src/handlers/patch.c
  
  Index: patch.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/patch.c,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- patch.c	3 Mar 2004 02:12:30 -0000	1.24
  +++ patch.c	18 Mar 2004 01:30:47 -0000	1.25
  @@ -153,12 +153,10 @@
   		data->base = xstrdup(value);
   		return 0;
   	case PATCH_PREFIX:
  -		append_str(&data->prefix, value);
  -		append_str(&data->prefix, " ");
  +		append_str_format(&data->prefix, "%s ", value);
   		return 0;
   	case PATCH_PARAM:
  -		append_str(&data->param, value);
  -		append_str(&data->param, " ");
  +		append_str_format(&data->param, "%s ", value);
   		data->param_seen = 1;
   		return 0;
   	case PATCH_FILE:
  @@ -244,9 +242,7 @@
   	if (change_to_base_dir(element, data->base, 1))
   		return -1;
   	
  -	append_str(&command, data->prefix);
  -	append_str(&command, "patch");
  -	append_str(&command, data->param);
  +	append_str_format(&command, "%s patch %s", data->prefix, data->param);
   
   	Nprint_h("Patching");
   	Nprint_h("    %s", command);
  
  
  
  1.22      +10 -15    ALFS/nALFS/src/handlers/permissions.c
  
  Index: permissions.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/permissions.c,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- permissions.c	3 Mar 2004 03:56:55 -0000	1.21
  +++ permissions.c	18 Mar 2004 01:30:47 -0000	1.22
  @@ -213,27 +213,22 @@
   {
   	struct permissions_data *data = (struct permissions_data *) element->handler_data;
   	int status = 0;
  -	char *command;
  -	char *message;
  +	char *command = NULL;
  +	char *message = NULL;
   	int i;
   
   	if (change_to_base_dir(element, data->base, 1))
   		return -1;
   
   	for (i = 0; i < data->name_count; i++) {
  -		command = xstrdup("chmod ");
  -		message = xstrdup("Changing permissions to ");
  -		append_str(&message, data->mode);
  -		append_str(&message, " ");
  -		if (data->recursive) {
  -			append_str(&command, "-R ");
  -			append_str(&message, "(recursive) ");
  -		}
  -		append_str(&message, ": ");
  -		append_str(&message, data->names[i]);
  -		append_str(&command, data->mode);
  -		append_str(&command, " ");
  -		append_str(&command, data->names[i]);
  +		append_str_format(&command, "chmod %s %s %s",
  +				  data->recursive ? "-R" : "",
  +				  data->mode,
  +				  data->names[i]);
  +		append_str_format(&message, "Changing permissions to %s%s: %s",
  +				  data->mode,
  +				  data->recursive ? " (recursive) " : " ",
  +				  data->names[i]);
   
   		Nprint_h("%s", message);
   
  
  
  



More information about the alfs-log mailing list