home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GEMini Atari
/
GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso
/
files
/
bbs
/
pibterm
/
pibt3sp1
/
kopen.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1985-10-04
|
9KB
|
206 lines
(*----------------------------------------------------------------------*)
(* Open_File --- Open file for use by Kermit protocol routines *)
(*----------------------------------------------------------------------*)
PROCEDURE Open_File( File_Mode : Kermit_File_Modes;
FileName : AnyStr );
(*----------------------------------------------------------------------*)
(* *)
(* Procedure: Open_File *)
(* *)
(* Purpose: Opens file for use by Kermit routines *)
(* *)
(* Calling Sequence: *)
(* *)
(* Open_File( File_Mode : Kermit_File_Modes; *)
(* FileName : AnyStr ); *)
(* *)
(* File_Mode --- whether file is to be opened for read or *)
(* write *)
(* FileName --- name of file to open *)
(* *)
(* Calls: *)
(* *)
(* Adjust_Fn *)
(* Open_For_Write *)
(* Int24Result *)
(* *)
(*----------------------------------------------------------------------*)
VAR
Count : INTEGER;
Space_Pos : INTEGER;
Drive : STRING[1];
Temp_Fn : AnyStr;
FileType : STRING[3];
F : FILE OF BYTE;
Err : INTEGER;
Save_Name : AnyStr;
IPos : INTEGER;
(*----------------------------------------------------------------------*)
(* Open_For_Write --- Open file for output *)
(*----------------------------------------------------------------------*)
PROCEDURE Open_For_Write( FileName : AnyStr;
VAR Open_OK : BOOLEAN );
BEGIN (* Open_For_Write *)
(* Check if file exists *)
ASSIGN( F, FileName );
(*$I-*)
RESET( F );
(*$I+*)
(* Error if file exists *)
IF Int24Result = 0 THEN
BEGIN
Open_OK := FALSE;
(*$I-*)
CLOSE( F );
(*$I+*)
Err := Int24Result;
END
ELSE (* Otherwise, new file -- open it *)
BEGIN
Err := Create_File_Handle( FileName, Attribute_None, XFile_Handle );
IF ( Err <> 0 ) OR ( Int24Result <> 0 ) THEN
Open_OK := FALSE
ELSE
BEGIN (* FileName is new file, open it *)
File_Records := 0.0;
Open_OK := TRUE;
File_Open := TRUE;
Buffer_Num := 0.0;
END;
END;
END (* Open_For_Write *);
(*----------------------------------------------------------------------*)
BEGIN (* Open_File *)
(* Remember original file name *)
Save_Name := UpperCase( FileName );
(* Select open based upon whether *)
(* file is to be read or written *)
CASE File_Mode OF
(* Open file for reading *)
Read_Open : BEGIN
ASSIGN( F, FileName );
(*$I-*)
RESET( F );
(*$I+*)
IF ( Int24Result = 0 ) THEN
BEGIN
Open_OK := TRUE;
File_Open := TRUE;
File_Records := LongFileSize( F );
GoToXY( 25 , 4 );
WRITE( File_Records : 8 : 0 );
ClrEol;
Buffer_Num := 0.0;
CLOSE( F );
Err := Open_File_Handle( FileName,
Access_Read_Mode,
XFile_Handle );
Writelne('Sending file ' + FileName , FALSE );
END
ELSE
BEGIN
Open_OK := FALSE;
GoToXY( 25 , 5 );
WRITE('File ', FileName, ' does not exist.');
ClrEol;
END;
END;
(* Open file for writing *)
Write_Open: BEGIN
(* Try opening under provided name *)
Open_For_Write( FileName, Open_OK );
(* If file exists (Open_OK = FALSE), *)
(* then try adjusting name until *)
(* non-existent name found. *)
IF ( NOT Open_OK ) THEN
BEGIN
Temp_Fn := FileName;
REPEAT
Adjust_Fn( Temp_Fn, Drive, FileName, FileType );
IF ( Drive = '!' ) THEN
Temp_Fn := FileName + '.' + FileType
ELSE
Temp_Fn := Drive + ':' +
FileName + '.' + FileType;
Space_Pos := POS( ' ', Temp_Fn );
IF ( Space_Pos <> 0 ) THEN
BEGIN
DELETE( Temp_Fn, Space_Pos, 1 );
INSERT( '&', Temp_Fn, Space_Pos);
WHILE ( POS(' ' , Temp_Fn ) <> 0 ) DO
DELETE( Temp_Fn, POS(' ',Temp_Fn), 1 );
Open_For_Write( Temp_Fn, Open_OK );
END;
UNTIL ( Open_OK OR ( Space_Pos = 0 ) );
IF ( NOT Open_OK ) THEN
BEGIN
IPos := LENGTH( Temp_Fn );
REPEAT
IF ( Temp_Fn[IPos] <> '&' ) THEN
BEGIN
Temp_Fn[IPos] := '&';
IPos := 0;
END
ELSE
IPos := IPos - 1;
Open_For_Write( Temp_Fn, Open_OK );
UNTIL ( IPos <= 0 ) OR Open_OK;
END;
GoToXY( 2 , 6 );
IF Open_OK THEN
BEGIN
IF ( Temp_Fn <> Save_Name ) THEN
WRITE('Filename ',Save_Name, ' changed to: ', Temp_Fn)
ELSE
WRITE('Filename: ',Temp_Fn);
Writelne('Receiving file ' + FileName , FALSE );
END
ELSE
WRITE('Filename ', Save_Name, ' could not be opened.');
ClrEol;
END (* NOT Open_OK *)
ELSE
Writelne('Receiving file ' + FileName , FALSE );
END (* Write_Open *);
END (* CASE *);
END (* Open_File *);
ə