summaryrefslogtreecommitdiffstats
path: root/usr.sbin/zic/zdump.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/zic/zdump.c')
-rw-r--r--usr.sbin/zic/zdump.c149
1 files changed, 104 insertions, 45 deletions
diff --git a/usr.sbin/zic/zdump.c b/usr.sbin/zic/zdump.c
index 1e44d4a..1058a84 100644
--- a/usr.sbin/zic/zdump.c
+++ b/usr.sbin/zic/zdump.c
@@ -1,6 +1,6 @@
#ifndef lint
#ifndef NOID
-static char elsieid[] = "@(#)zdump.c 7.10";
+static char elsieid[] = "@(#)zdump.c 7.24";
#endif /* !defined NOID */
#endif /* !defined lint */
@@ -10,10 +10,11 @@ static char elsieid[] = "@(#)zdump.c 7.10";
** You can use this code to help in verifying other implementations.
*/
-#include "stdio.h" /* for stdout, stderr */
+#include "stdio.h" /* for stdout, stderr, perror */
#include "string.h" /* for strcpy */
#include "sys/types.h" /* for time_t */
#include "time.h" /* for struct tm */
+#include "stdlib.h" /* for exit, malloc, atoi */
#ifndef MAX_STRING_LENGTH
#define MAX_STRING_LENGTH 1024
@@ -67,18 +68,55 @@ static char elsieid[] = "@(#)zdump.c 7.10";
#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
#endif /* !defined isleap */
+#if HAVE_GETTEXT - 0
+#include "locale.h" /* for setlocale */
+#include "libintl.h"
+#endif /* HAVE_GETTEXT - 0 */
+
+#ifndef GNUC_or_lint
+#ifdef lint
+#define GNUC_or_lint
+#endif /* defined lint */
+#ifndef lint
+#ifdef __GNUC__
+#define GNUC_or_lint
+#endif /* defined __GNUC__ */
+#endif /* !defined lint */
+#endif /* !defined GNUC_or_lint */
+
+#ifndef INITIALIZE
+#ifdef GNUC_or_lint
+#define INITIALIZE(x) ((x) = 0)
+#endif /* defined GNUC_or_lint */
+#ifndef GNUC_or_lint
+#define INITIALIZE(x)
+#endif /* !defined GNUC_or_lint */
+#endif /* !defined INITIALIZE */
+
+/*
+** For the benefit of GNU folk...
+** `_(MSGID)' uses the current locale's message library string for MSGID.
+** The default is to use gettext if available, and use MSGID otherwise.
+*/
+
+#ifndef _
+#if HAVE_GETTEXT - 0
+#define _(msgid) gettext(msgid)
+#else /* !(HAVE_GETTEXT - 0) */
+#define _(msgid) msgid
+#endif /* !(HAVE_GETTEXT - 0) */
+#endif /* !defined _ */
+
+#ifndef TZ_DOMAIN
+#define TZ_DOMAIN "tz"
+#endif /* !defined TZ_DOMAIN */
+
extern char ** environ;
extern int getopt();
extern char * optarg;
extern int optind;
extern time_t time();
extern char * tzname[2];
-extern void tzset();
-
-#ifdef USG
-extern void exit();
-extern void perror();
-#endif /* defined USG */
static char * abbr();
static long delta();
@@ -92,16 +130,28 @@ main(argc, argv)
int argc;
char * argv[];
{
- register int i, c;
- register int vflag;
- register char * cutoff;
- register int cutyear;
- register long cuttime;
- time_t now;
- time_t t, newt;
- time_t hibit;
- struct tm tm, newtm;
-
+ register int i;
+ register int c;
+ register int vflag;
+ register char * cutoff;
+ register int cutyear;
+ register long cuttime;
+ char ** fakeenv;
+ time_t now;
+ time_t t;
+ time_t newt;
+ time_t hibit;
+ struct tm tm;
+ struct tm newtm;
+
+ INITIALIZE(cuttime);
+#if HAVE_GETTEXT - 0
+ (void) setlocale(LC_MESSAGES, "");
+#ifdef TZ_DOMAINDIR
+ (void) bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR);
+#endif /* defined(TEXTDOMAINDIR) */
+ (void) textdomain(TZ_DOMAIN);
+#endif /* HAVE_GETTEXT - 0 */
progname = argv[0];
vflag = 0;
cutoff = NULL;
@@ -112,7 +162,7 @@ char * argv[];
if (c != EOF ||
(optind == argc - 1 && strcmp(argv[optind], "=") == 0)) {
(void) fprintf(stderr,
-"%s: usage is %s [ -v ] [ -c cutoff ] zonename ...\n",
+_("%s: usage is %s [ -v ] [ -c cutoff ] zonename ...\n"),
argv[0], argv[0]);
(void) exit(EXIT_FAILURE);
}
@@ -132,28 +182,36 @@ char * argv[];
longest = strlen(argv[i]);
for (hibit = 1; (hibit << 1) != 0; hibit <<= 1)
continue;
- for (i = optind; i < argc; ++i) {
- register char ** saveenv;
- static char buf[MAX_STRING_LENGTH];
- char * fakeenv[2];
-
- if (strlen(argv[i]) + 4 > sizeof buf) {
- (void) fflush(stdout);
- (void) fprintf(stderr, "%s: argument too long -- %s\n",
- progname, argv[i]);
- (void) exit(EXIT_FAILURE);
+ {
+ register int from;
+ register int to;
+
+ for (i = 0; environ[i] != NULL; ++i)
+ continue;
+ fakeenv = (char **) malloc((size_t) ((i + 2) *
+ sizeof *fakeenv));
+ if (fakeenv == NULL ||
+ (fakeenv[0] = (char *) malloc((size_t) (longest +
+ 4))) == NULL) {
+ (void) perror(progname);
+ (void) exit(EXIT_FAILURE);
}
- (void) strcpy(buf, "TZ=");
- (void) strcat(buf, argv[i]);
- fakeenv[0] = buf;
- fakeenv[1] = NULL;
- saveenv = environ;
+ to = 0;
+ (void) strcpy(fakeenv[to++], "TZ=");
+ for (from = 0; environ[from] != NULL; ++from)
+ if (strncmp(environ[from], "TZ=", 3) != 0)
+ fakeenv[to++] = environ[from];
+ fakeenv[to] = NULL;
environ = fakeenv;
- (void) tzset();
- environ = saveenv;
- show(argv[i], now, FALSE);
- if (!vflag)
+ }
+ for (i = optind; i < argc; ++i) {
+ static char buf[MAX_STRING_LENGTH];
+
+ (void) strcpy(&fakeenv[0][3], argv[i]);
+ if (!vflag) {
+ show(argv[i], now, FALSE);
continue;
+ }
/*
** Get lowest value of t.
*/
@@ -197,9 +255,9 @@ char * argv[];
show(argv[i], t, TRUE);
}
if (fflush(stdout) || ferror(stdout)) {
- (void) fprintf(stderr, "%s: Error writing standard output ",
+ (void) fprintf(stderr, _("%s: Error writing standard output "),
argv[0]);
- (void) perror("standard output");
+ (void) perror(_("standard output"));
(void) exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
@@ -268,14 +326,15 @@ struct tm * oldp;
return result;
}
+extern struct tm * localtime();
+
static void
show(zone, t, v)
char * zone;
time_t t;
int v;
{
- struct tm * tmp;
- extern struct tm * localtime();
+ struct tm * tmp;
(void) printf("%-*s ", longest, zone);
if (v)
@@ -298,10 +357,10 @@ abbr(tmp)
struct tm * tmp;
{
register char * result;
- static char nada[1];
+ static char nada;
if (tmp->tm_isdst != 0 && tmp->tm_isdst != 1)
- return nada;
+ return &nada;
result = tzname[tmp->tm_isdst];
- return (result == NULL) ? nada : result;
+ return (result == NULL) ? &nada : result;
}
OpenPOWER on IntegriCloud