1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

Avoid unnecessary vars, and make wgetrc_file_name build properly on Windows.

This commit is contained in:
Micah Cowan 2008-09-09 10:20:21 -07:00
parent abeb6c4a9e
commit a38d9e7e7a
4 changed files with 49 additions and 30 deletions

View File

@ -1,5 +1,12 @@
2008-09-09 Micah Cowan <micah@cowan.name>
* init.c (home_dir): Save the calculated value for home,
to avoid duplicated work on repeated calls.
(wgetrc_file_name) [WINDOWS]: Define and initialize home var.
* build_info.c: Remove unnecessary extern vars system_wgetrc and
locale_dir.
* main.c: Define program_name for lib/error.c.
2008-09-02 Gisle Vanem <gvanem@broadpark.no>

View File

@ -33,9 +33,6 @@ as that of the covered work. */
#include "wget.h"
#include <stdio.h>
char *system_wgetrc = SYSTEM_WGETRC;
char *locale_dir = LOCALEDIR;
const char* (compiled_features[]) =
{

View File

@ -338,35 +338,41 @@ defaults (void)
char *
home_dir (void)
{
char *home = getenv ("HOME");
static char buf[PATH_MAX];
static char *home;
if (!home)
{
home = getenv ("HOME");
if (!home)
{
#if defined(MSDOS)
/* Under MSDOS, if $HOME isn't defined, use the directory where
`wget.exe' resides. */
const char *_w32_get_argv0 (void); /* in libwatt.a/pcconfig.c */
char *p, buf[PATH_MAX];
/* Under MSDOS, if $HOME isn't defined, use the directory where
`wget.exe' resides. */
const char *_w32_get_argv0 (void); /* in libwatt.a/pcconfig.c */
char *p;
strcpy (buf, _w32_get_argv0 ());
p = strrchr (buf, '/'); /* djgpp */
if (!p)
p = strrchr (buf, '\\'); /* others */
assert (p);
*p = '\0';
home = buf;
strcpy (buf, _w32_get_argv0 ());
p = strrchr (buf, '/'); /* djgpp */
if (!p)
p = strrchr (buf, '\\'); /* others */
assert (p);
*p = '\0';
home = buf;
#elif !defined(WINDOWS)
/* If HOME is not defined, try getting it from the password
file. */
struct passwd *pwd = getpwuid (getuid ());
if (!pwd || !pwd->pw_dir)
return NULL;
home = pwd->pw_dir;
/* If HOME is not defined, try getting it from the password
file. */
struct passwd *pwd = getpwuid (getuid ());
if (!pwd || !pwd->pw_dir)
return NULL;
strcpy (buf, pwd->pw_dir);
home = buf;
#else /* !WINDOWS */
/* Under Windows, if $HOME isn't defined, use the directory where
`wget.exe' resides. */
home = ws_mypath ();
/* Under Windows, if $HOME isn't defined, use the directory where
`wget.exe' resides. */
home = ws_mypath ();
#endif /* WINDOWS */
}
}
return home ? xstrdup (home) : NULL;
@ -392,12 +398,13 @@ wgetrc_env_file_name (void)
}
return NULL;
}
/* Check for the existance of '$HOME/.wgetrc' and return it's path
if it exists and is set. */
char *
wgetrc_user_file_name (void)
{
char *home = home_dir();
char *home = home_dir ();
char *file = NULL;
if (home)
file = aprintf ("%s/.wgetrc", home);
@ -411,6 +418,7 @@ wgetrc_user_file_name (void)
}
return file;
}
/* Return the path to the user's .wgetrc. This is either the value of
`WGETRC' environment variable, or `$HOME/.wgetrc'.
@ -419,6 +427,7 @@ wgetrc_user_file_name (void)
char *
wgetrc_file_name (void)
{
char *home = NULL;
char *file = wgetrc_env_file_name ();
if (file && *file)
return file;
@ -430,6 +439,7 @@ wgetrc_file_name (void)
`wget.ini' in the directory where `wget.exe' resides; we do this for
backward compatibility with previous versions of Wget.
SYSTEM_WGETRC should not be defined under WINDOWS. */
home = home_dir ();
if (!file || !file_exists_p (file))
{
xfree_null (file);
@ -438,6 +448,7 @@ wgetrc_file_name (void)
if (home)
file = aprintf ("%s/wget.ini", home);
}
xfree_null (home);
#endif /* WINDOWS */
if (!file)

View File

@ -72,8 +72,6 @@ extern char *system_getrc;
extern char *link_string;
/* defined in build_info.c */
extern char *compiled_features[];
extern char *system_wgetrc;
extern char *locale_dir;
/* Used for --version output in print_version */
static const int max_chars_per_line = 72;
@ -743,6 +741,10 @@ format_and_print_line (char* prefix, char* line,
}
printf ("\n");
/* FIXME: Responsibility for deallocation should be handled by
whatever allocated it, wherever possible. These two lines result
in unnecessary strdup calls in the print_version function. */
xfree (prefix);
xfree (line);
}
@ -794,10 +796,12 @@ print_version (void)
printf ("%s (user)\n%s", user_wgetrc, prefix_spaces);
xfree (user_wgetrc);
}
printf ("%s (system)\n", system_wgetrc);
#ifdef SYSTEM_WGETRC
printf ("%s (system)\n", SYSTEM_WGETRC);
#endif
format_and_print_line (strdup (locale_title),
strdup (locale_dir),
strdup (LOCALEDIR),
max_chars_per_line);
format_and_print_line (strdup (compile_title),