Annotation of 43BSDReno/lib/libpc/CTTOT.c, revision 1.1.1.1

1.1       root        1: /*-
                      2:  * Copyright (c) 1979 The Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted
                      6:  * provided that: (1) source distributions retain this entire copyright
                      7:  * notice and comment, and (2) distributions including binaries display
                      8:  * the following acknowledgement:  ``This product includes software
                      9:  * developed by the University of California, Berkeley and its contributors''
                     10:  * in the documentation or other materials provided with the distribution
                     11:  * and in all advertising materials mentioning features or use of this
                     12:  * software. Neither the name of the University nor the names of its
                     13:  * contributors may be used to endorse or promote products derived
                     14:  * from this software without specific prior written permission.
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     18:  */
                     19: 
                     20: #ifndef lint
                     21: static char sccsid[] = "@(#)CTTOT.c    1.6 (Berkeley) 4/9/90";
                     22: #endif /* not lint */
                     23: 
                     24: #include "whoami.h"
                     25: #include "h00vars.h"
                     26: 
                     27: long   _mask[] = {     
                     28: #              ifdef DEC11
                     29:                    0xffffffff , 0xfffffffe , 0xfffffffc , 0xfffffff8 ,
                     30:                    0xfffffff0 , 0xffffffe0 , 0xffffffc0 , 0xffffff80 ,
                     31:                    0xffffff00 , 0xfffffe00 , 0xfffffc00 , 0xfffff800 ,
                     32:                    0xfffff000 , 0xffffe000 , 0xffffc000 , 0xffff8000 ,
                     33:                    0xffff0000 , 0xfffe0000 , 0xfffc0000 , 0xfff80000 ,
                     34:                    0xfff00000 , 0xffe00000 , 0xffc00000 , 0xff800000 ,
                     35:                    0xff000000 , 0xfe000000 , 0xfc000000 , 0xf8000000 ,
                     36:                    0xf0000000 , 0xe0000000 , 0xc0000000 , 0x80000000 ,
                     37:                    0x00000000
                     38: #              else
                     39:                    0xffffffff , 0xfeffffff , 0xfcffffff , 0xf8ffffff ,
                     40:                    0xf0ffffff , 0xe0ffffff , 0xc0ffffff , 0x80ffffff ,
                     41:                    0x00ffffff , 0x00feffff , 0x00fcffff , 0x00f8ffff ,
                     42:                    0x00f0ffff , 0x00e0ffff , 0x00c0ffff , 0x0080ffff ,
                     43:                    0x0000ffff , 0x0000feff , 0x0000fcff , 0x0000f8ff ,
                     44:                    0x0000f0ff , 0x0000e0ff , 0x0000c0ff , 0x000080ff ,
                     45:                    0x000000ff , 0x000000fe , 0x000000fc , 0x000000f8 ,
                     46:                    0x000000f0 , 0x000000e0 , 0x000000c0 , 0x00000080 ,
                     47:                    0x00000000
                     48: #              endif DEC11
                     49:            };
                     50: /*
                     51:  * Constant set constructors.
                     52:  *
                     53:  * CTTOT is called from compiled Pascal.  It takes the list of ranges
                     54:  * and single elements on the stack, varargs style.
                     55:  *
                     56:  * CTTOTA is called from the px interpreter.  It takes a pointer to the
                     57:  * list of ranges and single elements.
                     58:  *
                     59:  * This was easier than changing the compiler to pass a pointer into
                     60:  * its own partially-constructed stack, while working to make px portable.
                     61:  */
                     62: 
                     63: long *CTTOTA();
                     64: 
                     65: long *
                     66: CTTOT(result, lwrbnd, uprbnd, paircnt, singcnt, data)
                     67: 
                     68:        long    *result;        /* pointer to final set */
                     69:        long    lwrbnd;         /* lower bound of set */
                     70:        long    uprbnd;         /* upper - lower of set */
                     71:        long    paircnt;        /* number of pairs to construct */
                     72:        long    singcnt;        /* number of singles to construct */
                     73:        long    data;           /* paircnt plus singcnt sets of data */
                     74: {
                     75:        return CTTOTA(result, lwrbnd, uprbnd, paircnt, singcnt, &data);
                     76: }
                     77: 
                     78: long *
                     79: CTTOTA(result, lwrbnd, uprbnd, paircnt, singcnt, dataptr)
                     80: 
                     81:        register long   *result;        /* pointer to final set */
                     82:        long    lwrbnd;                 /* lower bound of set */
                     83:        long    uprbnd;                 /* upper - lower of set */
                     84:        long    paircnt;                /* number of pairs to construct */
                     85:        long    singcnt;                /* number of singles to construct */
                     86:        register long   *dataptr;       /* ->paircnt plus singcnt data values */
                     87: {
                     88:        int             lowerbnd = lwrbnd;
                     89:        int             upperbnd = uprbnd;
                     90:        register long   *lp;
                     91:        register char   *cp;
                     92:        register long   temp;
                     93:        long            *limit;
                     94:        int             lower;
                     95:        int             lowerdiv;
                     96:        int             lowermod;
                     97:        int             upper;
                     98:        int             upperdiv;
                     99:        int             uppermod;
                    100:        int             cnt;
                    101: 
                    102:        limit = &result[(upperbnd + 1 + BITSPERLONG - 1) >> LG2BITSLONG];
                    103:        for (lp = result; lp < limit; )
                    104:                *lp++ = 0;
                    105:        for (cnt = 0; cnt < paircnt; cnt++) {
                    106:                upper = *dataptr++ - lowerbnd;
                    107:                if (upper < 0 || upper > upperbnd) {
                    108:                        ERROR("Range upper bound of %D out of set bounds\n",
                    109:                                *--dataptr);
                    110:                }
                    111:                lower = *dataptr++ - lowerbnd;
                    112:                if (lower < 0 || lower > upperbnd) {
                    113:                        ERROR("Range lower bound of %D out of set bounds\n",
                    114:                                *--dataptr);
                    115:                }
                    116:                if (lower > upper) {
                    117:                        continue;
                    118:                }
                    119:                lowerdiv = lower >> LG2BITSLONG;
                    120:                lowermod = lower & MSKBITSLONG;
                    121:                upperdiv = upper >> LG2BITSLONG;
                    122:                uppermod = upper & MSKBITSLONG;
                    123:                temp = _mask [lowermod];
                    124:                if ( lowerdiv == upperdiv ) {
                    125:                        temp &= ~_mask[ uppermod + 1 ];
                    126:                }
                    127:                result[ lowerdiv ] |= temp;
                    128:                limit = &result[ upperdiv-1 ];
                    129:                for ( lp = &result[ lowerdiv+1 ] ; lp <= limit ; lp++ ) {
                    130:                        *lp |= ~0;
                    131:                }
                    132:                if ( lowerdiv != upperdiv ) {
                    133:                        result[ upperdiv ] |= ~_mask[ uppermod + 1 ];
                    134:                }
                    135:        }
                    136:        for (cnt = 0, cp = (char *)result; cnt < singcnt; cnt++) {
                    137:                lower = *dataptr++ - lowerbnd;
                    138:                if (lower < 0 || lower > upperbnd) {
                    139:                        ERROR("Value of %D out of set bounds\n", *--dataptr);
                    140:                }
                    141:                cp[ lower >> LG2BITSBYTE ] |= (1 << (lower & MSKBITSBYTE));
                    142:        }
                    143:        return(result);
                    144: }

unix.superglobalmegacorp.com

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