Annotation of coherent/a/usr/src/misc/Read_me, revision 1.1.1.1

1.1       root        1: misc/Read_me 10/11/90
                      2: 
                      3: libmisc.a is a collection of miscellaneous useful user functions
                      4: which can be used by C programmers to increase productivity.
                      5: 
                      6: misc.h
                      7:        Is a header file with externs and #define's for the
                      8:        various functions in libmisc.a
                      9: 
                     10: char * alloc(n) unsigned n;
                     11:        Malloc() n bytes and zero them, or put out a fatal error message.
                     12: 
                     13: int approx(a, b) double a, b;
                     14:        If a and b are within epsilon return 1 else 0. epsilon
                     15:        is a visable double.
                     16: 
                     17: char * ask(reply, msg, ...) char *reply *msg;
                     18:        Puts out msg as a printf style format string using any
                     19:        trailing arguments. Gets a line from stdin with gets()
                     20:        and returns the address of reply. For example
                     21:        sscanf(ask(buff, "%d numbers", 3), &a, &b, &c);
                     22:        puts out the message "Enter: 3 numbers " gets a reply
                     23:        in buff and hands that to sscanf().
                     24: 
                     25: void banner(word, pad) char *word; int pad;
                     26:        Prints word as a banner on stdout preceeded by pad
                     27:        spaces. Each letter of the banner is composed of
                     28:        occurances of itself.
                     29:        
                     30: unsigned short crc16(p) char *p;
                     31:        Takes the crc16 of the string p and returns it. Fast
                     32:        and perfect for hash tables, diff algorithms etc.
                     33: 
                     34: void fatal(msg, ...) char *msg;
                     35:        Prints the msg as a printf style format string using
                     36:        any trailing arguments. This is preceeded by
                     37:        "\nfatal". fatal() then does exit(1).
                     38: 
                     39: int is_fs(special) char *special;
                     40:        Checks if a special file is a well formed file system.
                     41:        Users should never put file systems on /dev/ram1 but
                     42:        For multi system software like compress it is smart
                     43:        to test.
                     44: 
                     45:        Return values:
                     46:        -1      Not a device, cannot open, read or seek failed.
                     47:         0      No filesystem.
                     48:         1      Legal filesystem.
                     49: 
                     50: char * lcase(str) char *str;
                     51:        Converts str to lower case.
                     52: 
                     53: char * match(string, pattern, fin) char *string, *pattern, **fin;
                     54:        Like pnmatch() except match returns the address of the
                     55:        pattern matched. fin is aimed past the end of the
                     56:        pattern found. That is match finds a pattern and tells
                     57:        you where it is.
                     58: 
                     59: char * newcpy(str) char* str;
                     60:        Creates a NUL terminated copy of str on the heap.
                     61:        It calls fatal if there is no space.
                     62: 
                     63: char * pathn(name, envpath, deflpath, access)
                     64:     char *name, *envpath, *deflpath, *access;
                     65:        example: pathn("helpfile", "LIBPATH", "/lib", "r")
                     66:        Looks for helpfile using the environmental variable
                     67:        LIBPATH if that isn't set, or the second parm is NULL
                     68:        it uses the default path "/lib". The file found must
                     69:        have read permission. pathn() returns the full path
                     70:        to the file found.
                     71: 
                     72: double picture (dble, format, output )
                     73:     double dble;    /* the number to format */
                     74:     char  *format;  /* the format mask */
                     75:     char  *output;  /* the output area. At least as large as format */
                     76: 
                     77:        The picture() function gives C users far better
                     78:        numeric formatting ability than COBOL and BASIC users. 
                     79: 
                     80:        9    Provides a slot for a number.
                     81:             5.000 passed through a mask of '999 CR' gives '005   '
                     82:            -5.000 passed through a mask of '999 CR' gives '005 CR'
                     83:         Note: C & R are not special to picture. Trailing non special
                     84:               characters print only if the number is negitave
                     85:        
                     86:        Z    Provides a slot for a number but supresses lead zeros.
                     87:          1034.000 passed through a mask of 'ZZZ,ZZZ' gives '  1,034'
                     88:         Note: comma is not special to picture. Imbeded non special
                     89:               characters print only if preceeded by significant digits
                     90:        
                     91:        J    Provides a slot for a number but shrinks out lead zeros.
                     92:          1034.000 passed through a mask of 'JJJ,JJJ' gives '1,034'
                     93:        
                     94:        K    Provides a slot for a number but shrinks out any zeros.
                     95:         70884.000 passed through a mask of 'K9/K9/K9' gives '7/8/84'
                     96:        
                     97:        $    Floats a dollar sign to the front of the displayed number.
                     98:           105.000 passed through a mask of '$ZZZ,ZZZ' gives '    $105'
                     99:        
                    100:        .    Separates the number between decimal and integer portions.
                    101:           105.670 passed through a mask of 'Z,ZZZ.999' gives '  105.670'
                    102:        
                    103:        T    Provides a slot for a number but supresses trailing zeros.
                    104:           105.670 passed through a mask of 'Z,ZZ9.9TT' gives '  105.67 '
                    105:        
                    106:        S    Provides a slot for a number but shrinks out trailing zeros.
                    107:           105.670 passed through a mask of 'Z,ZZ9.9SS' gives '  105.67'
                    108:        
                    109:        -    Floats a - infront of negitive numbers
                    110:           105.000 passed through a mask of '-Z,ZZZ' gives '   105'
                    111:          -105.000 passed through a mask of '-Z,ZZZ' gives '  -105'
                    112:        
                    113:        (    Acts like - but prints a (
                    114:           105.000 passed through a mask of '(ZZZ)' gives ' 105 '
                    115:            -5.000 passed through a mask of '(ZZZ)' gives '  (5)'
                    116:        
                    117:        +    Floats a + or - infront of the number depending on its sign
                    118:             5.000 passed through a mask of '+ZZZ' gives '  +5'
                    119:            -5.000 passed through a mask of '+ZZZ' gives '  -5'
                    120:        
                    121:        *    Fills all lead spaces to its right
                    122:           104.100 passed through a mask of '*ZZZ,ZZZ.99' gives '*****104.10'
                    123:           104.100 passed through a mask of '*$ZZZ,ZZZ.99' gives '*****$104.10'
                    124:        
                    125:        Any overflow is returned by picture as a double precision number.
                    126:         -1234.000 passed through a mask of '(ZZZ)' gives '(234)'
                    127:            With an overflow of -1.0
                    128:           123.400 passed through a mask of '99' gives '23'
                    129:            With an overflow of 1.0
                    130:          1200.000 passed through a mask of 'ZZ' gives '00'
                    131:            With an overflow of 12.0
                    132: 
                    133: long randl()
                    134:        Returns a long random number uniformly distributed in
                    135:        1..2147483562. This comes from CACM V. 31 N 6. And is
                    136:        the best algorithm I know as of this writing.
                    137:        see srandl() in this section.
                    138: 
                    139: char * replace(s1, pat, s3, all, matcher) char *s1, *pat, *s3, (matcher)();
                    140:        Replaces one or all occurances of pat in s1 by s3 and
                    141:        returns the result. The definition of match is set by matcher.
                    142:        This calls the user defined function matcher(sw, pat, &fin). The
                    143:        matcher must return the address of the pattern match and
                    144:        it's end in &fin. match() is a valid example of matcher.
                    145:        It replaces the first occurance, or all occurances of the
                    146:        pattern and returns the new pattern. The new pattern has been
                    147:        alloc()ed (see alloc).
                    148: 
                    149: showflag(data, flags, output) long data; char *flags, *output;
                    150:        Turns the bits in data to the flags in flags or '-'
                    151:        in the string output which must be as long as flags.
                    152: 
                    153: char * skip(s1, matcher, fin) char *s1, **fin; int (*matcher)();
                    154:        Skip one or more characters not matching some criterion
                    155:        such as isdigit(). Returns the first character skipped
                    156:        points fin at the character after the skip.
                    157: 
                    158: char * span(s1, matcher, fin) char *s1, **fin; int (*matcher)();
                    159:        Span one or more characters matching some criterion
                    160:        such as isdigit(). Returns the first character spanned
                    161:        points fin at the character after the span.
                    162: 
                    163: srandl(seed1, seed2) long seed1, seed2;
                    164:        randl() needs two seeds this sets them. Used only
                    165:        if you need to repeat a random number sequence.
                    166: 
                    167: strchtr(from, to, c, def) char *from, *to; int c, def;
                    168:        Look up the char c on the string from, return the corresponding
                    169:        char on the string to if it is found otherwise return the char
                    170:        def. example: strchr("abc", "xyz", c, d); if c == 'a' return
                    171:        'x', if c == 'b' return 'y' if c > 'c' return d.
                    172:        
                    173: 
                    174: strcmpl(s1, s2)
                    175:        Case insensative string compare.
                    176: 
                    177: #define strlcpy(to, from) memcpy(to, from, sizeof(to))
                    178: 
                    179: ucase(s) char *s;
                    180:        Convert a string to upper case.
                    181: 
                    182: usage(s) char *s;
                    183:        Put out a usage: message and exit(1)
                    184: 
                    185: The following are part of a user virtual memory system for
                    186: Coherent. Sometimes users port programs such as compress to
                    187: Coherent which have a small number of very large arrays. Since
                    188: Coherent is a small model operating system changes need to be
                    189: made. The following functions are intended to expedite these
                    190: changes.
                    191: 
                    192: void vinit(filename, ram) char *filename; unsigned ram;
                    193:        Init the virtual system using filename for work
                    194:        this may be a raw device such as /dev/rram1. ram
                    195:        is the amount of buffer space to give the system
                    196:        the more the better.
                    197: 
                    198: void vshutdown()
                    199:        Shut the virtual system, and make it restartable.
                    200: 
                    201: unsigned vopen(amt) unsigned long amt;
                    202:        Set up a virtual object. Say you want to emulate having
                    203:        a 100000 byte array and a 50000 byte array. use
                    204:        vid1 = vopen(100000L); vid2 = vopen(50000L);
                    205:        This does some checking and tells the system that any
                    206:        reference to vid2 will be between 100000 and 150000
                    207:        on the virtual file.
                    208: 
                    209: char *vfind(vid, disp, dirty) unsigned vid, dirty; unsigned long disp;
                    210:        Find a character on the virtual system mark the blocks
                    211:        dirty bit if the access is to write. Given the example in
                    212:        vopen, if you want to find the 1000 th byte in vdi1
                    213:        c = vfind(vdi1, 1000L, 0);
                    214:        To change the 2000 th byte in vid2 to d.
                    215:        *(vfind(vid2, 2000L, 1)) = d;
                    216:        Note the dirty indicator tells the system of the change so
                    217:        that the block will be written back before it is read over.
                    218:        Blocks are 512 bytes long so int's or long's can be read
                    219:        or written without multiple accesses to vfind.
                    220: 
                    221: xdump(p, length) char *p;
                    222:        Make a vertical hex dump of p for length on stdout. This
                    223:        is a usefull debugging tool. Vertical hex prints as 3 lines
                    224:        The top line is the display character or . if it's not
                    225:        cleanly displayable. The next two lines are the hex digit.
                    226:        The data is blocked in groups of four bytes.
                    227: 
                    228: xopen(filename, acs)
                    229:        Like fopen() but it calls fatal() if the open fails.
                    230: 
                    231: yn(question, ...) char *question;
                    232:        Ask a question with any trailing parms printf style and
                    233:        get a y or n answer. Returns a 1 for 'Y' or 'y' a 0
                    234:        for 'n' or 'N', reasks otherwise.

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.