next up previous contents index
Next: Menu Buttons Up: Operating System and Input/Output Previous: Date and Time   Contents   Index

File System Interface

(string) Glob(pattern)
This function returns a string which is a filename expansion of the pattern string, in the manner of the C-shell. The pattern can contain the usual substitution characters *, ?, [ ], { }.

Example: Return a list of ``.gds'' files in the current directory.

list = Glob("*.gds")

(file_handle) Open(file, mode)
This function opens the file given as a string argument according to the string mode, and returns a file descriptor. The mode string should consist of a single character: `r' for reading, `w' to write, or `a' to append. If the returned value is negative, an error occurred.

(file_handle) Popen(command, mode)
This command opens a pipe to the shell command given as the first argument, and returns a file handle that can be used to read and/or write to the process. The handle should be closed with the Close function. This is a wrapper around the C library popen command so has the same limitations as the local version of that command. In particular, on some systems the mode may be reading or writing, but not both. The function will fail if either argument is null or if the popen call fails.

(file_handle) Sopen(host, port)
This function opens a ``socket'' which is a communications channel to the given host and port. If the host string is null or empty, the local host is assumed. The port number must be provided, there is no default. If the open is successful, the return value is an integer larger than zero and is a handle that can be used in any of the read/write functions that accept a file handle. The Close function should be called on the handle when the interaction is complete. If the connection fails, a negative number is returned. The function fails if there is a major error, such as no BSD sockets support.

(string) ReadLine(maxlen, file_handle)
The ReadLine function returns a string with length up to maxlen filled with characters read from file_handle. The file_handle must have been successfully opened for reading with a call to Open, Popen, or Sopen. The read is terminated by end of file, a return character, or a null byte. The terminating character is not included in the string. A null string is returned when the end of file is reached, or if the handle is not found. The function will fail if the handle is not a file handle, or maxlen is less than 1.

(int) ReadChar(file_handle)
The ReadChar function returns a single character read from file_handle, which must have been successfully opened for reading with an Open, Popen, or Sopen call. The function returns EOF (-1) when the end of file is reached, or if the handle is not found. The function will fail if the handle is not a file handle.

(int) WriteLine(string, file_handle)
The WriteLine function writes the content of string to file_handle, which must have been successfully opened for writing or appending with an Open, Popen, or Sopen call. The number of characters written is returned. The function will fail if the handle is not a file handle, or the string is null.

This function has the unusual property that it will accept the arguments in reverse order.

WriteLine does not append a carriage return character to the string. See the PrintLog function for a variable argument list alternative that does append a return character.

(int) WriteChar(c, file_handle)
This function writes a single character c to file_handle, which must have been successfully opened for writing or appending with a call to Open, Popen, or Sopen. The function returns 1 on success. The function will fail if the handle is not a file handle, or the integer value of c is not in the range 0-255.

This function has the unusual property that it will accept the arguments in reverse order.

(string) TempFile(prefix)
This function creates a unique temporary file name using the prefix string given, and arranges for the file of that name to be deleted when the program terminates. The file is not actually created. The return from this command is passed to the Open command to actually open the file for writing.

(stringlist_handle) ListDirectory(directory, filter)
This function returns a handle to a list of names of files and/or directories in the given directory. If the directory argument is null or empty, the current directory is understood. If the filter string is null or empty, all files and subdirectories will be listed. Otherwise the filter string can be ``f'' in which case only regular files will be listed, or ``d'' in which case only directories will be listed. If the directory does not exist or can't be read, 0 is returned, otherwise the return value is a handle to a list of strings.


next up previous contents index
Next: Menu Buttons Up: Operating System and Input/Output Previous: Date and Time   Contents   Index
Stephen R. Whiteley 2006-10-23