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;
-
-
- {$IWriteBig.INC}
-
- {$ICalFuncs.INC}
-
- {$IStrFuncs.INC}
-
- 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.