home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / DLIBS.ZIP / DLIBS.DOC < prev    next >
Encoding:
Text File  |  1987-10-12  |  53.2 KB  |  1,742 lines

  1.  _________________________________________________________________________
  2. |                                      |
  3. | Replacement standard library functions for Atari ST with Alcyon C v4.14 |
  4. |       Version 1.00.0, by Dale Schumacher, last modified 10/12/87.      |
  5. |_________________________________________________________________________|
  6.  
  7.  
  8.  
  9. CONSTANTS:
  10.  
  11.     dLibs        Conditional complilation flag    (0x1000)
  12.     TRUE        Boolean true            (1)
  13.     FALSE        Boolean false            (0)
  14.     ERROR        General error value        (-1)
  15.     NULL        Null pointer            ((char *) 0)
  16.     MAXFILES    Maximum number of open streams    (20)
  17.     MAXINT        Maximum signed integer value    (32767)
  18.     MININT        Minimum signed integer value    (-32768)
  19.     BUFSIZ        Standard stream buffer size    (1024)
  20.     PATHSIZE    Maximum size of a pathname    (128)
  21.     EOF        End of file indicator        (-1)
  22.     EOS        End of string character        '\0'
  23.  
  24.  
  25. PROCESS CONTROL:
  26.  
  27. long _STKSIZ = 4096L;
  28.  
  29.     This variable defines the amount of run-time stack space to be
  30.     reserved.  The default value is 4K, which is more than enough
  31.     for most applications.  Since dynamic memory is NOT allocated
  32.     from the stack, this value need only be large enough to handle
  33.     local variables and deep recursion.
  34.  
  35. void _main(cmdline, cmdlen)
  36. char *cmdline;
  37. int cmdlen;
  38.  
  39.     Parses command line, opens standard files, plus other assorted
  40.     general setup. Then calls user's main() function.  If main()
  41.     returns, exit() is called with a 0 return value.  The following
  42.     standard streams are initialized by _main():
  43.         stdin        Standard input, may be redirected
  44.         stdout        Standard output, may be redirected
  45.         stderr        Usually the system console
  46.         stdprn        The standard printer (output only)
  47.         stdaux        The communication port (input/output)
  48.     The _initargs() function is called to process the command line.
  49.     The global variables "_argc", "_argv" and "_envp" are used to
  50.     store the values to be passed to the user's main().
  51.  
  52. void _initargs(cmdline, cmdlen)
  53. char *cmdline;
  54. int cmdlen;
  55.  
  56.     Process command line and retrieve the environment string.  This
  57.     function is responsible for allocating space to hold the parsed
  58.     command line arguments, etc.  Values to be passed to the user's
  59.     main() function are stored in the global variables "_argc",
  60.     "_argv" and "_envp".  _main() initiallizes these variables to
  61.     indicate that no arguments are available.  If a program doesn't
  62.     use command line arguments or the environment string, an
  63.     _initargs() function, which does nothing, should be defined in
  64.     the module containing main().  This will result in a smaller
  65.     executable size and a smaller run-time image.  The default
  66.     _initargs() function handles command line redirection, but does
  67.     not expand wildcards.  #ifdef's in the source code provide for
  68.     elimination of redirection processing and/or addition of wildcard
  69.     expansion. If these features are desired, a copy of _initargs(),
  70.     appropriately modified for your application, should be placed
  71.     in the module containing your main() function.
  72.  
  73. void main(argc, argv, envp)
  74. int argc;
  75. char *argv[];
  76. char *envp;
  77.  
  78.     This function is not actually in the standard libraries, but
  79.     must be present somewhere in the user's code.  The parameters
  80.     passed to it by _main() are the number of arguments in the
  81.     command line, a pointer to a list of pointers to arguments, and
  82.     a pointer to the environment string.  The return value from
  83.     main() is ignored by _main().  If the program wishes to return
  84.     a status code, it should call exit() directly.
  85.  
  86. void exit(status)
  87. int status;
  88.  
  89.     Flushes and closes all open streams.  Returns <status> value to
  90.     the operating system.
  91.  
  92. void _exit(status)
  93. int status;
  94.  
  95.     Exits the program immediately, returning <status> to the OS.
  96.  
  97. void abort()
  98.  
  99.     Prints the message "Abnormal program termination" to stderr and
  100.     calls _exit() with a status code of 3.
  101.  
  102. int getpid()
  103.  
  104.     Return an integer value unique for this process.
  105.  
  106. char *getenv(var)
  107. register char *var;
  108.  
  109.     Search for <var> in the environment.  If <var> is found, a pointer
  110.     to it's value is returned.  NULL is returned if <var> is not found.
  111.     WARNING:  The returned pointer points into the environment and
  112.     must not be modified!
  113.  
  114. int putenv(entry)
  115. char *entry;
  116.  
  117.     Add <entry> to the environment.  <entry> can be any of the following
  118.     forms:
  119.         <VARIABLE>
  120.         <VARIABLE>=
  121.         <VARIABLE>=<value>
  122.     The first form removes <VARIABLE> from the environment.  getenv()
  123.     will return NULL if looking for this variable.  The second form adds
  124.     <VARIABLE> to the environment, with a null value.  getenv() will
  125.     return a pointer to a '\0' character if looking for this variable.
  126.     Many environment handlers don't support such "tag variables", so
  127.     their use is not recommended.  The final form is the most common,
  128.     and safest to use.  <VARIABLE> is installed (or replaced) with the
  129.     value <value>.  It should be noted that the putenv() function itself
  130.     is not supported in many systems and therefore may not be portable.
  131.     In addition, care should be taken to prevent overflowing the space
  132.     allocated for the environment.  Returns TRUE for success or FALSE
  133.     for failure.  NO OVERFLOW CHECKING IS DONE.
  134.  
  135. void shell()
  136.  
  137.     Invoke a command line interface shell.  If the "SHELL" environment
  138.     variable is not defined, a prompt showing the current working
  139.     directory will be given.  Each line entered will then be passed
  140.     to the system() function for execution until the command "exit"
  141.     is entered to terminate the shell.  If "SHELL" is defined, and
  142.     the "_shell_p" variable is valid, the value of "SHELL" will be
  143.     passed to the program pointed to by "_shell_p" in order to allow
  144.     the shell to invoke a command line interaction of its own.  If
  145.     the "_shell_p" variable is not valid, the program defined by
  146.     "SHELL" will be searched for along the "PATH", and executed with
  147.     no arguments.  If the "SHELL" can't be found, the internal command
  148.     line described above will be used.
  149.  
  150. int system(command)
  151. char *command;
  152.  
  153.     Attempts to pass <command> to the shell program pointed to by
  154.     the system variable "_shell_p".  If a valid shell can't be found
  155.     there, the "SHELL" environment variable is searched for.  If it
  156.     exists and is not empty, it will be the name of the shell program
  157.     to execute the given command.  If "SHELL" is not valid, the
  158.     "PATH" variable is searched for.  This would specify the paths
  159.     to search for the program name which is the first token of the
  160.     <command>.  If "PATH" is not valid, the current directory is
  161.     searched for the given command.  The extensions tried (if none
  162.     is specified) are ".TTP", ".TOS", ".PRG" and ".APP".
  163.  
  164. int spawne(program, cmdline, envp)
  165. char *program;
  166. char *cmdline;
  167. char *envp;
  168.  
  169.     Calls the OS "Pexec" trap with the parameters specified.  Since
  170.     the OS uses a Pascal-like string for the command line, the
  171.     <cmdline> parameter, which is a normal C-string, is used to
  172.     create the actual command line which is passed to the OS trap.
  173.     Returns the value returned by the program, or -1 for errors.
  174.  
  175. int spawn(program, cmdline)
  176. char *program;
  177. char *cmdline;
  178.  
  179.     Like spawne() except that NULL is used for the environment pointer.
  180.     This causes the child to inherit a copy of the parent's environment.
  181.  
  182. int spawnpe(program, cmdline, envp)
  183. char *program;
  184. char *cmdline;
  185. char *envp;
  186.  
  187.     Operates like spawne() except that the "PATH" environment variable,
  188.     if it is valid, is used to locate the program to be executed.
  189.     Various extensions are tried, as described for system().  Returns
  190.     the value returned by the program, or -1 for errors.
  191.  
  192. int spawnp(program, cmdline)
  193. char *program;
  194. char *cmdline;
  195.  
  196.     Like spawnpe() except that NULL is used for the environment pointer.
  197.     This causes the child to inherit a copy of the parent's environment.
  198.  
  199. long gemdos(func[, arg1, ..., argN])
  200. int func;
  201.  
  202.     Call operating system trap #1 (GEMDOS) function number <func> with
  203.     the arguments given.  Returned value returned by the trap call.
  204.  
  205. long bios(func[, arg1, ..., argN])
  206. int func;
  207.  
  208.     Call operating system trap #13 (BIOS) function number <func> with
  209.     the arguments given.  Returned value returned by the trap call.
  210.  
  211. long xbios(func[, arg1, ..., argN])
  212. int func;
  213.  
  214.     Call operating system trap #14 (XBIOS) function number <func> with
  215.     the arguments given.  Returned value returned by the trap call.
  216.  
  217. int setjmp(context)
  218. jmp_buf context;
  219.  
  220.     [save <context> for longjmp(). MUST include "SETJMP.H" to use.]
  221.  
  222. void longjmp(context, rv)
  223. jmp_buf context;
  224. int rv;
  225.  
  226.     [return <rv> to <context> saved by setjmp().
  227.      MUST include "SETJMP.H" to use.]
  228.  
  229. int catch(context, func)
  230. jmp_buf context;
  231. int (*func)();
  232.  
  233.     [execute <func> with saved <context> for throw().
  234.      MUST include "SETJMP.H" to use.]
  235.  
  236. void throw(context, func)
  237. jmp_buf context;
  238. int rv;
  239.  
  240.     [return <rv> to <context> saved by catch().
  241.      MUST include "SETJMP.H" to use.]
  242.  
  243.  
  244. MEMORY MANAGEMENT:
  245.  
  246.     You may want to include "MALLOC.H" in your program if you use
  247.     functions in this section, otherwise you may have to declare
  248.     the return types for some functions.
  249.  
  250. long _BLKSIZ = 65536;
  251.  
  252.     This variable controls the granularity of system memory allocation
  253.     used by malloc(), et. al.  This is the amount of memory that is
  254.     requested from the system each time a new "heap" is needed to fill
  255.     dynamic memory requests.  To help avoid a GEMDOS bug, only 16
  256.     heaps can be active at a time.  Therefore, (16 * _BLKSIZ) defines
  257.     the maximum amount of memory which can be managed by these routines
  258.     under normal circumstances.  The exception is if any single request
  259.     for memory exceeds _BLKSIZ.  In this case, a heap will be allocated
  260.     larger than _BLKSIZ.
  261.  
  262. char *malloc(size)
  263. unsigned int size;
  264.  
  265.     Allocate at least <size> bytes of memory.  A pointer to the
  266.     requested block is returned, or NULL if there is not enough
  267.     free memory available.
  268.  
  269. char *calloc(n, size)
  270. unsigned int n;
  271. unsigned int size;
  272.  
  273.     Allocate space for an array of <n> element of <size> bytes each.
  274.     If the storage can be allocated, it is initialized to all zero.
  275.     NULL is returned is there is not enough free memory.
  276.  
  277. char *lalloc(size)
  278. long size;
  279.  
  280.     Allocate at least <size> bytes of memory.  A pointer to the
  281.     requested block is returned, or NULL if there is not enough
  282.     free memory available.
  283.  
  284. char *realloc(addr, size)
  285. char *addr;
  286. unsigned int size;
  287.  
  288.     Attempt to change the memory block at <addr> to the new <size>.
  289.     Making a block smaller will always work, but making it larger
  290.     may fail if there is not enough free memory.  If there is not
  291.     enough memory, NULL is returned and the block will still reside
  292.     at <addr>.  If realloc() succeeds, a pointer to the (possibly
  293.     moved) new block will be returned.
  294.  
  295. void free(addr)
  296. char *addr;
  297.  
  298.     Release the memory block at <addr> back into the free memory pool.
  299.     If <addr> doesn't point to a block allocated by calloc(), malloc(),
  300.     lalloc() or realloc(), very bad, unpredictable things will happen.
  301.  
  302. long msize(addr)
  303. char *addr;
  304.  
  305.     Return the size, in bytes, of the memory block at <addr>.  Note
  306.     that the size is a long value, since the block may have been
  307.     allocated by lalloc().
  308.  
  309. long memavail()
  310.  
  311.     Return the size, in bytes, of the largest block of free memory
  312.     available for allocation.  Note that this value is a long.
  313.  
  314.  
  315. FILE HANDLING:
  316.  
  317.     You may want to include "IO.H" in your program if you use
  318.     functions in this section, otherwise you may have to declare
  319.     the return types for some functions.  "IO.H" also contains
  320.     the definitions of many symbolic constants used with these
  321.     functions.
  322.  
  323. int chdir(pathname)
  324. char *pathname;
  325.  
  326.     Changes the current working directory to <pathname>.  If a
  327.     drive letter is specified in <pathname>, the current working
  328.     directory for that drive is set.  Returns 0 for success, or
  329.     a negative error code.
  330.  
  331. int mkdir(pathname)
  332. char *pathname;
  333.  
  334.     Creates a new directory called <pathname>.  A drive letter may
  335.     be specified.  Returns 0 for success, or a negative error code.
  336.  
  337. int rmdir(pathname)
  338. char *pathname;
  339.  
  340.     Removes an existing directory called <pathname>.  A drive letter may
  341.     be specified.  Returns 0 for success, or a negative error code.
  342.  
  343. char *fullpath(full, part)
  344. char *full;
  345. char *part;
  346.  
  347.     <part> is a (possibly) ambiguous file/path specification.  A
  348.     non-ambiguous file/path spec is created which includes a drive
  349.     letter and all intermediate sub-directories.  If the partial
  350.     specification is not valid, NULL is returned, otherwise a
  351.     pointer to <full> is returned.  If NULL is specified for <full>,
  352.     an internal buffer is used and a pointer to it is returned.
  353.  
  354. int access(name, amode)
  355. char *name;
  356. int amode;
  357.  
  358.     Return non-zero if a file with the given <name> can be accessed
  359.     in the given <amode>.  Possible <amode> values are:
  360.         _ACCe        file exists
  361.         _ACCr        file can be read
  362.         _ACCw        file can be written
  363.         _ACCrw        file can be read and written
  364.  
  365. char *findfile(afn[, ext])
  366. char *afn;
  367. char *ext;
  368.  
  369.     Return full file spec for <afn> if found. If <afn> has no extension,
  370.     extensions from <ext> are tried until a match is found, or the list
  371.     ends.  <ext> is a list of extensions separated by '\0' characters
  372.     and ending with an additional '\0', ie. "ttp\0tos\0prg\0" (note that
  373.     the final null is added by the compiler to any string constant.  If
  374.     <afn> already has an extension, <ext> is not used.  If no matching
  375.     files are found, NULL is returned.  The pointer returned when a match
  376.     is found points to a buffer which is internal to fullpath().  If you
  377.     want to save the value returned, you must make a copy before the
  378.     buffer is overwritten by subsequent calls.
  379.  
  380. char *pfindfile(afn[, ext])
  381. char *afn;
  382. char *ext;
  383.  
  384.     Like findfile() but search all directories listed in the environment
  385.     variable "PATH", if no match is found in the current directory. If
  386.     <afn> specifies a drive or directory, "PATH" is not used.
  387.  
  388. int stat(name, statbuf)
  389. char *name;
  390. STAT *statbuf;
  391.  
  392.     Search for file <name> and load <statbuf> with information
  393.     about that file, if it is found.  Return 0 if found, or
  394.     ERROR (-1) if no file/directory matched <name>.  Volume
  395.     labels are not included in the search.
  396.  
  397. long fsize(name)
  398. char *name;
  399.  
  400.     Return the size of the file <name> in bytes.  Note that this
  401.     is a long value.  Return -1L if the file is not found.
  402.  
  403. int isatty(h)
  404. int h;
  405.  
  406.     Return non-zero if <h> refers to a character device.  Both the
  407.     device handles (-1..-3) and the standard handles (0..5) are
  408.     considered character devices by this function.
  409.  
  410. int creat(filename, pmode)
  411. char *filename;
  412. int pmode;
  413.  
  414.     Create a new file with the given <filename>.  If a file with
  415.     the name already exists, it will be truncated to zero bytes.
  416.     Since the OS doesn't do this properly, the file is actually
  417.     deleted and then re-created.  <pmode> specifies the attributes
  418.     initially given to the file.  Valid <pmode> values are:
  419.         _CRErw        read/write
  420.         _CREro        read only
  421.         _CREh        hidden file
  422.         _CREs        system file
  423.         _CREv        volume label
  424.     If _CRErw or _CREv modes are specified, they must be the only
  425.     mode given.  Other modes may be combined with the | operator.
  426.  
  427. int chmod(filename, pmode)
  428. char *filename;
  429. int pmode;
  430.  
  431.     Change the mode attribute of <filename> to <pmode>.  Values for
  432.     <pmode> are the same as for the creat() function.  Returns 0 for
  433.     success, or a negative error code.
  434.  
  435. int open(filename, iomode)
  436. char *filename;
  437. int iomode;
  438.  
  439.     Attempt to open <filename> with the given <iomode>.  This is a
  440.     direct hook into the OS "Fopen" call.  A file handle is returned
  441.     if the open succeeds.  A negative error code is returned for
  442.     errors.  Valid <iomode> values are:
  443.         _OPNr        read mode
  444.         _OPNw        write mode
  445.         _OPNrw        read/write mode
  446.  
  447. int close(h)
  448. int h;
  449.  
  450.     Close file referenced by the file handle <h>.  Return 0 for
  451.     success, or a negative error code.
  452.  
  453. int dup(handle)
  454. int handle;
  455.  
  456.     Return a second file handle which refers to the same file as
  457.     the given <handle>.
  458.  
  459. int dup2(handle1, handle2)
  460. int handle1;
  461. int handle2;
  462.  
  463.     Force <handle2> to refer to the same file as <handle1>.  Return
  464.     0 for success, or a negative error code.  Both dup() and dup2()
  465.     are direct calls to Fdup() and Fforce() GEMDOS calls.  Refer to
  466.     your GEMDOS documentation for further information.
  467.  
  468. int unlink(filename)
  469. char *filename;
  470.  
  471.     Delete <filename>, if it exists.  Return 0 for success, or a
  472.     negative error code.
  473.  
  474. int rename(oldname, newname)
  475. char *oldname;
  476. char *newname;
  477.  
  478.     Change the name of file <oldname> to <newname>.  You may use this
  479.     function to move files from one directory (pathname) to another,
  480.     but not from one drive to another.  Return 0 for success, or a
  481.     negative error code.
  482.  
  483. long lseek(h, offset, origin)
  484. int h;
  485. long offset;
  486. int origin;
  487.  
  488.     Move file pointer for file <h> to specified location.  <origin>
  489.     specifies the starting point for the <offset> distance.  Valid
  490.     <origin> values are:
  491.         _LSKbeg        from beginning of file    (0)
  492.         _LSKcur        from current location    (1)
  493.         _LSKend        from end of file    (2)
  494.     The <offset> value is the distance in bytes from the origin.
  495.     The final file position, or a negative error code, is returned.
  496.  
  497. long tell(h)
  498. int h;
  499.  
  500.     Return the current file position for the file <h>.
  501.  
  502. FILE *fopen(filename, mode)
  503. char *filename;
  504. char *mode;
  505.  
  506.     Open <filename> as a stream file.  This is the normal open way
  507.     to open a file.  The <mode> is a string specifying the mode(s)
  508.     that are relevent to the file open.  Valid <mode> characters are:
  509.         r        read mode
  510.         w        write mode
  511.         a        append mode
  512.         b        binary mode
  513.         t        text (translated) mode
  514.     At least one of "r", "w" or "a" must be specified.  "t" is assumed
  515.     and indicates that <nl> is translated to <cr><lf> on output and
  516.     vica-versa on input.  If the stream is a character device, the
  517.     translation is slightly different.  The output translation is the
  518.     same, but on input <cr> and <lf> both become <nl> in all cases.
  519.     The "b", for binary mode, overides "t" and indicated that characters
  520.     are not translated during i/o operations.  "a" represents append
  521.     mode and means that the file pointer will initially be placed at
  522.     the end of the file.  "w" mode will create a file if it doesn't
  523.     exists, or zero an existing file.  If "r" is the only mode specified,
  524.     the file must already exist.  A (FILE *) is returned if the open
  525.     succeeds, or NULL if it fails.
  526.  
  527. FILE *freopen(filename, mode, fp)
  528. char *filename;
  529. char *mode;
  530. FILE *fp;
  531.  
  532.     Closes the file associated with <fp> and opens the new file as with
  533.     fopen(), except that a new FILE structure is not created.  The
  534.     existing FILE structure pointed to by <fp> is re-initialized with
  535.     the new file information.  This is typically used to redirect i/o
  536.     to standard streams "stdin", "stdout", "stderr", "stdprn", "stdaux".
  537.     <fp> is returned for success, or NULL for failure.
  538.  
  539. FILE *fdopen(h, mode)
  540. int h;
  541. char *mode;
  542.  
  543.     Associates a stream with the already open file <h>.  The <mode>
  544.     values are the same as for fopen(), but MUST be compatible with
  545.     the mode in which <h> was open()ed.  This functions allows use
  546.     of a file opened with the low level open()/creat() calls to be
  547.     used as a buffered/translated stream.  A pointer to a FILE struct
  548.     is returned, or NULL for errors.
  549.  
  550. int fclose(fp)
  551. FILE *fp;
  552.  
  553.     Close the stream <fp>, flushing the buffer.  Returns 0 on success.
  554.  
  555. void setbuf(fp, buf)
  556. FILE *fp;
  557. char *buf;
  558.  
  559.     If <buf> is NULL, make <fp> unbuffered; else <buf> points to a buffer
  560.     of BUFSIZ characters to be used as the stream buffer for <fp>.
  561.  
  562. void setvbuf(fp, buf, bmode, size)
  563. FILE *fp;
  564. char *buf;
  565. int bmode;
  566. unsigned int size;
  567.  
  568.     If <buf> is NULL or <bmode> is _SVBn, make <fp> unbuffered;
  569.     otherwise <buf> points to a buffer of <size> characters to be
  570.     used as the stream buffer for <fp>.  The <bmode> variable
  571.     indicates the type of buffering desired, as follows:
  572.         _SVBn        No buffering
  573.         _SVBf        Full buffering (normal)
  574.         _SVBl        Line buffering (not supported, same as _SVBf)
  575.  
  576. long fseek(fp, offset, origin)
  577. FILE *fp;
  578. long offset;
  579. int origin;
  580.  
  581.     Operates like lseek(), except it works on streams.  Note that
  582.     stream file positions may be misleading due to translation of
  583.     <nl> characters during i/o.  ftell() may be used reliably with
  584.     fseek() to reposition a file to a prior location.
  585.  
  586. void rewind(fp)
  587. FILE *fp;
  588.  
  589.     Operates like fseek(fp, 0L, _LSKbeg), except it also clears the
  590.     end-of-file and error flags for <fp>.  There is no return value.
  591.  
  592. long ftell(fp)
  593. FILE *fp;
  594.  
  595.     Operates like tell(), except it works on streams.  Note that
  596.     stream file positions may be misleading due to translation of
  597.     <nl> characters during i/o.
  598.  
  599. int fileno(fp)
  600.  
  601.     Return the file handle associated with the stream <fp>.
  602.  
  603. int feof(fp)
  604.  
  605.     Return non-zero if <fp>    is at end of file.
  606.  
  607. int ferror(fp)
  608.  
  609.     Return non-zero if and error has occurred on <fp>.
  610.  
  611. void clearerr(fp)
  612.  
  613.     Clear the error flag on <fp>.
  614.  
  615.  
  616. INPUT/OUTPUT FUNCTIONS:
  617.  
  618.     You may want to include "IO.H" in your program if you use
  619.     functions in this section, otherwise you may have to declare
  620.     the return types for some functions.  "IO.H" also contains
  621.     the definitions of many symbolic constants used with these
  622.     functions.
  623.  
  624. int read(h, data, length)
  625. int h;
  626. char *data;
  627. int length;
  628.  
  629.     Read <length> bytes from the file reference by file handle <h>.
  630.     Data is stored in the buffer pointed to by <data>.  The number
  631.     of bytes actually read is returned, 0 for end of file, or a
  632.     negative error code.  Note that the maximum number of bytes
  633.     that can be read by this function is MAXINT.
  634.  
  635. long lread(h, data, length)
  636. int h;
  637. char *data;
  638. long length;
  639.  
  640.     Same as read(), but uses a long value for number of bytes to read.
  641.  
  642. int write(h, data, length)
  643. int h;
  644. char *data;
  645. int length;
  646.  
  647.     Write <length> bytes to the file reference by file handle <h>.
  648.     Data is written from the buffer pointed to by <data>.  The number
  649.     of bytes actually written is returned, or a negative error code.
  650.     Note that the maximum number of bytes that can be written by
  651.     this function is MAXINT.
  652.  
  653. long lwrite(h, data, length)
  654. int h;
  655. char *data;
  656. long length;
  657.  
  658.     Same as write(), but uses a long value for number of bytes to write.
  659.  
  660. int fread(data, size, count, fp)
  661. char *data;
  662. int size;
  663. int count;
  664. FILE *fp;
  665.  
  666.     Read <count> items of <size> characters each from stream <fp>.
  667.     Data is stored in the buffer pointed to by <data>.  The number of
  668.     full items actually read is returned, or a negative error code.
  669.     This call DOES NOT translate characters, even if the stream is
  670.     opened in translate mode.
  671.  
  672. int fwrite(data, size, count, fp)
  673. char *data;
  674. int size;
  675. int count;
  676. FILE *fp;
  677.  
  678.     Write <count> items of <size> characters each to stream <fp>.
  679.     Data is read from the buffer pointed to by <data>.  The number of
  680.     full items actually written is returned, or a negative error code.
  681.     This call DOES NOT translate characters, even if the stream is
  682.     opened in translate mode.
  683.  
  684. int fgetc(fp)
  685. FILE *fp;
  686.  
  687.     Get a character from <fp>.  Returns the character or EOF.
  688.  
  689. int fungetc(c, fp)
  690. char c;
  691. FILE *fp;
  692.  
  693.     Push the character <c> back to be gotten by the next fgetc()
  694.     call on <fp>.  Only 1 character may be ungotten at a time on
  695.     each stream.  Subsequent calls to fungetc() will write over
  696.     the currently saved character.
  697.  
  698. int fputc(c, fp)
  699. char c;
  700. FILE *fp;
  701.  
  702.     Put the character <c> to the stream <fp>.
  703.  
  704. int fflush(fp)
  705. FILE *fp;
  706.  
  707.     Flush the output buffer of the stream <fp>.  The buffer is
  708.     automatically flushed when it is full, the stream is closed,
  709.     or the program terminates through exit().  This function has
  710.     no effect if the stream in unbuffered.
  711.  
  712. int getc(fp)
  713. FILE *fp;
  714.  
  715.     Same as fgetc() but implemented as a macro.
  716.  
  717. int ungetc(c, fp)
  718. char c;
  719. FILE *fp;
  720.  
  721.     Same as fungetc() but implemented as a macro.
  722.  
  723. int putc(c, fp)
  724. char c;
  725. FILE *fp;
  726.  
  727.     Same as fputc() but implemented as a macro.
  728.  
  729. int getw(fp)
  730. FILE *fp;
  731.  
  732.     Get a 2-byte value from the stream <fp>.  The high-order byte is
  733.     read first.
  734.  
  735. int putw(n, fp)
  736. int n;
  737. FILE *fp;
  738.  
  739.     Put the 2-byte value <n> to the stream <fp>.  The high-order byte
  740.     is written first.
  741.  
  742. int getchar()
  743.  
  744.     Same as "fgetc(stdin)".
  745.  
  746. int ungetchar(c)
  747. char c;
  748.  
  749.     Same as "fungetc(c, stdin)".  Note that this name will
  750.     conflict with any function beginning "ungetch..." due to
  751.     having only 7 significant characters in Alcyon C v4.14.
  752.  
  753. int putchar(c)
  754. char c;
  755.  
  756.     Same as "fputc(c, stdin)".
  757.  
  758. int cfg_ch(cfg)
  759. int cfg;
  760.  
  761.     Configure getch()/putch() operation.  The following are legal
  762.     values for <cfg> and may be combined with the | operator:
  763.         _CIOb        Use BIOS level i/o calls
  764.         _CIOch        8-bit character codes only (cf:getch)
  765.         _CIOvt        Enable VT-52 escape sequence processing
  766.     The initial configuration value at run time is _CIOch.
  767.  
  768. int getch()
  769.  
  770.     Machine dependent console input function.  This function normally
  771.     gets a character from the keyboard by calling the GEMDOS "Cconin"
  772.     function.  If cfg_ch() is given the _CIOb option, input is gotten
  773.     from the BIOS "Bconin" function instead.  The BIOS level functions
  774.     don't process ^C, ^S or ^Q, while the GEMDOS functions do.  The
  775.     most common use for getch() is when keyboard scan codes are needed
  776.     to process special function keys.  The return value from getch()
  777.     consists of the scan code in the high-order byte, and the ascii
  778.     character code in the low-order byte.  If cfg_ch() is given the
  779.     _CIOch option, the return value is always an 8-bit quantity,
  780.     either the scan code with the 8th bit set, or the ascii code with
  781.     the 8th bit clear.  This is somewhat less informative, since the
  782.     scan code form is returned only if the ascii value is 0, but is the
  783.     default configuration value for compatability with Microsoft C.
  784.     In any case, the global unsigned long variable "_getch" will contain
  785.     the full character code value returned by the OS.
  786.  
  787. int getche()
  788.  
  789.     Same as getch() but calls putch() to echo the character.
  790.  
  791. char putch(c)
  792. char c;
  793.  
  794.     Machine dependent (typically quite fast) console output function.
  795.     This function normally puts a character to the console by calling
  796.     the GEMDOS "Cconout" function.  If cfg_ch() is given the _CIOb
  797.     option, output is sent to the BIOS "Bconout" function instead.
  798.     The BIOS level functions don't process ^C, ^S or ^Q, while the
  799.     GEMDOS functions do.  At the BIOS level, the _CIOvt option to
  800.     cfg_ch() allows VT-52 escape code processing on output.  The
  801.     GEMDOS function always does VT-52 emulation.  The BIOS function
  802.     defaults to skipping this overhead, but if VT-52 emulation is
  803.     desired, it can still be used through the faster BIOS level
  804.     routine    by using the _CIOvt option.  Control codes, like '\b'
  805.     and '\r', are supported even without VT-52 emulation.  The return
  806.     value of this function is simply the character sent.
  807.  
  808. int kbhit()
  809.  
  810.     Machine dependent function to detect if input is waiting for the
  811.     getch() function.  Returns non-zero if the console has data ready.
  812.  
  813. char *getln(ip, get, put, buffer, limit)
  814. char *ip;
  815. int (*get)();
  816. int (*put)();
  817. char *buffer;
  818. int limit;
  819.  
  820.     Get a line of input from the user.  Allow simple editing of the line
  821.     with BS/DEL, ESC, and CR/LF to terminate input.  Characters are
  822.     retreived by a (*get)(ip) and echoed with (*put)(c).  A pointer to
  823.     <buffer> is returned in any case.
  824.  
  825. char *fgets(data, limit, fp)
  826. char *data;
  827. int limit;
  828. FILE *fp;
  829.  
  830.     Get data from <fp> and puts it in the <data> buffer.  At most,
  831.     <limit>-1 characters will be read.  Input will also be terminated
  832.     when a newline is read.  <data> will be '\0' terminated and the
  833.     newline, if read, will be included.  A pointer to the start of
  834.     <data> is returned, or NULL for EOF.
  835.  
  836. void fputs(data, fp)
  837. char *data;
  838. FILE *fp;
  839.  
  840.     Write the characters in <data> to the stream <fp>.  A newline
  841.     WILL NOT be added.
  842.  
  843. char *gets(data)
  844. char *data;
  845.  
  846.     Get data from stdin and puts it in the <data> buffer.  Input is
  847.     terminated when a newline is read.  The    newline will be replaced
  848.     by a '\0' to terminate the string.  A backspace character will
  849.     remove the preceeding character from the buffer, but will not
  850.     backspace past the start of the buffer.  A pointer to the start
  851.     of <data> is returned, or NULL for EOF.
  852.  
  853. void puts(data)
  854. char *data;
  855.  
  856.     Write the characters in <data> to stdout.  A newline WILL be
  857.     written after the data.
  858.  
  859. void cputs(data)
  860. char *data;
  861.  
  862.     Write the characters in <data> directly to the console using the
  863.     system dependent putch() function.  A newline WILL NOT be written
  864.     after the data.
  865.  
  866. int fprintf(fp, fmt[, arg1, ..., argN])
  867. FILE *fp;
  868. char *fmt;
  869.  
  870.     Formatted output to the stream <fp>.  See the _printf() function
  871.     for a description of the <fmt> formatting string.
  872.  
  873. int printf(fmt[, arg1, ..., argN])
  874. char *fmt;
  875.  
  876.     Formatted output to the stdout stream.  See the _printf() function
  877.     for a description of the <fmt> formatting string.
  878.  
  879. int sprintf(buf, fmt[, arg1, ..., argN])
  880. char *buf;
  881. char *fmt;
  882.  
  883.     Formatted output to the string <s>.  See the _printf() function
  884.     for a description of the <fmt> formatting string.
  885.  
  886. int cprintf(fmt[, arg1, ..., argN])
  887. char *fmt;
  888.  
  889.     Formatted output directly to the console.  This functions uses the
  890.     system dependent putch() for output.  See the _printf() function
  891.     for a description of the <fmt> formatting string.
  892.  
  893. int fscanf(fp, fmt[, arg1, ..., argN])
  894. FILE *fp;
  895. char *fmt;
  896.  
  897.     Formatted input from the stream <fp>.  See the _scanf() function
  898.     for a description of the <fmt> formatting string.
  899.  
  900. int scanf(fmt[, arg1, ..., argN])
  901. char *fmt;
  902.  
  903.     Formatted input from the stdin stream.  See the _scanf() function
  904.     for a description of the <fmt> formatting string.
  905.  
  906. int sscanf(buf, fmt[, arg1, ..., argN])
  907. char *buf;
  908. char *fmt;
  909.  
  910.     Formatted input from the string <s>.  See the _scanf() function
  911.     for a description of the <fmt> formatting string.
  912.  
  913.  
  914. FORMATTING/TYPE CONVERSION:
  915.  
  916. int _printf(op, put, fmt, args)
  917. char *op;
  918. int (*put)();
  919. char *fmt;
  920. int *args;
  921.  
  922.     <fmt> points to a format control string.  <args> pointers to a
  923.     list of arguments.  The format string is used to create and output
  924.     stream with the arguments.  The <put> function is used to output
  925.     each character.  The <op> parameter is given to the <put> function
  926.     to specify the output stream.  Calls to <put> are of the form:
  927.     "(*put)(c, op);" where <c> is the character to output.  The format
  928.     string is composed of characters and format specifications.  The
  929.     '%' character introduces a format specifier.  The general form of
  930.     a format specifier is:
  931.         %[-][ |+][0][<width>|*][.[<precision>|*]][l]{d|i|u|o|x|b|c|s}
  932.     The '-' specifies left justification.  The ' ' or '+' specifies
  933.     the character which preceeds positive numeric values.  The '0'
  934.     specifies that numeric fields will be padded with '0' rather than
  935.     ' '.  The <width> field is a numeric value specifying a minimum
  936.     field width.  The <precision> field is a numeric value specifying
  937.     the maximum number of data characters to display.  If '*' is
  938.     specified for the width or the precision, an "int" value is taken
  939.     from the argument list and used for that value.  If no width is
  940.     specified, the field width varies according to the data width.  If
  941.     no precision is specified, all data characters are included in the
  942.     data width.  If the data width exceeds the field width, the field
  943.     width will expand to allow all data characters to be printed.
  944.     Including the 'l' or capitalizing the trailing character specifies
  945.     that the associated value is a "long" type.  The trailing character
  946.     specifies the format type, as follows:
  947.         d    Signed decimal integer
  948.         i    same as 'd'
  949.         u    Unsigned decimal integer
  950.         o    Unsigned octal integer
  951.         x    Unsigned hexadecimal integer
  952.         b    Unsigned binary integer
  953.         c    Character
  954.         s    String
  955.     If the character following the '%' is not recognized, it is
  956.     simply passed along to the output stream, thus "%%" is used to
  957.     print a single '%' character.
  958.  
  959. char *ltoa(n, buffer, radix)
  960. long n;
  961. char *buffer;
  962. int radix;
  963.  
  964.     Convert the long value <n> to a string in <buf> using <radix>
  965.     as the number base.  If <n> is negative, '-' will be the first
  966.     character in <buf>.  A pointer to <buf> is returned.
  967.  
  968. char *ultoa(n, buffer, radix)
  969. unsigned long n;
  970. char *buffer;
  971. int radix;
  972.  
  973.     Convert the unsigned long value <n> to a string in <buf> using
  974.     <radix>    as the number base.  A pointer to <buf> is returned.
  975.  
  976. char *itoa(n, buffer, radix)
  977. int n;
  978. char *buffer;
  979. int radix;
  980.  
  981.     Convert the integer value <n> to a string in <buf> using <radix>
  982.     as the number base.  If <n> is negative, '-' will be the first
  983.     character in <buf>.  A pointer to <buf> is returned.
  984.  
  985. long atol(number)
  986. char *number;
  987.  
  988.     Convert the string <number> to a long value.  Leading whitespace
  989.     is ignored, a leading +/- is optional.  Characters are processed
  990.     until a non-digit is reached.  Return value is undefined in an
  991.     overflow situation.
  992.  
  993. int atoi(number)
  994. char *number;
  995.  
  996.     Convert the string <number> to an int value.  Leading whitespace
  997.     is ignored, a leading +/- is optional.  Characters are processed
  998.     until a non-digit is reached.  Return value is undefined in an
  999.     overflow situation.
  1000.  
  1001. int _scanf(ip, get, unget, fmt, args)
  1002. char *ip;
  1003. int (*get)();
  1004. int (*unget)();
  1005. char *fmt;
  1006. char **args;
  1007.  
  1008.     <fmt> points to a format control string.  <args> pointers to a
  1009.     list of arguments, each of which is the address of a variable in
  1010.     which input data may be stored.  The format string is used to
  1011.     control reading of characters from the <get> function.  As each
  1012.     character is needed <get> is called in the form "c = (*get)(ip);"
  1013.     where <c> is the character read (negative for errors) and <ip> is
  1014.     the auxiliary pointer specified by the <ip> parameter.  If a
  1015.     character needs to be un-gotten, a call to <unget> of the form
  1016.     "(*unget)(c, ip);" is made.  The format string is composed of
  1017.     characters and format specifications.  Any characters in <fmt>,
  1018.     except whitespace characters, which are not part of a format
  1019.     specifier are expected to be matched one-to-one by characters in
  1020.     the input stream.  Scanning terminates if a mismatch occurs or if
  1021.     any call to <get> results in an error.  Whitespace characters
  1022.     match 0 or more whitespace characters in the input stream.  The
  1023.     '%' character introduces a format specifier.  The general form
  1024.     of a format specifier is:
  1025.          %[*][<width>][l|h]{d|u|o|x|b|i|c|s}
  1026.     The '*' specifies that a field is to be scanned by not stored.
  1027.     No variable pointer should be provided for non-stored format
  1028.     specs.  The <width> field specifies that maximum number of
  1029.     characters to be process to fill the given format type.  Less
  1030.     than <width> characters will be processed if the field ends
  1031.     before <width> characters have been processed.  A field ends when
  1032.     either a whitespace character, or a character which does not fit
  1033.     the specified format, is read.  The preceding 'l' specifies that
  1034.     the associated variable is a "long" type.  The trailing character
  1035.     specifies the format type, as follows:
  1036.         d Signed decimal integer
  1037.         u Unsigned decimal integer
  1038.         o Unsigned octal integer
  1039.         x Unsigned hexadecimal integer
  1040.         b Unsigned binary integer
  1041.         i Unsigned decimal/octal/hexadecimal/binary integer
  1042.         c Character
  1043.         s String
  1044.     If a <width> is specified with the 'c' format, exactly <width>
  1045.     characters (including whitespace) are read from the input stream,
  1046.     and written to a string.  No '\0' character is added If the
  1047.     character following the '%' is not recognized, it is expected to
  1048.     match the input stream as a non-format character, thus "%%" is
  1049.     used to match a single '%' character.  One additional conversion is
  1050.     the brace-format.  Shown as "%[...]", the '...' represent a list of
  1051.     characters.  If the first character in the list is a '^', the field
  1052.     contains any characters NOT in the list (starting with the 1st
  1053.     character after the '^').  If the first character of the list is
  1054.     not a '^', then the field will only contain those characters found
  1055.     in the list.  The field will be stored as a null terminated string.
  1056.     Unlike most of the other formats, this conversion does allow the
  1057.     programmer to specify that whitespace characters will be included
  1058.     in the resulting string.
  1059.  
  1060. char *ctlcnv(string)
  1061. char *string;
  1062.  
  1063.     Convert \<char> notation in <string> to actual characters.  This
  1064.     is useful for reading strings from a stream when you want to allow
  1065.     insertion of control character or other characters that may have
  1066.     special meaning otherwise, or may not otherwise be allowed.  The
  1067.     following formats are supported:
  1068.         \n        newline or linefeed
  1069.         \r        carriage return
  1070.         \0        null character (value 0)
  1071.         \b        backspace
  1072.         \t        horizontal tab
  1073.         \v        vertical tab
  1074.         \f        form feed
  1075.         \a        alarm (bell)
  1076.         \\        backslash
  1077.         \'        single quote
  1078.         \"        double quote
  1079.         \NNN        octal constant
  1080.         \xNN        hexadecimal constant
  1081.         \<nl>        "folded" line (both characters removed)
  1082.     A pointer to the modified <string> is returned.
  1083.  
  1084.  
  1085. STRING MANIPULATION:
  1086.  
  1087.     You may want to include "STRING.H" in your program if you use
  1088.     functions in this section, otherwise you'll have to declare the
  1089.     return types for any functions you use.
  1090.  
  1091. char *blkcpy(dest, source, len)
  1092. char *dest;
  1093. char *source;
  1094. int len;
  1095.  
  1096.     Copies the <source> block to the <dest>.  <len> bytes are
  1097.     always copied.  No terminator is added to <dest>.  A pointer
  1098.     to <dest> is returned.  Overlap checking IS done.
  1099.  
  1100. char *lblkcpy(dest, source, len)
  1101. char *dest;
  1102. char *source;
  1103. long len;
  1104.  
  1105.     Same as blkcpy() except a long value is used for <len>.
  1106.  
  1107. char *blkfill(dest, data, len)
  1108. char *dest;
  1109. char data;
  1110. int len;
  1111.  
  1112.     Fill <dest> will <len> bytes of <data>.  A pointer to <dest>
  1113.     is returned.
  1114.  
  1115. int blkcmp(blk1, blk2, len)
  1116. char *blk1;
  1117. char *blk2;
  1118. int len;
  1119.  
  1120.     Lexicographically compare the two blocks.  Return a value
  1121.     indicating the relationship between the blocks.  Possible
  1122.     return values are:
  1123.         negative    blk1 < blk2
  1124.         0        blk1 == blk2
  1125.         positive    blk1 > blk2
  1126.     <len> bytes are always compared.
  1127.  
  1128. int blkicmp(blk1, blk2, len)
  1129. char *blk1;
  1130. char *blk2;
  1131. int len;
  1132.  
  1133.     Compare blocks as with blkcmp(), but ignore the case of any
  1134.     alphabetic characters.
  1135.  
  1136. char *memcpy(dst, src, cnt)
  1137. char *dst;
  1138. char *src;
  1139. int cnt;
  1140.  
  1141.     Same as blkcpy().
  1142.  
  1143. char *memccpy(dst, src, c, cnt)
  1144. char *dst;
  1145. char *src;
  1146. char c;
  1147. int cnt;
  1148.  
  1149.     Copy bytes from <src> to <dst> until either <cnt> bytes have been
  1150.     copied, or the character <c> has been copied.  Returns <dst>.
  1151.  
  1152. char *memset(dst, c, cnt)
  1153. char *dst;
  1154. char c;
  1155. int cnt;
  1156.  
  1157.     Same as blkfill().
  1158.  
  1159. char *memchr(buf, c, cnt)
  1160. char *buf;
  1161. char c;
  1162. int cnt;
  1163.  
  1164.     Search the first <cnt> bytes of <buf> for <c>.  Returns a pointer to
  1165.     the matching character, or NULL if not found.
  1166.  
  1167. int memcmp(buf1, buf2, cnt)
  1168. char *buf1;
  1169. char *buf2;
  1170. int cnt;
  1171.  
  1172.     Same as blkcmp().
  1173.  
  1174. int memicmp(buf1, buf2, cnt)
  1175. char *buf1;
  1176. char *buf2;
  1177. int cnt;
  1178.  
  1179.     Same as blkicmp().
  1180.  
  1181. int strlen(string)
  1182. char *string;
  1183.  
  1184.     Returns the number of characters in a string, not including the
  1185.     terminating '\0'.
  1186.  
  1187. char *strcpy(dest, source)
  1188. char *dest;
  1189. char *source;
  1190.  
  1191.     Copies the <source> string to the <dest> including the '\0'.  A
  1192.     pointer to the start of <dest> is returned.
  1193.  
  1194. char *strncpy(dest, source, limit)
  1195. char *dest;
  1196. char *source;
  1197. int limit;
  1198.  
  1199.     Copies the <source> string to the <dest>.  At most, <limit>
  1200.     characters are copied.  If <source> ends before <limit> characters
  1201.     have been copied, the '\0' is copied, otherwise <dest> is not
  1202.     terminated by the copy.
  1203.  
  1204. char *strdup(string)
  1205. char *string;
  1206.  
  1207.     Create a copy of <string> and return a pointer to the copy.
  1208.  
  1209. char *strset(string, c)
  1210. char *string;
  1211. char c;
  1212.  
  1213.     Fill <string> with <c> up the the terminating '\0' of <string>.
  1214.  
  1215. char *strnset(string, c, n)
  1216. char *string;
  1217. char c;
  1218. int n;
  1219.  
  1220.     Fill at most <n> characters of <string> with <c>, up the the
  1221.     terminating '\0' of <string>.
  1222.  
  1223. char *substr(dest, source, start, end)
  1224. char *dest;
  1225. char *source;
  1226. int start;
  1227. int end;
  1228.  
  1229.     Copy characters from <source> to <dest> starting with character
  1230.     <start> and ending with <end>.  A pointer to <dest>, which will
  1231.     be '\0' terminated, is returned.
  1232.  
  1233. char *subnstr(dest, source, start, length)
  1234. char *dest;
  1235. char *source;
  1236. int start;
  1237. int length;
  1238.  
  1239.     Copy <length> characters from <source> to <dest> starting with
  1240.     character <start>.  A pointer to <dest>, which will be '\0'
  1241.     terminated, is returned.
  1242.  
  1243. char *strcat(dest, source)
  1244. char *dest;
  1245. char *source;
  1246.  
  1247.     Concatenate <source> on the end of <dest>.  The terminator of
  1248.     <dest> will be overwritten by the first character of <source>.
  1249.     The termintor from <source> will be copied.  A pointer to
  1250.     the modified <dest> is returned.
  1251.  
  1252. char *strncat(dest, source, limit)
  1253. char *dest;
  1254. char *source;
  1255. int limit;
  1256.  
  1257.     Concatenate <limit> characters from <source> onto <dest>.  If
  1258.     <source> contains less than <limit> characters, the length of
  1259.     source is used for <limit>.  The terminating '\0' is always
  1260.     added.  A pointer to <dest> is returned.
  1261.  
  1262. char *strupr(string)
  1263. char *string;
  1264.  
  1265.     Convert all alphabetic characters in <string> to upper case.
  1266.  
  1267. char *strlwr(string)
  1268. char *string;
  1269.  
  1270.     Convert all alphabetic characters in <string> to lower case.
  1271.  
  1272. char *strrev(string)
  1273. char *string;
  1274.  
  1275.     Reverse the order of the characters in <string> in place.
  1276.  
  1277. int strcmp(str1, str2)
  1278. char *str1;
  1279. char *str2;
  1280.  
  1281.     Lexicographically compare the two strings.  Return a value
  1282.     indicating the relationship between the strings.  Possible
  1283.     return values are:
  1284.         negative    str1 < str2
  1285.         0        str1 == str2
  1286.         positive    str1 > str2
  1287.  
  1288. int strncmp(str1, str2, limit)
  1289. char *str1;
  1290. char *str2;
  1291. int limit;
  1292.  
  1293.     Compare strings as with strcmp(), but limit comparison to the
  1294.     <limit> characters.
  1295.  
  1296. int stricmp(str1, str2)
  1297. char *str1;
  1298. char *str2;
  1299.  
  1300.     Compare strings as with strcmp(), but ignore the case of any
  1301.     alphabetic characters.
  1302.  
  1303. int strnicmp(str1, str2, limit)
  1304. char *str1;
  1305. char *str2;
  1306. int limit;
  1307.  
  1308.     Compare strings as with strncmp(), but ignore the case of any
  1309.     alphabetic characters.
  1310.  
  1311. char *strstr(string, pattern)
  1312. char *string;
  1313. char *pattern;
  1314.  
  1315.     Return a pointer to the first occurance of <pattern> in <string>.
  1316.     NULL is returned if <pattern> is not found.
  1317.  
  1318. char *stristr(string, pattern)
  1319. char *string;
  1320. char *pattern;
  1321.  
  1322.     Same as strstr(), but ignore the case of any alphabetic characters.
  1323.  
  1324. char *strchr(string, symbol)
  1325. char *string;
  1326. char symbol;
  1327.  
  1328.     Return a pointer to the first occurance of <symbol> in <string>.
  1329.     NULL is returned if <symbol> is not found.
  1330.  
  1331. char *strrchr(string, symbol)
  1332. char *string;
  1333. char symbol;
  1334.  
  1335.     Return a pointer to the last occurance of <symbol> in <string>.
  1336.     NULL is returned if <symbol> is not found.
  1337.  
  1338. int strpos(string, symbol)
  1339. char *string;
  1340. char symbol;
  1341.  
  1342.     Return the index of the first occurance of <symbol> in <string>.
  1343.     -1 is returned if <symbol> is not found.
  1344.  
  1345. int strrpos(string, symbol)
  1346. char *string;
  1347. char symbol;
  1348.  
  1349.     Return the index of the last occurance of <symbol> in <string>.
  1350.     -1 is returned if <symbol> is not found.
  1351.  
  1352. int strspn(string, set)
  1353. char *string;
  1354. char *set;
  1355.  
  1356.     Return the length of the sub-string of <string> that consists
  1357.     entirely of characters found in <set>.  The terminating '\0'
  1358.     in <set> is not considered part of the match set.  If the first
  1359.     character if <string> is not in <set>, 0 is returned.
  1360.  
  1361. int strcspn(string, symbol)
  1362. char *string;
  1363. char *set;
  1364.  
  1365.     Return the length of the sub-string of <string> that consists
  1366.     entirely of characters not found in <set>.  The terminating '\0'
  1367.     in <set> is not considered part of the match set.  If the first
  1368.     character if <string> is in <set>, 0 is returned.
  1369.  
  1370. char *strpbrk(string, set)
  1371. char *string;
  1372. char *set;
  1373.  
  1374.     Return a pointer to the first occurace in <string> of any
  1375.     character in <set>.
  1376.  
  1377. char *strrpbrk(string, set)
  1378. char *string;
  1379. char *set;
  1380.  
  1381.     Return a pointer to the last occurace in <string> of any
  1382.     character in <set>.
  1383.  
  1384. char *strtok(string, delim)
  1385. char *string;
  1386. char *delim;
  1387.  
  1388.     Return a token from <string>.  If <string> is not NULL, it is
  1389.     the beginning of a string from which tokens are to be extracted.
  1390.     Characters found in <delim> are skipped over to find the start
  1391.     of a token, characters are then accumulated until a character in
  1392.     <delim> is found, or the terminator of <string> is reached.
  1393.     A pointer to the '\0' terminated token is then returned.  Note
  1394.     that this function modifies <string> (by inserting '\0's) in
  1395.     the process.  Subsequent calls to strtok() may specify NULL as
  1396.     the <string> argument, in which case subsequent tokens are
  1397.     returned, or NULL if there are no more tokens.
  1398.  
  1399. char *strtrim(string, junk)
  1400. char *string;
  1401. char *junk;
  1402.  
  1403.     Remove leading and trailing characters found in <junk>
  1404.     from <string>.  Return a pointer to the modified <string>.
  1405.  
  1406. char *stradj(string, dir)
  1407. char *string;
  1408. int dir;
  1409.  
  1410.     Adjust <string> by adding space if <dir> is positive, or removing
  1411.     space if <dir> is negative.  The magnitude of <dir> is the number
  1412.     of character positions to add or remove.  Characters are added or
  1413.     removed at the beginning of <string>.  A pointer to the modified
  1414.     <string> is returned.
  1415.  
  1416. int strrpl(string, ptrn, rpl, n)
  1417. char *string;
  1418. char *ptrn;
  1419. char *rpl;
  1420. int n;
  1421.  
  1422.     Replace at most <n> occurances of <ptrn> in <string> with <rpl>.
  1423.     If <n> is -1, replace all.  Return the number of replacments.
  1424.  
  1425. int strirpl(string, ptrn, rpl, n)
  1426. char *string;
  1427. char *ptrn;
  1428. char *rpl;
  1429. int n;
  1430.  
  1431.     Same as strrpl() except ignore the case of alphabetic characters.
  1432.  
  1433.  
  1434. CHARACTER FUNCTIONS:
  1435.  
  1436.     To use the functions in this section, you must include "CTYPE.H"
  1437.     in your source file.  Please note that the isXXXX() functions,
  1438.     except isascii(), only have defined results if isascii() is true.
  1439.     (ie. they only work properly on values 0x00 through 0x7F)
  1440.  
  1441. int toupper(c)
  1442. int c;
  1443.  
  1444.     Convert <c> to upper case, if alphabetic.  This is implemeted
  1445.     as a macro and also as a function.  You may force use of the
  1446.     function version rather than the macro (which evaluates its
  1447.     argument twice) by using the "#undef toupper" directive.
  1448.  
  1449. int tolower(c)
  1450. int c;
  1451.  
  1452.     Convert <c> to lower case, if alphabetic.  This is implemeted
  1453.     as a macro and also as a function.  You may force use of the
  1454.     function version rather than the macro (which evaluates its
  1455.     argument twice) by using the "#undef tolower" directive.
  1456.  
  1457. int _toupper(c)
  1458. int c;
  1459.  
  1460.     This macro should be used only if <c> is known to be lower case.
  1461.     It converts <c> to upper case.  Results are undefined if converting
  1462.     a character which is not lower case.
  1463.  
  1464. int _tolower(c)
  1465. int c;
  1466.  
  1467.     This macro should be used only if <c> is known to be upper case.
  1468.     It converts <c> to lower case.  Results are undefined if converting
  1469.     a character which is not upper case.
  1470.  
  1471. int toascii(c)
  1472. int c;
  1473.  
  1474.     Convert <c> to 7-bit ascii, putting it into the range 0x00..0x7F.
  1475.  
  1476. int isalnum(c)
  1477. int c;
  1478.  
  1479.     Return non-zero if <c> is '0'..'9','A'..'Z','a'..'z'.
  1480.  
  1481. int isalpha(c)
  1482. int c;
  1483.  
  1484.     Return non-zero if <c> is 'A'..'Z','a'..'z'.
  1485.  
  1486. int isascii(c)
  1487. int c;
  1488.  
  1489.     Return non-zero if <c> is 0x00..0x7F.
  1490.  
  1491. int iscntrl(c)
  1492. int c;
  1493.  
  1494.     Return non-zero if <c> is 0x00..0x1F,0x7F.
  1495.  
  1496. int isdigit(c)
  1497. int c;
  1498.  
  1499.     Return non-zero if <c> is '0'..'9'.
  1500.  
  1501. int islower(c)
  1502. int c;
  1503.  
  1504.     Return non-zero if <c> is 'a'..'z'.
  1505.  
  1506. int isprint(c)
  1507. int c;
  1508.  
  1509.     Return non-zero if <c> is 0x20..0x7E.
  1510.  
  1511. int ispunct(c)
  1512. int c;
  1513.  
  1514.     Return non-zero if <c> is not iscntrl(), isalnum() or isspace().
  1515.  
  1516. int isspace(c)
  1517. int c;
  1518.  
  1519.     Return non-zero if <c> is 0x09..0x0D,0x20.
  1520.  
  1521. int isupper(c)
  1522. int c;
  1523.  
  1524.     Return non-zero if <c> is 'A'..'Z'.
  1525.  
  1526. int isxdigit(c)
  1527. int c;
  1528.  
  1529.     Return non-zero if <c> is '0'..'9','A'..'F','a'..'f'.
  1530.  
  1531.  
  1532. DATE/TIME FUNCTIONS:
  1533.  
  1534.     To use the functions in this section, you must include "TIME.H"
  1535.     in your source file.
  1536.  
  1537. long time(rawtime)
  1538. long *rawtime;
  1539.  
  1540.     Get the current system clock date/time value.  Under many systems,
  1541.     this function returns the number of seconds since 00:00:00 GMT on
  1542.     Jan 1, 1970.  This implementation returns an encoded date/time
  1543.     value instead.  Therefore any programs which depend on this value
  1544.     being a number of seconds will not work properly.  However, other
  1545.     functions in this section which make use of the raw time value
  1546.     returned by time() are implemented to be compatible with this
  1547.     encoding, and will work properly.  In addition to returning the
  1548.     raw time value, if the <rawtime> pointer is not NULL, the value
  1549.     is stored in the long <rawtime> points to.
  1550.  
  1551. char *ctime(rawtime)
  1552. long *rawtime;
  1553.  
  1554.     Convert <rawtime> to a string.  A 26 character fixed field string
  1555.     is created from the raw time value.  The following is an example
  1556.     of what this string might look like:
  1557.         "Wed Jul 08 18:43:07 1987\n\0"
  1558.     A 24-hour clock is used, and due to a limitation in the ST system
  1559.     clock value, only a resolution of 2 seconds is possible.  A pointer
  1560.     to the formatted string, which is held in an internal buffer, is
  1561.     returned.
  1562.  
  1563. struct tm *gmtime(rawtime)
  1564. long *rawtime;
  1565.  
  1566.     Convert <rawtime> to fill time structure fields.  A pointer to an
  1567.     internal structure is returned.  Refer to "TIME.H" for the values
  1568.     of the various structure fields.
  1569.  
  1570. struct tm *localtime(rawtime)
  1571. long *rawtime;
  1572.  
  1573.     Since there is not concept of "time zone" on the ST, this function
  1574.     is identical to gmtime().
  1575.  
  1576. char *asctime(time)
  1577. struct tm *time;
  1578.  
  1579.     Convert <time> structure value to a string.  The same format, and
  1580.     the same internal buffer, as for ctime() is used for this function.
  1581.  
  1582. long cnvtime(rawtime, time)
  1583. long *rawtime;
  1584. struct tm *time;
  1585.  
  1586.     Convert <time> structure value to raw time format.  In addition to
  1587.     returning the raw time value, if the <rawtime> pointer in not NULL,
  1588.     the value is stored in the long <rawtime> points to. (cf: time)
  1589.  
  1590. void stime(rawtime)
  1591. long *rawtime;
  1592.  
  1593.     Set the system clock to <rawtime>.
  1594.  
  1595. int utime(pathname, rawtime)
  1596. char *pathname;
  1597. long *rawtime;
  1598.  
  1599.     Set the modification date of <pathname> to <rawtime>.  Returns zero
  1600.     for success, or a negative error code.
  1601.  
  1602. long start_timer(t)
  1603. TIMER *t;
  1604.  
  1605.     Start a 200Hz timer.  This timer value can later be checked with
  1606.     time_since() to determine elapsed time.  These functions provide
  1607.     a very low-overhead way of timing events.
  1608.  
  1609. long time_since(t)
  1610. TIMER *t;
  1611.  
  1612.     Returns the number of 200Hz ticks since start_timer() was called
  1613.     for timer <t>.
  1614.  
  1615. void sleep(dt)
  1616. int dt;
  1617.  
  1618.     Suspend operation for <dt> seconds.  This is implemented as a
  1619.     start_timer()/time_since() tight loop waiting for the specified
  1620.     amount of time to pass.  In a multi-tasking environment, this
  1621.     function should be replaced by a call which will de-activate
  1622.     this task for a period of time, allowing other tasks to run.
  1623.  
  1624.  
  1625. SEARCHING AND SORTING:
  1626.  
  1627. void qsort(base, num, size, cmp)
  1628. char *base;
  1629. int num;
  1630. int size;
  1631. int (*cmp)();
  1632.  
  1633.     Perform a recursive quick-sort on an array starting at <base>
  1634.     containing <num> elements of <size> bytes each.  The function
  1635.     pointed to by <cmp> is used to compare elements.  Pointers to
  1636.     two items in the array are passed to the function, which must
  1637.     return a number representing their relationship as follows:
  1638.         negative    item1 < item2
  1639.         0        item1 == item2
  1640.         positive    item1 > item2
  1641.     The qsort() function requires the use of a temporary data area
  1642.     that is large enough to hold <size> bytes.  The default space
  1643.     provided is 128 bytes large.  If your record size is larger than
  1644.     128 bytes, YOU MUST provide an alternative storage area.  The
  1645.     global variable "_qbuf" points to the storage qsort() will use.
  1646.     Setting "_qbuf" to NULL restores use of the internal buffer.
  1647.     This routine is optimized to avoid N*N sort times for ordered data.
  1648.  
  1649. void hsort(base, num, size, cmp)
  1650. char *base;
  1651. int num;
  1652. int size;
  1653. int (*cmp)();
  1654.  
  1655.     Perform an N*log(N) heap-sort on an array starting at <base>
  1656.     containing <num> elements of <size> bytes each.  The function
  1657.     pointed to by <cmp> is used to compare elements.  Pointers to
  1658.     two items in the array are passed to the function, which must
  1659.     return a number representing their relationship as follows:
  1660.         negative    item1 < item2
  1661.         0        item1 == item2
  1662.         positive    item1 > item2
  1663.     The hsort() function requires no extra storage, is not recursive,
  1664.     and has an almost constant N*log(N) sort time.  In the average
  1665.     case, it is about half as fast as qsort() on random data.  If
  1666.     portability is a concern, it should be noted that qsort() is
  1667.     almost always available, but hsort() is not.
  1668.  
  1669. char *bsearch(key, base, num, size, cmp)
  1670. char *key;
  1671. char *base;
  1672. int num;
  1673. int size;
  1674. int (*cmp)();
  1675.  
  1676.     Perform a binary search for <key> on the sorted data at <base>.
  1677.     <num>, <size> and <cmp> are like the corresponding parameters
  1678.     to qsort().  A pointer to the matching element is returned for
  1679.     success, or NULL for failure.  The global variable "_bsearch"
  1680.     will contain the index of either the matching element, or the
  1681.     place where <key> value should be inserted.  The use of "_bsearch"
  1682.     is not supported by many implementations of bsearch().
  1683.  
  1684. char *lsearch(key, base, num, size, cmp)
  1685. char *key;
  1686. char *base;
  1687. int num;
  1688. int size;
  1689. int (*cmp)();
  1690.  
  1691.     Perform a linear search for <key> on the data at <base>. The
  1692.     <num>, <size> and <cmp> parameters are like the corresponding
  1693.     parameters to qsort().  A pointer to the first matching element
  1694.     is returned for success, or NULL for failure.  If <key> is not
  1695.     found, it will be added to the end of the array.
  1696.  
  1697. char *lfind(key, base, num, size, cmp)
  1698. char *key;
  1699. char *base;
  1700. int num;
  1701. int size;
  1702. int (*cmp)();
  1703.  
  1704.     Like lsearch(), but do not add elements which are not found.
  1705.  
  1706.  
  1707. MISCELLANEOUS FUNCTIONS:
  1708.  
  1709. int rand()
  1710.  
  1711.     Return a pseudorandom number in the range 0..32767
  1712.  
  1713. void srand(seed)
  1714. unsigned int seed;
  1715.  
  1716.     Seed the random number generator.  This function is #defined as
  1717.     a comment, since no seeding is possible for this implementation
  1718.     of rand().
  1719.  
  1720. MACRO abs(x)
  1721.  
  1722.     Return the absolute value of <x>.  This macro evalutes it's
  1723.     argument twice.    ((x)<0?(-(x)):(x))
  1724.  
  1725. MACRO max(x,y)
  1726.  
  1727.     Return the larger of <x> and <y>.  This macro evaluates the
  1728.     larger argument twice and the smaller argument once.
  1729.  
  1730. MACRO min(x,y)
  1731.  
  1732.     Return the smaller of <x> and <y>.  This macro evaluates the
  1733.     smaller argument twice and the larger argument once.
  1734.  
  1735. MACRO swap(a,b)
  1736.  
  1737.     Exchange <a> and <b> by chained XORs.  The macro evaluates
  1738.     each argument several times.
  1739.  
  1740.  
  1741. ----- END OF FILE -----
  1742.