int archdep_num_text_columns(void) { #if defined(__IBMC__) || defined(WATCOM_COMPILE) return 80; #else int dst[2]; _scrsize(dst); return dst[0]; #endif }
int archdep_num_text_lines(void) { #if defined(__IBMC__) || defined(WATCOM_COMPILE) return 25; #else int dst[2]; _scrsize(dst); return dst[1]; #endif }
void progressbarinit(struct ProgressData *bar, struct Configurable *config) { #ifdef __EMX__ /* 20000318 mgs */ int scr_size[2]; #endif char *colp; memset(bar, 0, sizeof(struct ProgressData)); /* pass this through to progress function so * it can display progress towards total file * not just the part that's left. (21-may-03, dbyron) */ if(config->use_resume) bar->initial_size = config->resume_from; /* TODO: get terminal width through ansi escapes or something similar. try to update width when xterm is resized... - 19990617 larsa */ #ifndef __EMX__ /* 20000318 mgs * OS/2 users most likely won't have this env var set, and besides that * we're using our own way to determine screen width */ colp = curlx_getenv("COLUMNS"); if(colp) { char *endptr; long num = strtol(colp, &endptr, 10); if((endptr != colp) && (endptr == colp + strlen(colp)) && (num > 0)) bar->width = (int)num; else bar->width = 79; curl_free(colp); } else bar->width = 79; #else /* 20000318 mgs * We use this emx library call to get the screen width, and subtract * one from what we got in order to avoid a problem with the cursor * advancing to the next line if we print a string that is as long as * the screen is wide. */ _scrsize(scr_size); bar->width = scr_size[0] - 1; #endif bar->out = config->errors; }
void setlinescols(void) { char *p; int i; #ifdef __EMX__ { int s[2]; _scrsize(s); COLS = s[0]; LINES = s[1]; if (getenv("WINDOWID")) { FILE *fd = popen("scrsize", "rt"); if (fd) { fscanf(fd, "%i %i", &COLS, &LINES); pclose(fd); } } } #elif defined(HAVE_TERMIOS_H) && defined(TIOCGWINSZ) struct winsize wins; i = ioctl(tty, TIOCGWINSZ, &wins); if (i >= 0 && wins.ws_row != 0 && wins.ws_col != 0) { LINES = wins.ws_row; COLS = wins.ws_col; } #endif /* defined(HAVE-TERMIOS_H) && defined(TIOCGWINSZ) */ if (LINES <= 0 && (p = getenv("LINES")) != NULL && (i = atoi(p)) >= 0) LINES = i; if (COLS <= 0 && (p = getenv("COLUMNS")) != NULL && (i = atoi(p)) >= 0) COLS = i; if (LINES <= 0) LINES = tgetnum("li"); /* number of line */ if (COLS <= 0) COLS = tgetnum("co"); /* number of column */ if (COLS > MAX_COLUMN) COLS = MAX_COLUMN; if (LINES > MAX_LINE) LINES = MAX_LINE; #if defined(__CYGWIN__) LASTLINE = LINES - (isWinConsole == TERM_CYGWIN_RESERVE_IME ? 2 : 1); #endif /* defined(__CYGWIN__) */ }
int ROKEN_LIB_FUNCTION get_window_size(int fd, struct winsize *wp) { int ret = -1; memset(wp, 0, sizeof(*wp)); #if defined(TIOCGWINSZ) ret = ioctl(fd, TIOCGWINSZ, wp); #elif defined(TIOCGSIZE) { struct ttysize ts; ret = ioctl(fd, TIOCGSIZE, &ts); if(ret == 0) { wp->ws_row = ts.ts_lines; wp->ws_col = ts.ts_cols; } } #elif defined(HAVE__SCRSIZE) { int dst[2]; _scrsize(dst); wp->ws_row = dst[1]; wp->ws_col = dst[0]; ret = 0; } #endif if (ret != 0) { char *s; if((s = getenv("COLUMNS"))) wp->ws_col = atoi(s); if((s = getenv("LINES"))) wp->ws_row = atoi(s); if(wp->ws_col > 0 && wp->ws_row > 0) ret = 0; } return ret; }
int main() { char *cp; Display *dpy; Window window; XWindowAttributes win_attributes; XSizeHints hints; long longjunk; int dst[2]; _scrsize(dst); cp = getenv("WINDOWID"); if (cp) { dpy = XOpenDisplay(NULL); if (dpy) { if (XGetWindowAttributes(dpy, window = atol(cp), &win_attributes)) if (XGetWMNormalHints(dpy, window, &hints, &longjunk)) if (hints.flags & PResizeInc && hints.width_inc && hints.height_inc) { if (hints.flags & (PBaseSize | PMinSize)) { if (hints.flags & PBaseSize) { win_attributes.width -= hints.base_width; win_attributes.height -= hints.base_height; } else { win_attributes.width -= hints.min_width; win_attributes.height -= hints.min_height; } } dst[0] = win_attributes.width / hints.width_inc; dst[1] = win_attributes.height / hints.height_inc; } XCloseDisplay(dpy); } } printf("%i %i\n", dst[0], dst[1]); return 0; }
void clrscr(void) { memset((void*) REAL_SCREEN_BASE_ADDRESS, 0xFF, _scrsize()); }
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL get_window_size(int fd, int *lines, int *columns) { int ret; char *s; #if defined(TIOCGWINSZ) { struct winsize ws; ret = ioctl(fd, TIOCGWINSZ, &ws); if (ret != -1) { if (lines) *lines = ws.ws_row; if (columns) *columns = ws.ws_col; return 0; } } #elif defined(TIOCGSIZE) { struct ttysize ts; ret = ioctl(fd, TIOCGSIZE, &ts); if (ret != -1) { if (lines) *lines = ts.ws_lines; if (columns) *columns = ts.ts_cols; return 0; } } #elif defined(HAVE__SCRSIZE) { int dst[2]; _scrsize(dst); if (lines) *lines = dst[1]; if (columns) *columns = dst[0]; return 0; } #elif defined(_WIN32) { intptr_t fh = 0; CONSOLE_SCREEN_BUFFER_INFO sb_info; fh = _get_osfhandle(fd); if (fh != (intptr_t) INVALID_HANDLE_VALUE && GetConsoleScreenBufferInfo((HANDLE) fh, &sb_info)) { wp->ws_row = 1 + sb_info.srWindow.Bottom - sb_info.srWindow.Top; wp->ws_col = 1 + sb_info.srWindow.Right - sb_info.srWindow.Left; ret = 0; } } #endif if (columns) { if ((s = getenv("COLUMNS"))) *columns = atoi(s); else return -1; } if (lines) { if ((s = getenv("LINES"))) *lines = atoi(s); else return -1; } return 0; }
static void _nc_get_screensize(int *linep, int *colp) /* Obtain lines/columns values from the environment and/or terminfo entry */ { /* figure out the size of the screen */ T(("screen size: terminfo lines = %d columns = %d", lines, columns)); if (!_use_env) { *linep = (int) lines; *colp = (int) columns; } else { /* usually want to query LINES and COLUMNS from environment */ int value; *linep = *colp = 0; /* first, look for environment variables */ if ((value = _nc_getenv_num("LINES")) > 0) { *linep = value; } if ((value = _nc_getenv_num("COLUMNS")) > 0) { *colp = value; } T(("screen size: environment LINES = %d COLUMNS = %d", *linep, *colp)); #ifdef __EMX__ if (*linep <= 0 || *colp <= 0) { int screendata[2]; _scrsize(screendata); *colp = screendata[0]; *linep = screendata[1]; T(("EMX screen size: environment LINES = %d COLUMNS = %d", *linep, *colp)); } #endif #if HAVE_SIZECHANGE /* if that didn't work, maybe we can try asking the OS */ if (*linep <= 0 || *colp <= 0) { if (isatty(cur_term->Filedes)) { STRUCT_WINSIZE size; errno = 0; do { if (ioctl(cur_term->Filedes, IOCTL_WINSIZE, &size) < 0 && errno != EINTR) goto failure; } while (errno == EINTR); /* * Solaris lets users override either dimension with an * environment variable. */ if (*linep <= 0) *linep = WINSIZE_ROWS(size); if (*colp <= 0) *colp = WINSIZE_COLS(size); } /* FALLTHRU */ failure:; } #endif /* HAVE_SIZECHANGE */ /* if we can't get dynamic info about the size, use static */ if (*linep <= 0) { *linep = (int) lines; } if (*colp <= 0) { *colp = (int) columns; } /* the ultimate fallback, assume fixed 24x80 size */ if (*linep <= 0) { *linep = 24; } if (*colp <= 0) { *colp = 80; } /* * Put the derived values back in the screen-size caps, so * tigetnum() and tgetnum() will do the right thing. */ lines = (short) (*linep); columns = (short) (*colp); } T(("screen size is %dx%d", *linep, *colp)); if (VALID_NUMERIC(init_tabs)) TABSIZE = (int) init_tabs; else TABSIZE = 8; T(("TABSIZE = %d", TABSIZE)); }