home *** CD-ROM | disk | FTP | other *** search
- IOLIB Library Documentation
-
- IOLIB defines all the arithmetic operations, and the following
- I/O, heap management, and error reporting functions:
-
-
- FUNCTIONS
-
- cpm(bc,de) int bc,de;
- The registers BC and DE are set to the values of the
- corresponding arguments, and a BDOS service request
- (CALL to 5) is made. The value returned is the contents
- of A (sign extended).
- getchar()
- Echoes and returns one character from the standard
- input, which is initially the keyboard but can be
- redirected by setargs() in the ARGS library.
- putchar(c) char c;
- displays one character on the standard output, which is
- initially the console but can be redirected by setargs()
- in the ARGS library. Adds LF after CR. Returns c.
- gets(buf) char buf[80];
- Gets a null-terminated string from the standard input.
- If I/O has not been redirected, the string comes from
- the keyboard and standard CP/M editing is permitted. The
- maximum length of the string is fixed at 80 characters.
- puts(s) char *s;
- Displays a null-terminated string on the standard
- output, using putchar().
- fopen(name,mode) char *name,*mode;
- Opens file "name". "mode" is a pointer to a single
- character (either upper or lower case): "r" for read
- access, "w" for write access, and "a" for appending to
- an existing file. fopen returns a unit number (int)
- which must be used for subsequent file accesses.
- For example...
-
- u=fopen("frodo.c","r") opens FRODO.C for reading
- character=getc(u) gets a character from FRODO.C
- u=fopen("sam.c","W") opens SAM.C for writing
- putc(character,u) writes a character to SAM.C
-
- Up to three files may be open at once. (If more are
- needed, change NBUFS and BUFLGH in IOLIB.C, compile,
- and assemble.)
- fclose(u) int u;
- Closes the file with the unit number u.
- getc(u) int u;
- Returns the next character from the file (not sign
- extended), or -1 at end of file. Line feeds are
- discarded, and control Z (1AH) signals end of file.
- getb(u) int u;
- Return next byte from file (not sign extended), without
- regard to its value, or -1 if at end of file. (Use this
- one to read a COM file.)
- putc(c,u) char c; int u;
- Write character c to a file. If it is a carriage
- return, write a line feed as well. Returns c.
- putb(c,u) char c; int u;
- Write byte c to a file, without special handling of
- carriage return.
- fflush(u) int u;
- Flush buffer for unit u (which must be an output
- file) to disk. Called automatically by fclose().
-
- alloc(n) int n;
- Returns a pointer to a block of n bytes of memory
- (no error checking).
- free(ptr) char *ptr;
- ptr should be one of the pointers returned by alloc.
- That block AND ALL BLOCKS ALLOCATED SINCE THEN are
- returned to the heap.
- avail()
- Returns the number of bytes of memory available for
- the heap AND THE STACK. If you allocate all of it
- and write over the stack, you will cause trouble.
- The safe way to get a big buffer is as follows:
- size=avail()-300;
- where=alloc(size);
- /* initialize if needed... */
- i=0; while(i<size) {where[i]=0;}
-
- err(s) char *s;
- Prints "\nERROR" and the message pointed to by s on
- the console, and (if enabled during compilation)
- performs a walkback trace. For example, fopen uses
- the call:
- err("OUT OF DISK BUFFERS");
- The walkback trace lists the functions that have
- been called but have not yet returned, with the
- most recently called function first. Any functions
- compiled without the "profile and trace" option
- simply don't appear in the list.
-
- upper(c) char c;
- If c is a lower case character, converts it to upper
- case. Otherwise, it returns c.
-
-
- POTENTIAL IMPROVEMENTS
- Allocate buffers from the heap only when they are
- needed (would permit more disk buffers without
- penalizing programs that didn't use them).
- alloc() and free() should permit blocks of memory to be
- allocated and freed in any order.
-
-
- AUTHOR
- James R. Van Zandt
- 27 Spencer Dr.
- Nashua NH 03062
- 603-888-2272
-