⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch43_20.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 43] 43.20 Displaying a troff Macro Definition </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly &amp; Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1998-10-23T15:52:05Z"><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="ch43_01.htm"TITLE="43. Printing"><LINKREL="prev"HREF="ch43_19.htm"TITLE="43.19 Removing Leading Tabs and Other Trivia "><LINKREL="next"HREF="ch43_21.htm"TITLE="43.21 Preprocessing troff Input with sed "></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="ch43_19.htm"TITLE="43.19 Removing Leading Tabs and Other Trivia "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 43.19 Removing Leading Tabs and Other Trivia "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 43<BR>Printing</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch43_21.htm"TITLE="43.21 Preprocessing troff Input with sed "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 43.21 Preprocessing troff Input with sed "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-0084">43.20 Displaying a troff Macro Definition </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-48709"></A><ACLASS="indexterm"NAME="AUTOID-48713"></A>If you're writing or debugging <SPANCLASS="link"><EMCLASS="emphasis">troff</EM> macros (<ACLASS="linkend"HREF="ch43_13.htm"TITLE="The Text Formatters nroff, troff, ditroff, ... ">43.13</A>)</SPAN>,you often need to review thecontents of a macro.Rather than searching through the macro definition files with an editor, it is relatively easy to construct a small script that uses <SPANCLASS="link"><EMCLASS="emphasis">sed</EM> (<ACLASS="linkend"HREF="ch34_24.htm"TITLE="Quick Reference: sed ">34.24</A>)</SPAN>and the shell to extract and display a single macro.</P><PCLASS="para">The script is easy to construct because the macro definitions have aregular structure that lends itself to easy identification with the<SPANCLASS="link">regular expressions (<ACLASS="linkend"HREF="ch26_04.htm"TITLE="Using Metacharacters in Regular Expressions ">26.4</A>)</SPAN>used by <EMCLASS="emphasis">sed</EM>.A <EMCLASS="emphasis">troff</EM> macro definition always begins with the string <CODECLASS="literal">.de</CODE>,followedby an optional space and the one- or two-letter name of the macro. The definition ends with a line beginning with two dots (<CODECLASS="literal">..</CODE>).</P><PCLASS="para"><EMCLASS="emphasis">troff</EM> macrosare defined in a macro package, often a singlefile that's located in a directory such as <EMCLASS="emphasis">/usr/lib/tmac</EM>. The most common macro packages are <EMCLASS="emphasis">mm</EM>, <EMCLASS="emphasis">ms</EM> and<EMCLASS="emphasis">me</EM>-though it is unlikely that a given system will have allthree. <EMCLASS="emphasis">mm</EM> is generally found on System V-derived systems,and <EMCLASS="emphasis">ms</EM> and <EMCLASS="emphasis">me</EM> on BSD-derived systems. The <EMCLASS="emphasis">man</EM> macros are found on just about all systemsbecause they are used by the <SPANCLASS="link"><EMCLASS="emphasis">man</EM> command (<ACLASS="linkend"HREF="ch50_01.htm#UPT-ART-4910"TITLE="UNIX Online Documentation ">50.1</A>)</SPAN>.</P><PCLASS="para">Here's an example:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>getmac -ms LP</B></CODE>.\&quot;.\&quot; The following definition of LP was found in /usr/lib/tmac/tmac.s:.\&quot;.de LP.RT.if \\n(1T .sp \\n(PDu.ti \\n(.iu..</PRE></BLOCKQUOTE></P><PCLASS="para">The <EMCLASS="emphasis">getmac</EM> script is below.For those unfamiliar with <EMCLASS="emphasis">sed</EM>, there are comments in the scripton the CD-ROM (and in the online archive file):</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">&#13;#!/bin/sh# Usage: getmac -package macrocase $1 in-mm) file=&quot;/usr/lib/macros/mmt&quot;;;-ms) file=&quot;/usr/lib/tmac/tmac.s&quot;;;-me) file=&quot;/usr/lib/tmac/tmac.e&quot;;;-man) file=&quot;/usr/lib/tmac/tmac.an&quot;;;*) echo &quot;Usage: getmac -package macro&quot; 1&gt;&amp;2; exit 1;;esacmac=$2sed -n '/^\.de *'$mac'/,/^\.\.$/ {   /^\.de/i\.\\&quot;\.\\&quot; The following definition of '$mac' was found in '$file':\.\\&quot;   p   /^\.\.$/q}' $file</PRE></BLOCKQUOTE></P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">TOR</SPAN>, <SPANCLASS="authorinitials">JP</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="ch43_19.htm"TITLE="43.19 Removing Leading Tabs and Other Trivia "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 43.19 Removing Leading Tabs and Other Trivia "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="ch43_21.htm"TITLE="43.21 Preprocessing troff Input with sed "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 43.21 Preprocessing troff Input with sed "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">43.19 Removing Leading Tabs and Other Trivia </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">43.21 Preprocessing troff Input with sed </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 &amp; 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 + -