home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / BC_DICE3.DMS / in.adf / DOC / dice_libraries.doc < prev   
Encoding:
Text File  |  1995-01-10  |  213.9 KB  |  7,533 lines

  1. dice/StringFunctions                                       dice/StringFunctions
  2.  
  3.     String Functions
  4.     ----------------
  5.     Name         : Description                    : Class
  6.     =============+==============================================+=======
  7.     atof         : convert string into floating point        : ANSI
  8.     -------------+----------------------------------------------+-------
  9.     atoi         : convert string into integer            : ANSI
  10.     -------------+----------------------------------------------+-------
  11.     atol         : convert string into long integer         : ANSI
  12.     -------------+----------------------------------------------+-------
  13.     isalnum      : is character alphanumeric?            : ANSI
  14.     -------------+----------------------------------------------+-------
  15.     isalpha      : is character alphabetic?             : ANSI
  16.     -------------+----------------------------------------------+-------
  17.     iscntrl      : is character a control character?        : ANSI
  18.     -------------+----------------------------------------------+-------
  19.     isdigit      : is character numeric?                : ANSI
  20.     -------------+----------------------------------------------+-------
  21.     isgraph      : is character graphic?                : ANSI
  22.     -------------+----------------------------------------------+-------
  23.     islower      : is character lower case?             : ANSI
  24.     -------------+----------------------------------------------+-------
  25.     isprint      : is character printable?                : ANSI
  26.     -------------+----------------------------------------------+-------
  27.     ispunct      : is character punctuation?            : ANSI
  28.     -------------+----------------------------------------------+-------
  29.     isspace      : is character whitespace?             : ANSI
  30.     -------------+----------------------------------------------+-------
  31.     isupper      : is character upper case                : ANSI
  32.     -------------+----------------------------------------------+-------
  33.     isxdigit     : is character hex digit                : ANSI
  34.     -------------+----------------------------------------------+-------
  35.     printf         : format output                    : ANSI
  36.     -------------+----------------------------------------------+-------
  37.     stpchr         : search for a character in a string        : UNIX
  38.     -------------+----------------------------------------------+-------
  39.     stpcpy         : string copy                    : UNIX
  40.     -------------+----------------------------------------------+-------
  41.     strbpl         : build sting pointer                : DICE
  42.     -------------+----------------------------------------------+-------
  43.     strcat         : concatenate strings                : ANSI
  44.     -------------+----------------------------------------------+-------
  45.     strchr         : find character in string             : ANSI
  46.     -------------+----------------------------------------------+-------
  47.     strcmp         : compare strings                    : ANSI
  48.     -------------+----------------------------------------------+-------
  49.     strcpy         : string copy                    : ANSI
  50.     -------------+----------------------------------------------+-------
  51.     strcspn      : scan string for a character            : ANSI
  52.     -------------+----------------------------------------------+-------
  53.     strdup         : duplicate string                 : UNIX
  54.     -------------+----------------------------------------------+-------
  55.     strerror     : return error string                : ANSI
  56.     -------------+----------------------------------------------+-------
  57.     strftime     : convert time to string                : ANSI
  58.     -------------+----------------------------------------------+-------
  59.     stricmp      : compare strings (case insensitive)        : UNIX
  60.     -------------+----------------------------------------------+-------
  61.     strins         : insert a string                    : DICE
  62.     -------------+----------------------------------------------+-------
  63.     strlen         : return length of string                : ANSI
  64.     -------------+----------------------------------------------+-------
  65.     strncat      : concatenate strings                : ANSI
  66.     -------------+----------------------------------------------+-------
  67.     strncmp      : compare strings                    : ANSI
  68.     -------------+----------------------------------------------+-------
  69.     strncpy      : string copy (length limited)            : ANSI
  70.     -------------+----------------------------------------------+-------
  71.     strnicmp     : compare strings (case insensitive, length    : ANSI
  72.              : limited)                     :
  73.     -------------+----------------------------------------------+-------
  74.     strpbrk      : find break character in string            : ANSI
  75.     -------------+----------------------------------------------+-------
  76.     strrchr      : scan string for a character (backward)        : ANSI
  77.     -------------+----------------------------------------------+-------
  78.     strspn         : span of characters in string            : ANSI
  79.     -------------+----------------------------------------------+-------
  80.     strstr         : find sub-string in string            : ANSI
  81.     -------------+----------------------------------------------+-------
  82.     strtod         : convert string to double             : ANSI
  83.     -------------+----------------------------------------------+-------
  84.     strtok         : tokenize a string                : ANSI
  85.     -------------+----------------------------------------------+-------
  86.     strtol,      : convert string to [unsigned] long        : ANSI
  87.     strtoul      :                            :
  88.     -------------+----------------------------------------------+-------
  89.     tolower      : convert character to lower case            : ANSI
  90.     -------------+----------------------------------------------+-------
  91.     toupper      : convert character to upper case            : ANSI
  92.     -------------+----------------------------------------------+-------
  93.  
  94. dice/IOFunctions,InputFunctions,OutputFunctions              dice/IO
  95.  
  96.     Input/Output Functions
  97.     ----------------------
  98.       Name       : Description                : Class
  99.       =========+============================================+==========
  100.       access   : determine if file is accessible        : UNIX
  101.       ---------+--------------------------------------------+----------
  102.       chdir    : change current directory            : UNIX
  103.       ---------+--------------------------------------------+----------
  104.       clearerr : clear error associated with file pointer    : ANSI
  105.       ---------+--------------------------------------------+----------
  106.       close    : close a file descriptor            : UNIX
  107.       ---------+--------------------------------------------+----------
  108.       creat    : create a file (obsolete)            : UNIX
  109.       ---------+--------------------------------------------+----------
  110.       dir       : directory scanning routine         : UNIX
  111.       ---------+--------------------------------------------+----------
  112.       fclose   : close a file pointer            : ANSI
  113.       ---------+--------------------------------------------+----------
  114.       fcntl    : file control of a file            : UNIX
  115.       ---------+--------------------------------------------+----------
  116.       fdopen   : associate file pointer and file descriptor : UNIX
  117.       ---------+--------------------------------------------+----------
  118.       fdtoh    : return file handle from file descriptor    : AmigaDOS
  119.       ---------+--------------------------------------------+----------
  120.       feof       : return EOF indication for file        : ANSI
  121.       ---------+--------------------------------------------+----------
  122.       ferror   : return error condition for file        : ANSI
  123.       ---------+--------------------------------------------+----------
  124.       fflush   : flush buffers to file            : ANSI
  125.       ---------+--------------------------------------------+----------
  126.       fgetc    : get a single character from a file     : ANSI
  127.       ---------+--------------------------------------------+----------
  128.       fgetpos  : get current file position            : ANSI
  129.       ---------+--------------------------------------------+----------
  130.       fgets    : get a line from a file            : ANSI
  131.       ---------+--------------------------------------------+----------
  132.       fhprintf : formatted printing to a file        : AmigaDOS
  133.       ---------+--------------------------------------------+----------
  134.       fileno   : get file descriptor from file pointer    : UNIX
  135.       ---------+--------------------------------------------+----------
  136.       fopen    : open a file                : ANSI
  137.       ---------+--------------------------------------------+----------
  138.       fprintf  : formatted output to a file         : ANSI
  139.       ---------+--------------------------------------------+----------
  140.       fputc    : write a single character to a file     : ANSI
  141.       ---------+--------------------------------------------+----------
  142.       fputs    : write a string to a file            : ANSI
  143.       ---------+--------------------------------------------+----------
  144.       fread    : read from a file pointer            : ANSI
  145.       ---------+--------------------------------------------+----------
  146.       freopen  : reopen a file                : ANSI
  147.       ---------+--------------------------------------------+----------
  148.       fscanf   : formatted input from a file        : ANSI
  149.       ---------+--------------------------------------------+----------
  150.       fseek    : seek within a file             : ANSI
  151.       ---------+--------------------------------------------+----------
  152.       fsetpos  : set position within a file         : ANSI
  153.       ---------+--------------------------------------------+----------
  154.       fstat    : stat of a file                : UNIX
  155.       ---------+--------------------------------------------+----------
  156.       ftell    : get file position                : ANSI
  157.       ---------+--------------------------------------------+----------
  158.       fwrite   : write data to a file            : ANSI
  159.       ---------+--------------------------------------------+----------
  160.       getc       : get a single character from a file     : ANSI
  161.       ---------+--------------------------------------------+----------
  162.       getchar  : get a character from stdin         : ANSI
  163.       ---------+--------------------------------------------+----------
  164.       getcwd   : get current working directory        : UNIX
  165.       ---------+--------------------------------------------+----------
  166.       getfnl   : get file name list             : DICE
  167.       ---------+--------------------------------------------+----------
  168.       gets       : get a line from stdin            : ANSI
  169.       ---------+--------------------------------------------+----------
  170.       ioctl    : execute ioctl on file descriptor        : UNIX
  171.       ---------+--------------------------------------------+----------
  172.       isatty   : is a file descriptor a TTY         : UNIX
  173.       ---------+--------------------------------------------+----------
  174.       lseek    : seek in a file                : UNIX
  175.       ---------+--------------------------------------------+----------
  176.       mkdir    : create a directory             : UNIX
  177.       ---------+--------------------------------------------+----------
  178.       open       : open a file                : UNIX
  179.       ---------+--------------------------------------------+----------
  180.       perror   : print error message            : ANSI
  181.       ---------+--------------------------------------------+----------
  182.       printf   : formatted printing to standard out     : ANSI
  183.       ---------+--------------------------------------------+----------
  184.       putc       : write a single character to a file     : ANSI
  185.       ---------+--------------------------------------------+----------
  186.       putchar  : output character to stdout         : ANSI
  187.       ---------+--------------------------------------------+----------
  188.       puts       : write a string to a file            : ANSI
  189.       ---------+--------------------------------------------+----------
  190.       read       : read data from a file            : UNIX
  191.       ---------+--------------------------------------------+----------
  192.       remove   : delete a file                : ANSI
  193.       ---------+--------------------------------------------+----------
  194.       rename   : rename a file                : ANSI
  195.       ---------+--------------------------------------------+----------
  196.       rewind   : seek to file beginning            : ANSI
  197.       ---------+--------------------------------------------+----------
  198.       rmdir    : delete a directory             : UNIX
  199.       ---------+--------------------------------------------+----------
  200.       scanf    : formatted input from input         : ANSI
  201.       ---------+--------------------------------------------+----------
  202.       setvbuf  : change file buffering            : ANSI
  203.       ---------+--------------------------------------------+----------
  204.       sprintf  : formatted printing to a string        : ANSI
  205.       ---------+--------------------------------------------+----------
  206.       sscanf   : formatted input from a string        : ANSI
  207.       ---------+--------------------------------------------+----------
  208.       stat       : stat a file by name            : UNIX
  209.       ---------+--------------------------------------------+----------
  210.       tmpfile  : create a temporary file            : ANSI
  211.       ---------+--------------------------------------------+----------
  212.       tmpnam   : create a unique temporary file name    : ANSI
  213.       ---------+--------------------------------------------+----------
  214.       ungetc   : push character back to input stream    : ANSI
  215.       ---------+--------------------------------------------+----------
  216.       unlink   : delete a file                : UNIX
  217.       ---------+--------------------------------------------+----------
  218.       write    : write to a file                : UNIX
  219.       ---------+--------------------------------------------+----------
  220.  
  221. dice/MiscFunctions,Miscellaneous                           dice/MiscFunctions
  222.  
  223.     Miscellaneous Functions
  224.     -----------------------
  225.     Name             : Description              : Class
  226.     =========================+================================+==========
  227.     abort             : abort a program          : ANSI
  228.     -------------------------+--------------------------------+----------
  229.     asctime          : convert time into text      : ANSI
  230.     -------------------------+--------------------------------+----------
  231.     assert             : assert that an expression is   : ANSI
  232.                  : true               :
  233.     -------------------------+--------------------------------+----------
  234.     atexit             : specify routine to call on      : ANSI
  235.                  : exit               :
  236.     -------------------------+--------------------------------+----------
  237.     chkabort         : check for ^C           : AmigaDOS
  238.     -------------------------+--------------------------------+----------
  239.     clock             : return system clock time      : ANSI
  240.     -------------------------+--------------------------------+----------
  241.     CreateDiceRexxPort     : create an application ARexx      : DICE
  242.                  : port               :
  243.     -------------------------+--------------------------------+----------
  244.     CreateGlobalDiceRexxPort : create a global ARexx port      : DICE
  245.     -------------------------+--------------------------------+----------
  246.     ctime             : convert time into text      : ANSI
  247.     -------------------------+--------------------------------+----------
  248.     DeleteDiceRexxPort     : delete a DICE ARexx port      : DICE
  249.     -------------------------+--------------------------------+----------
  250.     DoRexxCommand         : Parse an incomming ARexx      : DICE
  251.                  : command              :
  252.     -------------------------+--------------------------------+----------
  253.     exit             : exit from a program          : ANSI
  254.     -------------------------+--------------------------------+----------
  255.     _exit             : exit from a program          : DICE
  256.     -------------------------+--------------------------------+----------
  257.     expand_args         : expand command line (very      : DICE
  258.                  : useful!)              :
  259.     -------------------------+--------------------------------+----------
  260.     getenv             : get environment variable      : ANSI
  261.     -------------------------+--------------------------------+----------
  262.     GetDiceRexxPortSlot     : Determine an application ARexx : DICE
  263.                  : slot               :
  264.     -------------------------+--------------------------------+----------
  265.     GetHead          : get first element in EXEC list : DICE
  266.     -------------------------+--------------------------------+----------
  267.     GetPred          : get preceding element in EXEC  : DICE
  268.                  : list               :
  269.     -------------------------+--------------------------------+----------
  270.     GetSucc          : get succeeding element in EXEC : DICE
  271.                  : list               :
  272.     -------------------------+--------------------------------+----------
  273.     GetTail          : get last element in EXEC list  : DICE
  274.     -------------------------+--------------------------------+----------
  275.     localtime         : unpack time              : ANSI
  276.     -------------------------+--------------------------------+----------
  277.     LockAddr         : semaphore routine          : DICE
  278.     -------------------------+--------------------------------+----------
  279.     LockAddrB         : semaphore routine          : DICE
  280.     -------------------------+--------------------------------+----------
  281.     longjmp          : jump to a saved setjmp      : ANSI
  282.     -------------------------+--------------------------------+----------
  283.     main             : main program entry point      : ANSI
  284.     -------------------------+--------------------------------+----------
  285.     _main             : main program entry point      : DICE
  286.     -------------------------+--------------------------------+----------
  287.     onbreak          : Set ^C function          : DICE
  288.     -------------------------+--------------------------------+----------
  289.     PlaceRexxCommand     : Send a command to ARexx      : DICE
  290.     -------------------------+--------------------------------+----------
  291.     PlaceRexxCommandDirect     : send an ARexx command to an      : DICE
  292.                  : application              :
  293.     -------------------------+--------------------------------+----------
  294.     ProcessRexxCommands     : Handle incomming ARexx      : DICE
  295.                  : commands              :
  296.     -------------------------+--------------------------------+----------
  297.     qsort             : sort an array          : ANSI
  298.     -------------------------+--------------------------------+----------
  299.     raise             : raise a signal          : ANSI
  300.     -------------------------+--------------------------------+----------
  301.     rega4             : return contents of register A4 : DICE
  302.                  : (different from geta4!)      :
  303.     -------------------------+--------------------------------+----------
  304.     setbuf             : select alternative stream      : ANSI
  305.                  : buffering              :
  306.     -------------------------+--------------------------------+----------
  307.     setjmp             : prepare for future long jmp      : ANSI
  308.     -------------------------+--------------------------------+----------
  309.     signal             : establish event traps      : ANSI
  310.     -------------------------+--------------------------------+----------
  311.     sleep             : sleep for a while          : UNIX
  312.     -------------------------+--------------------------------+----------
  313.     stack_abort         : exit point for stack alloc      : DICE
  314.                  : failure              :
  315.     -------------------------+--------------------------------+----------
  316.     system             : call system command shell      : ANSI
  317.     -------------------------+--------------------------------+----------
  318.     time             : get current time          : ANSI
  319.     -------------------------+--------------------------------+----------
  320.     TryLockAddr         : semaphore routine          : DICE
  321.     -------------------------+--------------------------------+----------
  322.     TryLockAddrB         : semaphore routine          : DICE
  323.     -------------------------+--------------------------------+----------
  324.     UnLockAddr         : semaphore routine          : DICE
  325.     -------------------------+--------------------------------+----------
  326.     UnLockAddrB         : semaphore routine          : DICE
  327.     -------------------------+--------------------------------+----------
  328.     wbmain             : main program entry for      : AmigaDos
  329.                  : WorkBench              :
  330.     -------------------------+--------------------------------+----------
  331.  
  332. dice/MemoryFunctions                                       dice/MemoryFunctions
  333.     Memory Functions
  334.     ----------------
  335.         Name    : Description             : Class
  336.         ========+================================+==========
  337.         alloca    : allocate memory from the stack : UNIX
  338.         --------+--------------------------------+----------
  339.         bcmp    : compare two memory buffers     : UNIX
  340.         --------+--------------------------------+----------
  341.         bcopy    : copy memory             : UNIX
  342.         --------+--------------------------------+----------
  343.         bzero    : zero memory             : UNIX
  344.         --------+--------------------------------+----------
  345.         calloc    : allocate memory         : ANSI
  346.         --------+--------------------------------+----------
  347.         clrmem    : zero memory             : AmigaDOS
  348.         --------+--------------------------------+----------
  349.         cmpmem    : compare two memory buffers     : UNIX
  350.         --------+--------------------------------+----------
  351.         free    : free allocated memory      : ANSI
  352.         --------+--------------------------------+----------
  353.         malloc    : allocate memory         : ANSI
  354.         --------+--------------------------------+----------
  355.         memcmp    : compare two memory buffers     : ANSI
  356.         --------+--------------------------------+----------
  357.         memcpy    : copy memory             : ANSI
  358.         --------+--------------------------------+----------
  359.         memmove : move memory             : ANSI
  360.         --------+--------------------------------+----------
  361.         memset    : set memory to value         : ANSI
  362.         --------+--------------------------------+----------
  363.         movmem    : move memory             : UNIX
  364.         --------+--------------------------------+----------
  365.         realloc : reallocate memory         : ANSI
  366.         --------+--------------------------------+----------
  367.         setmem    : set memory to value         : UNIX
  368.         --------+--------------------------------+----------
  369.  
  370. dice/AslBase,DiceCacheBase,DiskfontBase,DOSBase,FifoBase,GadToolsBase,IconBase,IntuitionBase,LayersBase,MathBase,MathIeeeDoubBasBase,MathIeeeDoubTransBase,MathIeeeSingBasBase,MathIeeeSingTransBase,MathTransBase,RexxSysBase,SysBase,TimerBase,TranslatorB
  371. se,UtilityBase
  372.  
  373.     AslBase, DiceCacheBase, DiskfontBase, DOSBase, FifoBase,
  374.     GadToolsBase, IconBase, IntuitionBase, LayersBase, MathBase,
  375.     MathIeeeDoubBasBase, MathIeeeDoubTransBase, MathIeeeSingBasBase,
  376.     MathIeeeSingTransBase, MathTransBase, RexxSysBase, SysBase,
  377.     TimerBase, TranslatorBase, UtilityBase
  378.  
  379.     FUNCTION
  380.     DICE will automatically open libraries for you (DICE)
  381.  
  382.     DESCRIPTION
  383.     With DICE you need not worry about opening or closing Amiga
  384.     libraries.  You don't have to deal with the mess and hassle of
  385.     checking error returns from each open.    If a function call to a
  386.     library is used, the library base variable will be referenced.    If
  387.     you did not explicitly define the variable, DICE will insert it,
  388.     along with code to open and close the library.
  389.  
  390.     For example, if the _IntuitionBase base variable is referenced (say,
  391.     with extern) but not declared then _IntuitionBase will be
  392.     automatically declared in auto.lib.  Additionally, auto.lib adds
  393.     routines to the autoinit and autoexit sequences that automatically
  394.     open "intuition.library" before _main and close it after _exit. If
  395.     the auto-open fails the program will be aborted before _main is ever
  396.     called. The autoexit routine that closes the library first checks to
  397.     see if the base variable is NULL and skips trying to close the
  398.     library if so.
  399.  
  400.     EXAMPLE
  401.     /*
  402.     **  Example program which just calls an
  403.     **  intuition.library function without
  404.     **  bothering to open the library.
  405.     */
  406.     main()
  407.     {
  408.        DisplayBeep( 0 );
  409.     }
  410.  
  411. dice/abort                                                        dice/abort
  412.  
  413.     FUNCTION
  414.     abort a program with an error (ANSI)
  415.  
  416.     SYNTAX
  417.     #include <stdlib.h>
  418.     void abort(void);
  419.  
  420.     DESCRIPTION
  421.     abort aborts a program with a non-zero exit code.  The default abort
  422.     routine in c.lib does the equivalent of an exit(20);. Programmers may
  423.     override the default abort routine with their own.
  424.  
  425.     RESULTS
  426.     abort never returns
  427.  
  428.     SEE ALSO
  429.     assert
  430.  
  431.     EXAMPLE
  432.     #include <stdio.h>
  433.     #include <stdlib.h>
  434.     main(int ac, char**av)
  435.     {
  436.        if (ac == 1) {
  437.           puts("Hey, I expected a parameter!");
  438.           abort();
  439.           }
  440.           puts("Thanks!");
  441.           return(0);
  442.     }
  443.  
  444. dice/access                                                      dice/access
  445.  
  446.     FUNCTION
  447.     determine whether file is accessible (UNIX)
  448.  
  449.     SYNTAX
  450.     #include <stdio.h>
  451.     int r = access(filename, mode);
  452.     const char *filename;
  453.     int mode;
  454.  
  455.     DESCRIPTION
  456.     access returns 0 upon success, -1 if access with the requested modes
  457.     was impossible.  The filename serves as a pointer to the string of
  458.     the filename we wish to check, and the modes are what we expect the
  459.     file to be able to do.    The modes may be one or more of the following
  460.     OR'd together.
  461.  
  462.      0   check for existence of file only
  463.      1   check execute permission for file
  464.      2   check write permission for file
  465.     4   check read permission for file
  466.  
  467.     INPUTS
  468.     char *filename;     file to check
  469.  
  470.     int mode;        modes as specified above
  471.  
  472.     RESULTS
  473.     int r;            0 if modes available, -1 if not
  474.  
  475.     SEE ALSO
  476.     open, fopen
  477.  
  478.     EXAMPLE
  479.     #include <stdio.h>
  480.  
  481.     main(int ac, char **av)
  482.     {
  483.        char *name;
  484.        if (ac == 1)
  485.        {
  486.           puts("Expected a file name argument");
  487.           exit(1);
  488.        }
  489.        name = av[1];
  490.        if (access(name, 0) == 0) {
  491.          puts("It exists");
  492.           if (access(name, 1) == 0)
  493.          puts("It is executable");
  494.           if (access(name, 2) == 0)
  495.             puts("I can write to it!");
  496.           if (access(name, 4) == 0)
  497.             puts("I can even read from it!");
  498.        }
  499.        else
  500.          puts("Hmmm, that file does not exist");
  501.     }
  502.  
  503. dice/alloca                                                      dice/alloca
  504.  
  505.     FUNCTION
  506.     allocate memory from the stack (UNIX)
  507.  
  508.     SYNTAX
  509.     #include <stdlib.h>
  510.     void *ptr = alloca(long bytes);
  511.  
  512.     DESCRIPTION
  513.     alloca comes from the UNIX world.  It allocates memory off the stack
  514.     for use within a procedure.  The allocated memory is automatically
  515.     freed when the subroutine returns.
  516.  
  517.     :: Beginner's Note: Do not use alloca if you can help it; alloca is
  518.     :: not easily portable across machines.
  519.  
  520.     || NOTE: When a low stack condition arises, alloca will abort by
  521.     || printing an error message and calling abort;  alloca does not
  522.     || currently try to allocate dynamic memory when it runs out of
  523.     || stack. Some implementations of alloca use alloca(0) to free
  524.     || allocated stack. This feature is not currently implemented in
  525.     || DICE's alloca call.
  526.  
  527.     SEE ALSO
  528.     setjmp, longjmp
  529.  
  530.     EXAMPLE
  531.     #include <alloca.h>
  532.     #include <stdio.h>
  533.     main(int ac, char*av[])
  534.     {
  535.        char *ptr;
  536.        if (ac == 1) {
  537.           puts("I need test string");
  538.           exit(1);
  539.        }
  540.        ptr = alloca(strlen(av[1]) + 8);
  541.        sprintf(ptr, "FOO.%s", av[1]);
  542.        puts(ptr);
  543.        return(0);
  544.     }
  545.  
  546. dice/asctime                                                    dice/asctime
  547.  
  548.     FUNCTION
  549.     convert broken down time into standard text (ANSI)
  550.  
  551.     SYNTAX
  552.     #include <time.h>
  553.     char *str = asctime(ts);
  554.     const struct tm *ts;
  555.  
  556.     DESCRIPTION
  557.     asctime converts a broken down time in the tm structure to an ASCII
  558.     string and returns a pointer to that string. The time string format
  559.     is:
  560.  
  561.     on Dec 8 01:53:33 1987\n\0
  562.  
  563.     where \n stands for a newline character and \0 is a terminating NULL.
  564.     The string is stored in a static buffer shared by both asctime and
  565.     ctime and so will be overwritten whenever either function is called.
  566.  
  567.     INPUTS
  568.     struct tm *ts;        pointer to a broken down time structure
  569.  
  570.     RESULTS
  571.     char *str;        pointer to static string
  572.  
  573.     SEE ALSO
  574.     time, localtime, asctime, strftime, ctime, clock
  575.  
  576.     EXAMPLE
  577.     #include <stdio.h>
  578.     #include <time.h>
  579.  
  580.     main()
  581.     {
  582.        time_t t = time(NULL);
  583.        fputs(asctime(localtime(&t)), stdout);
  584.        return(0);
  585.     }
  586.  
  587. dice/assert                                                      dice/assert
  588.  
  589.     FUNCTION
  590.     assert that an expression is true,  else abort (ANSI)
  591.  
  592.     SYNTAX
  593.     #include <assert.h>
  594.     assert(condition);   /* MACRO */
  595.  
  596.     DESCRIPTION
  597.     assert checks the condition and if not true prints an error message
  598.     indicating the source filename and line number that the assertion
  599.     failed at, and then aborts.  The DICE version of assert generates a
  600.     single static string in assert.h for each module containing the file
  601.     name. Multiple usages of assert refer to the same physical filename
  602.     string.
  603.  
  604.     INPUTS
  605.     expression;        an expression which the macro negates.
  606.  
  607.     SEE ALSO
  608.     abort
  609.  
  610.     EXAMPLE
  611.     #include <assert.h>
  612.  
  613.     main(int ac, char **av)
  614.     {
  615.        assert(ac > 1); /*  expect at least one argument! */
  616.        return(0);
  617.     }
  618.  
  619. dice/atexit                                                      dice/atexit
  620.  
  621.     FUNCTION
  622.     specify routine that is automatically called on exit (ANSI)
  623.  
  624.     SYNTAX
  625.     #include <stdio.h>
  626.     #include <stdlib.h>
  627.     int error = atexit(funcptr);
  628.     void (*fptr)(void);
  629.  
  630.     DESCRIPTION
  631.     The atexit routine adds a function to the list of functions called
  632.     when the program exits.  The atexit routine is called before stdio
  633.     and file descriptors are closed down.  This exit function is called
  634.     whenever the program exits, even if main returns normally. atexit
  635.     will return 0 on success, -1 on failure. Some systems limit the
  636.     number of atexit functions one can add (DICE does not) so if you add
  637.     more than one you should check the return value.
  638.  
  639.     INPUTS
  640.     void (*fptr)(void);
  641.                 routine to add to exit call list, takes no
  642.                 arguments and returns nothing.
  643.  
  644.     RESULTS
  645.     int error;        0 on success, -1 on failure.
  646.  
  647.     SEE ALSO
  648.     onbreak
  649.  
  650.     EXAMPLE
  651.     /*
  652.      *  Atexit is useful to free up resources that would
  653.      *  otherwise not be freed up by DICE. For example, any
  654.      *  thing AllocMem'd.  The atexit function is called on
  655.      *  any exit ... return from main, call to exit, or ^C.
  656.      *
  657.      *  Normally your atexit routine cannot make assumptions
  658.      *  as to what has been allocated and what has not since
  659.      *  exit can be called from anywhere in the program.
  660.      */
  661.     #include <stdio.h>
  662.     #include <stdlib.h>
  663.     extern void *AllocMem();
  664.     void *MemPtr; long MemLen;
  665.  
  666.     void myexit(void)
  667.     {
  668.        if (MemPtr) /*  only if it is allocated */
  669.            FreeMem(MemPtr, MemLen);
  670.        MemPtr = NULL;
  671.     }
  672.  
  673.     /*  Now we can take a ^C anywhere... before we allocate,
  674.      *  after, or even after we free (note I am careful to set
  675.      *  MemPtr back to NULL!)
  676.      */
  677.     main()
  678.     {
  679.        short i;
  680.        atexit(myexit);
  681.  
  682.        for (i = 0; i < 50; ++i)
  683.           printf("Before %d\t(%ld)\n", i, AvailMem(0) );
  684.        MemLen = 32;
  685.        MemPtr = AllocMem(MemLen, 0);
  686.        if (! MemPtr) {
  687.           exit(20);
  688.        }
  689.  
  690.        for (i = 0; i < 50; ++i)
  691.           printf("During %d\t(%ld)\n", i, AvailMem(0) );
  692.  
  693.        FreeMem(MemPtr, MemLen);
  694.        MemPtr = NULL; /* Mark as freed */
  695.  
  696.        for (i = 0; i < 50; ++i)
  697.           printf("After  %d\t(%ld)\n", i, AvailMem(0) );
  698.        return(0);
  699.     }
  700.  
  701. dice/atof                                                          dice/atof
  702.  
  703.     FUNCTION
  704.     convert string into double floating point value (ANSI)
  705.  
  706.     SYNTAX
  707.     #include <stdio.h>
  708.     #include <stdlib.h>
  709.     double d = atof(str);
  710.     const char *str;
  711.  
  712.     DESCRIPTION
  713.     atof converts a string into a double floating point value; it is
  714.     equivalent to calling strtod(str, NULL).  Please refer to strtod for
  715.     more information.
  716.  
  717.     INPUTS
  718.     char *str;        string, like "1.234E-4";
  719.  
  720.     RESULTS
  721.     double d;        double fp representation of string
  722.  
  723.     SEE ALSO
  724.     strtod
  725.  
  726. dice/atoi,atol                                                dice/atoi,atol
  727.  
  728.     FUNCTION
  729.     convert string into integer (ANSI)
  730.  
  731.     SYNTAX
  732.     #include <stdio.h>
  733.     #include <stdlib.h>
  734.     int x =atoi(str);
  735.     long y = atol(str);
  736.     const char *str;
  737.  
  738.     DESCRIPTION
  739.     atoi and atol convert a string of decimal integers into an integer.
  740.     It skips initial white space, processes an optional negative sign
  741.     ('-'), processes digits '0' - '9', and returns the integer. atoi and
  742.     atol have been superseded by the strtol function which can handle
  743.     numbers of any base.
  744.  
  745.     || NOTE: Under DICE, sizeof(int) == sizeof(long), and thus atoi and
  746.     || atol are exactly the same.
  747.  
  748.     INPUTS
  749.     char *str;        string to convert to int
  750.  
  751.     RESULTS
  752.     int x;            integer result long y; integer result
  753.  
  754.     SEE ALSO
  755.     strtol
  756.  
  757.     EXAMPLE
  758.     #include <stdio.h>
  759.     #include <stdlib.h>
  760.     main()
  761.     {
  762.        int i = atoi("  \t\t -123");
  763.        printf("i = %d (-123?)\n", i);
  764.        return(0);
  765.     }
  766.  
  767. dice/bcmp                                                          dice/bcmp
  768.  
  769.     FUNCTION
  770.     compare two memory buffers (UNIX)
  771.  
  772.     SYNTAX
  773.     #include <string.h>
  774.     int r = bcmp(s1, s2, bytes)
  775.     void *s1;
  776.     void *s2;
  777.     size_t bytes;
  778.  
  779.     DESCRIPTION
  780.     bcmp compares two memory buffers.  A byte by byte (unsigned)
  781.     comparison is done.  When a comparison fails and the byte in s1 is
  782.     less than the byte in s2 then -1 is returned.  If the byte in s1 is
  783.     greater than the byte in s2 then 1 is returned.  If the count is
  784.     exhausted and all comparisons succeed then 0 is returned indicating
  785.     the two buffers are the same.
  786.  
  787.     INPUTS
  788.     void *s1;        pointer to first buffer
  789.  
  790.     void *s2;        pointer to second buffer
  791.  
  792.     size_t bytes;        size of each buffer
  793.  
  794.     RESULTS
  795.     int r;            -1 if buf s1 < buf s2, 0 if buf s1 == buf s2, 1
  796.                 if buf s1 > buf s2.
  797.  
  798.     SEE ALSO
  799.     cmpmem, memcmp, strcmp
  800.  
  801.     EXAMPLE
  802.     #include <stdlib.h>
  803.     #include <assert.h>
  804.     main()
  805.     {
  806.        unsigned char buf1[] = {5, 12, 13};
  807.        unsigned char buf2[] = {5, 12, 13};
  808.        int r;
  809.        r = bcmp(buf1, buf2, 3);
  810.        assert(r == 0);
  811.  
  812.        buf1[2] = 12;
  813.        r = bcmp(buf1, buf2, 3);
  814.        assert(r < 0);
  815.  
  816.        buf1[2] = 200;
  817.        r = bcmp(buf1, buf2, 3);
  818.        assert(r > 0);
  819.        return(0);
  820.     }
  821.  
  822. dice/c.o                                                            dice/c.o
  823.  
  824.     FUNCTION
  825.     DICE startup module for all C programs
  826.  
  827.     SYNTAX
  828.     The module dlib:c.o is normally specified first in a link line, or
  829.     automatically by dcc.
  830.  
  831.     DESCRIPTION
  832.     C programs require a bit of code (called "glue") in order to start
  833.     execution.  This code saves machine registers, sets up global
  834.     storage, parses arguments, open libraries and, after the program
  835.     terminates, communicates results back to the host Operating System.
  836.     For use with the Amiga, DICE includes a suitable startup module
  837.     called c.o.  This module is automatically include by dcc, and need
  838.     not concern most programmers.
  839.  
  840.     The startup module performs the following tasks:
  841.  
  842.     1) Save non-scratch registers.
  843.  
  844.     2) If resident, allocate space for both DATA (Initialized globals) &
  845.        BSS (Uninitialized globals - set to zero).  Copy initialized data
  846.        into the allocated space. Clear the BSS portion of the data space.
  847.        If the BSS has already been allocated by the load module but not
  848.        cleared, clear the BSS portion of the data space.
  849.  
  850.     3) Clear the ^C (Control C) signal
  851.  
  852.     4) Setup _SysBase, the pointer to the Amiga's master library, Exec.
  853.  
  854.     5) Call all AUTOINIT subroutines (this usually results in at least
  855.        the dos.library being opened).
  856.  
  857.     6) Call _main (usually the c.lib version, but you may override it).
  858.  
  859.     7) Fall through to _exit(0).  Note that while c.a falls through to
  860.        _exit after calling _main, _main itself calls main with:
  861.        exit(main(args...)); Thus, main() is always expected to return a
  862.        valid value (i.e. not void).
  863.  
  864.     C.O. also handles the low-level _exit (__exit:) in the following
  865.     sequence:
  866.  
  867.     1) Call all AUTOEXEC subroutines (this normally closes the DOS
  868.        library and other automatically opened libraries such as floating
  869.        point).
  870.  
  871.     2) Free all memory allocated by the task, including the small data
  872.        segment & BSS space.  Note that all variables we use hereafter
  873.        have already been placed in registers since the dataspace is no
  874.        longer valid.
  875.  
  876.     3) If started from workbench, reply to the workbench message, _WBMsg.
  877.  
  878.     4) Restore original registers and rts (exit back to the Operating
  879.        System).
  880.  
  881.     c.o also exists in c.lib, however that version is not normally used.
  882.  
  883.     || NOTE: Normally the programmer does not override the startup object
  884.     || file (c.o).
  885.  
  886.     However, in some cases a programmer will want to override _main, as
  887.     in:
  888.  
  889.         _main(len, arg) int len; char *arg; {... }
  890.  
  891.     The _main entry point is passed the length and arg pointer unmodified
  892.     from the OS. When you override _main you cannot call any stdio
  893.     (fopen, fclose, puts, printf, etc...), any low level IO (open, close,
  894.     read, write, etc...), or any C memory allocation routine (malloc,
  895.     etc...).
  896.  
  897.     Normally _main will be overridden if the programmer wishes to save
  898.     space, and makes only Amiga system calls (such as Open, Close, Read,
  899.     Write, FindTask, etc.). Overriding the C.LIB generally makes
  900.     executables much smaller because no extraneous stdio or low level IO
  901.     routines are brought in from c.lib. Normally you exit out of _main by
  902.     calling _exit(code) (note the underscore).
  903.  
  904. dice/calloc                                                      dice/calloc
  905.  
  906.     FUNCTION
  907.     allocate memory and clear (ANSI)
  908.  
  909.     SYNTAX
  910.     #include <stdlib.h>
  911.     void *ptr = calloc(objsize, numobjs)
  912.     size_t objsize;
  913.     size_t numobjs;
  914.  
  915.     DESCRIPTION
  916.     Numobjs objects each objsize in size are allocated contiguously and a
  917.     pointer to the first object is returned.  The memory is cleared to 0.
  918.     Effectively this is equivalent to malloc(objsize * numobjs), and then
  919.     setmem(ptr, objsize * numobjs, 0) . calloc returns NULL if the memory
  920.     cannot be allocated.
  921.  
  922.     INPUTS
  923.     size_t objsize;     size of each object
  924.  
  925.     size_t numobjs;     number of objects to allocate
  926.  
  927.     RESULTS
  928.     void *ptr;        pointer to first object
  929.  
  930.     SEE ALSO
  931.     malloc, strdup
  932.  
  933.     EXAMPLE
  934.     /*
  935.      *  allocate 16 objects and fill with junk
  936.      */
  937.     #include <stdlib.h>
  938.     #include <assert.h>
  939.     typedef struct
  940.     {
  941.        long a, b, c;
  942.     }
  943.     Junk;
  944.     main()
  945.     {
  946.        Junk *jp;
  947.        jp = calloc(sizeof(Junk), 16);
  948.        assert(jp);
  949.        {
  950.           Junk *tj = jp;
  951.           short i;
  952.           for (i = 0; i < 16; ++i, ++tj)
  953.           {
  954.          tj->a = 1;
  955.          tj->b = 2;
  956.          tj->c = 3;
  957.           }
  958.        }
  959.     free(jp);
  960.     return(0);
  961.     }
  962.  
  963. dice/chdir                                                        dice/chdir
  964.  
  965.     FUNCTION
  966.     change current directory (UNIX)
  967.  
  968.     SYNTAX
  969.     #include <stdio.h>
  970.     int r = chdir(path);
  971.     const char *path;
  972.  
  973.     DESCRIPTION
  974.     chdir changes the current directory to the specified path, returning
  975.     0 on success and -1 on failure.
  976.  
  977.     || NOTE: When a program exits, the original directory will be
  978.     || restored.
  979.  
  980.     INPUTS
  981.     char *path;        path to chdir into
  982.  
  983.     RESULTS
  984.     int r;            return value, 0 if ok, -1 if error
  985.  
  986.     SEE ALSO
  987.     getcwd
  988.  
  989.     EXAMPLE
  990.     #include <stdio.h>
  991.     char buf[512];
  992.     main(int ac, char **av)
  993.     {
  994.        getcwd(buf, sizeof(buf));
  995.        if (chdir("RAM:")) {
  996.           puts("Couldn't chdir into RAM:");
  997.           exit(1);
  998.        }
  999.        FILE *fp;
  1000.        if (fp = fopen("yy", "w")) {
  1001.           fputs("Fight for vegetable rights!\n", fp);
  1002.           fclose(fp);
  1003.           puts("created file yy in RAM:");
  1004.        }
  1005.        if (chdir(buf)) {
  1006.           printf("Unable to chdir back into %s\n", buf);
  1007.        }
  1008.        return(0);
  1009.     }
  1010.  
  1011. dice/chkabort                                                  dice/chkabort
  1012.  
  1013.     FUNCTION
  1014.     Check for ^C and take the appropriate action (AmigaDOS)
  1015.  
  1016.     SYNTAX
  1017.     (void) chkabort(void);
  1018.  
  1019.     DESCRIPTION
  1020.     chkabort checks for a ^C and takes the appropriate action.  If the
  1021.     appropriate action is to exit then this routine does not return.
  1022.     Stdio and other routines will call chkabort at various points.    The
  1023.     action taken by ^C may be set by the signal or onbreak calls.
  1024.  
  1025.     SEE ALSO
  1026.     onbreak, atexit, signal
  1027.  
  1028.     EXAMPLE
  1029.     /*
  1030.      *  wait for somebody to hit ^C (note that this is very
  1031.      *  wasteful of CPU and thus isn't a real good example).
  1032.      */
  1033.     main()
  1034.     {
  1035.        int i;
  1036.        for (i = 0; i < 10000000; ++i)
  1037.           chkabort();
  1038.        return(0);
  1039.     }
  1040.  
  1041. dice/clearerr                                                  dice/clearerr
  1042.  
  1043.     FUNCTION
  1044.     Clear error associated with a file pointer (ANSI)
  1045.  
  1046.     SYNTAX
  1047.     #include <stdio.h>
  1048.     void clearerr(fp);
  1049.     (MACRO) FILE *fp;
  1050.  
  1051.     DESCRIPTION
  1052.     The clearerr macro clears both the EOF flag and the ERROR flag
  1053.     associated with a file pointer. When an ERROR occurs on a file
  1054.     pointer, addition fread, fwrite, etc. calls will not work until the
  1055.     ERROR indicator is cleared.
  1056.  
  1057.     || NOTE: Refer to the file_pointer manual page for general
  1058.     || information.
  1059.  
  1060.     INPUTS
  1061.     FILE *fp;        file pointer to clear the error on.
  1062.  
  1063.     RESULTS
  1064.     none;            the error and EOF indicators are cleared
  1065.  
  1066.     SEE ALSO
  1067.     feof, ferror, rewind, fseek
  1068.  
  1069. dice/clock                                                        dice/clock
  1070.  
  1071.     FUNCTION
  1072.     return system clock value (ANSI)
  1073.  
  1074.     SYNTAX
  1075.     #include <time.h>
  1076.     clock_t clk = clock(void);
  1077.  
  1078.     DESCRIPTION
  1079.     clock returns the system clock in ticks.  To obtain seconds from
  1080.     ticks divide the returned value by CLK_TCK in <time.h>.
  1081.  
  1082.     INPUTS
  1083.     none
  1084.  
  1085.     RESULTS
  1086.     clock_t clk;        system clock time value
  1087.  
  1088.     SEE ALSO
  1089.     time, localtime, asctime, strftime, ctime, clock
  1090.  
  1091.     EXAMPLE
  1092.     #include <stdio.h>
  1093.     #include <time.h>
  1094.  
  1095.     main()
  1096.     {
  1097.        clock_t clk = clock();
  1098.        long i;
  1099.        clk = clk + CLK_TCK;
  1100.        for (i = 0; clk - clock() > 0; ++i)
  1101.           ;
  1102.        printf("The FOR loop calling clock() took\
  1103.            %d loops in one second\n", i);
  1104.        return(0);
  1105.     }
  1106.  
  1107. dice/close                                                        dice/close
  1108.  
  1109.     FUNCTION
  1110.     close a file descriptor (UNIX)
  1111.  
  1112.     SYNTAX
  1113.     #include <fcntl.h>
  1114.     int r = close(fd);
  1115.     int fd;
  1116.  
  1117.     DESCRIPTION
  1118.     close closes a file descriptor.  If an error occurs or the descriptor
  1119.     is invalid, a non-zero return code will result and errno will be set
  1120.     to the appropriate error condition.
  1121.  
  1122.     || NOTE: Refer to the file_descriptor manual page for general
  1123.     || information.  Unlike file pointers and file handles, the file
  1124.     || descriptor is checked for validity and if illegal, an error will
  1125.     || be returned.
  1126.  
  1127.     INPUTS
  1128.     int fd;         file descriptor to close, the file descriptor
  1129.                 becomes invalid after this call
  1130.  
  1131.     RESULTS
  1132.     int r;            return value, 0 == ok, non-zero == error
  1133.  
  1134.     SEE ALSO
  1135.     creat, fcntl, fdtofh, ioctl, isatty, lseek, mkdir, open, read, rmdir,
  1136.     unlink, write
  1137.  
  1138.     See open for an example
  1139.  
  1140. dice/cmpmem                                                      dice/cmpmem
  1141.  
  1142.     FUNCTION
  1143.     compare two memory buffers (UNIX)
  1144.  
  1145.     SYNTAX
  1146.     #include <string.h>
  1147.     int r = cmpmem(s1, s2, bytes)
  1148.     void *s1;
  1149.     void *s2;
  1150.     size_t bytes;
  1151.  
  1152.     DESCRIPTION
  1153.     Like bcmp, this function compares two memory buffers.  A byte by byte
  1154.     (unsigned) comparison is done.    When a comparison fails and the byte
  1155.     in s1 is less than the byte in s2 then -1 is returned. If the byte in
  1156.     s1 is greater than the byte in s2 then 1 is returned. If the count is
  1157.     exhausted and all comparisons succeed then 0 is returned indicating
  1158.     the two buffers are the same.
  1159.  
  1160.     INPUTS
  1161.     void *s1;        pointer to first buffer
  1162.  
  1163.     void *s2;        pointer to second buffer
  1164.  
  1165.     size_t bytes;        size of each buffer
  1166.  
  1167.     RESULTS
  1168.     int r;            -1 if buf s1 < buf s2, 0 if buf s1 == buf s2, 1
  1169.                 if buf s1 > buf s2.
  1170.  
  1171.     SEE ALSO
  1172.     bcmp, memcmp
  1173.  
  1174.     EXAMPLE
  1175.     #include <stdlib.h>
  1176.     #include <assert.h>
  1177.     main()
  1178.     {
  1179.        unsigned char buf1[] = {3, 5, 7, 11, 13};
  1180.        unsigned char buf2[] = {3, 5, 7, 11, 13};
  1181.        int r;
  1182.  
  1183.        r = cmpmem(buf1, buf2, 5);
  1184.        assert(r == 0);
  1185.        buf1[2] = 2;
  1186.        r = cmpmem(buf1, buf2, 5);
  1187.        assert(r < 0);
  1188.        buf1[2] = 200;
  1189.        r = cmpmem(buf1, buf2, 5);
  1190.        assert(r > 0);
  1191.        return(0);
  1192.     }
  1193.  
  1194. dice/creat                                                        dice/creat
  1195.  
  1196.     FUNCTION
  1197.     create a file (UNIX)
  1198.  
  1199.     SYNTAX
  1200.     #include <fnctl.h>
  1201.     int fd = creat(file);
  1202.     char *file;
  1203.  
  1204.     DESCRIPTION
  1205.     creat creates a new file and returns a file descriptor for it. This
  1206.     call is equivalent to open(file,O_CREAT|O_TRUNC|O_RDWR); this is an
  1207.     obsolete function and should not be used.
  1208.  
  1209. dice/CreateDiceRexxPort                              dice/CreateDiceRexxPort
  1210.  
  1211.     FUNCTION
  1212.     Create an application ARexx port (DICE)
  1213.  
  1214.     SYNTAX
  1215.     #include <lib/rexx.h>
  1216.     short r = CreateDiceRexxPort(port, name)
  1217.     struct MsgPort *port;
  1218.     char *name;
  1219.  
  1220.     DESCRIPTION
  1221.     This call integrates any number of ARexx ports beyond the master port
  1222.     into DICE's ARexx system.  This call may be made from any point in
  1223.     your program.  After this call returns the message port will accept
  1224.     incomming ARexx messages.
  1225.  
  1226.     || NOTE: For simple programs you can simply use the master port
  1227.     || (RexxPort) that DICE sets up for you automatically and need not
  1228.     || bother with creating additional ports.  This call is more of use
  1229.     || in more complex programs which handle multiple projects
  1230.     || simultaniously.
  1231.  
  1232.     If you had declared RexxHostName as NULL causing DICE to not
  1233.     initialize an internal default RexxPort, you can pass NULL for port
  1234.     to initialize DICE's internal default RexxPort, thereby allowing
  1235.     PlaceRexxCommand() calls that specify a NULL port (i.e. to use DICE's
  1236.     internal default RexxPort).  You are not required to use DICE's
  1237.     internal message port, it is simply convenient.
  1238.  
  1239.     INPUTS
  1240.     struct MsgPort *port;
  1241.                 A blank msgPort structure (that is, totally
  1242.                 zero'd out). DICE will fill the structure with
  1243.                 appropriate values. DICE uses the same signal bit
  1244.                 as it allocated for the master port (RexxPort).
  1245.                 DICE makes this message port public through the
  1246.                 AddPort() call.
  1247.  
  1248.     char *name        A pointer to the name of the message port. DICE
  1249.                 adds a .NN extension to this name, finding a free
  1250.                 slot number when creating a public message port.
  1251.                 If you pass NULL for this field, DICE will create
  1252.                 a private message port suitable for handling
  1253.                 ARexx call-backs.  An error (-1) is returned if
  1254.                 no slots are available (all 99 are in use).  If
  1255.                 you had passed NULL for the port structure then
  1256.                 DICED will initialize RexxHostName to the
  1257.                 extended name.
  1258.  
  1259.     RESULTS
  1260.     int r;            the slot number for the port or -1 if an error
  1261.                 occured.
  1262.  
  1263.     SEE ALSO
  1264.     CreateGlobalDiceRexxPort, DeleteDiceRexxPort, GetDiceRexxPortSlot
  1265.  
  1266.     EXAMPLE
  1267.     See DICE ARexx Support in chapter
  1268.  
  1269. dice/CreateGlobalDiceRexxPort                  dice/CreateGlobalDiceRexxPort
  1270.  
  1271.     FUNCTION
  1272.     Create a global ARexx port (DICE)
  1273.  
  1274.     SYNTAX
  1275.     #include <lib/rexx.h>
  1276.     rc = CreateGlobalDiceRexxPort(port, name)
  1277.     int rc;
  1278.     struct MsgPort *port;
  1279.     char *name;
  1280.  
  1281.     DESCRIPTION
  1282.     CreateGlobalDiceRexxPort integrates any number of ARexx ports beyond
  1283.     the master port into DICE's ARexx system. This call may be made from
  1284.     any point in your program. After this call returns the message port
  1285.     will accept incomming ARexx messages.
  1286.  
  1287.     || NOTE: For simple programs you can simply use the master port
  1288.     || (RexxPort) that DICE sets up for you automatically and need not
  1289.     || bother with creating additional ports.  This call is more of use
  1290.     || in more complex programs which handle multiple projects
  1291.     || simultaniously.
  1292.  
  1293.     If you had declared RexxHostName as NULL causing DICE to not
  1294.     initialize an internal default RexxPort, you can pass NULL for
  1295.     msgPort to initialize DICE's internal default RexxPort, thereby
  1296.     allowing PlaceRexxCommand calls that specify a NULL port (i.e. to use
  1297.     DICE's internal default RexxPort).  You are not required to use
  1298.     DICE's internal message port, it is simply convenient.
  1299.  
  1300.     INPUTS
  1301.     struct MsgPort *port;
  1302.                 A blank msgPort structure (that is, totally
  1303.                 zero'd out). DICE will fill the structure with
  1304.                 appropriate values. DICE uses the same signal bit
  1305.                 as it allocated for the master port (RexxPort).
  1306.                 DICE will make this message port public through
  1307.                 the AddPort() call.
  1308.  
  1309.     char *name;        A pointer to the name of the message port.    DICE
  1310.                 uses this name verbatim.  An error (-1) is
  1311.                 returned if the port already exists.  If you had
  1312.                 passed NULL for the MsgPort structure DICE will
  1313.                 initialize RexxHostName to name.
  1314.  
  1315.     RESULTS
  1316.     int r;            0 for success, -1 for error
  1317.  
  1318.     SEE ALSO
  1319.     CreateDiceRexxPort, DeleteDiceRexxPort, GetDiceRexxPortSlot
  1320.  
  1321.     EXAMPLE
  1322.     See DICE ARexx Support in chapter
  1323.  
  1324. dice/ctime                                                        dice/ctime
  1325.  
  1326.     FUNCTION
  1327.     convert time into standard text (ANSI)
  1328.  
  1329.     SYNTAX
  1330.     #include <time.h>
  1331.     char *str = ctime(&t); time_t t;
  1332.  
  1333.     DESCRIPTION
  1334.     ctime converts a time pointer into ASCII text using the following
  1335.      format:
  1336.         Sun Dec 8 01:53:33 1987\n\0
  1337.     where \n stands for a newline character and \0 is terminating nul.
  1338.     The string is stored in a static buffer shared by both asctime and
  1339.     ctime and so will be overwritten whenever either function is called.
  1340.  
  1341.     INPUTS
  1342.     time_t *t;        pointer to a time_t value
  1343.  
  1344.     RESULTS
  1345.     char *str;        pointer to static string
  1346.  
  1347.     SEE ALSO
  1348.     time, localtime, asctime, strftime, ctime, clock
  1349.  
  1350.     EXAMPLE
  1351.     #include <stdio.h>
  1352.     #include <time.h>
  1353.  
  1354.     main()
  1355.     {
  1356.        time_t t = time(NULL);
  1357.        fputs(ctime(&t), stdout);
  1358.        return(0);
  1359.     }
  1360.  
  1361. dice/DeleteDiceRexxPort                              dice/DeleteDiceRexxPort
  1362.  
  1363.     FUNCTION
  1364.     Delete a DICE ARexx port (DICE)
  1365.  
  1366.     SYNTAX
  1367.     #include <lib/rexx.h>
  1368.     void DeleteDiceRexxPort(port)
  1369.     struct MsgPort *port;
  1370.  
  1371.     DESCRIPTION
  1372.     This call deletes a previously created DICE ARexx port. You may NOT
  1373.     delete any ARexx port while within DoRexxCommand().  This call may
  1374.     only be made from the top level of your program or you run the risk
  1375.     of deleted an ARexx port out from under yourself.
  1376.  
  1377.     ## WARNING: You may NOT delete the master ARexx port, only those you
  1378.     ## specifically create.
  1379.  
  1380.     This call automatically clears out any as yet unread messages on the
  1381.     port, removes the port from the public message list with RemPort(),
  1382.     and zero's the structure.
  1383.  
  1384.     INPUTS
  1385.     struct MsgPort *port;
  1386.                 The message port to delete.  You must have
  1387.                 created it using CreateGlobalDiceRexxPort or
  1388.                 CreateDiceRexxPort
  1389.  
  1390.     SEE ALSO
  1391.     CreateGlobalDiceRexxPort, CreateDiceRexxPort, GetDiceRexxPortSlot
  1392.  
  1393.     EXAMPLE
  1394.     See DICE ARexx Support in chapter
  1395.  
  1396. dice/dir                                                            dice/dir
  1397.  
  1398.     FUNCTION
  1399.     disk directory scanning (UNIX)
  1400.  
  1401.     SYNTAX
  1402.     #include <sys/dir.h>
  1403.     DIR *dirhan = opendir(path);
  1404.     struct direct *entry = readdir(dirhan);
  1405.     (void) rewinddir(dirhan);
  1406.     void
  1407.     closedir(dirhan);
  1408.     const char *path;
  1409.     DIR *dirhan;
  1410.  
  1411.     DESCRIPTION
  1412.     These are UNIX compatible directory scanning calls.  After opening a
  1413.     directory with opendir, you may scan it with successive calls to
  1414.     readdir until NULL is returned, then either rewinddir it for a
  1415.     rescan, or closedir it when done.  The DIR structure is private to
  1416.     the library.  Valid fields within struct direct are d_name (the file
  1417.     name), and d_namlen (the length of the file name, not usually
  1418.     needed).  You can chdir into the directory and stat each entry to
  1419.     obtain additional information.    Note that while the UNIX directory
  1420.     scanning routines will not be as efficient as the Amiga directory
  1421.     scanning routines, the UNIX directory scanning routines are portable.
  1422.  
  1423.     || NOTE: Unlike the Amiga directory scanning routines that use Amiga
  1424.     || File Locks, these calls will automatically deallocate resources if
  1425.     || the program terminates. rewinddir's prototype returns an int.
  1426.     || This is for internal use only.  You should never use rewinddir's
  1427.     || return value yourself.
  1428.  
  1429.     SEE ALSO
  1430.     chdir
  1431.  
  1432.     EXAMPLE
  1433.     #include <stdio.h>
  1434.     #include <sys/dir.h>
  1435.     main(int ac, char*av[])
  1436.     {
  1437.        DIR *dir;
  1438.        if (ac == 1)
  1439.        {
  1440.           puts("test dir");
  1441.           exit(1);
  1442.        }
  1443.        if (dir = opendir(av[1]))
  1444.        {
  1445.           struct direct *entry;
  1446.           while (entry = readdir(dir))
  1447.           {
  1448.          printf("%s\n", entry->d_name);
  1449.           }
  1450.           closedir(dir);
  1451.        }
  1452.        return(0);
  1453.     }
  1454.  
  1455. dice/DoRexxCommand                                        dice/DoRexxCommand
  1456.  
  1457.     FUNCTION
  1458.     Parse an incomming ARexx command (DICE)
  1459.  
  1460.     SYNTAX
  1461.     #include <lib/rexx.h>
  1462.     /* YOU DECLARE THIS IN YOUR CODE */
  1463.     long DoRexxCommand(msg, port, arg0, pres)
  1464.     void *msg;
  1465.     struct MsgPort *port;
  1466.     char *arg0;
  1467.     char **pres;
  1468.     {
  1469.        long rc = 0;
  1470.        *pres = "return string";
  1471.        return(rc);
  1472.     }
  1473.  
  1474.     DESCRIPTION
  1475.     DoRexxCommand is a routine that YOU supply to process incomming ARexx
  1476.     requests.  DICE will call your routine for any requests it processes
  1477.     with ProcessRexxCommands as well as for any requests that come in
  1478.     during processing of a PlaceRexxCommand. DICE presets pres to NULL.
  1479.  
  1480.     To return an error simply return a non-zero error code.
  1481.  
  1482.     To return a string, set pres to point to the string and return 0.
  1483.     DICE will make a copy of the string to return to ARexx.  Note that
  1484.     the application requesting the string will not see if if they have
  1485.     not requested 'OPTIONS RESULTS' as part of their processing.
  1486.  
  1487.     ## WARNING: Because your procedure must return before DICE can
  1488.     ## process the string, you MUST not assign pres to any local stack
  1489.     ## variables.  The resulting crash can be quite spectacular.
  1490.  
  1491.     INPUTS
  1492.     void *msg;        Incomming ARexx message if necessary.
  1493.  
  1494.     struct MsgPort *port;
  1495.                 Port that the message came in on.
  1496.  
  1497.     char *arg0;        The ARexx command that is to be processed.    Your
  1498.                 code must parse this in whatever way you want.
  1499.  
  1500.     char **pres;        Place to store result string.
  1501.  
  1502.     RESULTS
  1503.     int rc;         Return code to be passed to the application
  1504.                 requesting the ARexx command.
  1505.  
  1506.     SEE ALSO
  1507.     PlaceRexxCommand, PlaceRexxCommandDirect, ProcessRexxCommands
  1508.  
  1509.     EXAMPLE
  1510.     See DICE ARexx Support in chapter
  1511.  
  1512. dice/exit                                                          dice/exit
  1513.  
  1514.     FUNCTION
  1515.     Exit from a program 'nicely' (ANSI)
  1516.  
  1517.     SYNTAX
  1518.     #include <stdlib.h>
  1519.     (void) exit(code)
  1520.  
  1521.     DESCRIPTION
  1522.     exit exits the program and returns the specified exit code. Normally
  1523.     you pass 0 to indicate no errors, and a positive number to indicate a
  1524.     program error to the parent.  exit closes all stdio file pointers,
  1525.     low level file descriptors, perhaps a few other things, and then
  1526.     finally calls _exit with the code. If you use main you should call
  1527.     exit to exit the program or return an error code from main.  If you
  1528.     use the _main entry point (only for programmers dead set on
  1529.     optimizing executable size and using only system library calls) you
  1530.     should use the _exit exit point.
  1531.  
  1532.     SEE ALSO
  1533.     main, _main, _exit
  1534.  
  1535.     EXAMPLE
  1536.     main(int ac, char *av[])
  1537.     {
  1538.        if (ac <= 1) {
  1539.           puts("Sorry, you must supply a parameter!");
  1540.           exit(1);
  1541.        }
  1542.        puts("Thanks!");
  1543.        exit(0);
  1544.     }
  1545.  
  1546. dice/_exit                                                        dice/_exit
  1547.  
  1548.     FUNCTION
  1549.     exit from a program without bothering to release resources (ANSI)
  1550.  
  1551.     SYNTAX
  1552.     #include <stdlib.h>
  1553.     (void) _exit(code)
  1554.     int code;
  1555.  
  1556.     DESCRIPTION
  1557.     _exit exits from a program and returns the specified exit code.
  1558.     Normally you pass 0 to indicate no errors, a positive number to
  1559.     indicate a program error to the parent.  Note that since auto-init
  1560.     opened libraries are closed in the startup module (c.o),
  1561.     automatically opened libraries will be automatically closed for you.
  1562.     However, any libraries you manually declare the library base variable
  1563.     for and manually open must be closed by you.  You should only call
  1564.     _exit if you used the _main entry point (instead of the usual main),
  1565.     and then only after releasing all resources (such as file handles
  1566.     opened with open).
  1567.  
  1568.     INPUTS
  1569.     int code;        code is a value that is passed back to caller
  1570.  
  1571.     SEE ALSO
  1572.     main, _main, exit
  1573.  
  1574.     EXAMPLE
  1575.     _main()
  1576.     {
  1577.        Write(Output(), "Ouch!!\n", 7);
  1578.        _exit(20); /* 20 - Severe Error */
  1579.     }
  1580.  
  1581. dice/expand_args                                            dice/expand_args
  1582.  
  1583.     FUNCTION
  1584.     expand command line argument wildcards (DICE)
  1585.  
  1586.     SYNTAX
  1587.     #include <stdio.h>
  1588.     int error = expand_args(xac, xav, &ac, &av);
  1589.     int xac;
  1590.     const char **xav;
  1591.     int ac;
  1592.     char **av;
  1593.  
  1594.     DESCRIPTION
  1595.     expand_args is a powerful and convenient function.  A few lines of
  1596.     simple code allow your program to have full wildcard support under
  1597.     any version of the OS.    expand_args takes an argc/argv list and
  1598.     expands any wildcard arguments by scanning the appropriate directory.
  1599.     It  malloc's however much memory it needs to create the new list and
  1600.     ignores xav[0] (that is, it just copies it to the returned av[0]
  1601.     without doing a wildcard expansion). expand_args fills in the ac and
  1602.     av variables with its own malloc'd version of the argument list, now
  1603.     completely expanded.  There is no limit to the number of files that
  1604.     may be in this result list (you could conceivably have thousands).
  1605.     expand_args may be used to expand arbitrary AmigaDOS wildcards and is
  1606.     not limited to an anchored search.  For example, you could specify:
  1607.     sys:#?/#? in which case a list of a second level files/dirs will be
  1608.     generated. In the above case, expand_args scans sys, then scans any
  1609.     sub directories found in sys.  Generic AmigaDOS wildcarding is used
  1610.     and incredibly complex wildcards may be specified.  Please note,
  1611.     however, that any wildcard elements containing #? in combination with
  1612.     other elements (such as (a|b|c)) will cause huge amounts of stack to
  1613.     be used and also quite a bit of memory during the scan. expand_args
  1614.     limits itself to 4K of stack before giving up. Any program that uses
  1615.     expand_args should be run with at least 8K of stack.
  1616.  
  1617.     INPUTS
  1618.     int  xac;        original argc
  1619.  
  1620.     char **xav;        original argv
  1621.  
  1622.     int  *ac;        pointer to new argc
  1623.  
  1624.     char ***av;        pointer to new argv
  1625.  
  1626.     RESULTS
  1627.     int error;        0 if all went well, non-zero otherwise
  1628.  
  1629.     EXAMPLE
  1630.     #include <stdio.h>
  1631.     main(int xac, char **xav)
  1632.     {
  1633.        int ac, i, error;
  1634.        char **av;
  1635.        int error = expand_args(xac, xav, &ac, &av);
  1636.        for (i = 1; i < ac; ++i) {
  1637.           printf("%s\n", av[i]);
  1638.        }
  1639.     }    /* expand_args #?.c */
  1640.  
  1641. dice/fclose                                                      dice/fclose
  1642.  
  1643.     FUNCTION
  1644.     close a file pointer (ANSI)
  1645.  
  1646.     SYNTAX
  1647.     #include <stdio.h>
  1648.     int error = fclose(fp);
  1649.     FILE    *fp;
  1650.  
  1651.     DESCRIPTION
  1652.     fclose flushes any data remaining in the file pointer's output buffer
  1653.     to the file and then closes the file. The file pointer is no longer
  1654.     valid. fclose returns any error condition that occurred while it was
  1655.     flushing the buffered data to the file.  The file is closed even if
  1656.     an error occurred.
  1657.  
  1658.     || NOTE: You can fclose(stdin), fclose(stdout), and fclose(stderr) to
  1659.     || save space or detach your process from the console (i.e. allow the
  1660.     || console window to be closed).
  1661.  
  1662.     ## WARNING: If you fclose stdin, stdout, and stderr with the
  1663.     ## intention of removing all references to the console window, you
  1664.     ## must put a NULL in your processes pr_ConsoleTask field. Otherwise,
  1665.     ## the console window will be able to close, but your process will
  1666.     ## still have a reference to the now non-existent window.  Refer to
  1667.     ## the file_pointer manual page for general information
  1668.  
  1669.     INPUTS
  1670.     FILE *F;        file pointer
  1671.  
  1672.     RESULTS
  1673.     int error;        error on fclose, or 0 if none
  1674.  
  1675.     SEE ALSO
  1676.     fopen, fread, fwrite, fgets, fputs
  1677.  
  1678. dice/fcntl                                                        dice/fcntl
  1679.  
  1680.     FUNCTION
  1681.     file control on a file (UNIX)
  1682.  
  1683.     SYNTAX
  1684.     #include <fcntl.h>
  1685.     int r = fcntl(fd, req, arg)
  1686.     int fd;
  1687.     int req;
  1688.     int arg;
  1689.  
  1690.     DESCRIPTION
  1691.     fcntl may be used to control various aspects of an fd and is a higher
  1692.     level call than ioctl.    Currently, nothing truly significant can be
  1693.     accomplished by a fcntl call for files.  However, fcntl fully
  1694.     supports programmer simulated file descriptors.
  1695.  
  1696.     || NOTE: Refer to the file_descriptor manual page for general
  1697.     || information Unlike file pointers and file handles, the file
  1698.     || descriptor is checked for validity and if illegal, an error will
  1699.     || be returned.
  1700.  
  1701.     INPUTS
  1702.     int fd;         file descriptor to operate on
  1703.  
  1704.     int req;        request from <fcntl.h> (F_* defines)
  1705.  
  1706.     int arg;        control argument
  1707.  
  1708.     RESULTS
  1709.     int r;            result, error if less than 0
  1710.  
  1711.     SEE ALSO
  1712.     close, creat, fcntl, fdtofh, ioctl, isatty, lseek, mkdir, open, read,
  1713.     rmdir, unlink, write
  1714.  
  1715. dice/fdopen                                                      dice/fdopen
  1716.  
  1717.     FUNCTION
  1718.     associate a file pointer with an open file descriptor (UNIX)
  1719.  
  1720.     SYNTAX
  1721.     #include <stdio.h>
  1722.     FILE *fp = fdopen(fd, modes);
  1723.     int fd; char *modes;
  1724.  
  1725.     DESCRIPTION
  1726.     fdopen associates an open file descriptor with a file pointer.
  1727.  
  1728.     || NOTE: Once fclose is used, the file pointer will also close the
  1729.     || file descriptor.  Refer to the fopen manual page for a description
  1730.     || of available modes. Also, when you use fdopen the file will not be
  1731.     || truncated and if you specify mode a for append, the file
  1732.     || descriptor must have been opened with the O_APPEND flag.  That is,
  1733.     || the mode string should be similar to the open flags that were used
  1734.     || to open the file descriptor. Refer to the file_pointer manual page
  1735.     || for general information
  1736.  
  1737.     INPUTS
  1738.     int fd;         file descriptor to associated with a new file
  1739.                 pointer
  1740.  
  1741.     char *modes;        modes string, such as "r+".
  1742.  
  1743.     RESULTS
  1744.     FILE *fp;        new file pointer or NULL if an error occurred
  1745.  
  1746.     SEE ALSO
  1747.     fopen, fread, fwrite, fgets, fputs
  1748.  
  1749. dice/fdtofh                                                      dice/fdtofh
  1750.  
  1751.     FUNCTION
  1752.     return AmigaDOS file handle for file descriptor (AmigaDOS)
  1753.  
  1754.     SYNTAX
  1755.     #include <stdio.h>
  1756.     BPTR fh = fdtofh(fd);
  1757.     int fd;
  1758.  
  1759.     DESCRIPTION
  1760.     fdtofh returns the AmigaDOS file handle associated with a file
  1761.     descriptor or NULL if the file descriptor is illegal or simulated.
  1762.     You may then make AmigaDOS library calls using the file handle.
  1763.  
  1764.     INPUTS
  1765.     int fd;         file descriptor
  1766.  
  1767.     RESULTS
  1768.     BPTR fh;        associated file handle or NULL
  1769.  
  1770.     SEE ALSO
  1771.     close, creat, fcntl, ioctl, isatty, lseek, mkdir, open, read, rmdir,
  1772.     unlink, write
  1773.  
  1774.     EXAMPLE
  1775.     #include <stdio.h>
  1776.     main()
  1777.     {
  1778.     FILE * fh;
  1779.        write(1, "Quayle\n", 6);
  1780.        if( fh = fdtofh(1) )  /* Example Only! */
  1781.           Write(fh, "Bait\n", 6);
  1782.        return(0);
  1783.     }
  1784.  
  1785. dice/feof                                                          dice/feof
  1786.  
  1787.     FUNCTION
  1788.     test a file pointer for End Of File (ANSI)
  1789.  
  1790.     SYNTAX
  1791.     #include <stdio.h>
  1792.     int r = feof(fp);
  1793.     (MACRO) FILE *fp;
  1794.  
  1795.     DESCRIPTION
  1796.     feof returns the EOF  status of a file pointer.  The status is not
  1797.     changed by this macro.    0 is returned if no EOF condition exists,
  1798.     non-zero if an EOF condition exists (not necessarily 1 or -1, just
  1799.     non-zero).  Use clearerr to clear the EOF condition. Note than fseek
  1800.     and rewind also clear an EOF condition.
  1801.  
  1802.     INPUTS
  1803.     FILE *fp;        file pointer
  1804.  
  1805.     RESULTS
  1806.     int r;            0 if no EOF condition exists, != 0 if an EOF
  1807.                 condition exists (not necessarily 1 or -1).
  1808.  
  1809.     SEE ALSO
  1810.     fopen, fclose, fread, fwrite, fgets, fputs, file_pointer
  1811.  
  1812. dice/ferror                                                      dice/ferror
  1813.  
  1814.     FUNCTION
  1815.     return ERROR condition for file pointer (ANSI)
  1816.  
  1817.     SYNTAX
  1818.     #include <stdio.h>
  1819.     int r = ferror(fp); /* MACRO */
  1820.     FILE *fp;
  1821.  
  1822.     DESCRIPTION
  1823.     ferror returns the ERROR status of a file pointer.  The status is not
  1824.     changed by this macro.    0 is returned if no ERROR condition exists,
  1825.     non-zero if an ERROR condition exists (not necessarily 1 or -1, just
  1826.     non-zero).
  1827.  
  1828.     INPUTS
  1829.     FILE *fp;        file pointer
  1830.  
  1831.     RESULTS
  1832.     int r;            0 if no ERROR condition exists, != 0 if an ERROR
  1833.                 condition exists (not necessarily 1 or -1).
  1834.  
  1835.     SEE ALSO
  1836.     fopen, fclose, fread, fwrite, fgets, fputs, file_pointer
  1837.  
  1838. dice/fflush                                                      dice/fflush
  1839.  
  1840.     FUNCTION
  1841.     flush buffers to file (ANSI)
  1842.  
  1843.     SYNTAX
  1844.     #include <stdio.h>
  1845.     int error = fflush(fp);
  1846.     FILE *fp;
  1847.  
  1848.     DESCRIPTION
  1849.     fflush writes out any buffered data out to the file descriptor
  1850.     associated with the file pointer. Normally a file is either
  1851.     unbuffered, line buffered, or fully buffered;  fflush is useful in
  1852.     the latter two cases as is shown by the example. The function will
  1853.     return -1 if a write error occurred, 0 if no error occurred.
  1854.  
  1855.     || NOTE: Refer to the file_pointer manual page for general
  1856.     || information.
  1857.  
  1858.     INPUTS
  1859.     FILE *fp;        file pointer
  1860.  
  1861.     RESULTS
  1862.     int  error;        0 if no error, -1 on error.
  1863.  
  1864.     SEE ALSO
  1865.     fopen, fclose, fread, fwrite, fgets, fputs
  1866.  
  1867.     EXAMPLE
  1868.     /*
  1869.      *  Since text to stdout is normally line buffered,
  1870.      *  if we do not write out a newline '\n' then the
  1871.      *  line is still buffered in memory and we have to
  1872.      *  fflush() to write it out.
  1873.      */
  1874.     #include <stdio.h>
  1875.     main()
  1876.     {
  1877.        char buf[256];
  1878.        printf("Enter a number -");
  1879.        fflush(stdout);
  1880.        fgets(buf, sizeof(buf), stdin);
  1881.        printf("Munch Munch...");
  1882.        fflush(stdout);
  1883.        sleep(1);
  1884.        puts("Thanks!");
  1885.     }
  1886.  
  1887. dice/fgetc,getc                                              dice/fgetc,getc
  1888.  
  1889.     FUNCTION
  1890.     fgetc: get a single character (ANSI)
  1891.     getc: get a single character from a file pointer (ANSI)
  1892.  
  1893.     SYNTAX
  1894.     #include <stdio.h>
  1895.     int c = fgetc(fp);
  1896.     int c = getc(fp); /* MACRO */
  1897.     FILE *fp;
  1898.  
  1899.     DESCRIPTION
  1900.     getc and fgetc both read a single character from a file pointer.  The
  1901.     value returned is actually an int because EOF (-1) must be
  1902.     differentiated from a 255.  Each returns an integer 0-255 or EOF (-1)
  1903.     if an end of file occurs.
  1904.  
  1905.     || NOTE: Refer to the file_pointer manual page for general
  1906.     || information.
  1907.  
  1908.     INPUTS
  1909.     FILE *fp;        file pointer
  1910.  
  1911.     RESULTS
  1912.     int c;            character 0 to 255, or EOF (-1).
  1913.  
  1914.     SEE ALSO
  1915.     putc, fputc, fread, fwrite
  1916.  
  1917.     EXAMPLE
  1918.     /*
  1919.      *  copy stdin to stdout using getc/putc.  Normally
  1920.      *  one uses fread/fwrite, but I'll save that for the
  1921.      *  fread manual page.
  1922.      *  Note that I output the initial message to stderr so
  1923.      *  it does not get stuck into stdout in case the user
  1924.      *  has redirected stdout.
  1925.      */
  1926.     #include <stdio.h>
  1927.     main()
  1928.     {
  1929.        int c;
  1930.        fputs("Type a couple of lines, then ^\\ (EOF)\n",
  1931.           stderr);
  1932.        while ((c = getc(stdin)) != EOF)
  1933.        {
  1934.            putc(c, stdout);
  1935.        }
  1936.        return(0);
  1937.     }
  1938.  
  1939. dice/fgetpos                                                    dice/fgetpos
  1940.  
  1941.     FUNCTION
  1942.     get current file position (ANSI)
  1943.  
  1944.     SYNTAX
  1945.     #include <stdio.h>
  1946.     int error = fgetpos(fp, &pos);
  1947.     fpos_t pos;
  1948.  
  1949.     DESCRIPTION
  1950.     fgetpos returns the current seek position and is roughly equivalent
  1951.     to ftell.  fgetpos is a new ANSI call to better support C compilers
  1952.     that use 16 bit integers.  DICE uses 32 bit integers so fgetpos is
  1953.     not so useful.    fgetpos takes a file pointer and the address of a
  1954.     fpos_t type (a long).  It fills the fpos_t variable with the current
  1955.     file position and returns 0 if all went well, non-zero if an error
  1956.     occurred.
  1957.  
  1958.     || NOTE: Refer to the file_pointer manual page for general
  1959.     || information.
  1960.  
  1961.     INPUTS
  1962.     FILE *fp;        file pointer
  1963.  
  1964.     fpos_t *pos;        pointer to an fpos_t type that the position is
  1965.                 loaded into.
  1966.  
  1967.     RESULTS
  1968.     int error;        0 if no error, non-zero on error
  1969.  
  1970.     SEE ALSO
  1971.     ftell, rewind, fseek, rewind
  1972.  
  1973.     EXAMPLE
  1974.     /*
  1975.     **  Return the length of the file specified on the
  1976.     **  command line. */
  1977.     #include <stdio.h>
  1978.     main(int ac, char*av[])
  1979.     {
  1980.        FILE *fp;
  1981.        fpos_t off;
  1982.        if (ac == 1) {
  1983.           puts("Expected a filename argument");
  1984.           exit(1);
  1985.        }
  1986.        fp = fopen(av[1], "r");
  1987.        if (fp == NULL) {
  1988.           printf("Unable to open %s\n", av[1]);
  1989.           exit(5);
  1990.        }
  1991.        fseek(fp, 0L, SEEK_END);
  1992.        if (fgetpos(fp, &off)) {
  1993.           puts("Error getting file position");
  1994.           exit(20);
  1995.        }
  1996.        fclose(fp);
  1997.        printf("File %s is %d bytes long\n", av[1], off);
  1998.        return(0);
  1999.     }
  2000.  
  2001. dice/fgets                                                        dice/fgets
  2002.  
  2003.     FUNCTION
  2004.     get a line from a file pointer (ANSI)
  2005.  
  2006.     SYNTAX
  2007.     #include <stdio.h>
  2008.     char *ptr = fgets(buf, maxlen, fp);
  2009.     char *buf;
  2010.     int maxlen;
  2011.     FILE *fp;
  2012.  
  2013.     DESCRIPTION
  2014.     fgets gets a line from the specified file pointer, returning the
  2015.     first argument (buf) or NULL if an error or EOF occurs. fgets stores
  2016.     the line in buf, up to maxlen characters. This maximum includes a
  2017.     terminating newline '\n' and NULL '\0'. If more than maxlen-1
  2018.     characters are in the line fgets will terminate operation and put a
  2019.     NULL as the last character (so the buffer will still be a valid
  2020.     string). It is common to become confused by these functions:
  2021.  
  2022.  gets, puts
  2023.         These functions strip newline on input, add newline on output.
  2024.         gets works on stdin, puts on stdout.
  2025.  
  2026.  fgets, fputs
  2027.         These functions leave newlines alone on input, don't add to the
  2028.         output. Any file pointer, including stdin and stdout may be
  2029.         specified.
  2030.  
  2031.         || NOTE: Refer to the file_pointer manual page for general
  2032.         || information.
  2033.  
  2034.     INPUTS
  2035.     char *buf;        buffer
  2036.  
  2037.     int  maxlen;        maximum buffer size
  2038.  
  2039.     FILE *fp;        file pointer
  2040.  
  2041.     RESULTS
  2042.     char *ptr;        buf if all is well, or NULL if error or EOF
  2043.  
  2044.     SEE ALSO
  2045.     gets, puts, fputs, fread, getc, fgetc
  2046.  
  2047.     EXAMPLE
  2048.     #include <stdio.h>
  2049.     main()
  2050.     {
  2051.        unsigned char buf[128];
  2052.        short i;
  2053.        printf("Enter a line - ");
  2054.        fflush(stdout);
  2055.        if (fgets(buf, sizeof(buf), stdin) == NULL)
  2056.           exit(1);
  2057.        printf("In Hex: ");
  2058.        for (i = 0; buf[i]; ++i) printf(" %02x", buf[i]);
  2059.        puts("");
  2060.        return(0);
  2061.     }
  2062.  
  2063. dice/fhprintf                                                  dice/fhprintf
  2064.  
  2065.     FUNCTION
  2066.     formatted printing to a DOS file handle (AmigaDOS)
  2067.  
  2068.     SYNTAX
  2069.     #include <stdio.h>
  2070.     int n = fhprintf(fh, ctl, ...);
  2071.     BPTR fh;
  2072.     const char *ctl;
  2073.  
  2074.     DESCRIPTION
  2075.     fhprintf provides a method of using DICE's pfmt lib to do formatted
  2076.     printing to a file handle instead of a stdio file pointer. Output is
  2077.     unbuffered and thus not very efficient, but the call can be extremely
  2078.     useful when debugging libraries and such. If you have just a few
  2079.     things to print, and want to save the space the entire stdio package
  2080.     takes, you could use this function and _main.
  2081.  
  2082.     INPUTS
  2083.     BPTR fh;        DOS file handle
  2084.  
  2085.     const char *ctl;    format string, see printf()
  2086.  
  2087.     RESULTS
  2088.     int n;            number of characters output
  2089.  
  2090.     SEE ALSO
  2091.     printf, sprintf, vsprintf, fprintf, vfprintf, _main
  2092.  
  2093.     EXAMPLE
  2094.     void _main(int ac, char**av)
  2095.     {
  2096.        fhprintf(Output(), "The answer is %d!\n", 42);
  2097.     }
  2098.  
  2099. dice/file_descriptor                                    dice/file_descriptor
  2100.  
  2101.     FUNCTION
  2102.     file descriptor
  2103.  
  2104.     DESCRIPTION
  2105.     A file descriptor is the lowest portable access to the file system a
  2106.     C program may make.  File descriptors are used with open, read,
  2107.     write, close, etc.  A file descriptor is unbuffered (that is, every
  2108.     operation goes to the kernel and does not get buffered locally).
  2109.  
  2110.     || NOTE: Remember that a file descriptor is different from a stdio
  2111.     || file pointer (see the file_pointer manual page) and an AmigaDOS
  2112.     || file handle.
  2113.  
  2114. dice/fileno                                                      dice/fileno
  2115.  
  2116.     FUNCTION
  2117.     return file descriptor given a file pointer (UNIX)
  2118.  
  2119.     SYNTAX
  2120.     #include <stdio.h>
  2121.     int fd = fileno(fp); /* MACRO */
  2122.     FILE *fp;
  2123.  
  2124.     DESCRIPTION
  2125.     The fileno macro returns the file descriptor (open, close, read,
  2126.     write) associated with the file pointer (fopen, fclose, fread,
  2127.     fwrite). This is still not the AmigaDOS file handle; to get that you
  2128.     must use the fdtofh call.
  2129.  
  2130.     ## WARNING: If you use the file descriptor of a file pointer the file
  2131.     ## pointer will get its seek position confused. Additionally, there
  2132.     ## might be unflushed data in the file pointer's buffers that has not
  2133.     ## been written out to the file descriptor yet.  There also might be
  2134.     ## unread input on the file pointer's input buffers already read from
  2135.     ## the file descriptor.
  2136.  
  2137.     || NOTE: Refer to the file_pointer manual page for general
  2138.     || information.
  2139.  
  2140.     INPUTS
  2141.     FILE *fp;        file pointer
  2142.  
  2143.     RESULTS
  2144.     int  fd;        associated file descriptor
  2145.  
  2146.     SEE ALSO
  2147.     fdopen, fopen, fclose, open, close
  2148.  
  2149. dice/file_pointer                                          dice/file_pointer
  2150.  
  2151.     FUNCTION
  2152.     STDIO file_pointer (ANSI)
  2153.  
  2154.     DESCRIPTION
  2155.     A file pointer is the basis for stdio, a standard file management
  2156.     package available across all versions of C.  If you stick to the
  2157.     standard functions, your program should work on any machine that can
  2158.      compile C.
  2159.  
  2160.     The specific Amiga implementation builds file pointers (type "FILE
  2161.     *") on top of file descriptors (type "int"; see the file_descriptor
  2162.     manual page).  File pointers have a layer of buffering (good if you
  2163.     use many small reads and writes), while file descriptors pass
  2164.     requests directly to AmigaDOS.    Note that a stdio file pointer is not
  2165.     a file descriptor nor is a AmigaDOS file handle.  You may call only
  2166.     stdio routines (fopen, fclose, fread, fwrite, etc.) with file
  2167.     pointers.
  2168.  
  2169.     Some C implementations flush stdout whenever stdin is read.  DICE
  2170.     does not do this.
  2171.  
  2172. dice/fopen                                                        dice/fopen
  2173.  
  2174.     FUNCTION
  2175.     open a file and create a file pointer (ANSI)
  2176.  
  2177.     SYNTAX
  2178.     #include <stdio.h>
  2179.     FILE *fp = fopen(filename, modes)
  2180.     char *filename;
  2181.     char *modes;
  2182.  
  2183.     DESCRIPTION
  2184.     fopen is the grand master of stdio:  it opens and possibly creates a
  2185.     file and returns a new file pointer for use by the program. The first
  2186.     argument is the file to open, the second is a string containing one
  2187.     or mode characters defined as follows:
  2188.  
  2189.     Mode : Usage
  2190.     =====+===============================================================
  2191.     r    : open for reading, the file must already exist
  2192.     -----+---------------------------------------------------------------
  2193.     w    : open for writing, the file is created if it does not exist,
  2194.          : truncated if it does
  2195.     -----+---------------------------------------------------------------
  2196.     a    : open for append, writes always append to the file.
  2197.     -----+---------------------------------------------------------------
  2198.     a    : the file starts out positioned at the end instead of at the
  2199.          : beginning.  This mode also creates the file but only if it
  2200.          : does not already exist.
  2201.     -----+---------------------------------------------------------------
  2202.     r+   : also allows writing to the file in addition to reading
  2203.     -----+---------------------------------------------------------------
  2204.     w+   : also allows reading from the file
  2205.     -----+---------------------------------------------------------------
  2206.     b    : open for binary read/write, else the file is assumed to
  2207.          : contain text (this is ignored by DICE since there is no
  2208.          : difference on the Amiga).
  2209.     -----+---------------------------------------------------------------
  2210.  
  2211.     All combinations except "rw" are allowed.  One uses "r+" or "w+"
  2212.     instead of "rw".  By the above description "r+" is used to update an
  2213.     existing file while "w+" is used to create a new file and then allow
  2214.     reads as well as writes to it. "wa" is equivalent to creating a new
  2215.     file and then appending to it. "r+a" is equivalent to appending to an
  2216.     already existing file. Other examples of valid modes combinations:
  2217.     "r+b", "w+b", "rb", "wb", "ab", "w", "r", "r+", "a", etc...
  2218.  
  2219.     || NOTE: Refer to the file_pointer manual page for general
  2220.     || information.
  2221.  
  2222.     INPUTS
  2223.     char *filename;     file name to open
  2224.  
  2225.     char *modes;        open modes string
  2226.  
  2227.     RESULTS
  2228.     FILE *fp;        new file pointer
  2229.  
  2230.     SEE ALSO
  2231.     fdopen, fclose, open, close
  2232.  
  2233.     EXAMPLE
  2234.     #include <stdio.h>
  2235.     main()
  2236.     {
  2237.     FILE    *fp;
  2238.     char *    filename = "t:XX";
  2239.     char *    why     = "I don't do windows\n";
  2240.  
  2241.         fp = fopen(filename, "wb");
  2242.         if( fp )
  2243.         {
  2244.         fwrite(why, 1, strlen(why), fp);
  2245.         fwrite(why, strlen(why), 1, fp);
  2246.         fclose( fp );
  2247.         } else
  2248.         printf("Can't open file %s\n", filename);
  2249.         return(0);
  2250.  
  2251.     }
  2252.  
  2253. dice/fputc,putc                                              dice/fputc,putc
  2254.  
  2255.     FUNCTION
  2256.     fputc: write a single character (ANSI)
  2257.     putc: write a single character (ANSI)
  2258.  
  2259.     SYNTAX
  2260.     #include <stdio.h>
  2261.     int c = fputc(c, fp);
  2262.     int c = putc(c, fp); /* MACRO */
  2263.     FILE *fp;
  2264.  
  2265.     DESCRIPTION
  2266.     fputc writes a single character to a file pointer.  If all goes well
  2267.     the character is returned, else EOF is returned. fputc is a function
  2268.     call while putc is a macro
  2269.  
  2270.     || NOTE: Refer to the file_pointer manual page for general
  2271.     || information.
  2272.  
  2273.     INPUTS
  2274.     int c;            character to write
  2275.  
  2276.     FILE *fp;        file pointer
  2277.  
  2278.     RESULTS
  2279.     int c;            character written (same as first argument) or EOF
  2280.                 if error.
  2281.  
  2282.     SEE ALSO
  2283.     getc, putc, fputc, fread, fwrite, puts, fputs, gets, fgets
  2284.  
  2285.     EXAMPLE
  2286.     /*
  2287.      *  copy stdin to stdout using fgetc/fputc. Normally one
  2288.      *  uses fread/fwrite, but I'll save that for the fread
  2289.      *  manual page. note that I output the initial message
  2290.      *  to stderr so it does not get stuck into stdout in
  2291.      *  case the user has redirected stdout.
  2292.      */
  2293.     #include <stdio.h>
  2294.     main()
  2295.     {
  2296.        int c;
  2297.        fputs("Type a couple of lines, then ^\\ (EOF)\n",
  2298.           stderr);
  2299.        while ((c = fgetc(stdin)) != EOF)
  2300.        {
  2301.           fputc(c, stdout);
  2302.        }
  2303.        return(0);
  2304.     }
  2305.  
  2306. dice/fputs,puts                                              dice/fputs,puts
  2307.  
  2308.     FUNCTION
  2309.     fputs: write a string to a file pointer (ANSI)
  2310.     puts: then write a string to stdout, appending newline (ANSI)
  2311.  
  2312.     SYNTAX
  2313.     #include <stdio.h>
  2314.     int error = fputs(s, fp);
  2315.     int error = puts(s);
  2316.     const char *s;
  2317.     FILE *fp;
  2318.  
  2319.     DESCRIPTION
  2320.     fputs writes a string to a file pointer all the way up to, but not
  2321.     including, the NULL.  puts does the same thing but to stdout, and
  2322.     puts additionally writes a newline out.
  2323.  
  2324.     || NOTE: Refer to the file_pointer manual page for general
  2325.     || information.
  2326.  
  2327.     It is common to get confused between fputs and puts. Remember that
  2328.     puts adds a newline to the output while fputs does not.  gets strips
  2329.     the newline from an input line while fgets does not.
  2330.  
  2331.     INPUTS
  2332.     char *s;        string to write
  2333.  
  2334.     FILE *fp;        file pointer
  2335.  
  2336.     RESULTS
  2337.     int error;        0 or positive if all went ok, else negative. Note
  2338.                 that unlike printf() routines the numberr of
  2339.                 chars written out is NOT returned.
  2340.  
  2341.     SEE ALSO
  2342.     getc, putc, fputc, fread, fwrite, gets, fgets
  2343.  
  2344.     EXAMPLE
  2345.     #include <stdio.h>
  2346.     main()
  2347.     {
  2348.         /* note newline */
  2349.         fputs("This is a test of fputs\n", stdout);
  2350.         puts("This is a test of puts"); /*  note lack of */
  2351.         puts("That's it!");
  2352.         return(0);
  2353.     }
  2354.  
  2355. dice/fseek                                                        dice/fseek
  2356.  
  2357.     FUNCTION
  2358.     seek within a file pointer (ANSI)
  2359.  
  2360.     SYNTAX
  2361.     #include <stdio.h>
  2362.     int error = fseek(fp, offset, how);
  2363.     FILE *fp;
  2364.     long offset;
  2365.     int how;
  2366.  
  2367.     DESCRIPTION
  2368.     fseek changes the current seek position within a file. Offset is
  2369.     interpreted according to the how argument:
  2370.  
  2371.          :   :
  2372.     =========+===+=====================================================
  2373.     SEEK_SET : 0 : skip to position relative to beginning of file
  2374.     ---------+---+-----------------------------------------------------
  2375.     SEEK_CUR : 1 : skip to position relative to current position in
  2376.          :   : file
  2377.     ---------+---+-----------------------------------------------------
  2378.     SEEK_END : 2 : skip to position relative to end of file.
  2379.     ---------+---+-----------------------------------------------------
  2380.  
  2381.     So, for example, one may seek to the beginning of a file by fseek(fp,
  2382.     0L, SEEK_SET);, to the end of the file by fseek(fp, 0L, SEEK_END);.
  2383.     Calling getc at this time would return an immediate EOF.  You can
  2384.     skip characters in a file with something like fseek(fp, 5L,
  2385.     SEEK_CUR); which skips 5 characters.  Note that when seeking relative
  2386.     to the end of the file, negative offsets are used.  For example, to
  2387.     seek to the very last character in the file you would use fseek(fp,
  2388.     -1L, SEEK_END); fseek returns 0 on success, a negative number on
  2389.     ERROR.    A common mistake is to expect fseek to return the new
  2390.     position  of the file but this is not what is returned.  Use ftell or
  2391.     fgetpos to determine the current offset into a file.
  2392.  
  2393.     || NOTE: Refer to the file_pointer manual page for general
  2394.     || information fseek flushes any buffered write data before seeking.
  2395.  
  2396.     INPUTS
  2397.     FILE *fp;        file pointer to seek
  2398.  
  2399.     long offset;        relative offset, depending on how
  2400.  
  2401.     int how;        0, 1, or 2 (absolute, relative, end- relative)
  2402.  
  2403.     RESULTS
  2404.     int error;        Error code from operation
  2405.  
  2406.     SEE ALSO
  2407.     ftell, fgetpos, fsetpos, rewind
  2408.  
  2409.     EXAMPLE
  2410.     see fopen for an example
  2411.  
  2412. dice/fread                                                        dice/fread
  2413.  
  2414.     FUNCTION
  2415.     read data from a file pointer (ANSI)
  2416.  
  2417.     SYNTAX
  2418.     #include <stdio.h>
  2419.     size_t robjs = fread(buf, objsize, nobjs, fp);
  2420.     void *buf; size_t objsize; size_t nobjs;
  2421.     FILE *fp;
  2422.  
  2423.     DESCRIPTION
  2424.     fread reads an arbitrary number of objects from a file pointer into
  2425.     the specified buffer and returns the actual number of objects read.
  2426.     If the return value robjs is not equal to nobjs then fread was unable
  2427.     to read the requested number of objects due to either a read error or
  2428.     an EOF condition.  If the file is already completely exhausted fread
  2429.     simply returns 0. Having two size arguments, an object size and a
  2430.     number of objects, simplifies the reading of structure arrays off
  2431.     disk.
  2432.  
  2433.     || NOTE: To use fread to read an arbitrary number of bytes one
  2434.     || normally uses the form: r = fread(buf, 1, n, fp); that is, n
  2435.     || objects of size 1.  fread will attempt to read objsize * nobjs
  2436.     || bytes into the specified buffer.
  2437.  
  2438.     INPUTS
  2439.     void   *buf;        buffer to load data into
  2440.  
  2441.     size_t objsize;     size of one object
  2442.  
  2443.     size_t nobjs;        number of objects to read
  2444.  
  2445.     FILE   *fp;        file pointer to read objects from
  2446.  
  2447.     RESULTS
  2448.     size_t robjs;        number of objects actually read or 0 if EOF or
  2449.                 ERROR.
  2450.  
  2451.     SEE ALSO
  2452.     fwrite, fopen, fclose, fseek, ftell, rewind
  2453.  
  2454.     EXAMPLE
  2455.     #include stdlib.h
  2456.     #include stdio.h
  2457.  
  2458.     #define NOBJS    15
  2459.  
  2460.     typedef struct
  2461.         {
  2462.            short   a, b, c, d;
  2463.         }
  2464.         MyObj;
  2465.  
  2466.  
  2467.         main()
  2468.         {
  2469.            FILE *fp;
  2470.            MyObj O;
  2471.            if (fp = fopen("T:fwrite_tmp", "r"))
  2472.            {
  2473.               short n;
  2474.               for (n = 0; n < NOBJS; ++n)
  2475.               {
  2476.              O.a = n;
  2477.              O.b = n * 2;
  2478.              O.c = n * 3;
  2479.              O.d = n * 4;
  2480.              if (fread(&O, sizeof(MyObj), 1, fp) != 1)
  2481.              {
  2482.                 printf("read error, eof is %d\n",feof(fp));
  2483.                 exit(1);
  2484.              }
  2485.              else {
  2486.                 printf("read something, O.a is %d\n",O.a);
  2487.              }
  2488.               }
  2489.            fclose(fp);
  2490.            }
  2491.            return(0);
  2492.         }
  2493.  
  2494. dice/free                                                          dice/free
  2495.  
  2496.     FUNCTION
  2497.     free memory allocated by calloc, malloc, or strdup (ANSI)
  2498.  
  2499.     SYNTAX
  2500.     #include <stdlib.h>
  2501.     void free(ptr);
  2502.     void *ptr;
  2503.  
  2504.     DESCRIPTION
  2505.     free frees memory allocated by calloc, malloc, or strdup.
  2506.  
  2507.     || NOTE: Under ANSI C, it is legal to free(NULL). This is, however, a
  2508.     || bad idea to depend on.  Usually a free of the NULL pointer
  2509.     || indicates a bug in the code.
  2510.  
  2511.     INPUTS
  2512.     void *ptr;        pointer to memory to free
  2513.  
  2514.     SEE ALSO
  2515.     malloc, calloc, strdup
  2516.  
  2517.     EXAMPLE
  2518.     see calloc example
  2519.  
  2520. dice/freopen                                                    dice/freopen
  2521.  
  2522.     FUNCTION
  2523.     reopen a new file using an existing file pointer, the existing file
  2524.     is closed before it is reused (ANSI)
  2525.  
  2526.     SYNTAX
  2527.     #include <stdio.h>
  2528.     FILE *fp = freopen(filename, modes, ofp)
  2529.     char *filename;
  2530.     char *modes;
  2531.     FILE *ofp;
  2532.  
  2533.     DESCRIPTION
  2534.     freopen works exactly like fopen but takes an additional argument,  a
  2535.     file pointer to reuse. This file pointer, ofp, must reference a valid
  2536.     open file.  freopen will close out ofp then reuse the descriptor to
  2537.     open the new file, returning ofp (fp == ofp) on success, NULL on
  2538.     failure. If the freopen fails NULL is returned and the original file
  2539.     pointer is still closed, but not freed so you may call freopen again
  2540.     with the same ofp, even though it has already been closed.  Refer to
  2541.     the fopen manual page for information on the modes string. freopen is
  2542.     often used to change a program's stdin, stdout, or stderr though to
  2543.     be frank, using a separate file pointer is normally much more
  2544.     modular.
  2545.  
  2546.     ## WARNING: ANSI does not specify that the ofp can be used in a
  2547.     ## second freopen if the first freopen using ofp fails (returns
  2548.     ## NULL). Many implementations free the file pointer. This just might
  2549.     ## be the proper way of doing things but we don't know.  We suggest
  2550.     ## you do not use DICE's feature in that respect as we might have to
  2551.     ## change it back to free ofp if the new file is unopenable.
  2552.  
  2553.     || NOTE: Refer to the file_pointer manual page for general
  2554.     || information
  2555.  
  2556.     INPUTS
  2557.     char *filename;     file name to open
  2558.  
  2559.     char*modes;        open modes string
  2560.  
  2561.     FILE *ofp;        open file pointer to reuse
  2562.  
  2563.     RESULTS
  2564.     FILE *fp;        same as ofp if the new open worked, NULL
  2565.                 otherwise
  2566.  
  2567.     SEE ALSO
  2568.     fdopen, fopen, fclose, open, close
  2569.  
  2570.     EXAMPLE
  2571.     /*
  2572.      *  re-open stdin to an Amiga console device
  2573.      */
  2574.     #include <stdio.h>
  2575.     #include <assert.h>
  2576.     main()
  2577.     {
  2578.        char buf[256];
  2579.        assert(freopen("CON:0/0/320/100/freopen-in", "r",
  2580.           stdin));
  2581.        assert(freopen("CON:320/0/320/100/freopen-out", "w",
  2582.           stdout));
  2583.        /*
  2584.         *  set to line buffered
  2585.         */
  2586.        setvbuf(stdin, NULL, _IOLBF, 0);
  2587.        setvbuf(stdout, NULL, _IOLBF, 0);
  2588.        puts("Type a (short) line in the second window");
  2589.        gets(buf);
  2590.        fclose(stdin);
  2591.        fclose(stdout);
  2592.        fprintf(stderr, "Your line was: %s\n", buf);
  2593.        return(0);
  2594.     }
  2595.  
  2596. dice/fsetpos                                                    dice/fsetpos
  2597.  
  2598.     FUNCTION
  2599.     set position within file pointer (nearly equivalent to fseek
  2600.     absolute) (ANSI)
  2601.  
  2602.     SYNTAX
  2603.     #include <stdio.h>
  2604.     int error = fsetpos(fp, &pos);
  2605.     FILE *fp; fpos_t pos;
  2606.  
  2607.     DESCRIPTION
  2608.     fsetpos is a nearly useless call that is essentially the same as
  2609.     fseek(fp, (long)pos, 0); fsetpos seeks within a file pointer to the
  2610.     absolute position specified by an fpos_t type.    The address of an
  2611.     fpos_t object is passed to fsetpos. Normally one saves the current
  2612.     seek position into an fpos_t type using the fgetpos function, then
  2613.     seeks back using the fsetpos function.    In this way the programmer
  2614.     need not make any direct reference to the contents of the fpos_t
  2615.     type.
  2616.  
  2617.     INPUTS
  2618.     FILE *fp;        file pointer to seek
  2619.  
  2620.     fpos_t *pos;        pointer to fpos_t type previously initialized by
  2621.                 a fgetpos() call.
  2622.  
  2623.     RESULTS
  2624.     int error;        0 if no error, < 0 if error
  2625.  
  2626.     SEE ALSO
  2627.     ftell, fsetpos, fseek, rewind
  2628.  
  2629.     EXAMPLE
  2630.     /*
  2631.      *  get a line, save current position, get rest of
  2632.      *  file, go back to saved position, retrieve line
  2633.      *  again and print again.
  2634.      */
  2635.     #include <stdio.h>
  2636.     main(int ac, char*av[])
  2637.     {
  2638.        FILE *fp;
  2639.        fpos_t save_pos;
  2640.        int count;
  2641.        char buf[256];
  2642.        if (ac == 1)
  2643.        {
  2644.           puts("Expected textfile argument");
  2645.           exit(1);
  2646.        }
  2647.        fp = fopen(av[1], "r");
  2648.        if (fp == NULL)
  2649.        {
  2650.           printf("Unable to open %s\n", av[1]);
  2651.           exit(1);
  2652.        }
  2653.        for    (count = 0; fgets(buf, sizeof(buf), fp);
  2654.               ++count)
  2655.        {
  2656.           if (count == 0) /*  just before second line */
  2657.          fgetpos(fp, &save_pos);
  2658.           fprintf(stdout, "%-3d: %s", count + 1, buf);
  2659.        }
  2660.        if (count < 2)
  2661.        {
  2662.           puts("not enough lines in file for example!");
  2663.           exit(1);
  2664.        }
  2665.        puts("--end of file, now seeking back to line 2--");
  2666.        fsetpos(fp, &save_pos);
  2667.        if (fgets(buf, sizeof(buf), fp) == NULL)
  2668.        {
  2669.           puts("error!");
  2670.           exit(1);
  2671.        }
  2672.        fprintf(stdout, "%-3d: %s", 2, buf);
  2673.        fclose(fp);
  2674.        return(0);
  2675.     }
  2676.  
  2677. dice/fstat                                                        dice/fstat
  2678.  
  2679.     FUNCTION
  2680.     stat a file descriptor (UNIX)
  2681.  
  2682.     SYNTAX
  2683.     #include <sys/stat.h>
  2684.     int error = fstat(fd, &stat_buf);
  2685.     struct stat stat_buf;
  2686.  
  2687.     DESCRIPTION
  2688.     fstat is a UNIX-compatible call that returns information pertaining
  2689.     to the file represented by an open file descriptor. See stat for
  2690.     information on the struct stat fields.
  2691.  
  2692.     || NOTE: fstat works just like stat except you provide a UNIX file
  2693.     ||  descriptor (not an AmigaDOS File Handle).
  2694.     || Under 2.0, ExamineFH is used.  Under 1.3, the original path used
  2695.     || to open the file will be stat'd, which ends up scanning the
  2696.     || directory if the file was open for exclusive access.
  2697.  
  2698.     INPUTS
  2699.     int  fd;        file descriptor to stat
  2700.  
  2701.     struct stat *sbuf;
  2702.                 address of stat structure that will be filled in
  2703.  
  2704.     RESULTS
  2705.     int error;        0 on success, < 0 on error
  2706.  
  2707.     SEE ALSO
  2708.     chdir
  2709.  
  2710.     EXAMPLE
  2711.     #include <stdio.h>
  2712.     #include <fcntl.h>
  2713.     #include <sys/stat.h>
  2714.     main(int ac, char**av)
  2715.     {
  2716.        int r, fd;
  2717.        struct stat stat_buf;
  2718.        if (ac == 1)
  2719.        {
  2720.           puts("Expected a file name");
  2721.           exit(1);
  2722.        }
  2723.        fd = open(av[1], O_RDONLY );
  2724.        if( fd )
  2725.        {
  2726.           r = fstat(fd, &stat_buf);
  2727.           if (r < 0)
  2728.           printf("Can't stat fd=%d\n", fd);
  2729.           else
  2730.           {
  2731.         printf("File is %d bytes\n", stat_buf.st_size);
  2732.         printf("modified %s", ctime(&stat_buf.st_ctime));
  2733.           }
  2734.           close(fd);
  2735.        }
  2736.        return(0);
  2737.     }
  2738.  
  2739. dice/ftell                                                        dice/ftell
  2740.  
  2741.     FUNCTION
  2742.     return current position within file pointer (ANSI)
  2743.  
  2744.     SYNTAX
  2745.     #include <stdio.h>
  2746.     long pos = ftell(fp);
  2747.     FILE *fp;
  2748.  
  2749.     DESCRIPTION
  2750.     ftell returns the current absolute seek offset within a file pointer.
  2751.  
  2752.     INPUTS
  2753.     FILE *fp;        file pointer retrieve seek position from
  2754.  
  2755.     RESULTS
  2756.     long pos;        current absolute seek position in file
  2757.  
  2758.     SEE ALSO
  2759.     ftell, fgetpos, fsetpos, fseek, rewind
  2760.  
  2761.     EXAMPLE
  2762.     /*
  2763.      * get a line, save current position, get rest of file,
  2764.      * go backto saved position, retrieve line again and
  2765.      * print again.
  2766.      * like fsetpos() example but uses ftell()/fseek()
  2767.      * instead
  2768.      */
  2769.     #include <stdio.h>
  2770.     main(int ac, char**av)
  2771.     {
  2772.        FILE *fp;
  2773.        long save_pos;
  2774.        int count;
  2775.        char buf[256];
  2776.        if (ac == 1)
  2777.        {
  2778.           puts("Expected textfile argument");
  2779.           exit(1);
  2780.        }
  2781.        fp = fopen(av[1], "r");
  2782.        if (fp == NULL)
  2783.        {
  2784.           printf("Unable to open %s\n", av[1]);
  2785.           exit(1);
  2786.        }
  2787.        for (count = 0; fgets(buf, sizeof(buf), fp); ++count)
  2788.        {
  2789.           if (count == 0)      /*  just before second line */
  2790.          save_pos = ftell(fp);
  2791.           fprintf(stdout, "%-3d: %s", count + 1, buf);
  2792.        }
  2793.        if (count < 2)
  2794.        {
  2795.           puts("not enough lines in file for example!");
  2796.           exit(1);
  2797.        }
  2798.        puts("--end of file, now seeking back to line 2--");
  2799.        fseek(fp, save_pos, SEEK_SET);
  2800.        if (fgets(buf, sizeof(buf), fp) == NULL)
  2801.        {
  2802.           puts("error!");
  2803.           exit(1);
  2804.        }
  2805.        fprintf(stdout, "%-3d: %s", 2, buf);
  2806.        fclose(fp);
  2807.        return(0);
  2808.     }
  2809.  
  2810. dice/fwrite                                                      dice/fwrite
  2811.  
  2812.     FUNCTION
  2813.     write data to a file pointer (ANSI)
  2814.  
  2815.     SYNTAX
  2816.     #include <stdio.h>
  2817.     size_t robjs = fwrite(buf, objsize, nobjs, fp);
  2818.     const void *buf;
  2819.     size_t objsize;
  2820.     size_t nobjs;
  2821.     FILE *fp;
  2822.  
  2823.     DESCRIPTION
  2824.     fwrite writes the specified number of objects to a file pointer from
  2825.     the specified buffer and returns the actual number of objects written
  2826.     or 0 or -1 depending on the error.  If the return value robjs is not
  2827.     equal to nobjs then a write error occurred. Having two size
  2828.     arguments, an object size and number of objects, simplifies the
  2829.     reading of structure arrays off disk.
  2830.  
  2831.     || NOTE: To use fwrite to read an arbitrary number of bytes one
  2832.     || normally uses the form "r = fwrite(buf, 1, n, fp);", that is, n
  2833.     || objects of size 1.
  2834.  
  2835.     INPUTS
  2836.     void *buf;        buffer to copy data from
  2837.  
  2838.     size_t objsize;     size of one object
  2839.  
  2840.     size_t nobjs;        number of objects to write
  2841.  
  2842.     FILE *fp;        file pointer to read objects from
  2843.  
  2844.     RESULTS
  2845.     size_t robjs;        number of objects actually written (0 or EOF on
  2846.                 error)
  2847.  
  2848.     SEE ALSO
  2849.     fread, fopen, fclose, fseek, ftell, rewind
  2850.  
  2851. dice/getchar                                                    dice/getchar
  2852.  
  2853.     FUNCTION
  2854.     get character from stdin (ANSI)
  2855.  
  2856.     SYNTAX
  2857.     #include <stdio.h>
  2858.     int c = getchar(); /* MACRO */
  2859.  
  2860.     DESCRIPTION
  2861.     getchar returns the next available character on stdin or EOF if no
  2862.     more characters are available. getchar is equivalent to getc(stdin).
  2863.  
  2864.     || NOTE: Refer to the file_pointer manual page for general
  2865.     || information.
  2866.  
  2867.     INPUTS
  2868.     none
  2869.  
  2870.     RESULTS
  2871.     int c;            character 0 to 255, or EOF (-1) returned from
  2872.                 stdin
  2873.  
  2874.     SEE ALSO
  2875.     putc, putchar, fputc, fread, fwrite, getc
  2876.  
  2877.     EXAMPLE
  2878.     /*
  2879.      *  copy stdin to stdout using getchar/putchar. Normally
  2880.      *  one uses fread/fwrite, but I'll save that for the
  2881.      *  fread manual page.
  2882.      *  Note that I output the initial message to stderr
  2883.      *  so it does not get stuck into stdout in case the
  2884.      *  user has redirected stdout.
  2885.      *
  2886.      *  See getc manual page for equivalent example using
  2887.      *  getc/putc
  2888.      */
  2889.     #include <stdio.h>
  2890.     main()
  2891.     {
  2892.        int c;
  2893.        fputs("Type a couple of lines, then ^\\ (EOF)\n",
  2894.           stderr);
  2895.        while ((c = getchar()) != EOF)
  2896.        {
  2897.            putchar(c);
  2898.        }
  2899.        return(0);
  2900.     }
  2901.  
  2902. dice/getcwd                                                      dice/getcwd
  2903.  
  2904.     FUNCTION
  2905.     get current working directory (UNIX)
  2906.  
  2907.     SYNTAX
  2908.     #include <stdio.h>
  2909.     char *path = getcwd(buf, max);
  2910.     non-standard call
  2911.  
  2912.     DESCRIPTION
  2913.     getcwd gets the current working directory and puts it into the
  2914.     specified buffer buf. If buf is NULL it will be malloc'd
  2915.     automatically. The parameter buf is returned (or the malloc'd buffer
  2916.     if you passed NULL for buf). The parameter max specifies the maximum
  2917.     length of the path including the terminating NULL character. NULL is
  2918.     returned if any error occurs (such as malloc failing)
  2919.  
  2920.     INPUTS
  2921.     char *buf;        buffer to place current directory path into or
  2922.                 NULL if you want getcwd to allocate one
  2923.  
  2924.     int max;        maximum size of buffer
  2925.  
  2926.     RESULTS
  2927.     char *path;        returns allocated buffer if you passed NULL for
  2928.                 buf, else returns the first argument.  Returns
  2929.                 NULL on error.
  2930.  
  2931.     SEE ALSO
  2932.     chdir
  2933.  
  2934.     EXAMPLE
  2935.     #include <stdio.h>
  2936.     char buf[512];
  2937.     main(int ac, char**av)
  2938.     {
  2939.        getcwd(buf, sizeof(buf));
  2940.        printf("Current directory is: %s\n", buf);
  2941.        return(0);
  2942.     }
  2943.  
  2944. dice/GetDiceRexxPortSlot                            dice/GetDiceRexxPortSlot
  2945.  
  2946.     FUNCTION
  2947.     Determine an Application ARexx slot (DICE)
  2948.  
  2949.     SYNTAX
  2950.     #include <lib/rexx.h>
  2951.     slot = GetDiceRexxPortSlot(port, &nameptr);
  2952.     int slot;
  2953.     MsgPort *port;
  2954.     char *nameptr;
  2955.  
  2956.     DESCRIPTION
  2957.     GetDiceRexxPortSlot returns the ln_Name field of the specified port
  2958.     (i.e. the fully qualified port name) and extracts and returns the
  2959.     slot number.  -1 is returned if the port name does not terminate with
  2960.     ".xx" where xx is a number.  If a char ** pointer is passed as
  2961.     nameptr it will be initialized to point to the ln_Name field of the
  2962.     port.
  2963.  
  2964.     This call is normally used with port = NULL to obtain information
  2965.     about DICE's internally setup Rexx port.
  2966.  
  2967.     INPUTS
  2968.     struct MsgPort *port;
  2969.                 message port structure to extract ln_Name and
  2970.                 slot field from. You can pass NULL to extract the
  2971.                 full name and slot number selected by DICE when
  2972.                 automatic startup is used (i.e. your declaration
  2973.                 of RexxHostName is assigned a non-NULL pointer).
  2974.  
  2975.     char **nameptr;     The port name or NULL.  If not NULL the pointer
  2976.                 will be assigned the ln_Name field of the port.
  2977.                 Normally used when port is passed as NULL to
  2978.                 obtain the fully qualified rexx port name DICE
  2979.                 has constructed for you in an automatic startup.
  2980.  
  2981.     RESULTS
  2982.     int slot;        the slot number extracted from the port name or
  2983.                 -1 if the port name is not in the proper format.
  2984.  
  2985.     SEE ALSO
  2986.     CreateGlobalDiceRexxPort, CreateDiceRexxPort, DeleteDiceRexxPort
  2987.  
  2988.     EXAMPLE
  2989.     See DICE ARexx Support in chapter
  2990.  
  2991. dice/getenv                                                      dice/getenv
  2992.  
  2993.     FUNCTION
  2994.     get environment variable (ANSI)
  2995.  
  2996.     SYNTAX
  2997.     #include <stdlib.h>
  2998.     char *var = getenv(const char *name);
  2999.  
  3000.     DESCRIPTION
  3001.     getenv searches for and returns the ENV: environment variable
  3002.     requested.  getenv will cache variables so that requesting the same
  3003.     variable repeatedly does not allocate a new memory buffer.  getenv
  3004.     allocates a buffer for each variable returned, so you do not have to
  3005.     copy the return value from getenv.  This memory is free'd on program
  3006.     exit.  Do not attempt to free a getenv'd variable!!
  3007.  
  3008.     INPUTS
  3009.     char *name;        Name of environment variable, on the Amiga this
  3010.                 is not case sensitive. On UNIX systems it is.
  3011.  
  3012.     RESULTS
  3013.     char *var;        Contents of environment variable or NULL if the
  3014.                 variable could not be found.
  3015.  
  3016.     EXAMPLE
  3017.     #include <stdio.h>
  3018.     #include <stdlib.h>
  3019.     main(int ac, char**av)
  3020.     {
  3021.        char *dccopts = getenv("DCCOPTS");
  3022.        if (dccopts)
  3023.           printf("DCCOPTS = %s\n", dccopts);
  3024.        else
  3025.           printf("You do not have a DCCOPTS environment\
  3026.               variable!\n");
  3027.        return(0);
  3028.     }
  3029.  
  3030. dice/getfnl                                                      dice/getfnl
  3031.  
  3032.     FUNCTION
  3033.     get file name list: scan directory, return list of files that match
  3034.     the optional wildcard (DICE)
  3035.  
  3036.     SYNTAX
  3037.     #include <stdlib.h>
  3038.     int n = getfnl(pat, buf, bufsize, attr);
  3039.  
  3040.     const char *pat;
  3041.     char *buf;
  3042.     int bufsize;
  3043.     int attr;
  3044.  
  3045.     DESCRIPTION
  3046.     getfnl scans the specified anchored AmigaDOS pattern and fills the
  3047.     specified buffer (up to bufsize bytes) with file names separated by a
  3048.     NULL character (\0), ending the list with a double NULL (\0\0).
  3049.     getfnl returns the number of files/dirs in the buffer or -1 if there
  3050.     is not enough room  The pattern pat is an AmigaDOS pattern such as
  3051.     "df0:#?.c". The parameter buf is a buffer of bufsize bytes.  The
  3052.     parameter attr determines what kinds of files are valid:    0 for
  3053.     normal files only, 1 for files and directories
  3054.  
  3055.     || NOTE: getfnl exists for compatibility only;    expand_args is a much
  3056.     || better function function to use if you want a list of files &
  3057.     || dirs.
  3058.  
  3059.     INPUTS
  3060.     const char *pat;    pattern to scan for (anchored)
  3061.  
  3062.     char *buf;        buffer to put results in
  3063.  
  3064.     int bufsize;        size of buffer
  3065.  
  3066.     int attr;        attribes (0 or 1)
  3067.  
  3068.     RESULTS
  3069.     int n;            number of file names in buffer or -1 on error
  3070.  
  3071.     SEE ALSO
  3072.     strbpl, expand_args
  3073.  
  3074.     EXAMPLE
  3075.     #include <stdio.h>
  3076.     char Buf[4096];
  3077.     main(int ac, char**av)
  3078.     {
  3079.        int n;
  3080.        if (ac != 2)
  3081.        {
  3082.           puts("Expected an anchored wildcard such as '#?'");
  3083.           exit(1);
  3084.        }
  3085.        n = getfnl(av[1], Buf, sizeof(Buf), 1);
  3086.        {
  3087.           char *ptr = Buf;
  3088.           while (*ptr)
  3089.           {
  3090.           /*  look for \0\0   */
  3091.           puts(ptr);
  3092.           ptr += strlen(ptr) + 1;
  3093.           /*  skip first \0   */
  3094.           }
  3095.        }
  3096.        return(0);
  3097.     }
  3098.  
  3099. dice/GetHead,GetTail,GetSucc,GetPred    dice/GetHead,GetTail,GetSucc,GetPred
  3100.  
  3101.     FUNCTION
  3102.     Manipulate EXEC style lists (DICE)
  3103.  
  3104.     SYNTAX
  3105.     #include <lists.h>
  3106.     struct Node *node = GetHead(list);
  3107.     struct Node *node = GetTail(list);
  3108.     struct Node *node = GetSucc(oldNode);
  3109.     struct Node *node = GetPred(oldNode);
  3110.     const struct Node *oldNode;
  3111.     const struct List *list;
  3112.  
  3113.     DESCRIPTION
  3114.     These functions allow scanning of EXEC style lists (which are also
  3115.     useful for many programs having nothing to do with EXEC). GetHead
  3116.     returns the first node in a list or NULL if the list is empty;
  3117.     GetTail returns the last node in a list or NULL if the list is empty;
  3118.     GetSucc returns the next node in a list (given some intermediate
  3119.     node) or NULL when we reach the end of the list GetPred returns the
  3120.     previous node in a list before some intermediate node or NULL when we
  3121.     reach the beginning of the list
  3122.  
  3123.     || NOTE: These are DICE functions and do not exist outside of DICE,
  3124.     || though they could be easily written.
  3125.  
  3126.     INPUTS
  3127.     struct List *list;
  3128.                 list to get head or tail node from
  3129.  
  3130.     struct Node *oldNode;
  3131.                 node from which to get relative successor or
  3132.                 predecessor from
  3133.  
  3134.     RESULTS
  3135.     struct Node *node;
  3136.                 returned node or NULL
  3137.  
  3138.     EXAMPLE
  3139.     /*
  3140.      *  A simple symbol create/delete/list program.
  3141.      *  (Note: for a real symbol table you'd want
  3142.      *  to use hash tables)
  3143.      */
  3144.     #include <lists.h>  /* non-standard header file */
  3145.     #include <stdio.h>
  3146.     #include <stdlib.h>
  3147.     #include <string.h>
  3148.     typedef struct List List;
  3149.     typedef struct Node Node;
  3150.     List SymList;
  3151.     void AddSymbol(char *);
  3152.     void DelSymbol(char *);
  3153.     Node *FindSymbol(char *);
  3154.     main()
  3155.     {
  3156.        char buf[256];
  3157.        char symBuf[256];
  3158.        short notDone = 1;
  3159.        NewList(&SymList);
  3160.        puts("(return for help)");
  3161.        while (notDone)
  3162.        {
  3163.           printf("Enter Command: ");
  3164.           fflush(stdout);
  3165.           if ( fgets(buf, sizeof(buf), stdin) == NULL)
  3166.          break;
  3167.           switch(buf[0])
  3168.           {
  3169.          case 'a': if (sscanf(buf + 1,"%s",symBuf)== 1)
  3170.             AddSymbol(symBuf);
  3171.             break;
  3172.          case 'd': if (sscanf(buf + 1,"%s",symBuf)== 1)
  3173.             DelSymbol(symBuf);
  3174.             break;
  3175.          case 'l': { Node *node;
  3176.             for (node = GetHead(&SymList); node;
  3177.             node = GetSucc(node))
  3178.             puts(node->ln_Name);
  3179.           }
  3180.           break;
  3181.           case 'q': notDone = 0;
  3182.             break;
  3183.          default: puts("<return>      -help   ");
  3184.             puts("a name-add symbol");
  3185.             puts("d name-delete symbol");
  3186.             puts("l     -list symbols");
  3187.             puts("q     -quit");
  3188.             break;
  3189.        }
  3190.     }
  3191.     puts("bye!");
  3192.     return(0);
  3193.     }
  3194.  
  3195.     void AddSymbol(name)
  3196.     char *name;
  3197.     {
  3198.        Node *node;
  3199.        if (FindSymbol(name))
  3200.        {
  3201.           puts("already exists!");
  3202.           exit(1);
  3203.        }
  3204.        if (node = malloc(sizeof(Node)))
  3205.        {
  3206.           AddTail(&SymList, node);
  3207.           node->ln_Name = strdup(name);
  3208.           /* bad code, not checking */
  3209.           /* for error result!    */
  3210.        }
  3211.     }
  3212.  
  3213.     void DelSymbol(name)
  3214.     char *name;
  3215.     {
  3216.        Node *node;
  3217.        if (node = FindSymbol(name))
  3218.        {
  3219.           Remove(node);   /*  take out of list    */
  3220.           free(node->ln_Name);    /*  free name   */
  3221.           free(node);     /*  free node last      */
  3222.           puts("ok");
  3223.           }
  3224.        else
  3225.        {
  3226.           puts("Couldn't find it!");
  3227.        } }
  3228.  
  3229.     Node * FindSymbol(name)
  3230.     char *name;
  3231.     {
  3232.        Node *node;
  3233.        for (node = GetHead(&SymList); node;
  3234.          node = GetSucc(node))
  3235.        {
  3236.         if (strcmp(node->ln_Name, name) == 0)
  3237.         return(node);
  3238.        }
  3239.        return(NULL);
  3240.     }
  3241.  
  3242. dice/gets                                                          dice/gets
  3243.  
  3244.     FUNCTION
  3245.     get a line from stdin (ANSI)
  3246.  
  3247.     SYNTAX
  3248.     #include <stdio.h>
  3249.     char *ptr = gets(buf);
  3250.     char *buf;
  3251.  
  3252.     DESCRIPTION
  3253.     gets takes a line from stdin and places it into your buffer.  A null
  3254.     (\0) is placed in the buffer instead of the newline (\n).  While the
  3255.     function can be convenient, if your buffer is not large enough, you
  3256.     loose. See fgets for a more reasonable function.
  3257.  
  3258.  gets, puts
  3259.         These functions strip newline on input, add newline on output.
  3260.         gets works on stdin, puts on stdout.
  3261.  
  3262.  fgets, fputs
  3263.         These functions leave newlines alone on input, don't add to the
  3264.         output. Any file pointer, including stdin and stdout may be
  3265.         specified.
  3266.  
  3267.         || NOTE: Refer to the file_pointer manual page for general
  3268.         || information.
  3269.  
  3270.     INPUTS
  3271.     char *buf;        buffer, must be able to maximum possible line
  3272.  
  3273.     RESULTS
  3274.     char *ptr;        buf if all is well, or NULL if error or EOF
  3275.  
  3276.     SEE ALSO
  3277.     puts, fputs, fgets, fread, getc, fgetc
  3278.  
  3279.     EXAMPLE
  3280.     #include <stdio.h>
  3281.     main()
  3282.     {
  3283.        char buf[128];
  3284.        printf("Enter a line - ");
  3285.        fflush(stdout);
  3286.        if (gets(buf) == NULL) // Enter a long line to crash
  3287.           exit(1);
  3288.        printf("Your line was: %s\n", buf);
  3289.        return(0);
  3290.     }
  3291.  
  3292. dice/isalnum,isalpha,iscntrl,isdigit,isgraph,islower,isprint,ispunct,isspace,isupper,isxdigit
  3293.  
  3294.     FUNCTION
  3295.     Test a character for assorted attributes (ANSI)
  3296.  
  3297.     SYNTAX
  3298.     #include <ctype.h>
  3299.     int r = isxxxxx(c);
  3300.     int c;
  3301.  
  3302.     || NOTE: These are MACROS if you #include <ctype.h>, function calls
  3303.     || if you do not.
  3304.  
  3305.     DESCRIPTION
  3306.     These function return non-zero (true) if the test is true, and zero
  3307.     (false) if not.
  3308.  
  3309.     || NOTE: When a non-zero value is returned, this value might be
  3310.     || anything other than zero.  It is not necessarily a 1.  It is
  3311.     || guaranteed to fit in a short, however, and still remain
  3312.     ||  non-zero.
  3313.     ||
  3314.     || Characters in the -1 to 255 range are valid inputs. Characters
  3315.     || less than -1 or larger than 255 are illegal and the results will
  3316.     || be random.  If you are passing a CHAR, you must cast it to an
  3317.     || UNSIGNED CHAR first. EOF is a valid input, and always returns
  3318.     || false
  3319.  
  3320.    isalpha  Returns non-zero if the character is a letter in the alphabet
  3321.         (a-z, A-Z).
  3322.  
  3323.    isalnum  Returns non-zero if the character is alphanumeric (a-z, A-Z,
  3324.         0-9).
  3325.  
  3326.    iscntrl  Returns non-zero if the character is a control character (decimal
  3327.         0 to 31).
  3328.  
  3329.    isdigit  Returns non-zero if the character is a digit ('0' through '9').
  3330.  
  3331.    isgraph  Returns non-zero if the character is printable and not a space.
  3332.         isgraph is the same as isprint, but with the space character
  3333.         excluded from the printable set.
  3334.  
  3335.    islower  Returns non-zero if the character is a lower case letter 'a' -
  3336.         'z'.
  3337.  
  3338.     isprint
  3339.  
  3340.     Returns non-zero if the character is printable. isprint is the same
  3341.     as isgraph, but with the space character included in the printable
  3342.     set.
  3343.  
  3344.    ispunct  Returns non-zero if the character is any sort of punctuation,
  3345.         including punctuation in the extended ASCII range.    Basically, if
  3346.         it is not a control character, alpha or a digit, it is
  3347.         punctuation.
  3348.  
  3349.    isspace  Returns non-zero if the character is any sort of white space.
  3350.         Included are space, shifted space, line feed (lf), form feed
  3351.         (ff), carriage return (cr), tab, and vertical tab.
  3352.  
  3353.    isupper  Returns non-zero if the character is an upper case letter 'A'
  3354.         -'Z'.
  3355.  
  3356.   isxdigit  Returns non-zero if the character is a valid hexadecimal digit
  3357.         '0' - '9', 'a' - 'f', or 'A' - 'F'.
  3358.  
  3359.         These macros use a lookup table.  One table handles the eight
  3360.         most common functions.  A second table handles ispunct, isxdigit
  3361.         and isprint.  It saves space if you reference only one table.
  3362.         There is space in the second table if you wish to add your own
  3363.         tests (you'll have to recompile the library source code).
  3364.  
  3365.     INPUTS
  3366.     int c;            character that we are checking
  3367.  
  3368.     RESULTS
  3369.     int r;            0 if the check failed, non-zero if the check is
  3370.                 true
  3371.  
  3372.     SEE ALSO
  3373.     tolower, toupper
  3374.  
  3375.     #include <stdio.h>
  3376.     #include <ctype.h>
  3377.     main()
  3378.     {
  3379.     int c;
  3380.  
  3381.         for( c=0; c<256; c++) {
  3382.         if( (c & 31) == 0 )    /* 32 per line */
  3383.             printf("\n%02x: ", c);
  3384.         if( isprint( c ) )
  3385.             printf("%c", c );   /* character */
  3386.         else
  3387.             printf("%c", 127 ); /* placeholder */
  3388.         }
  3389.         printf("\n");
  3390.         for( c=0; c<256; c++) {
  3391.         if( (c & 31) == 0 )    /* 32 per line */
  3392.             printf("\n%02x: ", c);
  3393.         if( ispunct( c ) )
  3394.             printf("x");        /* true */
  3395.         else
  3396.             printf("-");        /* false */
  3397.         }
  3398.         printf("\n");
  3399.         return( 0 );
  3400.     }
  3401.  
  3402. dice/isatty                                                      dice/isatty
  3403.  
  3404.     FUNCTION
  3405.     Test if a a file descriptor is a TTY (UNIX)
  3406.  
  3407.     SYNTAX
  3408.     #include <ctype.h>
  3409.     int r = isatty(fd); int fd;
  3410.  
  3411.     DESCRIPTION
  3412.     isatty returns TRUE (1) if the file descriptor is associated with a
  3413.     console, FALSE (0) if not, or -1 if an error condition occurs (such
  3414.     as illegal file descriptor).
  3415.  
  3416.     || NOTE: The standard input (0), standard output (1), and standard
  3417.     || error (2) can all return different values for isatty depending on
  3418.     || how the program is redirected.  A program whose standard in and
  3419.     || standard out is redirected may still have a standard error that is
  3420.     || connected to the console. Refer to the file_descriptor manual page
  3421.     || for general information.  Unlike file pointers and file handles,
  3422.     || the file descriptor is checked for validity and will simply return
  3423.     || an error if illegal.
  3424.  
  3425.     INPUTS
  3426.     int fd;         file descriptor
  3427.  
  3428.     RESULTS
  3429.     int r;            result, 1 if a tty, 0 if not, or -1 if error
  3430.  
  3431.     SEE ALSO
  3432.     close, creat, fcntl, fdtofh, getfh, ioctl, lseek, mkdir, open, read,
  3433.     rmdir, unlink, write
  3434.  
  3435. dice/ioctl                                                        dice/ioctl
  3436.  
  3437.     FUNCTION
  3438.     IO control on file descriptor (UNIX)
  3439.  
  3440.     SYNTAX
  3441.     #include <fcntl.h>
  3442.     int r = ioctl(fd, req, parg1, parg2);
  3443.     int fd;
  3444.     int req;
  3445.     int *parg1;
  3446.     int *parg2;
  3447.  
  3448.     DESCRIPTION
  3449.     ioctl executes an IO control on the file descriptor.  Currently no IO
  3450.     controls are implemented.
  3451.  
  3452.     INPUTS
  3453.     int fd;         file descriptor
  3454.  
  3455.     int req;        request from <ioctl.h>
  3456.  
  3457.     int *parg1;        address of argument #1
  3458.  
  3459.     int *parg2;        address of argument #2
  3460.  
  3461.     RESULTS
  3462.     int r;            result, error if < 0.
  3463.  
  3464.     SEE ALSO
  3465.     close, creat, fcntl, fdtofh, getfh, isatty, lseek, mkdir, open, read,
  3466.     rmdir, unlink, write
  3467.  
  3468. dice/localtime                                                dice/localtime
  3469.  
  3470.     FUNCTION
  3471.     convert time into broken down time (ANSI)
  3472.  
  3473.     SYNTAX
  3474.     #include <time.h>
  3475.     struct tm *tp = localtime(&t);
  3476.     time_t t;
  3477.  
  3478.     DESCRIPTION
  3479.     localtime takes the address of a time_t variable and breaks up the
  3480.     time into component parts, storing them in a static tm structure.
  3481.     The address of this structure is returned.  Since the broken up time
  3482.     is stored into a static structure, the structure will get overwritten
  3483.     on the next call to localtime. The fields of the tm structure are:
  3484.  
  3485.     struct tm {
  3486.            int tm_sec;     /*  0-59    */
  3487.            int tm_min;     /*  0-59    */
  3488.            int tm_hour;    /*  0-23    */
  3489.            int tm_mday;    /*  1-31    */
  3490.            int tm_mon;     /*  0-11    */
  3491.            int tm_year;    /*  n+1900  */
  3492.            int tm_wday;    /*  (sun)0-6*/
  3493.            int tm_yday;    /*  0-366   */
  3494.            int tm_isdst;   /*  is daylight savings? */
  3495.     /* (DICE does not implement the is daylight flag) */
  3496.     };
  3497.  
  3498.     INPUTS
  3499.     time_t *t;        pointer to a time_t
  3500.  
  3501.     RESULTS
  3502.     struct tm *tp;        pointer to a struct tm structure filled out
  3503.                 according to the passed time.
  3504.  
  3505.     SEE ALSO
  3506.     time, asctime, strftime, ctime, clock
  3507.  
  3508.     EXAMPLE
  3509.     /*
  3510.      *  Note that it is much easier to format time/date
  3511.      *  strings with strftime().
  3512.      */
  3513.     #include <stdio.h>
  3514.     #include <time.h>
  3515.     main()
  3516.     {
  3517.        time_t t = time(NULL);
  3518.        struct tm *tp = localtime(&t);
  3519.        printf("The time is %02d:%02d:%02d\n", tp->tm_hour,
  3520.             tp->tm_min, tp->tm_sec);
  3521.        return(0);
  3522.     }
  3523.  
  3524. dice/LockAddr,LockAddrB,TryLockAddr,TryLockAddrB,UnlockAddr,UnlockAddrB
  3525.  
  3526.     FUNCTION
  3527.     LockAddr: Gain Exclusive, Fast semaphore (bit 0)
  3528.     LockAddrB: Gain Exclusive, Fast semaphore (bit n 0-7)
  3529.     TryLockAddr: Non- Blocking version of LockAddr
  3530.     TryLockAddrB: Non-Blocking version of LockAddrB
  3531.     UnlockAddr: Release exclusive semaphore, bit 0
  3532.     UnlockAddrB: Release exclusive semaphore, bit n 0-7 (DICE)
  3533.  
  3534.     SYNTAX
  3535.     void LockAddr(lck);
  3536.     void LockAddrB(bitno, lck);
  3537.     int r = TryLockAddr(lck);
  3538.     int r = TryLockAddrB(bitno, lck);
  3539.     void UnlockAddr(lck);
  3540.     void UnlockAddrB(bitno, lck);
  3541.     long lck[2];
  3542.  
  3543.     DESCRIPTION
  3544.     These are custom DICE functions used for inter-task locking
  3545.     semaphores in programs that need such functions.  These routines are
  3546.     somewhat faster than standard Amiga semaphore routines and take less
  3547.     memory, though at the cost of DICE specific. To use an inter-task
  3548.     lock one first initializes an lck array to 0's. The entry long
  3549.     lck[2]; is an array of two longwords that the lock routines will use
  3550.     to do their stuff.  This array should be zero'd only once at program
  3551.     initialization time (the master task before any other tasks are
  3552.     created that use it). Each lck array may hold up to 8 locks, hence
  3553.     the LockAddrB calls. The non-B calls use lock #0 for simplicity.  For
  3554.      simplicity we will only discuss non-B calls.
  3555.     To gain a lock you may call LockAddr with the address of the lck
  3556.     array (which, being an array, does not need the & in the call). This
  3557.     routine will not return until the lock can be obtained. You may also
  3558.     use TryLockAddr to attempt to gain a lock. The return value is:    -1
  3559.     if the command is unable to obtain the lock (that is, it is in use),
  3560.     1 if the lock has been obtained.  To release an obtained lock you
  3561.     call UnlockAddr(lck).
  3562.  
  3563.     ## WARNING: DO NOT RELEASE A LOCK YOU DO NOT HAVE!
  3564.  
  3565.     INPUTS
  3566.     long *lck;        a pointer to two longwords, initially zero'd
  3567.  
  3568.     -int bitno;        lock # ... up to 8 independent locks exist for
  3569.                 each lck structure
  3570.  
  3571.     RESULTS
  3572.     int r;            (TryLock only), -1 on failure, 1 on success.
  3573.  
  3574.     EXAMPLE
  3575.     /*
  3576.      *  This program obtains a lock based at a public
  3577.      *  message port and holds it for ten seconds before
  3578.      *  releasing it. The public message port is left
  3579.      *  in memory (but only exists once no matter how
  3580.      *  many programs you run).
  3581.      *
  3582.      *  To test locking, open up two or more CLI's and run
  3583.      *  the program simultaneously (or as close as your
  3584.      *  fingers can make it) two or more times.  Only one
  3585.      *  program will 'have' the lock at a time.
  3586.      *
  3587.      *  we use AllocMem() so the port survives the program
  3588.      */
  3589.  
  3590.     #include <exec/types.h>
  3591.     #include <exec/ports.h>
  3592.     #include <exec/memory.h>
  3593.     #include <stdio.h>
  3594.     #include <stdlib.h>
  3595.     #include <assert.h>
  3596.  
  3597.     typedef struct
  3598.     {
  3599.        struct MsgPort Port;
  3600.        long   Lock[2];
  3601.     }
  3602.     MyPort;
  3603.  
  3604.     extern void *FindPort();
  3605.     extern void *CreatePort();
  3606.     extern void *AllocMem();
  3607.     MyPort *Port;
  3608.     short HaveLock;
  3609.  
  3610.     int brk()
  3611.     {
  3612.        if (HaveLock)
  3613.        UnlockAddr(Port->Lock);
  3614.        return(1);       /*  abort   */
  3615.     }
  3616.  
  3617.     main()
  3618.     {
  3619.        char *portName = "Lock-Test";
  3620.        onbreak(brk);
  3621.        Forbid();
  3622.        if ((Port = FindPort(portName)) == NULL)
  3623.        {
  3624.           MyPort *port;
  3625.           port = AllocMem(sizeof(MyPort) + strlen(portName)
  3626.                   + 1, MEMF_PUBLIC | MEMF_CLEAR);
  3627.                   assert(port);
  3628.           port->Port.mp_Node.ln_Name = (char *)(port + 1);
  3629.           port->Port.mp_Node.ln_Type = NT_MSGPORT;
  3630.           strcpy(port->Port.mp_Node.ln_Name, portName);
  3631.           AddPort(port);
  3632.           Port = port;
  3633.        }
  3634.        Permit();
  3635.        puts("getting lock");
  3636.        LockAddr(Port->Lock);
  3637.        HaveLock = 1;
  3638.        puts("Got the lock!, sleeping for 10 seconds");
  3639.        sleep(10);
  3640.        UnlockAddr(Port->Lock);
  3641.        HaveLock = 0;
  3642.        puts("released lock");
  3643.        return(0);
  3644.     }
  3645.  
  3646. dice/lseek                                                        dice/lseek
  3647.  
  3648.     FUNCTION
  3649.     seek within a file descriptor (UNIX)
  3650.  
  3651.     SYNTAX
  3652.     #include <fcntl.h>
  3653.     long newpos = lseek(fd, offset, how)
  3654.     int fd;
  3655.     long offset;
  3656.     int how;
  3657.  
  3658.     DESCRIPTION
  3659.     lseek changes where the file descriptor points to within the open
  3660.     file.  You may specify an offset relative to the  beginning of the
  3661.     file, the current position in the file, or the end of the file:
  3662.  
  3663.        Val : Purpose
  3664.        ====+=========================================================
  3665.        0   : absolute offset (relative to the beginning of the file)
  3666.        ----+---------------------------------------------------------
  3667.        1   : offset relative to the current position in the file
  3668.        ----+---------------------------------------------------------
  3669.        2   : offset relative to the end of the file
  3670.        ----+---------------------------------------------------------
  3671.  
  3672.     Negative offsets may be specified when relative modes are used. The
  3673.     function lseek returns the new position in the file relative to the
  3674.     beginning of the file (i.e. an absolute offset).
  3675.  
  3676.     || NOTE: offsets are relative.    So, for example, if you want to seek
  3677.     || to the fourth character from the end of the file you would
  3678.     || lseek(fd, -4L, 2);.    Refer to the file_descriptor manual page for
  3679.     || general information.  Unlike file pointers and file handles, the
  3680.     || file descriptor is checked for validity and will simply return an
  3681.     || error if illegal.
  3682.  
  3683.     INPUTS
  3684.     int fd;         file descriptor
  3685.  
  3686.     long offset;        offset relative to how
  3687.  
  3688.     int how;        0 = rel beginning, 1 = rel middle, 2 = rel end
  3689.  
  3690.     RESULTS
  3691.     int newpos;        new position in file (absolute) or < 0 if error
  3692.  
  3693.     SEE ALSO
  3694.     close, creat, fcntl, fdtofh, getfh, ioctl, isatty, mkdir, open, read,
  3695.     rmdir, unlink, write
  3696.  
  3697.     EXAMPLE
  3698.     See open for an example.
  3699.  
  3700. dice/main                                                          dice/main
  3701.  
  3702.     FUNCTION
  3703.     main program entry (ANSI)
  3704.  
  3705.     SYNTAX
  3706.     #include <anything.h>
  3707.     int main(int argc, char **argv)
  3708.     {
  3709.        /* your pride and joy goes here */
  3710.     }
  3711.  
  3712.     DESCRIPTION
  3713.     The main routine is the entry point called after normal
  3714.     initialization of c.lib and the program environment is done by the
  3715.     startup module (c.o) and _main routine (in c.lib).  Under ANSI C main
  3716.     is expected to return an integer exit code. You can no longer simply
  3717.     fall through without returning any value.  Returning an exit code
  3718.     from your main routine is exactly the same as exiting with it.
  3719.  
  3720.     || NOTE: Any program run from the WORKBENCH uses a different access
  3721.     || point. Specifically, a program run from the WORKBENCH will run
  3722.     || wbmain instead of main.  Please refer to the manual    page for
  3723.     || wbmain for WORKBENCH operation.
  3724.  
  3725.     If you do not supply a wbmain a dummy wbmain will be supplied by the
  3726.     library which simply exits out of the program.
  3727.  
  3728.     INPUTS
  3729.     int argc;        number of arguments
  3730.  
  3731.     char *argv;        array pointer to arguments
  3732.  
  3733.     SEE ALSO
  3734.     wbmain, _main, exit, _exit
  3735.  
  3736.     EXAMPLE
  3737.     /* Print back out all given arguments */
  3738.     #include <stdio.h>
  3739.  
  3740.     int main(int ac, char**av)
  3741.     {
  3742.        int i;
  3743.        for (i = 0; i < ac; ++i) {
  3744.           printf("Arg #%d = %s\n", i, av[i]);
  3745.        }
  3746.        return(0);
  3747.     }
  3748.  
  3749. dice/_main                                                        dice/_main
  3750.  
  3751.     FUNCTION
  3752.     main program entry, bypass standard c.lib initialization (DICE)
  3753.  
  3754.     SYNTAX
  3755.     #include <the_world.h>
  3756.     void _main(int arglen, char *argptr)
  3757.     {
  3758.         /* your very special code goes here */
  3759.     }
  3760.  
  3761.     DESCRIPTION
  3762.     The _main entry point is called by the startup module (c.o).
  3763.     Normally _main is part of c.lib and does stdio and other
  3764.     initialization before calling the user main routine. _main is
  3765.     responsible for opening the stderr channel as well.  However, if you
  3766.     specify your own _main you will override the c.lib version.  Normally
  3767.     you either fall through or _exit from _main. A programmable can use
  3768.     the _main entry point when the executable uses nothing but system
  3769.     library routines.  That is, you make no calls to stdio functions such
  3770.     as puts, printf, etc., to low level IO routines such as open, close,
  3771.     read, etc., or malloc or any routine that uses malloc. Self contained
  3772.     routines such as strcpy may still be called, and, of course, you may
  3773.     open any libraries you wish and make library calls.  Since the
  3774.     auto-library opening and closing is done by the startup module (c.o),
  3775.     "dos.library" will still be opened for you automatically if you make
  3776.     any DOS calls.
  3777.  
  3778.     Using the _main entry point usually results in a substantially
  3779.     smaller executable because stdio and other library routines
  3780.     referenced by the c.lib. _main and exit are never referenced and thus
  3781.     never become part of the executable.  It is NOT SUGGESTED that
  3782.     beginning C programmers use the _main entry point.
  3783.  
  3784.     || NOTE: _main is called by the startup module whether the program
  3785.     || was run from the CLI or the WORKBENCH.  You must detect which
  3786.     || yourself and also deal with the WORKBENCH message yourself.
  3787.  
  3788.     int argc;        number of arguments
  3789.  
  3790.     char *argv;        array pointer to arguments
  3791.  
  3792.     SEE ALSO
  3793.     _exit, main, exit
  3794.  
  3795.     EXAMPLE
  3796.     /*
  3797.     **  This program comes in at under 600 bytes.
  3798.     */
  3799.     _main()
  3800.     {
  3801.        Write(Output(), "UG!\n", 4);
  3802.        _exit(0);
  3803.     }
  3804.  
  3805. dice/malloc                                                      dice/malloc
  3806.  
  3807.     FUNCTION
  3808.     allocate memory, the memory is NOT automatically cleared (ANSI)
  3809.  
  3810.     SYNTAX
  3811.     #include <stdlib.h>
  3812.     void *ptr = malloc(bytes);
  3813.     size_t bytes;
  3814.  
  3815.     DESCRIPTION
  3816.     malloc allocates the specified number of bytes of memory. The
  3817.     returned pointer is longword aligned; malloc returns NULL if the
  3818.     memory could not be allocated.
  3819.  
  3820.     || NOTE: Unlike calloc, malloc does not zero the memory before it
  3821.     || returns.
  3822.  
  3823.     INPUTS
  3824.     size_t bytes;        number of bytes to allocate
  3825.  
  3826.     RESULTS
  3827.     void *ptr;        pointer to base of allocated memory.  The memory
  3828.                 is not zero'd.
  3829.  
  3830.     SEE ALSO
  3831.     calloc, strdup
  3832.  
  3833. dice/memcmp                                                      dice/memcmp
  3834.  
  3835.     FUNCTION
  3836.     compare two memory buffers (ANSI)
  3837.  
  3838.     SYNTAX
  3839.     #include <string.h>
  3840.     int r = memcmp(s1, s2, bytes)
  3841.     void *s1;
  3842.     void *s2;
  3843.     size_t bytes;
  3844.  
  3845.     DESCRIPTION
  3846.     memcmp compares two memory buffers.  A byte by byte unsigned
  3847.     comparison is done.  When a comparison fails and the byte in s1 is
  3848.     less than the byte in s2 then -1 is returned.  If the byte in s1 is
  3849.     greater than the byte in s2 then 1 is returned.  If the count is
  3850.     exhausted and all comparisons succeed then 0 is returned indicating
  3851.     the two buffers are the same.
  3852.  
  3853.     INPUTS
  3854.     void *s1;        pointer to first buffer
  3855.  
  3856.     void *s2;        pointer to second buffer
  3857.  
  3858.     size_t bytes;        size of each buffer
  3859.  
  3860.     RESULTS
  3861.     int r;            -1 if buf s1 < buf s2, 0 if buf s1 == buf s2, 1
  3862.                 if buf s1 > buf s2.
  3863.  
  3864.     SEE ALSO
  3865.     memset, setmem, bzero, clrmem, bcopy, bcmp, movmem, memcpy, memmove
  3866.  
  3867.     EXAMPLE
  3868.     #include <stdlib.h>
  3869.     #include <assert.h>
  3870.  
  3871.     main()
  3872.     {
  3873.        unsigned char buf1[5] = {9, 10, 1, 12}; /* 1,729 */
  3874.        unsigned char buf2[5] = {9, 10, 1, 12}; /* 1,729 */
  3875.        int r;
  3876.  
  3877.        r = memcmp(buf1, buf2, 4);
  3878.        assert(r == 0);
  3879.        buf1[2] = 0;
  3880.        r = memcmp(buf1, buf2, 4);
  3881.        assert(r < 0);
  3882.        buf1[2] = 42;
  3883.        r = memcmp(buf1, buf2, 4);
  3884.        assert(r > 0);
  3885.        return(0);
  3886.     }
  3887.  
  3888. dice/memcpy,memmove,movmem,bcopy            dice/memcpy,memmove,movmem,bcopy
  3889.  
  3890.     FUNCTION
  3891.     memcopy: copy memory, ANSI, overlapped memory buffers illegal
  3892.     memmov: copy memory, ANSI, works with overlapped memory buffers
  3893.     movmem: copy memory, UNIX, works with overlapped memory buffers
  3894.     bcopy: copy memory, UNIX, works with overlapped memory buffers
  3895.  
  3896.     SYNTAX
  3897.     #include <string.h>
  3898.     void *ptr = memcpy(d, s, bytes);
  3899.     void *ptr = memmove(d, s, bytes);
  3900.     void *ptr = movmem(s, d, bytes);
  3901.     void *ptr = bcopy(s, d, bytes);
  3902.     void *d;
  3903.     void *s;
  3904.     size_t bytes;
  3905.  
  3906.     DESCRIPTION
  3907.     These functions copy memory from one region to another.  Unlike
  3908.     string routines these functions do not stop the copy when a NULL is
  3909.     encountered.
  3910.  
  3911.     ## WARNING: Be careful about argument ordering.  Some calls  take the
  3912.     ## source buffer first and other calls take the destination buffer
  3913.     ## first.
  3914.  
  3915.     The ANSI committee opted for a destination, source ordering rather
  3916.     than the more logical source, destination ordering. Thus, many
  3917.     programmers will use the non-standard movmem call instead of the ANSI
  3918.     memmove call.  The ANSI function 'memcpy' as defined by the ANSI
  3919.     standard cannot handle overlapped memory areas.  The Amiga
  3920.     implementation can but you should remember this if you intend to port
  3921.     your code.
  3922.  
  3923.     || NOTE: DICE's memory move optimizes the copy using movem when
  3924.     || possible, yielding very fast memory copies for large buffers. The
  3925.     || UNIX bcopy call exists for compatibility purposes and should not
  3926.     || be used with new programs.
  3927.  
  3928.     INPUTS
  3929.     void *s;        source buffer
  3930.  
  3931.     void *d;        destination buffer
  3932.  
  3933.     RESULTS
  3934.     void *ptr;        pointer to the destination buffer(d)
  3935.  
  3936.     SEE ALSO
  3937.     memset, setmem, bzero, clrmem, cmpmem, memcmp
  3938.  
  3939.     EXAMPLE
  3940.     /*
  3941.      * This example copies the entire buffer, not just
  3942.      * the part containing the string.  Normally one just
  3943.      * uses string routines.
  3944.      */
  3945.     #include <string.h>
  3946.     #include <assert.h>
  3947.  
  3948.     main()
  3949.     {
  3950.        char s[16];
  3951.        char d[16];
  3952.        void *p;
  3953.        strcpy(s, "This is a test");
  3954.        p = movmem(s, d, sizeof(s));
  3955.        assert(p == d);
  3956.        puts(d);
  3957.        strcpy(s, "Googolplex");
  3958.        p = bcopy(s, d, sizeof(s));
  3959.        assert(p == d);
  3960.        puts(d);
  3961.        strcpy(s, "EchoBeko");
  3962.        p = memcpy(d, s, sizeof(s));
  3963.        assert(p == d);
  3964.        puts(d);
  3965.        strcpy(s, "GakFuBar");
  3966.        p = memmove(d, s, sizeof(s));
  3967.        assert(p == d);
  3968.        puts(d);
  3969.        return(0);
  3970.     }
  3971.  
  3972. dice/memset,setmem,clrmem,bzero              dice/memset,setmem,clrmem,bzero
  3973.  
  3974.     FUNCTION
  3975.     memset: ANSI, set memory buffer to a byte value
  3976.     setmem: UNIX, set memory buffer to a byte value
  3977.     clrmem: DICE,  zero out a memory buffer
  3978.     bzero: UNIX, zero out a memory buffer
  3979.  
  3980.     SYNTAX
  3981.     #include <string.h>
  3982.     void *ptr = memset(buf, c, n);
  3983.     void *ptr = setmem(buf, n, c);
  3984.     void *ptr = clrmem(buf, n);
  3985.     void *ptr = bzero(buf, n);
  3986.     void *buf;
  3987.     int c;
  3988.     size_t n;
  3989.  
  3990.     DESCRIPTION
  3991.     These functions fill a memory buffer with the specified character c.
  3992.     C is converted to an unsigned character by the fill routine before
  3993.     beginning the fill.  N bytes are filled.
  3994.  
  3995.     ## WARNING: Again, watch out for argument ordering, especially for
  3996.     ## the ANSI memset call.
  3997.  
  3998.     The ANSI committee chose bizarre call ordering so there is another
  3999.     defacto standard call called setmem. The function bzero exists for
  4000.     UNIX compatibility, and clrmem is yet another call (this time
  4001.     introduced by DICE--sorry!). memset and setmem are the most portable
  4002.     calls.
  4003.  
  4004.     INPUTS
  4005.     void *buf;        pointer to buffer to fill
  4006.  
  4007.     int  c;         character to copy into buffer
  4008.  
  4009.     (setmem, memset) size_t n;
  4010.                 # of bytes to fill
  4011.  
  4012.     RESULTS
  4013.     void *ptr;        pointer to buffer (== buf).
  4014.  
  4015.     SEE ALSO
  4016.     malloc, calloc, strdup, movmem, cmpmem
  4017.  
  4018.     EXAMPLE
  4019.     #include <string.h>
  4020.     #include <assert.h>
  4021.     #include <stdlib.h>
  4022.     main()
  4023.     {
  4024.        char buf[32];
  4025.        char *b;
  4026.        b = setmem(buf, 32, 0);
  4027.        assert(b == buf);
  4028.        b = setmem(buf, 4, 'a');
  4029.        b = memset(buf + 4, 'b' , 4);
  4030.        puts(buf);       /*  aaaabbbb    */
  4031.        return(0);
  4032.     }
  4033.  
  4034. dice/mkdir                                                        dice/mkdir
  4035.  
  4036.     FUNCTION
  4037.     create a directory (UNIX)
  4038.  
  4039.     SYNTAX
  4040.     #include <stdio.h>
  4041.     int error = mkdir(dirname)
  4042.     char *dirname;
  4043.  
  4044.     DESCRIPTION
  4045.     mkdir creates a new directory.    It returns 0 if successful, -1 if not
  4046.     (with errno set to an error code).
  4047.  
  4048.     INPUTS
  4049.     char *dirname;        filename of directory to create
  4050.  
  4051.     RESULTS
  4052.     int r;            0 if no error, < 0 if error
  4053.  
  4054.     SEE ALSO
  4055.     close, creat, fcntl, fdtofh, getfh, ioctl, isatty, lseek, mkdir,
  4056.     open, read, rmdir, unlink, write
  4057.  
  4058.     EXAMPLE
  4059.     main()
  4060.     {
  4061.        int r;
  4062.        r = mkdir("T:tmpdir");
  4063.        if (r == 0)
  4064.           puts("Created T:tmpdir successfully");
  4065.        else
  4066.           puts("Unable to create directory T:tmpdir");
  4067.     }
  4068.  
  4069. dice/onbreak                                                    dice/onbreak
  4070.  
  4071.     FUNCTION
  4072.     Set special ^C handler (AmigaDOS)
  4073.  
  4074.     SYNTAX
  4075.     typedef int (*fptr)();
  4076.     fptr oldfunc = onbreak(newfunc);
  4077.     fptr newfunc;
  4078.  
  4079.     DESCRIPTION
  4080.     onbreak sets a special function to handle ^C.  It takes a pointer to
  4081.     this function and returns a pointer to the previous onbreak function,
  4082.     if any.  When ^C is hit, the special onbreak function is called
  4083.     before any other action. If the onbreak function returns a non-zero
  4084.     value, ^C aborts the program like it usually does.  If the function
  4085.     returns 0, however, the ^C is completely ignored.
  4086.  
  4087.     INPUTS
  4088.     newfunc         pointer to function or NULL
  4089.  
  4090.     RESULTS
  4091.     fptr oldfunc;        pointer to previous onbreak function
  4092.  
  4093.     SEE ALSO
  4094.     atexit
  4095.  
  4096.     EXAMPLE
  4097.     /*
  4098.     * Note: The reentrancy check is needed because of both
  4099.     * the puts and the sleep() call.
  4100.     */
  4101.     #include <stdio.h>
  4102.     #include <stdlib.h>
  4103.  
  4104.     int brk()
  4105.     {
  4106.        static short cnt = 0; /*  check for reentrancy */
  4107.        if (cnt)         /*  if not 0 then reentered! */
  4108.           return(0);
  4109.           ++cnt;
  4110.        puts("Nah Nah, you can't break me!");
  4111.        sleep(1);
  4112.        --cnt;
  4113.        return(0);
  4114.     }
  4115.  
  4116.     int main()
  4117.     {
  4118.        short i;
  4119.        onbreak(brk);
  4120.        puts("Hit ^C while I loop from 1 to 100.");
  4121.        sleep(2);
  4122.        for (i = 1; i <= 100; ++i)
  4123.        printf("Loop, counting, count = %d\n", i);
  4124.        return(0);
  4125.     }
  4126.  
  4127. dice/open                                                          dice/open
  4128.  
  4129.     FUNCTION
  4130.     open a file (UNIX)
  4131.  
  4132.     SYNTAX
  4133.     #include <fcntl.h>
  4134.     int fd = open(name, modes);
  4135.     char *name;
  4136.     int modes;
  4137.  
  4138.     DESCRIPTION
  4139.     open opens a file of the specified name using the specified modes.
  4140.     The combinations yield different results as described below:
  4141.  
  4142.     O_RDONLY  : open file for reading only
  4143.     ----------+----------------------------------------------------------
  4144.     O_WRONLY  : open file for writing only
  4145.     ----------+----------------------------------------------------------
  4146.     O_RDWR      : open file for reading and writing
  4147.     ----------+----------------------------------------------------------
  4148.     O_NDELAY  : open file non-blocking (not implemented)
  4149.     ----------+----------------------------------------------------------
  4150.     O_APPEND  : open file for writing only and force all writes to
  4151.           : append to the file regardless of the current seek
  4152.           : position.  open is a lower-level construct than the more
  4153.           : standard fopen.
  4154.     ----------+----------------------------------------------------------
  4155.  
  4156.  
  4157.     O_CREAT creates the file if it does not exist; O_TRUNC truncates the
  4158.     file if it does exist; O_EXCL is used only with O_CREAT and if the
  4159.     file already exists the open will fail; O_BINARY opens the file for
  4160.     binary reading and writing, vs text.  This flag is ignored by DICE
  4161.     since there is no difference on the Amiga.  However, on Messy-DOS
  4162.     systems, CR-LF must be converted to an LF when reading text files.
  4163.     open returns a descriptor (>= 0) or error (< 0) on failure.
  4164.  
  4165.     || NOTE: Refer to the file_descriptor manual page for general
  4166.     || information. Unlike file pointers and file handles, the file
  4167.     || descriptor is checked for validity and will simply return an error
  4168.     || if illegal.
  4169.  
  4170.     INPUTS
  4171.     char *name;        filename to open
  4172.  
  4173.     long modes;        modes to open the file with
  4174.  
  4175.     RESULTS
  4176.     int fd;         A file descriptor if >= 0, an error if < 0.
  4177.  
  4178.     SEE ALSO
  4179.     close, creat, fcntl, fdtofh, fopen, ioctl, isatty, lseek, mkdir,
  4180.     read, rmdir, unlink, write
  4181.  
  4182.     EXAMPLE
  4183.     #include <fcntl.h>
  4184.     #include <assert.h>
  4185.     main()
  4186.     {
  4187.        int fd, r;
  4188.        fd = open("T:xx", O_WRONLY|O_CREAT|O_TRUNC);
  4189.        assert(fd >= 0);
  4190.        close(fd);
  4191.        fd = open("T:xx", O_CREAT|O_EXCL|O_TRUNC|O_WRONLY);
  4192.        assert(fd < 0);  /* will fail, file already exists */
  4193.        remove("T:xx");
  4194.        fd = open("T:xx", O_CREAT|O_TRUNC|O_WRONLY);
  4195.        assert(fd >= 0); /* will work     */
  4196.        write(fd, "FuBar-", 6);
  4197.        lseek(fd, 0L, 0);  /*  seek back to start of file */
  4198.        r = write(fd, "XxXxx", 5);
  4199.        assert(r == 5);
  4200.        close(fd);
  4201.        fd = open("T:xx", O_APPEND|O_WRONLY);
  4202.        assert(fd >= 0);
  4203.        write(fd, "FuBar\n", 6);
  4204.        close(fd);
  4205.        printf("type t:xx should return \"XxXXX-FuBar\"\n");
  4206.        return(0);
  4207.     }
  4208.  
  4209. dice/perror                                                      dice/perror
  4210.  
  4211.     FUNCTION
  4212.     output error message associated with errno and text to stderr (ANSI)
  4213.  
  4214.     SYNTAX
  4215.     #include <stdio.h>
  4216.     void perror(str);
  4217.     const char *str;
  4218.  
  4219.     DESCRIPTION
  4220.     perror outputs the specified string, a colon, and the error number
  4221.     and error message associated with the current value of errno to
  4222.     stderr, ending with a newline.    Using perror is a common way to
  4223.     generate error messages due to IO failures.
  4224.  
  4225.     INPUTS
  4226.     char *str;        string message to include in error output
  4227.  
  4228.     EXAMPLE
  4229.     #include <stdio.h>
  4230.     main()
  4231.     {
  4232.        FILE *fp = fopen("T:DoesNotExist", "r");
  4233.        if( fp ) {
  4234.           puts("T:DoesNotExist is not supposed to exist!");
  4235.           exit(1);
  4236.        }
  4237.        perror("fopen");
  4238.        return(0);
  4239.     }
  4240.  
  4241. dice/PlaceRexxCommand                                  dice/PlaceRexxCommand
  4242.  
  4243.     FUNCTION
  4244.     Send a command to ARexx (DICE)
  4245.  
  4246.     SYNTAX
  4247.     #include <lib/rexx.h>
  4248.     rc = PlaceRexxCommand(port, str, &res, &ec)
  4249.     struct MsgPort *port;
  4250.     char *str;
  4251.     char *res;
  4252.     long ec;
  4253.  
  4254.     DESCRIPTION
  4255.     PlaceRexxCommand sends an ARexx command off to ARexx. (compare to
  4256.     PlaceRexxCommandDirect which talks to an application) The command is
  4257.     normally a script file to run.    You must specify the ARexx port that
  4258.     is to act as the default host port for the command or NULL to use
  4259.     DICE's default port. The default extension for the script is always
  4260.     the RexxHostName variable.  Note that if you specify NULL for the
  4261.     port to use DICE's default, then you must have previously setup
  4262.     DICE's default port.  This occurs automatically if RexxHostName was
  4263.     declared non-NULL, or manually if you had called
  4264.     Create[Global]DiceRexxPort(NULL, "name").
  4265.  
  4266.     You supply the command in str which is passed to ARexx as  Arg0.
  4267.     Currently there is no support for additional arguments.  DICE will
  4268.     run the command synchronously and return the result code.
  4269.  
  4270.     The result string pointer will be set to either NULL or a malloc()'d
  4271.     string.  If not NULL you are responsible for free()ing the result
  4272.     string when you are through with it!!  If you wish to ignore any
  4273.     result you may pass NULL for this argument.
  4274.  
  4275.     The ec longword will be set to an internal ARexx error code... if the
  4276.     returned result code is non-zero and ec == 1 then ARexx was unable to
  4277.     find the specified ARexx command.  You may pass NULL for this
  4278.     argument if you do not care about the error code.
  4279.  
  4280.     It is possible that your program will receive ARexx commands while it
  4281.     is waiting for the command you have sent to be returned.  DICE will
  4282.     automatically call DoRexxCommand() from within the PlaceRexxCommand()
  4283.     routine when this case occurs.
  4284.  
  4285.     ARexx will set the error-code ec, which is different from the
  4286.     result-code.  ec is set to 1 if the script could not be found. ARexx
  4287.     normally returns a severity code of 5 for this case.  If the return
  4288.     code is 0 then ec will be 0.
  4289.  
  4290.     INPUTS
  4291.     struct MsgPort *port;
  4292.                 Message port for processing.  Typically you pass
  4293.                 NULL to use the default port.
  4294.  
  4295.     char *str;        String to be passed to ARexx for execution
  4296.  
  4297.     char **res;        Pointer to place to store result string from
  4298.                 ARexx.  NULL indicates no result is desired.
  4299.  
  4300.     long *ec;        Pointer to place to store error code from ARexx.
  4301.                 Set to 1 for script not found.  NULL indicates no
  4302.                 result code desired.
  4303.  
  4304.     RESULTS
  4305.     int rc;         Return code from ARexx
  4306.  
  4307.     SEE ALSO
  4308.     DoRexxCommand, PlaceRexxCommandDirect, ProcessRexxCommands
  4309.  
  4310.     EXAMPLE
  4311.     See DICE ARexx Support in chapter
  4312.  
  4313. dice/PlaceRexxCommandDirect                      dice/PlaceRexxCommandDirect
  4314.  
  4315.     FUNCTION
  4316.     Send an ARexx command to an Application (DICE)
  4317.  
  4318.     SYNTAX
  4319.     #include <lib/rexx.h>
  4320.     rc = PlaceRexxCommandDirect(port, apport,str, &res, &ec);
  4321.     struct MsgPort *port;
  4322.     char *apport;
  4323.     char *str;
  4324.     char *res;
  4325.     long ec;
  4326.  
  4327.     DESCRIPTION
  4328.     PlaceRexxCommandDirect sends an ARexx command to a specification
  4329.     application (compare to PlaceRexxCommand which talks to ARexx
  4330.     directly). The command is normally a script file to run.  You must
  4331.     specify the ARexx port that is to act as the default host port for
  4332.     the command or NULL to use DICE's default port. The default extension
  4333.     for the script is always the RexxHostName variable.  Note that if you
  4334.     specify NULL for the port to use DICE's default, then you must have
  4335.     previously setup DICE's default port.  This occurs automatically if
  4336.     RexxHostName was declared non-NULL, or manually if you had called
  4337.     Create[Global]DiceRexxPort(NULL, "name").
  4338.  
  4339.     You supply the command in str which is made Arg0.  Currently there is
  4340.     no support for additional arguments.  DICE will run the command
  4341.     synchronously and return the result code.
  4342.  
  4343.     The result string pointer will be set to either NULL or a malloc()'d
  4344.     string.    If you wish to ignore any result you may pass NULL for
  4345.     this argument.
  4346.  
  4347.     || NOTE: If you do not pass NULL, you are responsible for free()ing
  4348.     || the result string when you are through with it!
  4349.  
  4350.     The ec longword will be set to an internal ARexx error code... if the
  4351.     returned result code is non-zero and ec == 1 then ARexx was unable to
  4352.     find the specified ARexx command.  You may pass NULL for this
  4353.     argument if you do not care about the error code.
  4354.  
  4355.     It is possible that your program will receive ARexx commands while it
  4356.     is waiting for the command you have sent to be returned.  DICE will
  4357.     automatically call DoRexxCommand() from within the PlaceRexxCommand()
  4358.     routine when this case occurs.
  4359.  
  4360.     ARexx will set the error-code ec, which is different from the
  4361.     result-code.  ec is set to 1 if the script could not be found. ARexx
  4362.     normally returns a severity code of 5 for this case.  If the return
  4363.     code is 0 then ec will be 0.
  4364.  
  4365.     INPUTS
  4366.     struct MsgPort *port;
  4367.                 Message port for processing.  Typically you pass
  4368.                 NULL to use the default port.
  4369.  
  4370.     char *apport;        Name of application to send commands to.
  4371.  
  4372.     char *str;        String to be passed to ARexx for execution
  4373.  
  4374.     char **res;        Pointer to place to store result string from
  4375.                 ARexx.  NULL indicates no result is desired.
  4376.  
  4377.     long *ec;        Pointer to place to store error code from ARexx.
  4378.                 Set to 1 for script not found.  NULL indicates no
  4379.                 result code desired.
  4380.  
  4381.     RESULTS
  4382.     int rc;         Return code from ARexx
  4383.  
  4384.     SEE ALSO
  4385.     DoRexxCommand, PlaceRexxCommand, ProcessRexxCommands
  4386.  
  4387.     EXAMPLE
  4388.     See DICE ARexx Support in chapter
  4389.  
  4390. dice/printf,fprintf,sprintf,vprintf,vfprintf,vsprintf
  4391.  
  4392.     FUNCTION
  4393.     formatted output to stdout, file pointer, or buffer (ANSI)
  4394.  
  4395.     SYNTAX
  4396.     #include <stdio.h>
  4397.     #include <stdarg.h> /* for v[f/s]printf() only */
  4398.     int n = printf(fmt, ...);
  4399.     int n = fprintf(fp, fmt, ...);
  4400.     int n = sprintf(buf, fmt, ...);
  4401.     int n = vprintf(fmt, argvect);
  4402.     int n = vfprintf(fp, fmt, argvect);
  4403.     int n = vsprintf(buf, fmt, argvect);
  4404.     FILE *fp;
  4405.     char *fmt;
  4406.     char *buf;
  4407.     va_list argvect;
  4408.  
  4409.     DESCRIPTION
  4410.     These functions offer formatted printing in various flavors. printf
  4411.     and vprintf output to stdout;  fprintf and vfprintf output to a file
  4412.     pointer (fp); sprintf and vsprintf output to a character buffer.  All
  4413.     routines return the number of characters written if successful, a
  4414.     negative number if not.  Only sprintf and vsprintf are limited in
  4415.     terms of output size (it cannot exceed the buffer you give it). The
  4416.     common argument to all routines is the format specifier.  The format
  4417.     specifier is scanned to determine how to handle the arguments to the
  4418.     call (or the argument list for vfprintf/vsprintf). Characters are
  4419.     copied to the output until a % is encountered. %% indicates a literal
  4420.     '%' character.  Otherwise, the % is followed by a control sequence
  4421.     that tells printf how to output the corresponding argument.  The
  4422.     quantity is output and the scan continues until the end of the format
  4423.     string.  The % formats are interpreted as follows:
  4424.  
  4425.     %[flags][#[.#]][modifier]<conversion-specifier>
  4426.     Items in brackets are optional.  After the %, zero or more flags may
  4427.     be specified.  Then, an optional integer which represents the minimum
  4428.     field width for the object may also be specified.  If an integer is
  4429.     specified it may be followed by a period and another integer that
  4430.     represents that precision with which a number is printed. Zero or
  4431.     more modifiers may then be specified followed by a mandatory
  4432.     conversion specifier.
  4433.  
  4434.     Either or both integers (#[.#]) may be specified as a '*', as in
  4435.     "%*d", specifying that the minimum field width and/or precision is
  4436.     specified as an integer in the argument that occurs before the
  4437.     conversion object.  For example, printf("--%*d--\n", 10, 23); would
  4438.     print the number 23 right justified in a field 10 characters wide.
  4439.  
  4440.     Conversion Flags
  4441.     ----------------
  4442.  Minus (-)  Left justify text within the field.
  4443.  
  4444.    <space>  This flag places a blank in front of positive signed numbers, and
  4445.         a minus in front of negative numbers.  This option allows columns
  4446.         of positive and negative numbers to line up.
  4447.  
  4448.   Plus (+)  Cause a plus sign to be placed before a positive result.  A minus
  4449.         sign is always placed before a negative result.
  4450.  
  4451.  Pound (#)  Format output according to the type of input.  e, E, f, F always
  4452.         retains the decimal point.    g, G always retains the decimal
  4453.         point, and trailing zeros are kept.  x and X print '0x' and '0X'
  4454.         respectively before the number (except that this is not currently
  4455.         implemented by DICE).
  4456.  
  4457.      0  Pad columns with zeros instead of spaces.  Ignored if a precision
  4458.         is specified or if the '-' flag is specified.
  4459.  
  4460.     Modifiers
  4461.     ---------
  4462.      h  Indicates the corresponding integer argument is a short or an
  4463.         unsigned short (stands for "half-size").  Affects scanf(), but
  4464.         since DICE uses 32 bit integers, has no effect on printf().
  4465.  
  4466.      l  Indicates the corresponding integer argument is a long or
  4467.         unsigned long.  Also indicates floating point argument is a
  4468.         double (else is a float). Under DICE this flag is superfluous for
  4469.         integers, but for portability reasons you want to specify it when
  4470.         an argument is explicitly a long.
  4471.  
  4472.     Conversion Specifiers
  4473.     ---------------------
  4474.      c  Output integer as a character.
  4475.  
  4476.      d  Output a signed integer.
  4477.  
  4478.      e  Output a double quantity in exponential form. The precision
  4479.         specifies the number of digits beyond the decimal point to print,
  4480.         ie: [-]d.dddddde+/-dd.
  4481.  
  4482.      E  Upper case version of e.
  4483.  
  4484.      f  Output a double quantity. The precision specifies the number of
  4485.         digits beyond the decimal point to print, ie:  [-]d.dddddd
  4486.  
  4487.      g  Output a double quantity using either the 'e' or 'f' form,
  4488.         depending on the exponent.
  4489.  
  4490.      G  Output a double quantity using either the 'E' or 'f' form,
  4491.         depending on the exponent.
  4492.  
  4493.      i  Same as 'd', but less portable.
  4494.  
  4495.      n  The argument is a pointer to an integer which is used to set the
  4496.         integer to the bytes written out so far. This is especially
  4497.         useful with sprintf to determine where a particular part of the
  4498.         format begins in the output buffer.
  4499.  
  4500.      o  The unsigned integer quantity is converted to ASCII-octal.
  4501.  
  4502.      p  The pointer is printed (basically the hexadecimal address is
  4503.         printed).
  4504.  
  4505.      s  The NULL-terminated string represented by the character pointer
  4506.         is printed.
  4507.  
  4508.      u  The unsigned integer quantity is converted to ASCII-decimal.
  4509.  
  4510.      x  The unsigned integer quantity is converted to ASCII-hex using
  4511.         '0'-'9', 'a'-'f'.
  4512.  
  4513.      X  The unsigned integer quantity is converted to ASCII-hex using
  4514.         upper case 'A'-'F' instead of lower case.
  4515.  
  4516.     INPUTS
  4517.     FILE *fp;        file pointer (fprintf, vfprintf)
  4518.  
  4519.     char *fmt;        format string, e.g. "Answer is %d\n"
  4520.  
  4521.     char *buf;        buffer (sprintf, vsprintf)
  4522.  
  4523.     va_list argvect;    arg list (vprintf, vfprintf, vsprintf)
  4524.  
  4525.     RESULTS
  4526.     int n;            Number of characters written if successful, a
  4527.                 negative number if not.  For sprintf and vsprintf
  4528.                 the NULL character at the end of the string is
  4529.                 NOT included in the count.
  4530.  
  4531.     SEE ALSO
  4532.     puts, fputs, fwrite
  4533.  
  4534.     EXAMPLE
  4535.     /*
  4536.     **  Example using most printf conversion specifiers.
  4537.     **  Compile with -lm for the math functions to operate.
  4538.     */
  4539.     #include <stdio.h>
  4540.     #include <stdarg.h>
  4541.     void test_varargs(); /* Always use function prototypes */
  4542.     main()
  4543.     {
  4544.     char buf[256];
  4545.     int  n, i;
  4546.  
  4547.        printf(
  4548.        "Normal: ab%c %03d %03o $%p  Fu%s  %u    $%x  $%8X $%08lX\n",
  4549.               'c', 43,  11,  buf, "Bar",32094,4095,4095,4095 );
  4550.  
  4551.        printf(
  4552.         "Math:   Double: %le Float: %lf Formatted Float: %2.2lf\n",
  4553.              1.23E-2,   1.23E-2,               1.257 );
  4554.  
  4555.        printf("%9s\n",    "<-"); /* Specify 9 character field width */
  4556.        printf("%*s\n", 9, "<-"); /* Indirect specification */
  4557.  
  4558.        n = sprintf(buf, "Save %n%s", &i, "the whales");
  4559.        puts(buf);
  4560.        printf("String is %d+1 bytes long,"  /* String Concatenation */
  4561.           "with a %%n token at %d.\n", n, i);
  4562.  
  4563.        fprintf(stdout, "\nThis is a call to %s\n", "fprintf");
  4564.  
  4565.        test_varargs("%d %d %d ", 1, 2, 3);
  4566.  
  4567.        return(0);
  4568.     }
  4569.  
  4570.     void test_varargs(ctl, ...)
  4571.     char *ctl;
  4572.     {
  4573.        va_list va;
  4574.        int n;
  4575.        va_start(va, ctl);
  4576.        n = vprintf(ctl, va);
  4577.        printf("<- %d chars written\n", n);
  4578.        va_end(va);
  4579.     }
  4580.  
  4581. dice/ProcessRexxCommands                            dice/ProcessRexxCommands
  4582.  
  4583.     FUNCTION
  4584.     Handle incomming ARexx commands (DICE)
  4585.  
  4586.     SYNTAX
  4587.     #include <lib/rexx.h>
  4588.     ProcessRexxCommands(port)
  4589.     struct MsgPort *port;
  4590.  
  4591.     DESCRIPTION
  4592.     In order to process incomming ARexx commands you must call
  4593.     ProcessRexxCommands when you receive the signal RexxSigBit (signal
  4594.     mask is (1 << RexxSigBit)).
  4595.  
  4596.     Passing NULL to this routine will cause DICE to scan ALL KNOWN ARexx
  4597.     ports belonging to this program... that is, the master port and all
  4598.     created ports.    DICE will call DoRexxCommand for each ARexx command
  4599.     received as well as weed out returned messages from any ARexx
  4600.     commands we have sent that are still in progress.
  4601.  
  4602.     If you wish, you can pass a specific message port to have DICE only
  4603.     process ARexx commands received on a specific port, but beware that
  4604.     your Wait on the signal bit has cleared the signal and you should be
  4605.     sure to process all message ports before calling Wait again, else
  4606.     risk leaving unprocessed ARexx messages queued in and then blocking
  4607.     in Wait.
  4608.  
  4609.     INPUTS
  4610.     struct MsgPort *port;
  4611.                 Message port to process or NULL to process all
  4612.                 ports.
  4613.  
  4614.     SEE ALSO
  4615.     DoRexxCommand, PlaceRexxCommand, PlaceRexxCommandDirect
  4616.  
  4617.     EXAMPLE
  4618.     See DICE ARexx Support in chapter
  4619.  
  4620. dice/putchar                                                    dice/putchar
  4621.  
  4622.     FUNCTION
  4623.     output character to stdout (ANSI)
  4624.  
  4625.     SYNTAX
  4626.     #include <stdio.h>
  4627.     int r = putchar(c); /* MACRO */
  4628.  
  4629.     DESCRIPTION
  4630.     putchar outputs a character to stdout, returning the output character
  4631.     unless an error occurred.  If an error occurred then EOF is returned.
  4632.  
  4633.     || NOTE: Refer to the file_pointer manual page for general
  4634.     || information.
  4635.  
  4636.     INPUTS
  4637.     int c;            character to output, 0 to 255
  4638.  
  4639.     RESULTS
  4640.     int r;            same as c unless error occurred in which case
  4641.                 EOF.
  4642.  
  4643.     SEE ALSO
  4644.     putc, fputc, fread, fwrite, getc, getchar
  4645.  
  4646.     EXAMPLE
  4647.     /*
  4648.      * copy stdin to stdout using getchar/putchar. Normally
  4649.      * one uses fread/fwrite, but I'll save that for the
  4650.      * fread manual page.  Note that I output the initial
  4651.      * message to stderr so it does not get stuck into stdout
  4652.      * in case the user has redirected stdout.
  4653.      *
  4654.      * See getc manual page for equivalent example using
  4655.      * getc/putc
  4656.      */
  4657.     #include <stdio.h>
  4658.     main()
  4659.     {
  4660.          int c;
  4661.          fputs("Type a couple of lines, then ^\\ (EOF)\n",
  4662.             stderr);
  4663.          while ((c = getchar()) != EOF)
  4664.          {
  4665.         putchar(c);
  4666.          }
  4667.          return(0);
  4668.     }
  4669.  
  4670. dice/qsort                                                        dice/qsort
  4671.  
  4672.     FUNCTION
  4673.     sort an array of objects (ANSI)
  4674.  
  4675.     SYNTAX
  4676.     #include <stdio.h>
  4677.     #include <stdlib.h>
  4678.     (void) qsort(array, numElem, elemSize, compare_func)
  4679.     void *array;
  4680.     size_t numElem;
  4681.     size_t elemSize;
  4682.     int (*comp_func)(const void *arg1, const void *arg2);
  4683.  
  4684.     DESCRIPTION
  4685.     qsort sorts numElem elements in an array based at array. Each element
  4686.     is elemSize bytes long. When a comparison is required, qsort calls
  4687.     the passed compare_func function pointer with a pointer to the two
  4688.     elements being sorted. DICE currently implements qsort with a simple
  4689.     merge sort algorithm, using relatively slow movmems to avoid having
  4690.     to allocate much additional storage. Very little stack is used.
  4691.     Traditional qsort employs a stack based quick-sort algorithm that
  4692.     might use a massive amount of stack.
  4693.  
  4694.     INPUTS
  4695.     void *array;        pointer to base of array of objects
  4696.  
  4697.     size_t numElem;     number of elements in the array
  4698.  
  4699.     size_t elemSize;    size, in bytes, of each element
  4700.  
  4701.     int (*comp_func)()
  4702.                 function pointer to compare function given
  4703.                 pointers to two of the elements
  4704.  
  4705.     EXAMPLE
  4706.     #include <stdio.h>
  4707.     #include <stdlib.h>
  4708.     #define NUM_GENIUS 8
  4709.     char *StrList[NUM_GENIUS] =
  4710.     {
  4711.        "Euler", "Einstein", "Pascal", "Zeno",
  4712.        "Godel", "Leibniz", "Euclid", "Von Neumann"
  4713.     };
  4714.     my_comp(s1, s2)
  4715.     char **s1; char **s2;
  4716.     {
  4717.        return(strcmp(*s1, *s2));
  4718.     }
  4719.     main()
  4720.     {
  4721.        short i;
  4722.        qsort(StrList, NUM_GENIUS, sizeof(char *), my_comp);
  4723.        for (i = 0; i < NUM_GENIUS; ++i)
  4724.           printf("%d %s\n", i, StrList[i]);
  4725.        return(0);
  4726.     }
  4727.  
  4728. dice/raise                                                        dice/raise
  4729.  
  4730.     FUNCTION
  4731.     raise a signal (cause an 'interrupt' synchronously) (ANSI)
  4732.  
  4733.     SYNTAX
  4734.     int r = raise(signo);
  4735.     int signo;
  4736.  
  4737.     DESCRIPTION
  4738.     raise causes a signal to occur and the appropriate action to be
  4739.     taken.    It returns 0 on success, -1 if the signo is invalid (outside
  4740.     the range of allowed signals).    When you raise a signal, the signal
  4741.     is set back to its default vector before the handler is called.
  4742.     Thus, if you are allowing multiple signals to occur you MUST restore
  4743.     the signal vector with signal from your signal handler before it
  4744.     returns.
  4745.  
  4746.     INPUTS
  4747.     int signo;        signal to cause
  4748.  
  4749.     RESULTS
  4750.     int r;            0 on success, -1 if signo is out of range.
  4751.  
  4752.     SEE ALSO
  4753.     signal
  4754.  
  4755.     EXAMPLE
  4756.     /*
  4757.      *  prints the numbers 0 to 99, except only gets
  4758.      *  to 50 because we 'cause' a ^C.
  4759.      */
  4760.     #include <signal.h>
  4761.     main()
  4762.     {
  4763.        short i;
  4764.        for (i = 0; i < 100; ++i) {
  4765.           printf("i = %d\n", i);
  4766.           if (i == 50)
  4767.           raise(SIGINT);
  4768.         }
  4769.         return(0);
  4770.     }
  4771.  
  4772. dice/read                                                          dice/read
  4773.  
  4774.     FUNCTION
  4775.     read data from a file (UNIX)
  4776.  
  4777.     SYNTAX
  4778.     #include <fcntl.h>
  4779.     int r = read(fd, buf, bytes);
  4780.     int fd;
  4781.     void *buf;
  4782.     int bytes;
  4783.  
  4784.     DESCRIPTION
  4785.     read reads data from a file starting at the current seek position.
  4786.     read returns the number of bytes read or -1 if a read error occurs.
  4787.     With normal files, read will always return the number of bytes
  4788.     requested until the end of file is reached, in which case read may
  4789.     return fewer than the number of bytes requested.  If at the end of a
  4790.     file, read will return 0. With devices read may or may not return the
  4791.     number of bytes requested depending on the device.
  4792.  
  4793.     || NOTE: Refer to the file_descriptor manual page for general
  4794.     || information Unlike file pointers and file handles, the file
  4795.     || descriptor is checked for validity and will simply return an error
  4796.     || if illegal.
  4797.  
  4798.     INPUTS
  4799.     int fd;         file descriptor to read from
  4800.  
  4801.     void *buf;        pointer to buffer to read data into
  4802.  
  4803.     int len;        maximum number of bytes to read
  4804.  
  4805.     RESULTS
  4806.     int r;            number of bytes actually read (could be less than
  4807.                 len or 0), or < 0 if error.
  4808.  
  4809.     SEE ALSO
  4810.     close, creat, fcntl, fdtofh, ioctl, isatty, lseek, mkdir, open, read,
  4811.     rmdir, unlink, write
  4812.  
  4813.     EXAMPLE
  4814.     #include <fcntl.h>
  4815.     #include <assert.h>
  4816.  
  4817.     main()
  4818.     {
  4819.        int fd;
  4820.        int r;
  4821.        char buf[32];
  4822.        fd = open("T:xx", O_WRONLY|O_CREAT|O_TRUNC);
  4823.        assert(fd >= 0);
  4824.        write(fd, "FuBar\n", 6);
  4825.        close(fd);
  4826.        fd = open("T:xx", O_RDONLY);
  4827.        assert(fd >= 0);
  4828.        r = read(fd, buf, sizeof(buf)); /* sizeof(buf)==32 */
  4829.        close(fd);
  4830.        assert(r == 6);
  4831.        /*
  4832.         *  note that the buffer is not terminated with
  4833.         *  a NULL, but since we are using write() which
  4834.         *  requires a length it does not matter
  4835.         */
  4836.        write(1, buf, r);
  4837.     }
  4838.  
  4839. dice/realloc                                                    dice/realloc
  4840.  
  4841.     FUNCTION
  4842.     reallocate memory allocated by calloc, malloc, or strdup (ANSI)
  4843.  
  4844.     SYNTAX
  4845.     #include <stdlib.h>
  4846.     void *newptr = realloc(oldptr, bytes)
  4847.     void *oldptr;
  4848.     size_t bytes;
  4849.  
  4850.     DESCRIPTION
  4851.     realloc reallocates a previously allocated buffer, making it larger
  4852.     or smaller.  It returns a pointer to a new buffer which might be the
  4853.     same as the old buffer, but might not.    Data in the original buffer
  4854.     is copied to the new buffer and the original buffer is freed.  When
  4855.     extending a buffer with realloc note that the extended bytes (beyond
  4856.     the original buffer) will come up garbage.  You may pass a NULL as
  4857.     the first argument to realloc which basically makes realloc a malloc.
  4858.  
  4859.     INPUTS
  4860.     void *oldptr;        pointer to original allocated buffer
  4861.  
  4862.     size_t bytes;        size of new buffer
  4863.  
  4864.     RESULTS
  4865.     void *newptr;        pointer to new buffer
  4866.  
  4867.     SEE ALSO
  4868.     malloc, calloc, strdup
  4869.  
  4870.     EXAMPLE
  4871.     #include <string.h>
  4872.     #include <assert.h>
  4873.     #include <stdlib.h>
  4874.     main()
  4875.     {
  4876.        char *s;
  4877.        int len;
  4878.        s = strdup("This is a test");
  4879.        assert(s);
  4880.        len = strlen(s);
  4881.        /*
  4882.         *  Remember that len does not include the NULL
  4883.         *  byte at the end of the string
  4884.         */
  4885.        s = realloc(s, len + 8);   /*  make more room */
  4886.        assert(s);
  4887.        /*
  4888.         *  we can use strcat since in extending the
  4889.         *  allocated string the NULL *was* copied along
  4890.         *  with the string during the realloc.
  4891.         */
  4892.        strcat(s, "xx");
  4893.        puts(s);       /*  This is a testxx    */
  4894.        return(0);
  4895.     }
  4896.  
  4897. dice/rega4                                                        dice/rega4
  4898.  
  4899.     FUNCTION
  4900.     return current contents of register A4 (DICE)
  4901.  
  4902.     SYNTAX
  4903.     char *basePtr = rega4();
  4904.  
  4905.     DESCRIPTION
  4906.     rega4 is not geta4;  rega4 simply returns the current contents of the
  4907.     A4 register when you need it.  Note that DICE offsets the A4 register
  4908.     32766 from the actual small-data base so as to be able to use the
  4909.     entire -32768 to 32767 range to access 64 kilobytes of small-data.
  4910.     Note that a rega4 call inside a subroutine qualified with __geta4 is
  4911.     guaranteed to return the data base pointer.  Also, a rega4 call from
  4912.     any subroutine not called from an interrupt or a call back will
  4913.     return the proper data base pointer.
  4914.  
  4915.     ## WARNING: Programs which use this function will not be able to be
  4916.     ## made resident.
  4917.  
  4918. dice/remove                                                      dice/remove
  4919.  
  4920.     FUNCTION
  4921.     delete a file (ANSI)
  4922.  
  4923.     SYNTAX
  4924.     #include <stdio.h>
  4925.     int error = remove(filename);
  4926.     const char *filename;
  4927.  
  4928.     DESCRIPTION
  4929.     remove deletes the specified file path returning 0 on success, a
  4930.     negative number on failure.  On the Amiga, an error will occur if you
  4931.     try to delete a file currently opened by yourself or any other
  4932.     process.  remove is an ANSI function.  unlink does the same thing but
  4933.     is a UNIX-compatible function.
  4934.  
  4935.     INPUTS
  4936.     char *filename;     filename to delete
  4937.  
  4938.     RESULTS
  4939.     int error;        0 on success, a negative number on failure
  4940.  
  4941.     SEE ALSO
  4942.     unlink
  4943.  
  4944.     EXAMPLE
  4945.     #include <stdio.h>
  4946.     main()
  4947.     {
  4948.        int error = remove("T:XXX");
  4949.        if (error < 0)
  4950.        {
  4951.           perror("remove(\"T:XXX\") failed");
  4952.           exit(1);
  4953.        }
  4954.        puts("T:XXX has been deleted");
  4955.        return(0);
  4956.     }
  4957.  
  4958. dice/rename                                                      dice/rename
  4959.  
  4960.     FUNCTION
  4961.     rename a file, or move a file from one directory to another on the
  4962.     same filesystem (ANSI)
  4963.  
  4964.     SYNTAX
  4965.     #include <stdio.h>
  4966.     int error = rename(origname, newname);
  4967.     const char *origname;
  4968.     const char *newname;
  4969.  
  4970.     DESCRIPTION
  4971.     rename renames a file.    You may also use rename to move a file (and
  4972.     rename at the same time) to another directory on the same filesystem.
  4973.     rename returns 0 on success, a negative number on failure.
  4974.  
  4975.     INPUTS
  4976.     const char *origname;
  4977.                 existing file const char
  4978.  
  4979.     *newname;        new filename and/or path
  4980.  
  4981.     RESULTS
  4982.     int error;        0 on success, a negative number on failure
  4983.  
  4984.     SEE ALSO
  4985.     rewind
  4986.  
  4987.     EXAMPLE
  4988.     /*
  4989.      *  create the file T:xxjunk and the directory
  4990.      *  T:junkdir then move T:xxjunk into T:junkdir
  4991.      *  and rename to T:yyjunk at the same time.
  4992.      *  As is aptly demonstrated by this example, some
  4993.      *  errors are not really errors.  For example,
  4994.      *  mkdir where the dir already exists is not usually
  4995.      *  an error.
  4996.      */
  4997.     #include <stdio.h>
  4998.     #include <assert.h>
  4999.     #include <errno.h>
  5000.     main()
  5001.     {
  5002.         FILE *fp;     int error;
  5003.         error = mkdir("T:junkdir");
  5004.         if (error < 0 && errno != EEXIST)
  5005.         perror("mkdir");
  5006.         fp = fopen("T:xxjunk", "w");
  5007.         if (fp == NULL) {
  5008.         perror("fopen"); exit(1);
  5009.         }
  5010.         fprintf(fp, "This was originally T:xxjunk!\n");
  5011.         fclose(fp);
  5012.  
  5013.         error = rename("T:xxjunk", "T:junkdir/yyjunk");
  5014.         if (error < 0)
  5015.            perror("Error renaming T:xxjunk");
  5016.         else
  5017.            puts("rename succeeded, look in T:junkdir");
  5018.         return(0);
  5019.     }
  5020.  
  5021. dice/rewind                                                      dice/rewind
  5022.  
  5023.     FUNCTION
  5024.     seek filepointer to beginning of file (ANSI)
  5025.  
  5026.     SYNTAX
  5027.     #include <stdio.h>
  5028.     void rewind(fp);
  5029.     FILE *fp;
  5030.  
  5031.     DESCRIPTION
  5032.     rewind rewinds the file to the beginning, equivalent to fseek(fp, 0L,
  5033.     0);.
  5034.  
  5035.     || NOTE: Refer to the file_pointer manual page for general
  5036.     || information.
  5037.  
  5038.     INPUTS
  5039.     FILE *fp;        file pointer to rewind
  5040.  
  5041.     SEE ALSO
  5042.     fseek, fgetpos, fsetpos
  5043.  
  5044.     EXAMPLE
  5045.     /* print a file 3 times */
  5046.     #include <stdio.h>
  5047.     main(int ac, char**av) {
  5048.        FILE *fp;
  5049.        int i;
  5050.        char buf[256];
  5051.        if (ac == 1) {
  5052.           puts("Expected textfile argument");
  5053.           exit(1);
  5054.        }
  5055.        fp = fopen(av[1], "r");
  5056.        if (fp == NULL) {
  5057.           printf("Unable to open %s\n", av[1]);
  5058.           exit(1);
  5059.        }
  5060.        for (i = 1; i <= 3; ++i) {
  5061.           rewind(fp); printf("PRINTING #%d\n", i);
  5062.           while (fgets(buf, sizeof(buf), fp))
  5063.          fputs(buf, stdout);
  5064.        }
  5065.        return(0);
  5066.     }
  5067.  
  5068. dice/rmdir                                                        dice/rmdir
  5069.  
  5070.     FUNCTION
  5071.     delete a directory (UNIX)
  5072.  
  5073.     SYNTAX
  5074.     #include <stdio.h>
  5075.     int r = rmdir(dirname);
  5076.     char *dirname;
  5077.  
  5078.     DESCRIPTION
  5079.     rmdir deletes a directory.  The directory must be empty for the
  5080.     deletion to work.  On the Amiga this call is equivalent to remove or
  5081.     unlink.
  5082.  
  5083.     INPUTS
  5084.     char *dirname;        name of directory to delete
  5085.  
  5086.     RESULTS
  5087.     int r;            0 if successful, non-zero if error
  5088.  
  5089.     SEE ALSO
  5090.     mkdir
  5091.  
  5092.     EXAMPLE
  5093.     #include <assert.h>
  5094.     main()
  5095.     {
  5096.        int r;
  5097.        r = mkdir("T:tmpdir");
  5098.        assert(r == 0);
  5099.        r = rmdir("T:tmpdir");
  5100.        assert(r == 0);
  5101.     }
  5102.  
  5103. dice/scanf,fscanf,sscanf                            dice/scanf,fscanf,sscanf
  5104.  
  5105.     FUNCTION
  5106.     scan formatted text and convert to variables (ANSI)
  5107.  
  5108.     SYNTAX
  5109.     #include <stdio.h>
  5110.     int n = scanf(ctl, ...);      /* Input: standard in */
  5111.     int n = fscanf(fp, ctl, ...); /* Input: file pointer */
  5112.     int n = sscanf(str,ctl, ...); /* Input: string buffer */
  5113.     const char *ctl;
  5114.     FILE *fp;
  5115.     char *str;
  5116.  
  5117.     DESCRIPTION
  5118.     These functions scan the specified input file or buffer for fields
  5119.     matching those specified by the control field. Commands starting with
  5120.     % relate the scanned text to a list of pointers. The values the
  5121.     pointers point to are updated (say that three times fast). Other
  5122.     characters in the control field must match the scanned text exactly,
  5123.     except for white space characters, which match any length of white
  5124.     space in the scanned text.
  5125.  
  5126.     Control Field Commands
  5127.     ----------------------
  5128.     The control field command format is as follows:
  5129.  
  5130.         %[*][nnn][h/l/L]<conversion-specifier>
  5131.  
  5132.      %  All conversion specifiers start with %.  Use %% to match a single
  5133.         % in the source text.
  5134.  
  5135.      *  An optional * tells scanf to perform the conversion, but discard
  5136.         the result. Do not include a destination pointer for skiped
  5137.         conversions.
  5138.  
  5139.        nnn  An optional decimal number is used for string conversion to
  5140.         specify a maximum field width.
  5141.  
  5142.      h  The modifier h specifies the destination should be treated as a
  5143.         short integer rather, than an integer.  The h conversion applies
  5144.         to d, i, n, o, u, x and X.
  5145.  
  5146.      l  The modifier l specifies the destination should be treated as a
  5147.         long integer, rather than an integer.  The l conversion applies
  5148.         to d, i, o, u, x and X.
  5149.  
  5150.      L  When used with formats e, f or g, specifies the destination
  5151.         should be treated to a long double rather than a double.
  5152.  
  5153.     Conversion Specifiers
  5154.     ---------------------
  5155.      c  With no field width specified, converts one character.  With a
  5156.         field width, converts the number of characters specified by the
  5157.         field width into an array. The expected argument is a pointer to
  5158.         a character or array of characters. No white space is skipped.
  5159.  
  5160.      d  Converts a decimal (base 10) number.  The expected argument is a
  5161.         pointer to an integer.  The l and h modifiers may be used to
  5162.         specify either a long or short integer result.
  5163.  
  5164.      e/f/g  Scans a floating point number.  If the l modifier is used, a long
  5165.         double pointer is expected (not implemented in DICE yet), else a
  5166.         double is expected.
  5167.  
  5168.      i  Converts a number to an integer.  The format should be equivalent
  5169.         to that expected by strtol with a base argument of 0 (automatic
  5170.         detection of format).
  5171.  
  5172.      n  This command does not scan any text.  It places into an integer
  5173.         the current count of processed characters.
  5174.  
  5175.      o  An octal number is expected.  The value is stored to an integer.
  5176.  
  5177.      p  A pointer is expected, in the same format as the %p from printf.
  5178.         The value is stored into a pointer, passed as void ** (a pointer
  5179.         to any type of pointer).
  5180.  
  5181.      s  Reads a string of non-white space characters and copies into the
  5182.         array specified by the argument.  The argument must be of type
  5183.         char * and have enough space to handle any possible string plus a
  5184.         NULL terminator.
  5185.  
  5186.      x  A hexadecimal (base 16) number is expected.  The value is stored
  5187.         into an integer.  This is equivalent to calling strtol with a
  5188.         base of 16.
  5189.  
  5190.     %%  Match a single % in the input stream.
  5191.  
  5192.      [...]  Scan a scanset.  Scan the input stream and place the characters
  5193.         into a char * buffer until a character is read that does not
  5194.         match the scanset.    If a scan set begins with ^ (as in [^abcd])
  5195.         then all characters are allowed except those specified in the
  5196.         scanset.  If a scanset begins as []abcd] or [^]abcd] then the ']'
  5197.         character is included in the scan set and the set is terminated
  5198.         by ']'.
  5199.  
  5200.         || NOTE: All scanf arguments are pointers.    A common mistake is
  5201.         || to pass arguments directly; pointers are required.  All
  5202.         || floating point arguments must be pointers to doubles.
  5203.  
  5204.     INPUTS
  5205.     char *ctl;        format control string, containing % commands
  5206.  
  5207.     FILE *fp;        file pointer for fscanf
  5208.  
  5209.     char *str;        string pointer for sscanf
  5210.  
  5211.     ...            pointers to variables ready to receive
  5212.                 conversions.
  5213.  
  5214.     RESULTS
  5215.     int n;            Number of conversions that occurred or -1 if no
  5216.                 conversions could be made (this usually means
  5217.                 EOF).  The function may return less than the
  5218.                 number of requested conversions.  This value does
  5219.                 not count any %* conversions.
  5220.  
  5221.     SEE ALSO
  5222.     sprintf, printf, fprintf, strtol
  5223.  
  5224.     EXAMPLE
  5225.     #include <stdio.h>
  5226.     main(int ac, char**av)
  5227.     {
  5228.     int    n, integer;
  5229.  
  5230.        n = sscanf("Input: 132\n", "Input: %ld\n", &integer);
  5231.        printf("First test: n=%d integer=%d  ", n, integer);
  5232.  
  5233.     short a[3] = {-1, -2, -3}; // Unscanned arguments are NOT
  5234.     int   b[3] = {-4, -5, -6}; // cleared - they retain
  5235.     char  buf1[11], buf2[11];  // former values!
  5236.  
  5237.        buf1[0]=buf2[0]=buf2[10] = 0;
  5238.  
  5239.        if (ac != 2) {
  5240.           puts("Expected string to format!"); exit(1);
  5241.        }
  5242.        n = sscanf(av[1],"%hd %ho %hi %*d %X %n%10s %10c   -%d-",
  5243.                  a+0,a+1,a+2,   b+0,b+1,buf1,buf2,b+2);
  5244.        printf("Second test: %d elements\n", n);
  5245.        printf("a (shorts): %d %d %d\n", a[0], a[1], a[2]);
  5246.        printf("b (ints)  : %d %d %d\n", b[0], b[1], b[2]);
  5247.        printf("buf1      : %s\nbuf2      : %s\n", buf1, buf2);
  5248.        return(0);
  5249.     }
  5250.     /* scanf "100 100 0x100 200 0x300 reduce reuse recycle!"
  5251.     ** First test: n=1 integer=132    Second test: 6 elements
  5252.     ** a (shorts): 100 64 256
  5253.     ** b (ints)  : 768 24 -6
  5254.     ** buf1      : reduce
  5255.     ** buf2      : reuse recy
  5256.     */
  5257.  
  5258. dice/setbuf,setvbuf                                      dice/setbuf,setvbuf
  5259.  
  5260.     FUNCTION
  5261.     change a file pointer's buffering (ANSI)
  5262.  
  5263.     SYNTAX
  5264.     #include <stdio.h>
  5265.     void setbuf(fp, buf);
  5266.     error = setvbuf(fp, buf, mode, size);
  5267.     FILE *fp; char *buf;
  5268.     int mode; size_t size; int error;
  5269.  
  5270.     DESCRIPTION
  5271.     setbuf changes the internal buffer used by stdio.  The buffer you
  5272.     pass it must be BUFSIZ bytes in size.  You can set a file pointer to
  5273.     unbuffered by passing NULL for your buffer.
  5274.  
  5275.     setvbuf supersedes this call and is, in general, a better function.
  5276.     Type type argument must be one of _IOFBF (Fully Buffered), _IOLBF
  5277.     (Line Buffered) or _IONBF (Non Buffered).  For use with DICE it is
  5278.     best to supply a buffer size, but a NULL buf pointer. DICE will
  5279.     allocate buffers as they are needed.
  5280.  
  5281.     ## WARNING: If buffering is turned off for a file pointer
  5282.     ## representing a console device, the console device is set to
  5283.     ## unbuffered as well.    If buffering is turned on for a file pointer
  5284.     ## representing a console device, the console device is set to
  5285.     ## buffered as well.
  5286.  
  5287.     || NOTE: Refer to the file_pointer manual page for general
  5288.     || information.
  5289.  
  5290.     INPUTS
  5291.     FILE *fp;        file pointer to affect.
  5292.  
  5293.     char *buf;        buffer for use by the file pointer, or NULL.
  5294.  
  5295.     int type;        (setvbuf) type of buffering.
  5296.  
  5297.     size_t size;        (setvbuf) requested buffer size or zero.
  5298.  
  5299.     int error;        (setvbuf) error code (if size or type are
  5300.                 invalid).
  5301.  
  5302.     EXAMPLE 1
  5303.     #include <stdio.h>
  5304.     main()
  5305.     {
  5306.     FILE *fp;
  5307.  
  5308.        fp = fopen("CON:0/0/640/100/DICE Setbuf Test","w");
  5309.        if(! fp )
  5310.           exit( 10 );
  5311.  
  5312.        fprintf(fp, "This will be buffered, ");
  5313.        sleep(2);
  5314.        setvbuf(fp, NULL, _IONBF, 0);
  5315.        fprintf(fp, "yet these will print immediately ");
  5316.        sleep(2);
  5317.        fprintf(fp, "(we are unbuffered).");
  5318.        sleep(4);
  5319.        fprintf(fp, "\n");
  5320.  
  5321.        setvbuf(fp, NULL, _IOLBF, 128);
  5322.        fprintf(fp, "Now back to buffered... ");
  5323.        sleep(2);
  5324.        fprintf(fp, "(See - you had to wait).\n");
  5325.        sleep(8);
  5326.  
  5327.        fclose( fp );
  5328.        return(0);
  5329.     }
  5330.  
  5331.     EXAMPLE 2
  5332.     #include <stdio.h>
  5333.     #define BUFFER_SIZE 128
  5334.     main()
  5335.     {
  5336.        int c;    char buf[256];
  5337.  
  5338.        setvbuf(stdin, NULL, _IONBF, 0);
  5339.        printf("Type a character: ");
  5340.        fflush(stdout);
  5341.        c = getchar();
  5342.        printf("c = %d\n", c);
  5343.  
  5344.        setvbuf(stdin, NULL, _IOLBF, BUFFER_SIZE);
  5345.        printf("Type a line: ");
  5346.        fflush(stdout);
  5347.        fgets(buf, sizeof(buf), stdin);
  5348.        printf("You said   : %s\n", buf);
  5349.        return(0);
  5350.     }
  5351.  
  5352. dice/setjmp,longjmp                                      dice/setjmp,longjmp
  5353.  
  5354.     FUNCTION
  5355.     setjmp: save procedure context for future long jump (ANSI)
  5356.     longjmp: jump to a previously saved procedure context (ANSI)
  5357.  
  5358.     SYNTAX
  5359.     #include <setjmp.h>
  5360.     int r = setjmp(enviro);
  5361.     (void) longjmp(enviro, rval)
  5362.     jmp_buf enviro;
  5363.     int rval;
  5364.  
  5365.     DESCRIPTION
  5366.     First, setjmp stores the current procedure context into an
  5367.     environment array whose type is jmp_buf.  When called by a procedure
  5368.     it saves the environment and returns 0.  Then when called, longjmp
  5369.     jumps to a previously saved environment causing execution to begin at
  5370.     the setjmp call that saved that environment. Yet instead of returning
  5371.     0 the 'resumed' setjmp returns a return value set by the longjmp
  5372.     call.  Jmp_buf is a typedef of an array, thus by passing a jmp_buf
  5373.     structure we really pass the address of it.  setjmp and longjmp are
  5374.     fully compatible with dynamic stacks  (-gs option to DCC).
  5375.  
  5376.     :: Beginner's Note: setjmp and longjmp should be used sparingly, if
  5377.     :: at all. They make code hard to understand, are rife with potential
  5378.     :: for adding bugs and are considered even uglier than the C goto
  5379.     :: statement.
  5380.  
  5381.     In the example below main is still stacked when the longjmp occurs
  5382.     and is thus valid.  It would be illegal, for instance, to call a
  5383.     subroutine which does a setjmp and RETURNS to you, then longjmp back
  5384.     to that subroutine. The contents of the jmp_buf structure are private
  5385.     and may not be modified by the program.
  5386.  
  5387.     ## WARNING: You can only longjmp to a previously saved environment
  5388.     ## that has not been unstacked.  WARNING: setjmp saves the current
  5389.     ## state of the registers, but not any registers that get modified
  5390.     ## between the setjmp and the longjmp!
  5391.  
  5392.     Thus, auto variables placed in registers (which is done so
  5393.     automatically under DICE) may contain 'old' values after a longjmp if
  5394.     they were modified after the setjmp. To prevent this such variables
  5395.     must, by ANSI convention, be made volatile.  The volatile qualifier
  5396.     forces an auto variable to be placed on the stack instead of in a
  5397.     register.
  5398.  
  5399.     INPUTS
  5400.     jmp_buf enviro;     environment structure
  5401.  
  5402.     int rval;        return value (longjmp call)
  5403.  
  5404.     RESULTS
  5405.     (setjmp) int r;     0 when called directly, rval when environment
  5406.                 restored by a longjmp
  5407.  
  5408.     SEE ALSO
  5409.     onbreak, signal
  5410.  
  5411.     EXAMPLE
  5412.     #include <stdio.h>
  5413.     #include <setjmp.h>
  5414.     jmp_buf x;
  5415.  
  5416.     int  brk(void);
  5417.     void breakme(void);
  5418.  
  5419.     main()
  5420.     {
  5421.        int r;
  5422.        onbreak(brk);
  5423.  
  5424.        r = setjmp(x); // returns 0 when called by main
  5425.        puts("\nArnie sez:  I'll be back...");
  5426.  
  5427.        if (r == 0)
  5428.           for (;;)
  5429.         breakme();
  5430.  
  5431.        printf("Broke and jumped, r = %d\n", r);
  5432.        return(0);
  5433.     }
  5434.     /* even though the onbreak call is supposed to return,
  5435.     ** we can longjmp out of it as well.
  5436.     */
  5437.     int brk()
  5438.     {
  5439.        longjmp(x, 23);
  5440.     }
  5441.     void breakme()
  5442.     {
  5443.        puts("Break Me With ^C!");
  5444.     }
  5445.  
  5446. dice/signal                                                      dice/signal
  5447.  
  5448.     FUNCTION
  5449.     set a signal vector for a signal (ANSI)
  5450.  
  5451.     SYNTAX
  5452.     #include <signal.h>
  5453.     typedef void (*__sigfunc)(int);
  5454.     __sigfunc oldfunc = signal(signo, newfunc)
  5455.     int signo;
  5456.     __sigfunc newfunc;
  5457.  
  5458.     DESCRIPTION
  5459.     signal sets a signal vector function for a given signal number as
  5460.     defined in <signal.h> and returns the previously set function.
  5461.     Currently only SIGINT causes any semi-asynchronous action to occur.
  5462.     You may pass newfunc as your own signal function or one of:
  5463.  
  5464.    SIG_ERR  error (exit program)
  5465.  
  5466.    SIG_DFL  default (for break, normal operation)
  5467.  
  5468.    SIG_IGN  ignore signal (for break, ^C is now ignored)
  5469.  
  5470.         when a signal occurs, the signal is set back to its default
  5471.         condition before the handler is called.  Thus, if you are
  5472.         allowing multiple signals to occur you must restore the signal
  5473.         vector with signal from your signal handler before it returns.
  5474.  
  5475.         || NOTE: On the Amiga, signals are not truly asynchronous.    ^C is
  5476.         || detected during stdio calls only.  No other signal is
  5477.         || implemented though you CAN modify any signal vector 0 to 31
  5478.         || and raise it with the raise call. Early versions of DICE,
  5479.         || including quite possibly this version, do not understand
  5480.         || complex type declarations containing procedural types. Thus,
  5481.         || you may have to get around the problem by building up a
  5482.         || complex procedural type with typedefs.  Unlike onbreak, a
  5483.         || signal function returns no value.
  5484.  
  5485.     INPUTS
  5486.     int signo;        signal to modify, usually SIGINT __sigfunc
  5487.  
  5488.     newfunc;        signal function or SIG_ERR, SIG_DFL, SIG_IGN
  5489.  
  5490.     RESULTS
  5491.     __sigfunc oldfunc;
  5492.                 previous signal function
  5493.  
  5494.     SEE ALSO
  5495.     raise
  5496.  
  5497.     EXAMPLE
  5498.     #include <signal.h>
  5499.     void brkfunc(int);
  5500.     main()
  5501.     {
  5502.        short i;
  5503.        puts("The following is unbreakable");
  5504.        sleep(1);
  5505.        signal(SIGINT, SIG_IGN);
  5506.        for (i = 0; i < 100; ++i) printf("1 %d\n", i);
  5507.        puts("The following may be broken out of");
  5508.        puts("with a cute message");
  5509.        sleep(1);
  5510.        signal(SIGINT, brkfunc);
  5511.        for (i = 0; i < 100; ++i) printf("2 %d\n", i);
  5512.        puts("The following may be broken out of");
  5513.        sleep(1);
  5514.        signal(SIGINT, SIG_DFL);
  5515.        for (i = 0; i < 100; ++i) printf("3 %d\n", i);
  5516.        puts("Hey! You never hit ^C! \
  5517.          What kind of test is this!");
  5518.        return(0);
  5519.     }
  5520.     void brkfunc(int signo)
  5521.     {
  5522.        printf("signo %d. Want cute?  Get a kitten.\n", signo);
  5523.        exit(1);
  5524.     }
  5525.  
  5526. dice/sleep                                                        dice/sleep
  5527.  
  5528.     FUNCTION
  5529.     sleep for a period of time (UNIX)
  5530.  
  5531.     SYNTAX
  5532.     #include <stdio.h>
  5533.     sleep(n);
  5534.     int n;
  5535.  
  5536.     DESCRIPTION
  5537.     The sleep function waits for a period of time specified in seconds.
  5538.     It can be interrupted by a ^C.
  5539.  
  5540.     || NOTE: The timekeeping of sleep is not very accurate.  On the
  5541.     || Amiga, sleep is implemented with a loop of delay(50); calls.
  5542.  
  5543.     INPUTS
  5544.     int n;            number of seconds to sleep
  5545.  
  5546.     EXAMPLE
  5547.     #include <stdio.h>
  5548.     main(int ac, char**av)
  5549.     {
  5550.        puts("Sleeping for 10 seconds");
  5551.        sleep(10);
  5552.        puts("That was a good rest");
  5553.        return(0);
  5554.     }
  5555.  
  5556. dice/stack_abort                                            dice/stack_abort
  5557.  
  5558.     FUNCTION
  5559.     exit point when dynamic stack allocation fails (DICE)
  5560.  
  5561.     SYNTAX
  5562.     void stack_abort(void)
  5563.     {
  5564.         /* .. your exit code .. */
  5565.         abort();
  5566.     }
  5567.  
  5568.     DESCRIPTION
  5569.     When dynamic stack allocation is enabled via the -gs option and such
  5570.     an allocation fails, stack_abort is called.  If you do not specify a
  5571.     stack_abort routine, the c.lib stack_abort function will simply call
  5572.     abort.
  5573.  
  5574.     If you do specify a stack_abort routine, you have two choices: you
  5575.     can exit out of the program, or you can simply return from the
  5576.     subroutine which retries the allocation and calls stack_abort again
  5577.     if it fails (perhaps wait a bit in hopes memory has become
  5578.     available).
  5579.  
  5580.     The program has about 2KB of stack left at the time this function is
  5581.     called.  Since a low memory condition exists when this function is
  5582.     called you should not do anything that might require additional
  5583.     allocations!
  5584.  
  5585.     SEE ALSO
  5586.     abort, exit
  5587.  
  5588. dice/stat                                                          dice/stat
  5589.  
  5590.     FUNCTION
  5591.     stat a file by name (UNIX)
  5592.  
  5593.     SYNTAX
  5594.     #include <sys/stat.h>
  5595.     int error = stat(name, &stat_buf);
  5596.     const char *name;
  5597.     struct stat stat_buf;
  5598.  
  5599.     DESCRIPTION
  5600.     stat is a UNIX-compatible call that returns information pertaining to
  5601.     the file represented by its name. If 0 is returned, stat succeeded
  5602.     and the fields will be filled in as follows:
  5603.  
  5604.    st_mode  Flags S_IFDIR if directory, S_IFREG if regular file, S_IREAD if
  5605.         readable, S_IWRITE if writable, S_IEXEC if executable.
  5606.  
  5607.    st_size  Size of the file, in bytes.
  5608.  
  5609.  st_blksize
  5610.         Always returns 512 (for now).
  5611.  
  5612.  st_blocks  A guess at the number of actual blocks the file takes up,
  5613.         including headers and side sectors.
  5614.  
  5615.   st_ctime  Time the file was last modified.
  5616.  
  5617.   st_mtime  Same as st_ctime.
  5618.  
  5619.     st_dev  Physical device ID (do not try to interpret this field, but it
  5620.         does represent the DOS handler).
  5621.  
  5622.     st_ino  inode ID (usually a file block number on the Amiga).
  5623.  
  5624.         || NOTE: On the Amiga one normally cannot directly examine a file
  5625.         || that is exclusively locked.  If this case occurs, stat will
  5626.         || attempt to scan the parent directory for the file and if that
  5627.         || doesn't work, returns -1.
  5628.  
  5629.     INPUTS
  5630.     char *name;        name of file to stat
  5631.  
  5632.     struct stat *sbuf;
  5633.                 address of stat structure that will be filled in
  5634.  
  5635.     RESULTS
  5636.     int error;        0 on success, < 0 on error
  5637.  
  5638.     SEE ALSO
  5639.     chdir
  5640.  
  5641.     EXAMPLE
  5642.     #include <stdio.h>
  5643.     #include <fcntl.h>
  5644.     #include <sys/stat.h>
  5645.     main(int ac, char**av)
  5646.     {
  5647.        int r;
  5648.        struct stat stat_buf;
  5649.        if (ac == 1) {
  5650.           puts("Expected a test file name");
  5651.           exit(1);
  5652.        }
  5653.        r = stat(av[1], &stat_buf);
  5654.        if (r < 0)
  5655.           printf("Can't stat %s\n", av[1]);
  5656.        else {
  5657.           printf("File is %d bytes long\n", stat_buf.st_size);
  5658.           printf("modified %s", ctime(&stat_buf.st_ctime));
  5659.        }
  5660.        return(0);
  5661.     }
  5662.  
  5663. dice/stdin,stdout,stderr,EOF                    dice/stdin,stdout,stderr,EOF
  5664.  
  5665.     FUNCTION
  5666.     stdin: standard input channel (file pointer - MACRO)
  5667.     stdout: standard output channel (file pointer - MACRO)
  5668.     stderr: standard error channel (file pointer - MACRO)
  5669.     EOF: special value representing End-Of-File
  5670.  
  5671.     SYNTAX
  5672.     #include <stdio.h>
  5673.  
  5674.     DESCRIPTION
  5675.     stdin is the name for the program's standard input stream, a "FILE *"
  5676.     (Pointer to structure FILE).  This can be redirected via command line
  5677.     redirection when the program is run.  stdout is a FILE * type that
  5678.     represents the program's standard output stream.  This can also be
  5679.     redirected via command line redirection when the program is run.
  5680.     stderr is a FILE * type that represents the program's standard error
  5681.     stream. Currently stderr is opened by _main and represents the
  5682.     console device associated with the program regardless of standard
  5683.     redirections.  EOF is special value, -1 in this implementation, that
  5684.     represents an end of file marker.  Functions that return a single
  5685.     character actually return type int to allow EOF to be distinct from
  5686.     valid characters. Include the file stdio.h to use these definitions.
  5687.  
  5688.     These file pointers may be fclose'd or freopen'd at any time. The
  5689.     stdio macros getchar and putchar and stdio library routines gets and
  5690.     puts deal with stdin and stdout respectively while other library
  5691.     routines such as perror output to stderr.
  5692.  
  5693. dice/stpchr                                                      dice/stpchr
  5694.  
  5695.     FUNCTION
  5696.     Search for a character in a string (UNIX)
  5697.  
  5698.     SYNTAX
  5699.     #include <string.h>
  5700.     char *ptr = stpchr(s, c)
  5701.     const char *s;
  5702.     int c;
  5703.  
  5704.     DESCRIPTION
  5705.     This searches for the character c within the string pointed to by s.
  5706.     The terminating NULL at the end of s is NOT included in the search.
  5707.     A pointer to the first occurrence of c in s is returned or NULL if c
  5708.     could not be found. c is converted to a char by stpchr before
  5709.     beginning the search.
  5710.  
  5711.     || NOTE: It is better to use the ANSI standard strchr and strrchr
  5712.     || functions.
  5713.  
  5714.     INPUTS
  5715.     char *s;        pointer to string to search
  5716.  
  5717.     int c;            character to search for
  5718.  
  5719.     RESULTS
  5720.     char *ptr;        pointer to the first occurrence of the character
  5721.                 c in s, or NULL if c could not be found in s.
  5722.  
  5723.     SEE ALSO
  5724.     strchr, strrchr
  5725.  
  5726.     EXAMPLE
  5727.     #include <stdio.h>
  5728.     #include <string.h>
  5729.     #include <assert.h>
  5730.     main()
  5731.     {
  5732.        char *s = "this is a test";
  5733.        char *ptr;
  5734.        ptr = stpchr(s, 'i');
  5735.        assert(ptr == s + 2);
  5736.        puts(ptr);       /*  "is is a test"  */
  5737.        return(0);
  5738.     }
  5739.  
  5740. dice/stpcpy                                                      dice/stpcpy
  5741.  
  5742.     FUNCTION
  5743.     copy a string returning a pointer to the end of the destination
  5744.     (UNIX)
  5745.  
  5746.     SYNTAX
  5747.     #include <string.h>
  5748.     char *ptr = stpcpy(d, s);
  5749.     char *d;
  5750.     char *s;
  5751.  
  5752.     DESCRIPTION
  5753.     This function copies the NULL terminated string pointed to by s to
  5754.     the buffer d.  The NULL is copied.  A pointer to the NULL character
  5755.     at the end of the copied string in d is returned.
  5756.  
  5757.     || NOTE: stpcpy is non-standard.  While a stpcpy/stpcpy combination
  5758.     || is more efficient than a strcpy/strcat combination, strcpy and
  5759.     || strcat are standard functions and thus are guaranteed to exist in
  5760.     || all environments.
  5761.  
  5762.     INPUTS
  5763.     char *d;        pointer to beginning of destination buffer
  5764.  
  5765.     char *s;        pointer to beginning of source string
  5766.  
  5767.     RESULTS
  5768.     char *ptr;        pointer to end of data copied to destination
  5769.                 buffer
  5770.  
  5771.     SEE ALSO
  5772.     strcpy, strbpl
  5773.  
  5774.     EXAMPLE
  5775.     #include <stdio.h>
  5776.     #include <string.h>
  5777.     main()
  5778.     {
  5779.        char *buf1 = "Micky ";
  5780.        char *buf2 = "Moose";
  5781.        char dest[32];
  5782.        char *ptr;
  5783.        ptr = stpcpy(dest, buf1);
  5784.        stpcpy(ptr, buf2);
  5785.        puts(dest);       /* Micky Moose */
  5786.        return(0);
  5787.     }
  5788.  
  5789. dice/strbpl                                                      dice/strbpl
  5790.  
  5791.     FUNCTION
  5792.     unpack a string-array buffer into an array of pointers (DICE)
  5793.  
  5794.     SYNTAX
  5795.     #include <string.h>
  5796.     int num = strbpl(av, max, sary)
  5797.     char **av;
  5798.     int max;
  5799.     const char *sary;
  5800.  
  5801.     DESCRIPTION
  5802.     strbpl unpacks a string-array into an array of string pointers.  The
  5803.     string array is a series of NULL terminated strings strung together
  5804.     and terminated by a final NULL.  A pointer to each string is placed
  5805.     in the array-of-pointers (av) with a final NULL entry assuming the
  5806.     number of strings does not exceed (max-1).
  5807.  
  5808.     INPUTS
  5809.     char **av;        pointer to a preallocated array of pointers
  5810.  
  5811.     int max;        the maximum number of entries in the above array
  5812.  
  5813.     char *sary;        pointer to a packed string.
  5814.  
  5815.     RESULTS
  5816.     int num;        number of pointers loaded into the av array not
  5817.                 including the final NULL.  If num == max then the
  5818.                 av array was not large enough to fit all the
  5819.                 strings or the final NULL.
  5820.  
  5821.     EXAMPLE
  5822.     #include <stdio.h>
  5823.     #include <string.h>
  5824.     #include <assert.h>
  5825.     main()
  5826.     {
  5827.        char *sary = "this\0is\0a\0test\0\0";
  5828.        char *av[16];
  5829.        int n;
  5830.        #define arysize(x) (sizeof(x)/sizeof((x)[0]))
  5831.        n = strbpl(av, arysize(av), sary);
  5832.        assert(n == 4);     /*  n == 4  */
  5833.        puts(av[0]);       /*  this    */
  5834.        puts(av[1]);       /*  is      */
  5835.        puts(av[2]);       /*  a       */
  5836.        puts(av[3]);       /*  test    */
  5837.        assert(av[4] == NULL); /*  av[4] == NULL   */
  5838.        return(0);
  5839.     }
  5840.  
  5841. dice/strcat                                                      dice/strcat
  5842.  
  5843.     FUNCTION
  5844.     concatenate a string to an existing string (ANSI)
  5845.  
  5846.     SYNTAX
  5847.     #include <string.h>
  5848.     char *d = strcat(d, s);
  5849.     char *d;
  5850.     const char *s;
  5851.  
  5852.     DESCRIPTION
  5853.     strcat scans the destination buffer for the NULL terminator and then
  5854.     appends the source string to the destination buffer (removing the
  5855.     NULL terminator and placing one at the end after the concatenation).
  5856.     A pointer to the beginning of the destination buffer is returned.
  5857.  
  5858.     INPUTS
  5859.     char *d;        pointer to destination buffer which already
  5860.                 contains a string (which could be just a \0).
  5861.  
  5862.     char *s;        pointer to the NULL terminated source string
  5863.  
  5864.     RESULTS
  5865.     char *d;        same as the first argument, a pointer to the
  5866.                 destination buffer.
  5867.  
  5868.     SEE ALSO
  5869.     strncpy, strcpy, strncat
  5870.  
  5871.     EXAMPLE
  5872.     #include <stdio.h>
  5873.     #include <string.h>
  5874.     main()
  5875.     {
  5876.        char dest[80];
  5877.        char *s1 = "I had an elegant proof also, ";
  5878.        char *s2 = "but the console window was too narrow...";
  5879.  
  5880.        strcpy(dest, s1);
  5881.        puts( strcat(dest, s2) ); /* returns its first arg */
  5882.     }
  5883.  
  5884. dice/strchr                                                      dice/strchr
  5885.  
  5886.     FUNCTION
  5887.     search for a character in a string (ANSI)
  5888.  
  5889.     SYNTAX
  5890.     #include <string.h>
  5891.     char *ptr = strchr(s, c)
  5892.     const char *s;
  5893.     int c;
  5894.  
  5895.     DESCRIPTION
  5896.     This searches for the character c within the string pointed to by s.
  5897.     The terminating NULL at the end of s is included in the search.  A
  5898.     pointer to the first occurrence of c in s is returned or NULL if c
  5899.     could not be found. C is converted to a char by strchr before
  5900.     beginning the search.
  5901.  
  5902.     || NOTE: While strchr(s, 0); may be used to find the end of the
  5903.     || string this is slow compared to using the construction: char *ptr
  5904.     || = s + strlen(s);  /*  ptr = end of string s */.
  5905.  
  5906.     INPUTS
  5907.     char *s;        pointer to the string to search
  5908.  
  5909.     int c;            character to search for.
  5910.  
  5911.     RESULTS
  5912.     char *ptr;        pointer to the first occurrence of character c in
  5913.                 s or NULL if c could not be found in s.
  5914.  
  5915.     SEE ALSO
  5916.     strrchr
  5917.  
  5918.     EXAMPLE
  5919.     #include <stdio.h>
  5920.     #include <string.h>
  5921.     #include <assert.h>
  5922.     main()
  5923.     {
  5924.        char *s = "We feel incredibly agile";
  5925.        char *ptr;
  5926.        ptr = strchr(s, 'i');
  5927.        assert(ptr == s + 2);
  5928.        puts(ptr);       /* "incredibly agile" */
  5929.        return(0);
  5930.     }
  5931.  
  5932. dice/strcmp                                                      dice/strcmp
  5933.  
  5934.     FUNCTION
  5935.     compare two strings (ANSI)
  5936.  
  5937.     SYNTAX
  5938.     #include <string.h>
  5939.     int r = strcmp(s1, s2);
  5940.     const char *s1;
  5941.     const char *s2;
  5942.  
  5943.     DESCRIPTION
  5944.     strcmp compares two strings, returning -1 if s1 < s2,  0 if s1 == s2
  5945.     , and 1 if  s1 > s2.
  5946.  
  5947.     || NOTE: strcmp converts the chars in the string to unsigned
  5948.     || quantities when comparing them.  However, for portability you
  5949.     || should not strcmp strings containing negative characters (bit 7
  5950.     || set) for anything other than checking the result against 0.    Use
  5951.     || the memcmp routine instead.
  5952.  
  5953.     INPUTS
  5954.     char *s1;        pointer to first string
  5955.  
  5956.     char *s2;        pointer to second string
  5957.  
  5958.     RESULTS
  5959.     int r;            -1, 0, or 1.
  5960.  
  5961.     SEE ALSO
  5962.     strncmp, stricmp
  5963.  
  5964.     EXAMPLE
  5965.     #include <stdio.h>
  5966.     #include <string.h>
  5967.     #include <assert.h>
  5968.     main()
  5969.     {
  5970.        char *s1 = "abca";
  5971.        char *s2 = "abcd";
  5972.        char *s3 = "abcx";
  5973.        char *s4 = "abcdx";
  5974.        char *s5 = "abc";
  5975.        char *x2 = "abcd";
  5976.        int r;
  5977.        r = strcmp(s2, x2);
  5978.        /*  string s2 same as string x2 */
  5979.        assert(r == 0);
  5980.        r = strcmp(s2, s1);
  5981.        /*  string s2 larger than string s1*/
  5982.        assert(r > 0);
  5983.        r = strcmp(s2, s3);
  5984.        assert(r < 0);
  5985.        r = strcmp(s2, s4);
  5986.        assert(r < 0);
  5987.        r = strcmp(s2, s5);
  5988.        assert(r > 0);
  5989.        return(0);
  5990.     }
  5991.  
  5992. dice/strcpy                                                      dice/strcpy
  5993.  
  5994.     FUNCTION
  5995.     copy a string returning a pointer to the beginning of the destination
  5996.     (ANSI)
  5997.  
  5998.     SYNTAX
  5999.     #include <string.h>
  6000.     char *ptr = strcpy(d, s);
  6001.     char *d;
  6002.     char *s;
  6003.  
  6004.     DESCRIPTION
  6005.     strcpy copies the NULL terminated string pointed to by s to the
  6006.     buffer d.  The NULL is copied.    The first argument is returned (a
  6007.     pointer to the buffer d).
  6008.  
  6009.     INPUTS
  6010.     char *d;        pointer to beginning of destination buffer
  6011.  
  6012.     char *s;        pointer to beginning of source string
  6013.  
  6014.     RESULTS
  6015.     char *ptr;        same as the destination buffer pointer (d).
  6016.  
  6017.     SEE ALSO
  6018.     stpcpy
  6019.  
  6020.     EXAMPLE
  6021.     #include <stdio.h>
  6022.     #include <string.h>
  6023.     #include <assert.h>
  6024.     /*
  6025.      *  Note that the stpcpy() example accomplishes the same
  6026.      *  thing and is more efficient, but also requires the
  6027.      *  use of a temporary pointer as well as cluttering the
  6028.      *  source and being non-standard.
  6029.      *  strcpy()/strcat() is more portable, though less
  6030.      *  efficient.
  6031.      */
  6032.      main()
  6033.     {
  6034.        char *buf1 = "saber";
  6035.        char *buf2 = "tooth";
  6036.        char dest[32];
  6037.  
  6038.        strcpy(dest, buf1);
  6039.        strcat(dest, buf2);
  6040.        puts(dest);       /* sabertooth */
  6041.        return(0);
  6042.     }
  6043.  
  6044. dice/strcspn                                                    dice/strcspn
  6045.  
  6046.     FUNCTION
  6047.     scan a string until a character is found that matches any character
  6048.     in a second string (ANSI)
  6049.  
  6050.     SYNTAX
  6051.     #include <string.h>
  6052.     int len = strcspn(s, toks)
  6053.     const char *s;
  6054.     const char *toks;
  6055.  
  6056.     DESCRIPTION
  6057.     With strcspn, the string s is scanned until a character is found that
  6058.     matches any character in the string toks.  The number of characters
  6059.     skipped is returned.  If no character in s matches any character in
  6060.      toks then the length of the string s is returned.
  6061.     strcspn is normally used to search for whitespace within a string.
  6062.     Note that in many cases strpbrk is more useful than strcspn.
  6063.  
  6064.     INPUTS
  6065.     char *s;        pointer to string to scan
  6066.  
  6067.     char *toks;        pointer to string containing characters to
  6068.                 compare against
  6069.  
  6070.     RESULTS
  6071.     int len;        # of characters skipped in s before a match was
  6072.                 found.
  6073.  
  6074.     SEE ALSO
  6075.     strpbrk, strspn
  6076.  
  6077.     EXAMPLE
  6078.     #include <stdio.h>
  6079.     #include <string.h>
  6080.     #include <assert.h>
  6081.     main()
  6082.     {
  6083.        int len;
  6084.        len = strcspn("hello this is a test", " \tabcd");
  6085.        assert(len == 5);  /*  stopped at the first space  */
  6086.        len = strcspn("hello this is a test", " abl");
  6087.        assert(len == 2);  /*  stopped at the first 'l'    */
  6088.        len = strcspn("hello", "abcd");
  6089.        assert(len == 5);  /*  stopped at end of string 1  */
  6090.        return(0);
  6091.     }
  6092.  
  6093. dice/strdup                                                      dice/strdup
  6094.  
  6095.     FUNCTION
  6096.     duplicate a string using malloc (DICE)
  6097.  
  6098.     SYNTAX
  6099.     #include <string.h>
  6100.     char *s2 = strdup(s1);
  6101.     const char *s1;
  6102.  
  6103.     DESCRIPTION
  6104.     strdup allocates enough space to hold s1 including the terminating
  6105.     NULL and then copies s1 into this space, returning a pointer to the
  6106.     new string.  NULL is returned if space could not be allocated due to
  6107.     low memory conditions.    Note free may be used to free the returned
  6108.     string.  The amount allocated is (strlen(s1) + 1).
  6109.  
  6110.     || NOTE: This is a non-standard function and may not exist in other C
  6111.     || environments.
  6112.  
  6113.     INPUTS
  6114.     char *s1;        pointer to the string to duplicate
  6115.  
  6116.     RESULTS
  6117.     char *s2;        pointer to malloc'd space containing a duplicate
  6118.                 of the string s1 or NULL if space could not be
  6119.                 malloc'd.
  6120.  
  6121.     SEE ALSO
  6122.     malloc, free, strcpy, strlen
  6123.  
  6124.     EXAMPLE
  6125.     #include <stdio.h>
  6126.     #include <string.h>
  6127.     #include <assert.h>
  6128.     /*
  6129.      *  Modifying string constants (quoted strings) may
  6130.      *  not be entirely portable.  Normally one does not
  6131.      *  use strdup() to accomplish the following function
  6132.      *  but instead declares a char array statically
  6133.      *  initialized with the string, such as:
  6134.      *  char FuBar[] = { "This is a test" };
  6135.      *  Which can be modified in a portable fashion without
  6136.      *  having to duplicate the string.
  6137.      */
  6138.     main()
  6139.     {
  6140.        char *s1 = "this is a test";
  6141.        char *s2;
  6142.        s2 = strdup(s1);
  6143.        s2[0] = 'x';
  6144.        puts(s2);   /*  this is a test  */
  6145.        free(s2);
  6146.        s2 = strdup(s1);
  6147.        s2[1] = '0';
  6148.        puts(s2);   /*  this is a test  */
  6149.        free(s2);
  6150.        return(0);
  6151.     }
  6152.  
  6153. dice/strerror                                                  dice/strerror
  6154.  
  6155.     FUNCTION
  6156.     return error string associated with error code (ANSI)
  6157.  
  6158.     SYNTAX
  6159.     #include <string.h>
  6160.     const char *str = strerror(error); int error;
  6161.  
  6162.     DESCRIPTION
  6163.     strerror returns a read-only string associated with the specified
  6164.     error, usually taken from errno after some c.lib call fails.  An
  6165.     unknown error will result in the string "unknown error."
  6166.  
  6167.     INPUTS
  6168.     int error;        error code
  6169.  
  6170.     RESULTS
  6171.     char *str;        error string
  6172.  
  6173.     SEE ALSO
  6174.     perror
  6175.  
  6176.     EXAMPLE
  6177.     #include <stdio.h>
  6178.     #include <string.h>
  6179.     #include <errno.h>
  6180.     #include <assert.h>
  6181.     main()
  6182.     {
  6183.        FILE *fi;
  6184.        fi = fopen("ThisFileDoesNotExist", "r");
  6185.        assert(fi == NULL);
  6186.        puts(strerror(errno));
  6187.        return(0);
  6188.     }
  6189.  
  6190. dice/strftime                                                  dice/strftime
  6191.  
  6192.     FUNCTION
  6193.     convert broken down time into a string according to a format (ANSI)
  6194.  
  6195.     SYNTAX
  6196.     #include <time.h>
  6197.     size_t len = strftime(buf, max, fmt, tm)
  6198.     char *buf; size_t max;
  6199.     const char *fmt;
  6200.     const struct tm *tm;
  6201.  
  6202.     DESCRIPTION
  6203.     strftime formats a broken down time into a buffer according to a
  6204.     format string fmt.  The fmt string looks like a the format for a
  6205.     printf except with different control definitions:
  6206.  
  6207.     %%  A literal '%' character.
  6208.  
  6209.     %a  The locale's abbreviated name for the day of week.
  6210.  
  6211.     %A  The locale's full name for the  day of week.
  6212.  
  6213.     %b  The locale's abbr. name for the month.
  6214.  
  6215.     %B  The locale's full name for the month.
  6216.  
  6217.     %c  The locale's default representation for the date & time (ctime).
  6218.  
  6219.     %d  The day of the month 01-31.
  6220.  
  6221.     %H  The hour 00-23 (24 hour time).
  6222.  
  6223.     %I  The hour 01-12 (12 hour time).
  6224.  
  6225.     %j  The day in the year 001-366.
  6226.  
  6227.     %m  The month 01-12.
  6228.  
  6229.     %M  The minute 00-59.
  6230.  
  6231.     %p  Indication of morning or afternoon.  In the US: "AM" or "PM".
  6232.  
  6233.     %S  The second 00-59.
  6234.  
  6235.     %U  The week of the year 00-53, Sunday is the first day in a week.
  6236.  
  6237.     %w  The day of the week 0-6, Sunday=0 (standard).
  6238.  
  6239.     %W  The day of the week 0-6, monday=0.
  6240.  
  6241.     %x  The locale's default representation for the date only.
  6242.  
  6243.     %X  The locale's default representation for the time only.
  6244.  
  6245.     %y  The year mod 100 (00-99).
  6246.  
  6247.     %Y  The full year (e.g. 1990).
  6248.  
  6249.     %Z  The name of the locale's time zone, nothing if unknown.
  6250.  
  6251.         ## WARNING: There must be at least max + 1 bytes in buf or you
  6252.         ## might unexpectedly overwrite memory.
  6253.  
  6254.     INPUTS
  6255.     char *buf;        buffer to write formatted string into
  6256.  
  6257.     size_t max;        maximum size of buffer - 1
  6258.  
  6259.     char *fmt;        format string
  6260.  
  6261.     struct tm *tm;        broken down time
  6262.  
  6263.     RESULTS
  6264.     size_t len;        length of formatted string in buffer or 0 if the
  6265.                 maximum was exceeded.
  6266.  
  6267.     SEE ALSO
  6268.     time, localtime, asctime, ctime, clock
  6269.  
  6270.     EXAMPLE
  6271.     #include <stdio.h>
  6272.     #include <time.h>
  6273.  
  6274.     main()
  6275.     {
  6276.        time_t t = time(NULL);
  6277.        struct tm *tp = localtime(&t);
  6278.        char buf[256];
  6279.        strftime(buf, sizeof(buf) - 1,
  6280.             "Now is %A %d %B %Y %X",  tp);
  6281.        puts(buf);
  6282.        return(0);
  6283.     }
  6284.  
  6285. dice/stricmp                                                    dice/stricmp
  6286.  
  6287.     FUNCTION
  6288.     compare two strings, case insensitive (UNIX)
  6289.  
  6290.     SYNTAX
  6291.     #include <string.h>
  6292.     int r = stricmp(s1, s2);
  6293.     const char *s1;
  6294.     const char *s2;
  6295.  
  6296.     DESCRIPTION
  6297.     stricmp compares two strings, returning: -1 if    s1 < s2, 0 if  s1 ==
  6298.     s2, or 1 if  s1 > s2. differs from strcmp in that case is ignored for
  6299.     alphabetic characters, i.e. a == A.
  6300.  
  6301.     || NOTE: NOTE= stricmp converts the chars in the string to unsigned
  6302.     || quantities when comparing them.  However, for portability you
  6303.     || should not stricmp strings containing negative characters (bit 7
  6304.     || set) for anything other than checking the result against 0.    Use
  6305.     || the memcmp routine instead.
  6306.  
  6307.     INPUTS
  6308.     char *s1;        pointer to first string
  6309.  
  6310.     char *s2;        pointer to second string
  6311.  
  6312.     RESULTS
  6313.     int r;            -1, 0, or 1.
  6314.  
  6315.     SEE ALSO
  6316.     strcmp, strncmp
  6317.  
  6318.     EXAMPLE
  6319.     #include <stdio.h>
  6320.     #include <string.h>
  6321.     #include <assert.h>
  6322.     main()
  6323.     {
  6324.        char *s1 = "abCa";
  6325.        char *s2 = "aBcD";
  6326.        char *s3 = "aBCX";
  6327.        char *s4 = "ABCdx";
  6328.        char *s5 = "Abc";
  6329.        char *x2 = "ABCD";
  6330.        int r;
  6331.        r = stricmp(s2, x2); /* string s2 same as x2 */
  6332.        assert(r == 0);
  6333.        r = stricmp(s2, s1); /* string s2 larger than s1 */
  6334.        assert(r > 0);
  6335.        r = stricmp(s2, s3);
  6336.        assert(r < 0);
  6337.        r = stricmp(s2, s4);
  6338.        assert(r < 0);
  6339.        r = stricmp(s2, s5);
  6340.        assert(r > 0);
  6341.        return(0);
  6342.     }
  6343.  
  6344. dice/strins                                                      dice/strins
  6345.  
  6346.     FUNCTION
  6347.     insert one string within another (DICE)
  6348.  
  6349.     SYNTAX
  6350.     #include <string.h>
  6351.     void strins(d, s);
  6352.     char *d;
  6353.     const char *s;
  6354.  
  6355.     DESCRIPTION
  6356.     strins inserts string s into d by shifting the string in d over
  6357.     strlen(s) spaces and then copying s into the newly made hold (except
  6358.     for the NULL, of course).  This result is s inserted into d.
  6359.  
  6360.     || NOTE: There must be enough room in d to insert s; if d is an array
  6361.     || of 32 chars and contains a string of 8 chars you can insert
  6362.     || another string of, say, 10 chars, but not of 30 chars.  strins is
  6363.     || not an ANSI standard function.
  6364.  
  6365.     INPUTS
  6366.     char *d;        destination to insert in front of
  6367.  
  6368.     char *s;        source string to insert
  6369.  
  6370.     SEE ALSO
  6371.     strcpy, strcat, strlen
  6372.  
  6373.     EXAMPLE
  6374.     #include <stdio.h>
  6375.     #include <string.h>
  6376.     main()
  6377.     {
  6378.        char buf[32];
  6379.        strcpy(buf, "This is a test");
  6380.        strins(buf + 5, "<gak!> ");
  6381.        puts(buf);
  6382.        /*  This <gak!> is a test  */
  6383.        return(0);
  6384.     }
  6385.  
  6386. dice/strlen                                                      dice/strlen
  6387.  
  6388.     FUNCTION
  6389.     returns length of a string (ANSI)
  6390.  
  6391.     SYNTAX
  6392.     #include <string.h>
  6393.     int len = strlen(s);
  6394.     const char *s;
  6395.  
  6396.     DESCRIPTION
  6397.     When this function is used, the length of the requested string is
  6398.     returned. The string is scanned until a NULL terminator is found and
  6399.     the number of characters (not including the NULL) is returned.
  6400.  
  6401.     :: Beginner's Note: The length returned by strlen does not include
  6402.     :: the NULL.  It is common error to forget this fact and reserve one
  6403.     :: too few bytes of storage!
  6404.  
  6405.     INPUTS
  6406.     char *s;        string to obtain length of
  6407.  
  6408.     RESULTS
  6409.     int len;        length of string
  6410.  
  6411.     SEE ALSO
  6412.     strcpy, strcat
  6413.  
  6414.     EXAMPLE
  6415.     #include <stdio.h>
  6416.     #include <string.h>
  6417.     main(int ac, char **av)
  6418.     {
  6419.         if( ac  1 )
  6420.         {
  6421.         printf("%s is %d byte(s) long\n",
  6422.                av[1], strlen( av[1] ) );
  6423.         } else
  6424.         printf("Gimme, gimme, gimme!!\n");
  6425.     }
  6426.  
  6427. dice/strncat                                                    dice/strncat
  6428.  
  6429.     FUNCTION
  6430.     concatenate a string to an existing string up to a maximum number of
  6431.     characters (ANSI)
  6432.  
  6433.     SYNTAX
  6434.     #include <string.h>
  6435.     char *d = strncat(d, s, n);
  6436.     char *d;
  6437.     const char *s;
  6438.     int n;
  6439.  
  6440.     DESCRIPTION
  6441.     strncat scans the destination buffer for the NULL terminator and then
  6442.     appends the source string to the destination buffer (removing the
  6443.     NULL terminator and placing one at the end after the concatenation).
  6444.     However, only up to n characters is concatenated including the NULL.
  6445.     If the source string is exactly n characters long no NULL will be
  6446.     appended.  If the source string is longer than n characters then only
  6447.     the first n characters of the source string will be appended (and no
  6448.     NULL will be).    A pointer to the beginning of the destination buffer
  6449.     is returned.
  6450.  
  6451.     INPUTS
  6452.     char *d;        pointer to destination buffer which already
  6453.                 contains a string (which could be just a \0).
  6454.  
  6455.     char *s;        pointer to the NULL terminated source string
  6456.  
  6457.     int n;            maximum number of characters to concatenate
  6458.  
  6459.     RESULTS
  6460.     char *d;        same as the first argument, a pointer to the
  6461.                 destination buffer.
  6462.  
  6463.     SEE ALSO
  6464.     strncpy, strcpy, strcat
  6465.  
  6466.     EXAMPLE
  6467.     #include <stdio.h>
  6468.     #include <string.h>
  6469.     main()
  6470.     {
  6471.        char d[32];           char *p;
  6472.        char *s1 = "grid";  char *s2 = "lock";
  6473.  
  6474.        strcpy( d, s1 );
  6475.        p = strncat( d, s2, 10 );
  6476.        puts( d );  /* gridlock */
  6477.  
  6478.        strcpy( d,I s1 );
  6479.        p = strncat( d, s2, 3 );
  6480.        puts( d );  /* gridloc  */
  6481.  
  6482.        return(0);
  6483.     }
  6484.  
  6485. dice/strncmp                                                    dice/strncmp
  6486.  
  6487.     FUNCTION
  6488.     compare two strings up to a maximum number of characters (ANSI)
  6489.  
  6490.     SYNTAX
  6491.     #include <string.h>
  6492.     int r = strncmp(s1, s2, n);
  6493.     const char *s1;
  6494.     const char *s2;
  6495.     int n;
  6496.  
  6497.     DESCRIPTION
  6498.     strncmp compares two strings, returning:  -1 if s1 < s2,  0 if s1 ==
  6499.     s2, or 1 if  s1 > s2.    strncmp works like strcmp but only up to n
  6500.     characters will be compared.  If all characters compare when n is
  6501.     reached 0 is returned indicating that the strings matched. Fewer
  6502.     characters might be compared if either string terminates (w/ a NULL)
  6503.     before the maximum is reached or a compare fails (scan is stopped and
  6504.     -1 or 1 is returned immediately).
  6505.  
  6506.     || NOTE: strncmp converts the chars in the string to unsigned
  6507.     || quantities when comparing them.  However, for portability you
  6508.     || should not strncmp strings containing negative characters (bit 7
  6509.     || set) for anything other than checking the result against 0.    Use
  6510.     || the memcmp routine instead.
  6511.  
  6512.     INPUTS
  6513.     char *s1;        pointer to first string
  6514.  
  6515.     char * s2;        pointer to second string
  6516.  
  6517.     int n;            maximum number of characters to compare
  6518.  
  6519.     RESULTS
  6520.     int r;            -1, 0, or 1.
  6521.  
  6522.     SEE ALSO
  6523.     stricmp
  6524.  
  6525.     EXAMPLE
  6526.     #include <stdio.h>
  6527.     #include <string.h>
  6528.     #include <assert.h>
  6529.     main()
  6530.     {
  6531.        char *s1 = "abcaq";
  6532.        char *s2 = "abcdr";
  6533.        char  *s3 = "abcxs";
  6534.        char *s4 = "abcdxx";
  6535.        char *s5 = "abc";
  6536.        char *x2 = "abcdt";
  6537.        int r;   r = strncmp(s2, x2, 4);
  6538.        assert(r == 0);
  6539.        r = strncmp(s2, s1, 4);
  6540.        assert(r > 0);
  6541.        r = strncmp(s2, s3, 4);
  6542.        assert(r < 0);
  6543.        r = strncmp(s2, s4, 8);
  6544.        assert(r < 0);
  6545.        r = strncmp(s2, s5, 4);
  6546.        assert(r > 0);
  6547.        return(0);
  6548.     }
  6549.  
  6550. dice/strncpy                                                    dice/strncpy
  6551.  
  6552.     FUNCTION
  6553.     copy a string returning a pointer to the beginning of the destination
  6554.     until NULL or the specified number of characters is reached (ANSI)
  6555.  
  6556.     SYNTAX
  6557.     #include <string.h>
  6558.     char *ptr = strncpy(d, s, n);
  6559.     char *d;
  6560.     const char *s;
  6561.     int n;
  6562.  
  6563.     DESCRIPTION
  6564.     strncpy copies the NULL terminated string pointed to by s to the
  6565.     buffer d. The NULL is normally copied.    The first argument is
  6566.     returned (a pointer to the buffer d). The copy will also be
  6567.     terminated if the specified maximum is reached, in which case the
  6568.     NULL is NOT copied (which makes the function useless - but hey, it
  6569.     does make it standard).
  6570.  
  6571.     INPUTS
  6572.     char *d;        pointer to beginning of destination buffer
  6573.  
  6574.     char *s;        pointer to beginning of source string
  6575.  
  6576.     int len;        maximum number of characters to copy
  6577.  
  6578.     RESULTS
  6579.     char *ptr;        same as the destination buffer pointer (d).
  6580.  
  6581.     SEE ALSO
  6582.     stpcpy, strcpy
  6583.  
  6584.     EXAMPLE
  6585.     #include <stdio.h>
  6586.     #include <string.h>
  6587.     #include <assert.h>
  6588.     main()
  6589.     {
  6590.        char *buf1 = "hello";
  6591.        char *buf2 = "123";
  6592.        char dest[32];
  6593.  
  6594.        strncpy(dest, buf1, 8);
  6595.        strcat(dest, buf2);
  6596.        puts(dest);           /* hello123 */
  6597.  
  6598.        dest[2] = 23;
  6599.        strncpy(dest, buf1, 2);
  6600.        assert(dest[2] == 23);  /* copy just two */
  6601.        dest[2] = 0;  /* we have to add the NULL */
  6602.        puts(dest);           /* he */
  6603.  
  6604.        strcat(dest, buf2);       /* he123   */
  6605.        puts(dest);
  6606.        return(0);
  6607.     }
  6608.  
  6609. dice/strnicmp                                                  dice/strnicmp
  6610.  
  6611.     FUNCTION
  6612.     compare two strings up to a maximum number of characters, case
  6613.     insensitive (UNIX)
  6614.  
  6615.     SYNTAX
  6616.     #include <string.h>
  6617.     int r = strnicmp(s1, s2, n);
  6618.     const char *s1;
  6619.     const char *s2;
  6620.     int n;
  6621.  
  6622.     DESCRIPTION
  6623.     strnicmp compares two strings, returning:  -1,    s1 < s2;  0, s1 ==
  6624.     s2;   1,  s1 > s2.  strnicmp differs from strcmp in that case is
  6625.     ignored for alphabetic characters (i.e., a == A) and only up to n
  6626.     characters are compared. Refer to stricmp and strncmp for other
  6627.     examples.
  6628.  
  6629.     || NOTE: strnicmp converts the chars in the string to unsigned
  6630.     || quantities when comparing them.  However, for portability you
  6631.     || should not strnicmp strings containing negative characters (bit 7
  6632.     || set) for anything other than checking the result against 0.    Use
  6633.     || the memcmp routine instead.
  6634.  
  6635.     INPUTS
  6636.     char *s1;        pointer to first string
  6637.  
  6638.     char *s2;        pointer to second string
  6639.  
  6640.     int n;            maximum # of characters to compare
  6641.  
  6642.     RESULTS
  6643.     int r;            -1, 0, or 1.
  6644.  
  6645.     SEE ALSO
  6646.     strcmp, strncmp, stricmp
  6647.  
  6648.     EXAMPLE
  6649.     #include <stdio.h>
  6650.     #include <string.h>
  6651.     #include <assert.h>
  6652.     main()
  6653.     {
  6654.        char *s1 = "aBcAQ";
  6655.        char *s2 = "abCDR";
  6656.        char *s3 = "ABcXs";
  6657.        char *s4 = "aBCDxX";
  6658.        char *s5 = "aBC";
  6659.        char *x2 = "AbCDt";
  6660.        int r;
  6661.        r = strnicmp(s2, x2, 4);
  6662.        assert(r == 0);
  6663.        r = strnicmp(s2, s1, 4);
  6664.        assert(r > 0);
  6665.        r = strnicmp(s2, s3, 4);
  6666.        assert(r < 0);
  6667.        r = strnicmp(s2, s4, 8);
  6668.        assert(r < 0);
  6669.        r = strnicmp(s2, s5, 4);
  6670.        assert(r > 0);
  6671.        return(0);
  6672.     }
  6673.  
  6674. dice/strpbrk                                                    dice/strpbrk
  6675.  
  6676.     FUNCTION
  6677.     search for specific characters in a string (ANSI)
  6678.  
  6679.     SYNTAX
  6680.     #include <string.h>
  6681.     char *ptr = strpbrk(s, toks)
  6682.     const char *s;
  6683.     char *toks;
  6684.  
  6685.     DESCRIPTION
  6686.     strpbrk searches the string s for any character in the string toks.
  6687.     For example, when searching for whitespace in s, toks would contain
  6688.     the space and tab character.  If no character in s matches any
  6689.     character in toks then NULL is returned.
  6690.  
  6691.     INPUTS
  6692.     char *s;        pointer to string to scan
  6693.  
  6694.     char *toks;        pointer to string containing tokens to scan for
  6695.  
  6696.     RESULTS
  6697.     char *ptr;        pointer to point in s where the character matches
  6698.                 any character in toks, or NULL if s was
  6699.                 exhausted.
  6700.  
  6701.     SEE ALSO
  6702.     strtok
  6703.  
  6704.     EXAMPLE
  6705.     #include <stdio.h>
  6706.     #include <string.h>
  6707.     #include <assert.h>
  6708.     main()
  6709.     {
  6710.        char *s = "This  \tis a test";
  6711.        char *ptr;
  6712.        ptr = strpbrk(s, " \t");
  6713.        assert(ptr == s + 4);
  6714.        ptr = strpbrk(ptr + 1, " \t");
  6715.        assert(ptr == s + 5);
  6716.        ptr = strpbrk(ptr + 1, " \t");
  6717.        assert(ptr == s + 6);
  6718.        ptr = strpbrk(ptr + 1, " \t");
  6719.        assert(ptr == s + 9);
  6720.        ptr = strpbrk(ptr + 1, "xyz"); /* doesn't find 'm */
  6721.        assert(ptr == NULL);
  6722.        return(0);
  6723.     }
  6724.  
  6725. dice/strrchr                                                    dice/strrchr
  6726.  
  6727.     FUNCTION
  6728.     search for a character in a string, scan backwards (ANSI)
  6729.  
  6730.     SYNTAX
  6731.     #include <string.h>
  6732.     char *ptr = strrchr(s, c)
  6733.     const char *s;
  6734.     int c;
  6735.  
  6736.     DESCRIPTION
  6737.     strrchr searches for the character c within the string pointed to by
  6738.     s. The terminating NULL at the end of s is included in the search.
  6739.     The string is searched backwards. A pointer to the last occurrence of
  6740.     c in s is returned or NULL if c could not be found.  C is converted
  6741.     to an 8 bit quantity by strrchr.
  6742.  
  6743.     || NOTE: The ANSI spec does not say anything about including the NULL
  6744.     || character in the search for strrchr and some implementation may
  6745.     || thus not implement this properly.
  6746.  
  6747.     INPUTS
  6748.     char *s;        pointer to the string to search
  6749.  
  6750.     int c;            character to search for
  6751.  
  6752.     RESULTS
  6753.     char *ptr;        pointer to the last occurrence of character c in
  6754.                 s or NULL if c could not be found in s.
  6755.  
  6756.     SEE ALSO
  6757.     strchr
  6758.  
  6759.     EXAMPLE
  6760.     #include <stdio.h>
  6761.     #include <string.h>
  6762.     #include <assert.h>
  6763.     main()
  6764.     {
  6765.        char *s = "this is a test";
  6766.        char *ptr;
  6767.        ptr = strrchr(s, 'i');
  6768.        assert(ptr == s + 5);
  6769.        puts(ptr);       /*  "is a test"  */
  6770.        ptr = strrchr(s, 'x');
  6771.        assert(ptr == NULL);
  6772.        return(0);
  6773.     }
  6774.  
  6775. dice/strspn                                                      dice/strspn
  6776.  
  6777.     FUNCTION
  6778.     scan a string until a character is found that does not match some
  6779.     character in a second string (ANSI)
  6780.  
  6781.     SYNTAX
  6782.     #include <string.h>
  6783.     int len = strspn(s, toks)
  6784.     const char *s;
  6785.     const char *toks;
  6786.  
  6787.     DESCRIPTION
  6788.     The string s is scanned until a character is found that does not
  6789.     match any character in the string toks.  The number of characters
  6790.     skipped is returned.  If every character in s matches some character
  6791.     in toks then the length of the string s is returned.
  6792.  
  6793.     strspn is normally used to skip whitespace within a string.
  6794.  
  6795.     INPUTS
  6796.     char *s;        pointer to string to scan
  6797.  
  6798.     char *toks;        pointer to string containing characters to
  6799.                 compare against
  6800.  
  6801.     RESULTS
  6802.     int len;        # of characters skipped in s before a match could
  6803.                 not be found
  6804.  
  6805.     SEE ALSO
  6806.     strpbrk, strcspn
  6807.  
  6808.     EXAMPLE
  6809.     #include <stdio.h>
  6810.     #include <string.h>
  6811.     #include <assert.h>
  6812.  
  6813.     main()
  6814.     {
  6815.        int len;
  6816.        len = strspn("  \t \t\t abcde test", " \t ");
  6817.        assert(len == 7);  /*  stopped at the 'a'  */
  6818.        len = strspn("abcd efg", " ");
  6819.        assert(len == 0);  /*  stopped at the 'a'  */
  6820.        len = strspn("   \t\t ", " \t");
  6821.        assert(len == 6);  /*  all match, len=strlen(str); */
  6822.        return(0);
  6823.     }
  6824.  
  6825. dice/strstr                                                      dice/strstr
  6826.  
  6827.     FUNCTION
  6828.     find sub-string within another string (ANSI)
  6829.  
  6830.     SYNTAX
  6831.     #include <string.h>
  6832.     char *ptr = strstr(s, sub);
  6833.     const char *s;
  6834.     const char *sub;
  6835.  
  6836.     DESCRIPTION
  6837.     The string s is scanned until the sub-string sub matches the string
  6838.     beginning at the current scan point, and a pointer to the sub-string
  6839.     within s is returned.  If the sub-string could not be found NULL is
  6840.     returned.
  6841.  
  6842.     INPUTS
  6843.     char *s;        pointer to string to scan
  6844.  
  6845.     char *toks;        pointer to string containing characters to
  6846.                 compare against
  6847.  
  6848.     RESULTS
  6849.     char *ptr;        point in s where sub string was found or NULL if
  6850.                 sub string could not be found.
  6851.  
  6852.     SEE ALSO
  6853.     strpbrk, strcspn
  6854.  
  6855.     EXAMPLE
  6856.     #include <stdio.h>
  6857.     #include <string.h>
  6858.     #include <assert.h>
  6859.  
  6860.     main()
  6861.     {
  6862.        char *s = "abcdefghijklmnopqrstuvwxyz";
  6863.        char *ptr;
  6864.        ptr = strstr(s, "klm");
  6865.        assert(ptr == s + 10);
  6866.        puts(ptr);  /*  klmnopqrstuvwxyz    */
  6867.        return(0);
  6868.     }
  6869.  
  6870. dice/strtod                                                      dice/strtod
  6871.  
  6872.     FUNCTION
  6873.     convert string to fp double (ANSI)
  6874.  
  6875.     LIBRARY
  6876.     m.lib
  6877.  
  6878.     SYNTAX
  6879.     #include <string.h>
  6880.     double d = strtod(s, &tp);
  6881.     const char *s;
  6882.     char *tp;
  6883.  
  6884.     DESCRIPTION
  6885.     strtod converts a string to a floating point double.  Initial
  6886.     whitespace is skipped.    The format of the fp number in the string is
  6887.     then:
  6888.  
  6889.     {+/-/<nothing>}ddddd[.ddddd][E{+/-/<nothing>}dddd]
  6890.  
  6891.     Example fp strings: " +1.234E-3", "-1234", "6.5676E4", "214.2345"
  6892.  
  6893.     INPUTS
  6894.     char *s;        pointer to string containing fp number
  6895.  
  6896.     char **tp;        pointer to pointer, the pointer is modified to
  6897.                 point to the end of the scanned fp number.
  6898.  
  6899.     RESULTS
  6900.     double d;        resulting double
  6901.  
  6902.     EXAMPLE
  6903.     /*
  6904.      *  compile -lm to include math library
  6905.      */
  6906.     #include <stdio.h>
  6907.     #include <string.h>
  6908.  
  6909.     main()
  6910.     {
  6911.        double d;
  6912.        char *tp;
  6913.        d = strtod("1.2134 3.45E2", &tp);
  6914.        printf("1.2134 = %lf\n", d);    /*  1.213400    */
  6915.        d = strtod(tp, &tp);
  6916.        printf("3.45E2 = %lf\n", d);    /*  345.000000  */
  6917.        return(0);
  6918.     }
  6919.  
  6920. dice/strtok                                                      dice/strtok
  6921.  
  6922.     FUNCTION
  6923.     break up a string into arguments (ANSI)
  6924.  
  6925.     SYNTAX
  6926.     #include <string.h>
  6927.     char *arg = strtok(s, toks)
  6928.     char *s;
  6929.     const char *toks;
  6930.  
  6931.     DESCRIPTION
  6932.     strtok breaks up a string into arguments.  It determines the break
  6933.     point from the toks string which contains a set of whitespace
  6934.     characters (usually \t to mean space and tab).    The first call to
  6935.     strtok should specify the string s and toks. Initial whitespace is
  6936.     skipped and the string is then scanned until the end of the first
  6937.     argument is found.  The string is then modified: a NULL is placed at
  6938.     the end of the first argument and a pointer to the beginning of the
  6939.     first argument is returned.
  6940.  
  6941.     Further calls to strtok should pass a NULL for the string s, which
  6942.     tells strtok to continue scanning the original string (whose pointer
  6943.     was stored in a static char * within strtok). strtok returns
  6944.     arguments until the string is exhausted, in which case it returns
  6945.     NULL.  The initial call to strtok can return NULL if the passed
  6946.     string s contains nothing but whitespace (as specified by toks).  You
  6947.     can change the toks string at any time (i.e. pass a different toks
  6948.     string to strtok).
  6949.  
  6950.     ## WARNING: strtok modifies the source string and returns pointers
  6951.     ## into it.
  6952.  
  6953.     INPUTS
  6954.     char *s;        pointer to string to parse
  6955.  
  6956.     char *toks;        pointer to string containing whitespace
  6957.                 characters (argument delimiters)
  6958.  
  6959.     RESULTS
  6960.     char *arg;        pointer into s to next argument that is NULL
  6961.                 terminated (s is modified).
  6962.  
  6963.     SEE ALSO
  6964.     strspn, strcspn
  6965.  
  6966.     EXAMPLE
  6967.     #include <stdio.h>
  6968.     #include <string.h>
  6969.  
  6970.     main()
  6971.     {
  6972.        char buf[32];
  6973.        char *arg;
  6974.        const char *ws = " \t";
  6975.        /*
  6976.         *  'This' 'is' 'a' 'test!'
  6977.         */
  6978.        strcpy(buf, "  This  is \t \t a test!");
  6979.        for (arg = strtok(buf, ws);
  6980.         arg; arg = strtok(NULL, ws))
  6981.        {
  6982.           printf("arg = '%s'\n", arg);
  6983.        }
  6984.        return(0);
  6985.     }
  6986.  
  6987. dice/strtol,strtoul                                      dice/strtol,strtoul
  6988.  
  6989.     FUNCTION
  6990.     convert string to integer (ANSI)
  6991.  
  6992.     SYNTAX
  6993.     #include <string.h>
  6994.     long v = strtol(str, &tail, base);
  6995.     unsigned long v = strtoul(str, &tail, base);
  6996.     const char *str;
  6997.     char *tail;
  6998.     int base;
  6999.  
  7000.     DESCRIPTION
  7001.     strtol converts a string into an integer using the specified base
  7002.     0-36.  If a non-zero base is specified conversion is done using that
  7003.     base (hex numbers may still be preceded by '0x' or '0X').  If 0 is
  7004.     specified for the base then the base is determined from the first one
  7005.     or two characters of the number portion of the string:
  7006.  
  7007.         0     octal
  7008.         1-9     decimal
  7009.         0x     hex (0x or 0X)
  7010.  
  7011.     For bases larger than 10, alphabetic characters are used to represent
  7012.     digits. Either lower case or upper case letters may be used.  strtol
  7013.     stores a pointer to the remainder of the string after the conversion.
  7014.     strtol ignores any whitespace at the beginning of the string and also
  7015.     handles an optional negative sign (which may precede the numerical
  7016.      portion of the string).
  7017.     If successful strtol returns the converted value as a long, 0 if it
  7018.     was unable to convert anything, and an undefined result if the
  7019.     converted value was out of range.
  7020.  
  7021.     || NOTE: strtol supersedes atoi and atol.
  7022.  
  7023.     INPUTS
  7024.     char *str;        pointer to string to convert
  7025.  
  7026.     char **tail;        *tail modified to point to just after last
  7027.                 character converted
  7028.  
  7029.     int base;        base of conversion or 0 for autoselect
  7030.  
  7031.     RESULTS
  7032.     long v;         converted result, an integer, or 0 if no
  7033.                 conversion could be done.
  7034.  
  7035.     SEE ALSO
  7036.     atoi, atol, strtod
  7037.  
  7038.     EXAMPLE
  7039.     #include <stdio.h>
  7040.     #include <string.h>
  7041.  
  7042.     main(int ac, char**av)
  7043.     {
  7044.        long v;
  7045.        char *tail;
  7046.        if (ac != 3)
  7047.        {
  7048.           puts("testprg <string> <base>");
  7049.           puts("testprg 0123abc 0");
  7050.           puts("testprg 0x1000 0");
  7051.           puts("testprg 0123abc 16");
  7052.           exit(1);
  7053.        }
  7054.        v = strtol(av[1], &tail, atoi(av[2]));
  7055.        printf("v = %d, tail = %s\n", v, tail);
  7056.        return(0);
  7057.     }
  7058.  
  7059. dice/system                                                      dice/system
  7060.  
  7061.     FUNCTION
  7062.     call system shell with a command line (ANSI)
  7063.  
  7064.     SYNTAX
  7065.     #include <stdio.h>
  7066.     #include <stdlib.h>
  7067.     int r = system(buf);
  7068.     const char *buf;
  7069.  
  7070.     DESCRIPTION
  7071.     system calls the system shell with the specified command line,
  7072.     returning the exit code of the command or -1 if it was unable to run
  7073.     the command.
  7074.  
  7075.     || NOTE: FOR PROGRAMS COMPILED UNDER 1.3, even if run in 2.0
  7076.     || environment, the system call will not return the exit code from
  7077.     || the command, but return -1 if could not be run, 0 if it could.
  7078.  
  7079.     || NOTE: FOR PROGRAMS COMPILED UNDER 2.0, system will use the 2.0
  7080.     || calls and return a proper exit code when running under 2.0, and
  7081.     || will use execute if running under 1.3.
  7082.  
  7083.     INPUTS
  7084.     char *buf;        command line to run, like a normal AmigaDOS CLI
  7085.                 command line.
  7086.  
  7087.     RESULTS
  7088.     int r;            return code
  7089.  
  7090.     EXAMPLE
  7091.     main()
  7092.     {
  7093.     int r;
  7094.         r = system("c:type s:startup-sequence");
  7095.         printf("System returns %d\n", r);
  7096.     }
  7097.  
  7098. dice/time                                                          dice/time
  7099.  
  7100.     FUNCTION
  7101.     get current time (ANSI)
  7102.  
  7103.     SYNTAX
  7104.     #include <time.h>
  7105.     time_t t = time(NULL);
  7106.     or
  7107.     time(&t);
  7108.     time_t t;
  7109.  
  7110.     DESCRIPTION
  7111.     time returns the current time as a time_t and also copies it into a
  7112.     time_t if the address of said is passed as an argument. You may pass
  7113.     NULL as an argument in which case the time is only returned.
  7114.  
  7115.     The time is returned as seconds since some base date, time_t is
  7116.     normally an unsigned long.
  7117.  
  7118.     INPUTS
  7119.     time_t *t;        pointer to a time_t or NULL
  7120.  
  7121.     RESULTS
  7122.     time_t t;        a time_t
  7123.  
  7124.     SEE ALSO
  7125.     time, localtime, asctime, strftime, ctime, clock
  7126.  
  7127.     EXAMPLE
  7128.     #include <stdio.h>
  7129.     #include <time.h>
  7130.  
  7131.     main()
  7132.     {
  7133.        time_t t = time(NULL);
  7134.        printf("t = %u\n", t);
  7135.        return(0);
  7136.     }
  7137.  
  7138. dice/tmpfile                                                    dice/tmpfile
  7139.  
  7140.     FUNCTION
  7141.     create a temporary file (ANSI)
  7142.  
  7143.     SYNTAX
  7144.     #include <stdio.h>
  7145.     FILE *fp = tmpfile(void);
  7146.  
  7147.     DESCRIPTION
  7148.     tmpfile creates a temporary file and returns a file pointer.  The
  7149.     name of the file is not accessible. The file pointer is available or
  7150.     reading, writing, and seeking (as in rewind, fseek).  The file is
  7151.     initially empty.  This call may be used to create a temporary file
  7152.     that will automatically be removed when you fclose it.    tmpfile
  7153.     returns a FILE pointer or NULL if it was unable to create the file.
  7154.  
  7155.     INPUTS
  7156.     none
  7157.  
  7158.     RESULTS
  7159.     FILE *fp;        opened temporary file
  7160.  
  7161.     SEE ALSO
  7162.     tmpnam, fopen, fclose
  7163.  
  7164.     EXAMPLE
  7165.     #include <stdio.h>
  7166.     #include <assert.h>
  7167.     main()
  7168.     {
  7169.        FILE *fp = tmpfile();
  7170.        char buf[256];
  7171.        assert(fp);
  7172.        fputs("This is a test of\n"
  7173.             "a temporary file\n"
  7174.             "fubar bletch\n", fp);
  7175.        rewind(fp);
  7176.        while (fgets(buf, sizeof(buf), fp))
  7177.        {
  7178.           fputs(buf, stdout);
  7179.        }
  7180.        fclose(fp);      /* close and delete the file     */
  7181.        return(0);
  7182.     }
  7183.  
  7184. dice/tmpnam                                                      dice/tmpnam
  7185.  
  7186.     FUNCTION
  7187.     create a unique, temporary file name (ANSI)
  7188.  
  7189.     SYNTAX
  7190.     #include <stdio.h>
  7191.     char *filename = tmpnam(buf);
  7192.     char *buf;
  7193.  
  7194.     DESCRIPTION
  7195.     tmpnam creates a unique temporary file name meant never to be seen by
  7196.     the user.  The filename tmpnam creates will be no more than L_tmpnam
  7197.     bytes long (L_tmpnam is a macro in <stdio.h>), including the NULL so
  7198.      you can simply declare a buffer: char buf[L_tmpnam];.
  7199.     tmpnam returns the buffer into which it created the temporary file
  7200.     name.  If you specify a non-NULL buffer it returns its first
  7201.     argument.  If you pass NULL to tmpnam then tmpnam will use its down
  7202.     internal static buffer (overwriting any previous name that was stored
  7203.     in said buffer) and return a pointer to that.
  7204.  
  7205.     INPUTS
  7206.     char *buf;        optional buffer of at least L_tmpnam bytes to
  7207.                 hold the temporary file name or NULL to have
  7208.                 tmpnam() use its own internal buffer.
  7209.  
  7210.     RESULTS
  7211.     char *ptr;        pointer to buffer (buf if buf != NULL)
  7212.  
  7213.     SEE ALSO
  7214.     tmpfile
  7215.  
  7216.     EXAMPLE
  7217.     #include <stdio.h>
  7218.     #include <assert.h>
  7219.     main()
  7220.     {
  7221.        char buf[L_tmpnam];      char *ptr;
  7222.        ptr = tmpnam(NULL);      puts(ptr);
  7223.        assert(tmpnam(buf) == buf);
  7224.        /*  returns argument */
  7225.        puts(buf);      /*  haven't overwritten it yet */
  7226.        printf("%s (same as first)\n", ptr);
  7227.        assert(tmpnam(NULL) == ptr);
  7228.        /*  that will overwrite it! */
  7229.        puts(ptr);
  7230.        return(0);
  7231.     }
  7232.  
  7233. dice/tolower,toupper                                    dice/tolower,toupper
  7234.  
  7235.     FUNCTION
  7236.     convert a character into lower or upper case (ANSI)
  7237.  
  7238.     SYNTAX
  7239.     #include <ctype.h>
  7240.     int lc = tolower(c);
  7241.     int uc = toupper(c);
  7242.     int c;
  7243.  
  7244.     || NOTE: These are MACROS if you #include <ctype.h>, subroutine calls
  7245.     || if you do not.
  7246.  
  7247.     DESCRIPTION
  7248.     toupper converts a character from lower to upper case, while tolower
  7249.     does the reverse.  Characters that are not of type upper or lower
  7250.     case (see isupper and islower) are left unchanged.
  7251.  
  7252.     || NOTE: Characters in the -1 to 255 range are valid inputs.
  7253.     || Characters less than -1 or larger than 255 are illegal and the
  7254.     || results will be random.  If you are passing a CHAR, you must cast
  7255.     || it to an UNSIGNED CHAR first. EOF is a valid input an always
  7256.     || returns false (zero).
  7257.  
  7258.     INPUTS
  7259.     int c;            character to be converted
  7260.  
  7261.     RESULTS
  7262.     int lc, uc;        converted character
  7263.  
  7264.     SEE ALSO
  7265.     isalnum, isalpha, iscntrl, isdigit, isgraph, islower, isprint,
  7266.     ispunct, isspace, isupper, isxdigit
  7267.  
  7268.     EXAMPLE
  7269.     #include <stdio.h>
  7270.     #include <ctype.h>
  7271.     main()
  7272.     {
  7273.     int c;
  7274.  
  7275.         /* Print all 256 characters, showing conversions */
  7276.         for( c=0; c<256; c++) {
  7277.         if( (c & 31) == 0 )    /* 32 per line */
  7278.             printf("\n%02x: ", c);
  7279.         if( isprint( c ) )    /* if printable ... */
  7280.             printf("%c", tolower( c ) );
  7281.         else
  7282.             printf("%c", 127);  /* if not-printable */
  7283.         }
  7284.         printf("\n");
  7285.         return( 0 );
  7286.     }
  7287.  
  7288. dice/ungetc                                                      dice/ungetc
  7289.  
  7290.     FUNCTION
  7291.     push a character back onto a file pointer's input stream (ANSI)
  7292.  
  7293.     SYNTAX
  7294.     #include <stdio.h>
  7295.     int r = ungetc(c, fp);
  7296.     int c;
  7297.     FILE *fp;
  7298.  
  7299.     DESCRIPTION
  7300.     ungetc pushes the specified character back onto the input stream, as
  7301.     if it had not been read.  Only ONE character may be pushed back onto
  7302.     an input stream at a time.  If all went well, the return value r is
  7303.     equal to c.  Else EOF is returned if too many characters were pushed
  7304.     back. Some implementations of C allow multiple characters to be
  7305.      pushed back.  The majority, including DICE, allows only one.
  7306.     ungetc is useful when, in scanning an input stream, you overshoot the
  7307.     'last' character you wanted a particular routine to retrieve.  This
  7308.     routine can push the character back onto the input stream with ungetc
  7309.     so another routine's getc (getchar, fread, fgetc, etc...) will get
  7310.     that character back.
  7311.  
  7312.     INPUTS
  7313.     int c;            character to push back onto input stream
  7314.  
  7315.     FILE *fp;        file pointer stream to push character on to.
  7316.  
  7317.     RESULTS
  7318.     int r;            pushed character (c) if no error, EOF if error
  7319.  
  7320.     SEE ALSO
  7321.     getc, getchar, fread, fgetc
  7322.  
  7323.     EXAMPLE
  7324.     #include <stdio.h>
  7325.     #include <ctype.h>
  7326.     main()
  7327.     {
  7328.        void scan_number();
  7329.        void scan_alpha();
  7330.        puts("Enter nnnaaannn where n=digit a=alpha");
  7331.        puts("Example: 1234abcd99");
  7332.        printf("? ");
  7333.        fflush(stdout);
  7334.        scan_number();  puts("--");
  7335.        scan_alpha();   puts("--");
  7336.        scan_number(); return(0);
  7337.     }
  7338.     static void scan_number()
  7339.     {
  7340.        short c;
  7341.        for (c = getchar(); c >= '0' && c <= '9';
  7342.          c = getchar())
  7343.        {
  7344.            printf("digit: %c\n", c);
  7345.        }
  7346.        if (c != EOF)
  7347.           ungetc(c, stdin);
  7348.     }
  7349.     static void scan_alpha()
  7350.     {
  7351.        short c;
  7352.        for (c = getchar();
  7353.        tolower(c) >= 'a' && tolower(c) <= 'z';
  7354.        c =getchar())
  7355.        {
  7356.           printf("alpha: %c\n", c);
  7357.        }
  7358.           if (c != EOF) ungetc(c, stdin);
  7359.     }
  7360.  
  7361. dice/unlink                                                      dice/unlink
  7362.  
  7363.     FUNCTION
  7364.     delete a file (UNIX)
  7365.  
  7366.     SYNTAX
  7367.     #include <stdio.h>
  7368.     int r = unlink(filename);
  7369.     char *filename;
  7370.  
  7371.     DESCRIPTION
  7372.     unlink deletes a file, equivalent to remove. This call deletes a file
  7373.     from the filesystem.  unlink exists for UNIX compatibility only. Use
  7374.     rmdir to delete a directory if you wish to maintain portability.
  7375.  
  7376.     INPUTS
  7377.     char *filename;     name of file to delete
  7378.  
  7379.     RESULTS
  7380.     int r;            0 if successful, non-zero if error
  7381.  
  7382.     SEE ALSO
  7383.     close, creat, fcntl, fdtofh, ioctl, isatty, lseek, mkdir, open, read,
  7384.     rmdir, unlink, write
  7385.  
  7386.     EXAMPLE
  7387.     main()
  7388.     {
  7389.        int r;
  7390.        r = unlink("T:xx");
  7391.        if (r == 0)
  7392.           puts("Deleted T:xx");
  7393.        else
  7394.           puts("Unable to delete t:xx or it does not exist");
  7395.        return(0);
  7396.     }
  7397.  
  7398. dice/wbmain                                                      dice/wbmain
  7399.  
  7400.     FUNCTION
  7401.     main program entry when run from Workbench (DICE)
  7402.  
  7403.     SYNTAX
  7404.     #include <startup.h>
  7405.     int wbmain(struct WBStartup *wbs)
  7406.     {
  7407.         /*    your main code goes here */
  7408.         return(exitcode);
  7409.     }
  7410.  
  7411.     DESCRIPTION
  7412.     The wbmain routine is the entry point called after normal
  7413.     initialization of c.lib and the program environment is done by the
  7414.     startup module (c.o) and _main() routine (in c.lib). wbmain is called
  7415.     when the program is run from the workbench, main is called when the
  7416.     program is run from the CLI.  The exit code is ignored. The standard
  7417.     workbench startup message is passed to wbmain, you can process or
  7418.     ignore this message as you like but should NOT ReplyMsg it.  We
  7419.     repeat, do not ReplyMsg it.  When you return from wbmain or exit out
  7420.     of the program the exit code will automatically deal with the
  7421.     message.
  7422.  
  7423.     SEE ALSO
  7424.     main
  7425.  
  7426.     EXAMPLE
  7427.     /*
  7428.     *  If run from the workbench this program will create a
  7429.     *  file T:XX instead of printing something on the
  7430.     *  console (since there is no console in that case).
  7431.     */
  7432.     #include <stdio.h>
  7433.     int main(int ac, char**av)
  7434.     {
  7435.        puts("This was run from a CLI");
  7436.        return(0);
  7437.     }
  7438.     int wbmain(msg)
  7439.     void *msg;  /* cheat to make the example less complex */
  7440.     {
  7441.        FILE *fi = fopen("T:xx", "w");
  7442.        fprintf(fi, "This was run from the WORKBENCH\n");
  7443.        fclose(fi);
  7444.     }
  7445.  
  7446. dice/write                                                        dice/write
  7447.  
  7448.     FUNCTION
  7449.     write data to a file (UNIX)
  7450.  
  7451.     SYNTAX
  7452.     #include <fcntl.h>
  7453.     int r = write(fd, buf, bytes);
  7454.     int fd;
  7455.     void *buf;
  7456.     int bytes;
  7457.  
  7458.     DESCRIPTION
  7459.     write writes data to a file, starting at the current seek position.
  7460.     It extends the file if necessary, or else writes over existing data.
  7461.     With normal files, write will always return the number of bytes
  7462.     requested and fewer only if an error occurs.  With devices write may
  7463.     or may not return the number of bytes requested depending on the
  7464.     device, though usually it does.
  7465.  
  7466.     || NOTE: Refer to the file_descriptor manual page for general
  7467.     || information. Unlike file pointers and file handles, the file
  7468.     || descriptor is checked for validity and will simply return an error
  7469.     || if illegal.
  7470.  
  7471.     INPUTS
  7472.     int fd;         file descriptor to write to void
  7473.  
  7474.     *buf;            pointer to buffer to write data from
  7475.  
  7476.     int len;        number of bytes to write
  7477.  
  7478.     RESULTS
  7479.     int r;            number of bytes actually written, usually an
  7480.                 error if r !=len.
  7481.  
  7482.     SEE ALSO
  7483.     close, creat, fcntl, fdtofh, ioctl, isatty, lseek, mkdir, open, read,
  7484.     rmdir, unlink
  7485.  
  7486.     EXAMPLE
  7487.     See open for an example
  7488.  
  7489. dice/x.o                                                            dice/x.o
  7490.  
  7491.     FUNCTION
  7492.     autoinit terminating tags (DICE)
  7493.  
  7494.     LIBRARY
  7495.     x.o
  7496.  
  7497.     DESCRIPTION
  7498.     The X.O module is the normally the last object module specified when
  7499.     linking.  DICE has a very unique and elegant system of creating
  7500.     automatic initialization and exit code.  The X.O module terminates
  7501.      these special sections.
  7502.     Autoinit/exit sections work as follows: any object module may define
  7503.     a specially named section which will be linked, in sequence, with
  7504.     other module's sections of the same name.  These sections contain
  7505.     only code and no RTS.  The terminating module X.O adds a single RTS
  7506.     to each section, allowing the base of the section to be called by the
  7507.     startup/exit module (C.O).  Execution propagates through all
  7508.     autoinit/exit routines before hitting the RTS placed in the section
  7509.     by X.O. DICE uses autoinit/exit sections to handle the following
  7510.     things:
  7511.  
  7512.     1) Code to initialize initialized data containing references to other
  7513.        initialized data (i.e.  int a, *b = &a;) when the code must be
  7514.        made residentable.  This precludes the need for the startup code
  7515.        to handle Data-Data 32-bit relocations for resident code.
  7516.  
  7517.     2) Code to open libraries whos base variables are referenced but
  7518.        never declared. _DOSBase and the various floating point libraries
  7519.        are automatically opened in this way whenever library calls to
  7520.        them are made.  This precludes the need for DICE to have massive,
  7521.        complex, and many times unnecessary code in c.lib to handle these
  7522.        situations.
  7523.  
  7524.     3) Code to close libraries that were opened by (2) on exit.
  7525.  
  7526.     4) Entry points for the special __autoinit keyword.
  7527.  
  7528.     SEE ALSO
  7529.     c.o
  7530.  
  7531.     EXAMPLE
  7532.     dlink dlib:c.o myprog.o dlib:x.o -o myprog -v
  7533.