Appending to a Text file. - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Appending to a Text file.

furfur Posts: 9Member

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.

Thanks

Comments

  • AtexAtex Posts: 268Member
    : 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.

  • furfur Posts: 9Member
    : : 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.
  • ActorActor Posts: 438Member
    [red]:
    : 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.
    : [/red]
    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?



  • furfur Posts: 9Member

    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.
  • ActorActor Posts: 438Member
    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.



  • furfur Posts: 9Member

    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.

    Thanks.
  • Phat NatPhat Nat Posts: 757Member
    This is from TP7 help, but may have been implemented before:

    [code]
    Append (procedure)
  • furfur Posts: 9Member

    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.
Sign In or Register to comment.