home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hall of Fame
/
HallofFameCDROM.cdr
/
3x400
/
cpyform.lzh
/
CPYFORM.EXE
/
arc
/
FCFC.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1987-06-03
|
4KB
|
167 lines
Program First_Character_File_Control;
{
3.11 87-06-03 Handle blank lines correctly !
3.10 87-04-13 Add total file size and characters processed display;
Test for file existence;
Create output file as *.prn if not equal to input file;
}
Const
NL = #13#10;
CR = #13;
LF = #10;
FF = #12;
Type
Str255 = String[255];
Var
Ch : Char;
OutName,
OutLine,
Line : Str255;
Line_Len : Byte Absolute Line;
File_Size,
Line_In,
Char_In,
Line_Out,
Char_Out : Real;
Disp_Idx,
X : Integer;
SizeOpen : File of Byte;
Inp : Text[4096];
Out : Text[7168];
Err : Text;
Procedure CTLASA( Ch : Char );
Begin;
Case Ch
Of
' ': { 1 Line }
Begin;
Write( Out, NL:2 );
Char_Out := Char_Out + 2.0;
Line_Out := Line_Out + 1.0;
End;
'0': { 2 Lines }
Begin;
Write( Out, NL:2, NL:2 );
Char_Out := Char_Out + 4.0;
Line_Out := Line_Out + 2.0;
End;
'-': { 3 lines }
Begin;
Write( Out, NL:2, NL:2, NL:2 );
Char_Out := Char_Out + 6.0;
Line_Out := Line_Out + 3.0;
End;
'1': { Form Feed - Line added ! }
Begin;
Write( Out, NL:2, FF:1 );
Char_Out := Char_Out + 3.0;
Line_Out := Line_Out + 1.0;
End;
'+': { NO SPACING - Cr ONLY }
Begin;
Write( Out, CR:1 );
Char_Out := Char_Out + 1.0;
End;
Else
Begin;
{ nothing ! } ;
End;
End;
End; { CTLASA }
Begin;
Disp_Idx := 9;
Assign(Err,'ERR:'); { MSDOS Handle #2 }
Rewrite( Err );
Writeln(Err);
Writeln(Err,'First Character File Control V/M 3.10 87-04-13 PRW');
Writeln(Err);
If (ParamCount < 1) or (ParamStr(1) = '?') Then
Begin;
Writeln(Err,'Usage format: FCFC infile [outfile]');
Writeln(Err,' -- Input file name required.');
WriteLn(Err,' Output file will be input name with ".PRN" ending.');
Writeln(Err,' -- Output file may be "PRN" to output to printer.');
Halt;
End;
Line := ParamStr(1);
If (ParamCount = 1) Then
Begin;
X := Pos('.',Line);
If X > 0 Then OutName := Copy(Line,1,X-1) + '.PRN'
Else OutName := Line + '.PRN';
End
Else
OutName := ParamStr(2);
Assign(SizeOpen, Line);
{$I-}
Reset( SizeOpen );
{$I+}
If IOresult <> 0 Then
Begin;
Writeln(Err,'File "'+Line+'" not found !');
Writeln(err);
Halt;
End;
File_Size := LongFileSize(SizeOpen);
Close( SizeOpen );
Assign(Inp,Line);
Reset( Inp );
Assign(Out,OutName);
Rewrite( Out );
Writeln(Err,'Input = "',Line,'" Output = "',OutName,'"',NL);
Char_In := 1.0; { EOF Character !! }
Line_In := 0.0;
Char_Out := 0.0;
Line_Out := 0.0;
Write(Err,CR,Char_In:8:0,' Processed of',File_Size:8:0,' Characters.');
While Not EOF( Inp ) Do
Begin;
ReadLn ( Inp, Line );
Char_In := Char_In + Line_Len + 2.0;
Line_In := Line_In + 1.0;
Case Line_Len
Of
0:
Begin;
CTLASA(' '); { Space 1 line }
End;
1:
Begin;
CTLASA( Line[1] );
End;
Else
Begin;
CTLASA ( Line[1] );
X := Pred(Line_Len);
Move (Line[2],Outline[1],X);
OutLine[0] := Char(X);
Write( Out, OutLine );
Char_Out := Char_Out + X;
End;
End;
Disp_Idx := Succ(Disp_Idx);
If Disp_Idx = 10 Then
Begin;
Disp_Idx := 1;
Write(Err,CR,Char_In:8:0);
End;
End;
Write(Err,CR,Char_In:8:0);
CTLASA ('1'); { New Page }
Close ( Out );
Close ( Inp );
Writeln(Err,NL:2);
Writeln(Err,'Input: ',Char_In:8:0 ,' Char',Line_In:8:0 ,' Lines');
Writeln(Err,'Output: ',Char_Out:8:0,' Char',Line_Out:8:0,' Lines');
Writeln(Err);
Flush(Err);
End.