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