diff options
-rw-r--r-- | usr.sbin/tzsetup/main.c | 35 | ||||
-rw-r--r-- | usr.sbin/tzsetup/tzmenu.c | 30 |
2 files changed, 45 insertions, 20 deletions
diff --git a/usr.sbin/tzsetup/main.c b/usr.sbin/tzsetup/main.c index 4351bbb..9e85ac8 100644 --- a/usr.sbin/tzsetup/main.c +++ b/usr.sbin/tzsetup/main.c @@ -28,7 +28,7 @@ */ static const char rcsid[] = - "$Id: main.c,v 1.3 1995/06/11 19:33:05 rgrimes Exp $"; + "$Id: main.c,v 1.4 1995/10/06 02:46:23 jkh Exp $"; #include <stdio.h> #include <ncurses.h> @@ -37,6 +37,7 @@ static const char rcsid[] = #include <time.h> #include <stdlib.h> #include <errno.h> +#include <fcntl.h> #include "tzsetup.h" @@ -66,11 +67,11 @@ main(void) fiddle_cmos(); - dialog_notify("Reboot the machine for changes to take effect.\n"); + dialog_notify("Daemons will only notice\n" + "a timezone change.\n" + "after rebooting.\n"); end_dialog(); - fprintf(stderr, - "Now reboot your computer for the changes to take effect.\n"); return tz ? 0 : 1; } @@ -133,10 +134,10 @@ set_time(void) if (labs(diff) > 15*60) { cmos_state = cmos(CMOS_LOCAL); if (diff > 0) { - time_adjust = ((diff + 15*60)/30*60 + time_adjust = ((diff + 15*60)/(30*60) * 30*60); } else { - time_adjust = ((diff - 15*60)/30*60 + time_adjust = ((diff - 15*60)/(30*60) * 30*60); } } else { @@ -177,17 +178,23 @@ cmos(enum cmos state) static void fiddle_cmos(void) { - FILE *fp; + int fd; switch(cmos_state) { case CMOS_LEAVE: + break; case CMOS_UTC: + if (unlink(PATH_WALL_CMOS_CLOCK) == -1 && + errno != ENOENT) + dialog_notify("Error removing " PATH_WALL_CMOS_CLOCK); break; case CMOS_LOCAL: - fp = fopen(PATH_WALL_CMOS_CLOCK, "w"); - if(fp) { - fclose(fp); - } /* xxx should have error message */ + if ((fd = open(PATH_WALL_CMOS_CLOCK, O_RDONLY|O_CREAT, 0644)) + == -1) + dialog_notify("Error creating " PATH_WALL_CMOS_CLOCK); + else + close(fd); + break; } } @@ -208,17 +215,15 @@ setzone(const char *zone) systime += time_adjust; tm = localtime(&systime); -#if 0 /* This never prints the right value! :( */ snprintf(msg, sizeof msg, "Does %02d:%02d:%02d %d.%d.%04d %s look reasonable?", - tm->tm_hour, tm->tm_min, tm->tm_sec, tm->tm_mday, tm->tm_mon, - tm->tm_year + 1900, tm->tm_zone); + tm->tm_hour, tm->tm_min, tm->tm_sec, tm->tm_mday, + tm->tm_mon + 1, tm->tm_year + 1900, tm->tm_zone); rv = dialog_yesno("Verifying timezone selection", msg, -1, -1); if (rv) return 1; -#endif snprintf(msg, sizeof msg, PATH_ZONEINFO "/%s", zone); ifp = fopen(msg, "r"); diff --git a/usr.sbin/tzsetup/tzmenu.c b/usr.sbin/tzsetup/tzmenu.c index bec4cfd..cb76c96 100644 --- a/usr.sbin/tzsetup/tzmenu.c +++ b/usr.sbin/tzsetup/tzmenu.c @@ -28,12 +28,15 @@ */ static const char rcsid[] = - "$Id: tzmenu.c,v 1.1 1995/04/24 21:04:34 wollman Exp $"; + "$Id: tzmenu.c,v 1.2 1995/05/30 03:52:50 rgrimes Exp $"; #include <stdio.h> #include <ncurses.h> #include <dialog.h> #include <limits.h> +#include <unistd.h> +#include <stdlib.h> +#include <sys/ioctl.h> #include "tzsetup.h" @@ -59,7 +62,10 @@ static struct region *regions[] = { &Pacific }; +static unsigned short nrows; + #define NREGIONS 8 +#define DEFAULT_NROWS 24 /* default height of tty */ static const char *country_menu(const struct region *, const char *); @@ -71,6 +77,16 @@ tzmenu(void) int item = 0; int sc = 0; const char *res; + struct winsize win; + char *cp; + + if (isatty(fileno(stdin)) && + ioctl(fileno(stdin), TIOCGWINSZ, &win) != -1) + nrows = win.ws_row; + else if ((cp = getenv("LINES"))) + nrows = atoi(cp); + if (nrows == 0) + nrows = DEFAULT_NROWS; while(1) { dialog_clear(); @@ -115,9 +131,11 @@ country_menu(const struct region *reg, const char *name) while(1) { dialog_clear(); rv = dialog_menu(title, "Select a country", - reg->r_count > 18 ? 24 : reg->r_count + 6, + reg->r_count > nrows - 6 ? + nrows : reg->r_count + 6, 78, - reg->r_count > 18 ? 18 : reg->r_count, + reg->r_count > nrows - 6 ? + nrows - 6 : reg->r_count, reg->r_count, (unsigned char **)reg->r_menu, rbuf, @@ -154,9 +172,11 @@ location_menu(const struct country *ctry, const char *name) while(1) { dialog_clear(); rv = dialog_menu(title, "Select a location", - ctry->c_count + 6, + ctry->c_count > nrows - 6? + nrows : ctry->c_count + 6, 78, - ctry->c_count, + ctry->c_count > nrows - 6? + nrows - 6 : ctry->c_count, ctry->c_count, (unsigned char **)ctry->c_menu, rbuf, |