Appending to a Text file.
I have a version of Pascal without the append command.
Is there a good way preferredly without reading through
the existing file to append text to a unix text file?
I want to write a log file that may eventually get
: I have a version of Pascal without the append command.
: Is there a good way preferredly without reading through
: the existing file to append text to a unix text file?
: I want to write a log file that may eventually get
: very large.
You'd have to use the [b]seek[/b] ( seek(_file_,filesize(_file_)); ) command to jump to the end of the file, then do the write. The only problem that seek doesn't work w/ text files, You'd have to handle the textfile as a untyped one, and use [b]blockwrite[/b] instead of [b]writeln[/b] and setup the output data accordingly.
: : I have a version of Pascal without the append command.
: : Is there a good way preferredly without reading through
: : the existing file to append text to a unix text file?
: : I want to write a log file that may eventually get
: : very large.
: You'd have to use the [b]seek[/b] ( seek(_file_,filesize(_file_)); )
: command to jump to the end of the file, then do the write. The only
: problem that seek doesn't work w/ text files, You'd have to handle
: the textfile as a untyped one, and use [b]blockwrite[/b] instead of
: [b]writeln[/b] and setup the output data accordingly.
Unfortunately the problem seems to be with the open. I seemingly
only have rewrite (which erases the file before starting) and reset
(which puts me into a read only mode on the file). All regardless,
to whether I am just writing text or record blocks. Seems to be
quite a shortcoming in the early Pascal.
Or am I missing something.
: Unfortunately the problem seems to be with the open. I seemingly
: only have rewrite (which erases the file before starting) and reset
: (which puts me into a read only mode on the file). All regardless,
: to whether I am just writing text or record blocks. Seems to be
: quite a shortcoming in the early Pascal.
: Or am I missing something.
You're not missing anything. These "shortcomings" of "early Pascal" was the driving force behind the 1983 standard and Turbo Pascal. Is there something keep you from upgrading to a more modern implementation?
Shoot, I was afraid of that. This is on an old legacy system that has been moved away from. I am coding a special for a customer still running the old. I will work my way around it.
Thanks for the assistance.
Early Pascal did not have [b]seek[/b] or [b]blockwrite[/b] so the solution suggested by Atex will not work either. Probably the only solution is to copy the entire file to a scratch file, then write the new data to the scratch file. If you are lucky your implementation will let you [b]remove[/b] your original file and [b]rename[/b] the scratch file, but most early Pascals did not have these capabilities. Lacking these capabilities your only option will be the copy the scratch file back to your original, leaving the scratch file on the system.
I think of "early Pascal", i.e., implementations based on the Jensen and Wirth descriptions, as an entirely different language than those based on the 1983 standard, e.g., Turbo Pascal, Free Pascal and Delphi. Detractors of the language inevitably point out the Jensen/Wirth deficiencies, arguments have no validity when applied to modern implementations.
I actually did have the [b]seek[/b] function and my [b]write[/b] functioned as a blockwrite as it did write out the record. Unfortunately, it still could not be used to append as the problem still is in the opening of the file.
This is from TP7 help, but may have been implemented before:
Earlier I mentioned that the [b]append[/b] commad is not available to
me with my version. That would be the ticket if it were.
...and yes something along the lines of your last suggestion could be accommodated but the file being created has the possiblity of becoming quite large and reading through it each time to add 1 additional entry would not be acceptable.
I will be doing one of a couple things, either living with a separate file for each log and utilizing a unix cron job to concatinate things or I have an ability to partner some "C" code with the Pascal to possibly do what I need.
Bottom line, this can be considered closed...thanks to all who offered suggestions...albeit the one acknowledging Pascal's early shortcomings seems to be the most accurate hammer.
It looks like you're new here. If you want to get involved, click one of these buttons!
Assembly Code Share
Getting started in assembly
C and C++
C/C++ on Linux/Unix
C/C++ Windows API
C++ Game Development
Delphi and Kylix
Java Server Pages
Access databases and VB
Advance Visual Basic
DirectX Game dev
Newbie Game Programmers
Cooling & Overclocking
Database & SQL
Sound & Music
FreeLance Software City
C# & VB.NET School Support
Join the Team
Comments on this site
New programming languages
Off topic board
Mobile & Wireless
Operating Systems & Platforms
Witsbits Go Cloud
Embedded / RTOS
Windows CE & Pocket PC
Networking And Security
Windows 2003 Server
RUP & UML
Quality & Testing
Active Server Pages
HTML & WEB-Design
Mobile Internet & Messaging
WEB-Services / SOAP
In this Discussion