zdump.c (2703) | zdump.c (9937) |
---|---|
1#ifndef lint 2#ifndef NOID | 1#ifndef lint 2#ifndef NOID |
3static char elsieid[] = "@(#)zdump.c 7.10"; | 3static char elsieid[] = "@(#)zdump.c 7.20"; |
4#endif /* !defined NOID */ 5#endif /* !defined lint */ 6 7/* 8** This code has been made independent of the rest of the time 9** conversion package to increase confidence in the verification it provides. 10** You can use this code to help in verifying other implementations. 11*/ 12 | 4#endif /* !defined NOID */ 5#endif /* !defined lint */ 6 7/* 8** This code has been made independent of the rest of the time 9** conversion package to increase confidence in the verification it provides. 10** You can use this code to help in verifying other implementations. 11*/ 12 |
13#include "stdio.h" /* for stdout, stderr */ | 13#include "stdio.h" /* for stdout, stderr, perror */ |
14#include "string.h" /* for strcpy */ 15#include "sys/types.h" /* for time_t */ 16#include "time.h" /* for struct tm */ | 14#include "string.h" /* for strcpy */ 15#include "sys/types.h" /* for time_t */ 16#include "time.h" /* for struct tm */ |
17#include "stdlib.h" /* for exit, malloc, atoi */ |
|
17 18#ifndef MAX_STRING_LENGTH 19#define MAX_STRING_LENGTH 1024 20#endif /* !defined MAX_STRING_LENGTH */ 21 22#ifndef TRUE 23#define TRUE 1 24#endif /* !defined TRUE */ --- 37 unchanged lines hidden (view full) --- 62#ifndef DAYSPERNYEAR 63#define DAYSPERNYEAR 365 64#endif /* !defined DAYSPERNYEAR */ 65 66#ifndef isleap 67#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0) 68#endif /* !defined isleap */ 69 | 18 19#ifndef MAX_STRING_LENGTH 20#define MAX_STRING_LENGTH 1024 21#endif /* !defined MAX_STRING_LENGTH */ 22 23#ifndef TRUE 24#define TRUE 1 25#endif /* !defined TRUE */ --- 37 unchanged lines hidden (view full) --- 63#ifndef DAYSPERNYEAR 64#define DAYSPERNYEAR 365 65#endif /* !defined DAYSPERNYEAR */ 66 67#ifndef isleap 68#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0) 69#endif /* !defined isleap */ 70 |
71#ifndef GNUC_or_lint 72#ifdef lint 73#define GNUC_or_lint 74#endif /* defined lint */ 75#ifndef lint 76#ifdef __GNUC__ 77#define GNUC_or_lint 78#endif /* defined __GNUC__ */ 79#endif /* !defined lint */ 80#endif /* !defined GNUC_or_lint */ 81 82#ifndef INITIALIZE 83#ifdef GNUC_or_lint 84#define INITIALIZE(x) ((x) = 0) 85#endif /* defined GNUC_or_lint */ 86#ifndef GNUC_or_lint 87#define INITIALIZE(x) 88#endif /* !defined GNUC_or_lint */ 89#endif /* !defined INITIALIZE */ 90 |
|
70extern char ** environ; 71extern int getopt(); 72extern char * optarg; 73extern int optind; 74extern time_t time(); 75extern char * tzname[2]; | 91extern char ** environ; 92extern int getopt(); 93extern char * optarg; 94extern int optind; 95extern time_t time(); 96extern char * tzname[2]; |
76extern void tzset(); | |
77 | 97 |
78#ifdef USG 79extern void exit(); 80extern void perror(); 81#endif /* defined USG */ 82 | |
83static char * abbr(); 84static long delta(); 85static time_t hunt(); 86static int longest; 87static char * progname; 88static void show(); 89 90int 91main(argc, argv) 92int argc; 93char * argv[]; 94{ | 98static char * abbr(); 99static long delta(); 100static time_t hunt(); 101static int longest; 102static char * progname; 103static void show(); 104 105int 106main(argc, argv) 107int argc; 108char * argv[]; 109{ |
95 register int i, c; 96 register int vflag; 97 register char * cutoff; 98 register int cutyear; 99 register long cuttime; 100 time_t now; 101 time_t t, newt; 102 time_t hibit; 103 struct tm tm, newtm; | 110 register int i; 111 register int c; 112 register int vflag; 113 register char * cutoff; 114 register int cutyear; 115 register long cuttime; 116 char ** fakeenv; 117 time_t now; 118 time_t t; 119 time_t newt; 120 time_t hibit; 121 struct tm tm; 122 struct tm newtm; |
104 | 123 |
124 INITIALIZE(cuttime); |
|
105 progname = argv[0]; 106 vflag = 0; 107 cutoff = NULL; 108 while ((c = getopt(argc, argv, "c:v")) == 'c' || c == 'v') 109 if (c == 'v') 110 vflag = 1; 111 else cutoff = optarg; 112 if (c != EOF || --- 14 unchanged lines hidden (view full) --- 127 } 128 (void) time(&now); 129 longest = 0; 130 for (i = optind; i < argc; ++i) 131 if (strlen(argv[i]) > longest) 132 longest = strlen(argv[i]); 133 for (hibit = 1; (hibit << 1) != 0; hibit <<= 1) 134 continue; | 125 progname = argv[0]; 126 vflag = 0; 127 cutoff = NULL; 128 while ((c = getopt(argc, argv, "c:v")) == 'c' || c == 'v') 129 if (c == 'v') 130 vflag = 1; 131 else cutoff = optarg; 132 if (c != EOF || --- 14 unchanged lines hidden (view full) --- 147 } 148 (void) time(&now); 149 longest = 0; 150 for (i = optind; i < argc; ++i) 151 if (strlen(argv[i]) > longest) 152 longest = strlen(argv[i]); 153 for (hibit = 1; (hibit << 1) != 0; hibit <<= 1) 154 continue; |
135 for (i = optind; i < argc; ++i) { 136 register char ** saveenv; 137 static char buf[MAX_STRING_LENGTH]; 138 char * fakeenv[2]; | 155 { 156 register int from; 157 register int to; |
139 | 158 |
140 if (strlen(argv[i]) + 4 > sizeof buf) { 141 (void) fflush(stdout); 142 (void) fprintf(stderr, "%s: argument too long -- %s\n", 143 progname, argv[i]); 144 (void) exit(EXIT_FAILURE); | 159 for (i = 0; environ[i] != NULL; ++i) 160 continue; 161 fakeenv = (char **) malloc((size_t) ((i + 2) * 162 sizeof *fakeenv)); 163 if (fakeenv == NULL || 164 (fakeenv[0] = (char *) malloc((size_t) (longest + 165 4))) == NULL) { 166 (void) perror(progname); 167 (void) exit(EXIT_FAILURE); |
145 } | 168 } |
146 (void) strcpy(buf, "TZ="); 147 (void) strcat(buf, argv[i]); 148 fakeenv[0] = buf; 149 fakeenv[1] = NULL; 150 saveenv = environ; | 169 to = 0; 170 (void) strcpy(fakeenv[to++], "TZ="); 171 for (from = 0; environ[from] != NULL; ++from) 172 if (strncmp(environ[from], "TZ=", 3) != 0) 173 fakeenv[to++] = environ[from]; 174 fakeenv[to] = NULL; |
151 environ = fakeenv; | 175 environ = fakeenv; |
152 (void) tzset(); 153 environ = saveenv; | 176 } 177 for (i = optind; i < argc; ++i) { 178 static char buf[MAX_STRING_LENGTH]; 179 180 (void) strcpy(&fakeenv[0][3], argv[i]); |
154 show(argv[i], now, FALSE); 155 if (!vflag) 156 continue; 157 /* 158 ** Get lowest value of t. 159 */ 160 t = hibit; 161 if (t > 0) /* time_t is unsigned */ --- 101 unchanged lines hidden (view full) --- 263 result += newp->tm_hour - oldp->tm_hour; 264 result *= MINSPERHOUR; 265 result += newp->tm_min - oldp->tm_min; 266 result *= SECSPERMIN; 267 result += newp->tm_sec - oldp->tm_sec; 268 return result; 269} 270 | 181 show(argv[i], now, FALSE); 182 if (!vflag) 183 continue; 184 /* 185 ** Get lowest value of t. 186 */ 187 t = hibit; 188 if (t > 0) /* time_t is unsigned */ --- 101 unchanged lines hidden (view full) --- 290 result += newp->tm_hour - oldp->tm_hour; 291 result *= MINSPERHOUR; 292 result += newp->tm_min - oldp->tm_min; 293 result *= SECSPERMIN; 294 result += newp->tm_sec - oldp->tm_sec; 295 return result; 296} 297 |
298extern struct tm * localtime(); 299 |
|
271static void 272show(zone, t, v) 273char * zone; 274time_t t; 275int v; 276{ | 300static void 301show(zone, t, v) 302char * zone; 303time_t t; 304int v; 305{ |
277 struct tm * tmp; 278 extern struct tm * localtime(); | 306 struct tm * tmp; |
279 280 (void) printf("%-*s ", longest, zone); 281 if (v) 282 (void) printf("%.24s GMT = ", asctime(gmtime(&t))); 283 tmp = localtime(&t); 284 (void) printf("%.24s", asctime(tmp)); 285 if (*abbr(tmp) != '\0') 286 (void) printf(" %s", abbr(tmp)); --- 6 unchanged lines hidden (view full) --- 293 (void) printf("\n"); 294} 295 296static char * 297abbr(tmp) 298struct tm * tmp; 299{ 300 register char * result; | 307 308 (void) printf("%-*s ", longest, zone); 309 if (v) 310 (void) printf("%.24s GMT = ", asctime(gmtime(&t))); 311 tmp = localtime(&t); 312 (void) printf("%.24s", asctime(tmp)); 313 if (*abbr(tmp) != '\0') 314 (void) printf(" %s", abbr(tmp)); --- 6 unchanged lines hidden (view full) --- 321 (void) printf("\n"); 322} 323 324static char * 325abbr(tmp) 326struct tm * tmp; 327{ 328 register char * result; |
301 static char nada[1]; | 329 static char nada; |
302 303 if (tmp->tm_isdst != 0 && tmp->tm_isdst != 1) | 330 331 if (tmp->tm_isdst != 0 && tmp->tm_isdst != 1) |
304 return nada; | 332 return &nada; |
305 result = tzname[tmp->tm_isdst]; | 333 result = tzname[tmp->tm_isdst]; |
306 return (result == NULL) ? nada : result; | 334 return (result == NULL) ? &nada : result; |
307} | 335} |