summaryrefslogtreecommitdiffstats
path: root/usr.sbin/tzsetup
diff options
context:
space:
mode:
authorjoerg <joerg@FreeBSD.org>1996-03-31 09:55:02 +0000
committerjoerg <joerg@FreeBSD.org>1996-03-31 09:55:02 +0000
commit3924abebea6059c45a7e021ab369acb3b515680e (patch)
treedd57519b2bedfcdafae77e292a3272299d481cd2 /usr.sbin/tzsetup
parent14c8c2c164f6052a871dcf5860402a973ac1b970 (diff)
downloadFreeBSD-src-3924abebea6059c45a7e021ab369acb3b515680e.zip
FreeBSD-src-3924abebea6059c45a7e021ab369acb3b515680e.tar.gz
Another round of fixes:
. Replace my NIH-suffering code to detect the number of lines on the terminal by the curses variable LINES. . Fix the selection code for countries with more than one screenful of locations. The very few people living in America/US/Pacific now won't be charged for Indiana any longer... :) . Removed the gross code that copied over the timezone file to /etc/localtime, and create a symlink now instead.
Diffstat (limited to 'usr.sbin/tzsetup')
-rw-r--r--usr.sbin/tzsetup/main.c62
-rw-r--r--usr.sbin/tzsetup/tzmenu.c33
2 files changed, 35 insertions, 60 deletions
diff --git a/usr.sbin/tzsetup/main.c b/usr.sbin/tzsetup/main.c
index 9e85ac8..e42006e 100644
--- a/usr.sbin/tzsetup/main.c
+++ b/usr.sbin/tzsetup/main.c
@@ -28,8 +28,10 @@
*/
static const char rcsid[] =
- "$Id: main.c,v 1.4 1995/10/06 02:46:23 jkh Exp $";
+ "$Id: main.c,v 1.5 1996/03/22 22:22:38 joerg Exp $";
+#include <sys/types.h>
+#include <sys/stat.h>
#include <stdio.h>
#include <ncurses.h>
#include <dialog.h>
@@ -206,7 +208,22 @@ setzone(const char *zone)
struct tm *tm;
char msg[_POSIX2_LINE_MAX];
int rv;
- FILE *ifp, *ofp;
+ struct stat sb;
+
+ /*
+ * Make sure the definition file does exist before clobbering
+ * an existing PATH_LOCALTIME. We do this before evaluating
+ * locatlime below, since a missing zoneinfo file would result
+ * in nothing but garbage in the displayed time information.
+ */
+ snprintf(msg, sizeof msg, PATH_ZONEINFO "/%s", zone);
+ if (stat(msg, &sb) == -1) {
+ snprintf(msg, sizeof msg,
+ "Could not find definition file\n"
+ PATH_ZONEINFO "/%s", zone);
+ dialog_notify(msg);
+ return 1;
+ }
snprintf(msg, sizeof msg, "TZ=%s", zone);
putenv(msg);
@@ -226,46 +243,13 @@ setzone(const char *zone)
return 1;
snprintf(msg, sizeof msg, PATH_ZONEINFO "/%s", zone);
- ifp = fopen(msg, "r");
- if (!ifp) {
- snprintf(msg, sizeof msg,
- "Could not open " PATH_ZONEINFO "/%s: %s",
- zone, strerror(errno));
- dialog_notify(msg);
+ (void)unlink(PATH_LOCALTIME);
+ if (symlink(msg, PATH_LOCALTIME) == -1) {
+ dialog_notify("Could not create a symbolic link for "
+ PATH_LOCALTIME);
return 1;
}
- ofp = fopen(PATH_LOCALTIME, "w");
- if (!ofp) {
- snprintf(msg, sizeof msg, "Could not open " PATH_LOCALTIME
- ": %s", strerror(errno));
- dialog_notify(msg);
- fclose(ifp);
- return 1;
- }
-
- while((rv = fread(msg, 1, sizeof msg, ifp)) > 0) {
- int rv2;
- if((rv2 = fwrite(msg, 1, rv, ofp)) != rv) {
- snprintf(msg, sizeof msg,
- "Could not write " PATH_LOCALTIME ": %s",
- strerror(errno));
-out:
- dialog_notify(msg);
- fclose(ifp);
- fclose(ofp);
- unlink(PATH_LOCALTIME);
- return 1;
- }
- }
- if (rv < 0) {
- snprintf(msg, sizeof msg, "Could not read timezone file: %s",
- strerror(errno));
- goto out;
- }
-
- fclose(ifp);
- fclose(ofp);
snprintf(msg, sizeof msg, "Installed timezone file %s", zone);
dialog_notify(msg);
return 0;
diff --git a/usr.sbin/tzsetup/tzmenu.c b/usr.sbin/tzsetup/tzmenu.c
index cb76c96..3fb89c6 100644
--- a/usr.sbin/tzsetup/tzmenu.c
+++ b/usr.sbin/tzsetup/tzmenu.c
@@ -28,7 +28,7 @@
*/
static const char rcsid[] =
- "$Id: tzmenu.c,v 1.2 1995/05/30 03:52:50 rgrimes Exp $";
+ "$Id: tzmenu.c,v 1.3 1996/03/22 22:22:40 joerg Exp $";
#include <stdio.h>
#include <ncurses.h>
@@ -62,8 +62,6 @@ static struct region *regions[] = {
&Pacific
};
-static unsigned short nrows;
-
#define NREGIONS 8
#define DEFAULT_NROWS 24 /* default height of tty */
@@ -80,14 +78,6 @@ tzmenu(void)
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();
rv = dialog_menu("Timezone Selector",
@@ -131,11 +121,11 @@ country_menu(const struct region *reg, const char *name)
while(1) {
dialog_clear();
rv = dialog_menu(title, "Select a country",
- reg->r_count > nrows - 6 ?
- nrows : reg->r_count + 6,
+ reg->r_count > LINES - 6 ?
+ LINES : reg->r_count + 6,
78,
- reg->r_count > nrows - 6 ?
- nrows - 6 : reg->r_count,
+ reg->r_count > LINES - 6 ?
+ LINES - 6 : reg->r_count,
reg->r_count,
(unsigned char **)reg->r_menu,
rbuf,
@@ -172,11 +162,11 @@ location_menu(const struct country *ctry, const char *name)
while(1) {
dialog_clear();
rv = dialog_menu(title, "Select a location",
- ctry->c_count > nrows - 6?
- nrows : ctry->c_count + 6,
+ ctry->c_count > LINES - 6?
+ LINES : ctry->c_count + 6,
78,
- ctry->c_count > nrows - 6?
- nrows - 6 : ctry->c_count,
+ ctry->c_count > LINES - 6?
+ LINES - 6 : ctry->c_count,
ctry->c_count,
(unsigned char **)ctry->c_menu,
rbuf,
@@ -188,11 +178,12 @@ location_menu(const struct country *ctry, const char *name)
return 0;
}
+ sscanf(rbuf, "%d", &rv);
- rv = setzone(ctry->c_filelist[item]);
+ rv = setzone(ctry->c_filelist[rv - 1]);
if (rv == 0)
- return ctry->c_filelist[item];
+ return ctry->c_filelist[rv - 1];
}
}
OpenPOWER on IntegriCloud