Read / write to file on old IBM PS / 2 in turbo pascal 5.5

Question I recently purchased the 1989 IBM PS2, and I'm trying to transfer large files from my new UNIX-based computer to this IBM via a floppy disk. I have a bash script that breaks my files into ~ 2MB chunks, now I'm trying to write a pascal program to recover these files after transferring them.

I can not find the correct methods to read / write to a file on this computer. I tried various training sites on pascal, but they are all for newer versions (the site I followed, File Processing in Pascal ). I can create an empty file (as described below), but I cannot write to it. Does anyone know the correct pascal read and write methods for this type of computer?

I know this is an unclear question, so well in advance for any help you can give me!

Details :

The current test code that correctly creates the file is as follows:

program testingFiles; uses Crt, Win; const FILE_NAME = 'testFile.txt'; var outFile : File; begin writeln('creating file ...'); Assign(outFile, FILE_NAME); rewrite(outFile); end. 

This is some test code that does not work, the append() and close() method was not found:

 program testingFiles; uses Crt, Win; const FILE_NAME = 'testFile.txt'; var outFile : File; begin writeln('creating file ...'); Assign(outFile, FILE_NAME); append(outFile); writeln('this should be in the file'); close(outFile); end. 

This is an alternative that also didn't work, the writeln() method only ever prints to the terminal. But otherwise, it will compile.

 program testingFiles; uses Crt, Win; const FILE_NAME = 'testFile.txt'; var outFile : File; begin writeln('creating file ...'); Assign(outFile, FILE_NAME); rewrite(outFile); writeln('this should be in the file'); close(outFile); end. 

System . As already mentioned, this is the 1989 IBM PS2 .

  • He installed Windows 3.0 and can also run DOS and MS-DOS terminals.
  • It has Microsoft SMARTDrive Disk Cache version 3.06
  • It has Turbo Pascal 5.5 installed, and I use turbo as the pascal command line editor. (last update was updated in 1989).
  • He has Turbo debugger 1.5 installed.

Again, I know this is an unclear question, so well in advance for any help you can give me!

+5
source share
2 answers

My Pascal's memory is VERY rusty ... but as others have pointed out, here's what you should consider:

 program testingFiles; uses Crt, System; //No need of importin Win Win is for Windows enviorment, however I'm not sure if you need to use System, Sysutils or was there a Dos class??? const FILE_NAME = 'testFile.txt'; var outFile,inFile : File; begin writeln('creating file ...'); Assign(outFile, FILE_NAME); rewrite(outFile); //Now Open the first chunk of the file you want to concatenate AssignFile(inFile, "fisrt_chunk.dat"); reset(inFile); while not eof(inFile) do begin readln(inFile, s); writeln(outFile,s); end; close(inFile); end. 

I donโ€™t have Turbo / Borland Pascal yet, so I couldnโ€™t compile it myself, I donโ€™t promise that it will work, it looks more like an idea:

  • The main thing to remember is that readln and writeln will ALWAYS add a return to the end of the line / line, on the other hand, reading and writing will leave the cursor wherever it is, without jumping to a new line.
+1
source

Here is some old Delphi code that should be at least close to the syntax that will give you the essence of copying a file (with limited error checking and resource handling in case of an error - I will leave this as an exercise for you). It works to copy both binary and text content.

 program Project2; uses SysUtils; var NumRead, NumWritten: LongInt; pBuff : PChar; SrcFile, DstFile: File; const BuffSize = 2048; // 2K buffer. Remember not much RAM available InFileName = 'somefile.txt'; OutFileName = 'newfile.txt'; begin NumRead := 0; NumWritten := 0; AssignFile(SrcFile, InFileName); AssignFile(DstFile, OutFileName); // Allocate memory for the buffer GetMem(pBuff, BuffSize); FileMode := 0; // Make input read-only Reset( SrcFile, 1 ); FileMode := 2; // Output file read/write Rewrite( DstFile, 1 ); repeat // Read a buffer full from input BlockRead(SrcFile, pBuff^, BuffSize, NumRead); // Write it to output BlockWrite(DstFile, pBuff^, NumRead, NumWritten); until (NumRead = 0) or (NumWritten <> NumRead); // Cleanup stuff. Should be protected in a try..finally, // of course. CloseFile(SrcFile); CloseFile(DstFile); FreeMem(pBuff); end. 

The above code is compiling in Delphi 2007 currently (the oldest version I installed). (See note below.)

As a side note, this was from an archive version of some code that was compiled for both 16-bit Delphi 1 and for expansion under 32-bit Delphi 2 in the mid-90s. It still hangs in my source repositories in an old tagged branch. I think I need to do some trimming. :-) I cleaned it up to remove some other features and removed a lot of stuff {$IFDEF WIN32} ... {$ELSE} ... {$ENDIF} before posting.)

0
source

Source: https://habr.com/ru/post/1241771/


All Articles