Adds build information to the --version command line option.

This commit is contained in:
Madhusudan Hosaagrahara 2008-05-05 23:14:25 -07:00
parent 54097c0e28
commit 5e7f976fa1
6 changed files with 282 additions and 27 deletions

View File

@ -1,3 +1,8 @@
2008-05-02 Madhusudan Hosaagrahara <com.gmail.hrmadhu>
* src/Makefile.am, src/main.c, src/init.c, src/init.h,
src/build_info.c: Adds build information to the --version
command line option. Fixes bug #20636.
2008-04-30 Micah Cowan <micah@cowan.name>
* progress.c (create_image): Fix glitch where too many spaces are

View File

@ -35,25 +35,32 @@ DEFS = @DEFS@ -DSYSTEM_WGETRC=\"$(sysconfdir)/wgetrc\" -DLOCALEDIR=\"$(local
LIBS = @LIBSSL@ @LIBGNUTLS@ @LIBINTL@ @LIBS@
bin_PROGRAMS = wget
wget_SOURCES = cmpt.c connect.c convert.c cookies.c ftp.c ftp-basic.c \
ftp-ls.c hash.c host.c html-parse.c html-url.c http.c \
init.c log.c main.c netrc.c progress.c ptimer.c recur.c \
res.c retr.c snprintf.c spider.c url.c \
utils.c xmalloc.c \
connect.h convert.h cookies.h \
ftp.h gen-md5.h hash.h host.h html-parse.h \
http.h http-ntlm.h init.h log.h mswindows.h netrc.h \
options.h progress.h ptimer.h recur.h res.h retr.h \
wget_SOURCES = build_info.c cmpt.c connect.c convert.c cookies.c ftp.c \
ftp-basic.c ftp-ls.c hash.c host.c html-parse.c html-url.c \
http.c init.c log.c main.c netrc.c progress.c ptimer.c \
recur.c res.c retr.c snprintf.c spider.c url.c \
utils.c xmalloc.c \
connect.h convert.h cookies.h \
ftp.h gen-md5.h hash.h host.h html-parse.h \
http.h http-ntlm.h init.h log.h mswindows.h netrc.h \
options.h progress.h ptimer.h recur.h res.h retr.h \
spider.h ssl.h sysdep.h url.h utils.h wget.h xmalloc.h
nodist_wget_SOURCES = version.c
EXTRA_wget_SOURCES = mswindows.c
LDADD = $(ALLOCA) $(LIBOBJS) ../lib/libgnu.a @MD5_LDADD@
AM_CPPFLAGS = -I$(top_srcdir)/lib @MD5_CPPFLAGS@
ESCAPEQUOTE = sed -e 's/[\\"]/\\&/g' -e 's/\\"/"/' -e 's/\\";$$/";/'
version.c: $(wget_SOURCES) $(LDADD) $(srcdir)/Makefile.am
echo 'const char *version_string = "@VERSION@"' > $@
-hg log -r . --template='" ({node|short})"\n' 2>/dev/null >> $@
echo '/* version.c */' > $@
echo '/* Autogenerated by Makefile - DO NOT EDIT */' >> $@
echo '' >> $@
echo -n 'char* version_string = "@VERSION@ ' >> $@
-hg log -r . --template=' ({node|short})"\n' 2>/dev/null >> $@
echo ';' >> $@
echo 'char* compilation_string = "'$(COMPILE)'";' | $(ESCAPEQUOTE) >> $@
echo 'char* link_string = "'$(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) $(LIBS) $(wget_LDADD)'";' | $(ESCAPEQUOTE) >> $@
check_LIBRARIES = libunittest.a
libunittest_a_SOURCES = $(wget_SOURCES) test.c test.h

107
src/build_info.c Normal file
View File

@ -0,0 +1,107 @@
/* This stores global variables that are initialized with
preprocessor declarations for output with the --version flag.
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
This file is part of GNU Wget.
GNU Wget is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
GNU Wget is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Wget. If not, see <http://www.gnu.org/licenses/>.
Additional permission under GNU GPL version 3 section 7
If you modify this program, or any covered work, by linking or
combining it with the OpenSSL project's OpenSSL library (or a
modified version of that library), containing parts covered by the
terms of the OpenSSL or SSLeay licenses, the Free Software Foundation
grants you additional permission to convey the resulting work.
Corresponding Source for a non-source form of such a combination
shall include the source code for the parts of OpenSSL used as well
as that of the covered work. */
#include "config.h"
#include <stdio.h>
char *system_wgetrc = SYSTEM_WGETRC;
char *locale_dir = LOCALEDIR;
const char* (compiled_features[]) =
{
#ifdef ENABLE_DIGEST
"+digest",
#else
"-digest",
#endif
#ifdef ENABLE_IPV6
"+ipv6",
#else
"-ipv6",
#endif
#ifdef ENABLE_NLS
"+nls",
#else
"-nls",
#endif
#ifdef HAVE_NTLM
"+ntlm",
#else
"-ntlm",
#endif
#ifdef ENABLE_OPIE
"+opie",
#else
"-opie",
#endif
#ifdef HAVE_MD5
#ifdef HAVE_BUILTIN_MD5
"+md5/builtin",
#elif HAVE_OPENSSL_MD5
"+md5/openssl",
#elif HAVE_SOLARIS_MD5
"+md5/solaris",
#else
#error "md5 set, but no library found!",
#endif
#else
"-md5",
#endif
#ifdef HAVE_LIBGNUTLS
"+gnutls",
#else
"-gnutls",
#endif
#ifdef HAVE_LIBSSL
"+ssl",
#else
"-ssl",
#endif
#ifdef HAVE_GETTEXT
"+gettext",
#else
"-gettext",
#endif
/* sentinel value */
NULL
};

View File

@ -369,19 +369,14 @@ home_dir (void)
return home ? xstrdup (home) : NULL;
}
/* Return the path to the user's .wgetrc. This is either the value of
`WGETRC' environment variable, or `$HOME/.wgetrc'.
/* Check the 'WGETRC' environment variable and return the file name
if 'WGETRC' is set and is a valid file.
If the `WGETRC' variable exists but the file does not exist, the
function will exit(). */
static char *
wgetrc_file_name (void)
char *
wgetrc_env_file_name (void)
{
char *env, *home;
char *file = NULL;
/* Try the environment. */
env = getenv ("WGETRC");
char *env = getenv ("WGETRC");
if (env && *env)
{
if (!file_exists_p (env))
@ -392,12 +387,40 @@ wgetrc_file_name (void)
}
return xstrdup (env);
}
/* If that failed, try $HOME/.wgetrc. */
home = home_dir ();
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 *file = NULL;
if (home)
file = aprintf ("%s/.wgetrc", home);
xfree_null (home);
if (!file)
return NULL;
if (!file_exists_p (file))
{
xfree (file);
return NULL;
}
return file;
}
/* Return the path to the user's .wgetrc. This is either the value of
`WGETRC' environment variable, or `$HOME/.wgetrc'.
Additionally, for windows, look in the directory where wget.exe
resides. */
char *
wgetrc_file_name (void)
{
char *file = wgetrc_env_file_name ();
if (file && *file)
return file;
file = wgetrc_user_file_name ();
#ifdef WINDOWS
/* Under Windows, if we still haven't found .wgetrc, look for the file
@ -538,7 +561,7 @@ initialize (void)
xfree (file);
return;
}
/* Remove dashes and underscores from S, modifying S in the
process. */

View File

@ -31,6 +31,9 @@ as that of the covered work. */
#ifndef INIT_H
#define INIT_H
char *wgetrc_env_file_name (void);
char *wgetrc_user_file_name (void);
char *wgetrc_file_name (void);
void initialize (void);
void run_command (const char *);
void setoptval (const char *, const char *, const char *);

View File

@ -63,7 +63,17 @@ as that of the covered work. */
struct options opt;
/* defined in version.c */
extern char *version_string;
extern char *compilation_string;
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;
#if defined(SIGHUP) || defined(SIGUSR1)
static void redirect_output_signal (int);
@ -673,10 +683,111 @@ secs_to_human_time (double interval)
return buf;
}
/* Function that prints the line argument while limiting it
to at most line_length. prefix is printed on the first line
and an appropriate number of spaces are added on subsequent
lines.*/
static void
format_and_print_line (char* prefix, char* line,
int line_length)
{
assert (prefix != NULL);
assert (line != NULL);
if (line_length <= 0)
line_length = max_chars_per_line;
const int leading_spaces = strlen (prefix);
printf ("%s", prefix);
int remaining_chars = line_length - leading_spaces;
/* We break on spaces. */
char* token = strtok (line, " ");
while (token != NULL)
{
/* If however a token is much larger than the maximum
line length, all bets are off and we simply print the
token on the next line. */
if (remaining_chars <= strlen (token))
{
printf ("\n");
int j = 0;
for (j = 0; j < leading_spaces; j++)
{
printf (" ");
}
remaining_chars = line_length - leading_spaces;
}
printf ("%s ", token);
remaining_chars -= strlen (token) + 1; // account for " "
token = strtok (NULL, " ");
}
printf ("\n");
xfree (prefix);
xfree (line);
}
static void
print_version (void)
{
printf ("GNU Wget %s\n\n", version_string);
const char *options_title = "Options : ";
const char *wgetrc_title = "Wgetrc : ";
const char *locale_title = "Locale : ";
const char *compile_title = "Compile : ";
const char *link_title = "Link : ";
const char *prefix_spaces = " ";
const int prefix_space_length = strlen (prefix_spaces);
printf ("GNU Wget %s\n", version_string);
printf (options_title);
/* compiled_features is a char*[]. We limit the characters per
line to max_chars_per_line and prefix each line with a constant
number of spaces for proper alignment. */
int i =0;
for (i = 0; compiled_features[i] != NULL; )
{
int line_length = max_chars_per_line - prefix_space_length;
while ((line_length > 0) && (compiled_features[i] != NULL))
{
printf ("%s ", compiled_features[i]);
line_length -= strlen (compiled_features[i]) + 2;
i++;
}
printf ("\n");
if (compiled_features[i] != NULL)
{
printf (prefix_spaces);
}
}
/* Handle the case when $WGETRC is unset and $HOME/.wgetrc is
absent. */
printf (wgetrc_title);
char *env_wgetrc = wgetrc_env_file_name ();
if (env_wgetrc && *env_wgetrc)
{
printf ("%s (env)\n%s", env_wgetrc, prefix_spaces);
xfree (env_wgetrc);
}
char *user_wgetrc = wgetrc_user_file_name ();
if (user_wgetrc)
{
printf ("%s (user)\n%s", user_wgetrc, prefix_spaces);
xfree (user_wgetrc);
}
printf ("%s (system)\n", system_wgetrc);
format_and_print_line (strdup (locale_title),
strdup (locale_dir),
max_chars_per_line);
format_and_print_line (strdup (compile_title),
strdup (compilation_string),
max_chars_per_line);
format_and_print_line (strdup (link_title),
strdup (link_string),
max_chars_per_line);
printf ("\n");
/* TRANSLATORS: When available, an actual copyright character
(cirle-c) should be used in preference to "(C)". */
fputs (_("\
@ -694,7 +805,6 @@ There is NO WARRANTY, to the extent permitted by law.\n"), stdout);
stdout);
exit (0);
}
int
main (int argc, char **argv)