Deleted Added
full compact
tzsetup.c (338440) tzsetup.c (364903)
1/*
2 * Copyright 1996 Massachusetts Institute of Technology
3 *
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

--- 19 unchanged lines hidden (view full) ---

28 */
29
30/*
31 * Second attempt at a `tzmenu' program, using the separate description
32 * files provided in newer tzdata releases.
33 */
34
35#include <sys/cdefs.h>
1/*
2 * Copyright 1996 Massachusetts Institute of Technology
3 *
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

--- 19 unchanged lines hidden (view full) ---

28 */
29
30/*
31 * Second attempt at a `tzmenu' program, using the separate description
32 * files provided in newer tzdata releases.
33 */
34
35#include <sys/cdefs.h>
36__FBSDID("$FreeBSD: stable/11/usr.sbin/tzsetup/tzsetup.c 338440 2018-09-03 06:55:38Z delphij $");
36__FBSDID("$FreeBSD: stable/11/usr.sbin/tzsetup/tzsetup.c 364903 2020-08-28 08:14:19Z philip $");
37
38#include <err.h>
39#include <errno.h>
40#include <stdio.h>
41#include <stdlib.h>
42#include <string.h>
43#include <time.h>
44#include <unistd.h>
45
46#include <sys/fcntl.h>
47#include <sys/param.h>
48#include <sys/queue.h>
49#include <sys/stat.h>
50#include <sys/sysctl.h>
51
52#ifdef HAVE_DIALOG
53#include <dialog.h>
54#endif
55
37
38#include <err.h>
39#include <errno.h>
40#include <stdio.h>
41#include <stdlib.h>
42#include <string.h>
43#include <time.h>
44#include <unistd.h>
45
46#include <sys/fcntl.h>
47#include <sys/param.h>
48#include <sys/queue.h>
49#include <sys/stat.h>
50#include <sys/sysctl.h>
51
52#ifdef HAVE_DIALOG
53#include <dialog.h>
54#endif
55
56#define _PATH_ZONETAB "/usr/share/zoneinfo/zone.tab"
56#define _PATH_ZONETAB "/usr/share/zoneinfo/zone1970.tab"
57#define _PATH_ISO3166 "/usr/share/misc/iso3166"
58#define _PATH_ZONEINFO "/usr/share/zoneinfo"
59#define _PATH_LOCALTIME "/etc/localtime"
60#define _PATH_DB "/var/db/zoneinfo"
61#define _PATH_WALL_CMOS_CLOCK "/etc/wall_cmos_clock"
62
63#ifdef PATH_MAX
64#define SILLY_BUFFER_SIZE 2*PATH_MAX

--- 147 unchanged lines hidden (view full) ---

212static int set_zone_menu(dialogMenuItem *);
213static int set_zone_utc(void);
214
215struct continent {
216 dialogMenuItem *menu;
217 int nitems;
218};
219
57#define _PATH_ISO3166 "/usr/share/misc/iso3166"
58#define _PATH_ZONEINFO "/usr/share/zoneinfo"
59#define _PATH_LOCALTIME "/etc/localtime"
60#define _PATH_DB "/var/db/zoneinfo"
61#define _PATH_WALL_CMOS_CLOCK "/etc/wall_cmos_clock"
62
63#ifdef PATH_MAX
64#define SILLY_BUFFER_SIZE 2*PATH_MAX

--- 147 unchanged lines hidden (view full) ---

212static int set_zone_menu(dialogMenuItem *);
213static int set_zone_utc(void);
214
215struct continent {
216 dialogMenuItem *menu;
217 int nitems;
218};
219
220static struct continent africa, america, antarctica, arctic, asia, atlantic;
220static struct continent africa, america, antarctica, asia, atlantic;
221static struct continent australia, europe, indian, pacific, utc;
222
223static struct continent_names {
224 const char *name;
225 struct continent *continent;
226} continent_names[] = {
227 { "Africa", &africa },
228 { "America", &america },
229 { "Antarctica", &antarctica },
221static struct continent australia, europe, indian, pacific, utc;
222
223static struct continent_names {
224 const char *name;
225 struct continent *continent;
226} continent_names[] = {
227 { "Africa", &africa },
228 { "America", &america },
229 { "Antarctica", &antarctica },
230 { "Arctic", &arctic },
231 { "Asia", &asia },
232 { "Atlantic", &atlantic },
233 { "Australia", &australia },
234 { "Europe", &europe },
235 { "Indian", &indian },
236 { "Pacific", &pacific },
237 { "UTC", &utc }
238};
239
240static struct continent_items {
241 char prompt[2];
242 char title[30];
243} continent_items[] = {
244 { "1", "Africa" },
245 { "2", "America -- North and South" },
246 { "3", "Antarctica" },
230 { "Asia", &asia },
231 { "Atlantic", &atlantic },
232 { "Australia", &australia },
233 { "Europe", &europe },
234 { "Indian", &indian },
235 { "Pacific", &pacific },
236 { "UTC", &utc }
237};
238
239static struct continent_items {
240 char prompt[2];
241 char title[30];
242} continent_items[] = {
243 { "1", "Africa" },
244 { "2", "America -- North and South" },
245 { "3", "Antarctica" },
247 { "4", "Arctic Ocean" },
248 { "5", "Asia" },
249 { "6", "Atlantic Ocean" },
250 { "7", "Australia" },
251 { "8", "Europe" },
252 { "9", "Indian Ocean" },
253 { "0", "Pacific Ocean" },
254 { "a", "UTC" }
246 { "4", "Asia" },
247 { "5", "Atlantic Ocean" },
248 { "6", "Australia" },
249 { "7", "Europe" },
250 { "8", "Indian Ocean" },
251 { "9", "Pacific Ocean" },
252 { "0", "UTC" }
255};
256
257#define NCONTINENTS \
258 (int)((sizeof(continent_items)) / (sizeof(continent_items[0])))
259static dialogMenuItem continents[NCONTINENTS];
260
253};
254
255#define NCONTINENTS \
256 (int)((sizeof(continent_items)) / (sizeof(continent_items[0])))
257static dialogMenuItem continents[NCONTINENTS];
258
261#define OCEANP(x) ((x) == 3 || (x) == 5 || (x) == 8 || (x) == 9)
259#define OCEANP(x) ((x) == 4 || (x) == 7 || (x) == 8)
262
263static int
264continent_country_menu(dialogMenuItem *continent)
265{
266 char title[64], prompt[64];
267 struct continent *contp = continent->data;
268 int isocean = OCEANP(continent - continents);
269 int menulen;

--- 207 unchanged lines hidden (view full) ---

477
478static void
479read_zones(void)
480{
481 char contbuf[16];
482 FILE *fp;
483 struct continent *cont;
484 size_t len, contlen;
260
261static int
262continent_country_menu(dialogMenuItem *continent)
263{
264 char title[64], prompt[64];
265 struct continent *contp = continent->data;
266 int isocean = OCEANP(continent - continents);
267 int menulen;

--- 207 unchanged lines hidden (view full) ---

475
476static void
477read_zones(void)
478{
479 char contbuf[16];
480 FILE *fp;
481 struct continent *cont;
482 size_t len, contlen;
485 char *line, *tlc, *file, *descr, *p;
483 char *line, *country_list, *tlc, *file, *descr, *p;
486 int lineno;
487
488 fp = fopen(path_zonetab, "r");
489 if (!fp)
490 err(1, "%s", path_zonetab);
491 lineno = 0;
492
493 while ((line = fgetln(fp, &len)) != NULL) {
494 lineno++;
495 if (line[len - 1] != '\n')
496 errx(1, "%s:%d: invalid format", path_zonetab, lineno);
497 line[len - 1] = '\0';
498 if (line[0] == '#')
499 continue;
500
484 int lineno;
485
486 fp = fopen(path_zonetab, "r");
487 if (!fp)
488 err(1, "%s", path_zonetab);
489 lineno = 0;
490
491 while ((line = fgetln(fp, &len)) != NULL) {
492 lineno++;
493 if (line[len - 1] != '\n')
494 errx(1, "%s:%d: invalid format", path_zonetab, lineno);
495 line[len - 1] = '\0';
496 if (line[0] == '#')
497 continue;
498
501 tlc = strsep(&line, "\t");
502 if (strlen(tlc) != 2)
503 errx(1, "%s:%d: invalid country code `%s'",
504 path_zonetab, lineno, tlc);
499 country_list = strsep(&line, "\t");
505 /* coord = */ strsep(&line, "\t"); /* Unused */
506 file = strsep(&line, "\t");
507 /* get continent portion from continent/country */
508 p = strchr(file, '/');
509 if (p == NULL)
510 errx(1, "%s:%d: invalid zone name `%s'", path_zonetab,
511 lineno, file);
512 contlen = p - file + 1; /* trailing nul */
513 if (contlen > sizeof(contbuf))
514 errx(1, "%s:%d: continent name in zone name `%s' too long",
515 path_zonetab, lineno, file);
516 strlcpy(contbuf, file, contlen);
517 cont = find_continent(contbuf);
518 if (!cont)
519 errx(1, "%s:%d: invalid region `%s'", path_zonetab,
520 lineno, contbuf);
521
522 descr = (line != NULL && *line != '\0') ? line : NULL;
523
500 /* coord = */ strsep(&line, "\t"); /* Unused */
501 file = strsep(&line, "\t");
502 /* get continent portion from continent/country */
503 p = strchr(file, '/');
504 if (p == NULL)
505 errx(1, "%s:%d: invalid zone name `%s'", path_zonetab,
506 lineno, file);
507 contlen = p - file + 1; /* trailing nul */
508 if (contlen > sizeof(contbuf))
509 errx(1, "%s:%d: continent name in zone name `%s' too long",
510 path_zonetab, lineno, file);
511 strlcpy(contbuf, file, contlen);
512 cont = find_continent(contbuf);
513 if (!cont)
514 errx(1, "%s:%d: invalid region `%s'", path_zonetab,
515 lineno, contbuf);
516
517 descr = (line != NULL && *line != '\0') ? line : NULL;
518
524 add_zone_to_country(lineno, tlc, descr, file, cont);
519 while (country_list != NULL) {
520 tlc = strsep(&country_list, ",");
521 if (strlen(tlc) != 2)
522 errx(1, "%s:%d: invalid country code `%s'",
523 path_zonetab, lineno, tlc);
524 add_zone_to_country(lineno, tlc, descr, file, cont);
525 }
525 }
526 fclose(fp);
527}
528
529static void
530make_menus(void)
531{
532 struct country *cp;

--- 536 unchanged lines hidden ---
526 }
527 fclose(fp);
528}
529
530static void
531make_menus(void)
532{
533 struct country *cp;

--- 536 unchanged lines hidden ---