[comp.lang.postscript] PostScript Calendars redux

jlw@lzga.ATT.COM (Joe Wood) (01/03/90)

I've been hacking at the PostScript Calendar maker recently.  I've
used what I feel is the better looking version with 5 rows of days
per month (handles overlapping days as in 24/31 in 12/89) and added
banners as well as left justified, centered, and right justified
footers.  All shamelessly stolen from others.  I've found it useful
in making up calendars for my kids' sports teams, the scout troop,
and for church groups.  Alas its a little too late for family calendars
for Christmas gifts.  Wouldn't want to forget Aunt Minnie's birthday
or your anniversary.


Joe Wood
jlw@lzga.ATT.COM

----------------------8<---CUT HERE--------8<------------------------
#!/bin/sh
#+
#
# NAME:
#	pscal
#
# SYNOPSIS:
#	pscal [-Pprinter] [other printer flags] month year
#
# DESCRIPTION:
#	`Pscal' is a PostScript program to print calendars.
#
#	The file $HOME/.holiday is read and used to print short messages
#	on specified days.  The .holiday file should consist of lines of
#	the form 
#		month:day:message string
#	Messages should be 20 characters or less, with no more than 6
#	messages per day.  No spaces should appear from the beginning
#	of a line until after the second colon.
#	Month and day should be numbers in the obvious ranges.
#	12/89 - The holiday checking has been loosened up in that the
#	following takes place:
#		1. The Shell Variable EFILE is used preferentially
#		2. Then the file Events in the current directory is used
#		3. Finally the $HOME/.holiday file is used.
#	The whole process can be turned off by setting EFILE=/dev/null.
#
# OPTIONS:
#	Any argument whose first character is '-' is passed on to lpr.
#	The shell variables BANNER, LFOOT, CFOOT, and RFOOT become a
#	top centered banner, and left, centered, or right justified
#	footers respectively.  As in:
#
#		BANNER="Schedule 1" CFOOT=Preliminary pscal 4 90
#
# AUTHOR:
#	Patrick Wood
#	Copyright (C) 1987 by Pipeline Associates, Inc.
#	Permission is granted to modify and distribute this free of charge.
# 
# HISTORY:
#	@Original From: patwood@unirot.UUCP (Patrick Wood)
#	@Shell stuff added 3/9/87 by King Ables
#	@Made pretty by tjt 1988
#	@Holiday and printer flag passing hacks added Dec 1988 
#	@ by smann@june.cs.washington.edu 
#	@Used the better looking version with 5 rows of days rather than 6
#	@ hacked together with holiday and banner/footnotes added
#	@ by Joe (No Relation) Wood, 12/89, jlw@lzga.ATT.COM
#
# BUGS:
#	`Pscal' doesn't work for months before 1753 (weird stuff happened
#	in September, 1752).
#
#	A better format for the dates of holidays would be nice.
#	An escape to allow holiday messages to be raw PostScript would
#	also be nice.
#	The holiday messages should be handled more intelligently (ie,
#	the messages should be clipped to the day).
#

# 
# PostScript program to print calendars.
# Doesn't deal well with September 1752 or before.
# 

USAGE="Usage: pscal [ -Rrt ] [ -F hfont ] [ -f font ] [ month [ year ] ]"

TFONT=Times-Bold
DFONT=Helvetica-Bold
EFONT=Times-Roman

ROTATE=90

LPR="imprint -Tascii -n"

while test $# != 0
do
    case $1 in
	-P) test $# -lt 2 && { echo "$USAGE" 1>&2; exit 1; }
	    eval ENVAR="$1$2"; shift 2;;
	-P*) eval ENVAR=$1; shift 1;;
	-F) test $# -lt 2 && { echo "$USAGE" 1>&2; exit 1; }
	    TFONT="$2"; shift 2;;
	-F*) TFONT=`echo $1 | sed -n 1s/-.//p`; shift 1;;
	-f) test $# -lt 2 && { echo "$USAGE" 1>&2; exit 1; }
	    DFONT="$2"; shift 2;;
	-f*) DFONT=`echo $1 | sed -n 1s/-.//p`; shift 1;;
	-t) LPR=cat; shift 1;;
	-r) ROTATE=90; shift 1;;
	-R) ROTATE=0; shift 1;;
	--|-) break;;
	-*) echo "$USAGE" 1>&2; exit 1;;
	*) break
    esac
done

test $# -gt 2 && { echo "$USAGE" 1>&2; exit 1; }

case $# in
    0)	set `date`; YEAR=$6
	MONTH=`case $2 in Jan) echo 1;;Feb) echo 2;;Mar) echo 3;;Apr) echo 4;;
		May) echo 5;;Jun) echo 6;;Jul) echo 7;;Aug) echo 8;;
		Sep) echo 9;;Oct) echo 10;;Nov) echo 11;;Dec) echo 12;;esac`;;
    1)	MONTH=$1; set `date`; YEAR=$6;;
    2)	MONTH=$1 YEAR=$2;;
esac

if [ -n "$EFILE" -a -r "$EFILE" ]
then
	Files=$EFILE
elif [ -r Events ]
then
	Files=Events
elif [ -r $HOME/.holiday ]
then
	Files=$HOME/.holiday
else
	Files=/dev/null
fi

holidays=`cat $Files | grep \^$MONTH: | awk -F: '{printf("%s ( %s",$2,$3);\
		for(i = 4; i <= NF; i++) printf(":%s", $i);printf(")\n"); }'`

test $YEAR -lt 100 && YEAR=`expr $YEAR + 1900`

$LPR $ENVAR <<END-OF-CALENDAR
%!
% PostScript program to draw calendar
% Copyright (C) 1987 by Pipeline Associates, Inc.
% Permission is granted to modify and distribute this free of charge.

% The number after /month should be set to a number from 1 to 12.
% The number after /year should be set to the year you want.
% You can change the title and date fonts, if you want.
% We figure out the rest.
% This program won't produce valid calendars before 1800 due to the switch
% from Julian to Gregorian calendars in September of 1752 wherever English
% was spoken.

/month $MONTH def
/year $YEAR def
/titlefont /$TFONT def
/dayfont /$DFONT def
/eventfont /$EFONT def
/holidays [ $holidays ] def
/Bannerstring ($BANNER) def
/Lfootstring ($LFOOT) def
/Rfootstring ($RFOOT) def
/Cfootstring ($CFOOT) def

% calendar names - change these if you don't speak english
% "August", "April" and "February" could stand to be kerned even if you do

/month_names
[ (January) (February) (March) (April) (May) (June) (July)
(August) (September) (October) (November) (December) ]
def

/day_names
[ (Sunday) (Monday) (Tuesday) (Wednesday) (Thursday) (Friday) (Saturday) ]
def

% layout parameters - you can change these, but things may not look nice

/daywidth 100 def
/dayheight 95 def

/titlefontsize 48 def
/weekdayfontsize 10 def
/datefontsize 30 def
/footfontsize 20 def

/topgridmarg 35 def
/leftmarg 35 def
/daytopmarg 10 def
/dayleftmarg 5 def

% layout constants - don't change these, things probably won't work

/rows 5 def
/subrows 6 def

% calendar constants - change these if you want a French revolutionary calendar

/days_week 7 def

/days_month [ 31 28 31 30 31 30 31 31 30 31 30 31 ] def

/isleap {				% is this a leap year?
	year 4 mod 0 eq			% multiple of 4
	year 100 mod 0 ne 		% not century
	year 1000 mod 0 eq or and	% unless it's a millenia
} def

/ndays {				% number of days in this month
	days_month month 1 sub get
	month 2 eq			% February
	isleap and
	{
		1 add
	} if
} def

/weekday {				% weekday (range 0-6) for integer date
	days_week mod
} def

/startday {				% starting day-of-week for this month
	/off year 2000 sub def		% offset from start of "epoch"
	off
	off 4 idiv add			% number of leap years
	off 100 idiv sub		% number of centuries
	off 1000 idiv add		% number of millenia
	6 add weekday days_week add 	% offset from Jan 1 2000
	/off exch def
	1 1 month 1 sub {
		/idx exch def
		days_month idx 1 sub get
		idx 2 eq
		isleap and
		{
			1 add
		} if
		/off exch off add def
	} for
	off weekday			% 0--Sunday, 1--monday, etc.
} def

/prtevent {		% event-string day prtevent
			%  print out an event
	/start startday def
	/day 2 1 roll def
	day start add 1 sub 7 mod daywidth mul
	day start add 1 sub 7 div truncate dayheight neg mul 
	-5 
	numevents day start add get -10 mul add
	numevents
	day start add 
	numevents day start add get 1 add
	put
	add moveto
	show
} def

/drawevents {		% read in a file full of events; print
			%  the events for this month
	/numevents
	[0 0 0 0 0 0 0
	 0 0 0 0 0 0 0
	 0 0 0 0 0 0 0
	 0 0 0 0 0 0 0
	 0 0 0 0 0 0 0
	 0 0 0 0 0 0 0] def 
	 eventfont findfont 9 scalefont setfont
	 0 2 holidays length 2 sub {
		dup
		1 add holidays 2 1 roll get
		2 1 roll holidays 2 1 roll get
		prtevent
	} for
		
} def

% ------------------------------------------------------------------------

/prtnum { 3 string cvs show } def

/center {				% center string in given width
	/width exch def
	/str exch def width str 
	stringwidth pop sub 2 div 0 rmoveto str show
} def

/centernum { exch 3 string cvs exch center } def

/drawgrid {				% draw calendar boxes
	titlefont findfont weekdayfontsize scalefont setfont
	currentpoint /y0 exch def /x0 exch def
	0 1 days_week 1 sub {
		submonth 0 eq
		{
			x0 y0 moveto
			dup dup daywidth mul 40 rmoveto
			day_names exch get
			daywidth center
		} if
		x0 y0 moveto
		daywidth mul topgridmarg rmoveto
		1.0 setlinewidth
		submonth 0 eq
		{
			/rowsused rows 1 sub def
		}
		{
			/rowsused rows def
		}
		ifelse
		0 1 rowsused {
			gsave
			daywidth 0 rlineto 
			0 dayheight neg rlineto
			daywidth neg 0 rlineto
			closepath stroke
			grestore
			0 dayheight neg rmoveto
		} for
	} for
} def

/drawnums {				% place day numbers on calendar
	dayfont findfont datefontsize
	submonth 0 ne
	{
		2.5 mul
	} if scalefont setfont
	/start startday def
	/days ndays def
	start daywidth mul dayleftmarg add daytopmarg rmoveto
	submonth 0 ne
	{
		dayleftmarg neg dayheight -2 div rmoveto
	} if
	1 1 days {
		/day exch def
		gsave
		day start add weekday 0 eq
		{
			submonth 0 eq
			{
				.7 setgray
			} if
		} if
		day start add weekday 1 eq
		{
			submonth 0 eq
			{
				.7 setgray
			} if
		} if
		submonth 0 eq
		{
			isdouble
			{
				day prtdouble
			}
			{
				day prtnum
			} ifelse
		}
		{
			day daywidth centernum
		} ifelse
		grestore
		day start add weekday 0 eq
		{
			currentpoint exch pop dayheight sub 0 exch moveto
			submonth 0 eq
			{
				dayleftmarg 0 rmoveto
			} if
		}
		{
			daywidth 0 rmoveto
		} ifelse
	} for
} def
/isdouble {				% overlay today with next/last week?
	days start add rows days_week mul gt
	{
		day start add rows days_week mul gt
		{
			true true
		}
		{
			day start add rows 1 sub days_week mul gt
			day days_week add days le and
			{
				false true
			}
			{
				false
			} ifelse
		} ifelse
	}
	{
		false
	} ifelse
} def

/prtdouble {
	gsave
	  dayfont findfont datefontsize 2 mul 3 div scalefont setfont
	  exch
	  {
		(23/) stringwidth pop dayheight rmoveto
		prtnum
	  }
	  {
		0 datefontsize 5 div rmoveto
		prtnum
		0 datefontsize -5 div rmoveto
		gsave
		  dayfont findfont datefontsize scalefont setfont
		  (/) show
		grestore
	  } ifelse
	grestore
} def

/drawfill {				% place fill squares on calendar
	/start startday def
	/days ndays def
	currentpoint /y0 exch def /x0 exch def
	submonth 0 eq
	{
		usefirst
		{
			/fillstart 2 def
		}
		{
			/fillstart 0 def
		}
		ifelse
	}
	{
		/fillstart 0 def
	}
	ifelse
	fillstart daywidth mul topgridmarg rmoveto
	1.0 setlinewidth
	fillstart 1 start 1 sub {
		gsave
		.9 setgray
		daywidth 0 rlineto 
		0 dayheight neg rlineto
		daywidth neg 0 rlineto
		closepath fill
		grestore
		daywidth 0 rmoveto
	} for
	x0 y0 moveto
	submonth 0 ne
	{
		/lastday rows 1 add days_week mul def
		days_week 1 sub daywidth mul -440 rmoveto
	}
	{
		/lastday rows days_week mul 2 sub fillstart add def
		days_week 3 sub fillstart add daywidth mul
		-440 dayheight add rmoveto
	} ifelse
	lastday -1 ndays start 1 add add
	{
		/day exch def
		gsave
		.9 setgray
		daywidth 0 rlineto 
		0 dayheight neg rlineto
		daywidth neg 0 rlineto
		closepath fill
		grestore
		day weekday 1 eq
		{
			x0 y0 moveto
			days_week 1 sub daywidth mul -440 dayheight add rmoveto
		}
		{
			daywidth neg 0 rmoveto
		} ifelse
	} for
} def

/usefirst {				% are last two boxes used by days?
	start ndays add rows days_week mul 3 sub gt
	start 2 ge and
	
} def

/calendar
{
	titlefont findfont titlefontsize scalefont setfont
	0 60 moveto
	/month_name month_names month 1 sub get def
	month_name show
	/yearstring year 10 string cvs def
	daywidth days_week mul yearstring stringwidth pop sub 60 moveto
	yearstring show

	eventflag {
		% Show a centered Banner if any at the Top
		daywidth days_week mul 2 div
		Bannerstring stringwidth pop 2 div sub
		60 moveto
		Bannerstring show
		% Show footnotes left-center-right
		eventfont findfont footfontsize scalefont setfont
		/bottomrow { dayheight rows mul 5 sub neg } def
		0 bottomrow moveto
		Lfootstring show
		daywidth days_week mul Rfootstring stringwidth pop sub
		bottomrow moveto
		Rfootstring show
		daywidth days_week mul Cfootstring stringwidth pop sub 2 div
		bottomrow moveto
		Cfootstring show
		
	} if

	0 -5 moveto
	drawnums

	0 -5 moveto
	drawfill

	eventflag {
		0 0 moveto
		drawevents
	} if

	0 -5 moveto
	drawgrid
} def

/eventflag true def

$ROTATE rotate
50 -120 translate
/submonth 0 def
calendar
/eventflag false def
month 1 sub 0 eq
{
	/lmonth 12 def
	/lyear year 1 sub def
}
{
	/lmonth month 1 sub def
	/lyear year def
} ifelse
month 1 add 13 eq
{
	/nmonth 1 def
	/nyear year 1 add def
} 
{
	/nmonth month 1 add def
	/nyear year def
} ifelse
usefirst
{
	0 30 translate
}
{
	days_week 2 sub daywidth mul -350 translate
}
ifelse
/submonth 1 def
/year lyear def
/month lmonth def
gsave
.138 .138 scale
12 -120 translate
calendar
grestore
/submonth 1 def
/year nyear def
/month nmonth def
daywidth 0 translate
gsave
.138 .138 scale
12 -120 translate
calendar
grestore

showpage

END-OF-CALENDAR

tim@dciem.dciem.dnd.ca (Tim Pointing) (01/06/90)

In a recent posting, an updated "pscal" was posted. I found one small
"bug" (where the program didn't behave as the comments suggested.)
The change is in line 93... change

	-*) echo "$USAGE" 1>&2; exit 1;;

to

	-*) eval ENVAR=$1; shift 1;;

Also, the comment on line 29 should read "Any argument whose first character
is '-' but which is not a recognised 'pscal' flag is passed on to lpr."

Note also that most people will have to change the assignment of LPR
to just "lpr" (or, perhaps, "lpr -Pps" to get to a PostScript printer.)
-- 
	Tim Pointing, DCIEM
	{decvax,attcan,watmath,...}!utzoo!dciem!tim
        uunet!csri.toronto.edu!dciem!tim or nrcaer!dciem!tim
	tim%ben@zorac.dciem.dnd.ca or tim@dretor.dciem.dnd.ca

mogul@decwrl.dec.com (Jeffrey Mogul) (01/09/90)

In article <2816@dciem.dciem.dnd.ca> tim@dretor.dciem.dnd.ca (Tim Pointing) writes:
>In a recent posting, an updated "pscal" was posted. I found one small
>"bug" (where the program didn't behave as the comments suggested.)
>The change is in line 93... change
>
>	-*) echo "$USAGE" 1>&2; exit 1;;
>
>to
>
>	-*) eval ENVAR=$1; shift 1;;

This is close, but not quite right, since it doesn't allow you
to specify more than one such passed-through argument.

The original program also had a bug in the "-R" mode; it would
rotate the calendar completely off the page.  I fixed this and
also made -R scale the image so as to fit on an 8.5x11 sheet of
paper.

Finally, I wrote a short manual page.  The new source and the manual
page are appended to the end of this message, in "shar" format.

-Jeff

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  pscal.sh pscal.man
# Wrapped by mogul@jove.pa.dec.com on Mon Jan  8 15:25:49 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'pscal.sh' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'pscal.sh'\"
else
echo shar: Extracting \"'pscal.sh'\" \(12393 characters\)
sed "s/^X//" >'pscal.sh' <<'END_OF_FILE'
X#!/bin/sh
X#+
X#
X# NAME:
X#	pscal
X#
X# SYNOPSIS:
X#	pscal [-Pprinter] [other printer flags] month year
X#
X# DESCRIPTION:
X#	`Pscal' is a PostScript program to print calendars.
X#
X#	The file $HOME/.holiday is read and used to print short messages
X#	on specified days.  The .holiday file should consist of lines of
X#	the form 
X#		month:day:message string
X#	Messages should be 20 characters or less, with no more than 6
X#	messages per day.  No spaces should appear from the beginning
X#	of a line until after the second colon.
X#	Month and day should be numbers in the obvious ranges.
X#	12/89 - The holiday checking has been loosened up in that the
X#	following takes place:
X#		1. The Shell Variable EFILE is used preferentially
X#		2. Then the file Events in the current directory is used
X#		3. Finally the $HOME/.holiday file is used.
X#	The whole process can be turned off by setting EFILE=/dev/null.
X#
X# OPTIONS:
X#	Any argument whose first character is '-' is passed on to lpr.
X#	The shell variables BANNER, LFOOT, CFOOT, and RFOOT become a
X#	top centered banner, and left, centered, or right justified
X#	footers respectively.  As in:
X#
X#		BANNER="Schedule 1" CFOOT=Preliminary pscal 4 90
X#
X# AUTHOR:
X#	Patrick Wood
X#	Copyright (C) 1987 by Pipeline Associates, Inc.
X#	Permission is granted to modify and distribute this free of charge.
X# 
X# HISTORY:
X#	@Original From: patwood@unirot.UUCP (Patrick Wood)
X#	@Shell stuff added 3/9/87 by King Ables
X#	@Made pretty by tjt 1988
X#	@Holiday and printer flag passing hacks added Dec 1988 
X#	@ by smann@june.cs.washington.edu 
X#	@Used the better looking version with 5 rows of days rather than 6
X#	@ hacked together with holiday and banner/footnotes added
X#	@ by Joe (No Relation) Wood, 12/89, jlw@lzga.ATT.COM
X#	@Fixed "-R" (didn't work at all; now it at least works on 8.5x11)
X#	@Also fixed handling of unrecognized arguments
X#	@ by Jeff Mogul, 1/90, mogul@decwrl.dec.com
X#
X# BUGS:
X#	`Pscal' doesn't work for months before 1753 (weird stuff happened
X#	in September, 1752).
X#
X#	A better format for the dates of holidays would be nice.
X#	An escape to allow holiday messages to be raw PostScript would
X#	also be nice.
X#	The holiday messages should be handled more intelligently (ie,
X#	the messages should be clipped to the day).
X#
X
X# 
X# PostScript program to print calendars.
X# Doesn't deal well with September 1752 or before.
X# 
X
USAGE="Usage: pscal [ -Rrt ] [ -F hfont ] [ -f font ] [ month [ year ] ]"
X
TFONT=Times-Bold
DFONT=Helvetica-Bold
XEFONT=Times-Roman
X
ROTATE=90
SCALE="1.0 1.0"
TRANSLATE="50 -120"
X
LPR="lpr"
X
while test $# != 0
do
X    case $1 in
X	-P) test $# -lt 2 && { echo "$USAGE" 1>&2; exit 1; }
X	    eval ENVAR="$1$2"; shift 2;;
X	-P*) eval ENVAR=$1; shift 1;;
X	-F) test $# -lt 2 && { echo "$USAGE" 1>&2; exit 1; }
X	    TFONT="$2"; shift 2;;
X	-F*) TFONT=`echo $1 | sed -n 1s/-.//p`; shift 1;;
X	-f) test $# -lt 2 && { echo "$USAGE" 1>&2; exit 1; }
X	    DFONT="$2"; shift 2;;
X	-f*) DFONT=`echo $1 | sed -n 1s/-.//p`; shift 1;;
X	-t) LPR=cat; shift 1;;
X	-r) ROTATE=90; shift 1;;
X	-R) ROTATE=0; SCALE="0.75 0.75"; TRANSLATE="50 900"; shift 1;;
X	--|-) break;;
X	-*) eval ENVAR=\"$ENVAR $1\"; shift 1;;
X	*) break
X    esac
done
X
test $# -gt 2 && { echo "$USAGE" 1>&2; exit 1; }
X
case $# in
X    0)	set `date`; YEAR=$6
X	MONTH=`case $2 in Jan) echo 1;;Feb) echo 2;;Mar) echo 3;;Apr) echo 4;;
X		May) echo 5;;Jun) echo 6;;Jul) echo 7;;Aug) echo 8;;
X		Sep) echo 9;;Oct) echo 10;;Nov) echo 11;;Dec) echo 12;;esac`;;
X    1)	MONTH=$1; set `date`; YEAR=$6;;
X    2)	MONTH=$1 YEAR=$2;;
esac
X
if [ -n "$EFILE" -a -r "$EFILE" ]
then
X	Files=$EFILE
elif [ -r Events ]
then
X	Files=Events
elif [ -r $HOME/.holiday ]
then
X	Files=$HOME/.holiday
else
X	Files=/dev/null
fi
X
holidays=`cat $Files | grep \^$MONTH: | awk -F: '{printf("%s ( %s",$2,$3);\
X		for(i = 4; i <= NF; i++) printf(":%s", $i);printf(")\n"); }'`
X
test $YEAR -lt 100 && YEAR=`expr $YEAR + 1900`
X
X$LPR $ENVAR <<END-OF-CALENDAR
X%!
X% PostScript program to draw calendar
X% Copyright (C) 1987 by Pipeline Associates, Inc.
X% Permission is granted to modify and distribute this free of charge.
X
X% The number after /month should be set to a number from 1 to 12.
X% The number after /year should be set to the year you want.
X% You can change the title and date fonts, if you want.
X% We figure out the rest.
X% This program won't produce valid calendars before 1800 due to the switch
X% from Julian to Gregorian calendars in September of 1752 wherever English
X% was spoken.
X
X/month $MONTH def
X/year $YEAR def
X/titlefont /$TFONT def
X/dayfont /$DFONT def
X/eventfont /$EFONT def
X/holidays [ $holidays ] def
X/Bannerstring ($BANNER) def
X/Lfootstring ($LFOOT) def
X/Rfootstring ($RFOOT) def
X/Cfootstring ($CFOOT) def
X
X% calendar names - change these if you don't speak english
X% "August", "April" and "February" could stand to be kerned even if you do
X
X/month_names
X[ (January) (February) (March) (April) (May) (June) (July)
X(August) (September) (October) (November) (December) ]
def
X
X/day_names
X[ (Sunday) (Monday) (Tuesday) (Wednesday) (Thursday) (Friday) (Saturday) ]
def
X
X% layout parameters - you can change these, but things may not look nice
X
X/daywidth 100 def
X/dayheight 95 def
X
X/titlefontsize 48 def
X/weekdayfontsize 10 def
X/datefontsize 30 def
X/footfontsize 20 def
X
X/topgridmarg 35 def
X/leftmarg 35 def
X/daytopmarg 10 def
X/dayleftmarg 5 def
X
X% layout constants - don't change these, things probably won't work
X
X/rows 5 def
X/subrows 6 def
X
X% calendar constants - change these if you want a French revolutionary calendar
X
X/days_week 7 def
X
X/days_month [ 31 28 31 30 31 30 31 31 30 31 30 31 ] def
X
X/isleap {				% is this a leap year?
X	year 4 mod 0 eq			% multiple of 4
X	year 100 mod 0 ne 		% not century
X	year 1000 mod 0 eq or and	% unless it's a millenia
X} def
X
X/ndays {				% number of days in this month
X	days_month month 1 sub get
X	month 2 eq			% February
X	isleap and
X	{
X		1 add
X	} if
X} def
X
X/weekday {				% weekday (range 0-6) for integer date
X	days_week mod
X} def
X
X/startday {				% starting day-of-week for this month
X	/off year 2000 sub def		% offset from start of "epoch"
X	off
X	off 4 idiv add			% number of leap years
X	off 100 idiv sub		% number of centuries
X	off 1000 idiv add		% number of millenia
X	6 add weekday days_week add 	% offset from Jan 1 2000
X	/off exch def
X	1 1 month 1 sub {
X		/idx exch def
X		days_month idx 1 sub get
X		idx 2 eq
X		isleap and
X		{
X			1 add
X		} if
X		/off exch off add def
X	} for
X	off weekday			% 0--Sunday, 1--monday, etc.
X} def
X
X/prtevent {		% event-string day prtevent
X			%  print out an event
X	/start startday def
X	/day 2 1 roll def
X	day start add 1 sub 7 mod daywidth mul
X	day start add 1 sub 7 div truncate dayheight neg mul 
X	-5 
X	numevents day start add get -10 mul add
X	numevents
X	day start add 
X	numevents day start add get 1 add
X	put
X	add moveto
X	show
X} def
X
X/drawevents {		% read in a file full of events; print
X			%  the events for this month
X	/numevents
X	[0 0 0 0 0 0 0
X	 0 0 0 0 0 0 0
X	 0 0 0 0 0 0 0
X	 0 0 0 0 0 0 0
X	 0 0 0 0 0 0 0
X	 0 0 0 0 0 0 0] def 
X	 eventfont findfont 9 scalefont setfont
X	 0 2 holidays length 2 sub {
X		dup
X		1 add holidays 2 1 roll get
X		2 1 roll holidays 2 1 roll get
X		prtevent
X	} for
X		
X} def
X
X% ------------------------------------------------------------------------
X
X/prtnum { 3 string cvs show } def
X
X/center {				% center string in given width
X	/width exch def
X	/str exch def width str 
X	stringwidth pop sub 2 div 0 rmoveto str show
X} def
X
X/centernum { exch 3 string cvs exch center } def
X
X/drawgrid {				% draw calendar boxes
X	titlefont findfont weekdayfontsize scalefont setfont
X	currentpoint /y0 exch def /x0 exch def
X	0 1 days_week 1 sub {
X		submonth 0 eq
X		{
X			x0 y0 moveto
X			dup dup daywidth mul 40 rmoveto
X			day_names exch get
X			daywidth center
X		} if
X		x0 y0 moveto
X		daywidth mul topgridmarg rmoveto
X		1.0 setlinewidth
X		submonth 0 eq
X		{
X			/rowsused rows 1 sub def
X		}
X		{
X			/rowsused rows def
X		}
X		ifelse
X		0 1 rowsused {
X			gsave
X			daywidth 0 rlineto 
X			0 dayheight neg rlineto
X			daywidth neg 0 rlineto
X			closepath stroke
X			grestore
X			0 dayheight neg rmoveto
X		} for
X	} for
X} def
X
X/drawnums {				% place day numbers on calendar
X	dayfont findfont datefontsize
X	submonth 0 ne
X	{
X		2.5 mul
X	} if scalefont setfont
X	/start startday def
X	/days ndays def
X	start daywidth mul dayleftmarg add daytopmarg rmoveto
X	submonth 0 ne
X	{
X		dayleftmarg neg dayheight -2 div rmoveto
X	} if
X	1 1 days {
X		/day exch def
X		gsave
X		day start add weekday 0 eq
X		{
X			submonth 0 eq
X			{
X				.7 setgray
X			} if
X		} if
X		day start add weekday 1 eq
X		{
X			submonth 0 eq
X			{
X				.7 setgray
X			} if
X		} if
X		submonth 0 eq
X		{
X			isdouble
X			{
X				day prtdouble
X			}
X			{
X				day prtnum
X			} ifelse
X		}
X		{
X			day daywidth centernum
X		} ifelse
X		grestore
X		day start add weekday 0 eq
X		{
X			currentpoint exch pop dayheight sub 0 exch moveto
X			submonth 0 eq
X			{
X				dayleftmarg 0 rmoveto
X			} if
X		}
X		{
X			daywidth 0 rmoveto
X		} ifelse
X	} for
X} def
X/isdouble {				% overlay today with next/last week?
X	days start add rows days_week mul gt
X	{
X		day start add rows days_week mul gt
X		{
X			true true
X		}
X		{
X			day start add rows 1 sub days_week mul gt
X			day days_week add days le and
X			{
X				false true
X			}
X			{
X				false
X			} ifelse
X		} ifelse
X	}
X	{
X		false
X	} ifelse
X} def
X
X/prtdouble {
X	gsave
X	  dayfont findfont datefontsize 2 mul 3 div scalefont setfont
X	  exch
X	  {
X		(23/) stringwidth pop dayheight rmoveto
X		prtnum
X	  }
X	  {
X		0 datefontsize 5 div rmoveto
X		prtnum
X		0 datefontsize -5 div rmoveto
X		gsave
X		  dayfont findfont datefontsize scalefont setfont
X		  (/) show
X		grestore
X	  } ifelse
X	grestore
X} def
X
X/drawfill {				% place fill squares on calendar
X	/start startday def
X	/days ndays def
X	currentpoint /y0 exch def /x0 exch def
X	submonth 0 eq
X	{
X		usefirst
X		{
X			/fillstart 2 def
X		}
X		{
X			/fillstart 0 def
X		}
X		ifelse
X	}
X	{
X		/fillstart 0 def
X	}
X	ifelse
X	fillstart daywidth mul topgridmarg rmoveto
X	1.0 setlinewidth
X	fillstart 1 start 1 sub {
X		gsave
X		.9 setgray
X		daywidth 0 rlineto 
X		0 dayheight neg rlineto
X		daywidth neg 0 rlineto
X		closepath fill
X		grestore
X		daywidth 0 rmoveto
X	} for
X	x0 y0 moveto
X	submonth 0 ne
X	{
X		/lastday rows 1 add days_week mul def
X		days_week 1 sub daywidth mul -440 rmoveto
X	}
X	{
X		/lastday rows days_week mul 2 sub fillstart add def
X		days_week 3 sub fillstart add daywidth mul
X		-440 dayheight add rmoveto
X	} ifelse
X	lastday -1 ndays start 1 add add
X	{
X		/day exch def
X		gsave
X		.9 setgray
X		daywidth 0 rlineto 
X		0 dayheight neg rlineto
X		daywidth neg 0 rlineto
X		closepath fill
X		grestore
X		day weekday 1 eq
X		{
X			x0 y0 moveto
X			days_week 1 sub daywidth mul -440 dayheight add rmoveto
X		}
X		{
X			daywidth neg 0 rmoveto
X		} ifelse
X	} for
X} def
X
X/usefirst {				% are last two boxes used by days?
X	start ndays add rows days_week mul 3 sub gt
X	start 2 ge and
X	
X} def
X
X/calendar
X{
X	titlefont findfont titlefontsize scalefont setfont
X	0 60 moveto
X	/month_name month_names month 1 sub get def
X	month_name show
X	/yearstring year 10 string cvs def
X	daywidth days_week mul yearstring stringwidth pop sub 60 moveto
X	yearstring show
X
X	eventflag {
X		% Show a centered Banner if any at the Top
X		daywidth days_week mul 2 div
X		Bannerstring stringwidth pop 2 div sub
X		60 moveto
X		Bannerstring show
X		% Show footnotes left-center-right
X		eventfont findfont footfontsize scalefont setfont
X		/bottomrow { dayheight rows mul 5 sub neg } def
X		0 bottomrow moveto
X		Lfootstring show
X		daywidth days_week mul Rfootstring stringwidth pop sub
X		bottomrow moveto
X		Rfootstring show
X		daywidth days_week mul Cfootstring stringwidth pop sub 2 div
X		bottomrow moveto
X		Cfootstring show
X		
X	} if
X
X	0 -5 moveto
X	drawnums
X
X	0 -5 moveto
X	drawfill
X
X	eventflag {
X		0 0 moveto
X		drawevents
X	} if
X
X	0 -5 moveto
X	drawgrid
X} def
X
X/eventflag true def
X
X$SCALE	scale
X$ROTATE rotate
X$TRANSLATE translate
X/submonth 0 def
calendar
X/eventflag false def
month 1 sub 0 eq
X{
X	/lmonth 12 def
X	/lyear year 1 sub def
X}
X{
X	/lmonth month 1 sub def
X	/lyear year def
X} ifelse
month 1 add 13 eq
X{
X	/nmonth 1 def
X	/nyear year 1 add def
X} 
X{
X	/nmonth month 1 add def
X	/nyear year def
X} ifelse
usefirst
X{
X	0 30 translate
X}
X{
X	days_week 2 sub daywidth mul -350 translate
X}
ifelse
X/submonth 1 def
X/year lyear def
X/month lmonth def
gsave
X.138 .138 scale
X12 -120 translate
calendar
grestore
X/submonth 1 def
X/year nyear def
X/month nmonth def
daywidth 0 translate
gsave
X.138 .138 scale
X12 -120 translate
calendar
grestore
X
showpage
X
XEND-OF-CALENDAR
X
END_OF_FILE
if test 12393 -ne `wc -c <'pscal.sh'`; then
    echo shar: \"'pscal.sh'\" unpacked with wrong size!
fi
chmod +x 'pscal.sh'
# end of 'pscal.sh'
fi
if test -f 'pscal.man' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'pscal.man'\"
else
echo shar: Extracting \"'pscal.man'\" \(1794 characters\)
sed "s/^X//" >'pscal.man' <<'END_OF_FILE'
X.TH PSCAL L
X.SH NAME
pscal \- print calendar page on a PostScript printer
X.SH SYNTAX
X.B pscal
X[ -Pprinter ]
X[ -R ] [ -r ] [ -t ]
X[ month [ year ] ]
X.SH DESCRIPTION
X.I Pscal
prints (on a PostScript printer)
a calendar for the specified month and year.  The year, if omitted, defaults
to the current year.  If both month and year are omitted, the current
month is printed.
X.I Year
can be between 1753
and 9999.
The
X.I month
is a number between 1 and 12.
X.PP
This version of the
X.I pscal
program will print short messages on user-chosen dates, as specified
in your
X.I $HOME/.holiday
file.  The .holiday file should consist of lines of
the form 
X.nf
X.RS
month:day:message string
X.RE
X.fi
Messages should be 20 characters or less, with no more than 6
messages per day.  No spaces should appear from the beginning
of a line until after the second colon.
Month and day should be numbers in the obvious ranges.
XFor example,
X.nf
X.RS
X12:16:Beethoven's Birthday
X.RE
X.fi
X.SH OPTIONS
X.IP "\-P\fIprinter\fR" 1i
The printer may be specified with the usual \-P\fIprinter\fR syntax.
X.IP "\-r" 1i
The calendar page is printed in ``landscape'' orientation (the default).
X.IP "\-R" 1i
The calendar page is printed in ``portrait'' orientation; this
yields a slightly smaller image and may be more suitable for
embedding into other documents.
X.IP "\-t" 1i
Causes the PostScript to be sent to the standard output, rather
than to the printer.  This is useful if you wish to save the
output in a file, or if you want to use options with the
X.IR lpr (1)
command.
X.IP "\-F\fIfont\fR" 1i
Sets the font family for the title text (the month and year).
X.IP "\-f\fIfont\fR" 1i
Sets the font family for the day-of-month numbers.
X.PP
Other arguments starting with `\-' are passed through to
X.IR lpr (1).
X.SH FILES
X$HOME/.holiday
END_OF_FILE
if test 1794 -ne `wc -c <'pscal.man'`; then
    echo shar: \"'pscal.man'\" unpacked with wrong size!
fi
# end of 'pscal.man'
fi
echo shar: End of shell archive.
exit 0