static int mergestates(int v) { State *a, *b; int m, cnt=0; if (tl_verbose) return 0; do { m = 0; cnt++; for (a = never; a; a = a->nxt) { if (v && !a->reachable) continue; if (a->redundant) continue; /* 3.3.10 */ for (b = a->nxt; b; b = b->nxt) { if (v && !b->reachable) continue; if (b->redundant) continue; /* 3.3.10 */ if (all_trans_match(a, b)) { m++; if (tl_verbose) { printf("%d: state %s equals state %s\n", cnt, a->name->name, b->name->name); showtrans(a); printf("==\n"); showtrans(b); } retarget(a->name->name, b->name->name); if (!strncmp(a->name->name, "accept", 6) && Max_Red == 0) { char buf[64]; sprintf(buf, "T0%s", &(a->name->name[6])); retarget(buf, b->name->name); } break; } #if 0 else if (tl_verbose) { printf("\n%d: state %s differs from state %s [%d,%d]\n", cnt, a->name->name, b->name->name, a->accepting, b->accepting); showtrans(a); printf("==\n"); showtrans(b); printf("\n"); } #endif } } } while (m && cnt < 10); return cnt-1; }
static int mergetrans(void) { State *b; Transition *s, *t; Node *nc; int cnt = 0; for (b = never; b; b = b->nxt) { if (!b->reachable) continue; for (s = b->trans; s; s = s->nxt) { if (s->redundant) continue; for (t = s->nxt; t; t = t->nxt) if (!t->redundant && !strcmp(s->name->name, t->name->name)) { if (tl_verbose) { printf("===\nstate %s, trans to %s redundant\n", b->name->name, s->name->name); showtrans(b); printf(" conditions "); dump(s->cond); printf(" <-> "); dump(t->cond); printf("\n"); } if (!s->cond) /* same as T */ { releasenode(1, t->cond); /* T or t */ nc = True; } else if (!t->cond) { releasenode(1, s->cond); nc = True; } else { nc = combination(s->cond, t->cond); } t->cond = rewrite(nc); t->merged = 1; s->redundant = 1; cnt++; break; } } } return cnt; }
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; }