📄 ch48_04.htm
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 48] 48.4 Automatic Reminders and More: calendar </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-10-23T15:55:26Z"><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="ch48_01.htm"TITLE="48. Office Automation"><LINKREL="prev"HREF="ch48_03.htm"TITLE="48.3 A Scratchpad on Your Screen "><LINKREL="next"HREF="ch48_05.htm"TITLE="48.5 leave: A Maddening Aid to Quitting on Time "></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="ch48_03.htm"TITLE="48.3 A Scratchpad on Your Screen "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 48.3 A Scratchpad on Your Screen "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 48<BR>Office Automation</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch48_05.htm"TITLE="48.5 leave: A Maddening Aid to Quitting on Time "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 48.5 leave: A Maddening Aid to Quitting on Time "BORDER="0"></A></TD></TR></TABLE> <HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-3180">48.4 Automatic Reminders and More: calendar </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="UPT-ART-3180-IX-CALENDAR-PROGRAM"></A><ACLASS="indexterm"NAME="AUTOID-57714"></A>If you type the command <EMCLASS="emphasis">calendar</EM>, you'll see lineswith "to-do" items for today and tomorrow from a file named<EMCLASS="emphasis">calendar</EM> in your current directory.If you put that file in your home directory, your system administrator can run the command <EMCLASS="emphasis">calendar</EM>-to<SPANCLASS="link">mail (<ACLASS="linkend"HREF="ch01_33.htm"TITLE="UNIX Networking and Communications ">1.33</A>)</SPAN>everyones' "to-do" items to them.You can also automate your personal calendar setup by running <EMCLASS="emphasis">calendar</EM>yourself - the calendar can be mailed to you, sent to the printer, and soon, first thing each morning.See below for an example <EMCLASS="emphasis">calendar</EM> file and more information.</P><PCLASS="para"><EMCLASS="emphasis">calendar</EM> builds a complicated<SPANCLASS="link"><EMCLASS="emphasis">egrep</EM> (<ACLASS="linkend"HREF="ch27_05.htm"TITLE="Extended Searching for Text with egrep ">27.5</A>)</SPAN>expression to search your <EMCLASS="emphasis">calendar</EM> file.You can see that expression yourself if you want to.</P><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="UPT-ART-3180-SECT-1.1">48.4.1 How calendar Works </A></H3><PCLASS="para">Let's start by showing a few lines of a sample <EMCLASS="emphasis">calendar</EM> file.(Yours can be much longer.)Then I'll run <EMCLASS="emphasis">calendar</EM> to show what lines it picks:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>cat calendar</B></CODE>-- WORK --12/28 Project report due tomorrow!-- PERSONAL --* 8 rub Lisa's feetTake Lisa out to dinner on December 8dec 9 buy Lisa lunchOn 12/10, Lisa will be hungry for ice cream-- BIRTHDAYS --1/1 Mom's birthday - make dinner reservations by 12/20!% <CODECLASS="userinput"><B>date</B></CODE>Tue Dec 8 08:43:40 PST 1992% <CODECLASS="userinput"><B>calendar</B></CODE>* 8 rub Lisa's feetTake Lisa out to dinner on December 8dec 9 buy Lisa lunch</PRE></BLOCKQUOTE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-57739"></A><ACLASS="indexterm"NAME="AUTOID-57742"></A>Today is December 8.The <EMCLASS="emphasis">calendar</EM> utility found lines in my <EMCLASS="emphasis">calendar</EM> file fortoday and tomorrow.<EMCLASS="emphasis">calendar</EM> understands lots of date formats.The date can be anywhere on a line.If you leave a line in your file for more than one year (like Mom'sbirthday) <EMCLASS="emphasis">calendar</EM> will show it every year.If a line has more than one date, you'll see the line on both of thosedates (I'll be reminded before Mom's birthday and also in time to make adinner reservation).An asterisk (<CODECLASS="literal">*</CODE>) in place of a month means "all months."</P><PCLASS="para">Many versions of <EMCLASS="emphasis">calendar</EM> utility run your <EMCLASS="emphasis">calendar</EM> filethrough the C language preprocessor, <EMCLASS="emphasis">cpp</EM>.Among other things, this lets you includeseveral calendar files in your own calendar file.Lines that start with a hash mark (<CODECLASS="literal">#</CODE>) in column 1 are read by thepreprocessor.For instance, this line in your <EMCLASS="emphasis">calendar</EM> file would include allthe contents of the file <EMCLASS="emphasis">/usr/local/lib/office.calendar</EM>just as if you'd typed them into your own file:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">#include "/usr/local/lib/office.calendar"</PRE></BLOCKQUOTE></P><PCLASS="para"> Someone (the office secretary) can maintain the <EMCLASS="emphasis">office.calendar</EM> file.People in the office who want reminders from it can put the<CODECLASS="literal">#include</CODE> line in their own <EMCLASS="emphasis">calendar</EM> files.</P><PCLASS="para">By the way, if you start a line with <CODECLASS="literal">#</CODE> and it's not for thepreprocessor, you'll get a mysterious error like<CODECLASS="literal">calendar:</CODE> <CODECLASS="literal">1:</CODE> <CODECLASS="literal">undefined</CODE> <CODECLASS="literal">control</CODE>.That means line 1 of the file had something the preprocessor couldn'tunderstand.</P></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="UPT-ART-3180-SECT-1.2">48.4.2 The egrep Expression calendar Uses </A></H3><PCLASS="para">How can <EMCLASS="emphasis">calendar</EM> find dates in all the formats it accepts - andonly for today and tomorrow?It runs a system program, usually named <EMCLASS="emphasis">/usr/lib/calendar</EM>,that generates an expression for<SPANCLASS="link"><EMCLASS="emphasis">egrep -f</EM> (<ACLASS="linkend"HREF="ch27_07.htm"TITLE="grepping for a List of Patterns ">27.7</A>)</SPAN>.The expression searches for the dates of today and tomorrow; iftoday is a Friday, the expression includes dates on Saturday, Sunday, andMonday.Here's the expression I got by running <EMCLASS="emphasis">/usr/lib/calendar</EM>on Tuesday, December 8.TAB characters are shown as <CODECLASS="literal">T</CODE>; spaces are shown as <IMGSRC="../chars/squ.gif"ALT=" ">.</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>/usr/lib/calendar</B></CODE>(^|[<IMGSRC="../chars/squ.gif"ALT=" ">T(,;])((([Dd]ec[^<IMGSRC="../chars/squ.gif"ALT=" ">T]*|\*)[<IMGSRC="../chars/squ.gif"ALT=" ">T]*|(012|12|\*)/)0*8)([^0123456789]|$)(^|[<IMGSRC="../chars/squ.gif"ALT=" ">T(,;])((([Dd]ec[^<IMGSRC="../chars/squ.gif"ALT=" ">T]*|\*)[<IMGSRC="../chars/squ.gif"ALT=" ">T]*|(012|12|\*)/)0*9)([^0123456789]|$)</PRE></BLOCKQUOTE></P><PCLASS="para">I'll turn the first line of that into English.I'm not writing this just for <EMCLASS="emphasis">egrep</EM> fanatics <CODECLASS="literal">:-)</CODE>; this isalso useful for understanding what kinds of dates <EMCLASS="emphasis">calendar</EM> willrecognize.I'm going to skip some not-so-subtle things like the nesting of the parenthesesand just give an overview.If you haven't seen extended regular expressions before, see article<ACLASS="xref"HREF="ch26_04.htm"TITLE="Using Metacharacters in Regular Expressions ">26.4</A>.The expression finds lines in your <EMCLASS="emphasis">calendar</EM> file that meet theseconditions, in order from left to right across the line:</P><DLCLASS="variablelist"><DTCLASS="term"><CODECLASS="literal">(^|[<IMGSRC="../chars/squ.gif"ALT=" ">T(,;])</CODE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -