IMPORT WITH:


      #import "file"

The routines in this packagage are statically compiled into the prog_unit, but become available only after the above directive is given.

EXPORTED CONSTANTS:

stdin, stdout, stderr
constants to designate std input, std output and stderr for routines below (for lack of a FILE* data type, these constants are of type float in the #importing prog unit)
EOF, SEEK_SET, SEEK_CUR, SEEK_END
constants for for fseek() below.

EXPORTED FUNCTIONS:

float fopen(char *filename,char *mode)
open file with mode mode and return handle (for lack of a FILE* data type, the returned handle is of type float in the prog_unit) Mimics the stdlib C-function of the same name.
For all of the following routines, fp denotes a file handle (of type float or int) that was obtained from a previous fopen() or fifo(), or one of the exported constants stdin, stdout, stderr.
fclose(float fp)
close file
feof(float fp)
test end-of-file condition
rewind(float fp)
rewind to start of file
ftell(float fp)
return offset (in bytes) from start of file
fflush(float fp)
flush file
fseek(float fp, float offset, float whence)
position file pointer at designated locatation. Whence is one of SEEK_SET, SEEK_CUR, SEEK_END (mimics stdlib C-function of the same name)
fgets(float *buf, float maxlen, float fp)
read string into buffer (a float array is expected), maximal nr of read chars is maxlen. Mimics C fgets() function.
fputs(char *str, float fp)
write string to file. Mimics C fputs() function.
fprintf(float fp, char *fmt, ...)
formatted print. Mimics C fprintf() function.
fprintf_vec(float fp, char *fmt, float *vec, float split)
formatted print of a vector vec, splitting every split items (no split, if split=0, transposed print with -split, if split<0).
skip_comments(float fp, float ch)
skip comment lines starting with character ch.

READING OR WRITING IMAGE FILES:

void peek_image(char *filename, int *width, int *height):
get image size
byte *read_image(char *filename, byte *buffer, int colorspace=1):
read image file into buffer, using image format as specified by colorspace. Return value is unused and NULL. If buffer is a byte pointer prefixed with (&), it will be resized if too small.
byte *read_image(char *filename, int colorspace=1):
as before, but allocates suitably sized result array and returns pointer.

Constants to specify colorspace for the above:

I_MONO=0:
use monochrome color space (each pixel = one byte)
I_RGB=1:
use RGB color space (each pixel = three bytes)
I_YUV=2:
use YUV color space (each pixel = three bytes) NOTE: currently only for jpeg images operative

Further routines:

int write_pnm_file(int fp, int dx, int dy, byte *red,*green,*blue, *comment=NULL) : int write_pnm_file(char *fileid, int dx, int dy, byte *red,*green,*blue, *comment=NULL) : If red,green,blue are non-NULL: write a ppm file for given color pixel data, which are assumed to be a rectangle of width dx and height dy. If the last two arguments are both NULL, red is re-interpreted as monochrome gray value, green as an (optional) comment and a pgm file is written instead, ie., the above are in this case interpreted as the calls void write_pnm_file(int fp, int dx, int dy, byte *mono, char *comment=NULL) : void write_pnm_file(char *fileid, int dx, int dy, byte *mono, char *comment=NULL) : write pgm file for image data mono. which are assumed to be a rectangle of width dx and height dy.

FIFO FOR INTERPROCESS SYNCHRONIZATION:

These routines allow a convenient synchronization with another process that writes into a fifo.
int fifo(char *fifoname, char *mode)
open a named fifo with mode mode (one of "r" or "w"). If the fifo does not yet exist, it will be created.
fwaits(int fi, float msec)
wait up to msec milliseconds (0=indefinitly) for fifo fi to fill up with another text line (terminated by a newline char) and return newly allocated copy of that line (with the terminating newline character as its last char before the nullbyte), NULL if no line was completed during the waiting period.
fwaitw(int fi, float msec)
analogous to fwaitw(), but waiting now is for a text token (delimited by white space which itself is not returned as part of the token) instead of a full line.
With both routines, fi must be a fifo handle obtained from fifo() with mode "r". Any input that was not yet shipped out during previous calls will be kept internally for further completion to lines or tokens in subsequent calls (in particular, a partially accumulated but incomplete line from a previous fwaits() call may allow an immediate successful return of one or more subsequent fwaitw() calls when it contains one or more complete tokens). A fifo handle may also be used together with the other file read/write functions.

EXAMPLES:

FifoDemo.NST

NOTES:

(i) a "r" mode fifo will be non-blocking (ii) calls of fwaitw() and fwaits should not be mixed with other reading calls on the same fifo (this would lead to unpredictable results) (iii) the timeout intervals will have a granularity of about 50ms. (iv) when several processes write to the same fifo, they should use chunks of size no larger than PIPE_BUF, the maximal guaranteed size of atomic writes to a fifo (in limits.h, POSIX requests 512 bytes, actual size is often larger), otherwise interleaving of messages may occur.

FILE

/local/homes/rhaschke/nst7/man/../o.linx86_64//../nstsrc/nst_prog_libs.c