Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

The Question: I recently acquired a 1989 IBM PS2 and I am trying move large files from my newer UNIX-based machine to this IBM via floppy. I have a bash script that splits my files into ~2MB chunks, now I am trying to write a pascal program to reconstruct these files after they have been transferred.

I am unable to find the correct read/write to file methods on this computer. I have tried various pascal tutorial sites, but they are all for newer versions (the site I followed with File Handling In Pascal). I am able to create an empty file (as described below), but I am unable to write to it. Does anyone know the correct pascal read and write methods for this type of computer?

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

The Details:

The current test code that creates a file correctly is this:

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 method's append() and close() could not be 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 did not work, the writeln() method only ever prints to the terminal. But otherwise this does 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.

The system: As was previously mentioned, this is a 1989 IBM PS2.

  • It has Windows 3.0 installed 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 am using turbo as my command line pascal editor. (the readme was last updated in 1989)
  • It has Turbo debugger 1.5 installed.

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

like image 696
Caleb Adams Avatar asked Jan 29 '16 03:01

Caleb Adams


2 Answers

My Pascal memory is VERY rusty... but as other have pointed out, here is 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 installed any longer so I couldn't compile it myself, no promise that it will work it is more like an idea:

  • Key thing to remember, readln and writeln will ALWAYS add a return at the end of the string/line, read and write on the other hand will leave the cursor wherever it is without jumping to a new line.
like image 73
Emil Borconi Avatar answered Oct 17 '22 17:10

Emil Borconi


Here's some old Delphi code that should be at least close to syntax-compatible that will give you the gist of copying a file (with limited error checking and resource handling in case of error - I'll leave that 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 compiles under Delphi 2007 currently (the oldest version I have installed). (See the note below.)

As a side note, this was from an archived version of some code I had that compiled both for 16-bit Delphi 1 and was extended to also compile under 32-bit Delphi 2 back in the mid-to-late 90s. It's still hanging around in my source repositories in an old tagged branch. I think I need to do some pruning. :-) I cleaned it up to remove some other functionality and removed a lot of {$IFDEF WIN32} ... {$ELSE} ... {$ENDIF} stuff before posting.)

like image 30
Ken White Avatar answered Oct 17 '22 17:10

Ken White