int compare(const char *dest) { if (options & AR_TR) return (!strncmp(chdr.name, rname(dest), OLDARMAXNAME)); return (!strcmp(chdr.name, rname(dest))); }
int cpwd() { msg.action = CPWD; int i; char tmp_password1[20]; char tmp_password2[20]; printf("\t\t\033[47;31m 请输入新密码:\033[0m"); for(i = 0; i < 20; i++) { tmp_password1[i] = getch(); if(tmp_password1[i] == '\r') { tmp_password1[i] = '\0'; break; } printf("*"); } printf("\n"); printf("\t\t\033[47;31m 确认密码:\033[0m"); for(i = 0; i < 20; i++) { tmp_password2[i] = getch(); if(tmp_password2[i] == '\r') { tmp_password2[i] = '\0'; break; } printf("*"); } printf("\n"); if(strcmp(tmp_password1,tmp_password2) != 0) { printf("\t\t\033[47;31m 两次输入不同,请重新改密:\033[0m"); rname(); } else { strcpy(msg.password,tmp_password1); if(write(sockfd,&msg,sizeof(msg))==-1) { fprintf(stderr,"regist write Error:%s\n",strerror(errno)); } } printf("\t\t\033[47;31m 按任意键返回!\033[0m\n"); getchar(); getchar(); return 0; }
void rput(Map *map, char *name, vlong v) { Reglist *rp; int ret; rp = rname(name); if (!rp) error("invalid register name"); if (rp->rflags & RRDONLY) error("register is read-only"); switch (rp->rformat) { case 'x': ret = put2(map, rp->roffs, (ushort) v); break; case 'X': case 'f': case 'F': ret = put4(map, rp->roffs, (long) v); break; case 'Y': ret = put8(map, rp->roffs, v); break; default: ret = -1; } if (ret < 0) error("can't write register"); }
uvlong rget(Map *map, char *name) { Reglist *rp; rp = rname(name); if (!rp) error("invalid register name"); return getreg(map, rp); }
void CpuAttributes::publish( ClassAd* cp, amask_t how_much ) { if( IS_UPDATE(how_much) || IS_PUBLIC(how_much) ) { cp->Assign( ATTR_VIRTUAL_MEMORY, (int)c_virt_mem ); cp->Assign( ATTR_TOTAL_DISK, (int)c_total_disk ); cp->Assign( ATTR_DISK, (int)c_disk ); } if( IS_TIMEOUT(how_much) || IS_PUBLIC(how_much) ) { cp->Assign( ATTR_CONDOR_LOAD_AVG, rint(c_condor_load * 100) / 100.0 ); cp->Assign( ATTR_LOAD_AVG, rint((c_owner_load + c_condor_load) * 100) / 100.0 ); cp->Assign( ATTR_KEYBOARD_IDLE, (int)c_idle ); // ConsoleIdle cannot be determined on all platforms; thus, only // advertise if it is not -1. if( c_console_idle != -1 ) { cp->Assign( ATTR_CONSOLE_IDLE, (int)c_console_idle ); } } if( IS_STATIC(how_much) || IS_PUBLIC(how_much) ) { cp->Assign( ATTR_MEMORY, c_phys_mem ); cp->Assign( ATTR_CPUS, c_num_cpus ); cp->Assign( ATTR_TOTAL_SLOT_MEMORY, c_slot_mem ); cp->Assign( ATTR_TOTAL_SLOT_DISK, (int)c_slot_disk ); cp->Assign( ATTR_TOTAL_SLOT_CPUS, c_num_slot_cpus ); // publish local resource quantities for this slot for (slotres_map_t::iterator j(c_slotres_map.begin()); j != c_slotres_map.end(); ++j) { string rname(j->first.c_str()); *(rname.begin()) = toupper(*(rname.begin())); string attr; formatstr(attr, "%s%s", "", rname.c_str()); cp->Assign(attr.c_str(), int(j->second)); formatstr(attr, "%s%s", ATTR_TOTAL_SLOT_PREFIX, rname.c_str()); cp->Assign(attr.c_str(), int(c_slottot_map[j->first])); } } }
const char *write_regionname(const region * r, const faction * f, char *buffer, size_t size) { char *buf = (char *)buffer; const struct locale *lang = f ? f->locale : 0; if (r == NULL) { strlcpy(buf, "(null)", size); } else { plane *pl = rplane(r); int nx = r->x, ny = r->y; pnormalize(&nx, &ny, pl); adjust_coordinates(f, &nx, &ny, pl, r); slprintf(buf, size, "%s (%d,%d)", rname(r, lang), nx, ny); } return buffer; }
bool gkScene::hasObject(const gkHashedString& ob) { bool result = m_objects.find(ob) != GK_NPOS; if (!result) { gkGameObjectManager& mgr = gkGameObjectManager::getSingleton(); gkResourceName rname(ob, m_name.group); if (mgr.exists(rname)) { gkGameObject* obj = mgr.getByName<gkGameObject>(rname); if (obj && obj->getOwner() == this) result = true; } } return result; }
gkGameObject* gkScene::getObject(const gkHashedString& name) { UTsize pos = m_objects.find(name); if (pos != GK_NPOS) return m_objects.at(pos); else { gkGameObjectManager& mgr = gkGameObjectManager::getSingleton(); gkResourceName rname(name, getGroupName()); if (mgr.exists(rname)) { gkGameObject* obj = mgr.getByName<gkGameObject>(rname); if (obj && obj->getOwner() == this) return obj; } } return 0; }
int PWSfileV1V2::WriteV2Header() { CItemData header; // Fill out with V2-specific info // To make a dictionary attack a little harder, we make the length // of the first record (Name) variable, by appending variable length randomness // to the fixed string // OOPS - can't do this yet, since previous versions (pre-2.14) read the name // (in ReadV2Header) // and compare it directly to VersionString to check version - a small // mistake that would cause a pre-2.14 executable to barf reading a database // written by 2.14 and later. // #idef-ing this out, while correcting the code // in ReadV2Header. Perhaps this can be fixed a year from now? #ifdef BREAK_PRE_2_14_COMPATIBILITY unsigned int rlen = RangeRand(62) + 2; // 64 is a trade-off... char *rbuf = new char[rlen]; PWSrand::GetInstance()->GetRandomData(rbuf, rlen-1); rbuf[rlen-1] = TCHAR('\0'); // although zero may be there before - who cares? stringT rname(V2ItemName); rname += rbuf; delete[] rbuf; header.SetName(rname, _T("")); #else header.SetName(V2ItemName, _T("")); #endif /* BREAK_PRE_2_14_COMPATIBILITY */ header.SetPassword(VersionString); header.SetNotes(m_hdr.m_prefString); // need to fallback to V17, since the record // won't be readable otherwise! VERSION sv = m_curversion; m_curversion = V17; int status = WriteRecord(header); // restore after writing V17-format header m_curversion = sv; m_hdr.m_nCurrentMajorVersion = 2; m_hdr.m_nCurrentMinorVersion = 0; return status; }
int value(const void *a0, const void *b0) { struct nlist * const *a = a0, * const *b = b0; if (SYMBOL_TYPE((*a)->n_type) == N_UNDF) if (SYMBOL_TYPE((*b)->n_type) == N_UNDF) return(0); else return(-1); else if (SYMBOL_TYPE((*b)->n_type) == N_UNDF) return(1); if (rev) { if ((*a)->n_value == (*b)->n_value) return(rname(a0, b0)); return((*b)->n_value > (*a)->n_value ? 1 : -1); } else { if ((*a)->n_value == (*b)->n_value) return(fname(a0, b0)); return((*a)->n_value > (*b)->n_value ? 1 : -1); } }
/* * main -- * main basically uses getopt to parse options and calls the appropriate * functions. Some hacks that let us be backward compatible with 4.3 ar * option parsing and sanity checking. */ int main(int argc, char *argv[]) { int c; char *p; int (*fcall)(char **); if (argc < 3) usage(); /* * Historic versions didn't require a '-' in front of the options. * Fix it, if necessary. */ if (*argv[1] != '-') { size_t len; len = (u_int)(strlen(argv[1]) + 2); if (!(p = malloc(len))) err(1, NULL); *p = '-'; (void)strncpy(p + 1, argv[1], len - 1); argv[1] = p; } while ((c = getopt(argc, argv, "abcCdilmopqrTtuvx")) != -1) { switch(c) { case 'a': options |= AR_A; break; case 'b': case 'i': options |= AR_B; break; case 'c': options |= AR_C; break; case 'C': options |= AR_CC; break; case 'd': options |= AR_D; fcall = delete; break; case 'l': /* not documented, compatibility only */ envtmp = "."; break; case 'm': options |= AR_M; fcall = move; break; case 'o': options |= AR_O; break; case 'p': options |= AR_P; fcall = print; break; case 'q': options |= AR_Q; fcall = append; break; case 'r': options |= AR_R; fcall = replace; break; case 'T': options |= AR_TR; break; case 't': options |= AR_T; fcall = contents; break; case 'u': options |= AR_U; break; case 'v': options |= AR_V; break; case 'x': options |= AR_X; fcall = extract; break; default: usage(); } } argv += optind; argc -= optind; /* One of -dmpqrtx required. */ if (!(options & (AR_D|AR_M|AR_P|AR_Q|AR_R|AR_T|AR_X))) { warnx("one of options -dmpqrtx is required"); usage(); } /* Only one of -a and -bi allowed. */ if (options & AR_A && options & AR_B) { warnx("only one of -a and -[bi] options allowed"); usage(); } /* -ab require a position argument. */ if (options & (AR_A|AR_B)) { if (!(posarg = *argv++)) { warnx("no position operand specified"); usage(); } posname = rname(posarg); } /* -d only valid with -Tv. */ if (options & AR_D && options & ~(AR_D|AR_TR|AR_V)) badoptions("-d"); /* -m only valid with -abiTv. */ if (options & AR_M && options & ~(AR_A|AR_B|AR_M|AR_TR|AR_V)) badoptions("-m"); /* -p only valid with -Tv. */ if (options & AR_P && options & ~(AR_P|AR_TR|AR_V)) badoptions("-p"); /* -q only valid with -cTv. */ if (options & AR_Q && options & ~(AR_C|AR_Q|AR_TR|AR_V)) badoptions("-q"); /* -r only valid with -abcuTv. */ if (options & AR_R && options & ~(AR_A|AR_B|AR_C|AR_R|AR_U|AR_TR|AR_V)) badoptions("-r"); /* -t only valid with -Tv. */ if (options & AR_T && options & ~(AR_T|AR_TR|AR_V)) badoptions("-t"); /* -x only valid with -CouTv. */ if (options & AR_X && options & ~(AR_O|AR_U|AR_TR|AR_V|AR_X|AR_CC)) badoptions("-x"); if (!(archive = *argv++)) { warnx("no archive specified"); usage(); } exit((*fcall)(argv)); }
/* * main -- * main basically uses getopt to parse options and calls the appropriate * functions. Some hacks that let us be backward compatible with 4.3 ar * option parsing and sanity checking. */ int main(int argc, char *argv[]) { extern char *__progname; int c; char *p; int (*fcall)(char **); fcall = NULL; if (strcmp(__progname, "ranlib") == 0) { if (argc < 2) usage(); options |= AR_S; while ((c = getopt(argc, argv, "t")) != -1) switch(c) { case 't': options |= AR_T; break; default: usage(); } } else { if (argc < 3) usage(); /* * Historic versions didn't require a '-' in front of the * options. Fix it, if necessary. */ if (*argv[1] != '-') { size_t len; len = (u_int)(strlen(argv[1]) + 2); if (!(p = malloc(len))) err(1, NULL); *p = '-'; (void)strlcpy(p + 1, argv[1], len - 1); argv[1] = p; } while ((c = getopt(argc, argv, "abcCdilmopqrsTtuvx")) != -1) switch(c) { case 'a': options |= AR_A; break; case 'b': case 'i': options |= AR_B; break; case 'c': options |= AR_C; break; case 'C': options |= AR_CC; break; case 'd': options |= AR_D; fcall = delete; break; case 'l': /* * "local" tmp-files option; * ignored for compatibility */ break; case 'm': options |= AR_M; fcall = move; break; case 'o': options |= AR_O; break; case 'p': options |= AR_P; fcall = print; break; case 'q': /* TODO optimise symdef generation for -c */ options |= AR_Q; fcall = append; break; case 'r': options |= AR_R; fcall = replace; break; case 's': options |= AR_S; break; case 'T': options |= AR_TR; break; case 't': options |= AR_T; fcall = contents; break; case 'u': options |= AR_U; break; case 'v': options |= AR_V; break; case 'x': options |= AR_X; fcall = extract; break; default: usage(); } } argv += optind; argc -= optind; /* single -s is a ranlib for the ar files given */ if (fcall == NULL && (options & AR_S)) exit(ranlib(argv)); /* One of -dmpqrtx required. */ if (!(options & (AR_D|AR_M|AR_P|AR_Q|AR_R|AR_T|AR_X))) { warnx("one of options -dmpqrtx is required"); usage(); } /* Only one of -a and -bi allowed. */ if (options & AR_A && options & AR_B) { warnx("only one of -a and -[bi] options allowed"); usage(); } /* -ab require a position argument. */ if (options & (AR_A|AR_B)) { if (!(posarg = *argv++)) { warnx("no position operand specified"); usage(); } posname = rname(posarg); } /* -d only valid with -sTv. */ if (options & AR_D && options & ~(AR_D|AR_TR|AR_S|AR_V)) badoptions("-d"); /* -m only valid with -abiTsv. */ if (options & AR_M && options & ~(AR_A|AR_B|AR_M|AR_TR|AR_S|AR_V)) badoptions("-m"); /* -p only valid with -Tv. */ if (options & AR_P && options & ~(AR_P|AR_TR|AR_V)) badoptions("-p"); /* -q only valid with -csTv. */ if (options & AR_Q && options & ~(AR_C|AR_Q|AR_TR|AR_S|AR_V)) badoptions("-q"); /* -r only valid with -abcuTsv. */ if (options & AR_R && options & ~(AR_A|AR_B|AR_C|AR_R|AR_U|AR_TR|AR_S|AR_V)) badoptions("-r"); /* -t only valid with -Tv. */ if (options & AR_T && options & ~(AR_T|AR_TR|AR_V)) badoptions("-t"); /* -x only valid with -CouTv. */ if (options & AR_X && options & ~(AR_O|AR_U|AR_TR|AR_V|AR_X|AR_CC)) badoptions("-x"); if (!(archive = *argv++)) { warnx("no archive specified"); usage(); } exit((*fcall)(argv)); }
static order *plan_dragon(unit * u) { attrib *ta = a_find(u->attribs, &at_targetregion); region *r = u->region; region *tr = NULL; bool move = false; order *long_order = NULL; if (ta == NULL) { move |= (r->land == 0 || r->land->peasants == 0); /* when no peasants, move */ move |= (r->land == 0 || r->land->money == 0); /* when no money, move */ } move |= chance(0.04); /* 4% chance to change your mind */ if (u_race(u) == get_race(RC_WYRM) && !move) { unit *u2; for (u2 = r->units; u2; u2 = u2->next) { /* wyrme sind einzelgänger */ if (u2 == u) { /* we do not make room for newcomers, so we don't need to look at them */ break; } if (u2 != u && u_race(u2) == u_race(u) && chance(0.5)) { move = true; break; } } } if (move) { /* dragon gets bored and looks for a different place to go */ ta = set_new_dragon_target(u, u->region, DRAGON_RANGE); } else ta = a_find(u->attribs, &at_targetregion); if (ta != NULL) { tr = (region *)ta->data.v; if (tr == NULL || !path_exists(u->region, tr, DRAGON_RANGE, allowed_dragon)) { ta = set_new_dragon_target(u, u->region, DRAGON_RANGE); if (ta) tr = findregion(ta->data.sa[0], ta->data.sa[1]); } } if (tr != NULL) { assert(long_order == NULL); switch (old_race(u_race(u))) { case RC_FIREDRAGON: long_order = make_movement_order(u, tr, 4, allowed_dragon); break; case RC_DRAGON: long_order = make_movement_order(u, tr, 3, allowed_dragon); break; case RC_WYRM: long_order = make_movement_order(u, tr, 1, allowed_dragon); break; default: break; } if (long_order) { reduce_weight(u); } if (rng_int() % 100 < 15) { const struct locale *lang = u->faction->locale; /* do a growl */ if (rname(tr, lang)) { addlist(&u->orders, create_order(K_MAIL, lang, "%s '%s... %s %s %s'", LOC(lang, parameters[P_REGION]), random_growl(), u->number == 1 ? "Ich rieche" : "Wir riechen", "etwas in", rname(tr, u->faction->locale))); } } } else { /* we have no target. do we like it here, then? */ long_order = get_money_for_dragon(u->region, u, income(u)); if (long_order == NULL) { /* money is gone, need a new target */ set_new_dragon_target(u, u->region, DRAGON_RANGE); } else if (u_race(u) != get_race(RC_FIREDRAGON)) { /* neue dracoiden! */ if (r->land && !fval(r->terrain, FORBIDDEN_REGION)) { int ra = 20 + rng_int() % 100; if (get_money(u) > ra * 50 + 100 && rng_int() % 100 < 50) { recruit_dracoids(u, ra); } } } } if (long_order == NULL) { skill_t sk = SK_PERCEPTION; /* study perception (or a random useful skill) */ while (!skill_enabled(sk) || u_race(u)->bonus[sk] < -5) { sk = (skill_t)(rng_int() % MAXSKILLS); } long_order = create_order(K_STUDY, u->faction->locale, "'%s'", skillname(sk, u->faction->locale)); } return long_order; }
void MachAttributes::publish( ClassAd* cp, amask_t how_much) { if( IS_STATIC(how_much) || IS_PUBLIC(how_much) ) { // STARTD_IP_ADDR cp->Assign( ATTR_STARTD_IP_ADDR, daemonCore->InfoCommandSinfulString() ); cp->Assign( ATTR_ARCH, m_arch ); cp->Assign( ATTR_OPSYS, m_opsys ); if (m_opsysver) { cp->Assign( ATTR_OPSYSVER, m_opsysver ); } cp->Assign( ATTR_OPSYS_AND_VER, m_opsys_and_ver ); if (m_opsys_major_ver) { cp->Assign( ATTR_OPSYS_MAJOR_VER, m_opsys_major_ver ); } if (m_opsys_name) { cp->Assign( ATTR_OPSYS_NAME, m_opsys_name ); } if (m_opsys_long_name) { cp->Assign( ATTR_OPSYS_LONG_NAME, m_opsys_long_name ); } if (m_opsys_short_name) { cp->Assign( ATTR_OPSYS_SHORT_NAME, m_opsys_short_name ); } if (m_opsys_legacy) { cp->Assign( ATTR_OPSYS_LEGACY, m_opsys_legacy ); } cp->Assign( ATTR_UID_DOMAIN, m_uid_domain ); cp->Assign( ATTR_FILE_SYSTEM_DOMAIN, m_filesystem_domain ); cp->Assign( ATTR_HAS_IO_PROXY, true ); cp->Assign( ATTR_CHECKPOINT_PLATFORM, m_ckptpltfrm ); #if defined ( WIN32 ) // publish the Windows version information if ( m_got_windows_version_info ) { cp->Assign( ATTR_WINDOWS_MAJOR_VERSION, (int)m_window_version_info.dwMajorVersion ); cp->Assign( ATTR_WINDOWS_MINOR_VERSION, (int)m_window_version_info.dwMinorVersion ); cp->Assign( ATTR_WINDOWS_BUILD_NUMBER, (int)m_window_version_info.dwBuildNumber ); // publish the extended Windows version information if we // have it at our disposal if ( sizeof ( OSVERSIONINFOEX ) == m_window_version_info.dwOSVersionInfoSize ) { cp->Assign( ATTR_WINDOWS_SERVICE_PACK_MAJOR, (int)m_window_version_info.wServicePackMajor ); cp->Assign( ATTR_WINDOWS_SERVICE_PACK_MINOR, (int)m_window_version_info.wServicePackMinor ); cp->Assign( ATTR_WINDOWS_PRODUCT_TYPE, (int)m_window_version_info.wProductType ); } } /* Publish .Net versions installed on current machine assuming the option is turned on.. */ if(param_boolean("STARTD_PUBLISH_DOTNET", true)) { if(m_dot_Net_Versions) cp->Assign(ATTR_DOTNET_VERSIONS, m_dot_Net_Versions); } // publish values from the window's registry as specified // in the STARTD_PUBLISH_WINREG param. // m_lst_static.Rewind(); while (AttribValue *pav = m_lst_static.Next()) { if (pav) pav->AssignToClassAd(cp); } /* char * pubreg_param = param("STARTD_PUBLISH_WINREG"); if (pubreg_param) { StringList reg_list(pubreg_param, ";"); reg_list.rewind(); while(char * reg_item = reg_list.next()) { // if the reg_item is of the form attr_name=reg_path; // then skip over the attr_name and '=' and trailing // whitespace. But if the = is after the first \, then // it's a part of the reg_path, so ignore it. // const char * pkey = strchr(reg_item, '='); const char * pbs = strchr(reg_item, '\\'); if (pkey && ( ! pbs || pkey < pbs)) { ++pkey; // skip the '=' } else { pkey = reg_item; } // skip any leading whitespace in the reg_path while (isspace(pkey[0])) ++pkey; // if the keyname begins with 32 or 64, use that to designate either // the WOW64 or WOW32 view of the registry, but don't pass the // leading number on to the lower level code. int options = 0; if (isdigit(pkey[0])) { options = atoi(pkey); while (isdigit(pkey[0])) { ++pkey; } } // get the registry value of the given key, and assign it // to the given attribute name, or a generated name. // char * value = get_windows_reg_value(pkey, NULL, options); if (value) { char * attr_name = generate_reg_key_attr_name("WINREG_", reg_item); if (attr_name) { cp->Assign(attr_name, value); free (attr_name); } free(value); } } free (pubreg_param); } */ #endif // defined ( WIN32 ) } if( IS_UPDATE(how_much) || IS_PUBLIC(how_much) ) { cp->Assign( ATTR_TOTAL_VIRTUAL_MEMORY, (int)m_virt_mem ); cp->Assign( ATTR_TOTAL_CPUS, m_num_cpus ); cp->Assign( ATTR_TOTAL_MEMORY, m_phys_mem ); // KFLOPS and MIPS are only conditionally computed; thus, only // advertise them if we computed them. if ( m_kflops > 0 ) { cp->Assign( ATTR_KFLOPS, m_kflops ); } if ( m_mips > 0 ) { cp->Assign( ATTR_MIPS, m_mips ); } #if defined(WIN32) if ( m_local_credd != NULL ) { cp->Assign(ATTR_LOCAL_CREDD, m_local_credd); } #endif string machine_resources = "cpus memory disk swap"; // publish any local resources for (slotres_map_t::iterator j(m_machres_map.begin()); j != m_machres_map.end(); ++j) { string rname(j->first.c_str()); *(rname.begin()) = toupper(*(rname.begin())); string attr; formatstr(attr, "%s%s", ATTR_DETECTED_PREFIX, rname.c_str()); cp->Assign(attr.c_str(), int(j->second)); formatstr(attr, "%s%s", ATTR_TOTAL_PREFIX, rname.c_str()); cp->Assign(attr.c_str(), int(j->second)); machine_resources += " "; machine_resources += j->first; } cp->Assign(ATTR_MACHINE_RESOURCES, machine_resources.c_str()); } // We don't want this inserted into the public ad automatically if( IS_UPDATE(how_much) || IS_TIMEOUT(how_much) ) { cp->Assign( ATTR_LAST_BENCHMARK, (unsigned)m_last_benchmark ); } if( IS_TIMEOUT(how_much) || IS_PUBLIC(how_much) ) { cp->Assign( ATTR_TOTAL_LOAD_AVG, rint(m_load * 100) / 100.0); cp->Assign( ATTR_TOTAL_CONDOR_LOAD_AVG, rint(m_condor_load * 100) / 100.0); cp->Assign( ATTR_CLOCK_MIN, m_clock_min ); cp->Assign( ATTR_CLOCK_DAY, m_clock_day ); m_lst_dynamic.Rewind(); while (AttribValue *pav = m_lst_dynamic.Next() ) { if (pav) pav->AssignToClassAd(cp); } } // temporary attributes for raw utsname info cp->Assign( ATTR_UTSNAME_SYSNAME, m_utsname_sysname ); cp->Assign( ATTR_UTSNAME_NODENAME, m_utsname_nodename ); cp->Assign( ATTR_UTSNAME_RELEASE, m_utsname_release ); cp->Assign( ATTR_UTSNAME_VERSION, m_utsname_version ); cp->Assign( ATTR_UTSNAME_MACHINE, m_utsname_machine ); // Advertise chroot information if ( m_named_chroot.size() > 0 ) { cp->Assign( "NamedChroot", m_named_chroot.c_str() ); } }
void MachAttributes::init_machine_resources() { // defines the space of local machine resources, and their quantity m_machres_map.clear(); // this may be filled from resource inventory scripts m_machres_attr.Clear(); // these are reserved for standard/fixed resources std::set<string> fixedRes; fixedRes.insert("cpu"); fixedRes.insert("cpus"); fixedRes.insert("disk"); fixedRes.insert("swap"); fixedRes.insert("mem"); fixedRes.insert("memory"); fixedRes.insert("ram"); // get the list of defined local resource names: char* ptmp = param("MACHINE_RESOURCE_NAMES"); string resnames; if (NULL != ptmp) { // if admin defined MACHINE_RESOURCE_NAMES, then use this list // as the source of expected custom machine resources resnames = ptmp; free(ptmp); } else { // otherwise, build the list of custom machine resources from // all occurrences of MACHINE_RESOURCE_<resname> std::set<string> resset; Regex re; int err = 0; const char* pszMsg = 0; const string prefix = "MACHINE_RESOURCE_"; const string invprefix = "INVENTORY_"; const string restr = prefix + "(.+)"; ASSERT(re.compile(restr.c_str(), &pszMsg, &err, PCRE_CASELESS)); std::vector<std::string> resdef; const int n = param_names_matching(re, resdef); for (int j = 0; j < n; ++j) { string rname = resdef[j].substr(prefix.length()); string testinv = rname.substr(0, invprefix.length()); if (0 == strcasecmp(testinv.c_str(), invprefix.c_str())) { // if something was defined via MACHINE_RESOURCE_INVENTORY_<rname>, strip "INVENTORY_" rname = rname.substr(invprefix.length()); } std::transform(rname.begin(), rname.end(), rname.begin(), ::tolower); resset.insert(rname); } for (std::set<string>::iterator j(resset.begin()); j != resset.end(); ++j) { resnames += " "; resnames += *j; } } // scan the list of local resources, to obtain their quantity and associated attributes (if any) StringList reslist(resnames.c_str()); reslist.rewind(); while (const char* rnp = reslist.next()) { string rname(rnp); std::transform(rname.begin(), rname.end(), rname.begin(), ::tolower); if (fixedRes.count(rname) > 0) { EXCEPT("pre-defined resource name '%s' is reserved", rname.c_str()); } // If MACHINE_RESOURCE_<rname> is present, use that and move on: string pname; formatstr(pname, "MACHINE_RESOURCE_%s", rname.c_str()); char* machresp = param(pname.c_str()); if (machresp) { int v = param_integer(pname.c_str(), 0, 0, INT_MAX); m_machres_map[rname] = v; free(machresp); continue; } // current definition of REMIND macro is not working with gcc #pragma message("MACHINE_RESOURCE_INVENTORY_<rname> is deprecated, and will be removed when a solution using '|' in config files is fleshed out") // if we didn't find MACHINE_RESOURCE_<rname>, then try MACHINE_RESOURCE_INVENTORY_<rname> formatstr(pname, "MACHINE_RESOURCE_INVENTORY_%s", rname.c_str()); char* invscriptp = param(pname.c_str()); if (NULL == invscriptp) { EXCEPT("Missing configuration for local machine resource %s", rname.c_str()); } // if there is an inventory script, then attempt to execute it and use its output to // identify the local resource quantity, and any associated attributes: string invscript = invscriptp; free(invscriptp); ArgList invcmd; StringList invcmdal(invscript.c_str()); invcmdal.rewind(); while (char* invarg = invcmdal.next()) { invcmd.AppendArg(invarg); } FILE* fp = my_popen(invcmd, "r", FALSE); if (NULL == fp) { EXCEPT("Failed to execute local resource inventory script \"%s\"\n", invscript.c_str()); } ClassAd invad; char invline[1000]; while (fgets(invline, sizeof(invline), fp)) { if (!invad.Insert(invline)) { dprintf(D_ALWAYS, "Failed to insert \"%s\" into machine resource attributes: ignoring\n", invline); } } my_pclose(fp); // require the detected machine resource to be present as an attribute string ccname(rname.c_str()); *(ccname.begin()) = toupper(*(ccname.begin())); string detname; formatstr(detname, "%s%s", ATTR_DETECTED_PREFIX, ccname.c_str()); int v = 0; if (!invad.LookupInteger(detname.c_str(), v)) { EXCEPT("Missing required attribute \"%s = <n>\" from output of %s\n", detname.c_str(), invscript.c_str()); } // success m_machres_map[rname] = v; invad.Delete(rname.c_str()); m_machres_attr.Update(invad); } for (slotres_map_t::iterator j(m_machres_map.begin()); j != m_machres_map.end(); ++j) { dprintf(D_ALWAYS, "Local machine resource %s = %d\n", j->first.c_str(), int(j->second)); } }
static const char *dragon_name(const unit * u) { static char name[NAMESIZE + 1]; // FIXME: static return value int rnd, ter = 0; int anzahl = 1; static int num_postfix; char zText[32]; const char *str; if (num_postfix == 0) { for (num_postfix = 0;; ++num_postfix) { sprintf(zText, "dragon_postfix_%d", num_postfix); str = locale_getstring(default_locale, zText); if (str == NULL) break; } if (num_postfix == 0) num_postfix = -1; } if (num_postfix <= 0) { return NULL; } if (u) { region *r = u->region; anzahl = u->number; switch (rterrain(r)) { case T_PLAIN: ter = 1; break; case T_MOUNTAIN: ter = 2; break; case T_DESERT: ter = 3; break; case T_SWAMP: ter = 4; break; case T_GLACIER: ter = 5; break; } } rnd = num_postfix / 6; rnd = (rng_int() % rnd) + ter * rnd; sprintf(zText, "dragon_postfix_%d", rnd); str = locale_getstring(default_locale, zText); assert(str != NULL); if (anzahl > 1) { const char *no_article = strchr((const char *)str, ' '); assert(no_article); // TODO: localization sprintf(name, "Die %sn von %s", no_article + 1, rname(u->region, default_locale)); } else { char n[32]; strcpy(n, silbe1[rng_int() % SIL1]); strcat(n, silbe2[rng_int() % SIL2]); strcat(n, silbe3[rng_int() % SIL3]); if (rng_int() % 5 > 2) { sprintf(name, "%s, %s", n, str); /* "Name, der Titel" */ } else { strcpy(name, (const char *)str); /* "Der Titel Name" */ name[0] = (char)toupper(name[0]); /* TODO: UNICODE - should use towupper() */ strcat(name, " "); strcat(name, n); } if (u && (rng_int() % 3 == 0)) { strcat(name, " von "); strcat(name, (const char *)rname(u->region, default_locale)); } } return name; }