Changeset View
Changeset View
Standalone View
Standalone View
lib/libdpv/dialog_util.c
Show First 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | |||||
* active TTY size. | * active TTY size. | ||||
* | * | ||||
* This function is called automatically by dialog_maxrows/cols() to reflect | * This function is called automatically by dialog_maxrows/cols() to reflect | ||||
* changes in terminal size in-between calls. | * changes in terminal size in-between calls. | ||||
*/ | */ | ||||
static void | static void | ||||
tty_maxsize_update(void) | tty_maxsize_update(void) | ||||
{ | { | ||||
int fd = STDIN_FILENO; | int doclose = 0, fd = STDIN_FILENO; | ||||
struct termios t; | struct termios t; | ||||
if (maxsize == NULL) { | if (maxsize == NULL) { | ||||
if ((maxsize = malloc(sizeof(struct winsize))) == NULL) | if ((maxsize = malloc(sizeof(struct winsize))) == NULL) | ||||
errx(EXIT_FAILURE, "Out of memory?!"); | errx(EXIT_FAILURE, "Out of memory?!"); | ||||
memset((void *)maxsize, '\0', sizeof(struct winsize)); | memset((void *)maxsize, '\0', sizeof(struct winsize)); | ||||
} | } | ||||
if (!isatty(fd)) | if (!isatty(fd)) { | ||||
fd = open("/dev/tty", O_RDONLY); | fd = open("/dev/tty", O_RDONLY); | ||||
if (fd < 0) | |||||
err(EXIT_FAILURE, "Unable to open /dev/tty"); | |||||
doclose = 1; | |||||
} | |||||
if ((tcgetattr(fd, &t) < 0) || (ioctl(fd, TIOCGWINSZ, maxsize) < 0)) { | if ((tcgetattr(fd, &t) < 0) || (ioctl(fd, TIOCGWINSZ, maxsize) < 0)) { | ||||
maxsize->ws_row = TTY_DEFAULT_ROWS; | maxsize->ws_row = TTY_DEFAULT_ROWS; | ||||
maxsize->ws_col = TTY_DEFAULT_COLS; | maxsize->ws_col = TTY_DEFAULT_COLS; | ||||
} | } | ||||
if (doclose) | |||||
(void)close(fd); | |||||
} | } | ||||
/* | /* | ||||
* Update row/column fields of `maxsize' global (used by dialog_maxrows() and | * Update row/column fields of `maxsize' global (used by dialog_maxrows() and | ||||
* dialog_maxcols()). If the `maxsize' pointer is NULL, it will be initialized. | * dialog_maxcols()). If the `maxsize' pointer is NULL, it will be initialized. | ||||
* The `ws_row' and `ws_col' fields of `maxsize' are updated to hold current | * The `ws_row' and `ws_col' fields of `maxsize' are updated to hold current | ||||
* maximum height and width (respectively) for an Xdialog(1) widget based on | * maximum height and width (respectively) for an Xdialog(1) widget based on | ||||
* the active video resolution of the X11 environment. | * the active video resolution of the X11 environment. | ||||
Show All 26 Lines | x11_maxsize_update(void) | ||||
if ((f = popen(cmdbuf, "r")) == NULL) { | if ((f = popen(cmdbuf, "r")) == NULL) { | ||||
if (debug) | if (debug) | ||||
warnx("WARNING! Command `%s' failed", cmdbuf); | warnx("WARNING! Command `%s' failed", cmdbuf); | ||||
return; | return; | ||||
} | } | ||||
/* Read in the line returned from Xdialog(1) */ | /* Read in the line returned from Xdialog(1) */ | ||||
if ((fgets(rbuf, LINE_MAX, f) == NULL) || (pclose(f) < 0)) | if (fgets(rbuf, LINE_MAX, f) == NULL) { | ||||
(void)pclose(f); | |||||
return; | |||||
} | |||||
if (pclose(f) < 0) | |||||
return; | return; | ||||
/* Check for X11-related errors */ | /* Check for X11-related errors */ | ||||
if (strncmp(rbuf, "Xdialog: Error", 14) == 0) | if (strncmp(rbuf, "Xdialog: Error", 14) == 0) | ||||
return; | return; | ||||
/* Parse expected output: MaxSize: YY, XXX */ | /* Parse expected output: MaxSize: YY, XXX */ | ||||
if ((rows = strchr(rbuf, ' ')) == NULL) | if ((rows = strchr(rbuf, ' ')) == NULL) | ||||
▲ Show 20 Lines • Show All 488 Lines • Show Last 20 Lines |