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

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Sat Mar 20 20:38:53 PST 2004


kpfleming    04/03/20 21:38:53

  Modified:    nALFS/src backend.c logfiles.c nalfs.c parser.c parser.h
                        utility.c
               nALFS/src/lib get_url.c
  Log:
  use append_str_format instead of multiple append_str wherever possible
  use only element->id for communication beteen backend and frontend about element state
  
  Revision  Changes    Path
  1.17      +6 -16     ALFS/nALFS/src/backend.c
  
  Index: backend.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/backend.c,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- backend.c	21 Mar 2004 03:40:51 -0000	1.16
  +++ backend.c	21 Mar 2004 04:38:52 -0000	1.17
  @@ -355,15 +355,12 @@
   static int do_execute_element(element_s *el)
   {
   	int i = 0;
  -	element_s *profile = get_profile_by_element(el);
  -
   
   	if (! (Can_run(el) && el->should_run)) {
   		return 0;
   	}
   
  -	comm_send_ctrl_msg(BACKEND_CTRL_SOCK, CTRL_ELEMENT_STARTED,
  -		"%s %s %d", profile->handler->name, el->handler->name, el->id);
  +	comm_send_ctrl_msg(BACKEND_CTRL_SOCK, CTRL_ELEMENT_STARTED, "%d", el->id);
   
   	if (el->type == TYPE_PROFILE) {
   		i = execute_children(el);
  @@ -390,12 +387,10 @@
   	if (i == 0) {
   		// TODO: Is there a point of setting these at all?
   		el->run_status = get_element_status(el);
  -		comm_send_ctrl_msg(BACKEND_CTRL_SOCK, CTRL_ELEMENT_ENDED,
  -			"%s %s %d", profile->handler->name, el->handler->name, el->id);
  +		comm_send_ctrl_msg(BACKEND_CTRL_SOCK, CTRL_ELEMENT_ENDED, "%d", el->id);
   	} else {
   		el->run_status = RUN_STATUS_FAILED;
  -		comm_send_ctrl_msg(BACKEND_CTRL_SOCK, CTRL_ELEMENT_FAILED,
  -			"%s %s %d", profile->handler->name, el->handler->name, el->id);
  +		comm_send_ctrl_msg(BACKEND_CTRL_SOCK, CTRL_ELEMENT_FAILED, "%d", el->id);
   	}
   
   	return i;
  @@ -404,15 +399,12 @@
   int do_execute_test_element(element_s *element, int *result)
   {
   	int i = 0;
  -	element_s *profile = get_profile_by_element(element);
  -
   
   	if (! (Can_run(element) && element->should_run)) {
   		return 0;
   	}
   
  -	comm_send_ctrl_msg(BACKEND_CTRL_SOCK, CTRL_ELEMENT_STARTED,
  -		"%s %s %d", profile->handler->name, element->handler->name, element->id);
  +	comm_send_ctrl_msg(BACKEND_CTRL_SOCK, CTRL_ELEMENT_STARTED, "%d", element->id);
   
   	if (*opt_use_relative_dirs)
   		change_to_profiles_dir(element);
  @@ -422,12 +414,10 @@
   	if (i == 0) {
   		// TODO: Is there a point of setting these at all?
   		element->run_status = get_element_status(element);
  -		comm_send_ctrl_msg(BACKEND_CTRL_SOCK, CTRL_ELEMENT_ENDED,
  -			"%s %s %d", profile->handler->name, element->handler->name, element->id);
  +		comm_send_ctrl_msg(BACKEND_CTRL_SOCK, CTRL_ELEMENT_ENDED, "%d", element->id);
   	} else {
   		element->run_status = RUN_STATUS_FAILED;
  -		comm_send_ctrl_msg(BACKEND_CTRL_SOCK, CTRL_ELEMENT_FAILED,
  -			"%s %s %d", profile->handler->name, element->handler->name, element->id);
  +		comm_send_ctrl_msg(BACKEND_CTRL_SOCK, CTRL_ELEMENT_FAILED, "%d", element->id);
   	}
   
   	return i;
  
  
  
  1.16      +7 -9      ALFS/nALFS/src/logfiles.c
  
  Index: logfiles.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/logfiles.c,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- logfiles.c	21 Mar 2004 03:40:51 -0000	1.15
  +++ logfiles.c	21 Mar 2004 04:38:52 -0000	1.16
  @@ -253,9 +253,9 @@
   
   			plogf = xmalloc(sizeof *plogf);
   
  -			plogf->filename = xstrdup(dir_name);
  -			append_str(&plogf->filename, "/");
  -			append_str(&plogf->filename, next->d_name);
  +			plogf->filename = NULL;
  +			append_str_format(&plogf->filename, "%s/%s",
  +					  dir_name, next->d_name);
   			plogf->name = NULL;
   			plogf->version = NULL;
   			plogf->installed = NULL;
  @@ -354,10 +354,9 @@
   
   	plogf = xmalloc(sizeof *plogf);
   
  -	plogf->filename = xstrdup(pdir);
  -	append_str(&plogf->filename, "/");
  -	append_str(&plogf->filename, package_str);
  -	append_str(&plogf->filename, SUFFIX_FOR_LOGF);
  +	plogf->filename = NULL;
  +	append_str_format(&plogf->filename, "%s/%s%s", pdir,
  +			  package_str, SUFFIX_FOR_LOGF);
   	plogf->name = NULL;
   	plogf->version = NULL;
   	plogf->installed = NULL;
  @@ -420,8 +419,7 @@
   	tmp = strrchr(filename, '.');
   	*tmp = '\0';
   	
  -	append_str(&filename, SUFFIX_FOR_FLOG);
  -	append_str(&filename, ".XXXXXX");
  +	append_str(&filename, SUFFIX_FOR_FLOG ".XXXXXX");
   
   	if (create_temp_file(filename)) {
   		xfree(filename);
  
  
  
  1.49      +23 -110   ALFS/nALFS/src/nalfs.c
  
  Index: nalfs.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/nalfs.c,v
  retrieving revision 1.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- nalfs.c	21 Mar 2004 03:40:51 -0000	1.48
  +++ nalfs.c	21 Mar 2004 04:38:52 -0000	1.49
  @@ -685,53 +685,16 @@
   	return 0;
   }
   
  -static element_s *do_find_element_by_key(element_s *profile, unsigned int id)
  -{
  -	unsigned int i;
  -	element_s *el;
  -
  -
  -	for (i = 0, el = profile; el; el = get_next_element(el), ++i) {
  -		if (i == id) {
  -			return el;
  -		}
  -	}
  -
  -	return NULL;
  -}
  -
  -/* str's format: "profile_name element_name element_id" */
  +/* takes string containing element id and gets element */
   static element_s *find_element_by_key(const char *str)
   {
  -	char *tok;
  -	char *str_copy;
  -	element_s *element = NULL;
  -
  -
  -	str_copy = xstrdup(str);
  -
  -	if ((tok = strtok(str_copy, " "))) { /* Profile's name. */
  -		element_s *profile = get_profile_by_name(tok);
  -
  -		ASSERT(profile != NULL);
  -
  -		if ((tok = strtok(NULL, " "))) { /* Element's name. */
  -
  -			if ((tok = strtok(NULL, " "))) { /* Element's ID. */
  -				char *endptr;
  -				unsigned int id = strtoul(tok, &endptr, 10);
  -
  -				if (*endptr == 0) {
  -					element =
  -					do_find_element_by_key(profile, id);
  -				}
  -			}
  -		}
  -	}
  +	char *endptr;
  +	unsigned int id = strtoul(str, &endptr, 10);
   
  -	xfree(str_copy);
  +	if (*endptr == NULL)
  +		return get_element_by_id(id);
   
  -	return element;
  +	return NULL;
   }
   
   static INLINE void send_element_status(const char *key)
  @@ -929,7 +892,7 @@
   {
   	int i;
   	const char *editor;
  -	char *command;
  +	char *command = NULL;
   
   
   	endwin();
  @@ -944,9 +907,7 @@
   		editor = "vi";
   	}
   
  -	command = xstrdup(editor);
  -	append_str(&command, " ");
  -	append_str(&command, filename);
  +	append_str_format(&command, "%s %s", editor, filename);
   
   	i = system(command);
   
  @@ -1078,12 +1039,8 @@
   	char *plog = logs_get_plog_filename(logs, idx);
   
   
  -	append_str(&command, "rm -fr `cat ");
  -	append_str(&command, flog);
  -	append_str(&command, "`");
  -
  +	append_str_format(&command, "rm -fr `cat %s`", flog);
   	system(command);
  -
   	xfree(command);
   
   	Nprint("Done removing files.");
  @@ -1092,13 +1049,8 @@
   
   	if (get_key(windows.main->name) == 'Y') {
   		command = NULL;
  -		append_str(&command, "rm -f ");
  -		append_str(&command, flog);
  -		append_str(&command, " ");
  -		append_str(&command, plog);
  -
  +		append_str_format(&command, "rm -f %s %f", flog, plog);
   		system(command);
  -
   		xfree(command);
   
   		Nprint("Log files removed:");
  @@ -1200,9 +1152,7 @@
   		append_str(&line, " ");
   	}
   
  -	append_str(&line, name);
  -	append_str(&line, " - ");
  -	append_str(&line, version);
  +	append_str_format(&line, "%s - %s", name, version);
   
   	/* Print the line. */
   	if (strlen(line) + 4 > (unsigned int)windows.max_cols) {
  @@ -1336,8 +1286,6 @@
   {
   	int i, j;
   	char *line = NULL;
  -	char status_mark[4];
  -
   
   	if (should_skip_element(el, depth)) {
   		return;
  @@ -1348,46 +1296,15 @@
   		(displayed.total) * sizeof *displayed.elements);
   	displayed.elements[displayed.total - 1] = el;
   
  -
  -	/* Space for cursor. */
  -	for (i = 0; i < (int)strlen(*opt_cursor); ++i) {
  -		append_str(&line, " ");
  -	}
  -
  -	/* Marked or not. */
  -	if (el->marked) {
  -		append_str(&line, " * ");
  -	} else {
  -		append_str(&line, "   ");
  -	}
  -
  -	/* Run-status mark. */
  -	status_mark[0] = status_to_mark(el->run_status);
  -	status_mark[1] = ' ';
  -	status_mark[2] = ' ';
  -	status_mark[3] = '\0';
  -	append_str(&line, status_mark);
  -
  -	/* Indentation space. */
  -	j = (*depth) * *opt_indentation_size;
  -	for (i = 0; i < j; ++i) {
  -		append_str(&line, " ");
  -	}
  -
  -	/* Does element have children. */
  -	if (el->children) {
  -		if (el->hide_children) {
  -			append_str(&line, "+ ");
  -		} else {
  -			append_str(&line, "- ");
  -		}
  -	} else {
  -		append_str(&line, "  ");
  -	}
  +	append_str_format(&line, "%*s %s %c%*s%s ",
  +			  strlen(*opt_cursor), "",
  +			  el->marked ? "*" : " ",
  +			  status_to_mark(el->run_status),
  +			  *depth * *opt_indentation_size, "",
  +			  el->children ? (el->hide_children ? "+" : "-") : " ");
   
   	if (el->handler->data & HDATA_DISPLAY_NAME) {
  -		char *display = el->handler->alloc_data(el,
  -							HDATA_DISPLAY_NAME);
  +		char *display = el->handler->alloc_data(el, HDATA_DISPLAY_NAME);
   		append_str(&line, display);
   		xfree(display);
   	} else {
  @@ -4370,16 +4287,14 @@
   static INLINE void append_prune_dirs_from_file(void)
   {
   	FILE *fp;
  -	char *file;
  +	char *file = NULL;
   
   
   	/* Get real file name. */
   	if (*opt_find_prunes_file[0] == '/') {
   		file = xstrdup(*opt_find_prunes_file);
   	} else {
  -		file = xstrdup(*opt_alfs_directory);
  -		append_str(&file, "/");
  -		append_str(&file, *opt_find_prunes_file);
  +		append_str_format(&file, "%s/%s", *opt_alfs_directory, *opt_find_prunes_file);
   	}
   
   	/* Read directories from a file. */
  @@ -4413,10 +4328,8 @@
    */
   static INLINE void init_state_file(void)
   {
  -	state.filename = xstrdup(*opt_alfs_directory);
  -	append_str(&state.filename, "/");
  -       	append_str(&state.filename, state_file_name);
  -
  +	state.filename = NULL;
  +	append_str_format(&state.filename, "%s/%s",  *opt_alfs_directory, state_file_name);
   	state.exists = file_exists(state.filename) ? 1 : 0;
   }
   
  @@ -4488,7 +4401,7 @@
   	}
   
   	va_start(ap, format);
  -        __va_copy(ap2, ap);
  +        va_copy(ap2, ap);
   
   	console = (mid == T_ERR) ? stderr : stdout;
   
  
  
  
  1.18      +13 -0     ALFS/nALFS/src/parser.c
  
  Index: parser.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/parser.c,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- parser.c	21 Mar 2004 03:40:51 -0000	1.17
  +++ parser.c	21 Mar 2004 04:38:52 -0000	1.18
  @@ -241,6 +241,18 @@
    * Different utility funtions.
    */
   
  +element_s *get_element_by_id(unsigned int id)
  +{
  +	element_s *el;
  +
  +	for (el = root_element; el; el = get_next_element(el)) {
  +		if (el->id == id)
  +			return el;
  +	}
  +
  +	return NULL;
  +}
  +
   element_s *get_profile_by_element(const element_s * const el)
   {
   	return el->profile;
  @@ -251,6 +263,7 @@
   	element_s *el;
   
   	for (el = root_element->children; el; el = el->next) {
  +/* TODO: is this correct, or even necessary? */
   		if (strcmp(el->handler->name, name) == 0) {
   			return el;
   		}
  
  
  
  1.12      +2 -0      ALFS/nALFS/src/parser.h
  
  Index: parser.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/parser.h,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- parser.h	16 Mar 2004 04:21:58 -0000	1.11
  +++ parser.h	21 Mar 2004 04:38:52 -0000	1.12
  @@ -88,6 +88,8 @@
   
   element_s *parse_profile(const char *filename);
   
  +element_s *get_element_by_id(unsigned int id);
  +
   element_s *get_profile_by_element(const element_s * const el);
   element_s *get_profile_by_name(const char * const name);
   
  
  
  
  1.11      +4 -3      ALFS/nALFS/src/utility.c
  
  Index: utility.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/utility.c,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- utility.c	21 Mar 2004 03:40:51 -0000	1.10
  +++ utility.c	21 Mar 2004 04:38:52 -0000	1.11
  @@ -180,6 +180,7 @@
   void append_str_format(char **ptr, const char *format, ...)
   {
   	va_list ap;
  +	va_list ap2;
   	int old_length = 0;
   	int new_length;
   	char *value;
  @@ -192,13 +193,13 @@
   		old_length = strlen(*ptr);
   
   	va_start(ap, format);
  +	va_copy(ap2, ap);
   	new_length = vsnprintf(NULL, 0, format, ap);
   	va_end(ap);
   
         	value = xrealloc(*ptr, new_length + old_length + 1);
  -	va_start(ap, format);
  -	vsnprintf(value + old_length, new_length + 1, format, ap);
  -	va_end(ap);
  +	vsnprintf(value + old_length, new_length + 1, format, ap2);
  +	va_end(ap2);
   
   	*ptr = value;
   }
  
  
  
  1.6       +2 -4      ALFS/nALFS/src/lib/get_url.c
  
  Index: get_url.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/lib/get_url.c,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- get_url.c	21 Mar 2004 03:40:52 -0000	1.5
  +++ get_url.c	21 Mar 2004 04:38:53 -0000	1.6
  @@ -43,7 +43,7 @@
   	int command_status;
   	struct stat stat_buf;
   	char *dirname_buf;
  -	char *temp_file_name;
  +	char *temp_file_name = NULL;
   	    
   
   	/* Construct a temporary filename */
  @@ -52,10 +52,8 @@
   	   the dirname() function wants to modify it
   	*/
   	dirname_buf = xstrdup(destination);
  -	temp_file_name = xstrdup(dirname(dirname_buf));
  +	append_str_format(&temp_file_name, "%s/.nALFS.XXXXXX", dirname(dirname_buf));
   	xfree(dirname_buf);
  -	append_str(&temp_file_name, "/");
  -	append_str(&temp_file_name, ".nALFS.XXXXXX");
   	if (create_temp_file(temp_file_name))
   		goto free_all_and_return;
   	/* There is a small risk that another user could create a symlink
  
  
  



More information about the alfs-log mailing list