Fix wget error message and add (and use) chomp library function.

This commit is contained in:
Matt Kraai 2001-02-01 16:49:30 +00:00
parent bd018b1bab
commit 05e782ddd3
15 changed files with 31 additions and 24 deletions

View File

@ -274,8 +274,7 @@ extern int tar_main(int argc, char **argv)
while (fgets(file, sizeof(file), fileList) != NULL) { while (fgets(file, sizeof(file), fileList) != NULL) {
excludeList = xrealloc(excludeList, excludeList = xrealloc(excludeList,
sizeof(char *) * (excludeListSize+2)); sizeof(char *) * (excludeListSize+2));
if (file[strlen(file)-1] == '\n') chomp(file);
file[strlen(file)-1] = '\0';
excludeList[excludeListSize] = xstrdup(file); excludeList[excludeListSize] = xstrdup(file);
/* Tack a NULL onto the end of the list */ /* Tack a NULL onto the end of the list */
excludeList[++excludeListSize] = NULL; excludeList[++excludeListSize] = NULL;

View File

@ -152,6 +152,7 @@ extern char process_escape_sequence(char **ptr);
extern char *get_last_path_component(char *path); extern char *get_last_path_component(char *path);
extern FILE *wfopen(const char *path, const char *mode); extern FILE *wfopen(const char *path, const char *mode);
extern FILE *xfopen(const char *path, const char *mode); extern FILE *xfopen(const char *path, const char *mode);
extern void chomp(char *s);
#ifndef DMALLOC #ifndef DMALLOC
extern void *xmalloc (size_t size); extern void *xmalloc (size_t size);

View File

@ -436,8 +436,7 @@ static void load_cmd_file(char *filename)
} }
/* eat trailing newline (if any) --if I don't do this, edit commands /* eat trailing newline (if any) --if I don't do this, edit commands
* (aic) will print an extra newline */ * (aic) will print an extra newline */
if (line[strlen(line)-1] == '\n') chomp(line);
line[strlen(line)-1] = 0;
add_cmd_str(line); add_cmd_str(line);
free(line); free(line);
} }

View File

@ -69,8 +69,7 @@ static void grep_file(FILE *file)
int nmatches = 0; int nmatches = 0;
while ((line = get_line_from_file(file)) != NULL) { while ((line = get_line_from_file(file)) != NULL) {
if (line[strlen(line)-1] == '\n') chomp(line);
line[strlen(line)-1] = '\0';
linenum++; linenum++;
ret = regexec(&regex, line, 0, NULL, 0); ret = regexec(&regex, line, 0, NULL, 0);
if (ret == 0 && !invert_search) { /* match */ if (ret == 0 && !invert_search) { /* match */

View File

@ -68,8 +68,7 @@ int xargs_main(int argc, char **argv)
char *execstr = NULL; char *execstr = NULL;
/* eat the newline off the filename. */ /* eat the newline off the filename. */
if (file_to_act_on[strlen(file_to_act_on)-1] == '\n') chomp(file_to_act_on);
file_to_act_on[strlen(file_to_act_on)-1] = '\0';
/* eat blank lines */ /* eat blank lines */
if (strlen(file_to_act_on) == 0) if (strlen(file_to_act_on) == 0)

3
grep.c
View File

@ -69,8 +69,7 @@ static void grep_file(FILE *file)
int nmatches = 0; int nmatches = 0;
while ((line = get_line_from_file(file)) != NULL) { while ((line = get_line_from_file(file)) != NULL) {
if (line[strlen(line)-1] == '\n') chomp(line);
line[strlen(line)-1] = '\0';
linenum++; linenum++;
ret = regexec(&regex, line, 0, NULL, 0); ret = regexec(&regex, line, 0, NULL, 0);
if (ret == 0 && !invert_search) { /* match */ if (ret == 0 && !invert_search) { /* match */

View File

@ -1,6 +1,6 @@
/* vi: set sw=4 ts=4: */ /* vi: set sw=4 ts=4: */
/* /*
* $Id: hostname.c,v 1.22 2001/01/31 19:00:20 kraai Exp $ * $Id: hostname.c,v 1.23 2001/02/01 16:49:29 kraai Exp $
* Mini hostname implementation for busybox * Mini hostname implementation for busybox
* *
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org> * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@ -49,8 +49,7 @@ void do_sethostname(char *s, int isfile)
f = xfopen(s, "r"); f = xfopen(s, "r");
fgets(buf, 255, f); fgets(buf, 255, f);
fclose(f); fclose(f);
if (buf[strlen(buf) - 1] == '\n') chomp(buf);
buf[strlen(buf) - 1] = 0;
if (sethostname(buf, strlen(buf)) < 0) if (sethostname(buf, strlen(buf)) < 0)
perror_msg_and_die("sethostname"); perror_msg_and_die("sethostname");
} }

View File

@ -152,6 +152,7 @@ extern char process_escape_sequence(char **ptr);
extern char *get_last_path_component(char *path); extern char *get_last_path_component(char *path);
extern FILE *wfopen(const char *path, const char *mode); extern FILE *wfopen(const char *path, const char *mode);
extern FILE *xfopen(const char *path, const char *mode); extern FILE *xfopen(const char *path, const char *mode);
extern void chomp(char *s);
#ifndef DMALLOC #ifndef DMALLOC
extern void *xmalloc (size_t size); extern void *xmalloc (size_t size);

View File

@ -1,6 +1,6 @@
/* vi: set sw=4 ts=4: */ /* vi: set sw=4 ts=4: */
/* /*
* $Id: hostname.c,v 1.22 2001/01/31 19:00:20 kraai Exp $ * $Id: hostname.c,v 1.23 2001/02/01 16:49:29 kraai Exp $
* Mini hostname implementation for busybox * Mini hostname implementation for busybox
* *
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org> * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@ -49,8 +49,7 @@ void do_sethostname(char *s, int isfile)
f = xfopen(s, "r"); f = xfopen(s, "r");
fgets(buf, 255, f); fgets(buf, 255, f);
fclose(f); fclose(f);
if (buf[strlen(buf) - 1] == '\n') chomp(buf);
buf[strlen(buf) - 1] = 0;
if (sethostname(buf, strlen(buf)) < 0) if (sethostname(buf, strlen(buf)) < 0)
perror_msg_and_die("sethostname"); perror_msg_and_die("sethostname");
} }

View File

@ -216,6 +216,7 @@ int wget_main(int argc, char **argv)
/*FALLTHRU*/ /*FALLTHRU*/
default: default:
close_and_delete_outfile(output, fname_out, do_continue); close_and_delete_outfile(output, fname_out, do_continue);
chomp(buf);
error_msg_and_die("server returned error %d: %s", atoi(s), buf); error_msg_and_die("server returned error %d: %s", atoi(s), buf);
} }
@ -532,7 +533,7 @@ progressmeter(int flag)
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: wget.c,v 1.25 2001/01/31 19:00:21 kraai Exp $ * $Id: wget.c,v 1.26 2001/02/01 16:49:30 kraai Exp $
*/ */

3
sed.c
View File

@ -436,8 +436,7 @@ static void load_cmd_file(char *filename)
} }
/* eat trailing newline (if any) --if I don't do this, edit commands /* eat trailing newline (if any) --if I don't do this, edit commands
* (aic) will print an extra newline */ * (aic) will print an extra newline */
if (line[strlen(line)-1] == '\n') chomp(line);
line[strlen(line)-1] = 0;
add_cmd_str(line); add_cmd_str(line);
free(line); free(line);
} }

3
tar.c
View File

@ -274,8 +274,7 @@ extern int tar_main(int argc, char **argv)
while (fgets(file, sizeof(file), fileList) != NULL) { while (fgets(file, sizeof(file), fileList) != NULL) {
excludeList = xrealloc(excludeList, excludeList = xrealloc(excludeList,
sizeof(char *) * (excludeListSize+2)); sizeof(char *) * (excludeListSize+2));
if (file[strlen(file)-1] == '\n') chomp(file);
file[strlen(file)-1] = '\0';
excludeList[excludeListSize] = xstrdup(file); excludeList[excludeListSize] = xstrdup(file);
/* Tack a NULL onto the end of the list */ /* Tack a NULL onto the end of the list */
excludeList[++excludeListSize] = NULL; excludeList[++excludeListSize] = NULL;

View File

@ -1760,6 +1760,19 @@ char *format(unsigned long val, unsigned long hr)
} }
#endif #endif
#if defined(BB_GREP) || defined(BB_HOSTNAME) || defined(BB_SED) || defined(BB_TAR) || defined(BB_WGET) || defined(BB_XARGS)
void chomp(char *s)
{
size_t len = strlen(s);
if (len == 0)
return;
if (s[len-1] == '\n')
s[len-1] = '\0';
}
#endif
/* END CODE */ /* END CODE */
/* /*
Local Variables: Local Variables:

3
wget.c
View File

@ -216,6 +216,7 @@ int wget_main(int argc, char **argv)
/*FALLTHRU*/ /*FALLTHRU*/
default: default:
close_and_delete_outfile(output, fname_out, do_continue); close_and_delete_outfile(output, fname_out, do_continue);
chomp(buf);
error_msg_and_die("server returned error %d: %s", atoi(s), buf); error_msg_and_die("server returned error %d: %s", atoi(s), buf);
} }
@ -532,7 +533,7 @@ progressmeter(int flag)
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: wget.c,v 1.25 2001/01/31 19:00:21 kraai Exp $ * $Id: wget.c,v 1.26 2001/02/01 16:49:30 kraai Exp $
*/ */

View File

@ -68,8 +68,7 @@ int xargs_main(int argc, char **argv)
char *execstr = NULL; char *execstr = NULL;
/* eat the newline off the filename. */ /* eat the newline off the filename. */
if (file_to_act_on[strlen(file_to_act_on)-1] == '\n') chomp(file_to_act_on);
file_to_act_on[strlen(file_to_act_on)-1] = '\0';
/* eat blank lines */ /* eat blank lines */
if (strlen(file_to_act_on) == 0) if (strlen(file_to_act_on) == 0)