1*35196Smarc /* 2*35196Smarc 3*35196Smarc * Copyright (c) 1984, 1985, 1986 AT&T 4*35196Smarc * All Rights Reserved 5*35196Smarc 6*35196Smarc * THIS IS UNPUBLISHED PROPRIETARY SOURCE 7*35196Smarc * CODE OF AT&T. 8*35196Smarc * The copyright notice above does not 9*35196Smarc * evidence any actual or intended 10*35196Smarc * publication of such source code. 11*35196Smarc 12*35196Smarc */ 13*35196Smarc /* @(#)namscan.c 1.1 */ 14*35196Smarc 15*35196Smarc /* 16*35196Smarc * NAMSCAN.C 17*35196Smarc * 18*35196Smarc * GSCAN_ALL (FN, ROOT) 19*35196Smarc * Execute FN at each node in the linked memory trees, 20*35196Smarc * which are given by ROOT. 21*35196Smarc * 22*35196Smarc * GSCAN_SOME (FN, ROOT, MASK, FLAG) 23*35196Smarc * Execute FN at those nodes in the linked memory trees 24*35196Smarc * that have certain attributes, as determined by MASK and 25*35196Smarc * FLAG. ROOT is the first of the list of memory trees. 26*35196Smarc * 27*35196Smarc * SCAN_ALL (FN, ROOT) 28*35196Smarc * Execute function FN at each of the Namnods in the tree 29*35196Smarc * given by ROOT. 30*35196Smarc * 31*35196Smarc */ 32*35196Smarc 33*35196Smarc #include "flags.h" 34*35196Smarc #include "name.h" 35*35196Smarc 36*35196Smarc /* These routines are defined by this module */ 37*35196Smarc void gscan_all(); 38*35196Smarc void scan_all(); 39*35196Smarc void gscan_some(); 40*35196Smarc 41*35196Smarc static int scanmask; 42*35196Smarc static int scanflag; 43*35196Smarc 44*35196Smarc 45*35196Smarc /* 46*35196Smarc * GSCAN_ALL (FN, ROOT) 47*35196Smarc * 48*35196Smarc * int (*FN)(); 49*35196Smarc * 50*35196Smarc * struct Amemory *root; 51*35196Smarc * 52*35196Smarc * Execute FN at each node in the linked memory trees. 53*35196Smarc * Note that the first tree need not exist. 54*35196Smarc */ 55*35196Smarc 56*35196Smarc void gscan_all(fn, root) 57*35196Smarc void (*fn)(); 58*35196Smarc struct Amemory *root; 59*35196Smarc { 60*35196Smarc register struct Amemory *app = root; 61*35196Smarc while(app) 62*35196Smarc { 63*35196Smarc scan_all(fn,app); 64*35196Smarc app = app->nexttree; 65*35196Smarc } 66*35196Smarc return; 67*35196Smarc } 68*35196Smarc 69*35196Smarc 70*35196Smarc /* 71*35196Smarc * GSCAN_SOME (FN, ROOT, MASK, FLAG) 72*35196Smarc * int (*FN)(); 73*35196Smarc * struct Amemory *ROOT; 74*35196Smarc * int MASK; 75*35196Smarc * int FLAG; 76*35196Smarc * 77*35196Smarc * Execute FN at each of the Namnods in the trees given by ROOT 78*35196Smarc * that meet certain criteria, as determined by MASK and FLAG. 79*35196Smarc * If flag is non-zero then at least one of these mask bits must be on. 80*35196Smarc * If flag is zero then all the mask bits must be off to match. 81*35196Smarc */ 82*35196Smarc 83*35196Smarc void gscan_some(fn,root,mask,flag) 84*35196Smarc void (*fn)(); 85*35196Smarc int mask,flag; 86*35196Smarc struct Amemory *root; 87*35196Smarc { 88*35196Smarc scanmask = mask; 89*35196Smarc scanflag = flag; 90*35196Smarc gscan_all(fn,root); 91*35196Smarc scanmask = scanflag = 0; 92*35196Smarc } 93*35196Smarc 94*35196Smarc /* 95*35196Smarc * SCAN_ALL (FN, ROOT) 96*35196Smarc * int (*FN)(); 97*35196Smarc * struct Amemory *ROOT; 98*35196Smarc * 99*35196Smarc * Execute FN at each node in the tree given by ROOT, according 100*35196Smarc * to the values of scanmask and scanflag, which are established 101*35196Smarc * in scan_some(). 102*35196Smarc */ 103*35196Smarc 104*35196Smarc void scan_all(fn,root) 105*35196Smarc void (*fn)(); 106*35196Smarc struct Amemory *root; 107*35196Smarc { 108*35196Smarc register struct Namnod *np; 109*35196Smarc register int i; 110*35196Smarc register int smask = scanmask^N_AVAIL; 111*35196Smarc int k; 112*35196Smarc for(i=0;i < root->memsize;i++) 113*35196Smarc for(np=root->memhead[i];np;np= np->namnxt) 114*35196Smarc { 115*35196Smarc k = np->value.namflg&smask; 116*35196Smarc if((scanflag?scanflag&k:k==0)) 117*35196Smarc { 118*35196Smarc if (attest (np, ARRAY)) 119*35196Smarc { 120*35196Smarc register struct Namaray *ap=arayp(np); 121*35196Smarc if(ap == NULL) 122*35196Smarc (*fn)(np); 123*35196Smarc else 124*35196Smarc { 125*35196Smarc int i = ap->adot; 126*35196Smarc for (ap->adot=i=0; i<=ap->maxi;i++) 127*35196Smarc { 128*35196Smarc ap->adot = i; 129*35196Smarc if (ap->val[i]) 130*35196Smarc (*fn)(np); 131*35196Smarc i = ap->adot; 132*35196Smarc } 133*35196Smarc } 134*35196Smarc } 135*35196Smarc else if (attest(np,~N_DEFAULT) || np->value.namval.cp) 136*35196Smarc (*fn)(np); 137*35196Smarc } 138*35196Smarc } 139*35196Smarc } 140*35196Smarc 141