home *** CD-ROM | disk | FTP | other *** search
- /*
- * $Header: pcal.c,v 2.1 89/05/16 16:30:00 billr Exp $
- */
- /*
- * pcal - print pretty PostScript image of a month calendar
- *
- * Pieces extracted from the pcal program by Ken Keirnan and modified
- * slightly by Bill Randle, Tektronix, Inc. <billr@saab.CNA.TEK.COM>.
- *
- * "Pcal" is a program to print PostScript calendars for any month and year.
- * Pcal is the combined effort of several people, most notably Patrick Wood
- * of Pipeline Associates, Inc. for the original PostScript code and Bill
- * Vogel of AT&T for the calendar file mechanism. My part was simple
- * translation to a "C" program, the addition of a couple options and a more
- * generalized date searching routine (oh yes, and a manual page :-).
- *
- * The original calendar PostScript was Copyright (c) 1987 by Patrick Wood
- * and Pipeline Associates, Inc. with permission to modify and redistribute.
- *
- * Ken Keirnan
- * Pacific Bell
- * San Ramon, CA.
- *
- * Changes and additions Copyright (C) 1989 Tektronix, Inc.
- * All Rights Reserved
- * Permission is hereby granted to use and modify the modifications in source
- * or binary form as long as they are not sold for profit and this copyright
- * notice remains intact.
- */
- #include "ct.h" /* for the NO_PRINTER #define */
-
- #ifndef NO_PRINTER
- #include <stdio.h>
- #include <time.h>
-
- extern struct tm current, First;
- extern struct dayslot slots[];
-
- /*
- * pheader - provides the PostScript routines
- */
- char *pheader[] = {
- "%!",
- "/titlefont /Times-Bold def",
- "/dayfont /Helvetica-Bold def",
- "/month_names [ (January) (February) (March) (April) (May) (June) (July)",
- "\t\t(August) (September) (October) (November) (December) ] def",
- "/prtnum { 3 string cvs show} def",
- "/drawgrid {\t\t% draw calendar boxes",
- "\tdayfont findfont 10 scalefont setfont",
- "\t0 1 6 {",
- "\t\tdup dup 100 mul 40 moveto",
- "\t\t[ (Sunday) (Monday) (Tuesday) (Wednesday) (Thursday) (Friday) (Saturday) ] exch get",
- "\t\t100 center",
- "\t\t100 mul 35 moveto",
- "\t\t1.0 setlinewidth",
- "\t\t0 1 5 {",
- "\t\t\tgsave",
- "\t\t\t100 0 rlineto ",
- "\t\t\t0 -80 rlineto",
- "\t\t\t-100 0 rlineto",
- "\t\t\tclosepath stroke",
- "\t\t\tgrestore",
- "\t\t\t0 -80 rmoveto",
- "\t\t} for",
- "\t} for",
- "} def",
- "/drawnums {\t\t% place day numbers on calendar",
- "\tdayfont findfont 30 scalefont setfont",
- "\t/start startday def",
- "\t/days ndays def",
- "\tstart 100 mul 5 add 10 rmoveto",
- "\t1 1 days {",
- "\t\t/day exch def",
- "\t\tgsave",
- #ifndef SATBLK
- "\t\tday start add 7 mod 0 eq",
- "\t\t{",
- "\t\t\tsubmonth 0 eq",
- "\t\t\t{",
- "\t\t\t\t.8 setgray",
- "\t\t\t} if",
- "\t\t} if",
- #endif
- "\t\tday start add 7 mod 1 eq",
- "\t\t{",
- "\t\t\tsubmonth 0 eq",
- "\t\t\t{",
- "\t\t\t\t.8 setgray",
- "\t\t\t} if",
- "\t\t} if",
- "\t\tday prtnum",
- "\t\tgrestore",
- "\t\tday start add 7 mod 0 eq",
- "\t\t{",
- "\t\t\tcurrentpoint exch pop 80 sub 5 exch moveto",
- "\t\t}",
- "\t\t{",
- "\t\t\t100 0 rmoveto",
- "\t\t} ifelse",
- "\t} for",
- "} def",
- "/drawfill {\t\t% place fill squares on calendar",
- "\t/start startday def",
- "\t/days ndays def",
- "\t0 35 rmoveto",
- "\t1.0 setlinewidth",
- "\t0 1 start 1 sub {",
- "\t\tgsave",
- "\t\t.9 setgray",
- "\t\t100 0 rlineto ",
- "\t\t0 -80 rlineto",
- "\t\t-100 0 rlineto",
- "\t\tclosepath fill",
- "\t\tgrestore",
- "\t\t100 0 rmoveto",
- "\t} for",
- "\tsubmonth 1 eq",
- "\t{",
- "\t\t/lastday 42 def",
- "\t\t600 -365 moveto",
- "\t}",
- "\t{",
- "\t\t/lastday 40 def",
- "\t\t400 -365 moveto",
- "\t} ifelse",
- "\tlastday -1 ndays start 1 add add",
- "\t{",
- "\t\t/day exch def",
- "\t\tgsave",
- "\t\t.9 setgray",
- "\t\t100 0 rlineto ",
- "\t\t0 -80 rlineto",
- "\t\t-100 0 rlineto",
- "\t\tclosepath fill",
- "\t\tgrestore",
- "\t\tday 7 mod 1 eq",
- "\t\t{",
- "\t\t\t600 -365 80 add moveto",
- "\t\t}",
- "\t\t{",
- "\t\t\t-100 0 rmoveto",
- "\t\t} ifelse",
- "\t} for",
- "} def",
- "/isleap {\t\t% is this a leap year?",
- "\tyear 4 mod 0 eq\t\t% multiple of 4",
- "\tyear 100 mod 0 ne \t% not century",
- "\tyear 1000 mod 0 eq or and\t% unless it's a millenia",
- "} def",
- "/days_month [ 31 28 31 30 31 30 31 31 30 31 30 31 ] def",
- "/ndays {\t\t% number of days in this month",
- "\tdays_month month 1 sub get",
- "\tmonth 2 eq\t% Feb",
- "\tisleap and",
- "\t{",
- "\t\t1 add",
- "\t} if",
- "} def",
- "/startday {\t\t% starting day-of-week for this month",
- "\t/off year 2000 sub def\t% offset from start of epoch",
- "\toff",
- "\toff 4 idiv add\t\t% number of leap years",
- "\toff 100 idiv sub\t% number of centuries",
- "\toff 1000 idiv add\t% number of millenia",
- "\t6 add 7 mod 7 add \t% offset from Jan 1 2000",
- "\t/off exch def",
- "\t1 1 month 1 sub {",
- "\t\t/idx exch def",
- "\t\tdays_month idx 1 sub get",
- "\t\tidx 2 eq",
- "\t\tisleap and",
- "\t\t{",
- "\t\t\t1 add",
- "\t\t} if",
- "\t\t/off exch off add def",
- "\t} for",
- "\toff 7 mod\t\t% 0--Sunday, 1--monday, etc.",
- "} def",
- "/center {\t\t% center string in given width",
- "\t/width exch def",
- "\t/str exch def width str ",
- "\tstringwidth pop sub 2 div 0 rmoveto str show",
- "} def",
- "/calendar",
- "{",
- "\ttitlefont findfont 48 scalefont setfont",
- "\t0 60 moveto",
- "\t/month_name month_names month 1 sub get def",
- "\tmonth_name show",
- "\t/yearstring year 10 string cvs def",
- "\t700 yearstring stringwidth pop sub 60 moveto",
- "\tyearstring show",
- "\t0 0 moveto",
- "\tdrawnums",
- "\t0 0 moveto",
- "\tdrawfill",
- "\t0 0 moveto",
- "\tdrawgrid",
- "} def",
- "/daytext {",
- "\t/Helvetica-Narrow findfont 6 scalefont setfont",
- "\t/mytext\texch def /myday exch def",
- "\tstartday myday 1 sub add dup 7 mod 100 mul 5 add % gives column",
- "\texch 7 idiv -80 mul % gives row",
- "\tdup /ypos exch def moveto",
- "\t/LM currentpoint pop def /RM LM 95 add def",
- " mytext { dup (.p) eq { crlf pop} {prstr ( ) show} ifelse } forall",
- "} def",
- "/crlf {",
- " ypos 8 sub /ypos exch def LM ypos moveto",
- "} def",
- "/prstr {",
- " dup stringwidth pop currentpoint pop",
- " add RM gt {crlf} if show",
- "} def",
- "/printmonth {",
- "\t90 rotate",
- "\t50 -120 translate",
- "\t/submonth 0 def",
- "\tcalendar",
- "\tmonth 1 sub 0 eq",
- "\t{",
- "\t\t/lmonth 12 def",
- "\t\t/lyear year 1 sub def",
- "\t}",
- "\t{",
- "\t\t/lmonth month 1 sub def",
- "\t\t/lyear year def",
- "\t} ifelse",
- "\tmonth 1 add 13 eq",
- "\t{",
- "\t\t/nmonth 1 def",
- "\t\t/nyear year 1 add def",
- "\t} ",
- "\t{",
- "\t\t/nmonth month 1 add def",
- "\t\t/nyear year def",
- "\t} ifelse",
- "\t/savemonth month def",
- "\t/saveyear year def",
- "\t/submonth 1 def",
- "\t/year lyear def",
- "\t/month lmonth def",
- "\tgsave",
- "\t500 -365 translate",
- "\tgsave",
- "\t.138 .138 scale",
- "\t10 -120 translate",
- "\tcalendar",
- "\tgrestore",
- "\t/submonth 1 def",
- "\t/year nyear def",
- "\t/month nmonth def",
- "\t100 0 translate",
- "\tgsave",
- "\t.138 .138 scale",
- "\t10 -120 translate",
- "\tcalendar",
- "\tgrestore",
- "\t/month savemonth def",
- "\t/year saveyear def",
- "\t/submonth 0 def",
- "\tgrestore",
- "} def",
- (char *)0,
- };
-
- print_month(fp)
- FILE *fp;
- {
- char **ap;
- int i;
-
- /*
- * Write out PostScript prolog
- */
- for (ap = pheader; *ap; ap++)
- fprintf(fp, "%s\n", *ap);
-
- /*
- * Do the calendar
- */
- fprintf(fp, "/year %d def\n", current.tm_year+1900);
- fprintf(fp, "/month %d def\n", current.tm_mon+1);
- fprintf(fp, "printmonth\n");
-
- First = current;
- current.tm_mday = 1;
- for (i=0; i<monthlength(current.tm_mon); i++) {
- fix_current_day();
- get_day_appts();
- print_mday(fp);
- current.tm_mday++;
- }
- current = First;
-
- /*
- * Write out PostScript postlog
- */
- fprintf(fp, "showpage\n");
- }
-
- print_mday(fp)
- FILE *fp;
- {
- int slotno, did_one=0;
- struct appt_entry *aptr, *optr;
-
- fprintf(fp, "%d [ \n", current.tm_mday);
- for (slotno=0; slotno<N_SLOTS; slotno++) {
- /* any appts in this timeslot? */
- if (slots[slotno].first) {
- /* get printable string from each appt */
- for (aptr=slots[slotno].first; aptr;) {
- if (did_one)
- fprintf(fp, "(.p)\n");
- fprintf(fp, "(%s)\n", format_appt_nd(aptr));
- did_one = 1;
- /* free up memory used */
- optr = aptr;
- aptr = aptr->next;
- free(optr);
- }
- }
- }
- fprintf(fp, " ] daytext\n");
- }
- #endif /* NO_PRINTER */
-