tzsetup.c (44e86fbdcf5a3e625095652a3d0ab99532e54eea) | tzsetup.c (f872dde34c6af8c27e16905ebfdb62cddb4c35ba) |
---|---|
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 --- 35 unchanged lines hidden (view full) --- 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 | 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 --- 35 unchanged lines hidden (view full) --- 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> | 52#ifdef HAVE_BSDDIALOG 53#include <bsddialog.h> |
54#endif 55 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" --- 19 unchanged lines hidden (view full) --- 81static int reallydoit = 1; 82static int reinstall = 0; 83static char *chrootenv = NULL; 84 85static void usage(void); 86static int install_zoneinfo(const char *zoneinfo); 87static int install_zoneinfo_file(const char *zoneinfo_file); 88 | 54#endif 55 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" --- 19 unchanged lines hidden (view full) --- 81static int reallydoit = 1; 82static int reinstall = 0; 83static char *chrootenv = NULL; 84 85static void usage(void); 86static int install_zoneinfo(const char *zoneinfo); 87static int install_zoneinfo_file(const char *zoneinfo_file); 88 |
89#ifdef HAVE_DIALOG | 89#ifdef HAVE_BSDDIALOG 90static struct bsddialog_conf conf; 91 |
90/* for use in describing more exotic behaviors */ 91typedef struct dialogMenuItem { 92 char *prompt; 93 char *title; 94 int (*fire)(struct dialogMenuItem *self); 95 void *data; 96} dialogMenuItem; 97 --- 25 unchanged lines hidden (view full) --- 123 } 124 125 len = strlen(p); 126 max_len = MAX(max_len, len); 127 return (max_len); 128} 129 130static int | 92/* for use in describing more exotic behaviors */ 93typedef struct dialogMenuItem { 94 char *prompt; 95 char *title; 96 int (*fire)(struct dialogMenuItem *self); 97 void *data; 98} dialogMenuItem; 99 --- 25 unchanged lines hidden (view full) --- 125 } 126 127 len = strlen(p); 128 max_len = MAX(max_len, len); 129 return (max_len); 130} 131 132static int |
131xdialog_menu(const char *title, const char *cprompt, int height, int width, | 133xdialog_menu(char *title, char *cprompt, int height, int width, |
132 int menu_height, int item_no, dialogMenuItem *ditems) 133{ 134 int i, result, choice = 0; | 134 int menu_height, int item_no, dialogMenuItem *ditems) 135{ 136 int i, result, choice = 0; |
135 DIALOG_LISTITEM *listitems; 136 DIALOG_VARS save_vars; | 137 struct bsddialog_menuitem *listitems; |
137 | 138 |
138 dlg_save_vars(&save_vars); 139 | |
140 /* initialize list items */ | 139 /* initialize list items */ |
141 listitems = dlg_calloc(DIALOG_LISTITEM, item_no + 1); 142 assert_ptr(listitems, "xdialog_menu"); | 140 listitems = calloc(item_no + 1, sizeof(struct bsddialog_menuitem)); 141 if (listitems == NULL) 142 errx(1, "Failed to allocate memory in xdialog_menu"); |
143 for (i = 0; i < item_no; i++) { | 143 for (i = 0; i < item_no; i++) { |
144 listitems[i].prefix = ""; 145 listitems[i].depth = 0; 146 listitems[i].bottomdesc = ""; 147 listitems[i].on = false; |
|
144 listitems[i].name = ditems[i].prompt; | 148 listitems[i].name = ditems[i].prompt; |
145 listitems[i].text = ditems[i].title; | 149 listitems[i].desc = ditems[i].title; |
146 } 147 148 /* calculate height */ 149 if (height < 0) 150 height = xdialog_count_rows(cprompt) + menu_height + 4 + 2; | 150 } 151 152 /* calculate height */ 153 if (height < 0) 154 height = xdialog_count_rows(cprompt) + menu_height + 4 + 2; |
151 if (height > LINES) 152 height = LINES; | 155 if (height > bsddialog_terminalheight()) 156 height = bsddialog_terminalheight() - 2; |
153 154 /* calculate width */ 155 if (width < 0) { 156 int tag_x = 0; 157 158 for (i = 0; i < item_no; i++) { 159 int j, l; 160 161 l = strlen(listitems[i].name); 162 for (j = 0; j < item_no; j++) { | 157 158 /* calculate width */ 159 if (width < 0) { 160 int tag_x = 0; 161 162 for (i = 0; i < item_no; i++) { 163 int j, l; 164 165 l = strlen(listitems[i].name); 166 for (j = 0; j < item_no; j++) { |
163 int k = strlen(listitems[j].text); | 167 int k = strlen(listitems[j].desc); |
164 tag_x = MAX(tag_x, l + k + 2); 165 } 166 } 167 width = MAX(xdialog_count_columns(cprompt), title != NULL ? 168 xdialog_count_columns(title) : 0); 169 width = MAX(width, tag_x + 4) + 4; 170 } 171 width = MAX(width, 24); | 168 tag_x = MAX(tag_x, l + k + 2); 169 } 170 } 171 width = MAX(xdialog_count_columns(cprompt), title != NULL ? 172 xdialog_count_columns(title) : 0); 173 width = MAX(width, tag_x + 4) + 4; 174 } 175 width = MAX(width, 24); |
172 if (width > COLS) 173 width = COLS; | 176 if (width > bsddialog_terminalwidth()) 177 width = bsddialog_terminalwidth() - 3; |
174 175again: | 178 179again: |
176 dialog_vars.default_item = listitems[choice].name; 177 result = dlg_menu(title, cprompt, height, width, 178 menu_height, item_no, listitems, &choice, NULL); | 180 conf.menu.default_item = listitems[choice].name; 181 conf.title = title; 182 result = bsddialog_menu(conf, cprompt, height, width, 183 menu_height, item_no, listitems, NULL); 184 for (int i = 0; i < item_no; i++) 185 if (listitems[i].on) 186 choice = i; |
179 switch (result) { | 187 switch (result) { |
180 case DLG_EXIT_ESC: | 188 case BSDDIALOG_ESC: |
181 result = -1; 182 break; | 189 result = -1; 190 break; |
183 case DLG_EXIT_OK: | 191 case BSDDIALOG_YESOK: |
184 if (ditems[choice].fire != NULL) { 185 int status; 186 187 status = ditems[choice].fire(ditems + choice); 188 if (status & DITEM_RECREATE) { | 192 if (ditems[choice].fire != NULL) { 193 int status; 194 195 status = ditems[choice].fire(ditems + choice); 196 if (status & DITEM_RECREATE) { |
189 dlg_clear(); | |
190 goto again; 191 } 192 } 193 result = 0; 194 break; | 197 goto again; 198 } 199 } 200 result = 0; 201 break; |
195 case DLG_EXIT_CANCEL: | 202 case BSDDIALOG_NOCANCEL: |
196 default: 197 result = 1; 198 break; 199 } 200 201 free(listitems); | 203 default: 204 result = 1; 205 break; 206 } 207 208 free(listitems); |
202 dlg_restore_vars(&save_vars); | |
203 return (result); 204} 205 206static int usedialog = 1; 207 208static int confirm_zone(const char *filename); 209static int continent_country_menu(dialogMenuItem *); 210static int set_zone_multi(dialogMenuItem *); --- 441 unchanged lines hidden (view full) --- 652 return (DITEM_FAILURE | DITEM_RECREATE); 653 654 return (install_zoneinfo("UTC")); 655} 656 657static int 658confirm_zone(const char *filename) 659{ | 209 return (result); 210} 211 212static int usedialog = 1; 213 214static int confirm_zone(const char *filename); 215static int continent_country_menu(dialogMenuItem *); 216static int set_zone_multi(dialogMenuItem *); --- 441 unchanged lines hidden (view full) --- 658 return (DITEM_FAILURE | DITEM_RECREATE); 659 660 return (install_zoneinfo("UTC")); 661} 662 663static int 664confirm_zone(const char *filename) 665{ |
660 char title[64], prompt[64]; | 666 char prompt[64]; |
661 time_t t = time(0); 662 struct tm *tm; 663 int rv; 664 665 setenv("TZ", filename, 1); 666 tzset(); 667 tm = localtime(&t); 668 | 667 time_t t = time(0); 668 struct tm *tm; 669 int rv; 670 671 setenv("TZ", filename, 1); 672 tzset(); 673 tm = localtime(&t); 674 |
669 snprintf(title, sizeof(title), "Confirmation"); | |
670 snprintf(prompt, sizeof(prompt), 671 "Does the abbreviation `%s' look reasonable?", tm->tm_zone); | 675 snprintf(prompt, sizeof(prompt), 676 "Does the abbreviation `%s' look reasonable?", tm->tm_zone); |
672 rv = !dialog_yesno(title, prompt, 5, 72); | 677 conf.title = "Confirmation"; 678 rv = !bsddialog_yesno(conf, prompt, 5, 72); |
673 return (rv); 674} 675 676static int 677set_zone_multi(dialogMenuItem *dmi) 678{ 679 struct zone *zp = dmi->data; 680 int rv; --- 19 unchanged lines hidden (view full) --- 700} 701 702#endif 703 704static int 705install_zoneinfo_file(const char *zoneinfo_file) 706{ 707 char buf[1024]; | 679 return (rv); 680} 681 682static int 683set_zone_multi(dialogMenuItem *dmi) 684{ 685 struct zone *zp = dmi->data; 686 int rv; --- 19 unchanged lines hidden (view full) --- 706} 707 708#endif 709 710static int 711install_zoneinfo_file(const char *zoneinfo_file) 712{ 713 char buf[1024]; |
708 char title[64], prompt[SILLY_BUFFER_SIZE]; | 714 char prompt[SILLY_BUFFER_SIZE]; |
709 struct stat sb; 710 ssize_t len; 711 int fd1, fd2, copymode; 712 713 if (lstat(path_localtime, &sb) < 0) { 714 /* Nothing there yet... */ 715 copymode = 1; 716 } else if (S_ISLNK(sb.st_mode)) 717 copymode = 0; 718 else 719 copymode = 1; 720 721#ifdef VERBOSE | 715 struct stat sb; 716 ssize_t len; 717 int fd1, fd2, copymode; 718 719 if (lstat(path_localtime, &sb) < 0) { 720 /* Nothing there yet... */ 721 copymode = 1; 722 } else if (S_ISLNK(sb.st_mode)) 723 copymode = 0; 724 else 725 copymode = 1; 726 727#ifdef VERBOSE |
722 snprintf(title, sizeof(title), "Info"); | |
723 if (copymode) 724 snprintf(prompt, sizeof(prompt), 725 "Copying %s to %s", zoneinfo_file, path_localtime); 726 else 727 snprintf(prompt, sizeof(prompt), 728 "Creating symbolic link %s to %s", 729 path_localtime, zoneinfo_file); | 728 if (copymode) 729 snprintf(prompt, sizeof(prompt), 730 "Copying %s to %s", zoneinfo_file, path_localtime); 731 else 732 snprintf(prompt, sizeof(prompt), 733 "Creating symbolic link %s to %s", 734 path_localtime, zoneinfo_file); |
730#ifdef HAVE_DIALOG | 735#ifdef HAVE_BSDDIALOG |
731 if (usedialog) | 736 if (usedialog) |
732 dialog_msgbox(title, prompt, 8, 72, 1); | 737 conf.title = "Info"; 738 bsddialog_msgbox(conf, prompt, 8, 72); |
733 else 734#endif 735 fprintf(stderr, "%s\n", prompt); 736#endif 737 738 if (reallydoit) { 739 if (copymode) { 740 fd1 = open(zoneinfo_file, O_RDONLY, 0); 741 if (fd1 < 0) { | 739 else 740#endif 741 fprintf(stderr, "%s\n", prompt); 742#endif 743 744 if (reallydoit) { 745 if (copymode) { 746 fd1 = open(zoneinfo_file, O_RDONLY, 0); 747 if (fd1 < 0) { |
742 snprintf(title, sizeof(title), "Error"); | |
743 snprintf(prompt, sizeof(prompt), 744 "Could not open %s: %s", zoneinfo_file, 745 strerror(errno)); | 748 snprintf(prompt, sizeof(prompt), 749 "Could not open %s: %s", zoneinfo_file, 750 strerror(errno)); |
746#ifdef HAVE_DIALOG 747 if (usedialog) 748 dialog_msgbox(title, prompt, 8, 72, 1); 749 else | 751#ifdef HAVE_BSDDIALOG 752 if (usedialog) { 753 conf.title = "Error"; 754 bsddialog_msgbox(conf, prompt, 8, 72); 755 } else |
750#endif 751 fprintf(stderr, "%s\n", prompt); 752 return (DITEM_FAILURE | DITEM_RECREATE); 753 } 754 755 if (unlink(path_localtime) < 0 && errno != ENOENT) { 756 snprintf(prompt, sizeof(prompt), 757 "Could not delete %s: %s", 758 path_localtime, strerror(errno)); | 756#endif 757 fprintf(stderr, "%s\n", prompt); 758 return (DITEM_FAILURE | DITEM_RECREATE); 759 } 760 761 if (unlink(path_localtime) < 0 && errno != ENOENT) { 762 snprintf(prompt, sizeof(prompt), 763 "Could not delete %s: %s", 764 path_localtime, strerror(errno)); |
759#ifdef HAVE_DIALOG | 765#ifdef HAVE_BSDDIALOG |
760 if (usedialog) { | 766 if (usedialog) { |
761 snprintf(title, sizeof(title), "Error"); 762 dialog_msgbox(title, prompt, 8, 72, 1); | 767 conf.title = "error"; 768 bsddialog_msgbox(conf, prompt, 8, 72); |
763 } else 764#endif 765 fprintf(stderr, "%s\n", prompt); 766 return (DITEM_FAILURE | DITEM_RECREATE); 767 } 768 769 fd2 = open(path_localtime, O_CREAT | O_EXCL | O_WRONLY, 770 S_IRUSR | S_IRGRP | S_IROTH); 771 if (fd2 < 0) { | 769 } else 770#endif 771 fprintf(stderr, "%s\n", prompt); 772 return (DITEM_FAILURE | DITEM_RECREATE); 773 } 774 775 fd2 = open(path_localtime, O_CREAT | O_EXCL | O_WRONLY, 776 S_IRUSR | S_IRGRP | S_IROTH); 777 if (fd2 < 0) { |
772 snprintf(title, sizeof(title), "Error"); | |
773 snprintf(prompt, sizeof(prompt), 774 "Could not open %s: %s", 775 path_localtime, strerror(errno)); | 778 snprintf(prompt, sizeof(prompt), 779 "Could not open %s: %s", 780 path_localtime, strerror(errno)); |
776#ifdef HAVE_DIALOG 777 if (usedialog) 778 dialog_msgbox(title, prompt, 8, 72, 1); 779 else | 781#ifdef HAVE_BSDDIALOG 782 if (usedialog) { 783 conf.title = "Error"; 784 bsddialog_msgbox(conf, prompt, 8, 72); 785 } else |
780#endif 781 fprintf(stderr, "%s\n", prompt); 782 return (DITEM_FAILURE | DITEM_RECREATE); 783 } 784 785 while ((len = read(fd1, buf, sizeof(buf))) > 0) 786 if ((len = write(fd2, buf, len)) < 0) 787 break; 788 789 if (len == -1) { | 786#endif 787 fprintf(stderr, "%s\n", prompt); 788 return (DITEM_FAILURE | DITEM_RECREATE); 789 } 790 791 while ((len = read(fd1, buf, sizeof(buf))) > 0) 792 if ((len = write(fd2, buf, len)) < 0) 793 break; 794 795 if (len == -1) { |
790 snprintf(title, sizeof(title), "Error"); | |
791 snprintf(prompt, sizeof(prompt), 792 "Error copying %s to %s %s", zoneinfo_file, 793 path_localtime, strerror(errno)); | 796 snprintf(prompt, sizeof(prompt), 797 "Error copying %s to %s %s", zoneinfo_file, 798 path_localtime, strerror(errno)); |
794#ifdef HAVE_DIALOG 795 if (usedialog) 796 dialog_msgbox(title, prompt, 8, 72, 1); 797 else | 799#ifdef HAVE_BSDDIALOG 800 if (usedialog) { 801 conf.title = "Error"; 802 bsddialog_msgbox(conf, prompt, 8, 72); 803 } else |
798#endif 799 fprintf(stderr, "%s\n", prompt); 800 /* Better to leave none than a corrupt one. */ 801 unlink(path_localtime); 802 return (DITEM_FAILURE | DITEM_RECREATE); 803 } 804 close(fd1); 805 close(fd2); 806 } else { 807 if (access(zoneinfo_file, R_OK) != 0) { | 804#endif 805 fprintf(stderr, "%s\n", prompt); 806 /* Better to leave none than a corrupt one. */ 807 unlink(path_localtime); 808 return (DITEM_FAILURE | DITEM_RECREATE); 809 } 810 close(fd1); 811 close(fd2); 812 } else { 813 if (access(zoneinfo_file, R_OK) != 0) { |
808 snprintf(title, sizeof(title), "Error"); | |
809 snprintf(prompt, sizeof(prompt), 810 "Cannot access %s: %s", zoneinfo_file, 811 strerror(errno)); | 814 snprintf(prompt, sizeof(prompt), 815 "Cannot access %s: %s", zoneinfo_file, 816 strerror(errno)); |
812#ifdef HAVE_DIALOG 813 if (usedialog) 814 dialog_msgbox(title, prompt, 8, 72, 1); 815 else | 817#ifdef HAVE_BSDDIALOG 818 if (usedialog) { 819 conf.title = "Error"; 820 bsddialog_msgbox(conf, prompt, 8, 72); 821 } else |
816#endif 817 fprintf(stderr, "%s\n", prompt); 818 return (DITEM_FAILURE | DITEM_RECREATE); 819 } 820 if (unlink(path_localtime) < 0 && errno != ENOENT) { 821 snprintf(prompt, sizeof(prompt), 822 "Could not delete %s: %s", 823 path_localtime, strerror(errno)); | 822#endif 823 fprintf(stderr, "%s\n", prompt); 824 return (DITEM_FAILURE | DITEM_RECREATE); 825 } 826 if (unlink(path_localtime) < 0 && errno != ENOENT) { 827 snprintf(prompt, sizeof(prompt), 828 "Could not delete %s: %s", 829 path_localtime, strerror(errno)); |
824#ifdef HAVE_DIALOG | 830#ifdef HAVE_BSDDIALOG |
825 if (usedialog) { | 831 if (usedialog) { |
826 snprintf(title, sizeof(title), "Error"); 827 dialog_msgbox(title, prompt, 8, 72, 1); | 832 conf.title = "Error"; 833 bsddialog_msgbox(conf, prompt, 8, 72); |
828 } else 829#endif 830 fprintf(stderr, "%s\n", prompt); 831 return (DITEM_FAILURE | DITEM_RECREATE); 832 } 833 if (symlink(zoneinfo_file, path_localtime) < 0) { | 834 } else 835#endif 836 fprintf(stderr, "%s\n", prompt); 837 return (DITEM_FAILURE | DITEM_RECREATE); 838 } 839 if (symlink(zoneinfo_file, path_localtime) < 0) { |
834 snprintf(title, sizeof(title), "Error"); | |
835 snprintf(prompt, sizeof(prompt), 836 "Cannot create symbolic link %s to %s: %s", 837 path_localtime, zoneinfo_file, 838 strerror(errno)); | 840 snprintf(prompt, sizeof(prompt), 841 "Cannot create symbolic link %s to %s: %s", 842 path_localtime, zoneinfo_file, 843 strerror(errno)); |
839#ifdef HAVE_DIALOG 840 if (usedialog) 841 dialog_msgbox(title, prompt, 8, 72, 1); 842 else | 844#ifdef HAVE_BSDDIALOG 845 if (usedialog) { 846 conf.title = "Error"; 847 bsddialog_msgbox(conf, prompt, 8, 72); 848 } else |
843#endif 844 fprintf(stderr, "%s\n", prompt); 845 return (DITEM_FAILURE | DITEM_RECREATE); 846 } 847 } 848 849#ifdef VERBOSE | 849#endif 850 fprintf(stderr, "%s\n", prompt); 851 return (DITEM_FAILURE | DITEM_RECREATE); 852 } 853 } 854 855#ifdef VERBOSE |
850 snprintf(title, sizeof(title), "Done"); | |
851 if (copymode) 852 snprintf(prompt, sizeof(prompt), 853 "Copied timezone file from %s to %s", 854 zoneinfo_file, path_localtime); 855 else 856 snprintf(prompt, sizeof(prompt), 857 "Created symbolic link from %s to %s", 858 zoneinfo_file, path_localtime); | 856 if (copymode) 857 snprintf(prompt, sizeof(prompt), 858 "Copied timezone file from %s to %s", 859 zoneinfo_file, path_localtime); 860 else 861 snprintf(prompt, sizeof(prompt), 862 "Created symbolic link from %s to %s", 863 zoneinfo_file, path_localtime); |
859#ifdef HAVE_DIALOG 860 if (usedialog) 861 dialog_msgbox(title, prompt, 8, 72, 1); 862 else | 864#ifdef HAVE_BSDDIALOG 865 if (usedialog) { 866 conf.title = "Done"; 867 bsddialog_msgbox(conf, prompt, 8, 72); 868 } else |
863#endif 864 fprintf(stderr, "%s\n", prompt); 865#endif 866 } /* reallydoit */ 867 868 return (DITEM_LEAVE_MENU); 869} 870 --- 27 unchanged lines hidden (view full) --- 898 fprintf(stderr, "usage: tzsetup [-nrs] [-C chroot_directory]" 899 " [zoneinfo_file | zoneinfo_name]\n"); 900 exit(1); 901} 902 903int 904main(int argc, char **argv) 905{ | 869#endif 870 fprintf(stderr, "%s\n", prompt); 871#endif 872 } /* reallydoit */ 873 874 return (DITEM_LEAVE_MENU); 875} 876 --- 27 unchanged lines hidden (view full) --- 904 fprintf(stderr, "usage: tzsetup [-nrs] [-C chroot_directory]" 905 " [zoneinfo_file | zoneinfo_name]\n"); 906 exit(1); 907} 908 909int 910main(int argc, char **argv) 911{ |
906#ifdef HAVE_DIALOG 907 char title[64], prompt[128]; | 912#ifdef HAVE_BSDDIALOG 913 char prompt[128]; |
908 int fd; 909#endif 910 int c, rv, skiputc; 911 char vm_guest[16] = ""; 912 size_t len = sizeof(vm_guest); 913 914 skiputc = 0; 915 --- 7 unchanged lines hidden (view full) --- 923 case 'C': 924 chrootenv = optarg; 925 break; 926 case 'n': 927 reallydoit = 0; 928 break; 929 case 'r': 930 reinstall = 1; | 914 int fd; 915#endif 916 int c, rv, skiputc; 917 char vm_guest[16] = ""; 918 size_t len = sizeof(vm_guest); 919 920 skiputc = 0; 921 --- 7 unchanged lines hidden (view full) --- 929 case 'C': 930 chrootenv = optarg; 931 break; 932 case 'n': 933 reallydoit = 0; 934 break; 935 case 'r': 936 reinstall = 1; |
931#ifdef HAVE_DIALOG | 937#ifdef HAVE_BSDDIALOG |
932 usedialog = 0; 933#endif 934 break; 935 case 's': 936 skiputc = 1; 937 break; 938 default: 939 usage(); --- 48 unchanged lines hidden (view full) --- 988 /* 989 * If the arguments on the command-line do not specify a file, 990 * then interpret it as a zoneinfo name 991 */ 992 if (optind == argc - 1) { 993 struct stat sb; 994 995 if (stat(argv[optind], &sb) != 0) { | 938 usedialog = 0; 939#endif 940 break; 941 case 's': 942 skiputc = 1; 943 break; 944 default: 945 usage(); --- 48 unchanged lines hidden (view full) --- 994 /* 995 * If the arguments on the command-line do not specify a file, 996 * then interpret it as a zoneinfo name 997 */ 998 if (optind == argc - 1) { 999 struct stat sb; 1000 1001 if (stat(argv[optind], &sb) != 0) { |
996#ifdef HAVE_DIALOG | 1002#ifdef HAVE_BSDDIALOG |
997 usedialog = 0; 998#endif 999 rv = install_zoneinfo(argv[optind]); 1000 exit(rv & ~DITEM_LEAVE_MENU); 1001 } 1002 /* FALLTHROUGH */ 1003 } | 1003 usedialog = 0; 1004#endif 1005 rv = install_zoneinfo(argv[optind]); 1006 exit(rv & ~DITEM_LEAVE_MENU); 1007 } 1008 /* FALLTHROUGH */ 1009 } |
1004#ifdef HAVE_DIALOG | 1010#ifdef HAVE_BSDDIALOG |
1005 1006 read_iso3166_table(); 1007 read_zones(); 1008 sort_countries(); 1009 make_menus(); 1010 | 1011 1012 read_iso3166_table(); 1013 read_zones(); 1014 sort_countries(); 1015 make_menus(); 1016 |
1011 init_dialog(stdin, stdout); | 1017 bsddialog_initconf(&conf); 1018 conf.clear = true; 1019 1020 if (bsddialog_init() < 0) 1021 return (1); 1022 |
1012 if (skiputc == 0) { | 1023 if (skiputc == 0) { |
1013 DIALOG_VARS save_vars; | |
1014 int yesno; 1015 | 1024 int yesno; 1025 |
1016 snprintf(title, sizeof(title), 1017 "Select local or UTC (Greenwich Mean Time) clock"); | |
1018 snprintf(prompt, sizeof(prompt), 1019 "Is this machine's CMOS clock set to UTC? " 1020 "If it is set to local time,\n" 1021 "or you don't know, please choose NO here!"); | 1026 snprintf(prompt, sizeof(prompt), 1027 "Is this machine's CMOS clock set to UTC? " 1028 "If it is set to local time,\n" 1029 "or you don't know, please choose NO here!"); |
1022 dlg_save_vars(&save_vars); 1023 dialog_vars.defaultno = TRUE; 1024 yesno = dialog_yesno(title, prompt, 7, 73); 1025 dlg_restore_vars(&save_vars); | 1030 1031 conf.button.defaultno = true; 1032 conf.title = "Select local or UTC (Greenwich Mean Time) clock"; 1033 yesno = bsddialog_yesno(conf, prompt, 7, 73); 1034 conf.button.defaultno = false; |
1026 if (!yesno) { 1027 if (reallydoit) 1028 unlink(path_wall_cmos_clock); 1029 } else { 1030 if (reallydoit) { 1031 fd = open(path_wall_cmos_clock, 1032 O_WRONLY | O_CREAT | O_TRUNC, 1033 S_IRUSR | S_IRGRP | S_IROTH); 1034 if (fd < 0) { | 1035 if (!yesno) { 1036 if (reallydoit) 1037 unlink(path_wall_cmos_clock); 1038 } else { 1039 if (reallydoit) { 1040 fd = open(path_wall_cmos_clock, 1041 O_WRONLY | O_CREAT | O_TRUNC, 1042 S_IRUSR | S_IRGRP | S_IROTH); 1043 if (fd < 0) { |
1035 end_dialog(); | 1044 bsddialog_end(); |
1036 err(1, "create %s", 1037 path_wall_cmos_clock); 1038 } 1039 close(fd); 1040 } 1041 } | 1045 err(1, "create %s", 1046 path_wall_cmos_clock); 1047 } 1048 close(fd); 1049 } 1050 } |
1042 dlg_clear(); | |
1043 } 1044 if (optind == argc - 1) { | 1051 } 1052 if (optind == argc - 1) { |
1045 snprintf(title, sizeof(title), "Default timezone provided"); | |
1046 snprintf(prompt, sizeof(prompt), 1047 "\nUse the default `%s' zone?", argv[optind]); | 1053 snprintf(prompt, sizeof(prompt), 1054 "\nUse the default `%s' zone?", argv[optind]); |
1048 if (!dialog_yesno(title, prompt, 7, 72)) { | 1055 conf.title = "Default timezone provided"; 1056 if (!bsddialog_yesno(conf, prompt, 7, 72)) { |
1049 rv = install_zoneinfo_file(argv[optind]); | 1057 rv = install_zoneinfo_file(argv[optind]); |
1050 dlg_clear(); 1051 end_dialog(); | 1058 bsddialog_end(); |
1052 exit(rv & ~DITEM_LEAVE_MENU); 1053 } | 1059 exit(rv & ~DITEM_LEAVE_MENU); 1060 } |
1054 dlg_clear(); | |
1055 } | 1061 } |
1056 snprintf(title, sizeof(title), "Time Zone Selector"); 1057 snprintf(prompt, sizeof(prompt), "Select a region"); 1058 xdialog_menu(title, prompt, -1, -1, NCONTINENTS, NCONTINENTS, 1059 continents); | 1062 xdialog_menu("Time Zone Selector", "Select a region", -1, -1, 1063 NCONTINENTS, NCONTINENTS, continents); |
1060 | 1064 |
1061 dlg_clear(); 1062 end_dialog(); | 1065 bsddialog_end(); |
1063#else 1064 usage(); 1065#endif 1066 return (0); 1067} | 1066#else 1067 usage(); 1068#endif 1069 return (0); 1070} |