📄 ch05_02.htm
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 5] 5.2 The Idea of a Terminal Database </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly & Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly & Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:32:56Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch05_01.htm"TITLE="5. Setting Up Your Terminal"><LINKREL="prev"HREF="ch05_01.htm"TITLE="5.1 There's a Lot to Know About Terminals "><LINKREL="next"HREF="ch05_03.htm"TITLE="5.3 Setting the Terminal Type When You Log In "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch05_01.htm"TITLE="5.1 There's a Lot to Know About Terminals "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 5.1 There's a Lot to Know About Terminals "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 5<BR>Setting Up Your Terminal</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch05_03.htm"TITLE="5.3 Setting the Terminal Type When You Log In "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 5.3 Setting the Terminal Type When You Log In "BORDER="0"></A></TD></TR></TABLE> <HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-0075">5.2 The Idea of a Terminal Database </A></H2><PCLASS="para">Terminals differ. Manufacturers produce a variety of terminals, each oneincluding a particular set of features for a certain price.There are new terminals and old, smart terminals and dumb ones, terminalswith big screens and terminals with small screens, printing terminals and video displays, and terminals with all sorts of special features.</P><PCLASS="para">Differences between terminals do not matter much to programs like<SPANCLASS="link"><EMCLASS="emphasis">cat</EM> (<ACLASS="linkend"HREF="ch25_02.htm"TITLE="Four Ways to Skin a cat ">25.2</A>)</SPAN>or<SPANCLASS="link"><EMCLASS="emphasis">who</EM> (<ACLASS="linkend"HREF="ch51_04.htm"TITLE="Who's On? ">51.4</A>)</SPAN>that use theterminal screen as a sort of typewriter with an endless scroll of paper.These programs produce sequential outputand do not make use of the terminal's special features; they do not need to know much to do their job.<ACLASS="indexterm"NAME="AUTOID-4789"></A>Only programs such as screen editors,which make use of screen-handling features, need to know about differences between terminals.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-4794"></A><ACLASS="indexterm"NAME="AUTOID-4796"></A>In the late 1970s, Bill Joycreated the<SPANCLASS="link"><EMCLASS="emphasis">vi</EM> (<ACLASS="linkend"HREF="ch30_02.htm"TITLE="What We Cover ">30.2</A>)</SPAN>text editor at U.C. Berkeley.Like all screen-oriented editors, <EMCLASS="emphasis">vi</EM> uses the terminalscreen non-sequentially. A program performing non-sequential output does not just print character after character,but must manipulatethe text that was sent before, scroll the page,move the cursor, delete lines, insert characters, and more.While it would be possible to keep redrawing the screen in itsentirety, many features are provided in hardware or firmware by theterminal itself, and save too much time and trouble to be ignored.</P><PCLASS="para">The first version of <EMCLASS="emphasis">vi</EM> was written specifically for Lear SieglerADM3a terminals. <EMCLASS="emphasis">vi</EM> was such an improvement over line-oriented editors that there was great demand to port <EMCLASS="emphasis">vi</EM> to other brands of terminals. The problem was that each terminal had different features and used different control codes to manipulate the features that they did have in common.</P><PCLASS="para">Rather than write separate<SPANCLASS="link">terminal drivers (<ACLASS="linkend"HREF="ch42_01.htm#UPT-ART-1142"TITLE="Making Sense Out of the Terminal Mess ">42.1</A>)</SPAN>for eachterminal type, Bill Joy did something very clever, which all UNIX usersnow take for granted.He wrote a version of <EMCLASS="emphasis">vi</EM> with generic commands to manipulatethe screen instead of hardcoding the control codes and dimensionsfor a particular terminal.</P><PCLASS="para">The generic terminal-handling mechanism Joy came up with had two parts:a database describing the capabilities of each of the terminals to be supported, and a subroutine library that allows programs toquery that database and to make use of the capability valuesit contains. Both the library and the database were giventhe name <EMCLASS="emphasis">termcap</EM>, which is short for <EMCLASS="emphasis">term</EM>inal<EMCLASS="emphasis">cap</EM>abilities.<ACLASS="indexterm"NAME="AUTOID-4813"></A></P><PCLASS="para">At this point, users take for granted the fact that you canuse just about any terminal with a UNIX system and usescreen-oriented programs like <EMCLASS="emphasis">vi</EM> without any problem.But it is really quite remarkable!</P><PCLASS="para">The <EMCLASS="emphasis">termcap</EM> database is contained in a single text file, which grew quite large over the years to include descriptions of hundreds ofdifferent terminals. To improve performance, AT&T later introduced a<ACLASS="indexterm"NAME="AUTOID-4819"></A>database called <EMCLASS="emphasis">terminfo</EM>, which stores terminal descriptions, in compiled form, in a separate file for each terminal.</P><PCLASS="para">If a program is designed to use <EMCLASS="emphasis">termcap</EM> or <EMCLASS="emphasis">terminfo</EM>, it queries anenvironment variable called<SPANCLASS="link"><EMCLASS="emphasis">TERM</EM> (<ACLASS="linkend"HREF="ch05_10.htm"TITLE="Finding What Terminal Names You Can Use ">5.10</A>)</SPAN>to determine the terminal type, thenlooks up the entry for that terminal in the terminal database, and reads the definition of any capabilities it plans to use into external variables.Programs that use <EMCLASS="emphasis">termcap</EM> or <EMCLASS="emphasis">terminfo</EM> range from screen editors like<EMCLASS="emphasis">vi</EM> and<SPANCLASS="link"><EMCLASS="emphasis">emacs</EM> (<ACLASS="linkend"HREF="ch32_01.htm#UPT-ART-5540"TITLE="Emacs: The Other Editor ">32.1</A>)</SPAN>,which use the complete terminal description,to a program like<SPANCLASS="link"><EMCLASS="emphasis">clear</EM> (<ACLASS="linkend"HREF="ch22_18.htm"TITLE="Clear Your Terminal for Security, to Stop Burn-in ">22.18</A>)</SPAN>,which needs to know only one capability(the escape sequence to clear the screen). Other programs include<SPANCLASS="link"><EMCLASS="emphasis">more</EM> (<ACLASS="linkend"HREF="ch25_03.htm"TITLE="Using more to Page Through Files ">25.3</A>)</SPAN>,<EMCLASS="emphasis">pg</EM>, <EMCLASS="emphasis">rogue</EM>,<SPANCLASS="link"><EMCLASS="emphasis">tset</EM> (<ACLASS="linkend"HREF="ch05_03.htm"TITLE="Setting the Terminal Type When You Log In ">5.3</A>)</SPAN>,<EMCLASS="emphasis">ul</EM>, and<SPANCLASS="link"><EMCLASS="emphasis">nroff</EM> (<ACLASS="linkend"HREF="ch43_13.htm"TITLE="The Text Formatters nroff, troff, ditroff, ... ">43.13</A>)</SPAN>.</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">JS</SPAN> <SPANCLASS="bibliomisc">from O'Reilly & Associates' <CITECLASS="citetitle">termcap & terminfo</CITE>, Chapter 1</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch05_01.htm"TITLE="5.1 There's a Lot to Know About Terminals "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 5.1 There's a Lot to Know About Terminals "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch05_03.htm"TITLE="5.3 Setting the Terminal Type When You Log In "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 5.3 Setting the Terminal Type When You Log In "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">5.1 There's a Lot to Know About Terminals </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">5.3 Setting the Terminal Type When You Log In </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed & awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -