Annotation of 3BSD/cmd/pi/tCopy.c, revision 1.1.1.1

1.1       root        1:     /*
                      2:      * tCopy.c
                      3:      *
                      4:      * functions to copy pi trees to pTrees
                      5:      */
                      6: 
                      7: #include       "whoami"
                      8: 
                      9: #ifdef PTREE
                     10: 
                     11: #include       "0.h"
                     12: 
                     13: #include       "tree.h"
                     14: 
                     15:     /*
                     16:      * tCopy
                     17:      * a mongo switch statement to farm out the actual copying 
                     18:      * to the appropriate routines.
                     19:      * given a pointer to a pi tree branch, it returns a pPointer to
                     20:      * a pTree copy of that branch.
                     21:      */
                     22: pPointer
                     23: tCopy( node )
                     24:     int        *node;
                     25:     {
                     26: 
                     27:        if ( node == NIL )
                     28:            return pNIL;
                     29:        switch ( node[ 0 ] ) {
                     30:            case T_PROG:        
                     31:            case T_PDEC:
                     32:            case T_FDEC:        
                     33:                return PorFCopy( node );
                     34:            case T_TYPTR:
                     35:                return PtrTCopy( node );
                     36:            case T_TYPACK:
                     37:                return PackTCopy( node );
                     38:            case T_TYSCAL:
                     39:                return EnumTCopy( node );
                     40:            case T_TYRANG:
                     41:                return RangeTCopy( node );
                     42:            case T_TYARY:
                     43:                return ArrayTCopy( node );
                     44:            case T_TYFILE:
                     45:                return FileTCopy( node );
                     46:            case T_TYSET:
                     47:                return SetTCopy( node );
                     48:            case T_TYREC:
                     49:                return RecTCopy( node );
                     50:            case T_FLDLST:
                     51:                return FldlstCopy( node );
                     52:            case T_RFIELD:
                     53:                return FieldCopy( node );
                     54:            case T_TYVARPT:
                     55:                return VarntCopy( node );
                     56:            case T_TYVARNT:
                     57:                return VCaseCopy( node );
                     58:            case T_CSTAT:
                     59:                return CasedCopy( node );
                     60:            case T_PVAL:
                     61:            case T_PVAR:
                     62:                return ParamCopy( node );
                     63:            case T_CSTRNG:
                     64:                return sCopy( node[1] );
                     65:            case T_STRNG:
                     66:                return sCopy( node[2] );
                     67:            case T_PLUSC:
                     68:            case T_PLUS:
                     69:            case T_MINUSC:
                     70:            case T_MINUS:
                     71:            case T_NOT:
                     72:                return UnOpCopy( node );
                     73:            case T_ID:
                     74:                return ThreadSymbol( node[1] );
                     75:            case T_TYID:
                     76:                return ThreadSymbol( node[2] );
                     77:            case T_CINT:
                     78:            case T_CBINT:
                     79:                return iCopy( node[1] );
                     80:            case T_INT:
                     81:            case T_BINT:
                     82:                return iCopy( node[2] );
                     83:            case T_CFINT:
                     84:                return fCopy( node[1] );
                     85:            case T_FINT:
                     86:                return fCopy( node[2] );
                     87:            case T_LISTPP:
                     88:                return ListCopy( node );
                     89:            case T_PCALL:
                     90:                return PCallCopy( node );
                     91:            case T_BLOCK:
                     92:            case T_BSTL:
                     93:                return ListCopy( node[2] );
                     94:            case T_CASE:
                     95:                return CaseSCopy( node );
                     96:            case T_WITH:
                     97:                return WithCopy( node );
                     98:            case T_WHILE:
                     99:                return WhileCopy( node );
                    100:            case T_REPEAT:
                    101:                return RepeatCopy( node );
                    102:            case T_FORU:
                    103:            case T_FORD:
                    104:                return ForCopy( node );
                    105:            case T_IF:
                    106:            case T_IFEL:
                    107:                return IfCopy( node );
                    108:            case T_GOTO:
                    109:                return GotoCopy( node );
                    110:            case T_LABEL:
                    111:                return LabelCopy( node );
                    112:            case T_ASRT:
                    113:                return AssertCopy( node );
                    114:            case T_ASGN:
                    115:                return AssignCopy( node );
                    116:            case T_NIL:
                    117:                return NilCopy( node );
                    118:            case T_FCALL:
                    119:                return FCallCopy( node );
                    120:            case T_CSET:
                    121:                return SetCopy( node );
                    122:            case T_RANG:
                    123:                return RangeCopy( node );
                    124:            case T_VAR:
                    125:                return VarCopy( node );
                    126:            case T_ARY:
                    127:                return SubscCopy( node );
                    128:            case T_FIELD:
                    129:                return SelCopy( node );
                    130:            case T_PTR:
                    131:                return PtrCopy( node );
                    132:            case T_EQ:
                    133:            case T_LT:
                    134:            case T_GT:
                    135:            case T_LE:
                    136:            case T_GE:
                    137:            case T_NE:
                    138:            case T_IN:
                    139:            case T_ADD:
                    140:            case T_SUB:
                    141:            case T_MULT:
                    142:            case T_DIVD:
                    143:            case T_DIV:
                    144:            case T_MOD:
                    145:            case T_OR:
                    146:            case T_AND:
                    147:                return BinOpCopy( node );
                    148:            case T_WEXP:
                    149:                return WidthCopy( node );
                    150:            default:
                    151:                panic("tCopy");
                    152:        }
                    153:     }
                    154: 
                    155: 
                    156:     /*
                    157:      * copy a list of nodes into ListNodes
                    158:      * (with a hack for appending one list to another
                    159:      *     for example: labelled statements)
                    160:      * listnode[0]     T_LISTPP
                    161:      *         [1]     "list_element"
                    162:      *         [2]     "list_next"
                    163:      */
                    164: pPointer
                    165: ListCopy( listnode )
                    166:     int        *listnode;
                    167:     {
                    168:        pPointer        First;
                    169:        pPointer        After;
                    170:        int             *listp;
                    171:        pPointer        Item;
                    172:        pPointer        List;
                    173:        pPointer        Furthur;
                    174: 
                    175:        First = pNIL;
                    176:        After = pNIL;
                    177:        for ( listp = listnode ; listp != NIL ; listp = (int *) listp[2] ) {
                    178:            List = pNewNode( ListTAG , sizeof( struct ListNode ) );
                    179:            if ( First == pNIL )
                    180:                First = List;
                    181:            Item = tCopy( listp[1] );
                    182:            pDEF( List ).ListItem = Item;
                    183:            pDEF( List ).ListDown = pNIL;
                    184:            pDEF( List ).ListUp = After;
                    185:            if ( After != pNIL )
                    186:                pDEF( After ).ListDown = List;
                    187:            After = List;
                    188:            /*
                    189:             *  if ListItem is a ListNode whose ListUp is non-pNIL
                    190:             *  append that list to this list, using that ListUp
                    191:             *  as an additional ListItem.
                    192:             */
                    193:            Furthur = Item;
                    194:            if (  Furthur != pNIL
                    195:               && pTAG( Furthur ) == ListTAG
                    196:               && pUSE( Furthur ).ListUp != pNIL ) {
                    197:                Item = pUSE( Furthur ).ListUp;
                    198:                pDEF( List ).ListItem = Item;
                    199:                pDEF( Furthur ).ListUp = List;
                    200:                pDEF( List ).ListDown = Furthur;
                    201:                do {
                    202:                    After = Furthur;
                    203:                    Furthur = pUSE( After ).ListDown;
                    204:                } while ( Furthur != pNIL );
                    205:            }
                    206:        }
                    207:        return First;
                    208:     }
                    209: 
                    210:     /*
                    211:      * ListAppend
                    212:      * append a random item to the end of a list
                    213:      * (with a hack for appending one list to another
                    214:      *  e.g. labelled statments)
                    215:      */
                    216: pPointer
                    217: ListAppend( list , item )
                    218:     pPointer   list;
                    219:     pPointer   item;
                    220:     {
                    221:        pPointer        List = pNewNode( ListTAG , sizeof( struct ListNode ) );
                    222:        pPointer        First;
                    223:        pPointer        After;
                    224:        pPointer        Furthur;
                    225: 
                    226:        pDEF( List ).ListItem = item;
                    227:        pDEF( List ).ListDown = pNIL;
                    228:        First = After = list;
                    229:        if ( First == pNIL ) {
                    230:                First = List;
                    231:        } else {
                    232:                while ( ( Furthur = pUSE( After ).ListDown ) != pNIL )
                    233:                    After = Furthur;
                    234:                pDEF( After ).ListDown = List;
                    235:        }
                    236:        pDEF( List ).ListUp = After;
                    237:        /*
                    238:         *      if item is a ListNode whose ListUp is non-pNIL
                    239:         *      append that list to this list, using that ListUp
                    240:         *      as an additional ListItem.
                    241:         */
                    242:        Furthur = item;
                    243:        if (  Furthur != pNIL
                    244:           && pTAG( Furthur ) == ListTAG
                    245:           && pUSE( Furthur ).ListUp != pNIL ) {
                    246:            pDEF( List ).ListDown = Furthur;
                    247:            pDEF( List ).ListItem = pUSE( Furthur ).ListUp;
                    248:            pDEF( Furthur ).ListUp = List;
                    249:        }
                    250:        return First;
                    251:     }
                    252: 
                    253:     /*
                    254:      * iCopy
                    255:      * copy an integer (string) to an IntNode
                    256:      */
                    257: pPointer
                    258: iCopy( intstring )
                    259:     char *intstring;
                    260:     {
                    261:        pPointer        Int = pNewNode( IntTAG , sizeof( struct IntNode ) );
                    262: 
                    263:        pDEF( Int ).IntValue = atol( intstring );
                    264:        return Int;
                    265:     }
                    266: 
                    267:     /*
                    268:      * fCopy
                    269:      * copy a float (string) to a RealNode
                    270:      */
                    271: pPointer
                    272: fCopy( realstring )
                    273:     char *realstring;
                    274:     {
                    275:        pPointer        Real = pNewNode( RealTAG , sizeof( struct RealNode ) );
                    276: 
                    277:        pDEF( Real ).RealValue = atof( realstring );
                    278:        return Real;
                    279:     }
                    280: 
                    281:     /*
                    282:      * sCopy
                    283:      * copy a string to a StringNode
                    284:      */
                    285: pPointer
                    286: sCopy( string )
                    287:     char *string;
                    288:     {
                    289:        pPointer        String;
                    290: 
                    291:        if ( string == NIL )
                    292:            return pNIL;
                    293:        String = pNewNode( StringTAG , strlen( string ) + 1 );
                    294:        strcpy( pDEF( String ).StringValue , string );
                    295:        return String;
                    296:     }
                    297: 
                    298: #endif PTREE

unix.superglobalmegacorp.com

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