#!/bin/sh -
# 
# gpscal Version 1.3.0 - March 10 1995
# gpscal Version 1.3.1 - 2015-10-11 T.T.
#
# Newsgroups: soc.culture.greek
# From: dimitri@cui.unige.ch (Dimitri Konstantas)
# Subject: Re: Postscript calendar (gpscal)
# Organization: University of Geneva - CUI
# Date: Fri, 12 Jan 1996 11:49:32 GMT
# 
# There is a newer version of gpscal (1.2) which allows direct printing of a
# complete year, inclusion of "special days" (birthdays for example of
# friends) etc. (for this last feature you must edit the file itself - I will
# change some day to take input either from the command line or an external
# file).
# 
# make sure this file is executable: chmod a+x gpscal
#
# gpscal -h		help
# gpscal -g -e 3 1996	print March 1996 with Greek moving holidays
# gpscal -g -e -y 1997	print the whole year
# gpscal -t > cal	redirect output to "cal" instead of printer
# 
# PostScript program to print calendars.
# Doesn't deal well with September 1752 or before.
# Includes Greek Orthodox holidays (stable and Easter based)
# 
# Author:
# Dimitri Konstantas CUI Geneva, Oct 1993.  (dimitri@cui.unige.ch)
#
# This calendar is a modification of pscal from Pipeline Associates, Inc.
# Information for Greek Holidays was extracted from Manolis M. Tsangaris gcal
#
# set ENVAR to PRINTER for BSD spooler, LPDEST for USG spooler
#
# Note: Oi giortes : Ag. Georgiou (23/4), Euagelistou Markou (25/4),
#	Agias Eirhnhs (5/5) einei imi-kinities: An pesoun prin apo
#	to pasxa metaferontai ws exis:
#		Agiou Georgiou:  thn deytera tou Pasxa
#		Euagg. Markou:   thn triti tou Pasxa (+2)
#		Agias Eirhnhs: Tin teterti tou Pasxa (+3) (not confirmed)
#
# ----------------------------------------------------------------------
help(){
echo "HOW TO PRINT THE CALENDAR."
echo "Gpscal allows you to print a year calendar or isolated months."
echo "In order to print February 1994, for example,"
echo "you give"
echo "	gpscal 2 1994"
echo "if the currect year IS 1994 you can simply give"
echo "	gpscal 2"
echo "This will print a simple English calendar on the (postscript)"
echo "printer PostScript. If your printer has a different name then"
echo "you can either use "
echo "	gpscal -P lw3 2 1994"
echo "In order to print a Greek calendar (that is days and months are in"
echo "Greek) you give"
echo "	gpscal -g 2 1994"
echo "If in addition you want the Greek holidays to be printed (both"
echo "stable and easter-dependent) you give"
echo "	gpscal -g -e 2 1994"
echo "This will print a greek calendar with the major Greek holidays,"
echo "all written in Greek."
echo "Omitting the -g option (gpscal -e 2 1994) will print an English"
echo "calendar (names of months and weekdays in English) with the Greek"
echo "holidays (in Greek always)"
echo "For printing the complete year you must use the option -y"
echo "	gpscal -y 1994"
echo "If you wish to include in the calendar the birthdays of friends"	
echo "you must use the -b option."
echo "If you have problems or questions feel free to contact me :-)"
echo "						dimitri@cui.unige.ch"
}

ENVAR=PRINTER

PATH=/usr/ucb:/bin:/usr/bin

eval test \$$ENVAR || eval $ENVAR=PostScript
export $ENVAR

VERSION="gpscal Version 1.2.0 - December 15 1994"
USAGE="Usage: pscal [ -Rrt ] [-b] [-g] [-e] [-P printer] [ -F hfont ] [ -f font ] [-v] [-help] [-y year | month [ year ] ]"

TFONT=Times-Bold
DFONT=Helvetica-Bold
DTFONT=Symbol
DTFONT2=Times-Roman
GREEKHOLIDAYS=0
GREEK=0
ALLYEAR=0
BIRTHDAYS=0

ROTATE=90

LPR="lpr"

while test $# != 0
do
    case $1 in
	-P) test $# -lt 2 && { echo "$USAGE" 1>&2; exit 1; }
	    eval $ENVAR="$2"; shift 2;;
	-P*) eval $ENVAR=`echo $1 | sed -n 1s/-.//p`; 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;;
	-b) BIRTHDAYS=1; shift 1 ;;
	-t) LPR=cat; shift 1;;
	-r) ROTATE=90; shift 1;;
	-R) ROTATE=0; shift 1;;
	-e) GREEKHOLIDAYS=1 ; shift 1 ;;
	-g) GREEK=1 ; shift 1 ;;
	-v) echo "$VERSION" 1>&2 ; exit ;;
	-h) help 1>&2 ; exit ;;
	-help) help 1>&2 ; exit ;;
	-y) test $# -lt 2 && { echo "$USAGE" 1>&2; exit 1; }
	    ALLYEAR=1; YEAR=$2 ; shift 2 ;;
	--|-) break;;
	-*) echo "$USAGE" 1>&2; exit 1;;
	*) break
    esac
done

if [ $ALLYEAR -eq 0 ] ; then
  test $# -gt 2 && { echo "$USAGE" 1>&2; exit 1; }
  case $# in
    0)	set `date`; case $# in 7) YEAR=$7;; 6) YEAR=$6;; esac
	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`; case $# in 7) YEAR=$7;; 6) YEAR=$6;; esac ;;
    2)	MONTH=$1; YEAR=$2;;
    *) echo "$USAGE" 1>&2; exit 1;; 
  esac
else
	test $# -gt 0 && { echo "$USAGE" 1>&2; exit 1; }
fi

main() {

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

 if [ $ALLYEAR -eq 0 ]; then	
	doit
 else
	for MONTH in 1 2 3 4 5 6 7 8 9 10 11 12
	do
		doit
	done
 fi
}

doit() {
	echo "Printing callendar for $MONTH - $YEAR" 1>&2
$LPR <<END-OF-CALENDAR
%!
% PostScript program to draw calendar
% gpscal Version 1.2.0
%
% PostScript program to print calendars.
% Doesn't deal well with September 1752 or before.
% Includes Greek Orthodox holidays (stable and Easter based)
% 
% Author:
% Dimitri Konstantas CUI Geneva, Oct 1993.  (dimitri@cui.unige.ch)
%
% This calendar is a modification of pscal from Pipeline Associates, Inc.
% Information for Greek Holidays was extracted from Manolis M. Tsangaris gcal
% 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.
% NOTE: Year 1923 was a special one for Greece : The new calendar was
% introduced and 13 days were added. Unfortunatelly this is not visible in
% this version of the calendar.

/month $MONTH def
/year $YEAR def
/titlefont /$TFONT def
/dayfont /$DFONT def
/daytextfont /$DTFONT def
/daytextfont2 /$DTFONT2 def
/pageRotation $ROTATE def
/greekHolidays $GREEKHOLIDAYS def
/inGreek $GREEK def
/birthDays $BIRTHDAYS 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

/gmonth_names
[ (IanouarioV) (FebrouarioV) (MartioV) (AprilioV) (MaioV) (IounioV) (IoulioV)
(AugoustoV) (SeptembrioV) (OktwbrioV) (NoembrioV) (DekembrioV) ]
def 

/gday_names
[ (Kuriakh) (Deutera) (Trith) (Tetarth) (Pempth) (Paraskeuh) (Sabbato) ]
def


/setRows {
	/fday startday def
	/mdays ndays def
	fday 6 eq month 2 ne and
	fday 5 eq mdays 31 ge and
	or
% layout parameters - you can change these, but things may not look nice
	{ /rows 6 def }
	{/rows 5 def } ifelse
	/subrows 6 def 
	/dayheight 475 rows idiv def
	/daywidth 100 def
} def

/titlefontsize 48 def
/weekdayfontsize 10 def
/datefontsize 30 def
/daytextfontsize 6 def

/topgridmarg 35 def
/leftmarg 35 def
/daytopmarg 10 def
/dayleftmarg 5 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 400 mod 0 eq or and	% unless centuries multiple of 4
} def
/isnotleap {				% is this a leap year?
	year 4 mod 0 ne			% multiple of 4
	year 100 mod 0 eq 		% not century
	year 400 mod 0 ne and or	% unless centuries multiple of 4
} 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
/ndays {				% number of days in this month
	days_month month 1 sub get
	month 2 eq			% February
	isleap and
	{
		1 add
	} if
} def
/prtnum { 3 string cvs show } 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 400 idiv add		% number of leap centuries
	year 2000 gt isnotleap and { 1 add } if	% 2000 is leap, so we must count it
	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
/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 def
		}
		{
			/rowsused subrows def
		}
		ifelse
		1 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 eq
	{
		/lastday rows days_week mul 2 sub fillstart add def
		days_week 3 sub fillstart add daywidth mul
		topgridmarg dayheight rows mul sub
		% -440
		dayheight add rmoveto
	}
	{
		/lastday rows days_week mul def
		days_week 1 sub daywidth mul
		topgridmarg dayheight rows 1 sub mul sub
		% -440
		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
			topgridmarg dayheight rows 1 sub
			% submonth 0 eq { 1 sub} if
			mul sub
			% -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

	0 -5 moveto
	drawnums

	0 -5 moveto
	drawfill

	0 -5 moveto
	drawgrid
} def

/printmonth {
	pageRotation rotate
	50 -120 translate
	/submonth 0 def
	calendar
	month 1 add 13 eq
	{
		/lmonth 1 def
		/lyear year 1 add def
	}
	{
		/lmonth month 1 add def
		/lyear year def
	} ifelse
	month 2 add 13 eq
	{
		/nmonth 1 def
		/nyear year 1 add def
	} 
	{
		month 2 add 14 eq
		{
			/nmonth 2 def
			/nyear year 1 add def
		} 
		{
			/nmonth month 2 add def
			/nyear year def
		} ifelse
	} ifelse
gsave
	usefirst
	{
		0 45 translate
	}
	{
		days_week 2 sub daywidth mul dayheight 428 sub translate	
	} ifelse
	/savemonth month def
	/saveyear year def
	/submonth 1 def
	/year lyear def
	/month lmonth def
	gsave
	% .138 .138 scale
        .138 .138 scale
	12 -240 translate % 240 was 120
	/rows subrows def 
        calendar
	grestore
	/submonth 1 def
	/year nyear def
	/month nmonth def
	daywidth 0 translate
	gsave
	.138 .138  scale
	12 -240 translate
	calendar
	grestore
	/month savemonth def
	/year saveyear def
	/submonth 0 def
grestore
	%-600 350 translate
} def

%% Greek holidays extensions

% calculate the month and day of easter
/orthodoxEaster { % returns on the stack No of days from Jan 1 to Easter

	year 1 sub 19 mod 1 add 19 mul 15 add 30 mod
	% one item left on the stack (unadjasted days after 3rd of April)
	dup

	% is this year leap ?
	isleap { 1 } { 0 } ifelse
	% one item on the stack

	% calculate week day of the 1st of January op this year
	/savemonth month def
	/month 1 def
	startday
	/month savemonth def
	% one item on the stack (week day of Jan 1)

	90 add add add 3 add
	1 sub 7 mod 7 exch sub
	3 add add

	year 1923 le { 13 sub } if

	% now we have the days from 1st of April for easter
	% from January first they are
	90 isleap { 1 } { 0 } ifelse add add


} def

/printEasterHolidays { 
	% get start and end year days for the month
	/start 1 def
	0 1 month 2 sub { 
		/idx exch def
		days_month idx get
		idx 1 eq isleap and { 1 add } if
		/start exch start add def
	} for

	/end ndays start add 1 sub def

	% now which year day is the easter day?
	/EasterDay orthodoxEaster def

	% for each easter dependent holiday check if it is in the current month
	easterDays { doEasterDays } forall

} def

/doEasterDays {
	% on the stack we have : integer [ .. ]
	% make the easter relative day to year relative day
	exch EasterDay add
	dup 3 1 roll dup

	% is it the month ?
	start ge { end le { % it is !! print it!!
				% year-day to month-day
				exch start sub 1 add exch
				daytext1
			  }
			  { pop pop } ifelse
	} {pop pop pop} ifelse
} 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

/daytext1 { % print a day message using daytextfont
	    % it expectes as input (on the stack) a number (the day) and an
	    % array of text.
        daytextfont findfont daytextfontsize scalefont setfont
        /mytext exch def /myday exch def
        startday myday 1 sub add dup days_week mod 100 mul 5 add % gives column
        exch days_week idiv dayheight neg mul % gives row
        dup /ypos exch def moveto
        /LM currentpoint pop def /RM LM 95 add def
        mytext { dup (.p) eq { crlf pop} {prstr ( ) show} ifelse } forall
} def

/pheart { % print a little heart (for birthdays)
	currentfont
	/Symbol findfont daytextfontsize 3 add scalefont setfont
	(\251) show 
	setfont
} def

/pbirthday { % print a birthday message using daytextfont
	    % it expectes as input (on the stack) a number (the day) and an
	    % array of text.
	    % The (.l) directive in the text switches the text
	    % to Latin (daytextfont2) 
	    % The default font is Greek (daytextfont)
        /mytext exch def /myday exch def
        startday myday 1 sub add dup days_week mod 100 mul 5 add % gives column
        exch days_week idiv dayheight neg mul % gives row
        dup /ypos exch def moveto
        /LM currentpoint pop def /RM LM 95 add def
	pheart
        daytextfont findfont daytextfontsize 1 add scalefont setfont
        mytext { dup (.l) eq
		{daytextfont2 findfont daytextfontsize 1 add scalefont setfont }
        	{ dup (.p) eq { crlf pop pheart} {prstr ( ) show} ifelse }
		ifelse } forall
} def

/chooseLanguage {
	inGreek 1 eq {
		/day_names gday_names def
		/month_names gmonth_names def
		/titlefont /Symbol def
	} if
} def


% definition of the stable month holidays
/mput { put dup } def
/january 31 dict def
january dup
1 [ (Peritomh) (Cristou) (.p) (Megalou) (Basileiou) (.p) (Neo) (EtoV) ] mput
6 [ (Ta) (Agia) (Qeofaneia) ] mput
7 [ (Iwannou) (tou) (Prodromou) ] mput
9 [ (Eustratiou) ] mput
11 [ (Qeodosiou) ] mput
12 [ (TatianhV) ] mput
17 [ (Antwniou) (tou) (Megalou) ] mput
18 [ (Aqanasiou) (kai) (Kurillou) ] mput
20 [ (Euqumiou) ] mput
22 [ (Timoqeou) ] mput
25 [ (Grhgoriou) (Qeologou) ] mput
26 [ (XenofwntoV) ] mput
27 [ (Anakomidh) (Leiyanwn) (Iwannou) (Crusostomou) ] mput
30 [ (Twn) (Triwn) (Ierarcwn) ] mput
31 [(Kurou) (kai) (Iwannh) (twn) (Anargurwn) ]  mput
pop
/february 29 dict def
february dup
2 [ (Upapanth) (tou) (Kuriou) ] mput
4 [ (Isidwrou) ] mput
5 [ (AgaqhV) ] mput
6 [ (Fwtiou) (KwnstantinoupolewV) ] mput
9 [ (Nikhforou) ] mput
10 [ (CaralampouV) ] mput
11 [ (Blasiou) ] mput
19 [ (FiloqehV) ] mput
pop
/march 31 dict def
march dup
1 [ (EudokiaV) ] mput
13 [ (Nikhforou) ] mput
14 [ (Benediktou)] mput
17 [ (Alexiou) (tou) (Anqrwpou) (tou) (Qeou) ] mput
25 [ (EuaggelismoV) (thV) (Parqenou) (.p) (Enarxh) (thV) (EpanastashV) (1821) ] mput
30 [ (Iwannou) (thV) (KlimakoV) ] mput
pop
/april 30 dict def
april dup
2 [ (Titou) ] mput
6 [ (Eutuciou) ] mput
24 [ (Sabba) (tou) (Strathlatou) (.p) (Elisabet) (thV) (Qaumatourgou) ] mput
30 [ (Iakwbou) (Apostolou) ] mput
pop
/may 31 dict def
may dup
1 [ (Ieremiou,) (IsidwraV) (.p) (Ergatikh) (Eorth) ] mput
4 [ (PelagiaV) ] mput
6 [ (Serafeim) ] mput
8 [ (Iwannou) (tou) (Qeologou) ] mput
11 [ (Meqodiou) (kai) (Kurillou) ] mput
13 [ (GlukeriaV) ] mput
21 [ (Kwnstantinou) (kai) (ElenhV) (Isapostolwn) ] mput
24 [ (Sumewn) ] mput
29 [ (QeodosiaV) ] mput
pop
/june 30 dict def
june dup
8 [ (KalliophV) ] mput
11 [ (Barqolomaiou,) (Naqanahl) (kai) (Barnaba) (twn) (Apostolwn) ] mput
21 [ (AfrodithV) (kai) (Ioulianou) ] mput
29 [ (Petrou) (kai) (Paulou) ] mput
30 [ (H) (sunaxh) (twn) (Dwdeka) (Apostolwn) ] mput
pop
/july 31 dict def
july dup
1 [ (Kosma) (kai) (Damianou) ] mput
7 [ (KuriakhV) (MegolomarturoV) ] mput
11 [ (EufhmiaV) (kai) (OlgaV) ] mput
17 [ (MarinhV) (MegalomarturoV) ] mput
20 [ (Profhth) (Hlia) ] mput
22 [ (MarkellaV) ] mput
25 [ (KoimhsiV) (AgiaV) (AnnhV) ] mput
26 [ (ParaskeuhV) ] mput
27 [ (PantelehmonoV) ] mput
pop
/august 31 dict def
august dup
6 [ (Metamorfwsh) (tou) (SwthroV) ] mput
15 [ (H) (Koimhsh) (thV) (Qeotokou) ] mput
17 [ (MurwnoV,) (IoulianhV) (kai) (Kuprianou) ] mput
26 [ (Adrianou) (kai) (NataliaV) ] mput
29 [ (Apotomh) (KefalhV) (Prodromou) ] mput
30 [ (Alexandrou) ] mput
pop
/september 30 dict def
september dup
8 [ (To) (Geneqlion) (thV) (Qeotokou) ] mput
9 [ (Iwakeim) (kai) (AnnhV) ] mput
14 [ (Uywsh) (tou) (Timiou) (Staurou) ] mput
16 [ (EufhmiaV) ] mput
17 [ (SofiaV) (kai) (twn) (qugaterwn) (thV,) (.p) (PisthV,) (AgaphV) (kai) (ElpidaV) ] mput
18 [ (AriadnhV) ] mput
24 [ (QeklhV) (PrwtomarturoV) ] mput
25 [ (EufrosunhV) ] mput
26 [ (Metastash) (tou) (Euaggellistou) (Iwannh) ] mput
pop
/october 31 dict def
october dup
1 [ (Rwmanou) (tou) (Melwdou) ] mput
3 [ (Dionusiou) (tou) (Areopagitou) ] mput
6 [ (Qwma) (Apostolou) ] mput
7 [ (Sergiou) (kai) (Bakcou) ] mput
8 [ (PelagiaV) ] mput
9 [ (Iakwbou) (tou) (Alfaiou) ] mput
10 [ (Eulampiou) (kai) (EulampiaV) ] mput
11 [ (Filippou) (tou) (Diakonou) ] mput
12 [ (Andronikou) (kai) (AndromachV) ] mput
18 [ (Louka) (tou) (Euaggelistou) ] mput
20 [ (Gerasimou) (tou) (en) (Kefallhnia) ] mput
23 [ (Iakwbou) (tou) (Adelfoqeou) ] mput
26 [ (Dhmhtriou) (tou) (Muroblhtou) ] mput
28 [ (AgiaV) (SkephV) (.p) (To) (OCI) (tou) (1940) ] mput
pop
/november 30 dict def
november dup
1 [ (Kosma) (kai) (Damianou) ] mput
8 [ (Twn) (Taxiarcwn) (Micahl) (kai) (Gabrihl) ] mput
9 [ (Nektariou) (PentapolewV) ] mput
11 [ (Mhna) (.p) (BiktoroV) (kai) (Bikentiou) ] mput
13 [ (Iwannou) (tou) (Crusostomou) ] mput
14 [ (Filippou) (Apostolou) ] mput
16 [ (Matqaiou) (tou) (Euaggelistou) ] mput
21 [ (Ta) (Eisodia) (thV) (Qeotokou) ] mput
25 [ (AikaterinhV) (MegalomarturoV) ] mput
26 [ (Stulianou) ] mput
30 [ (Andrea) (tou) (Prwtoklhtou) ] mput
pop
/december 31 dict def
december dup
4 [ (BarbaraV) (MegalomarturoV) ] mput
5 [ (Sabba) (Hgiasmenou) ] mput
6 [ (Nikolaou) ] mput
9 [ (SullhyiV) (AgiaV) (AnnhV) ] mput
10 [ (Mhna) ] mput
12 [ (SpuridwnoV) ] mput
13 [ (Eugeniou,) (Eustratiou,) (Auxentiou,) (Orestou) (kai) (LoukiaV) ] mput
15 [ (Eleuqeriou) ] mput
17 [ (Dionusiou) (AiginhV) ] mput
19 [ (AglaiaV) ] mput
20 [ (Ignatiou) (Qeoforou) ] mput
21 [ (IoulianhV) (kai) (QemistokleouV) ] mput
22 [ (AnastasiaV) (thV) (FarmakolutriaV) ] mput
24 [ (EugeniaV) ] mput
25 [ (CRISTOUGENNA) ] mput
26 [ (Sunaxh) (thV) (Qeotokou) ] mput
27 [ (Stefanou) (tou) (PrwtomarturoV) ] mput
pop

% Here the stack contains the 12 month dictionaries.
% we pack them in an array
/stableMonths 12 array def
stableMonths astore
pop

% defintions of the Easter dependent holidays. At 0 we have easter
/easterDays 50 dict def
easterDays dup
-70 [ (Kuriakh) (tou) (Telwnou) (kai) (tou) (Farisaiou,) (Arch) (Triwdiou) ] mput
-63 [ (Kuriakh) (tou) (Aswtou) ] mput
-57 [ (Yucosabbato) ] mput
-56 [ (Kuriakh) (thV) (Apokrew) ] mput
-49 [ (Kuriakh) (thV) (TurinhV) ] mput
-48 [ (Kaqara) (Deutera) ] mput
-44 [ (A\262) (Cairetismoi) ] mput
-43 [ (To) (dia) (kollubwn) (qauma) (tou) (Agiou) (Qeodwrou) ] mput
-42 [ (Kuriakh) (A\262) (Nhsteiwn) (.p) (thV) (OrqodoxiaV) ] mput
-37 [ (B\262) (Cairetismoi) ] mput
-35 [ (Kuriakh) (B\262) (Nhsteiwn) ] mput
-30 [ (G\262) (Cairetismoi) ] mput
-28 [ (Kuriakh) (G\262) (Nhsteiwn) (.p) (thV) (StauroproskunhshV) ] mput
-23 [ (D\262) (Cairetismoi) ] mput
-21 [ (Kuriakh) (D\262) (Nhsteiwn) ] mput
-16 [ (AkaqistoV) (UmnoV) ] mput
-14 [ (Kuriakh) (E\262) (Nhsteiwn) ] mput
-8 [ (Anastash) (tou) (Lazarou) ] mput
-7 [ (Twn) (Baiwn) ] mput
-6 [ (Megalh) (Deutera) ] mput
-5 [ (Megalh) (Trith) ] mput
-4 [ (Megalh) (Tetarth) ] mput
-3 [ (Megalh) (Pempth) ] mput
-2 [ (Megalh) (Paraskeuh) ] mput
-1 [ (Megalo) (Sabbato) ] mput
0 [ (TO) (AGION) (PASCA) ] mput
% 1 [ (Diakainisimou) ] mput
5 [ (Zwodocou) (PhghV) ] mput
7 [ (Kuriakh) (tou) (Qwma) ] mput
14 [ (Kuriakh) (twn) (Muroforwn) ] mput
21 [ (Kuriakh) (tou) (Paralutou) ] mput
28 [ (Kuriakh) (thV) (SamareitidoV) ] mput
35 [ (Kuriakh) (tou) (Tuflou) ] mput
39 [ (ThV) (AnalhyewV) ] mput
42 [ (Kuriakh) (twn) (Agiwn) (Paterwn) ] mput
48 [ (Yucosabbato) ] mput
49 [ (Kuriakh) (thV) (PenthkosthV) ] mput
50 [ (Tou) (Agiou) (PneumatoV) ] mput
56 [ (Kuriakh) (twn) (Agiwn) (Pantwn) ] mput
pop

%-------------------- Birthdays -----------------------------------

/mput { put dup } def
/bjanuary 31 dict def
bjanuary dup
%% 1 [ (somebody's) (birthday) (1999) ] mput
pop
/bfebruary 29 dict def
bfebruary dup
%% 1 [ (somebody's) (birthday) (1999) ] mput
pop
/bmarch 31 dict def
bmarch dup
%% 1 [ (somebody's) (birthday) (1999) ] mput
pop
/bapril 30 dict def
bapril dup
%% 1 [ (somebody's) (birthday) (1999) ] mput
pop
/bmay 31 dict def
bmay dup
%% 1 [ (somebody's) (birthday) (1999) ] mput
pop
/bjune 30 dict def
bjune dup
%% 1 [ (somebody's) (birthday) (1999) ] mput
pop
/bjuly 31 dict def
bjuly dup
%% 1 [ (somebody's) (birthday) (1999) ] mput
pop
/baugust 31 dict def
baugust dup
%% 1 [ (somebody's) (birthday) (1999) ] mput
pop
/bseptember 30 dict def
bseptember dup
%% 1 [ (somebody's) (birthday) (1999) ] mput
pop
/boctober 31 dict def
boctober dup
%% 1 [ (somebody's) (birthday) (1999) ] mput
17 [ (DhmhtrhV) (KwnstantaV) (1958) ] mput
pop
/bnovember 30 dict def
bnovember dup
%% 1 [ (somebody's) (birthday) (1999) ] mput
pop
/bdecember 31 dict def
bdecember dup
%% 1 [ (somebody's) (birthday) (1999) ] mput
pop

% Here the stack contains the 12 month dictionaries.
% we pack them in an array
/birthlist 12 array def
birthlist astore
pop
%-- END -- END ------ Birthdays -----------------------------------

% Custom made handling of semi-movable selebrations.

/setSemiMovable {
	% get easterday 
	% calculate the year day of the three semimovable selebrations
	/off 0 def
	1 1 3 {
		/idx exch def
		days_month idx 1 sub get
		idx 2 eq
		isleap and
		{
			1 add
		} if
		/off exch off add def
	} for
	off 23 add /gewrgiou exch def
	off 25 add /markou exch def
	off 35 add /eirhnhs exch def
	orthodoxEaster /oeday exch def
	oeday eirhnhs ge { % Eirhnhs 
		easterDays dup
		3 [ (EirhnhV) (thV) (MegolomarturoV)] mput
		pop pop
		may dup
		5 [ (KornhliaV) ] mput
		pop pop
	}
	{
		may dup
		5 [ (EirhnhV) (thV) (MegolomarturoV) (.p) (KornhliaV) ] mput
		pop pop
	} ifelse
	oeday markou ge { % Markou
		easterDays dup
		2 [ (Markou) (Euaggelistou) ] mput 
		pop pop
	}
	{
		april dup
		25 [ (Markou) (Euaggelistou) ] mput 
		pop pop
	} ifelse
	oeday gewrgiou ge { % Gewrgiou
		easterDays dup
		1 [ (Diakainisimou) (.p) (Gewrgiou) (MegalomarturoV) ] mput
		pop pop
	}
	{
		easterDays dup
		1 [ (Diakainisimou) ] mput
		pop pop
		april dup
		23 [ (Gewrgiou) (MegalomarturoV) ] mput
		pop pop
	} ifelse
}  def

% end of defintions. Do it!!!

setRows
chooseLanguage
printmonth

greekHolidays 1 eq {
    % First set the semi-movable selebration
    setSemiMovable

    % Now print the stable holidays
    stableMonths month 1 sub get { daytext1 } forall

    % Print the Easter dependent holidays (at the botom of the day-box)
    0 datefontsize dayheight sub 6 add daytextfontsize add translate
    printEasterHolidays
} if

birthDays 1 eq {
    % Print the birthdays at the middle of the day-box)
        0 dayheight 2 div 12 sub translate
	birthlist month 1 sub get { pbirthday } forall
} if

showpage
END-OF-CALENDAR
}

main

exit

# ---=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# Dr. Dimitri Konstantas               | E-mail: dimitri@cui.unige.ch
# Centre Universitaire d'Informatique  | WWW   : http://cuiwww.unige.ch/~dimitri
# University of Geneva	 	     | Tel.  : +41 (22) 705 7664   
# 24 rue du General-Dufour	     | Tel.  : +41 (22) 705 7770 (secretariat)
# CH-1211 Geneva 4, SWITZERLAND	     | Fax   : +41 (22) 705 7780
# ---=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
