Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.terminals Subject: Re: Lines and columns under 4.3 Message-ID: <5502@brl-smoke.ARPA> Date: Fri, 9-Jan-87 14:03:47 EST Article-I.D.: brl-smok.5502 Posted: Fri Jan 9 14:03:47 1987 Date-Received: Mon, 12-Jan-87 21:52:15 EST References: <234@su-russell.ARPA> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB)) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 54 In article <234@su-russell.ARPA> goldberg@su-russell.UUCP (Jeffrey Goldberg) writes: >"Lines and columns are now stored in the kernel as well as in the >termcap entry. Most programs now use the kernel information >primarily; the information in this file is used only if the kernel >does not have any information." The 4.3BSD kernel (following the lead of Sun and/or AT&T) maintains information about the dimensions of each "terminal" (which may actually be just a window on a multi-window display) in a /* * Window size structure */ struct winsize { unsigned short ws_row, ws_col; /* character size of window */ unsigned short ws_xpixel, ws_ypixel; /* pixel size of window */ }; That contains all 0 data if the "terminal" size has never been set. The only way to set the size is via a TIOCSWINSZ ioctl, and the only way to query the size is via a TIOCGWINSZ ioctl, both of which take a (struct winsize *) as their third parameter. (Note: DMD-supporting UNIX System Vs, such as SVR3, have analogous information contained in a (struct jwinsize) with a JWINSIZE ioctl to retrieve it; it's updated automatically inside the kernel when a window size changes.) The general procedure for determining a terminal's screen size is: 1) Try a TIOCGWINSZ. If it fails, or if it returns 0 data, then proceed to step 3; otherwise use the returned information as the terminal's screen size. 2) Some sites have added pagination to their terminal handler; in this case one might be able to obtain the number of rows via an ioctl analogous to the procedure of step 1; if supported and successful (and non-zero!), use this value and proceed to step 3 just to get columns information. 3) Try to fetch COLUMNS and/or LINES from the environment (if not yet known from previous steps). If either is available, use it for the terminal size in that direction; if either is not set in the environment, find it out by proceeding to step 4. 4) Get TERM from the environment and use it in a tgetent (or equivalent call to initialize the display-handling package). The termcap capability "li" (terminfo "lines") is the default number of lines and termcap "co" (terminfo "cols") is the default number of columns to assume for that terminal type. 5) If one still hasn't determined the terminal screen size, assume that it is an "infinite quadrant". This probably isn't correct, but then it's what the user deserves for not setting up any information about his terminal.