📄 ch48_09.htm
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 48] 48.9 PostScript Calendars with pcal </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:33Z"><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_08.htm"TITLE="48.8 Calendar for 132-Column Terminals or Printers "><LINKREL="next"HREF="ch48_10.htm"TITLE="48.10 Working with Names and Addresses "></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_08.htm"TITLE="48.8 Calendar for 132-Column Terminals or Printers "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 48.8 Calendar for 132-Column Terminals or Printers "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_10.htm"TITLE="48.10 Working with Names and Addresses "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 48.10 Working with Names and Addresses "BORDER="0"></A></TD></TR></TABLE> <HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-9011">48.9 PostScript Calendars with pcal </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-58073"></A>Sometimes you want a hardcopy calendar.You can generateone using <SPANCLASS="link"><EMCLASS="emphasis">cal</EM> (<ACLASS="linkend"HREF="ch48_06.htm"TITLE="Get Calendar for Any Month or Year: cal ">48.6</A>)</SPAN>and an ASCII-to-PostScript filter like<SPANCLASS="link"><EMCLASS="emphasis">pstext</EM> (<ACLASS="linkend"HREF="ch43_22.htm"TITLE="Converting Text Files to PostScript ">43.22</A>)</SPAN>,but the resulting calendar is nothingto write home about.</P><TABLECLASS="para.programreference"BORDER="1"><TR><THVALIGN="TOP"><ACLASS="programreference"HREF="examples/index.htm"TITLE="pcal">pcal</A><BR></TH><TDVALIGN="TOP"><ACLASS="indexterm"NAME="UPT-ART-9011-IX-PCAL-PROGRAM"></A>A nifty alternative for printing calendars is <EMCLASS="emphasis">pcal</EM>.<EMCLASS="emphasis">pcal</EM>isn't just a pretty face: yes, it prints nice calendars, but you can also configure it to do quite a lot more.I just discovered <EMCLASS="emphasis">pcal</EM>, and it already has potential forbecoming one of my favorite utilities. </TD></TR></TABLE><PCLASS="para">In its default form, <EMCLASS="emphasis">pcal</EM> just creates a PostScriptcalendar for the current month.The PostScript commands are writtento standard output, so you need to pipe it to <EMCLASS="emphasis">lpr</EM> for BSD-based systems, or <EMCLASS="emphasis">lp</EM>for System V-based systems.(Of course, your printer has to be able to print PostScript.)For example:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>pcal | lpr</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">You'll get a full-page calendar of the current month.The dates for Saturdays and Sundays are printed in gray.To get a differentmonth, you can specify it the same way you would using <EMCLASS="emphasis">cal</EM>.For a calendar for November 1992, you could do:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>pcal 11 1992 | lpr</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para"> For a calendar for the whole year, use the <EMCLASS="emphasis">-w</EM> option to<EMCLASS="emphasis">pcal</EM>.</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>pcal -w | lpr</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">Once you get a chance to see the <EMCLASS="emphasis">pcal</EM> output, you'll alreadysee how big an improvement it is over just printing the output of the<EMCLASS="emphasis">cal</EM> program.But <EMCLASS="emphasis">pcal</EM> also gives you the opportunity toconfigure your calendars.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-58110"></A><EMCLASS="emphasis">pcal</EM> looks for a file called <EMCLASS="emphasis">.calendar</EM> in either your home directory or your current directory.(This is a<SPANCLASS="link">hidden file (<ACLASS="linkend"HREF="ch16_11.htm"TITLE="Showing Hidden Files with ls -A and -a ">16.11</A>)</SPAN>because the name starts with a dot.)You can use this file to mark days in the year.For example, you can use it to define particular days as holidays:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">1/1 New Year's DayFeb 14 Valentine's Day</PRE></BLOCKQUOTE></P><PCLASS="para">But <EMCLASS="emphasis">pcal</EM> also understands a limited set of relational words as well.For example:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">Second Sunday in May Mother's Day4th thu of nov Thanksgiving</PRE></BLOCKQUOTE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-58122"></A>For each of these examples, the given day will have the specifiedtext written in.If you use an asterisk (<CODECLASS="literal">*</CODE>) after the date, the day ismarked as a holiday.</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">1/1* New Year's DayFeb 14 Valentine's DaySecond Sunday in May Mother's Day4th thu of nov* Thanksgiving</PRE></BLOCKQUOTE></P><PCLASS="para">This means that the day appears in gray on the calendar, like Saturdayand Sunday.But more important, it means that <EMCLASS="emphasis">pcal</EM> will understand that the marked day isn't a working day.</P><PCLASS="para">In addition to holidays,you can use <EMCLASS="emphasis">pcal</EM> to mark things like birthdays andanniversaries.</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">June 4 My Birthday!!!September 3 Peter's birthdayApril 1 Mom and Dad's anniversary</PRE></BLOCKQUOTE></P><PCLASS="para">Now here's where <EMCLASS="emphasis">pcal</EM> starts to get useful.You can use <EMCLASS="emphasis">pcal</EM>to mark meetings you have scheduled:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">april 14 Meet with tax attorney at 4:45last day of october Dr. Jekyll's office, 5:30</PRE></BLOCKQUOTE></P><PCLASS="para">Or for regular appointments:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">Each Friday of July Leave early for Cape</PRE></BLOCKQUOTE></P><PCLASS="para">As you can probably tell by now, the syntax accepted by <EMCLASS="emphasis">pcal</EM> is very flexible.It's actually much too complicated to be ableto explain in full here, but <EMCLASS="emphasis">pcal</EM> comes with a completemanual page, and <EMCLASS="emphasis">pcal -h</EM> will give you a list ofsyntax and command-line options.And if you just wing it, you're likely to comeup with syntax that works. </P><PCLASS="para">I don't want to leave it at that, though.Let's get on with a few more examples of some of the nicer features.</P><PCLASS="para">In place of the name of a month, you can use the <CODECLASS="literal">all</CODE> keyword to mean all months, i.e., the entire year.For example:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">First day of all Send monthly report to bossEach Monday in all Status meeting at 11:30</PRE></BLOCKQUOTE></P><PCLASS="para">Now, we used <CODECLASS="literal">First</CODE> <CODECLASS="literal">day</CODE> <CODECLASS="literal">of</CODE> <CODECLASS="literal">all</CODE>, above,to specify whenwe should send our monthly report.What about when the first ofthe month falls on a weekend or holiday?Well, <EMCLASS="emphasis">pcal</EM> alsounderstands phrases like <CODECLASS="literal">workday</CODE> and <CODECLASS="literal">holiday</CODE>.To make sure that your reminder to submit your report appears on the first workday of the month, you can write:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">First workday of all Send monthly report to boss</PRE></BLOCKQUOTE></P><PCLASS="para">By default, <EMCLASS="emphasis">pcal</EM> considers only Saturdays and Sundaysto be non-workdays.You add days to this list when you define holidays with asterisks (*) as described previously.[1]</P><BLOCKQUOTECLASS="footnote"><PCLASS="para">[1] Note that <EMCLASS="emphasis">pcal</EM> only knows about holidays that have alreadybeen declared in your specification file.So in general, youwant to define your holidays early in your <EMCLASS="emphasis">.calendar</EM> fileso that later references to workdays will be up-to-date.</P></BLOCKQUOTE><PCLASS="para">Another feature of <EMCLASS="emphasis">pcal</EM> is that you can use the phases ofthe moon in your date specifications. </P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">2nd full_moon in all Blue moon!</PRE></BLOCKQUOTE></P><PCLASS="para"><EMCLASS="emphasis">pcal</EM> supplies format specifiers for writing moredetailed descriptions.For example, suppose you want to be reminded atthe beginning of each month to make your monthly schedule.You can make up an entry that reads:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">First workday of all Write schedule for %B</PRE></BLOCKQUOTE></P><PCLASS="para">The special format specifier <CODECLASS="literal">%B</CODE> expands into the name of the current month.So the first workday of Octoberwill read, "Write schedule for October."</P><PCLASS="para">Some other modifiers defined by <EMCLASS="emphasis">pcal</EM> are <CODECLASS="literal">%A</CODE> for the nameof the weekday,<CODECLASS="literal">%d</CODE> for the day of the month, <CODECLASS="literal">%Y</CODE> for the year,<CODECLASS="literal">%j</CODE> for the day of theyear, and <CODECLASS="literal">%l</CODE> for the number of days remaining in the year.There are also a few modifiers available.The most useful ones are <CODECLASS="literal">%+</CODE> and <CODECLASS="literal">%-</CODE> for using the following or previousmonth or year. For example, suppose you want a reminder on the last dayof the month to pay the rent for the nextmonth.You can write:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">Last day of all Pay rent for month of %+B</PRE></BLOCKQUOTE></P><PCLASS="para">In our office, we're expected to turn in time sheets for each2-week period, on the 1st and 16th of each month.We can write:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">first workday of all Time sheet due for end of %-Bworkday on_or_after all 16 Time sheet due for beginning of %B</PRE></BLOCKQUOTE></P><PCLASS="para"> You can also specify command-line options to <EMCLASS="emphasis">pcal</EM> inyour <EMCLASS="emphasis">.calendar</EM> file, using the <CODECLASS="literal">opt</CODE> keyword.For example:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">opt -n Times-Italic -m</PRE></BLOCKQUOTE></P><PCLASS="para">The <EMCLASS="emphasis">-n Times-Italic</EM> option tells <EMCLASS="emphasis">pcal</EM> to use theTimes Italic font to display the text within the dates. The <EMCLASS="emphasis">-m</EM> option tells <EMCLASS="emphasis">pcal</EM> to show the new, half, and full moons in the month.<ACLASS="indexterm"NAME="AUTOID-58202"></A></P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">LM</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="ch48_08.htm"TITLE="48.8 Calendar for 132-Column Terminals or Printers "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 48.8 Calendar for 132-Column Terminals or Printers "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="ch48_10.htm"TITLE="48.10 Working with Names and Addresses "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 48.10 Working with Names and Addresses "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">48.8 Calendar for 132-Column Terminals or Printers </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">48.10 Working with Names and Addresses </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 + -