home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 156_01 / iolib.doc < prev    next >
Text File  |  1985-08-21  |  4KB  |  113 lines

  1.         IOLIB Library Documentation 
  2.  
  3. IOLIB defines all the arithmetic operations, and the following
  4. I/O, heap management, and error reporting functions:
  5.  
  6.  
  7. FUNCTIONS
  8.  
  9. cpm(bc,de) int bc,de;
  10.     The registers BC and DE are set to the values of the
  11.     corresponding arguments, and a BDOS service request
  12.     (CALL to 5) is made. The value returned is the contents
  13.     of A (sign extended).
  14. getchar()
  15.     Echoes and returns one character from the standard
  16.     input, which is initially the keyboard but can be 
  17.     redirected by setargs() in the ARGS library.
  18. putchar(c) char c;
  19.     displays one character on the standard output, which is
  20.     initially the console but can be redirected by setargs()
  21.     in the ARGS library.  Adds LF after CR.  Returns c.
  22. gets(buf) char buf[80];
  23.     Gets a null-terminated string from the standard input.
  24.     If I/O has not been redirected, the string comes from
  25.     the keyboard and standard CP/M editing is permitted. The
  26.     maximum length of the string is fixed at 80 characters.
  27. puts(s) char *s;
  28.     Displays a null-terminated string on the standard
  29.     output, using putchar(). 
  30. fopen(name,mode) char *name,*mode;
  31.     Opens file "name". "mode" is a pointer to a single 
  32.     character (either upper or lower case): "r" for read
  33.     access, "w" for write access, and "a" for appending to 
  34.     an existing file. fopen returns a unit number (int) 
  35.     which must be used for subsequent file accesses. 
  36.     For example...
  37.  
  38.     u=fopen("frodo.c","r")    opens FRODO.C for reading
  39.     character=getc(u)    gets a character from FRODO.C
  40.     u=fopen("sam.c","W")    opens SAM.C for writing
  41.     putc(character,u)    writes a character to SAM.C
  42.  
  43.     Up to three files may be open at once. (If more are
  44.     needed, change NBUFS and BUFLGH in IOLIB.C, compile, 
  45.     and assemble.)
  46. fclose(u) int u;
  47.     Closes the file with the unit number u.
  48. getc(u) int u;
  49.     Returns the next character from the file (not sign
  50.     extended), or -1 at end of file. Line feeds are
  51.     discarded, and control Z (1AH) signals end of file. 
  52. getb(u) int u;
  53.     Return next byte from file (not sign extended), without
  54.     regard to its value, or -1 if at end of file. (Use this
  55.     one to read a COM file.) 
  56. putc(c,u) char c; int u;
  57.     Write character c to a file. If it is a carriage
  58.     return, write a line feed as well. Returns c.
  59. putb(c,u) char c; int u;
  60.     Write byte c to a file, without special handling of
  61.     carriage return. 
  62. fflush(u) int u;
  63.     Flush buffer for unit u (which must be an output
  64.     file) to disk. Called automatically by fclose().
  65.  
  66. alloc(n) int n;
  67.     Returns a pointer to a block of n bytes of memory
  68.     (no error checking).
  69. free(ptr) char *ptr;
  70.     ptr should be one of the pointers returned by alloc.
  71.     That block AND ALL BLOCKS ALLOCATED SINCE THEN are
  72.     returned to the heap.    
  73. avail()
  74.     Returns the number of bytes of memory available for
  75.     the heap AND THE STACK. If you allocate all of it
  76.     and write over the stack, you will cause trouble.
  77.     The safe way to get a big buffer is as follows:
  78.         size=avail()-300;
  79.         where=alloc(size);
  80.             /* initialize if needed... */
  81.         i=0; while(i<size) {where[i]=0;}
  82.  
  83. err(s) char *s;
  84.     Prints "\nERROR" and the message pointed to by s on
  85.     the console, and (if enabled during compilation)
  86.     performs a walkback trace. For example, fopen uses
  87.     the call:
  88.         err("OUT OF DISK BUFFERS");
  89.     The walkback trace lists the functions that have
  90.     been called but have not yet returned, with the
  91.     most recently called function first. Any functions
  92.     compiled without the "profile and trace" option
  93.     simply don't appear in the list.
  94.  
  95. upper(c) char c;
  96.     If c is a lower case character, converts it to upper
  97.     case. Otherwise, it returns c.
  98.  
  99.  
  100. POTENTIAL IMPROVEMENTS
  101.     Allocate buffers from the heap only when they are
  102.     needed (would permit more disk buffers without
  103.     penalizing programs that didn't use them).
  104.     alloc() and free() should permit blocks of memory to be
  105.     allocated and freed in any order.
  106.  
  107.  
  108. AUTHOR
  109.     James R. Van Zandt
  110.     27 Spencer Dr.
  111.     Nashua NH 03062
  112.     603-888-2272
  113.