Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Reid G.C.Thinking in PostScript.1990.pdf
Скачиваний:
17
Добавлен:
23.08.2013
Размер:
846.44 Кб
Скачать

 

Streams and Files

 

A stream is a special case of a file object that can only be accessed

 

sequentially. You have no real way to know, given an arbitrary file object,

 

whether or not you can read or write arbitrary parts of the file. It is best

 

always to assume that the file is a stream, and only to read sequentially

 

from it (or write sequentially to it). For example, the currentfile operator

 

will often return the file stream representing the serial port on the printer,

 

although it might represent a real disk file in an environment where there

 

is a file system available to the interpreter. As long as you use the

 

setfileposition operator with some care, the distinction between a stream

 

and a file probably won’t matter.

 

 

TIP

Some file operations will work on virtually any PostScript interpreter,

 

such as reading from the current file or writing to the standard output

 

stream. Other file operations, such as explicitly opening a file by name,

 

checking the status of a file, or using a very specific operator like set-

 

fileposition, depend heavily on the existence of a file system supported

 

by the interpreter. It is very important to make sure that the interpreter

 

supports these operations before attempting them, or you may get an er-

 

ror. You can use the known or where operators to check for the existence

 

of certain operators, or you can consult the manual for your interpreter to

 

find out how to test for the presence of a file system.

 

As a rule of thumb, any printer equipped with a hard disk or any worksta-

 

tion running a PostScript interpreter will have access to the full range of

 

disk operations described in this chapter.

 

 

PostScript File Operators

Many PostScript operators read to, write from, or administer files. They differ quite a bit in the details, but they all work in pretty much the same way. Remember that you almost always need either a file object or a file name with each of these operators. Also, keep in mind that the reading and writing operators are analogous to the get and put operators. This will help you to conceptualize the file operations somewhat; they both require

168

Chapter 14: USING FILES AND INPUT/OUTPUT TECHNIQUES

two basic pieces of information: what you want to read or write, and which file you are interested in.

Table 14.1 contains a list of PostScript file operators. Some of these operators are not available in early implementations of PostScript printers, especially those without hard disk capabilities.

Table 14.1: PostScript File Operators

Arguments Operator

 

Action

string1 string2

file file_object

open file string1 with access string2

file_object

closefile

±

close file

string

deletefile

remove file from device

string1 string2

renamefile

±

change file name string1 to string2

pattern proc scratch filenameforall±

execute proc for files that match

 

 

 

 

pattern string (can use *)

file_object

read int true

read one character from file

 

false

 

 

file_object int

write

 

 

write one character to file

file_object string

readhexstring

read hexadecimal strings

 

 

 

substring

 

 

 

 

boolean

 

file_object string

writehexstring

write hexadecimal strings

file_object string

readstring

string

read string from file

file_object string

writestring

 

write string to file

file_object string

readline

string

read through newline

file_object

token token true

read PostScript token from file

 

false

 

 

file_object

bytesavailableint

how many bytes left in file

 

flush

 

 

flush stdout file

file_object

flushfile

 

 

flush file_object

file_object

resetfile

 

reset file pointer to beginning of file

file_object int

setfileposition

set file position to int

file_object

filepositionint

return current position in file

file_object

status

boolean

is file_object still valid?

string

status

pages

return information on disk file named

 

 

bytes

string and leave data on stack

 

 

referenced

 

 

 

created

 

 

or

true

 

 

false

 

 

 

 

 

diskstatus

 

 

 

 

pages_used

 

 

 

total_pages

 

string

run

 

 

execute contents of file string

 

currentfile

file_object

returns currently active file object

Chapter 14: USING FILES AND INPUT/OUTPUT TECHNIQUES

169