static void show(timezone_t tz, char *zone, time_t t, bool v) { struct tm * tmp; struct tm * gmtmp; struct tm tm, gmtm; (void) printf("%-*s ", (int) longest, zone); if (v) { gmtmp = my_gmtime_r(&t, &gmtm); if (gmtmp == NULL) { printf(tformat(), t); } else { dumptime(gmtmp); (void) printf(" UT"); } (void) printf(" = "); } tmp = my_localtime_rz(tz, &t, &tm); dumptime(tmp); if (tmp != NULL) { if (*abbr(tmp) != '\0') (void) printf(" %s", abbr(tmp)); if (v) { long off = gmtoff(tmp, NULL, gmtmp); (void) printf(" isdst=%d", tmp->tm_isdst); if (off != LONG_MIN) (void) printf(" gmtoff=%ld", off); } } (void) printf("\n"); if (tmp != NULL && *abbr(tmp) != '\0') abbrok(abbr(tmp), zone); }
/* Store into BUF, of size SIZE, a formatted UTC offset for the localtime *TM corresponding to time T. Use ISO 8601 format +HH:MM:SS, or -HH:MM:SS for time stamps west of Greenwich. Omit :SS if :SS is zero, and omit :MM too if :MM is also zero. If the time stamp represents an unknown UTC offset, use the format -00. Return the length of the resulting string, or -1 if the result is not representable as a string. If the string does not fit, return the length that the string would have been if it had fit; do not overrun the output buffer. */ static int format_utc_offset(char *buf, size_t size, struct tm const *tm, time_t t) { long off = gmtoff(tm, &t, NULL); char sign = ((off < 0 || (off == 0 && (*abbr(tm) == '-' || strcmp(abbr(tm), "zzz") == 0))) ? '-' : '+'); long hh; int mm, ss; if (off < 0) { if (off == LONG_MIN) return -1; off = -off; } ss = off % 60; mm = off / 60 % 60; hh = off / 60 / 60; return (ss ? snprintf(buf, size, "%c%02ld:%02d:%02d", sign, hh, mm, ss) : mm ? snprintf(buf, size, "%c%02ld:%02d", sign, hh, mm) : snprintf(buf, size, "%c%02ld", sign, hh)); }
static void show(char *zone, time_t t, int v) { register struct tm * tmp; (void) printf("%-*s ", (int) longest, zone); if (v) { tmp = gmtime(&t); if (tmp == NULL) { (void) printf(tformat(), t); } else { dumptime(tmp); (void) printf(" UTC"); } (void) printf(" = "); } tmp = my_localtime(&t); dumptime(tmp); if (tmp != NULL) { if (*abbr(tmp) != '\0') (void) printf(" %s", abbr(tmp)); if (v) { (void) printf(" isdst=%d", tmp->tm_isdst); #ifdef TM_GMTOFF (void) printf(" gmtoff=%ld", tmp->TM_GMTOFF); #endif /* defined TM_GMTOFF */ } } (void) printf("\n"); if (tmp != NULL && *abbr(tmp) != '\0') abbrok(abbr(tmp), zone); }
static time_t hunt(char *name, time_t lot, time_t hit) { time_t t; long diff; struct tm lotm; register struct tm * lotmp; struct tm tm; register struct tm * tmp; char loab[MAX_STRING_LENGTH]; lotmp = my_localtime(&lot); if (lotmp != NULL) { lotm = *lotmp; (void) strncpy(loab, abbr(&lotm), (sizeof loab) - 1); } for ( ; ; ) { diff = (long) (hit - lot); if (diff < 2) break; t = lot; t += diff / 2; if (t <= lot) ++t; else if (t >= hit) --t; tmp = my_localtime(&t); if (tmp != NULL) tm = *tmp; if ((lotmp == NULL || tmp == NULL) ? (lotmp == tmp) : (delta(&tm, &lotm) == (t - lot) && tm.tm_isdst == lotm.tm_isdst && strcmp(abbr(&tm), loab) == 0)) { lot = t; lotm = tm; lotmp = tmp; } else hit = t; } show(name, lot, TRUE); show(name, hit, TRUE); return hit; }
void Monitor::NodeGenerator::findConnections(TreeNode * t) { if (t == 0) { return; } std::string key = t->column(0).toString().toLocal8Bit().constData(); std::string val = t->column(1).toString().toLocal8Bit().constData(); // store this writer-->reader connection info TreeNode *c; std::string tmp; std::string conn; if (key == "Reader" || key == "Writer") { for (int i = 0; i < t->size(); ++i) { c = t->operator[](i); tmp = c->column(0).toString().toLocal8Bit().constData(); if (nodeOpt_.abbrGUIDs()) { conn = abbr(c->column(1).toString().toLocal8Bit().constData()); val = abbr(t->column(1).toString().toLocal8Bit().constData()); } else { conn = c->column(1).toString().toLocal8Bit().constData(); } if (tmp == "Writer" && key == "Reader") { rMap_[t] = conn; } else if (tmp == "Reader" && key == "Writer") { wMap_[val] = t; } } } for (int i = 0; i < t->size(); ++i) { findConnections(t->operator[](i)); } }
char *encodeRnaName(struct track *tg, void *item) /* Return RNA gene name. */ { struct encodeRna *el = item; char *full = el->name; static char abbrev[SMALLBUF]; char *e; strcpy(abbrev, skipChr(full)); subChar(abbrev, '_', ' '); abbr(abbrev, " pseudogene"); if ((e = strstr(abbrev, "-related")) != NULL) strcpy(e, "-like"); return abbrev; }
/* Return a time zone abbreviation. If the abbreviation needs to be saved, use *BUF (of size *BUFALLOC) to save it, and return the abbreviation in the possibly-reallocated *BUF. Otherwise, just return the abbreviation. Get the abbreviation from TMP. Exit on memory allocation failure. */ static char const * saveabbr(char **buf, size_t *bufalloc, struct tm const *tmp) { char const *ab = abbr(tmp); if (HAVE_LOCALTIME_RZ) return ab; else { size_t ablen = strlen(ab); if (*bufalloc <= ablen) { free(*buf); /* Make the new buffer at least twice as long as the old, to avoid O(N**2) behavior on repeated calls. */ *bufalloc = sumsize(*bufalloc, ablen + 1); *buf = xmalloc(*bufalloc); } return strcpy(*buf, ab); } }
static time_t hunt(timezone_t tz, char *name, time_t lot, time_t hit) { static char * loab; static size_t loabsize; char const * ab; time_t t; struct tm lotm; struct tm * lotmp; struct tm tm; struct tm * tmp; lotmp = my_localtime_rz(tz, &lot, &lotm); if (lotmp) ab = saveabbr(&loab, &loabsize, &lotm); else ab = NULL; for ( ; ; ) { time_t diff = hit - lot; if (diff < 2) break; t = lot; t += diff / 2; if (t <= lot) ++t; else if (t >= hit) --t; tmp = my_localtime_rz(tz, &t, &tm); if ((lotmp == NULL || tmp == NULL) ? (lotmp == tmp) : (delta(&tm, &lotm) == (t - lot) && tm.tm_isdst == lotm.tm_isdst && strcmp(abbr(&tm), ab) == 0)) { lot = t; lotm = tm; lotmp = tmp; } else hit = t; } show(tz, name, lot, true); show(tz, name, hit, true); return hit; }
static time_t hunt(timezone_t tz, char *name, time_t lot, time_t hit) { static char * loab; static size_t loabsize; char const * ab; time_t t; struct tm lotm; struct tm tm; bool lotm_ok = my_localtime_rz(tz, &lot, &lotm) != NULL; bool tm_ok; if (lotm_ok) ab = saveabbr(&loab, &loabsize, &lotm); else ab = NULL; for ( ; ; ) { time_t diff = hit - lot; if (diff < 2) break; t = lot; t += diff / 2; if (t <= lot) ++t; else if (t >= hit) --t; tm_ok = my_localtime_rz(tz, &t, &tm) != NULL; if (lotm_ok & tm_ok ? (delta(&tm, &lotm) == t - lot && tm.tm_isdst == lotm.tm_isdst && strcmp(abbr(&tm), ab) == 0) : lotm_ok == tm_ok) { lot = t; if (tm_ok) lotm = tm; } else hit = t; } return hit; }
int main(int argc, char *argv[]) { /* These are static so that they're initially zero. */ static char * abbrev; static size_t abbrevsize; int i; bool vflag; bool Vflag; char * cutarg; char * cuttimes; time_t cutlotime; time_t cuthitime; time_t now; bool iflag = false; cutlotime = absolute_min_time; cuthitime = absolute_max_time; #if HAVE_GETTEXT (void) setlocale(LC_ALL, ""); #ifdef TZ_DOMAINDIR (void) bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR); #endif /* defined TEXTDOMAINDIR */ (void) textdomain(TZ_DOMAIN); #endif /* HAVE_GETTEXT */ progname = argv[0]; for (i = 1; i < argc; ++i) if (strcmp(argv[i], "--version") == 0) { (void) printf("zdump %s%s\n", PKGVERSION, TZVERSION); return EXIT_SUCCESS; } else if (strcmp(argv[i], "--help") == 0) { usage(stdout, EXIT_SUCCESS); } vflag = Vflag = false; cutarg = cuttimes = NULL; for (;;) switch (getopt(argc, argv, "c:it:vV")) { case 'c': cutarg = optarg; break; case 't': cuttimes = optarg; break; case 'i': iflag = true; break; case 'v': vflag = true; break; case 'V': Vflag = true; break; case -1: if (! (optind == argc - 1 && strcmp(argv[optind], "=") == 0)) goto arg_processing_done; /* Fall through. */ default: usage(stderr, EXIT_FAILURE); } arg_processing_done:; if (iflag | vflag | Vflag) { intmax_t lo; intmax_t hi; char *loend, *hiend; intmax_t cutloyear = ZDUMP_LO_YEAR; intmax_t cuthiyear = ZDUMP_HI_YEAR; if (cutarg != NULL) { lo = strtoimax(cutarg, &loend, 10); if (cutarg != loend && !*loend) { hi = lo; cuthiyear = hi; } else if (cutarg != loend && *loend == ',' && (hi = strtoimax(loend + 1, &hiend, 10), loend + 1 != hiend && !*hiend)) { cutloyear = lo; cuthiyear = hi; } else { fprintf(stderr, _("%s: wild -c argument %s\n"), progname, cutarg); return EXIT_FAILURE; } } if (cutarg != NULL || cuttimes == NULL) { cutlotime = yeartot(cutloyear); cuthitime = yeartot(cuthiyear); } if (cuttimes != NULL) { lo = strtoimax(cuttimes, &loend, 10); if (cuttimes != loend && !*loend) { hi = lo; if (hi < cuthitime) { if (hi < absolute_min_time) hi = absolute_min_time; cuthitime = hi; } } else if (cuttimes != loend && *loend == ',' && (hi = strtoimax(loend + 1, &hiend, 10), loend + 1 != hiend && !*hiend)) { if (cutlotime < lo) { if (absolute_max_time < lo) lo = absolute_max_time; cutlotime = lo; } if (hi < cuthitime) { if (hi < absolute_min_time) hi = absolute_min_time; cuthitime = hi; } } else { (void) fprintf(stderr, _("%s: wild -t argument %s\n"), progname, cuttimes); return EXIT_FAILURE; } } } gmtzinit(); INITIALIZE (now); if (! (iflag | vflag | Vflag)) now = time(NULL); longest = 0; for (i = optind; i < argc; i++) { size_t arglen = strlen(argv[i]); if (longest < arglen) longest = arglen < INT_MAX ? arglen : INT_MAX; } for (i = optind; i < argc; ++i) { timezone_t tz = tzalloc(argv[i]); char const *ab; time_t t; struct tm tm, newtm; bool tm_ok; if (!tz) { errx(EXIT_FAILURE, "%s", argv[i]); } if (! (iflag | vflag | Vflag)) { show(tz, argv[i], now, false); tzfree(tz); continue; } warned = false; t = absolute_min_time; if (! (iflag | Vflag)) { show(tz, argv[i], t, true); t += SECSPERDAY; show(tz, argv[i], t, true); } if (t < cutlotime) t = cutlotime; tm_ok = my_localtime_rz(tz, &t, &tm) != NULL; if (tm_ok) { ab = saveabbr(&abbrev, &abbrevsize, &tm); if (iflag) { showtrans("\nTZ=%f", &tm, t, ab, argv[i]); showtrans("-\t-\t%Q", &tm, t, ab, argv[i]); } } else ab = NULL; while (t < cuthitime) { time_t newt = ((t < absolute_max_time - SECSPERDAY / 2 && t + SECSPERDAY / 2 < cuthitime) ? t + SECSPERDAY / 2 : cuthitime); struct tm *newtmp = localtime_rz(tz, &newt, &newtm); bool newtm_ok = newtmp != NULL; if (! (tm_ok & newtm_ok ? (delta(&newtm, &tm) == newt - t && newtm.tm_isdst == tm.tm_isdst && strcmp(abbr(&newtm), ab) == 0) : tm_ok == newtm_ok)) { newt = hunt(tz, argv[i], t, newt); newtmp = localtime_rz(tz, &newt, &newtm); newtm_ok = newtmp != NULL; if (iflag) showtrans("%Y-%m-%d\t%L\t%Q", newtmp, newt, newtm_ok ? abbr(&newtm) : NULL, argv[i]); else { show(tz, argv[i], newt - 1, true); show(tz, argv[i], newt, true); } } t = newt; tm_ok = newtm_ok; if (newtm_ok) { ab = saveabbr(&abbrev, &abbrevsize, &newtm); tm = newtm; } } if (! (iflag | Vflag)) { t = absolute_max_time; t -= SECSPERDAY; show(tz, argv[i], t, true); t += SECSPERDAY; show(tz, argv[i], t, true); } tzfree(tz); } close_file(stdout); if (errout && (ferror(stderr) || fclose(stderr) != 0)) return EXIT_FAILURE; return EXIT_SUCCESS; }
DSTTime get_dst_time(const char *zone, int year) { register time_t cutlotime; register time_t cuthitime; cutlotime = yeartot(year); cuthitime = yeartot(year+1); time_t t; time_t newt; struct tm tm; struct tm newtm; register struct tm * tmp; register struct tm * newtmp; static char buf[MAX_STRING_LENGTH]; DSTTime ret = {0, 0}; char *tz = getenv("TZ"); if (setenv("TZ", zone, 1) != 0 ) { fprintf(stderr, "Set TZ=%s failed\n", zone); return ret; } t = absolute_min_time; if (t < cutlotime) t = cutlotime; tmp = localtime(&t); if (tmp != NULL) { tm = *tmp; strncpy(buf, abbr(&tm), (sizeof buf) - 1); } int enter_flag = 0; for ( ; ; ) { newt = (t < absolute_max_time - SECSPERDAY / 2 ? t + SECSPERDAY / 2 : absolute_max_time); if (cuthitime <= newt) break; newtmp = localtime(&newt); if (newtmp != NULL) newtm = *newtmp; if ((tmp == NULL || newtmp == NULL) ? (tmp != newtmp) : (delta(&newtm, &tm) != (newt - t) || newtm.tm_isdst != tm.tm_isdst || strcmp(abbr(&newtm), buf) != 0)) { newt = hunt(t, newt); newtmp = localtime(&newt); if (newtmp != NULL) { if (newtmp->tm_isdst) { if (!enter_flag) { ret.enter = newt; enter_flag = 1; } else { ret.leave = newt; } } else { if (!enter_flag) { ret.enter = newt-1; enter_flag = 1; } else { ret.leave = newt-1; } } newtm = *newtmp; strncpy(buf, abbr(&newtm),(sizeof buf) - 1); } } t = newt; tm = newtm; tmp = newtmp; } setenv("TZ", tz, 1); return ret; }
int main(int argc, char *argv[]) { register int i; register int c; register int vflag; register char * cutarg; register long cutloyear = ZDUMP_LO_YEAR; register long cuthiyear = ZDUMP_HI_YEAR; register time_t cutlotime; register time_t cuthitime; register char ** fakeenv; time_t now; time_t t; time_t newt; struct tm tm; struct tm newtm; register struct tm * tmp; register struct tm * newtmp; INITIALIZE(cutlotime); INITIALIZE(cuthitime); #if HAVE_GETTEXT (void) setlocale(LC_ALL, ""); #ifdef TZ_DOMAINDIR (void) bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR); #endif /* defined TEXTDOMAINDIR */ (void) textdomain(TZ_DOMAIN); #endif /* HAVE_GETTEXT */ progname = argv[0]; for (i = 1; i < argc; ++i) if (strcmp(argv[i], "--version") == 0) { (void) printf("zdump %s%s\n", PKGVERSION, TZVERSION); exit(EXIT_SUCCESS); } else if (strcmp(argv[i], "--help") == 0) { usage(stdout, EXIT_SUCCESS); } vflag = 0; cutarg = NULL; while ((c = getopt(argc, argv, "c:v")) == 'c' || c == 'v') if (c == 'v') vflag = 1; else cutarg = optarg; if ((c != EOF && c != -1) || (optind == argc - 1 && strcmp(argv[optind], "=") == 0)) { usage(stderr, EXIT_FAILURE); } if (vflag) { if (cutarg != NULL) { long lo; long hi; char dummy; if (sscanf(cutarg, "%ld%c", &hi, &dummy) == 1) { cuthiyear = hi; } else if (sscanf(cutarg, "%ld,%ld%c", &lo, &hi, &dummy) == 2) { cutloyear = lo; cuthiyear = hi; } else { (void) fprintf(stderr, _("%s: wild -c argument %s\n"), progname, cutarg); exit(EXIT_FAILURE); } } checkabsolutes(); cutlotime = yeartot(cutloyear); cuthitime = yeartot(cuthiyear); } (void) time(&now); longest = 0; for (i = optind; i < argc; ++i) if (strlen(argv[i]) > longest) longest = strlen(argv[i]); { register int from; register int to; for (i = 0; environ[i] != NULL; ++i) continue; fakeenv = malloc((i + 2) * sizeof *fakeenv); if (fakeenv == NULL || (fakeenv[0] = malloc(longest + 4)) == NULL) { (void) perror(progname); exit(EXIT_FAILURE); } 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; } 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; } warned = FALSE; t = absolute_min_time; show(argv[i], t, TRUE); t += SECSPERHOUR * HOURSPERDAY; show(argv[i], t, TRUE); if (t < cutlotime) t = cutlotime; tmp = my_localtime(&t); if (tmp != NULL) { tm = *tmp; (void) strncpy(buf, abbr(&tm), (sizeof buf) - 1); } for ( ; ; ) { if (t >= cuthitime || t >= cuthitime - SECSPERHOUR * 12) break; newt = t + SECSPERHOUR * 12; newtmp = localtime(&newt); if (newtmp != NULL) newtm = *newtmp; if ((tmp == NULL || newtmp == NULL) ? (tmp != newtmp) : (delta(&newtm, &tm) != (newt - t) || newtm.tm_isdst != tm.tm_isdst || strcmp(abbr(&newtm), buf) != 0)) { newt = hunt(argv[i], t, newt); newtmp = localtime(&newt); if (newtmp != NULL) { newtm = *newtmp; (void) strncpy(buf, abbr(&newtm), (sizeof buf) - 1); } } t = newt; tm = newtm; tmp = newtmp; } t = absolute_max_time; t -= SECSPERHOUR * HOURSPERDAY; show(argv[i], t, TRUE); t += SECSPERHOUR * HOURSPERDAY; show(argv[i], t, TRUE); } if (fflush(stdout) || ferror(stdout)) { (void) fprintf(stderr, "%s: ", progname); (void) perror(_("Error writing to standard output")); exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); /* If exit fails to exit... */ return EXIT_FAILURE; }
bool Monitor::NodeGenerator::isNodeValid(TreeNode *t, QString &text) { bool ret = false; // draw this node ? if (t != root_ && t->width() >= 2) { if (!honorDisplayFlag_ || (honorDisplayFlag_ && t->display())) { std::string key = t->column(0).toString().toLocal8Bit().constData(); std::string val = t->column(1).toString().toLocal8Bit().constData(); // host and process nodes // TODO: this is terribly ugly if ( (key == "Host" && !nodeOpt_.ignoreHosts()) || (key == "Process" && !nodeOpt_.ignoreProcs()) || (key == "DomainParticipant") || (key == "Publisher" && !nodeOpt_.ignorePubs()) || (key == "Subscriber" && !nodeOpt_.ignoreSubs()) || (key == "Topic" && !nodeOpt_.hideTopics()) || (key == "Transport" && !nodeOpt_.ignoreTransports()) || (key == "Reader" || key == "Writer") || (key == "Qos" && !nodeOpt_.ignoreQos()) ) { ret = true; // check for ignoreBuiltInTopics if (key == "Topic" && !nodeOpt_.hideTopics() && nodeOpt_.ignoreBuiltinTopics()) { ret = false; std::string tmp; TreeNode* c; for (int i = 0; i < t->size(); ++i) { c = t->operator[](i); tmp = c->column(0).toString().toLocal8Bit().constData(); if (tmp == "Topic Name") { tmp = c->column(1).toString().toLocal8Bit().constData(); if(tmp.substr(0, 4) != "DCPS") { ret = true; } } } } if (ret) { // yes, draw this node! if (nodeOpt_.abbrGUIDs()) { val = abbr(val); } text = key.c_str(); text += "\n"; text += val.c_str(); } } } } return ret; }
int main(int argc, char *argv[]) { int i; int vflag; int Vflag; char * cutarg; char * cuttimes; time_t cutlotime; time_t cuthitime; char ** fakeenv; time_t now; time_t t; time_t newt; struct tm tm; struct tm newtm; struct tm * tmp; struct tm * newtmp; cutlotime = absolute_min_time; cuthitime = absolute_max_time; #if HAVE_GETTEXT (void) setlocale(LC_ALL, ""); #ifdef TZ_DOMAINDIR (void) bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR); #endif /* defined TEXTDOMAINDIR */ (void) textdomain(TZ_DOMAIN); #endif /* HAVE_GETTEXT */ progname = argv[0]; for (i = 1; i < argc; ++i) if (strcmp(argv[i], "--version") == 0) { (void) printf("zdump %s%s\n", PKGVERSION, TZVERSION); exit(EXIT_SUCCESS); } else if (strcmp(argv[i], "--help") == 0) { usage(stdout, EXIT_SUCCESS); } vflag = Vflag = 0; cutarg = cuttimes = NULL; for (;;) switch (getopt(argc, argv, "c:t:vV")) { case 'c': cutarg = optarg; break; case 't': cuttimes = optarg; break; case 'v': vflag = 1; break; case 'V': Vflag = 1; break; case -1: if (! (optind == argc - 1 && strcmp(argv[optind], "=") == 0)) goto arg_processing_done; /* Fall through. */ default: usage(stderr, EXIT_FAILURE); } arg_processing_done:; if (vflag | Vflag) { intmax_t lo; intmax_t hi; char dummy; intmax_t cutloyear = ZDUMP_LO_YEAR; intmax_t cuthiyear = ZDUMP_HI_YEAR; if (cutarg != NULL) { if (sscanf(cutarg, "%"SCNdMAX"%c", &hi, &dummy) == 1) { cuthiyear = hi; } else if (sscanf(cutarg, "%"SCNdMAX",%"SCNdMAX"%c", &lo, &hi, &dummy) == 2) { cutloyear = lo; cuthiyear = hi; } else { (void) fprintf(stderr, _("%s: wild -c argument %s\n"), progname, cutarg); exit(EXIT_FAILURE); } } if (cutarg != NULL || cuttimes == NULL) { cutlotime = yeartot(cutloyear); cuthitime = yeartot(cuthiyear); } if (cuttimes != NULL) { if (sscanf(cuttimes, "%"SCNdMAX"%c", &hi, &dummy) == 1) { if (hi < cuthitime) { if (hi < absolute_min_time) hi = absolute_min_time; cuthitime = hi; } } else if (sscanf(cuttimes, "%"SCNdMAX",%"SCNdMAX"%c", &lo, &hi, &dummy) == 2) { if (cutlotime < lo) { if (absolute_max_time < lo) lo = absolute_max_time; cutlotime = lo; } if (hi < cuthitime) { if (hi < absolute_min_time) hi = absolute_min_time; cuthitime = hi; } } else { (void) fprintf(stderr, _("%s: wild -t argument %s\n"), progname, cuttimes); exit(EXIT_FAILURE); } } } (void) time(&now); longest = 0; for (i = optind; i < argc; ++i) if (strlen(argv[i]) > longest) longest = strlen(argv[i]); { int from; int to; for (i = 0; environ[i] != NULL; ++i) continue; fakeenv = malloc((i + 2) * sizeof *fakeenv); if (fakeenv == NULL || (fakeenv[0] = malloc(longest + 4)) == NULL) { err(EXIT_FAILURE, "Can't allocated %zu bytes", longest + 4); } to = 0; (void)strcpy(fakeenv[to++], "TZ="); /* XXX strcpy is safe */ for (from = 0; environ[from] != NULL; ++from) if (strncmp(environ[from], "TZ=", 3) != 0) fakeenv[to++] = environ[from]; fakeenv[to] = NULL; environ = fakeenv; } for (i = optind; i < argc; ++i) { static char buf[MAX_STRING_LENGTH]; (void) strcpy(&fakeenv[0][3], argv[i]); /* XXX strcpy is safe */ if (! (vflag | Vflag)) { show(argv[i], now, FALSE); continue; } warned = FALSE; t = absolute_min_time; if (!Vflag) { show(argv[i], t, TRUE); t += SECSPERDAY; show(argv[i], t, TRUE); } if (t < cutlotime) t = cutlotime; tmp = my_localtime(&t); if (tmp != NULL) { tm = *tmp; (void) strncpy(buf, abbr(&tm), (sizeof buf) - 1); } for ( ; ; ) { newt = (t < absolute_max_time - SECSPERDAY / 2 ? t + SECSPERDAY / 2 : absolute_max_time); if (cuthitime <= newt) break; newtmp = localtime(&newt); if (newtmp != NULL) newtm = *newtmp; if ((tmp == NULL || newtmp == NULL) ? (tmp != newtmp) : (delta(&newtm, &tm) != (newt - t) || newtm.tm_isdst != tm.tm_isdst || strcmp(abbr(&newtm), buf) != 0)) { newt = hunt(argv[i], t, newt); newtmp = localtime(&newt); if (newtmp != NULL) { newtm = *newtmp; (void) strncpy(buf, abbr(&newtm), (sizeof buf) - 1); } } t = newt; tm = newtm; tmp = newtmp; } if (!Vflag) { t = absolute_max_time; t -= SECSPERDAY; show(argv[i], t, TRUE); t += SECSPERDAY; show(argv[i], t, TRUE); } } if (fflush(stdout) || ferror(stdout)) { err(EXIT_FAILURE, _("Error writing standard output")); } exit(EXIT_SUCCESS); /* If exit fails to exit... */ return EXIT_FAILURE; }
int main(int argc, char *argv[]) { int i; int vflag; int Vflag; char *cutarg; char *cuttimes; time_t cutlotime; time_t cuthitime; char **fakeenv; time_t now; time_t t; time_t newt; struct tm tm; struct tm newtm; struct tm *tmp; struct tm *newtmp; cutlotime = absolute_min_time; cuthitime = absolute_max_time; vflag = Vflag = 0; cutarg = cuttimes = NULL; for (;;) switch (getopt(argc, argv, "c:t:vV")) { case 'c': cutarg = optarg; break; case 't': cuttimes = optarg; break; case 'v': vflag = 1; break; case 'V': Vflag = 1; break; case -1: if (! (optind == argc - 1 && strcmp(argv[optind], "=") == 0)) goto arg_processing_done; /* Fall through. */ default: usage(); } arg_processing_done:; if (vflag | Vflag) { intmax_t lo; intmax_t hi; char *loend, *hiend; intmax_t cutloyear = ZDUMP_LO_YEAR; intmax_t cuthiyear = ZDUMP_HI_YEAR; if (cutarg != NULL) { lo = strtoimax(cutarg, &loend, 10); if (cutarg != loend && !*loend) { hi = lo; cuthiyear = hi; } else if (cutarg != loend && *loend == ',' && (hi = strtoimax(loend + 1, &hiend, 10), loend + 1 != hiend && !*hiend)) { cutloyear = lo; cuthiyear = hi; } else { errx(EXIT_FAILURE, _("wild -c argument %s\n"), cutarg); } } if (cutarg != NULL || cuttimes == NULL) { cutlotime = yeartot(cutloyear); cuthitime = yeartot(cuthiyear); } if (cuttimes != NULL) { lo = strtoimax(cuttimes, &loend, 10); if (cuttimes != loend && !*loend) { hi = lo; if (hi < cuthitime) { if (hi < absolute_min_time) hi = absolute_min_time; cuthitime = hi; } } else if (cuttimes != loend && *loend == ',' && (hi = strtoimax(loend + 1, &hiend, 10), loend + 1 != hiend && !*hiend)) { if (cutlotime < lo) { if (absolute_max_time < lo) lo = absolute_max_time; cutlotime = lo; } if (hi < cuthitime) { if (hi < absolute_min_time) hi = absolute_min_time; cuthitime = hi; } } else { errx(EXIT_FAILURE, _("wild -t argument %s\n"), cuttimes); } } } time(&now); longest = 0; for (i = optind; i < argc; ++i) if (strlen(argv[i]) > longest) longest = strlen(argv[i]); { int from; int to; for (i = 0; environ[i] != NULL; ++i) continue; fakeenv = malloc((i + 2) * sizeof *fakeenv); if (fakeenv == NULL || (fakeenv[0] = malloc(longest + 4)) == NULL) { errx(EXIT_FAILURE, _("malloc() failed")); } to = 0; 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; } for (i = optind; i < argc; ++i) { static char buf[MAX_STRING_LENGTH]; strcpy(&fakeenv[0][3], argv[i]); if (! (vflag | Vflag)) { show(argv[i], now, FALSE); continue; } warned = FALSE; t = absolute_min_time; if (!Vflag) { show(argv[i], t, TRUE); t += SECSPERDAY; show(argv[i], t, TRUE); } if (t < cutlotime) t = cutlotime; tmp = my_localtime(&t); if (tmp != NULL) { tm = *tmp; strncpy(buf, abbr(&tm), (sizeof buf) - 1); } for ( ; ; ) { newt = (t < absolute_max_time - SECSPERDAY / 2 ? t + SECSPERDAY / 2 : absolute_max_time); if (cuthitime <= newt) break; newtmp = localtime(&newt); if (newtmp != NULL) newtm = *newtmp; if ((tmp == NULL || newtmp == NULL) ? (tmp != newtmp) : (delta(&newtm, &tm) != (newt - t) || newtm.tm_isdst != tm.tm_isdst || strcmp(abbr(&newtm), buf) != 0)) { newt = hunt(argv[i], t, newt); newtmp = localtime(&newt); if (newtmp != NULL) { newtm = *newtmp; strncpy(buf, abbr(&newtm), (sizeof buf) - 1); } } t = newt; tm = newtm; tmp = newtmp; } if (!Vflag) { t = absolute_max_time; t -= SECSPERDAY; show(argv[i], t, TRUE); t += SECSPERDAY; show(argv[i], t, TRUE); } } if (fflush(stdout) || ferror(stdout)) errx(EXIT_FAILURE, _("error writing standard output")); exit(EXIT_SUCCESS); /* If exit fails to exit... */ return EXIT_FAILURE; }
int main(int argc, char *argv[]) { int i; int c; int vflag; char *cutarg; long cutloyear = ZDUMP_LO_YEAR; long cuthiyear = ZDUMP_HI_YEAR; time_t cutlotime; time_t cuthitime; char **fakeenv; time_t now; time_t t; time_t newt; struct tm tm; struct tm newtm; struct tm *tmp; struct tm *newtmp; INITIALIZE(cutlotime); INITIALIZE(cuthitime); vflag = 0; cutarg = NULL; while ((c = getopt(argc, argv, "c:v")) == 'c' || c == 'v') if (c == 'v') vflag = 1; else cutarg = optarg; if ((c != EOF && c != -1) || (optind == argc - 1 && strcmp(argv[optind], "=") == 0)) { usage(); } if (vflag) { if (cutarg != NULL) { long lo; long hi; char dummy; if (sscanf(cutarg, "%ld%c", &hi, &dummy) == 1) { cuthiyear = hi; } else if (sscanf(cutarg, "%ld,%ld%c", &lo, &hi, &dummy) == 2) { cutloyear = lo; cuthiyear = hi; } else { errx(EXIT_FAILURE, _("wild -c argument %s\n"), cutarg); } } setabsolutes(); cutlotime = yeartot(cutloyear); cuthitime = yeartot(cuthiyear); } time(&now); longest = 0; for (i = optind; i < argc; ++i) if (strlen(argv[i]) > longest) longest = strlen(argv[i]); { int from; 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) errx(EXIT_FAILURE, _("malloc() failed")); to = 0; 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; } for (i = optind; i < argc; ++i) { static char buf[MAX_STRING_LENGTH]; strcpy(&fakeenv[0][3], argv[i]); if (!vflag) { show(argv[i], now, FALSE); continue; } warned = FALSE; t = absolute_min_time; show(argv[i], t, TRUE); t += SECSPERHOUR * HOURSPERDAY; show(argv[i], t, TRUE); if (t < cutlotime) t = cutlotime; tmp = my_localtime(&t); if (tmp != NULL) { tm = *tmp; strncpy(buf, abbr(&tm), (sizeof buf) - 1); } for ( ; ; ) { if (t >= cuthitime || t >= cuthitime - SECSPERHOUR * 12) break; newt = t + SECSPERHOUR * 12; newtmp = localtime(&newt); if (newtmp != NULL) newtm = *newtmp; if ((tmp == NULL || newtmp == NULL) ? (tmp != newtmp) : (delta(&newtm, &tm) != (newt - t) || newtm.tm_isdst != tm.tm_isdst || strcmp(abbr(&newtm), buf) != 0)) { newt = hunt(argv[i], t, newt); newtmp = localtime(&newt); if (newtmp != NULL) { newtm = *newtmp; strncpy(buf, abbr(&newtm), (sizeof buf) - 1); } } t = newt; tm = newtm; tmp = newtmp; } t = absolute_max_time; t -= SECSPERHOUR * HOURSPERDAY; show(argv[i], t, TRUE); t += SECSPERHOUR * HOURSPERDAY; show(argv[i], t, TRUE); } if (fflush(stdout) || ferror(stdout)) errx(EXIT_FAILURE, _("error writing standard output")); exit(EXIT_SUCCESS); /* If exit fails to exit... */ return EXIT_FAILURE; }