2 * Copyright 1996 Massachusetts Institute of Technology
4 * Permission to use, copy, modify, and distribute this software and
5 * its documentation for any purpose and without fee is hereby
6 * granted, provided that both the above copyright notice and this
7 * permission notice appear in all copies, that both the above
8 * copyright notice and this permission notice appear in all
9 * supporting documentation, and that the name of M.I.T. not be used
10 * in advertising or publicity pertaining to distribution of the
11 * software without specific, written prior permission. M.I.T. makes
12 * no representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied
16 * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
17 * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
20 * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Second attempt at a `tzmenu' program, using the separate description
32 * files provided in newer tzdata releases.
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
47 #include <sys/fcntl.h>
48 #include <sys/param.h>
49 #include <sys/queue.h>
52 #define _PATH_ZONETAB "/usr/share/zoneinfo/zone.tab"
53 #define _PATH_ISO3166 "/usr/share/misc/iso3166"
54 #define _PATH_ZONEINFO "/usr/share/zoneinfo"
55 #define _PATH_LOCALTIME "/etc/localtime"
56 #define _PATH_DB "/var/db/zoneinfo"
57 #define _PATH_WALL_CMOS_CLOCK "/etc/wall_cmos_clock"
60 #define SILLY_BUFFER_SIZE 2*PATH_MAX
62 #warning "Somebody needs to fix this to dynamically size this buffer."
63 #define SILLY_BUFFER_SIZE 2048
66 static char path_zonetab[MAXPATHLEN], path_iso3166[MAXPATHLEN],
67 path_zoneinfo[MAXPATHLEN], path_localtime[MAXPATHLEN],
68 path_db[MAXPATHLEN], path_wall_cmos_clock[MAXPATHLEN];
70 static int reallydoit = 1;
71 static int reinstall = 0;
72 static int usedialog = 1;
73 static char *chrootenv = NULL;
75 static void usage(void);
76 static int confirm_zone(const char *filename);
77 static int continent_country_menu(dialogMenuItem *);
78 static int install_zoneinfo_file(const char *zoneinfo_file);
79 static int set_zone_multi(dialogMenuItem *);
80 static int set_zone_whole_country(dialogMenuItem *);
81 static int set_zone_menu(dialogMenuItem *);
82 static int set_zone_utc(void);
91 static struct continent africa, america, antarctica, arctic, asia, atlantic;
92 static struct continent australia, europe, indian, pacific, utc;
94 static struct continent_names {
96 struct continent *continent;
97 } continent_names[] = {
98 { "Africa", &africa },
99 { "America", &america },
100 { "Antarctica", &antarctica },
101 { "Arctic", &arctic },
103 { "Atlantic", &atlantic },
104 { "Australia", &australia },
105 { "Europe", &europe },
106 { "Indian", &indian },
107 { "Pacific", &pacific },
111 static struct continent_items {
114 } continent_items[] = {
116 { "2", "America -- North and South" },
117 { "3", "Antarctica" },
118 { "4", "Arctic Ocean" },
120 { "6", "Atlantic Ocean" },
121 { "7", "Australia" },
123 { "9", "Indian Ocean" },
124 { "0", "Pacific Ocean" },
128 #define NCONTINENTS \
129 (int)((sizeof(continent_items)) / (sizeof(continent_items[0])))
130 static dialogMenuItem continents[NCONTINENTS];
132 #define OCEANP(x) ((x) == 3 || (x) == 5 || (x) == 8 || (x) == 9)
135 continent_country_menu(dialogMenuItem *continent)
137 char title[64], prompt[64];
138 struct continent *contp = continent->data;
139 int isocean = OCEANP(continent - continents);
143 if (strcmp(continent->title, "UTC") == 0)
144 return set_zone_utc();
146 /* Short cut -- if there's only one country, don't post a menu. */
147 if (contp->nitems == 1)
148 return (contp->menu[0].fire(&contp->menu[0]));
150 /* It's amazing how much good grammar really matters... */
152 snprintf(title, sizeof(title), "Countries in %s",
154 snprintf(prompt, sizeof(prompt), "Select a country or region");
156 snprintf(title, sizeof(title), "Islands and groups in the %s",
158 snprintf(prompt, sizeof(prompt), "Select an island or group");
161 menulen = contp->nitems < 16 ? contp->nitems : 16;
162 rv = dialog_menu(title, prompt, -1, -1, menulen, -contp->nitems,
163 contp->menu, 0, &contp->ch, &contp->sc);
165 return (DITEM_LEAVE_MENU);
166 return (DITEM_RECREATE);
169 static struct continent *
170 find_continent(const char *name)
174 for (i = 0; i < NCONTINENTS; i++)
175 if (strcmp(name, continent_names[i].name) == 0)
176 return (continent_names[i].continent);
184 char *filename; /* use iff nzones < 0 */
185 struct continent *continent; /* use iff nzones < 0 */
186 TAILQ_HEAD(, zone) zones; /* use iff nzones > 0 */
187 dialogMenuItem *submenu; /* use iff nzones > 0 */
191 TAILQ_ENTRY(zone) link;
194 struct continent *continent;
198 * This is the easiest organization... we use ISO 3166 country codes,
199 * of the two-letter variety, so we just size this array to suit.
200 * Beats worrying about dynamic allocation.
202 #define NCOUNTRIES (26 * 26)
203 static struct country countries[NCOUNTRIES];
205 #define CODE2INT(s) ((s[0] - 'A') * 26 + (s[1] - 'A'))
208 * Read the ISO 3166 country code database in _PATH_ISO3166
209 * (/usr/share/misc/iso3166). On error, exit via err(3).
212 read_iso3166_table(void)
220 fp = fopen(path_iso3166, "r");
222 err(1, "%s", path_iso3166);
225 while ((s = fgetln(fp, &len)) != 0) {
227 if (s[len - 1] != '\n')
228 errx(1, "%s:%d: invalid format", path_iso3166, lineno);
230 if (s[0] == '#' || strspn(s, " \t") == len - 1)
233 /* Isolate the two-letter code. */
234 t = strsep(&s, "\t");
235 if (t == 0 || strlen(t) != 2)
236 errx(1, "%s:%d: invalid format", path_iso3166, lineno);
237 if (t[0] < 'A' || t[0] > 'Z' || t[1] < 'A' || t[1] > 'Z')
238 errx(1, "%s:%d: invalid code `%s'", path_iso3166,
241 /* Now skip past the three-letter and numeric codes. */
242 name = strsep(&s, "\t"); /* 3-let */
243 if (name == 0 || strlen(name) != 3)
244 errx(1, "%s:%d: invalid format", path_iso3166, lineno);
245 name = strsep(&s, "\t"); /* numeric */
246 if (name == 0 || strlen(name) != 3)
247 errx(1, "%s:%d: invalid format", path_iso3166, lineno);
251 cp = &countries[CODE2INT(t)];
253 errx(1, "%s:%d: country code `%s' multiply defined: %s",
254 path_iso3166, lineno, t, cp->name);
255 cp->name = strdup(name);
256 if (cp->name == NULL)
257 errx(1, "malloc failed");
260 errx(1, "malloc failed");
267 add_zone_to_country(int lineno, const char *tlc, const char *descr,
268 const char *file, struct continent *cont)
273 if (tlc[0] < 'A' || tlc[0] > 'Z' || tlc[1] < 'A' || tlc[1] > 'Z')
274 errx(1, "%s:%d: country code `%s' invalid", path_zonetab,
277 cp = &countries[CODE2INT(tlc)];
279 errx(1, "%s:%d: country code `%s' unknown", path_zonetab,
284 errx(1, "%s:%d: conflicting zone definition",
285 path_zonetab, lineno);
287 zp = malloc(sizeof(*zp));
289 errx(1, "malloc(%zu)", sizeof(*zp));
292 TAILQ_INIT(&cp->zones);
294 zp->descr = strdup(descr);
295 if (zp->descr == NULL)
296 errx(1, "malloc failed");
297 zp->filename = strdup(file);
298 if (zp->filename == NULL)
299 errx(1, "malloc failed");
300 zp->continent = cont;
301 TAILQ_INSERT_TAIL(&cp->zones, zp, link);
305 errx(1, "%s:%d: zone must have description",
306 path_zonetab, lineno);
308 errx(1, "%s:%d: zone multiply defined",
309 path_zonetab, lineno);
311 cp->filename = strdup(file);
312 if (cp->filename == NULL)
313 errx(1, "malloc failed");
314 cp->continent = cont;
319 * This comparison function intentionally sorts all of the null-named
320 * ``countries''---i.e., the codes that don't correspond to a real
321 * country---to the end. Everything else is lexical by country name.
324 compare_countries(const void *xa, const void *xb)
326 const struct country *a = xa, *b = xb;
328 if (a->name == 0 && b->name == 0)
330 if (a->name == 0 && b->name != 0)
335 return (strcmp(a->name, b->name));
339 * This must be done AFTER all zone descriptions are read, since it breaks
346 qsort(countries, NCOUNTRIES, sizeof(countries[0]), compare_countries);
354 struct continent *cont;
356 char *line, *tlc, *coord, *file, *descr, *p;
359 fp = fopen(path_zonetab, "r");
361 err(1, "%s", path_zonetab);
364 while ((line = fgetln(fp, &len)) != 0) {
366 if (line[len - 1] != '\n')
367 errx(1, "%s:%d: invalid format", path_zonetab, lineno);
368 line[len - 1] = '\0';
372 tlc = strsep(&line, "\t");
373 if (strlen(tlc) != 2)
374 errx(1, "%s:%d: invalid country code `%s'",
375 path_zonetab, lineno, tlc);
376 coord = strsep(&line, "\t"); /* Unused */
377 file = strsep(&line, "\t");
378 p = strchr(file, '/');
380 errx(1, "%s:%d: invalid zone name `%s'", path_zonetab,
383 strncat(contbuf, file, p - file);
384 cont = find_continent(contbuf);
386 errx(1, "%s:%d: invalid region `%s'", path_zonetab,
389 descr = (line != NULL && *line != '\0') ? line : NULL;
391 add_zone_to_country(lineno, tlc, descr, file, cont);
400 struct zone *zp, *zp2;
401 struct continent *cont;
406 * First, count up all the countries in each continent/ocean.
407 * Be careful to count those countries which have multiple zones
408 * only once for each. NB: some countries are in multiple
411 for (cp = countries; cp->name; cp++) {
414 if (cp->nzones < 0) {
415 cp->continent->nitems++;
417 TAILQ_FOREACH(zp, &cp->zones, link) {
418 cont = zp->continent;
419 for (zp2 = TAILQ_FIRST(&cp->zones);
420 zp2->continent != cont;
421 zp2 = TAILQ_NEXT(zp2, link))
424 zp->continent->nitems++;
430 * Now allocate memory for the country menus and initialize
431 * continent menus. We set nitems back to zero so that we can
432 * use it for counting again when we actually build the menus.
434 memset(continents, 0, sizeof(continents));
435 for (i = 0; i < NCONTINENTS; i++) {
436 continent_names[i].continent->menu =
437 malloc(sizeof(dialogMenuItem) *
438 continent_names[i].continent->nitems);
439 if (continent_names[i].continent->menu == 0)
440 errx(1, "malloc for continent menu");
441 continent_names[i].continent->nitems = 0;
442 continents[i].prompt = continent_items[i].prompt;
443 continents[i].title = continent_items[i].title;
444 continents[i].fire = continent_country_menu;
445 continents[i].data = continent_names[i].continent;
449 * Now that memory is allocated, create the menu items for
450 * each continent. For multiple-zone countries, also create
451 * the country's zone submenu.
453 for (cp = countries; cp->name; cp++) {
456 if (cp->nzones < 0) {
457 dmi = &cp->continent->menu[cp->continent->nitems];
458 memset(dmi, 0, sizeof(*dmi));
459 asprintf(&dmi->prompt, "%d", ++cp->continent->nitems);
460 dmi->title = cp->name;
462 dmi->fire = set_zone_whole_country;
466 cp->submenu = malloc(cp->nzones * sizeof(*dmi));
467 if (cp->submenu == 0)
468 errx(1, "malloc for submenu");
470 TAILQ_FOREACH(zp, &cp->zones, link) {
471 cont = zp->continent;
472 dmi = &cp->submenu[cp->nzones];
473 memset(dmi, 0, sizeof(*dmi));
474 asprintf(&dmi->prompt, "%d", ++cp->nzones);
475 dmi->title = zp->descr;
477 dmi->fire = set_zone_multi;
481 for (zp2 = TAILQ_FIRST(&cp->zones);
482 zp2->continent != cont;
483 zp2 = TAILQ_NEXT(zp2, link))
488 dmi = &cont->menu[cont->nitems];
489 memset(dmi, 0, sizeof(*dmi));
490 asprintf(&dmi->prompt, "%d", ++cont->nitems);
491 dmi->title = cp->name;
493 dmi->fire = set_zone_menu;
502 set_zone_menu(dialogMenuItem *dmi)
504 char title[64], prompt[64];
505 struct country *cp = dmi->data;
509 snprintf(title, sizeof(title), "%s Time Zones", cp->name);
510 snprintf(prompt, sizeof(prompt),
511 "Select a zone which observes the same time as your locality.");
512 menulen = cp->nzones < 16 ? cp->nzones : 16;
513 rv = dialog_menu(title, prompt, -1, -1, menulen, -cp->nzones,
514 cp->submenu, 0, 0, 0);
516 return (DITEM_RECREATE);
517 return (DITEM_LEAVE_MENU);
523 if (!confirm_zone(NULL))
524 return (DITEM_FAILURE | DITEM_RECREATE);
526 return (install_zoneinfo_file(NULL));
530 install_zoneinfo_file(const char *zoneinfo_file)
533 char title[64], prompt[SILLY_BUFFER_SIZE];
536 int fd1, fd2, copymode;
538 if (lstat(path_localtime, &sb) < 0) {
539 /* Nothing there yet... */
541 } else if (S_ISLNK(sb.st_mode))
547 snprintf(title, sizeof(title), "Info");
548 if (zoneinfo_file == NULL)
549 snprintf(prompt, sizeof(prompt),
550 "Removing %s", path_localtime);
552 snprintf(prompt, sizeof(prompt),
553 "Copying %s to %s", zoneinfo_file, path_localtime);
555 snprintf(prompt, sizeof(prompt),
556 "Creating symbolic link %s to %s",
557 path_localtime, zoneinfo_file);
559 dialog_mesgbox(title, prompt, 8, 72);
561 fprintf(stderr, "%s\n", prompt);
565 if (zoneinfo_file == NULL) {
566 if (unlink(path_localtime) < 0 && errno != ENOENT) {
567 snprintf(title, sizeof(title), "Error");
568 snprintf(prompt, sizeof(prompt),
569 "Could not delete %s: %s", path_localtime,
572 dialog_mesgbox(title, prompt, 8, 72);
574 fprintf(stderr, "%s\n", prompt);
576 return (DITEM_FAILURE | DITEM_RECREATE);
578 if (unlink(path_db) < 0 && errno != ENOENT) {
579 snprintf(title, sizeof(title), "Error");
580 snprintf(prompt, sizeof(prompt),
581 "Could not delete %s: %s", path_db,
584 dialog_mesgbox(title, prompt, 8, 72);
586 fprintf(stderr, "%s\n", prompt);
588 return (DITEM_FAILURE | DITEM_RECREATE);
591 snprintf(title, sizeof(title), "Done");
592 snprintf(prompt, sizeof(prompt),
593 "Removed %s", path_localtime);
595 dialog_msgbox(title, prompt, 8, 72, 1);
597 fprintf(stderr, "%s\n", prompt);
599 return (DITEM_LEAVE_MENU);
603 fd1 = open(zoneinfo_file, O_RDONLY, 0);
605 snprintf(title, sizeof(title), "Error");
606 snprintf(prompt, sizeof(prompt),
607 "Could not open %s: %s", zoneinfo_file,
610 dialog_mesgbox(title, prompt, 8, 72);
612 fprintf(stderr, "%s\n", prompt);
613 return (DITEM_FAILURE | DITEM_RECREATE);
616 if (unlink(path_localtime) < 0 && errno != ENOENT) {
617 snprintf(prompt, sizeof(prompt),
618 "Could not unlink %s: %s",
619 path_localtime, strerror(errno));
621 snprintf(title, sizeof(title), "Error");
622 dialog_msgbox(title, prompt, 8, 72, 1);
624 fprintf(stderr, "%s\n", prompt);
625 return (DITEM_FAILURE | DITEM_RECREATE);
628 fd2 = open(path_localtime, O_CREAT | O_EXCL | O_WRONLY,
629 S_IRUSR | S_IRGRP | S_IROTH);
631 snprintf(title, sizeof(title), "Error");
632 snprintf(prompt, sizeof(prompt),
633 "Could not open %s: %s",
634 path_localtime, strerror(errno));
636 dialog_mesgbox(title, prompt, 8, 72);
638 fprintf(stderr, "%s\n", prompt);
639 return (DITEM_FAILURE | DITEM_RECREATE);
642 while ((len = read(fd1, buf, sizeof(buf))) > 0)
643 if ((len = write(fd2, buf, len)) < 0)
647 snprintf(title, sizeof(title), "Error");
648 snprintf(prompt, sizeof(prompt),
649 "Error copying %s to %s %s", zoneinfo_file,
650 path_localtime, strerror(errno));
652 dialog_mesgbox(title, prompt, 8, 72);
654 fprintf(stderr, "%s\n", prompt);
655 /* Better to leave none than a corrupt one. */
656 unlink(path_localtime);
657 return (DITEM_FAILURE | DITEM_RECREATE);
662 if (access(zoneinfo_file, R_OK) != 0) {
663 snprintf(title, sizeof(title), "Error");
664 snprintf(prompt, sizeof(prompt),
665 "Cannot access %s: %s", zoneinfo_file,
668 dialog_mesgbox(title, prompt, 8, 72);
670 fprintf(stderr, "%s\n", prompt);
671 return (DITEM_FAILURE | DITEM_RECREATE);
673 if (unlink(path_localtime) < 0 && errno != ENOENT) {
674 snprintf(prompt, sizeof(prompt),
675 "Could not unlink %s: %s",
676 path_localtime, strerror(errno));
678 snprintf(title, sizeof(title), "Error");
679 dialog_msgbox(title, prompt, 8, 72, 1);
681 fprintf(stderr, "%s\n", prompt);
682 return (DITEM_FAILURE | DITEM_RECREATE);
684 if (symlink(zoneinfo_file, path_localtime) < 0) {
685 snprintf(title, sizeof(title), "Error");
686 snprintf(prompt, sizeof(prompt),
687 "Cannot create symbolic link %s to %s: %s",
688 path_localtime, zoneinfo_file,
691 dialog_mesgbox(title, prompt, 8, 72);
693 fprintf(stderr, "%s\n", prompt);
694 return (DITEM_FAILURE | DITEM_RECREATE);
699 snprintf(title, sizeof(title), "Done");
701 snprintf(prompt, sizeof(prompt),
702 "Copied timezone file from %s to %s",
703 zoneinfo_file, path_localtime);
705 snprintf(prompt, sizeof(prompt),
706 "Created symbolic link from %s to %s",
707 zoneinfo_file, path_localtime);
709 dialog_mesgbox(title, prompt, 8, 72);
711 fprintf(stderr, "%s\n", prompt);
715 return (DITEM_LEAVE_MENU);
719 install_zoneinfo(const char *zoneinfo)
723 char path_zoneinfo_file[MAXPATHLEN];
725 sprintf(path_zoneinfo_file, "%s/%s", path_zoneinfo, zoneinfo);
726 rv = install_zoneinfo_file(path_zoneinfo_file);
728 /* Save knowledge for later */
729 if (reallydoit && (rv & DITEM_FAILURE) == 0) {
730 if ((f = fopen(path_db, "w")) != NULL) {
731 fprintf(f, "%s\n", zoneinfo);
740 confirm_zone(const char *filename)
742 char title[64], prompt[64];
747 setenv("TZ", filename == NULL ? "" : filename, 1);
751 snprintf(title, sizeof(title), "Confirmation");
752 snprintf(prompt, sizeof(prompt),
753 "Does the abbreviation `%s' look reasonable?", tm->tm_zone);
754 rv = !dialog_yesno(title, prompt, 5, 72);
759 set_zone_multi(dialogMenuItem *dmi)
761 struct zone *zp = dmi->data;
764 if (!confirm_zone(zp->filename))
765 return (DITEM_FAILURE | DITEM_RECREATE);
767 rv = install_zoneinfo(zp->filename);
772 set_zone_whole_country(dialogMenuItem *dmi)
774 struct country *cp = dmi->data;
777 if (!confirm_zone(cp->filename))
778 return (DITEM_FAILURE | DITEM_RECREATE);
780 rv = install_zoneinfo(cp->filename);
788 fprintf(stderr, "usage: tzsetup [-nrs] [-C chroot_directory]"
789 " [zoneinfo_file | zoneinfo_name]\n");
793 #if defined(__sparc64__)
794 #define DIALOG_UTC dialog_yesno
796 #define DIALOG_UTC dialog_noyes
800 main(int argc, char **argv)
802 char title[64], prompt[128];
803 int c, fd, rv, skiputc;
806 while ((c = getopt(argc, argv, "C:nrs")) != -1) {
826 if (argc - optind > 1)
829 if (chrootenv == NULL) {
830 strcpy(path_zonetab, _PATH_ZONETAB);
831 strcpy(path_iso3166, _PATH_ISO3166);
832 strcpy(path_zoneinfo, _PATH_ZONEINFO);
833 strcpy(path_localtime, _PATH_LOCALTIME);
834 strcpy(path_db, _PATH_DB);
835 strcpy(path_wall_cmos_clock, _PATH_WALL_CMOS_CLOCK);
837 sprintf(path_zonetab, "%s/%s", chrootenv, _PATH_ZONETAB);
838 sprintf(path_iso3166, "%s/%s", chrootenv, _PATH_ISO3166);
839 sprintf(path_zoneinfo, "%s/%s", chrootenv, _PATH_ZONEINFO);
840 sprintf(path_localtime, "%s/%s", chrootenv, _PATH_LOCALTIME);
841 sprintf(path_db, "%s/%s", chrootenv, _PATH_DB);
842 sprintf(path_wall_cmos_clock, "%s/%s", chrootenv,
843 _PATH_WALL_CMOS_CLOCK);
847 /* Override the user-supplied umask. */
848 (void)umask(S_IWGRP | S_IWOTH);
850 if (reinstall == 1) {
852 char zoneinfo[MAXPATHLEN];
854 if ((f = fopen(path_db, "r")) != NULL) {
855 if (fgets(zoneinfo, sizeof(zoneinfo), f) != NULL) {
856 zoneinfo[sizeof(zoneinfo) - 1] = 0;
857 if (strlen(zoneinfo) > 0) {
858 zoneinfo[strlen(zoneinfo) - 1] = 0;
859 rv = install_zoneinfo(zoneinfo);
860 exit(rv & ~DITEM_LEAVE_MENU);
862 errx(1, "Error reading %s.\n", path_db);
866 "Unable to determine earlier installed zoneinfo "
867 "name. Check %s", path_db);
869 errx(1, "Cannot open %s for reading. Does it exist?", path_db);
873 * If the arguments on the command-line do not specify a file,
874 * then interpret it as a zoneinfo name
876 if (optind == argc - 1) {
879 if (stat(argv[optind], &sb) != 0) {
881 rv = install_zoneinfo(argv[optind]);
882 exit(rv & ~DITEM_LEAVE_MENU);
887 read_iso3166_table();
894 snprintf(title, sizeof(title),
895 "Select local or UTC (Greenwich Mean Time) clock");
896 snprintf(prompt, sizeof(prompt),
897 "Is this machine's CMOS clock set to UTC? "
898 "If it is set to local time,\n"
899 "or you don't know, please choose NO here!");
900 if (!DIALOG_UTC(title, prompt, 7, 72)) {
902 unlink(path_wall_cmos_clock);
905 fd = open(path_wall_cmos_clock,
906 O_WRONLY | O_CREAT | O_TRUNC,
907 S_IRUSR | S_IRGRP | S_IROTH);
911 path_wall_cmos_clock);
916 dialog_clear_norefresh();
918 if (optind == argc - 1) {
919 snprintf(title, sizeof(title), "Default timezone provided");
920 snprintf(prompt, sizeof(prompt),
921 "\nUse the default `%s' zone?", argv[optind]);
922 if (!dialog_yesno(title, prompt, 7, 72)) {
923 rv = install_zoneinfo_file(argv[optind]);
926 exit(rv & ~DITEM_LEAVE_MENU);
928 dialog_clear_norefresh();
930 snprintf(title, sizeof(title), "Time Zone Selector");
931 snprintf(prompt, sizeof(prompt), "Select a region");
932 dialog_menu(title, prompt, -1, -1, NCONTINENTS, -NCONTINENTS,
933 continents, 0, NULL, NULL);