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> 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. * main.c: Define program_name for lib/error.c.
2008-09-02 Gisle Vanem <gvanem@broadpark.no> 2008-09-02 Gisle Vanem <gvanem@broadpark.no>

View File

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

View File

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

View File

@ -72,8 +72,6 @@ extern char *system_getrc;
extern char *link_string; extern char *link_string;
/* defined in build_info.c */ /* defined in build_info.c */
extern char *compiled_features[]; extern char *compiled_features[];
extern char *system_wgetrc;
extern char *locale_dir;
/* Used for --version output in print_version */ /* Used for --version output in print_version */
static const int max_chars_per_line = 72; static const int max_chars_per_line = 72;
@ -743,6 +741,10 @@ format_and_print_line (char* prefix, char* line,
} }
printf ("\n"); 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 (prefix);
xfree (line); xfree (line);
} }
@ -794,10 +796,12 @@ print_version (void)
printf ("%s (user)\n%s", user_wgetrc, prefix_spaces); printf ("%s (user)\n%s", user_wgetrc, prefix_spaces);
xfree (user_wgetrc); 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), format_and_print_line (strdup (locale_title),
strdup (locale_dir), strdup (LOCALEDIR),
max_chars_per_line); max_chars_per_line);
format_and_print_line (strdup (compile_title), format_and_print_line (strdup (compile_title),