BINIO.FAS Version 2.25, 2/19/99 Optional External STDLIB Module for Vital Lisp and Visual LISP If this doesn't work for your system, use the STDLIB ads/arx module instead. --------------------------------------------------------------------------- Copyright (c) 1998,1999 by Reini Urban Available for free at http://xarch.tu-graz.ac.at/autocad/stdlib/ Permission to use, copy, modify and distribute this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that the copyright notice, this permission notice and the pointer where to download the library for free appear in the supporting documentation, and that the name of Reini Urban not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. No Warranty Reini Urban makes no representations about the suitability of this software for any purpose, without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. It is provided "as is" without express or implied warranty. See the full Disclaimer for all detailed permissions and warranties. --------------------------------------------------------------------------- Binary File IO streams returned by BINIO-fopen are incompatible with plain AutoLISP open! (BINIO-FOPEN fname mode) ; opens fname with modes "r" "w" or "a" and returns a stream object (BINIO-FCLOSE stream) ; closes a stream opened with BINIO-fopen (BINIO-FCLOSEALL) ; closes all opened streams (BINIO-FSEEK stream pos [start-from]) ; moves the filepointer to pos, ; start-from may be :start (default) :end or :relative (BINIO-FTELL stream) ; returns the filepointer or nil (BINIO-REWIND stream) ; moves the filepointer to the beginning, returns 0 or nil reader support, v2.2 (BINIO-READ-CHAR [input-stream [eof-error-p [eof-value [recursive-p]]]]) => char ViLL only: (not in VLisp) (BINIO-UNREAD-CHAR CHAR-CODE [ISTREAM]) => CHAR-CODE (BINIO-PEEK-CHAR [peek-type [input-stream [eof-error-p [eof-value [recursive-p]]]]]) => char All fput funcs accept either the single type or a list of those. (BINIO-FPUTC ostream int |list-of-ints) ; integer (BINIO-FPUTINT ostream int |list-of-ints) ; integer (BINIO-FPUTLONG ostream num |list-of-nums) ; integer or real (BINIO-FPUTREAL ostream real|list-of-reals) ; double (BINIO-FPUTS ostream str |list-of-str) ; ASCIIZ string (0 terminated) (BINIO-FPUTSTRING ostream str |list-of-str) ; string \r\n terminated on End of File nil is returned (BINIO-FGETC istream) ; #\0 too (BINIO-FGETREAL istream) ; read double (4 byte) from stream (BINIO-FGETINT istream) ; read signed short int (2 byte) from stream (BINIO-FGETLONG istream) ; read signed long int (4 byte) from stream (BINIO-FGETS istream) ; ASCIIZ string (0 terminated) (BINIO-FGETSTRING istream) ; string \r\n terminated Needed for file access on bit-level instead of byte-wise: (BINIO-%DOUBLE->2LONGS double) => (long long) ; only for INTEL, 8 byte IEEE double (BINIO-%2LONGS->DOUBLE l1 l2) => double ; only for INTEL, 8 byte IEEE double Sample for fput: (defun test(/ *error*) (defun *error* (s) (princ s) (binio-fcloseall)) (defun inc-list (lst end len) ; create incremented list: '(0 1 2 ... n) (repeat len (setq lst (cons (setq end (1- end)) lst)))) (binio-fcloseall) (if (and (setq fn "test.bin") (setq f (binio-fopen fn "w")) ) (progn (binio-fputstring f "256 bytes 0 - 255:") (binio-fputc f (inc-list nil 255 256)) ;; Note the \r\n instead of \n alone! (binio-fputstring f "\r\nsome doubles:") (setq i 0.0) (repeat 10 (binio-fputstring f (rtos i)) (binio-fputreal f (setq i (+ i 0.1))) ) (binio-fputstring f "\r\n100 longs from 100000 on:") (binio-fputlong f (inc-list nil 100099 100)) (binio-fputs f "\r\nASCIIZ string") (binio-fclose f) ) ) ) --------------------------------------------------------------------------- Version 2.25, 2/19/99 fixed symbol in *MODULES* Version 2.24, 2/9/99 al-provide inlined, no apply Version 2.23, 12/10/98 changed binio-fseek [start-from] argument from type symbol to integer Version 2.22, 8/8/98 al-provide depends dynamically on AL:*MODULES* Version 2.21, 30.July 98 only internal changes, experimental: bionio-fopen with "r+" or "w+" Version 2.2, 29.June 98 added reader-support: read-char, ViLL only: unread-char, peek-char Version 2.1, 22.June 98 new: binio-fseek: optional 3rd parameter binio-open: mode may be "rw", read-write fixed: binio-ftell: with output streams renamed: binio-%double->2longs, binio-%2longs->double deleted: all urx- and std- extensions (see FILEEXT) Version 2.0, 21.June 98 added: binio-fseek,... double->2long,... Version 1.0, 23.Feb 98 initial release with: binio-fopen binio-fclose binio-fcloseall binio-fputc binio-fputint binio-fputlong binio-fputreal binio-fputs binio-fputstring binio-fgetc binio-fgetreal binio-fgetint binio-fgetlong binio-fgets binio-fgetstring --------------------------------------------------------------------------- for more see STDLIB.HLP or CLtL2 or the CLHS http://xarch.tu-graz.ac.at/autocad/stdlib/