home *** CD-ROM | disk | FTP | other *** search
- Program Calendar;
- {$C-}
-
- Type TWeek = Array[0..6] of Byte;
- TMonth = Array[1..6] of TWeek;
- TYear = Array[1..12] of TMonth;
-
- MonthArray = Array[1..12] of String[9];
-
- String3 = String[3];
- String4 = String[4];
- String5 = String[5];
- String65 = String[65];
- String255 = String[255];
-
- Const
-
- MonthName : MonthArray =('January','February','March','April',
- 'May','June','July','August','September','October','November','December');
-
- Var SYSLST : Text;
- Table : TYear;
-
- Type WriteBigParam = String[11];
- PrintBigParam = String[22];
-
- Fontarray = Array[33..95] of Array[1..7] of Byte;
-
- Const
-
- FontTable : Fontarray = ((04,04,04,04,00,00,04),
- (10,10,10,00,00,00,00),
- (10,10,31,10,31,10,10),
- (04,15,20,14,05,30,04),
- (25,25,02,04,08,19,19),
- (04,10,10,12,21,18,11),
- (02,04,08,00,00,00,00),
- (02,04,08,08,08,04,02),
- (08,04,02,02,02,04,08),
- (00,04,21,14,21,04,00),
- (00,04,04,31,04,04,00),
- (00,00,00,00,08,08,16),
- (00,00,00,31,00,00,00),
- (00,00,00,00,00,24,24),
- (01,01,02,04,08,16,16),
- (14,17,17,17,17,17,14),
- (04,12,20,04,04,04,31),
- (14,17,01,02,12,16,31),
- (30,01,02,04,02,01,30),
- (02,06,10,18,31,02,02),
- (31,16,30,01,01,17,14),
- (07,08,16,30,17,17,14),
- (31,01,02,04,08,08,08),
- (14,17,17,14,17,17,14),
- (14,17,17,15,01,02,28),
- (00,00,04,00,00,00,04),
- (00,00,08,00,08,08,16),
- (03,04,08,16,08,04,03),
- (00,00,31,00,31,00,00),
- (24,04,02,01,02,04,24),
- (14,17,01,02,04,00,04),
- (14,17,23,21,23,16,14),
- (14,17,17,31,17,17,17),
- (30,17,17,30,17,17,30),
- (14,17,16,16,16,17,14),
- (28,18,17,17,17,18,28),
- (31,16,16,30,16,16,31),
- (31,16,16,30,16,16,16),
- (14,17,16,19,17,17,15),
- (17,17,17,31,17,17,17),
- (14,04,04,04,04,04,14),
- (07,02,02,02,02,18,12),
- (17,18,20,24,20,18,17),
- (16,16,16,16,16,16,31),
- (17,27,21,21,17,17,17),
- (17,25,25,21,19,19,17),
- (14,17,17,17,17,17,14),
- (30,17,17,30,16,16,16),
- (14,17,17,17,21,18,13),
- (30,17,17,30,20,18,17),
- (15,16,16,13,01,01,30),
- (31,04,04,04,04,04,04),
- (17,17,17,17,17,17,14),
- (17,17,17,10,10,04,04),
- (17,17,17,21,21,27,17),
- (17,17,10,04,10,17,17),
- (17,17,17,14,04,04,04),
- (31,01,02,04,08,16,31),
- (28,16,16,16,16,16,28),
- (16,16,08,04,02,01,01),
- (03,01,01,01,01,01,03),
- (14,17,00,00,00,00,00),
- (00,00,00,00,00,00,31));
-
- Procedure WriteBig(Input : WriteBigParam);
- Var a,b,c,d :Byte;
- Begin
- for a:=1 to 7 Do
- Begin
- for b:=1 to Length(input) Do
- Begin
- c:=Ord(Input[b]);
- if c>95 Then c:=c-32;
- for d:=0 to 4 Do
- If (FontTable[c,a] and (16 shr d)) <> 0 Then
- Write(chr(c)) Else Write(' ');
- Write(' ');
- End;
- Writeln
- End
- End;
-
- Procedure PrintBig(Input : PrintBigParam);
- Var a,b,c,d :Byte;
- Begin
- for a:=1 to 7 Do
- Begin
- for b:=1 to Length(input) Do
- Begin
- c:=Ord(Input[b]);
- if c>95 Then c:=c-32;
- for d:=0 to 4 Do
- If (FontTable[c,a] and (16 shr d)) <> 0 Then
- Write(LST,chr(c)) Else Write(LST,' ');
- Write(LST,' ');
- End;
- Writeln
- End
- End;
-
- Type BuildBigParam=String[5];
-
- Function BuildBig(ch : Char; l : Byte) : BuildBigParam;
- Var c,d : Byte;
- x : BuildBigParam;
- Begin
- x:='';
- c:=Ord(ch);
- if c>95 Then c:=c-32;
- for d:=0 to 4 Do
- If (FontTable[c,l] and (16 shr d))<>0 Then x:=x+chr(c) Else x:=x+' ';
- BuildBig:=x
- End;
-
- Function LeapYear(Year:Integer):Byte;
- Begin
- If (((Year Mod 400)=0) Or (((Year Mod 4)=0) And ((Year Mod 100)<>0))) Then
- LeapYear:=1 Else LeapYear:=0;
- End;
-
- Function DayOfYear(Year, Month, Day : Integer) : Integer;
- Begin
- DayOfYear:=Trunc(Int(3055.0*(Month+2.0)/100.0)
- -Int((Month+10.0)/13.0)*2-91
- +(LeapYear(Year)*Int((Month+10.0)/13.0)
- +Day));
- End;
-
- Function RealMod(x:Real;y:Integer):Integer; {-------------------------}
- Begin {Turbo MOD operator only }
- RealMod:=Trunc(x-Int(x/y)*y+0.5); {works with Integer values}
- End; { This is same operation }
- {For real argument. }
- {-------------------------}
-
- Function RealDay(Year,Month,Day : Integer) : Real;
- Begin
- RealDay:=DayOfYear(Year,Month,Day)
- +((Year-1)*365.0)
- +Int((Year-1)/4)
- -Int((Year-1)/100)
- +Int((Year-1)/400);
- End;
-
- Function DayOfWeek(Year,Month,Day : Integer) : Integer;
- Begin {0 is Sunday}
- DayOfWeek:=RealMod(RealDay(Year,Month,Day),7)
- End;
-
- Procedure GetMonthDay(Year, DayOfYear : Integer; Var Month,Day : Integer);
- Var
- Temp : Integer;
- Leap : Byte;
- Begin
- Leap:=LeapYear(Year);
- Temp:=Trunc(DayOfYear+Int((305+DayOfYear-Leap)/365)*(2-Leap));
- Month:=Trunc(Int(((Temp+91.0)*100.0)/3055.0)-2.0);
- Day:=Trunc(Temp+30.0-Int((Month*3056.0)/100.0));
- End;
-
- Function DupString(Str:String255; Size: Integer) : String255;
- Var s: String255;
- x: Byte;
- Begin
- s:='';
- Repeat s:=s+Str Until Length(s) >= Size;
- DupString := Copy(s,1,Size)
- End;
-
- Function RightString(Str: String255; Size: Byte) : String255;
- Begin
- If Length(Str)>Size Then
- RightString:=Copy(Str,1+Length(Str)-Size,Size)
- Else
- RightString:=DupString(' ',Size-Length(Str))+Str
- End;
-
- Function Center(s : String255; size : Byte) : String255 ;
- Var x : integer;
- Begin
- x:=size-Length(s);
- x:=trunc(x/2);
- Center:=DupString(' ',x)+s+DupString(' ',size-Length(s)-x);
- End;
-
- Procedure BuildCalendar(Year:Integer);
- Var x,Month,Week,Day : Integer;
- Begin
- FillChar(Table,504,0);
- For Month:=1 to 12 Do
- Begin
- Day:=DayOfWeek(Year,Month,1);
- Week:=1;
- For x:=1 to DayOfYear(Year,Month+1,1) - DayOfYear(Year,Month,1) Do
- Begin
- Table[Month,Week,Day]:=x;
- Day:=(Day+1) Mod 7;
- If Day=0 Then Week:=Succ(Week);
- End;
- End;
- End;
-
- Procedure PrintCalendar(Year : Integer; up:Byte);
- Var x,Month,Week,Day : Integer;
- yname : String4;
- Begin
- Month:=1;
- Str(Year:4,yname);
- Repeat
- For x:= 0 to Up-1 Do
- Write (SYSLST,Center(MonthName[Month+x]+' '+yname,29),' ');
- Writeln(SYSLST);
- For x:= 0 to Up-1 Do Write(SYSLST,' Sun Mon Tue Wed Thu Fri Sat ');
- Writeln(SYSLST);
- Writeln(SYSLST);
- For week:=1 to 6 Do
- Begin
- For x:=0 to Up-1 Do
- Begin
- For day:=0 to 6 Do
- If Table[Month+x,week,day]=0 then Write(SYSLST,' ')
- Else Write(SYSLST,Table[Month+x,week,day]:4);
- Write(SYSLST,' ');
- End;
- Writeln(SYSLST);
- End;
- Month:=Month+Up;
- Writeln(SYSLST);
- Until Month>12;
- Writeln(SYSLST,#12); {Top of Page}
- End;
-
- {------------Procedures for Block Character Calendar------------------------}
-
- Procedure PrintHeader(Year: Integer; Month:Byte);
- Var mname,prtstr : string255;
- yname : String4;
- x,line : Byte;
- Begin
- mname:=MonthName[Month];
- str(Year:4,yname);
- mname:=mname+' '+yname;
- for line:=1 to 7 Do
- Begin
- prtstr:=BuildBig(mname[1],line);
- for x:=2 to Length(mname) Do
- Begin
- prtstr:=prtstr+' '+BuildBig(mname[x],line);
- End;
- Writeln(SYSLST,Center(prtstr,127));
- End
- End;
-
- Procedure PrintDividerLine;
- Begin
- Write(SYSLST,'|');
- Writeln(SYSLST,DupString('-----------------|',126));
- End;
-
- Procedure PrintDayNames;
- Begin
- Write (SYSLST,'| Sunday ');
- Write (SYSLST,'| Monday ');
- Write (SYSLST,'| Tuesday ');
- Write (SYSLST,'| Wednesday ');
- Write (SYSLST,'| Thursday ');
- Write (SYSLST,'| Friday ');
- Writeln(SYSLST,'| Saturday |');
- End;
-
- Function BuildBigNumber(Num, line : Byte) : String255;
- Var b : Byte;
- x : String5;
- y : String255;
- Begin
- If Num=0 Then y:='' Else
- Begin
- str(Num:5,x);
- Repeat if x[1]=' ' then delete(x,1,1); until x[1]<>' ';
- y:=BuildBig(x[1],line);
- For b:=2 to length(x) Do y:=y+' '+BuildBig(x[b],line);
- End;
- BuildBigNumber:=y
- End;
-
- Function MkStr(n : Integer) :String3;
- Var s : String3;
- Begin
- Str(n:3,s);
- If n < 10 Then MkStr:=s[3] Else
- If n < 100 Then MkStr:=s[2]+s[3] Else
- MkStr:=s;
- End;
-
- Procedure PrintaWeek(Year : Integer; Month,week : Byte);
- Var x,line: Byte;
- Begin
- for line:=1 to 7 Do
- Begin
- Write(SYSLST,'|');
- for x:=0 to 6 Do
- Write(SYSLST,Center(BuildBigNumber(Table[Month,week,x],line),17),'|');
- Writeln(SYSLST);
- End;
-
- Write(SYSLST,'|');
- For x:=0 to 6 Do
- If Table[Month,Week,x]=0 Then Write(SYSLST,Center('',17),'|')
- Else
- Write(SYSLST,
- Center('('+MkStr(DayOfYear(Year,Month,Table[Month,Week,x]))+')',17),'|');
-
- Writeln(SYSLST)
- End;
-
- Procedure PrintMonth(Year,Month:Integer);
- Var x : Byte;
- Begin
- PrintHeader(Year,month);
- PrintDividerLine;
- PrintDayNames;
- PrintDividerLine;
- For x:=1 to 6 Do
- Begin
- If Table[Month,x,0]<>Table[Month,x,6] Then
- Begin
- PrintaWeek(Year,Month,x);
- PrintDividerLine
- End
- End;
- Writeln(SYSLST,#12);
- end;
-
- Procedure PrintYear(Year : Integer;Month,Format : Byte);
- Var x : Integer;
- Begin
- BuildCalendar(Year);
-
- If Format>0 Then PrintCalendar(Year,Format) Else
- If Month=0 Then For x:=1 to 12 Do PrintMonth(Year,x)
- Else PrintMonth(Year,Month);
- End;
-
- Procedure Quit;
- Begin
- Close(SYSLST);
- HALT
- End;
-
- Var OutputFile : String65;
-
- Procedure NewFile;
- Var x: Integer;
- Begin
- Close(SYSLST);
- Assign(SYSLST,OutputFile);
- {$I-}
- ReWrite(SYSLST);
- {$I+}
- x:=IOResult;
- If x<>0 Then
- Begin
- Writeln('Filename=',OutputFile,' File Error=',x);
- Halt
- End;
- End;
-
- {---------------- Main Program Block --------------}
-
- Var ErrCode,Format,x,y,Month,Week,Day,Year : Integer;
- c : String255;
-
- Begin
-
- ClrSCr;
- WriteBig(' Calendar ');
- Writeln;
- Writeln;
-
- {Default Parameter Values}
-
- OutputFile:='OUT:'; Year:=1985; Month:=0; Format:=2;
-
- Assign(SYSLST,OutputFile);
- ReWrite(SYSLST);
-
- If ParamCount=0 then Begin Writeln('No parameters supplied - See CALNDR.DOC');
- HALT End;
-
- For x:=1 To ParamCount Do
- Begin
- c:=ParamStr(x);
- Writeln('Processing Param # ',x,' -->',c,'<--');
- Case UpCase(c[1]) of
-
- 'M' : Begin
- Delete(c,1,1);
- Val(c,Month,ErrCode);
- If ErrCode<>0 Then
- Begin
- Writeln('Invalid Month -->',c,'<');
- Quit
- End
- Else If (Month>12) or (Month<0) Then
- Begin
- Writeln('Invalid Month (Must be 0 thru 12)');
- Quit
- End;
- End;
-
- 'F' : Begin
- Delete(c,1,1);
- Val(c,Format,ErrCode);
- If ErrCode<>0 Then
- Begin
- Writeln('Invalid Format Param -->',c,'<');
- Quit
- End
- Else If (Format>4) or (Format<0) Then
- Begin
- Writeln('Invalid Format Param (Must be 0 thru 4)');
- Quit
- End;
- End;
-
- 'Y' : Begin
- Delete(c,1,1);
- Val(c,Year,ErrCode);
- If ErrCode<>0 Then
- Begin
- Writeln('Invalid Year -->',c,'<');
- Quit
- End
- Else If Year < 0 Then
- Begin
- Writeln('Invalid Year -->',c,'<');
- Quit
- End;
- PrintYear(Year,Month,Format);
- End;
-
- 'P' : Begin
- Delete(c,1,1);
- y:=1;
- Repeat
- If c[y]='^' Then
- Begin
- Write(SYSLST,Chr(Byte(c[y+1])-$40));
- y:=succ(y)
- End
- Else
- Write(SYSLST,c[y]);
- y:=succ(y);
- Until y>Length(c);
- End;
-
- 'O' : Begin
- Delete(c,1,1);
- OutputFile:=c;
- NewFile
- End;
-
- Else Writeln('Unknown Param Type -->',c,'<-- Ignored');
-
- End; {--- CASE ---}
- End;
-
- Close(SYSLST);
-
- End.