home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / prog_c / mylib.lzh / MY.LIB / DOC.TXT next >
Encoding:
Text File  |  1991-11-01  |  18.9 KB  |  619 lines

  1.  
  2. MY.LIB COMPILATION
  3.  
  4.    - 32 bit Lattice C  OR  32 bit Manx C (i.e. +l option) It has not
  5.      been tested under Manx, but since the assembly routines do not use
  6.      the frame pointer (Lattice and Manx use different FP's), I see no
  7.      problems.
  8.  
  9.    - Compile Each .C module with stack checking DISABLED (this is an option
  10.      with lattice, I don't know about manx)
  11.  
  12.    - Assemble each .ASM module
  13.  
  14.    - JOIN ALL the .O modules together to create the library.  Under MANX,
  15.      you might have to use Manx's support programs to create the library.
  16.  
  17.    - When linking in MY.LIB, link it BEFORE Amiga.lib.  It can go before or
  18.      after any other libraries, but remember that if MY.LIB has priority
  19.      (comes before) LC.LIB, some of LC.LIB's functions are replaced
  20.      (string functions, etc...).  Additionaly, MY.LIB contains the function
  21.      FPRINTF for FILEHANDLES (the fprintf in LC.LIB and MAnx's library is
  22.      for the respective STDIO routines).  Also read the docs on malloc() and
  23.      free() under MY.LIB
  24.  
  25.  
  26.  
  27. MY.LIB DOCUMENTATION OF COMMANDS:
  28.  
  29. XSTDIO:
  30.  
  31.    fi     = xopen(name, mode, bufsize)
  32.    result = xasync(fi, command)
  33.             xclose(fi)
  34.         c = xgetc(fi)
  35.             xputc(fi, c)
  36.    actual = xread(fi, buf, n)
  37.      bool = xwrite(fi, buf, n)
  38.      bool = xsetbuf(fi, bufsize)
  39.        fi = xattach(FileHandle, bufsize)
  40.        fh = xdetach(fi)
  41.  position = xtell(fi)
  42.    newpos = xseek(fi, offset, mode)    mode= -1/0/1
  43.      bool = xputs(fi, buf)             Note: adds \n
  44.    nchars = xgets(fi, buf, max)        Replaces \n with \0. nchars includes \0
  45.       buf = gets(buf)
  46.             puts(buf)
  47.      bool = xflush(fi)
  48.             xprintf(fi, ctlstring, args...)     xstdio file pointer
  49.             fprintf(fh, ctlstring, args...)     AmigaDos file handle
  50.  
  51. STRING:
  52.       len = strlen(str)
  53.       dst = strcpy(dst, src)
  54.       dst = strcat(dst, src)
  55.    result = strcmp(s1, s2)              result: -1 s1<s2  0 s1=s2  1 s1>s2
  56.  
  57.       dst = strncpy(dst, src, max)      max doesn't include \0
  58.       dst = strncat(dst, src, max)      max doesn't include \0
  59.       dst = strncmp(dst, src, max)
  60.  
  61. MEMORY:
  62.  
  63.       str = malloc(bytes)               (a hack.. is wasteful)
  64.             free(str)
  65.             free_memory()               must be called on exit if you use
  66.                                          malloc().
  67.  
  68.             bzero(ptr, bytes)
  69.             bmov(src, dst, bytes)       handles both src<dst and src>dst
  70.             bset(ptr, bytes, char)
  71.  
  72. MISC:
  73.       val = atoi(str)
  74.      bool = openlibs(mask)              see xmisc.h for bitmap of mask
  75.             closelibs(mask)             may give argument '-1' to close all
  76.      bool = wildcmp(wild, name)
  77.             check32()                   exits if not compiled w/32 bit ints
  78.             io_open()                   See below for calling parameters
  79.             io_close()                  See below for calling parameters
  80.  
  81.      bool = checkbreak()                check if break pressed
  82.             resetbreak()                reset 'break-pressed' signal.
  83.  
  84.             mountrequest(bool)          disable/enable requestors for
  85.                                         unmounted filing system accesses.
  86.  
  87.  
  88. CAPSULE SUMMARY OF XSTDIO:
  89.  
  90.    The xstdio routines provide the programmer (read 'us') with buffered
  91.    and asyncronous file support.  With xstdio, you generally have better
  92.    control over your file-pointers than the original stdio.  The
  93.    disadvantage to xstdio is that its error reporting mechanism hasn't
  94.    been fully developed as yet.
  95.  
  96.    Please note that the xstdio file pointers (I denote them as 'FI') are
  97.    not in anyway compatible with stdio file pointers.
  98.  
  99.    For your safety, you should not access an xstdio file pointer's file
  100.    handle directly.  Especially when you are using the asyncronous write
  101.    utility (see xasync()), the file pointer's file handle is placed in a
  102.    precarious position and should only be accessed through xstdio routines.
  103.  
  104.    The XSTDIO routines provide the programmer with buffered file I/O much
  105.    like STDIO routines.  XSTDIO routines offer better control over your
  106.    enviroment, but lack in error reporting for some functions.  The
  107.    XSTDIO routines also have the ability to double-buffer writes.
  108.  
  109.    XSTDIO routines use a File Pointer (fi), but are NOT compatible
  110.    with STDIO routines.
  111.  
  112. Implimentation Notes:
  113.    My implimentation of xprintf() and fprintf() uses the stack to hold
  114.    the output buffer... 256 bytes.  Therefore, the eventual output
  115.    string of a given xprintf() or fprintf() call cannot be larger than
  116.    255 bytes.  I've heard that it can't be larger anyway due to
  117.    restrictions on RawDoFmt(), but am not sure.
  118.  
  119.    The xstdio puts() exists to correct a problem with AMIGA.LIB's puts().
  120.    Namely, the latter crashes on outputs larger than 255 bytes for no
  121.    good reason.
  122.  
  123.  
  124. --------------------------------------------------------------------------
  125.  
  126.    fi = xopen(name, access, bufsize)
  127.  
  128.       FILE *fi;         returned file pointer
  129.       char *name;       file name to open
  130.       char *access;     access modes "r", "r+", "w", "w+"
  131.       int  bufsize;     requested buffer size, in bytes
  132.  
  133.       "r"   -read           (fail if non-existant)
  134.       "r+"  -read and write (fail if non-existant)
  135.       "w"   -write          (create if non-existant, truncate if exists)
  136.       "w+"  -append         (create if non-existant, seek to end if exists)
  137.  
  138.       The minimum buffer size is 1 (calling w/ 0 is actually 1).  It is
  139.       suggested that you use buffer sizes of at least 512 bytes.  For
  140.       example, if you xopen() with a bufsize of 1 and write out a 20K
  141.       block, it will be written 1 byte at a time.
  142.  
  143.       NULL is returned on error.
  144.  
  145.  
  146.    result = xasync(fi, operation)
  147.  
  148.       int result;       -result of operation (depends)
  149.       FILE *fi;         -file pointer
  150.       int operation;    -operation
  151.  
  152.       operation = -1    -returns boolean whether async. is on or off.
  153.                   0     -turns async OFF
  154.                   1     -turns async-writes ON
  155.                   2     -reserved
  156.                   3     -(internal) waits for async. operation to complete
  157.                   4     -(internal) don't call with this operation.
  158.  
  159.       usually one calls xasync() with operation 0 or 1 to turn off or
  160.       on asyncronous write mode.  When ON, another buffer of the same
  161.       size is allocated to provide the double buffering asyncronous-writes
  162.       need.  When on, any write operation which causes the buffer to
  163.       flush to the disk will be done asyncronously (e.g. will return before
  164.       disk operation is complete).  This is only useful if you are not
  165.       writing to the disk at full speed.  Since the writes are only double-
  166.       buffered, writing at full speed WILL cause momentary block conditions
  167.       just like normal writing.  A good use for asyncronous writes is the
  168.       capture function of a modem program.
  169.  
  170.       Future revisions of the library will also have an asyncronous READ
  171.       capability.
  172.  
  173.  
  174.  
  175.    fi = xattach(fh, bufsize)
  176.  
  177.       FILE *fi;         -return file pointer
  178.       FileHandle fh;    -source AmigaDOS file handle
  179.       int bufsize;      -buffering size (like xopen()).
  180.  
  181.       This routine will attempt to attach a file pointer to a file handle.
  182.       If it succedes, any further I/O should be through XSTDIO functions
  183.       and the file pointer rather than AmigaDOS functions through the
  184.       File Handle.
  185.  
  186.       fi returns NULL if the buffer could not be allocated.
  187.  
  188.  
  189.    fh = xdetach(fi)
  190.  
  191.       FileHandle fh;    -file handle
  192.       FILE *fi;         -file pointer
  193.  
  194.       This call deallocates the XSTDIO file pointer and returns a properly
  195.       Seek'd file handle.  It ALWAYS works.
  196.  
  197.  
  198.    bool  = xsetbuf(fi, newbufsize)
  199.  
  200.       int bool;            -did the operatio work?
  201.       FILE *fi;            -file pointer
  202.       int newbufsize;      -new buffer size.
  203.  
  204.       This operation resizes a file pointer's buffer(s).  If it fails, the
  205.       original buffer(s) are still in place.  Remember that if xasync() is
  206.       on for that file pointer, the actual allocated memory is twice the
  207.       requested buffer size.
  208.  
  209.  
  210.    chars =  xgets(fi, buf, n)
  211.  
  212.       int chars;     -# bytes in buffer INCLUDING the termination \0.
  213.       FILE *fi;      -file handle to get data from.
  214.       char *buf;     -buffer to place data in
  215.       int n;         -maximum buffer size allowed.
  216.  
  217.       This routine will retrieve a string from the file pointer until it
  218.       reaches the end of file or a newline '\n'.  The newline is REPLACED
  219.       by a \0 before the function returns.
  220.  
  221.       The End Of File occurs when 'chars' is 0.
  222.  
  223.  
  224.    bool  = xputs(fi, buf);
  225.  
  226.       int bool;      -did the operation work?
  227.       FILE *fi;      -file pointer
  228.       char *buf;     -\0 terminated string
  229.  
  230.       xputs() writes the specified string to the specified file pointer.
  231.       The \0 in the string is replaced with a newline '\n' in the output.
  232.  
  233.  
  234.    c  = xgetc(fi);
  235.  
  236.       int c;         -returned char or -1
  237.       FILE *fi;      -file pointer
  238.  
  239.       xgets() gets a single character from a file pointer.  -1 is returned
  240.       on EOF or error.
  241.  
  242.  
  243.    bool  = xputc(fi, c);
  244.  
  245.       int bool;      -did it work?
  246.       FILE *fi;      -file pointer
  247.       char c;        -character to write
  248.  
  249.       output a single character to a file.  NOTE: Since files are buffered,
  250.       you may not get an error until the buffer is flushed.
  251.  
  252.  
  253.    actual = xread(fi, buf, n);
  254.  
  255.       int actual;    -actual bytes read or 0
  256.       FILE *fi;      -file pointer
  257.       char *buf;     -buffer to read into
  258.       int n;         -max # bytes to read
  259.  
  260.       0 is returned on EOF or error.  Attempt to read n bytes into a buffer.
  261.       The actual number read is returned.
  262.  
  263.  
  264.    bool = xwrite(fi, buf, n);
  265.  
  266.       int bool;      -did the operation work?
  267.       FILE *fi;      -file pointer
  268.       char *buf;     -buffer
  269.       int n;         -bytes to write
  270.  
  271.       Note that xwrite() returns a bool, not the actual number bytes
  272.       written.
  273.  
  274.  
  275.    bool = xflush(fi);
  276.  
  277.       int bool;      -sucess?
  278.       FILE *fi;      -file ptr;
  279.  
  280.       FILE is returned only if the buffer was modified AND the Write()
  281.       failed.
  282.  
  283.  
  284.    newpos = xseek(fi, offset, which);
  285.  
  286.       int newpos;    -NEW position AFTER xseek.
  287.       FILE *fi;      -file pointer
  288.       int offset;    -offset relative to 'which'
  289.       int which;     -AMIGA conventions  -1(start)  0(current)  1(end)
  290.  
  291.  
  292.    pos = xtell(fi);
  293.  
  294.       int pos;
  295.       FILE *fi;
  296.  
  297.       Self evident: returns the current seek position.  Note that this
  298.       may not reflect the actual Seek() position of the underlying file
  299.       handle.
  300.  
  301.  
  302.    xclose(fi);
  303.  
  304.       FILE *fi;
  305.  
  306.       close the file pointer AND the underlying file handle.  You may pass
  307.       this routine a NULL without ill-effects.
  308.  
  309.  
  310.    xprintf(fi, cs, arg, arg ... )
  311.  
  312.       FILE *fi;
  313.       char *cs;
  314.  
  315.       Uses AMIGA.LIB's RawDoFmt.  This version of printf outputs to a
  316.       file pointer.  xprintf() dies with large output strings (>255), so
  317.       don't be too fancy.  Also note that RawDoFmt is not a full fledged
  318.       printf, but should do what you want.
  319.  
  320.  
  321.    fprintf(fh, cs, arg, arg ... )
  322.  
  323.       long fh;
  324.       char *cs;
  325.  
  326.       Same thing as xprintf() except works on AmigaDos File Handles.
  327.  
  328.  
  329.    ptr = gets(buf)
  330.  
  331.       char *ptr;
  332.       char *buf;
  333.  
  334.       gets() uses Input() to get the next line from the programs STDIN.
  335.       NULL is returned on EOF or error.
  336.  
  337.       This is rather a slow function, since data is read one-byte-at-a-time.
  338.       It works fine for user-input, but if your program expects STDIN to
  339.       be a file, you may want to xattach() Input() to a file-pointer and
  340.       use xgets().
  341.  
  342.  
  343.    bool = puts(str)
  344.  
  345.       int bool;
  346.       char *str;
  347.  
  348.       Output the \0 terminated string to STDOUT, replacing the \0 with
  349.       a newline (\n).  Unlike AMIGA.LIB's puts(), this one allows
  350.       strings of any size.
  351.  
  352.  
  353. ---------------------------------------------------------------------------
  354.  
  355.  
  356. result   = atoi(str)
  357.  
  358.       int result;    -resulting integer
  359.       char *str;     -source string
  360.  
  361.       atoi() converts ascii-decimal integers into integers, stopping at
  362.       the first illegal character.
  363.  
  364.  
  365. #include <xmisc.h>
  366. bool     = openlibs(libs_mask)
  367.  
  368.       int bool;         -if all the libraries were openned
  369.       int libs_mask;    -mask of all libraries to open.
  370.  
  371.       openlibs() is an easy way of openning several run-time libraries at
  372.       once.  If you have this call in your code, global definitions for
  373.       all of the amiga's standard libraries will be automatically
  374.       included.  You specify a mask of libraries to open (see xmisc.h for
  375.       mask #defines).  If all the libraries could be openned, TRUE is
  376.       returned.  If one or more could not be openned, FALSE is returned on
  377.       the ones that were able to be openned are closed.
  378.  
  379.  
  380. closelibs(libs_mask)
  381.  
  382.       int libs_mask;
  383.  
  384.       close the specified libraries.  Only open libraries will be closed.
  385.       Thus, you can say:  closelibs(-1); to close all the libraries.
  386.  
  387.  
  388. bool = wildcmp(wild, name)
  389.  
  390.       int bool;
  391.       char *wild;
  392.       char *name;
  393.  
  394.       wildcmp() returns TRUE of the wildcard-name matches a normal
  395.       string-name:
  396.  
  397.          TRUE = wildcmp("abcd?f", "abcdef");
  398.          TRUE = wildcmp("abc*x",  "abcd.e.f.x");
  399.          FALSE= wildcmp("ab??",   "ab");
  400.  
  401.       The wildcard name may consist of any number of '*'s and '?'s.
  402.  
  403.  
  404. check32()
  405.       Checks to see if the program was compiled using 32-bit ints.  If
  406.       not, gives an error message and exit()'s.
  407.  
  408.  
  409. checkbreak()
  410. resetbreak()
  411.       checkbreak() returns true (1) if ^C has been pressed.  Once ^C has
  412.       been pressed, checkbreak() will always return true until you call
  413.       resetbreak() to reset the signal. (checkbreak() does not reset the
  414.       signal).
  415.  
  416.  
  417. mountrequest(bool)
  418.       turn on or off automatic system requestors when your program accesses
  419.       unmounted prefixes:
  420.  
  421.       TRUE (default) -system will prompt user to place correct disk
  422.                       in drive via a requestor when program accesses
  423.                       unmounted file.
  424.  
  425.       FALSE          -if a given file path is not mounted, an error is
  426.                       returned to the program rather than prompting the
  427.                       user.
  428.  
  429.       WARNING:  Do not exit the program while mountrequest() is set to
  430.       FALSE... bad things might happen.
  431.  
  432.       NOTE: You can call mountrequest() with it's current state without
  433.       harm.  That is, you can call mountrequest(TRUE) when it is already
  434.       TRUE, and mountrequest(FALSE) when it is already false.
  435.  
  436.  
  437.  
  438. io_open()
  439. io_close()
  440.  
  441.  
  442.   long
  443.   io_open(device_name, unit, flags, &rreq, &wwreq, req_size, spec1, spec2)
  444.  
  445.     char *device_name          -the device name (ex: "serial.device")
  446.     int   unit                 -unit #
  447.     int   flags                -OpenDevice flags
  448.     struct IOxxxxxx *rreq      -address of pointer (will be filled in)
  449.     struct IOxxxxxx *wreq      -address of pointer (will be filled in)
  450.     int   req_size             -size of above structures
  451.     long  spec1,spec2          -special arguments for preinitialization
  452.                                  (depends on the device your openning)
  453.  
  454.     EXAMPLE:
  455.     ----------------------
  456.     typedef struct IOExtSer SIO;
  457.  
  458.     #define SERFLAGS (SERF_XDISABLED | SERF_SHARED)
  459.     SIO *srr, *swr;
  460.     long mask;
  461.  
  462.     mask = io_open("serial.device",0,0,&srr,&swr,sizeof(SIO),SERFLAGS,0);
  463.                    ...
  464.     io_close(srr, swr, sizeof(SIO));
  465.  
  466.     ----------------------
  467.  
  468.     The structure for rreq and wreq depend on the device you are openning.
  469.     You must be sure to specify the correct size.
  470.  
  471.     Some devices, such as the serial device, require certain fields inside
  472.     their IO structures to be initialized before the OpenDevice().  Since
  473.     io_open() Allocates these structures for you, these extra parameters
  474.     must be passed to io_open() via SPEC1 and SPEC2 in the arguments list
  475.     as outlined below:
  476.                      SPEC1              SPEC2
  477.     console.device   window pointer     window structure size
  478.     parallel.device  parallel flags     0
  479.     serial.device    serial flags       0
  480.     **ALL OTHERS**   0                  0
  481.  
  482.     note on audio device:  You must ADCMD_ALLOCATE and ADCMD_FREE
  483.     manually.
  484.  
  485.     You also pass io_open() the address of two pointers (e.g. **x).  These
  486.     will be filled in by io_open() to result in a READ and WRITE request
  487.     structure, each with it's own reply port, and with it's io_Command
  488.     fields initialized to CMD_READ and CMD_WRITE, respectively.  You may
  489.     specify a NULL for the **WRITE request structure instead of a
  490.     **wreq.  This will result in only a READ request structure being
  491.     set up.
  492.  
  493.     You do not have to use the structures for only CMD_READ and CMD_WRITE,
  494.     of course, you can use them for any io command.
  495.  
  496.     a signal MASK with one bit set is returned.  This is the signal bit
  497.     for the read-request structure (if rreq was NULL, then it is the
  498.     signal for the write-request structure).  an example mask:
  499.      00000000001000000000000000000000 in binary.
  500.  
  501.     0 is returned if the open fails.
  502.  
  503.  
  504.   io_close(rreq, wreq, size)
  505.  
  506.        specify 0 for the wreq if it doesn't exist (e.g. you passed a
  507.        NULL for it in the io_open() ).
  508.  
  509.  
  510.  
  511.  
  512. ----------------------------------------------------------------------------
  513. memory routines.  These are not quite automatic.  You must call the
  514. routine 'free_memory()' just before you exit if you use 'malloc'.
  515. The binary-zero/set/mov routines are written in assembly for speed.
  516.  
  517.  
  518. ptr = malloc(bytes);
  519.  
  520.    char *ptr;        -pointer to buffer
  521.    int bytes;        -#bytes to allocate
  522.  
  523.    NULL is returned if the allocation failed.  The pointer returned is on
  524.    32-bit boundries (e.g. longword).
  525.  
  526.  
  527. free(ptr)
  528.  
  529.    char *ptr;
  530.  
  531.    Free a malloc'd space.  Call only with pointer's you have
  532.    malloc'd.
  533.  
  534.  
  535. free_memory()
  536.  
  537.    Must be called before you exit to free ALL mallocs that have occured .
  538.  
  539.  
  540. bzero(s, n)
  541.  
  542.    char *s;
  543.    int n;
  544.  
  545.    Zero n bytes starting at s.
  546.  
  547.  
  548. bset(s, n, v)
  549.  
  550.    char *s;    -start address
  551.    int n;      -# bytes
  552.    int v;      -fill value
  553.  
  554.    Set a memory area to 'v'.
  555.  
  556.  
  557. bmov(s, d, n)
  558.  
  559.    char *s;    -source
  560.    char *d;    -dest
  561.    int n;      -# bytes
  562.  
  563.    Move from source to destination. bmov() will properly do a forward or
  564.    reverse move depending on where s and d are relative to each other.
  565.  
  566.  
  567. --------------------------------------------------------------------------
  568. String routines.  Exactly as normal STDIO routines.
  569.  
  570.  
  571. len   = strlen(str)
  572.  
  573.    int len;
  574.    char *str;
  575.  
  576.    return the length of the string.
  577.  
  578.  
  579. dest = strcpy(dest, source)
  580.  
  581.    char *source, *dest;
  582.  
  583.    string copy.  source and destination must be disjunct.
  584.  
  585.  
  586. dest = strncpy(dest, source, maxchars)
  587.  
  588.    char *dest, *source;
  589.    int maxchars;
  590.  
  591.    Copy no more than maxchars bytes.  This does NOT include the \0.
  592.  
  593.  
  594. dest = strcat(dest, source)
  595.  
  596.    Place the source after the destination.  Source and where source will
  597.    be placed on destination must be disjuct.
  598.  
  599.  
  600. dest = strncat(dest, source, n)
  601.  
  602.    Same as strcat, but no more than n chars will be copied, \0 NOT included.
  603.  
  604.  
  605. result = strcmp(source, dest)
  606.  
  607.    Compare the source with the destination.  Result is:
  608.  
  609.    -1    source < dest
  610.    0     source = dest
  611.    1     source > dest
  612.  
  613.  
  614. result = strncmp(source, dest, n)
  615.  
  616.    Same as strcmp, but a maximum of n chars are compared.
  617.  
  618.  
  619.