groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Groff] conditional for file existence?


From: Werner LEMBERG
Subject: Re: [Groff] conditional for file existence?
Date: Tue, 15 Jul 2003 07:28:59 +0200 (CEST)

> Is there a way to check if a filename names an existent file?

No.  You are the first one who asks this question here.

Perhaps we should do the same route as TeX, namely adding .openr,
.read, and a new operator to .if:

  .openr <stream> <file>
  .read <stream> <string variable>
  .if f <stream>

`openr' opens a file for reading.  It does *not* produce an error.
[Use the `close' request to undefine the stream handle.]

`read' gets a line (in text mode; stripping the final newline) from a
stream and puts it into a string variable.

The new conditional operator `f' returns zero if either the stream is
not open or we are at EOF.

Both `read' and `if f' return an error if the specified stream
doesn't exist.

A file test for file foo.bar would then look like this:

  .open FILE foo.bar
  .if f FILE \{\
  .  close FILE
  .  so foo.bar
  .\}

For a zero-length file, `if f' will be true before the first call to
`read' but not afterwards.

Any volunteer to implement?


    Werner

reply via email to

[Prev in Thread] Current Thread [Next in Thread]