+static void usage(FILE *fp)
+{
+ char longbuf[80];
+ const char *prefix, *shortopt, *longopt, *optarg;
+ int i, optex;
+
+#define HELPRESET prefix = shortopt = longopt = optarg = NULL, optex = -1
+#define HELPNOVAL(s) optex = 0;
+#define HELPVAL(s) optex = 1;
+#define HELPSHORT(s) if (!shortopt) shortopt = "-" #s;
+#define HELPLONG(s) if (!longopt) { \
+ strcpy(longbuf, "--" #s); longopt = longbuf; \
+ for (i = 0; longbuf[i]; i++) if (longbuf[i] == '_') longbuf[i] = '-'; }
+#define HELPPFX(s) prefix = s;
+#define HELPARG(s) optarg = s;
+#define HELPLINE(s) assert(optex == -1); \
+ fprintf(fp, "%7s%c %s\n", prefix?prefix:"", prefix?':':' ', s); \
+ HELPRESET;
+#define HELPOPT(s) assert((optex == 1 && optarg) || (optex == 0 && !optarg)); \
+ assert(shortopt || longopt); \
+ i = fprintf(fp, "%7s%c %s%s%s%s%s", prefix?prefix:"", prefix?':':' ', \
+ shortopt?shortopt:"", shortopt&&longopt?", ":"", longopt?longopt:"", \
+ optarg?" ":"", optarg?optarg:""); \
+ fprintf(fp, "%*s %s\n", i<32?32-i:0,"",s); HELPRESET;
+
+ HELPRESET;
+ OPTHELP(HELPNOVAL, HELPVAL, HELPSHORT, HELPLONG,
+ HELPPFX, HELPARG, HELPLINE, HELPOPT);
+
+#undef HELPRESET
+#undef HELPNOVAL
+#undef HELPVAL
+#undef HELPSHORT
+#undef HELPLONG
+#undef HELPPFX
+#undef HELPARG
+#undef HELPLINE
+#undef HELPOPT
+}
+
+static time_t parse_age(time_t now, const char *agestr)
+{
+ time_t t;
+ struct tm tm;
+ int nunits;
+ char unit[2];
+
+ t = now;
+
+ if (2 != sscanf(agestr, "%d%1[DdWwMmYy]", &nunits, unit)) {
+ fprintf(stderr, "%s: age specification should be a number followed by"
+ " one of d,w,m,y\n", PNAME);
+ exit(1);
+ }
+
+ if (unit[0] == 'd') {
+ t -= 86400 * nunits;
+ } else if (unit[0] == 'w') {
+ t -= 86400 * 7 * nunits;
+ } else {
+ int ym;
+
+ tm = *localtime(&t);
+ ym = tm.tm_year * 12 + tm.tm_mon;
+
+ if (unit[0] == 'm')
+ ym -= nunits;
+ else
+ ym -= 12 * nunits;
+
+ tm.tm_year = ym / 12;
+ tm.tm_mon = ym % 12;
+
+ t = mktime(&tm);
+ }
+
+ return t;
+}
+