Полезная информация

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 48.8 Calendar for 132-Column Terminals or Printers Chapter 48
Office Automation
Next: 48.10 Working with Names and Addresses
 

48.9 PostScript Calendars with pcal

Sometimes you want a hardcopy calendar. You can generate one using cal (48.6) and an ASCII-to-PostScript filter like pstext (43.22), but the resulting calendar is nothing to write home about.

pcal
A nifty alternative for printing calendars is pcal. pcal 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 pcal, and it already has potential for becoming one of my favorite utilities.

In its default form, pcal just creates a PostScript calendar for the current month. The PostScript commands are written to standard output, so you need to pipe it to lpr for BSD-based systems, or lp for System V-based systems. (Of course, your printer has to be able to print PostScript.) For example:

% pcal | lpr

You'll get a full-page calendar of the current month. The dates for Saturdays and Sundays are printed in gray. To get a different month, you can specify it the same way you would using cal. For a calendar for November 1992, you could do:

% pcal 11 1992 | lpr

For a calendar for the whole year, use the -w option to pcal.

% pcal -w | lpr

Once you get a chance to see the pcal output, you'll already see how big an improvement it is over just printing the output of the cal program. But pcal also gives you the opportunity to configure your calendars.

pcal looks for a file called .calendar in either your home directory or your current directory. (This is a hidden file (16.11) 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:

1/1                           New Year's Day
Feb 14                        Valentine's Day

But pcal also understands a limited set of relational words as well. For example:

Second Sunday in May          Mother's Day
4th thu of nov                Thanksgiving

For each of these examples, the given day will have the specified text written in. If you use an asterisk (*) after the date, the day is marked as a holiday.

1/1*                          New Year's Day
Feb 14                        Valentine's Day
Second Sunday in May          Mother's Day
4th thu of nov*               Thanksgiving

This means that the day appears in gray on the calendar, like Saturday and Sunday. But more important, it means that pcal will understand that the marked day isn't a working day.

In addition to holidays, you can use pcal to mark things like birthdays and anniversaries.

June 4                        My Birthday!!!
September 3                   Peter's birthday
April 1                       Mom and Dad's anniversary

Now here's where pcal starts to get useful. You can use pcal to mark meetings you have scheduled:

april 14                      Meet with tax attorney at 4:45
last day of october           Dr. Jekyll's office, 5:30

Or for regular appointments:

Each Friday of July           Leave early for Cape

As you can probably tell by now, the syntax accepted by pcal is very flexible. It's actually much too complicated to be able to explain in full here, but pcal comes with a complete manual page, and pcal -h will give you a list of syntax and command-line options. And if you just wing it, you're likely to come up with syntax that works.

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.

In place of the name of a month, you can use the all keyword to mean all months, i.e., the entire year. For example:

First day of all              Send monthly report to boss
Each Monday in all            Status meeting at 11:30

Now, we used First day of all, above, to specify when we should send our monthly report. What about when the first of the month falls on a weekend or holiday? Well, pcal also understands phrases like workday and holiday. To make sure that your reminder to submit your report appears on the first workday of the month, you can write:

First workday of all          Send monthly report to boss

By default, pcal considers only Saturdays and Sundays to be non-workdays. You add days to this list when you define holidays with asterisks (*) as described previously. [1]

[1] Note that pcal only knows about holidays that have already been declared in your specification file. So in general, you want to define your holidays early in your .calendar file so that later references to workdays will be up-to-date.

Another feature of pcal is that you can use the phases of the moon in your date specifications.

2nd full_moon in all          Blue moon!

pcal supplies format specifiers for writing more detailed descriptions. For example, suppose you want to be reminded at the beginning of each month to make your monthly schedule. You can make up an entry that reads:

First workday of all          Write schedule for %B

The special format specifier %B expands into the name of the current month. So the first workday of October will read, "Write schedule for October."

Some other modifiers defined by pcal are %A for the name of the weekday, %d for the day of the month, %Y for the year, %j for the day of the year, and %l for the number of days remaining in the year. There are also a few modifiers available. The most useful ones are %+ and %- for using the following or previous month or year. For example, suppose you want a reminder on the last day of the month to pay the rent for the next month. You can write:

Last day of all               Pay rent for month of %+B

In our office, we're expected to turn in time sheets for each 2-week period, on the 1st and 16th of each month. We can write:

first workday of all          Time sheet due for end of %-B
workday on_or_after all 16    Time sheet due for beginning of %B

You can also specify command-line options to pcal in your .calendar file, using the opt keyword. For example:

opt   -n Times-Italic -m

The -n Times-Italic option tells pcal to use the Times Italic font to display the text within the dates. The -m option tells pcal to show the new, half, and full moons in the month.

- LM


Previous: 48.8 Calendar for 132-Column Terminals or Printers UNIX Power ToolsNext: 48.10 Working with Names and Addresses
48.8 Calendar for 132-Column Terminals or Printers Book Index48.10 Working with Names and Addresses

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System