diff options
author | jkh <jkh@FreeBSD.org> | 1997-01-03 06:32:39 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 1997-01-03 06:32:39 +0000 |
commit | ea0a75ee129d9998ed792e26f9256aa68fcf5bea (patch) | |
tree | 896ba9fcb9176c55630520639c25dbe04e995774 /usr.sbin/sysinstall/tcpip.c | |
parent | b755851a75932ff275e1d0b9fd2283b881a80139 (diff) | |
download | FreeBSD-src-ea0a75ee129d9998ed792e26f9256aa68fcf5bea.zip FreeBSD-src-ea0a75ee129d9998ed792e26f9256aa68fcf5bea.tar.gz |
Do something I've wanted to do for quite some time - collapse all the
common layout code into some work functions and make all the layout-using
routine adopt them. Also reorganize includes and generally clean up.
Diffstat (limited to 'usr.sbin/sysinstall/tcpip.c')
-rw-r--r-- | usr.sbin/sysinstall/tcpip.c | 211 |
1 files changed, 44 insertions, 167 deletions
diff --git a/usr.sbin/sysinstall/tcpip.c b/usr.sbin/sysinstall/tcpip.c index 96cbdb6..db7b252 100644 --- a/usr.sbin/sysinstall/tcpip.c +++ b/usr.sbin/sysinstall/tcpip.c @@ -1,5 +1,5 @@ /* - * $Id: tcpip.c,v 1.52 1996/12/12 22:44:22 jkh Exp $ + * $Id: tcpip.c,v 1.53 1996/12/14 23:09:08 jkh Exp $ * * Copyright (c) 1995 * Gary J Palmer. All rights reserved. @@ -37,17 +37,8 @@ * -jkh */ -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/param.h> -#include <string.h> -#include <dialog.h> -#include "ui_objects.h" -#include "dir.h" -#include "dialog.priv.h" -#include "colors.h" #include "sysinstall.h" +#include <sys/param.h> /* The help file for the TCP/IP setup screen */ #define TCP_HELPFILE "tcp" @@ -65,62 +56,49 @@ static char ipaddr[IPADDR_FIELD_LEN], netmask[IPADDR_FIELD_LEN], extras[EXTRAS_F #define TCP_DIALOG_WIDTH COLS - 16 #define TCP_DIALOG_HEIGHT LINES - 2 -/* The screen layout structure */ -typedef struct _layout { - int y; /* x & Y co-ordinates */ - int x; - int len; /* The size of the dialog on the screen */ - int maxlen; /* How much the user can type in ... */ - char *prompt; /* The string for the prompt */ - char *help; /* The display for the help line */ - void *var; /* The var to set when this changes */ - int type; /* The type of the dialog to create */ - void *obj; /* The obj pointer returned by libdialog */ -} Layout; - static Layout layout[] = { #define LAYOUT_HOSTNAME 0 -{ 1, 2, 25, HOSTNAME_FIELD_LEN - 1, + { 1, 2, 25, HOSTNAME_FIELD_LEN - 1, "Host:", "Your fully-qualified hostname, e.g. foo.bar.com", hostname, STRINGOBJ, NULL }, #define LAYOUT_DOMAINNAME 1 -{ 1, 35, 20, HOSTNAME_FIELD_LEN - 1, + { 1, 35, 20, HOSTNAME_FIELD_LEN - 1, "Domain:", "The name of the domain that your machine is in, e.g. bar.com", domainname, STRINGOBJ, NULL }, #define LAYOUT_GATEWAY 2 -{ 5, 2, 18, IPADDR_FIELD_LEN - 1, + { 5, 2, 18, IPADDR_FIELD_LEN - 1, "Gateway:", "IP address of host forwarding packets to non-local destinations", gateway, STRINGOBJ, NULL }, #define LAYOUT_NAMESERVER 3 -{ 5, 35, 18, IPADDR_FIELD_LEN - 1, + { 5, 35, 18, IPADDR_FIELD_LEN - 1, "Name server:", "IP address of your local DNS server", nameserver, STRINGOBJ, NULL }, #define LAYOUT_IPADDR 4 -{ 10, 10, 18, IPADDR_FIELD_LEN - 1, + { 10, 10, 18, IPADDR_FIELD_LEN - 1, "IP Address:", "The IP address to be used for this interface", ipaddr, STRINGOBJ, NULL }, #define LAYOUT_NETMASK 5 -{ 10, 35, 18, IPADDR_FIELD_LEN - 1, + { 10, 35, 18, IPADDR_FIELD_LEN - 1, "Netmask:", "The netmask for this interface, e.g. 0xffffff00 for a class C network", netmask, STRINGOBJ, NULL }, #define LAYOUT_EXTRAS 6 -{ 14, 10, 37, HOSTNAME_FIELD_LEN - 1, + { 14, 10, 37, HOSTNAME_FIELD_LEN - 1, "Extra options to ifconfig:", "Any interface-specific options to ifconfig you would like to add", extras, STRINGOBJ, NULL }, #define LAYOUT_OKBUTTON 7 -{ 19, 15, 0, 0, + { 19, 15, 0, 0, "OK", "Select this if you are happy with these settings", &okbutton, BUTTONOBJ, NULL }, #define LAYOUT_CANCELBUTTON 8 -{ 19, 35, 0, 0, + { 19, 35, 0, 0, "CANCEL", "Select this if you wish to cancel this screen", &cancelbutton, BUTTONOBJ, NULL }, -{ NULL }, + { NULL }, }; #define _validByte(b) ((b) >= 0 && (b) <= 255) @@ -147,9 +125,8 @@ verifyIP(char *ip) return 0; } -/* Check for the settings on the screen - the per interface stuff is +/* Check for the settings on the screen - the per-interface stuff is moved to the main handling code now to do it on the fly - sigh */ - static int verifySettings(void) { @@ -174,11 +151,9 @@ tcpOpenDialog(Device *devp) { WINDOW *ds_win, *save; ComposeObj *obj = NULL; - ComposeObj *first, *last; - int n=0, quit=FALSE, cancel=FALSE, ret; - int max; + int n = 0, cancel = FALSE; + int max, ret; char *tmp; - char help[FILENAME_MAX]; char title[80]; if (!RunningAsInit) { @@ -188,18 +163,16 @@ tcpOpenDialog(Device *devp) } save = savescr(); dialog_clear_norefresh(); - /* We need a curses window */ - ds_win = newwin(LINES, COLS, 0, 0); - if (ds_win == 0) - msgFatal("Cannot open TCP/IP dialog window!!"); - /* Say where our help comes from */ - use_helpfile(systemHelpFile(TCP_HELPFILE, help)); + /* We need a curses window */ + if (!(ds_win = openLayoutDialog(TCP_HELPFILE, " Network Configuration ", + TCP_DIALOG_X, TCP_DIALOG_Y, TCP_DIALOG_WIDTH, TCP_DIALOG_HEIGHT))) { + beep(); + msgConfirm("Cannot open TCP/IP dialog window!!"); + return DITEM_FAILURE; + } - /* Setup a nice screen for us to splat stuff onto */ - draw_box(ds_win, TCP_DIALOG_Y, TCP_DIALOG_X, TCP_DIALOG_HEIGHT, TCP_DIALOG_WIDTH, dialog_attr, border_attr); - wattrset(ds_win, dialog_attr); - mvwaddstr(ds_win, TCP_DIALOG_Y, TCP_DIALOG_X + 20, " Network Configuration "); + /* Draw interface configuration box */ draw_box(ds_win, TCP_DIALOG_Y + 9, TCP_DIALOG_X + 8, TCP_DIALOG_HEIGHT - 13, TCP_DIALOG_WIDTH - 17, dialog_attr, border_attr); wattrset(ds_win, dialog_attr); @@ -236,6 +209,7 @@ tcpOpenDialog(Device *devp) SAFE_STRCPY(extras, cp); } } + /* Look up values already recorded with the system, or blank the string variables ready to accept some new data */ tmp = variable_get(VAR_HOSTNAME); if (tmp) @@ -258,75 +232,21 @@ tcpOpenDialog(Device *devp) else bzero(nameserver, sizeof(nameserver)); - /* Loop over the layout list, create the objects, and add them - onto the chain of objects that dialog uses for traversal*/ - n = 0; -#define lt layout[n] - while (lt.help != NULL) { - switch (lt.type) { - case STRINGOBJ: - lt.obj = NewStringObj(ds_win, lt.prompt, lt.var, - lt.y + TCP_DIALOG_Y, lt.x + TCP_DIALOG_X, - lt.len, lt.maxlen); - break; - - case BUTTONOBJ: - lt.obj = NewButtonObj(ds_win, lt.prompt, lt.var, - lt.y + TCP_DIALOG_Y, lt.x + TCP_DIALOG_X); - break; - - default: - msgFatal("Don't support this object yet!"); - } - AddObj(&obj, lt.type, (void *) lt.obj); - n++; - } - max = n - 1; - - /* Find the last object we can traverse to */ - last = obj; - while (last->next) - last = last->next; - - /* Find the first object in the list */ - first = obj; - for (first = obj; first->prev; first = first->prev); - /* Some more initialisation before we go into the main input loop */ - n = 0; - cancelbutton = okbutton = 0; + obj = initLayoutDialog(ds_win, layout, TCP_DIALOG_X, TCP_DIALOG_Y, &max); - /* Incoming user data - DUCK! */ - while (!quit) { - char help_line[80]; - int i, len = strlen(lt.help); - - /* Display the help line at the bottom of the screen */ - for (i = 0; i < 79; i++) - help_line[i] = (i < len) ? lt.help[i] : ' '; - help_line[i] = '\0'; - use_helpline(help_line); - display_helpline(ds_win, LINES - 1, COLS - 1); - - /* Ask for libdialog to do its stuff */ - ret = PollObj(&obj); - - if (n == LAYOUT_HOSTNAME) { - /* We are in the Hostname field - calculate the domainname */ - if ((tmp = index(hostname, '.')) != NULL) { - sstrncpy(domainname, tmp + 1, strlen(tmp)); - RefreshStringObj(layout[LAYOUT_DOMAINNAME].obj); - } - } - else if (n == LAYOUT_IPADDR) { +reenter: + cancelbutton = okbutton = 0; + while (layoutDialogLoop(ds_win, layout, &obj, &n, max, &cancelbutton, &cancel)) { + if (n == LAYOUT_IPADDR) { /* Insert a default value for the netmask, 0xffffff00 is the most appropriate one (entire class C, or subnetted class A/B network). */ - if(netmask[0] == '\0') { + if (netmask[0] == '\0') { strcpy(netmask, "255.255.255.0"); RefreshStringObj(layout[LAYOUT_NETMASK].obj); } - } + } else if (n == LAYOUT_DOMAINNAME) { if (!index(hostname, '.') && domainname[0]) { strcat(hostname, "."); @@ -334,68 +254,24 @@ tcpOpenDialog(Device *devp) RefreshStringObj(layout[LAYOUT_HOSTNAME].obj); } } - /* Handle special case stuff that libdialog misses. Sigh */ - switch (ret) { - /* Bail out */ - case SEL_ESC: - quit = TRUE, cancel=TRUE; - break; - - /* This doesn't work for list dialogs. Oh well. Perhaps - should special case the move from the OK button ``up'' - to make it go to the interface list, but then it gets - awkward for the user to go back and correct screw up's - in the per-interface section */ - - case KEY_DOWN: - case SEL_TAB: - case SEL_CR: - if (n < max) - ++n; - else - n = 0; - break; - - /* The user has pressed enter over a button object */ - case SEL_BUTTON: - if (cancelbutton) - cancel = TRUE, quit = TRUE; - else { - if (verifySettings()) - quit = TRUE; + else if (n == LAYOUT_HOSTNAME) { + if (((tmp = index(hostname, '.')) != NULL) && !domainname[0]) { + SAFE_STRCPY(domainname, tmp + 1); + RefreshStringObj(layout[LAYOUT_DOMAINNAME].obj); } - break; - - case KEY_UP: - case SEL_BACKTAB: - if (n) - --n; - else - n = max; - break; - - case KEY_F(1): - display_helpfile(); - - /* They tried some key combination we don't support - tell them! */ - default: - beep(); - } - - /* BODGE ALERT! */ - if (((tmp = index(hostname, '.')) != NULL) && (strlen(domainname)==0)) { - SAFE_STRCPY(domainname, tmp + 1); - RefreshStringObj(layout[1].obj); } } + + if (!verifySettings()) + goto reenter; /* Clear this crap off the screen */ dialog_clear_norefresh(); use_helpfile(NULL); /* We actually need to inform the rest of sysinstall about this - data now - if the user hasn't selected cancel, save the stuff - out to the environment via the variable_set layers */ + data now if the user hasn't selected cancel. Save the stuff + out to the environment via the variable_set() mechanism */ if (!cancel) { DevInfo *di; @@ -431,12 +307,13 @@ tcpOpenDialog(Device *devp) } if (ipaddr[0]) variable_set2(VAR_IPADDR, ipaddr); - restorescr(save); configResolv(); /* XXX this will do it on the MFS copy XXX */ - return DITEM_SUCCESS; + ret = DITEM_SUCCESS; } + else + ret = DITEM_FAILURE; restorescr(save); - return DITEM_FAILURE; + return ret; } static int |