+
+
+/* Make sure all the values in the preferences struct are sane.
+ */
+static void
+stop_the_insanity (saver_preferences *p)
+{
+ if (p->passwd_timeout <= 0) p->passwd_timeout = 30000; /* 30 secs */
+ if (p->timeout < 15000) p->timeout = 15000; /* 15 secs */
+ if (p->cycle != 0 && p->cycle < 2000) p->cycle = 2000; /* 2 secs */
+ if (p->pointer_timeout <= 0) p->pointer_timeout = 5000; /* 5 secs */
+ if (p->notice_events_timeout <= 0)
+ p->notice_events_timeout = 10000; /* 10 secs */
+ if (p->fade_seconds <= 0 || p->fade_ticks <= 0)
+ p->fade_p = False;
+ if (! p->fade_p) p->unfade_p = False;
+
+ /* The DPMS settings may have the value 0.
+ But if they are negative, or are a range less than 10 seconds,
+ reset them to sensible defaults. (Since that must be a mistake.)
+ */
+ if (p->dpms_standby != 0 &&
+ p->dpms_standby < 10 * 1000)
+ p->dpms_standby = 2 * 60 * 60 * 1000; /* 2 hours */
+ if (p->dpms_suspend != 0 &&
+ p->dpms_suspend < 10 * 1000)
+ p->dpms_suspend = 2 * 60 * 60 * 1000; /* 2 hours */
+ if (p->dpms_off != 0 &&
+ p->dpms_off < 10 * 1000)
+ p->dpms_off = 4 * 60 * 60 * 1000; /* 4 hours */
+
+ /* suspend may not be greater than off, unless off is 0.
+ standby may not be greater than suspend, unless suspend is 0.
+ */
+ if (p->dpms_off != 0 &&
+ p->dpms_suspend > p->dpms_off)
+ p->dpms_suspend = p->dpms_off;
+ if (p->dpms_suspend != 0 &&
+ p->dpms_standby > p->dpms_suspend)
+ p->dpms_standby = p->dpms_suspend;
+
+ /* These fixes above ignores the case
+ suspend = 0 and standby > off ...
+ */
+ if (p->dpms_off != 0 &&
+ p->dpms_standby > p->dpms_off)
+ p->dpms_standby = p->dpms_off;
+
+
+ if (p->dpms_standby == 0 && /* if *all* are 0, then DPMS is disabled */
+ p->dpms_suspend == 0 &&
+ p->dpms_off == 0 &&
+ !(p->dpms_quickoff_p) /* ... but we want to do DPMS quick off */
+ )
+ p->dpms_enabled_p = False;
+
+
+ /* Set watchdog timeout to about half of the cycle timeout, but
+ don't let it be faster than 1/2 minute or slower than 1 minute.
+ */
+ p->watchdog_timeout = p->cycle * 0.6;
+ if (p->watchdog_timeout < 27000) p->watchdog_timeout = 27000; /* 27 secs */
+ if (p->watchdog_timeout > 57000) p->watchdog_timeout = 57000; /* 57 secs */
+
+ if (p->pointer_hysteresis < 0) p->pointer_hysteresis = 0;
+ if (p->pointer_hysteresis > 100) p->pointer_hysteresis = 100;
+}
+
+
+/* Getting very tired of bug reports of already-fixed bugs due to
+ Linux distros shipping multi-year-old versions.
+ */
+Bool
+senescent_p (void)
+{
+ time_t now = time ((time_t *) 0);
+ struct tm *tm = localtime (&now);
+ const char *s = screensaver_id;
+ char mon[4], year[5];
+ int m, y, months;
+ s = strchr (s, ' '); if (!s) abort(); s++;
+ s = strchr (s, '('); if (!s) abort(); s++;
+ s = strchr (s, '-'); if (!s) abort(); s++;
+ strncpy (mon, s, 3);
+ mon[3] = 0;
+ s = strchr (s, '-'); if (!s) abort(); s++;
+ strncpy (year, s, 4);
+ year[4] = 0;
+ y = atoi (year);
+ if (!strcmp(mon, "Jan")) m = 0;
+ else if (!strcmp(mon, "Feb")) m = 1;
+ else if (!strcmp(mon, "Mar")) m = 2;
+ else if (!strcmp(mon, "Apr")) m = 3;
+ else if (!strcmp(mon, "May")) m = 4;
+ else if (!strcmp(mon, "Jun")) m = 5;
+ else if (!strcmp(mon, "Jul")) m = 6;
+ else if (!strcmp(mon, "Aug")) m = 7;
+ else if (!strcmp(mon, "Sep")) m = 8;
+ else if (!strcmp(mon, "Oct")) m = 9;
+ else if (!strcmp(mon, "Nov")) m = 10;
+ else if (!strcmp(mon, "Dec")) m = 11;
+ else abort();
+ months = ((((tm->tm_year + 1900) * 12) + tm->tm_mon) -
+ (y * 12 + m));
+
+ return (months > 12);
+}