7.1. C-Style Input/Output
|
(lsh/libc/stdio.lsh) |
functions this section provide a convenient interface to the C stdio
library. Functions are provided to open and close C-style file
descriptors and pipes. The most commonly used stdio functions are also
provided, including ftell, fseek, fprintf, rewind, fputc, fgetc, and
several others. C-style file descriptors manipulated by these functions
are merely generic pointers (-gptr-). As a consequence, many of these
function as "unsafe", i.e. calling them with an invalid file pointer may
cause the interpreter to crash.
7.1.0. (fprintf file-pointer args...)
|
(lsh/libc/stdio.lsh) |
((-gptr-) file) ; the file pointer returned by a fopen
MACRO
DESCRIPTION: same as printf, but writes to a file rather than to standard output
RETURNS: ()
CREATED: Pascal Vincent 04/05/96
7.1.1. (fwrite-str file-pointer s)
|
(lsh/libc/stdio.lsh) |
((-gptr-) file) ;; the file pointer returned by a fopen
((-str-) s) ;; the string to be written to the file
RETURNS: ()
CREATED: Pascal Vincent 04/05/96
COMPILABLE: Yes
DESCRIPTION: writes string <s> to file <file-pointer>
See: Compilable file I/O
7.1.2. (stdout)
|
(lsh/libc/stdio.lsh) |
RETURNS: (-gptr-) the file pointer associated with the standard output
CREATED: Pascal Vincent 04/05/96
COMPILABLE: Yes
See: Compilable file I/O
7.1.3. (stdin)
|
(lsh/libc/stdio.lsh) |
RETURNS: (-gptr-) the file pointer associated with the standard input
CREATED: Pascal Vincent 04/05/96
COMPILABLE: Yes
See: Compilable file I/O
7.1.4. (fopen filename type)
|
(lsh/libc/stdio.lsh) |
((-str-) filename) ; the name (or path) of the file to be opened:
((-str-) type) ; the opening type: "rb" for reading, "wb" for creating and writing, "a" for append, ...:
RETURNS: (-gptr-) a file pointer to the open file (the pointer is null in case of failiure)
CREATED: Pascal Vincent 04/05/96
COMPILABLE: Yes
DESCRIPTION: same as the C function fopen
See: Compilable file I/O
7.1.5. (fclose file-pointer)
|
(lsh/libc/stdio.lsh) |
((-gptr-) file) ; the file pointer returned by a fopen
RETURNS: ()
CREATED: Pascal Vincent 04/05/96
COMPILABLE: Yes
DESCRIPTION: same as the C function fclose
See: Compilable file I/O
7.1.6. (popen filename type)
|
(lsh/libc/stdio.lsh) |
((-str-) filename) ; the name (or path) of the pipe to be opened:
((-str-) type) ; the opening type: "rb" for reading, "wb" for creating and writing, "a" for append, ...:
RETURNS: (-gptr-) a file pointer to the open pipe (the pointer is null in case of failiure)
CREATED: Yann LeCun 08/29/96
COMPILABLE: Yes
DESCRIPTION: same as the C function popen
See: Compilable file I/O
7.1.7. (pclose file-pointer)
|
(lsh/libc/stdio.lsh) |
((-gptr-) file) ; the file pointer returned by a popen
RETURNS: ()
CREATED: Yann LeCun 08/29/96
COMPILABLE: Yes
DESCRIPTION: same as the C function pclose
See: Compilable file I/O
7.1.8. (ftell file-pointer)
|
(lsh/libc/stdio.lsh) |
((-gptr-) file) ; the file pointer returned by a fopen
RETURNS: The current position in the file
CREATED: Pascal Vincent 04/05/96
COMPILABLE: Yes
DESCRIPTION: same as C function ftell
See: Compilable file I/O
7.1.9. (fseek file-pointer pos)
|
(lsh/libc/stdio.lsh) |
((-gptr-) file) ; the file pointer returned by a fopen
((-real-) pos) ; an absolute position in the file:
RETURNS: ()
CREATED: Pascal Vincent 04/05/96
COMPILABLE: Yes
DESCRIPTION: moves to the given position in the file
See: Compilable file I/O
7.1.10. (fseek-from-end file-pointer pos)
|
(lsh/libc/stdio.lsh) |
((-gptr-) file) ; the file pointer returned by a fopen
((-real-) pos) ; a position in the file relative to the end
RETURNS: ()
CREATED: Pascal Vincent 04/05/96
COMPILABLE: Yes
DESCRIPTION: moves to the given position in the file
See: Compilable file I/O
7.1.11. (fseek-from-current file-pointer pos)
|
(lsh/libc/stdio.lsh) |
((-gptr-) file) ; the file pointer returned by a fopen
((-real-) pos) ; a position in the file relative to the current position:
RETURNS: ()
CREATED: Pascal Vincent 04/05/96
COMPILABLE: Yes
DESCRIPTION: moves to the given position in the file
See: Compilable file I/O
7.1.12. (fgetc file-pointer)
|
(lsh/libc/stdio.lsh) |
((-gptr-) file) ; the file pointer returned by a fopen
RETURNS: (-int-) The next byte read from the file
CREATED: Pascal Vincent 04/05/96
COMPILABLE: Yes
DESCRIPTION: Reads a byte (character) from the file (same as C function fgetc)
See: Compilable file I/O
7.1.13. (fputc file-pointer val)
|
(lsh/libc/stdio.lsh) |
((-gptr-) file) ; the file pointer returned by a fopen
((-int-) val) ; contains the byte to be written to the file
RETURNS: ()
CREATED: Pascal Vincent 04/05/96
COMPILABLE: Yes
DESCRIPTION: Writes a byte (character) to the file (same as C function fputc)
See: Compilable file I/O
7.1.14. (fread-ubyte file-pointer)
|
(lsh/libc/stdio.lsh) |
((-gptr-) file) ; the file pointer returned by a fopen
RETURNS: (-ubyte-) the next ubyte read from the file
CREATED: Pascal Vincent 04/05/96
COMPILABLE: Yes
See: Compilable file I/O
7.1.15. (fwrite-ubyte file-pointer val)
|
(lsh/libc/stdio.lsh) |
((-gptr-) file) ; the file pointer returned by a fopen
((-ubyte-) val) ; contains the ubyte to be written to the file
RETURNS: ()
CREATED: Pascal Vincent 04/05/96
COMPILABLE: Yes
DESCRIPTION: Writes a ubyte to the given file
See: Compilable file I/O
7.1.16. (fread-byte file-pointer)
|
(lsh/libc/stdio.lsh) |
((-gptr-) file) ; the file pointer returned by a fopen
RETURNS: (-byte-) the next byte read from the file
CREATED: Pascal Vincent 04/05/96
COMPILABLE: Yes
See: Compilable file I/O
7.1.17. (fwrite-byte file-pointer val)
|
(lsh/libc/stdio.lsh) |
((-gptr-) file) ; the file pointer returned by a fopen
((-byte-) val) ; contains the byte to be written to the file
RETURNS: ()
CREATED: Pascal Vincent 04/05/96
COMPILABLE: Yes
DESCRIPTION: Writes an byte (4 bytes on Sun-OS or Solaris) to the given file
See: Compilable file I/O
7.1.18. (fread-short file-pointer)
|
(lsh/libc/stdio.lsh) |
((-gptr-) file) ; the file pointer returned by a fopen
RETURNS: (-short-) the next short (2 bytes) read from the file
CREATED: Pascal Vincent 04/05/96
COMPILABLE: Yes
See: Compilable file I/O
7.1.19. (fwrite-short file-pointer val)
|
(lsh/libc/stdio.lsh) |
((-gptr-) file) ; the file pointer returned by a fopen
((-short-) val)
RETURNS: ()
CREATED: Pascal Vincent 04/05/96
COMPILABLE: Yes
DESCRIPTION: Writes a short (2 bytes) to the given file
See: Compilable file I/O
7.1.20. (fread-int file-pointer)
|
(lsh/libc/stdio.lsh) |
((-gptr-) file) ; the file pointer returned by a fopen
RETURNS: (-int-) the next int (4 bytes on Sun-OS or Solaris) read from the file
CREATED: Pascal Vincent 04/05/96
COMPILABLE: Yes
See: Compilable file I/O
7.1.21. (fwrite-int file-pointer val)
|
(lsh/libc/stdio.lsh) |
((-gptr-) file) ; the file pointer returned by a fopen
((-int-) val) ; contains the int to be written to the file
RETURNS: ()
CREATED: Pascal Vincent 04/05/96
COMPILABLE: Yes
DESCRIPTION: Writes an int (4 bytes on Sun-OS or Solaris) to the given file
See: Compilable file I/O
7.1.22. (fread-flt file-pointer)
|
(lsh/libc/stdio.lsh) |
((-gptr-) file) ; the file pointer returned by a fopen
RETURNS: (-float-) the next float (4 bytes) read from the file
CREATED: Pascal Vincent 04/05/96
COMPILABLE: Yes
See: Compilable file I/O
7.1.23. (fwrite-flt file-pointer val)
|
(lsh/libc/stdio.lsh) |
((-gptr-) file) ; the file pointer returned by a fopen
((-float-) val):
RETURNS: ()
CREATED: Pascal Vincent 04/05/96
COMPILABLE: Yes
DESCRIPTION: Writes a float (4 bytes) to the given file
See: Compilable file I/O
7.1.24. (fread-real file-pointer)
|
(lsh/libc/stdio.lsh) |
((-gptr-) file) ; the file pointer returned by a fopen
RETURNS: (-real-) the next real (8 bytes) read from the file
CREATED: Pascal Vincent 04/05/96
COMPILABLE: Yes
See: Compilable file I/O
7.1.25. (fwrite-real file-pointer val)
|
(lsh/libc/stdio.lsh) |
((-gptr-) file) ; the file pointer returned by a fopen
((-real-) val):
RETURNS: ()
CREATED: Pascal Vincent 04/05/96
COMPILABLE: Yes
DESCRIPTION: Writes a real (8 bytes) to the given file
See: Compilable file I/O
7.1.26. (reverse_n ptr sz n)
|
(lsh/libc/stdio.lsh) |
((-gptr-) ptr) ;; pointer to the block of memory that must be reversed
((-int-) sz) ;; size of each item to reverse
((-int-) n) ;; number of items to reverse
RETURNS: ()
CREATED: Pascal Vincent 04/17/96
COMPILABLE: Yes
DESCRIPTION: Reverses order of bytes in <n> items of size <sz>
starting at memory location <ptr>
This is a tool for writing/reading file formats that are portable
across systems with processors that represent long-words
differently in memory (Sparc vs Intel-Pentium for ex.)
It can be called from inline-C as C_reverse8(ptr,n);
7.1.27. (fscan-int file-pointer)
|
(lsh/libc/stdio.lsh) |
(-gptr- file-pointer) ;; the file poiner returned by fopen
DESCRIPTION: Same as fscanf(file_pointer,"%d",&result) in C.
RETURNS: int
CREATED: Yoshua Bengio 23 August 1996
7.1.28. (fscan-flt file-pointer)
|
(lsh/libc/stdio.lsh) |
(-gptr- file-pointer) ;; the file poiner returned by fopen
DESCRIPTION: Same as fscanf(file_pointer,"%d",&result) in C.
RETURNS: float
CREATED: Yoshua Bengio 23 August 1996
7.1.29. (fscan-str file-pointer)
|
(lsh/libc/stdio.lsh) |
(-gptr- file-pointer) ;; the file poiner returned by fopen
DESCRIPTION: same as fscanf(file_pointer,"%s",result).
The result must hold in a string of size < 1024 bytes.
RETURNS: string
CREATED: Yoshua Bengio 23 August 1996
7.1.30. (fgets file-pointer max-size)
|
(lsh/libc/stdio.lsh) |
(-gptr- file-pointer) ;; the file poiner returned by fopen
(-int- max-size) ;; maximum allowed size of line in bytes
DESCRIPTION: same as C's fgets(result,max_size,file_pointer).
RETURNS: string
CREATED: Yoshua Bengio 23 August 1996
7.1.31. (file-size file-name)
|
[DE] (lsh/libc/stdio.lsh) |
returns the size in byte of file file-name
author: Leon Bottou.
7.1.32. (rewind f)
|
(lsh/libc/stdio.lsh) |
((-gptr-) f):
CREATED: Oct 97
DESCRIPTION:
7.1.33. (skip-comments start f)
|
(lsh/libc/stdio.lsh) |
((-char-) start):
((-gptr-) f):
CREATED: Oct 97
DESCRIPTION:
skip comments lines starting with <start>