int fetch_propvals(dbref obj, const char *dir) { PropPtr p, pptr; int cnt = 0; char buf[BUFFER_LEN]; char name[BUFFER_LEN]; p = first_prop_nofetch(obj, dir, &pptr, name, sizeof(name)); while (p) { cnt = (cnt || propfetch(obj, p)); if (PropDir(p) || (PropFlags(p) & PROP_DIRUNLOADED)) { strcpyn(buf, sizeof(buf), dir); strcatn(buf, sizeof(buf), name); strcatn(buf, sizeof(buf), "/"); if (PropFlags(p) & PROP_DIRUNLOADED) { SetPFlags(p, (PropFlags(p) & ~PROP_DIRUNLOADED)); getproperties(input_file, obj, buf); } fetch_propvals(obj, buf); } p = next_prop(pptr, p, name, sizeof(name)); } return cnt; }
// calculates the "male optimal" stable marriage (i.e. there // is no stable marriage where any man prefers his match // over the one given here) a female optimal matching can be // found by swapping men and women // mpref: vector i is the list of i's preferred partners, in // *decreasing* order of preference (0 indexed) // fpref: as above, but for women // match: a vector (passed in with any size) filled so that // position i gives the man matched with woman i void stable_marriage(const vvi& mpref, const vvi& fpref, vi& match) { // initially no one matched match.resize(mpref.size(), -1); // get a map from (w, m) to w's "rank" for m vvi fmap(match.size(), vi(match.size())); for(int i = 0; i < match.size(); ++i) for(int j = 0; j < match.size(); ++j) fmap[i][fpref[i][j]] = j; vi next_prop(match.size(), 0); queue<int> mfree; for(int i = 0; i < match.size(); ++i) mfree.push(i); while(!mfree.empty()) { const int m = mfree.front(); const int w = mpref[m][next_prop[m]]; mfree.pop(); if(match[w] == -1) { match[w] = m; } else if(fmap[w][match[w]] > fmap[w][m]) { mfree.push(match[w]); match[w] = m; } else if(++next_prop[m] < match.size()) { mfree.push(m); } } }
int blessprops_wildcard(dbref player, dbref thing, const char *dir, const char *wild, int blessp) { char propname[BUFFER_LEN]; char wld[BUFFER_LEN]; char buf[BUFFER_LEN]; char buf2[BUFFER_LEN]; char *ptr, *wldcrd = wld; PropPtr propadr, pptr; int i, cnt = 0; int recurse = 0; #ifdef GOD_PRIV if(tp_strict_god_priv && !God(player) && God(OWNER(thing))) { notify(player,"Only God may touch what is God's."); return 0; } #endif strcpyn(wld, sizeof(wld), wild); i = strlen(wld); if (i && wld[i - 1] == PROPDIR_DELIMITER) strcatn(wld, sizeof(wld), "*"); for (wldcrd = wld; *wldcrd == PROPDIR_DELIMITER; wldcrd++) ; if (!strcmp(wldcrd, "**")) recurse = 1; for (ptr = wldcrd; *ptr && *ptr != PROPDIR_DELIMITER; ptr++) ; if (*ptr) *ptr++ = '\0'; propadr = first_prop(thing, (char *) dir, &pptr, propname, sizeof(propname)); while (propadr) { if (equalstr(wldcrd, propname)) { snprintf(buf, sizeof(buf), "%s%c%s", dir, PROPDIR_DELIMITER, propname); if (!Prop_System(buf) && ((!Prop_Hidden(buf) && !(PropFlags(propadr) & PROP_SYSPERMS)) || Wizard(OWNER(player)))) { if (!*ptr || recurse) { cnt++; if (blessp) { set_property_flags(thing, buf, PROP_BLESSED); snprintf(buf2, sizeof(buf2), "Blessed %s", buf); } else { clear_property_flags(thing, buf, PROP_BLESSED); snprintf(buf2, sizeof(buf2), "Unblessed %s", buf); } notify(player, buf2); } if (recurse) ptr = "**"; cnt += blessprops_wildcard(player, thing, buf, ptr, blessp); } } propadr = next_prop(pptr, propadr, propname, sizeof(propname)); } return cnt; }
/* * Support Routines */ static RealDTEntry skipProperties(RealDTEntry entry) { DeviceTreeNodeProperty *prop; int k; if (entry == NULL || entry->nProperties == 0) { return NULL; } else { prop = (DeviceTreeNodeProperty *) (entry + 1); for (k = 0; k < entry->nProperties; k++) { prop = next_prop(prop); } } return ((RealDTEntry) prop); }
void find_path( dbref loc, const char *pathname, char buf[BUFFER_LEN] ) { PropPtr propadr, pptr; #ifdef DISKBASE fetchprops(loc); #endif buf[0] = '\0'; propadr = first_prop(loc, "@u/d/", &pptr, buf); while (propadr > 0) { if( exit_prefix(buf, pathname) ) return; propadr = next_prop(pptr, propadr, buf); } buf[0] = '\0'; }
const char * mfn_dirprops(MFUNARGS) { char propname[BUFFER_LEN]; PropPtr propadr, pptr; char buf2[BUFFER_LEN]; int list_limit = MAX_MFUN_LIST_LEN; dbref obj; int outlen, nextlen; if(argc > 1) { obj = mesg_dbref_local(player, what, perms, argv[1]); if (obj == AMBIGUOUS || obj == UNKNOWN || obj == NOTHING || obj == HOME) ABORT_MPI("DIRPROPS","Match failed"); if (obj == PERMDENIED) ABORT_MPI("DIRPROPS",NOPERM_MESG); } else obj = what; buf[0] = '\0'; outlen = 0; #ifdef DISKBASE fetchprops(obj); #endif propadr = first_prop(obj, argv[0], &pptr, propname); while ((propadr > 0) && *propname) { if ( ( !Prop_Hidden(propname) && !(PropFlags(propadr) & PROP_SYSPERMS)) || (Permlevel(perms) >= tp_hidden_prop_mlevel)) { sprintf(buf2, "%s", propname); nextlen = strlen(buf2); if ((outlen + nextlen) >= (BUFFER_LEN - 3)) break; if (outlen) strcat((buf+(outlen++)), "\r"); strcat((buf + outlen), buf2); outlen += nextlen; list_limit--; } propadr = next_prop(pptr, propadr, propname); } return buf; }
int DTIterateProperties(DTPropertyIterator iterator, char **foundProperty) { RealDTPropertyIterator iter = iterator; if (iter->currentIndex >= iter->entry->nProperties) { *foundProperty = NULL; return kIterationDone; } else { iter->currentIndex++; if (iter->currentIndex == 1) { iter->currentProperty = (DeviceTreeNodeProperty *) (iter->entry + 1); } else { iter->currentProperty = next_prop(iter->currentProperty); } *foundProperty = iter->currentProperty->name; return kSuccess; } }
int DTGetProperty(const DTEntry entry, const char *propertyName, void **propertyValue, int *propertySize) { DeviceTreeNodeProperty *prop; int k; if (entry == NULL || entry->nProperties == 0) { return kError; } else { prop = (DeviceTreeNodeProperty *) (entry + 1); for (k = 0; k < entry->nProperties; k++) { if (strcmp(prop->name, propertyName) == 0) { *propertyValue = (void *) (((int)prop) + sizeof(DeviceTreeNodeProperty)); *propertySize = prop->length; return kSuccess; } prop = next_prop(prop); } } return kError; }
INTN DTGetProperty(CONST DTEntry entry, CONST CHAR8 *propertyName, VOID **propertyValue, UINT32 *propertySize) { DeviceTreeNodeProperty *prop; UINTN k; if (entry == NULL || entry->nProperties == 0) { return kError; } else { prop = (DeviceTreeNodeProperty *) (entry + 1); for (k = 0; k < entry->nProperties; k++) { if (AsciiStrCmp((CHAR8*)prop->name, (CHAR8*)propertyName) == 0) { *propertyValue = (VOID *) (((UINT8*)prop) + sizeof(DeviceTreeNodeProperty)); *propertySize = prop->length; return kSuccess; } prop = next_prop(prop); } } return kError; }
void check_properties(const char *dir, dbref obj) { int val; char *buf, *prop; PropPtr pptr; PropPtr pref; char name[BUFFER_LEN]; pref = first_prop(obj, dir, &pptr, name); while (pref > 0) { buf = (char *) malloc(strlen(dir) + strlen(name) + 2); (void) strcat(strcpy(buf, dir), name); if (prop = (char *) get_property_class(obj, buf)) printf("%s%c%s\n", buf + 1, PROP_DELIMITER, uncompress(prop)); else if (val = get_property_value(obj, buf)) printf("%s%c^%d\n", buf + 1, PROP_DELIMITER, val); if (is_propdir(obj, buf)) check_properties((char *) strcat(buf, "/"), obj); free(buf); pref = next_prop(pptr, pref, name); } }
void ofw_construct_node(char **bufPtr, device_node_t *parent, device_node_t **sib, device_node_t **nodelist, unsigned long asic_base) { DeviceTreeNode *bufNode = (DeviceTreeNode *) *bufPtr; DeviceTreeNodeProperty *bufProp; device_node_t *node, *kid = NULL; property_t *prop; reg_property_t *reg; pci_reg_property_t *pciOFW; char *propData; int p, i; long *seenAAPL = NULL; int seenAssigned = FALSE; if (bufNode->nProperties == 0) return; node = (device_node_t *) ofw_alloc(sizeof(*node)); bzero((char *) node, sizeof(*node)); node->parent = parent; prop = NULL; *bufPtr = (char *) (bufNode + 1); if (*nodelist) (*nodelist)->allnext = node; else ofw_node_list = node; *nodelist = node; if (*sib) (*sib)->sibling = node; *sib = node; if (parent && parent->child == NULL) parent->child = node; for (p = 0; p < bufNode->nProperties; p++) { // Iterate through the list of properties. bufProp = (DeviceTreeNodeProperty *) *bufPtr; propData = (char *) (bufProp+1); *bufPtr = (char *) (next_prop(bufProp)); if (prop) { prop->next = ofw_alloc(sizeof(property_t)); prop = prop->next; } else { prop = ofw_alloc(sizeof(property_t)); node->properties = prop; } bzero((char *) prop, sizeof(*prop)); prop->value = (unsigned char *) propData; prop->length = bufProp->length; prop->name = bufProp->name; /* * Look through each property and build * up a convience shopping list for the node */ if (strcmp(bufProp->name, "name") == 0) { node->name = ofw_alloc(prop->length+1); strncpy(node->name, propData, prop->length); node->name[prop->length] = 0; /* Kind of device - dbdma, scsi, pram, etc */ } else if (strcmp(bufProp->name, "device_type") == 0) node->type = propData; /* Look for assigned addresses */ else if(strcmp(bufProp->name, "assigned-addresses") == 0) { seenAssigned = TRUE; node->addrs = reg = (reg_property_t *) ofw_alloc(bufProp->length); pciOFW = (pci_reg_property_t *) propData; for (i = 0; i < bufProp->length; reg++, pciOFW++) { reg->address = pciOFW->addr.addr_low; reg->size = pciOFW->size_low; i += sizeof(pci_reg_property_t); } node->n_addrs = i / sizeof(pci_reg_property_t); /* Look for register address */ } else if (strcmp(bufProp->name, "reg") == 0) { /* If the assigned-addresses property has * already been seen, don't bother with */ if (seenAssigned) continue; node->n_addrs = bufProp->length/sizeof(reg_property_t); node->addrs = (reg_property_t *)ofw_alloc(bufProp->length); bcopy_nc(propData, (char*)node->addrs, bufProp->length); /* Adjust the addresses - most are relative to * the asic which contains them */ for (i = 0; i < node->n_addrs; i++) node->addrs[i].address += asic_base; } else if (strcmp(bufProp->name, "AAPL,interrupts") == 0) { node->n_intrs = prop->length / sizeof(long); node->intrs = (unsigned long *) prop->value; } else if (strcmp(bufProp->name, "AAPL,address") == 0) seenAAPL = (long *) propData; } #if 0 /* * Override the register address values with Apple * defined ones if the property was seen. */ if (seenAAPL && !seenAssigned && node->n_addrs) { for (i = 0; i < node->n_addrs; i++) node->addrs[i].address = seenAAPL[i]; } #endif /* Is there a better way? */ if (node->type && node->n_addrs && strcmp(node->type, "dbdma") == 0) asic_base = node->addrs[0].address; kid = NULL; parent = node; for (i = 0; i < bufNode->nChildren; i++) ofw_construct_node(bufPtr, parent, &kid, nodelist, asic_base); }