static void printsigns(const unsigned char *key,void *data) { static int sign_count = 0; int ipct = 0; sign_count = *(int*)(hash_find(data,(const unsigned char *)"#count")); #if 1 ipct = pct(sign_count,signiary->key_count); #else ipct = pct(sign_count,total_sign_instances); #endif printf("%s\t%d\t%d\t",key,sign_count,ipct); hash_exec_user_key_data(data, printvals, &sign_count); printf("\n"); }
// ========================================================================= Pruning_table:: Pruning_table(Transform_table *tr, Turn_table *tn, struct CubeState state, int opt) // ------------------------------------------------------------------------- { Pack_ef pef(state.eo); Pack_ct pct(state.co); fprintf(stderr, "\nBuilding pruning tables...\n"); ef_big = ct_big = 0; if (pef.len() > A_N_EF) ef_big = 1; if (pct.len() > A_N_CT) ct_big = 1; fprintf(stderr, " - edge flips number: %s, corner twists number: %s\n", ef_big ? "big" : "small", ct_big ? "big" : "small"); ct_el = new Pruning_table_ct_el(tr, tn, state.co, state.e1); if (ef_big) { ef_xx = new Pruning_table_ef_xx(tr, tn, state.eo); fprintf(stderr, "\n - edge flips - middle edge locations (phase 1): none\n"); ef_el = 0; fprintf(stderr, "\n - corner twists - edge flips (phase 1): none\n"); ct_ef = 0; } else { fprintf(stderr, "\n - edge flips (phase 1): none\n"); ef_xx = 0; ef_el = new Pruning_table_ef_el(tr, tn, state.eo, state.e1); if (ct_big) { fprintf(stderr, "\n - corner twists - edge flips (phase 1): none\n"); ct_ef = 0; } else { ct_ef = new Pruning_table_ct_ef(tr, tn, state.co, state.eo); } } if (opt) { // do not use phase 2 cp_xx = new Pruning_table_cp_xx(tr, tn, state.c1); us_el = new Pruning_table_us_el(tr, tn, state.e1); ds_el = new Pruning_table_ds_el(tr, tn, state.e1); ms_xx = new Pruning_table_ms_xx(tr, tn, state.e1); fprintf(stderr, "\n - middle edge permutations - corner permutations (phase 2): none\n"); mp_cp = 0; fprintf(stderr, "\n - middle edge - updown edge permutations (phase 2): none\n"); mp_ep = 0; } else { // use phase 2 fprintf(stderr, "\n - corner permutations (phase 1): none\n"); cp_xx = 0; fprintf(stderr, "\n - upslice edge positions - middle edge locations (phase 1): none\n"); us_el = 0; fprintf(stderr, "\n - downslice edge positions - middle edge locations (phase 1): none\n"); ds_el = 0; fprintf(stderr, "\n - middle slice edge positions (phase 1): none\n"); ms_xx = 0; mp_cp = new Pruning_table_mp_cp(tr, tn, state.e1, state.c1); mp_ep = new Pruning_table_mp_ep(tr, tn, state.e1); } fprintf(stderr, "Pruning tables done.\n"); }
// Warning: takes 1 second to run int fill_ioutil(char *str, int n) { if (n == 0) return 0; FILE *f = popen("iostat -x 1 2", "r"); if (NULL == f) return 0; char line[256]; int skips = 4; while (NULL != fgets(line, sizeof(line), f)) { if (line[0] == '\n') skips--; if (skips == 0) { break; } } if (NULL == fgets(line, sizeof(line), f)) return 0; float maxUtil = 0.0; while (NULL != fgets(line, sizeof(line), f)) { char *last = rindex(line, ' '); if (NULL != last) { float util = atof(last); if (util > maxUtil) maxUtil = util; } } pclose(f); if (maxUtil > 100.0) maxUtil = 100.0; str[0] = pct(maxUtil / 100.0); return 1; }
/* pirate stuff */ void dopirate() { int j; boolean k; if (g.newloc == g.chloc || g.prop[CHEST] >= 0) return; k = FALSE; /* Pirate won't take pyramid from plover room or dark room (too easy! ) */ for (j = 1; j < MAXOBJ; ++j) if (treasr(j) && !(j == CASK && liq(CASK) == WINE) && !(j == PYRAMID && (g.newloc == g.place[PYRAMID] || g.newloc == g.place[EMERALD]))) { if (toting(j) && athand(j)) goto stealit; if (here(j)) k = TRUE; } if (g.tally == g.tally2 + 1 && k == FALSE && g.place[CHEST] == 0 && athand(LAMP) && g.prop[LAMP] == 1) { rspeak(186); move(CHEST, g.chloc); move(MESSAGE, g.chloc2); g.dloc[DWARFMAX] = g.chloc; g.odloc[DWARFMAX] = g.chloc; g.dseen[DWARFMAX] = 0; return; } if (g.odloc[DWARFMAX] != g.dloc[DWARFMAX] && pct(30)) rspeak(127); return; stealit: rspeak(128); /* don't steal chest back from troll! */ if (g.place[MESSAGE] == 0) move(CHEST, g.chloc); move(MESSAGE, g.chloc2); for (j = 1; j < MAXOBJ; ++j) { if (!treasr(j) || !athand(j) || (j == PYRAMID && (g.newloc == plac[PYRAMID] || g.newloc == plac[EMERALD])) || (j == CASK && (liq(CASK) != WINE))) continue; if (enclosed(j)) extract(j); if (wearng(j)) { g.prop[j] = 0; bitoff(j, WEARBT); } insert(j, CHEST); } g.dloc[DWARFMAX] = g.chloc; g.odloc[DWARFMAX] = g.chloc; g.dseen[DWARFMAX] = FALSE; return; }
static void printvals(const unsigned char *key, void *data, void *user) { if (*key != '#') { int ipct = 0; ipct = pct(*(int*)data, *(int*)user); printf("%s %d/%d\t",key, *(int*)data, ipct); } }
// ========================================================================= Pruning_table_ct_el:: Pruning_table_ct_el(Transform_table *tr, Turn_table *tn, int co, int e1): co(co), e1(e1) // ------------------------------------------------------------------------- { int n, d, mx = 0; int ct, el, t; unsigned int sm = 0; Pack_ct pct(co); int Nct = pct.len(); int Sct = pct.startlen(); Pack_el pel(e1); int Nel = pel.len(); int Sel = pel.startlen(); for (ct = 0; ct < Nct; ct++) for (el = 0; el < Nel; el++) a[ct][el] = BIG; for (t = 0; t < A_N_TW; t++) if (mx < tn->a_len(t)) mx = tn->a_len(t); fprintf(stderr, "\n - corner twists - middle edge locations (phase 1, %i x %i goal/s):\n", Sct, Sel); for (ct = 0; ct < Sct; ct++) for (el = 0; el < Sel; el++) a[pct.start(ct)][pel.start(el)] = 0; d = 0; n = Sct * Sel; while (n) { fprintf(stderr," %2i %8i %10u\n", d, n, sm += n); n = 0; d++; for (ct = 0; ct < Nct; ct++) { for (el = 0; el < Nel; el++) { if (d <= a[ct][el] || d > a[ct][el] + mx) continue; for (t = 0; t < A_N_TW; t++) { if (d == a[ct][el] + tn->a_len(t)) { int nct = tr->ct->a_do_tw(t, ct); int nel = tr->el->a_do_tw(t, el); if (a[nct][nel] > d) { a[nct][nel] = d; n++; } } } } } } }
IMPISD_BEGIN_NAMESPACE // MarginalNOERestraint::MarginalNOERestraint() {} // add a contribution: simple case void MarginalNOERestraint::add_contribution(Particle *p1, Particle *p2, double Iexp) { ParticlePair pc(p1, p2); ParticlePairsTemp pct(1, pc); IMP_NEW(container::ListPairContainer, cont, (pct)); // container::ListPairContainer cont(pct); add_contribution(cont, Iexp); }
static void display_brw_stats(struct seq_file *seq, char *name, char *units, struct obd_histogram *read, struct obd_histogram *write, int scale) { unsigned long read_tot, write_tot, r, w, read_cum = 0, write_cum = 0; int i; seq_printf(seq, "\n%26s read | write\n", " "); seq_printf(seq, "%-22s %-5s %% cum %% | %-11s %% cum %%\n", name, units, units); read_tot = lprocfs_oh_sum(read); write_tot = lprocfs_oh_sum(write); for (i = 0; i < OBD_HIST_MAX; i++) { r = read->oh_buckets[i]; w = write->oh_buckets[i]; read_cum += r; write_cum += w; if (read_cum == 0 && write_cum == 0) continue; if (!scale) seq_printf(seq, "%u", i); else if (i < 10) seq_printf(seq, "%u", scale << i); else if (i < 20) seq_printf(seq, "%uK", scale << (i-10)); else seq_printf(seq, "%uM", scale << (i-20)); seq_printf(seq, ":\t\t%10lu %3lu %3lu | %4lu %3lu %3lu\n", r, pct(r, read_tot), pct(read_cum, read_tot), w, pct(w, write_tot), pct(write_cum, write_tot)); if (read_cum == read_tot && write_cum == write_tot) break; } }
/* Routine to describe current location */ void describe() { if (toting(BEAR)) rspeak(141); if (dark()) rspeak(16); else if ((g.terse && verb != LOOK) || g.visited[g.loc] % g.abbnum) descsh(g.loc); else desclg(g.loc); if (g.loc == 33 && pct(25) && !g.closing) rspeak(8); if (g.loc == 147 && !g.visited[g.loc]) rspeak(216); return; }
/* dwarf stuff. */ void dwarves() { int i, j, k, attack, stick, dtotal; /* See if dwarves allowed here */ if (g.newloc == 0 || forced(g.newloc) || g.loc_attrib[g.newloc] & NOPIRAT) return; /* See if dwarves are active. */ if (!g.dflag) { if (inside(g.newloc)) ++g.dflag; return; } /* If first close encounter (of 3rd kind) */ if (g.dflag == 1) { if (!inside(g.newloc) || pct(85)) return; ++g.dflag; /* kill 0, 1 or 2 of the dwarfs */ for (i = 1; i < 3; ++i) if (pct(50)) g.dloc[(ranz(DWARFMAX - 1)) + 1] = 0; /* If any of the survivors is at location, use alternate choise */ for (i = 1; i <= DWARFMAX; ++i) { if (g.dloc[i] == g.newloc) g.dloc[i] = g.daltloc; g.odloc[i] = g.dloc[i]; } rspeak(3); drop(AXE, g.newloc); return; } /* Things are in full swing. Move each dwarf at random, except if he's seen us then he sticks with us. Dwarfs never go to locations outside or meet the bear or following him into dead end in maze. And of couse, dead dwarves don't do much of anything. */ dtotal = attack = stick = 0; for (i = 1; i <= DWARFMAX; ++i) { if (g.dloc[i] == 0) continue; /* Move a dwarf at random. we don't have a matrix around to do it as in the original version... */ do j = ranz(106) + 15; /* allowed area */ while (j == g.odloc[i] || j == g.dloc[i] || g.loc_attrib[j] & NOPIRAT); if (j == 0) bug(36); g.odloc[i] = g.dloc[i]; g.dloc[i] = j; g.dseen[i] = ((g.dseen[i] && inside(g.newloc)) || g.dloc[i] == g.newloc || g.odloc[i] == g.newloc); if (g.dseen[i]) { g.dloc[i] = g.newloc; if (i == DWARFMAX) dopirate(); else { ++dtotal; if (g.odloc[i] == g.dloc[i]) { ++attack; if (g.knfloc >= 0) g.knfloc = g.newloc; if (ranz(1000) < (45 * (g.dflag - 2))) ++stick; } } } } /* Now we know shat's happing, let's tell the poor sucker about it */ if (dtotal == 0) return; if (dtotal > 1) printf("There are %d threatening little dwarves in the room with you!\n", dtotal); else rspeak(4); if (attack == 0) return; if (g.dflag == 2) ++g.dflag; if (attack > 1) { printf("%d of them throw knives at you!!\n", attack); k = 6; } else { rspeak(5); k = 52; } if (stick <= 1) { rspeak(stick + k); if (stick == 0) return; } else printf("%d of them get you !!!\n", stick); g.oldloc2 = g.newloc; death(); return; }
/* Routine to take 1 turn */ void turn() { int i, hint; static int waste = 0; if (newtravel) { /* If closing, then he can't leave except via the main office. */ if (outside(g.newloc) && g.newloc != 0 && g.closing) { rspeak(130); g.newloc = g.loc; if (!g.panic) g.clock2 = 15; g.panic = TRUE; } /* See if a dwarf has seen him and has come from where he wants to go. */ if (g.newloc != g.loc && !forced(g.loc) && g.loc_attrib[g.loc] & NOPIRAT == 0) for (i = 1; i < (DWARFMAX - 1); ++i) if (g.odloc[i] == g.newloc && g.dseen[i]) { g.newloc = g.loc; rspeak(2); break; } g.loc = g.newloc; dwarves(); /* & special dwarf(pirate who steals) */ /* Check for death */ if (g.loc == 0) { death(); return; } /* Check for forced move */ if (forced(g.loc)) { desclg(g.loc); ++g.visited[g.loc]; domove(); return; } /* Check for wandering in dark */ if (g.wzdark && dark() && pct(35)) { rspeak(23); g.oldloc2 = g.loc; death(); return; } /* see if he is wasting his batteies out in the open */ if (outside(g.loc) && g.prop[LAMP]) { waste++; if (waste > 11) { rspeak(324); waste = 0; } } else waste = 0; /* If wumpus is chasing stooge, see if wumpus gets him */ if (g.chase) { g.chase++; g.prop[WUMPUS] = g.chase / 2; move(WUMPUS, g.loc); if (g.chase >= 10) { if (dark()) rspeak(270); pspeak(WUMPUS, 5); death(); return; } } /* check for radiation poisoning. */ g.health += (outside(g.loc)) ? 3 : 1; if (g.health > 100) g.health = 100; if (here(RADIUM) && (g.place[RADIUM] != -SHIELD || ajar(SHIELD))) g.health -= 7; if (g.health < 60) { rspeak(391 + (60 - g.health) / 10); if (g.health < 0) { death(); return; } } if ((g.oldloc == 188) && (g.loc != 188 && g.loc != 189) && (g.prop[BOOTH] == 1)) { move(GNOME, 0); g.prop[BOOTH] = 0; } /* Describe his situation */ describe(); if (!blind()) { ++g.visited[g.loc]; descitem(); } } /* end of newtravel start for second entry point */ /* Check if this location is eligible for any hints. If been here long enough, branch to help section. Ignore "hints" < HNTMIN (special stuff, see database notes. */ for (hint = HNTMIN; hint <= HNTMAX; hint++) { if (g.hinted[hint]) continue; if (g.loc_attrib[g.loc] / 256 != hint - 6) g.hintlc[hint] = -1; g.hintlc[hint]++; if (g.hintlc[hint] >= g.hints[hint][1]) do_hint(hint); } if (g.closed) { if (g.prop[OYSTER] < 0 && toting(OYSTER)) pspeak(OYSTER, 1); for (i = 1; i < MAXOBJ; ++i) if (toting(i) && g.prop[i] < 0) g.prop[i] = -1 - g.prop[i]; } g.wzdark = dark(); if (g.knfloc > 0 && g.knfloc != g.loc) g.knfloc = 0; ++g.turns; i = rand(); if (stimer()) /* as the grains of sand slip by */ return; while (!english()) /* retrieve player instructions */ ; vrbx = 1; objx = objs[1] ? 1 : 0; iobx = iobjs[1] ? 1 : 0; verb = VAL(verbs[vrbx]); do { object = objx ? objs[objx] : 0; iobj = iobx ? iobjs[iobx] : 0; if (object && (objs[2] || iobjs[2])) { pspeak(object, -1); printf(" "); } switch (CLASS(verbs[vrbx])) { case MOTION: motion = verb; domove(); break; case NOUN: bug(22); case ACTION: if (object || iobj) trverb(); else itverb(); break; case MISC: rspeak(verb); if (verb == 51) g.hinted[1] = TRUE; break; default: bug(22); } if (objx) { objx++; if (objs[objx] == 0) objx = 0; } if ((!objx || !objs[objx]) && iobx) { iobx++; if (iobjs[iobx] == 0) iobx = 0; if (iobx && iobjs[1]) objx = 1; } } while (objx || iobx); return; }
int client(pid_t srvpid) { int r; /* test simple pct */ errno = 0; r = pct(MIN_APP_IPC_NUMBER, 11, 12, 0, 0L, my_ret_handler, srvpid, &ret); printf("c: pct(%d,11,12,0,%d) -> r,errno,ret:%d,%d,%d, ", MIN_APP_IPC_NUMBER,srvpid,r,errno,ret); printf("should be: 1,0,11\n"); ipc_clear_request(r); /* test simple pct that passes two args */ r = pct(MIN_APP_IPC_NUMBER, 12, 12, 0, 0L, my_ret_handler, srvpid, &ret); printf("c: pct(%d,12,12,0,%d) -> r,errno,ret:%d,%d,%d, ", MIN_APP_IPC_NUMBER,srvpid,r,errno,ret); printf("should be: 257,%d,-1\n",V_PROGUNAVAIL); ipc_clear_request(r); ret = -1; errno = 0; /* test ipc_msg */ r = ipc_msg(MIN_APP_IPC_NUMBER, 13, 12, 0, 0L, my_ret_handler, srvpid, &ret); printf("c: msg(%d,13,12,0,%d) -> r,errno,ret:%d,%d,%d, ", MIN_APP_IPC_NUMBER,srvpid,r,errno,ret); printf("should be: 513,0,-1\n"); while(ret == -1) { asm volatile ("" : : : "memory"); env_fastyield(srvpid); } printf("client eventually returned %d (should be 13)\n",ret); ipc_clear_request(r); /* test ipc_sleepwait, using pct */ ret = -1; errno = 0; r = ipc_sleepwait(MIN_APP_IPC_NUMBER,14,12,0,0L,my_ret_handler,srvpid,1000); printf("c: msg(%d,14,12,0,%d) -> r,errno,ret:%d,%d,%d, ", MIN_APP_IPC_NUMBER,srvpid,r,errno,ret); printf("should be: 14,??,-1\n"); ipc_clear_request(r); /* test ipc_sleepwait, using msg, should timeout */ ret = -1; errno = 0; r = ipc_sleepwait(MIN_APP_IPC_NUMBER,15,12,0,0L,my_ret_handler,srvpid,1); printf("c: msg(%d,15,12,0,%d) -> r,errno,ret:%d,%d,%d, ", MIN_APP_IPC_NUMBER,srvpid,r,errno,ret); printf("should be: -1,35,-1\n"); ipc_clear_request(r); /* test ipc_sleepwait, using msg, should not timeout */ ret = -1; errno = 0; r = ipc_sleepwait(MIN_APP_IPC_NUMBER,16,12,0,0L,my_ret_handler,srvpid,0); printf("c: msg(%d,16,12,0,%d) -> r,errno,ret:%d,%d,%d, ", MIN_APP_IPC_NUMBER,srvpid,r,errno,ret); printf("should be: 16,??,-1\n"); ipc_clear_request(r); return 0; }
bool WorldSocket::ProcessIncomingData() { ClientPktHeader header; if (m_useExistingHeader) { m_useExistingHeader = false; header = m_existingHeader; ReadSkip(sizeof(ClientPktHeader)); } else { if (!Read((char *)&header, sizeof(ClientPktHeader))) { errno = EBADMSG; return false; } m_crypt.DecryptRecv((uint8 *)&header, sizeof(ClientPktHeader)); EndianConvertReverse(header.size); EndianConvert(header.cmd); } // there must always be at least four bytes for the opcode, // and 0x2800 is the largest supported buffer in the client if ((header.size < 4) || (header.size > 0x2800) || (header.cmd >= NUM_MSG_TYPES)) { sLog.outError("WorldSocket::ProcessIncomingData: client sent malformed packet size = %u , cmd = %u", header.size, header.cmd); errno = EINVAL; return false; } // the minus four is because we've already read the four byte opcode value const uint16 validBytesRemaining = header.size - 4; // check if the client has told us that there is more data than there is if (validBytesRemaining > ReadLengthRemaining()) { // we must preserve the decrypted header so as not to corrupt the crypto state, and to prevent duplicating work m_useExistingHeader = true; m_existingHeader = header; // we move the read pointer backward because it will be skipped again later. this is a slight kludge, but to solve // it more elegantly would require introducing protocol awareness into the socket library, which we want to avoid ReadSkip(-static_cast<int>(sizeof(ClientPktHeader))); errno = EBADMSG; return false; } Opcodes x; const OpcodesList opcode = static_cast<OpcodesList>(header.cmd); if (IsClosed()) return false; std::unique_ptr<WorldPacket> pct(new WorldPacket(opcode, validBytesRemaining)); if (validBytesRemaining) { pct->append(InPeak(), validBytesRemaining); ReadSkip(validBytesRemaining); } sLog.outWorldPacketDump(GetRemoteEndpoint().c_str(), pct->GetOpcode(), pct->GetOpcodeName(), *pct, true); try { switch (opcode) { case CMSG_AUTH_SESSION: if (m_session) { sLog.outError("WorldSocket::ProcessIncomingData: Player send CMSG_AUTH_SESSION again"); return false; } return HandleAuthSession(*pct); case CMSG_PING: return HandlePing(*pct); case CMSG_KEEP_ALIVE: DEBUG_LOG("CMSG_KEEP_ALIVE ,size: " SIZEFMTD " ", pct->size()); return true; default: { if (!m_session) { sLog.outError("WorldSocket::ProcessIncomingData: Client not authed opcode = %u", uint32(opcode)); return false; } m_session->QueuePacket(std::move(pct)); return true; } } } catch (ByteBufferException&) { sLog.outError("WorldSocket::ProcessIncomingData ByteBufferException occured while parsing an instant handled packet (opcode: %u) from client %s, accountid=%i.", opcode, GetRemoteAddress().c_str(), m_session ? m_session->GetAccountId() : -1); if (sLog.HasLogLevelOrHigher(LOG_LVL_DEBUG)) { DEBUG_LOG("Dumping error-causing packet:"); pct->hexlike(); } if (sWorld.getConfig(CONFIG_BOOL_KICK_PLAYER_ON_BAD_PACKET)) { DETAIL_LOG("Disconnecting session [account id %i / address %s] for badly formatted packet.", m_session ? m_session->GetAccountId() : -1, GetRemoteAddress().c_str()); return false; } } return true; }
int main(int argc, char *argv[]) { int i; int rval, ll; struct text *kk; init(); /* Initialize everything */ signal(SIGINT, trapdel); if (argc > 1) { /* Restore file specified */ /* Restart is label 8305 (Fortran) */ i = restore(argv[1]); /* See what we've got */ switch (i) { case 0: /* The restore worked fine */ yea = Start(); k = null; unlink(argv[1]);/* Don't re-use the save */ goto l8; /* Get where we're going */ case 1: /* Couldn't open it */ errx(1, "can't open file"); /* So give up */ case 2: /* Oops -- file was altered */ rspeak(202); /* You dissolve */ exit(2); /* File could be non-adventure */ } /* So don't unlink it. */ } startup(); /* prepare for a user */ for (;;) { /* main command loop (label 2) */ if (newloc < 9 && newloc != 0 && closng) { rspeak(130); /* if closing leave only by */ newloc = loc; /* main office */ if (!panic) clock2 = 15; panic = TRUE; } rval = fdwarf(); /* dwarf stuff */ if (rval == 99) die(99); l2000: if (loc == 0) die(99); /* label 2000 */ kk = &stext[loc]; if ((abb[loc] % abbnum) ==0 || kk->seekadr == 0) kk = <ext[loc]; if (!forced(loc) && dark()) { if (wzdark && pct(35)) { die(90); goto l2000; } kk = &rtext[16]; } l2001: if (toting(bear)) rspeak(141); /* 2001 */ speak(kk); k = 1; if (forced(loc)) goto l8; if (loc == 33 && pct(25) && !closng) rspeak(8); if (!dark()) { abb[loc]++; for (i = atloc[loc]; i != 0; i = linkx[i]) { /*2004*/ obj = i; if (obj > 100) obj -= 100; if (obj == steps && toting(nugget)) continue; if (prop[obj] < 0) { if (closed) continue; prop[obj] = 0; if (obj == rug || obj == chain) prop[obj] = 1; tally--; if (tally == tally2 && tally != 0) if (limit > 35) limit = 35; } ll = prop[obj]; /* 2006 */ if (obj == steps && loc == fixed[steps]) ll = 1; pspeak(obj, ll); } /* 2008 */ goto l2012; l2009: k = 54; /* 2009 */ l2010: spk = k; l2011: rspeak(spk); } l2012: verb = 0; /* 2012 */ obj = 0; l2600: checkhints(); /* to 2600-2602 */ if (closed) { if (prop[oyster] < 0 && toting(oyster)) pspeak(oyster, 1); for (i = 1; i < 100; i++) if (toting(i) && prop[i] < 0) /* 2604 */ prop[i] = -1 - prop[i]; } wzdark = dark(); /* 2605 */ if (knfloc > 0 && knfloc != loc) knfloc = 1; getin(wd1, sizeof(wd1), wd2, sizeof(wd2)); if (delhit) { /* user typed a DEL */ delhit = 0; /* reset counter */ /* pretend he's quitting */ strlcpy(wd1, "quit", sizeof(wd1)); wd2[0] = 0; } l2608: if ((foobar = -foobar) > 0) foobar = 0; /* 2608 */ /* should check here for "magic mode" */ turns++; if (demo && turns >= SHORT) done(1); /* to 13000 */ if (verb == say && wd2[0] != 0) verb = 0; if (verb == say) goto l4090; if (tally == 0 && loc >= 15 && loc != 33) clock1--; if (clock1 == 0) { closing(); /* to 10000 */ goto l19999; } if (clock1 < 0) clock2--; if (clock2 == 0) { caveclose(); /* to 11000 */ continue; /* back to 2 */ } if (prop[lamp] == 1) limit--; if (limit <= 30 && here(batter) && prop[batter] == 0 && here(lamp)) { rspeak(188); /* 12000 */ prop[batter] = 1; if (toting(batter)) drop(batter, loc); limit += 2500; lmwarn = FALSE; goto l19999; } if (limit == 0) { limit = -1; /* 12400 */ prop[lamp] = 0; rspeak(184); goto l19999; } if (limit < 0 && loc <= 8) { rspeak(185); /* 12600 */ gaveup = TRUE; done(2); /* to 20000 */ } if (limit <= 30) { if (lmwarn || !here(lamp)) goto l19999; /*12200*/ lmwarn = TRUE; spk = 187; if (place[batter] == 0) spk = 183; if (prop[batter] == 1) spk = 189; rspeak(spk); } l19999: k = 43; if (liqloc(loc) == water) k = 70; if (weq(wd1, "enter") && (weq(wd2, "strea") || weq(wd2, "water"))) goto l2010; if (weq(wd1, "enter") && *wd2 != 0) goto l2800; if ((!weq(wd1, "water") && !weq(wd1, "oil")) || (!weq(wd2, "plant") && !weq(wd2, "door"))) goto l2610; if (at(vocab(wd2, 1, 0))) strlcpy(wd2, "pour", sizeof(wd2)); l2610: if (weq(wd1, "west")) if (++iwest == 10) rspeak(17); l2630: i = vocab(wd1, -1, 0); if (i== -1) { spk = 60; /* 3000 */ if (pct(20)) spk = 61; if (pct(20)) spk = 13; rspeak(spk); goto l2600; } k = i % 1000; kq = i / 1000 + 1; switch (kq) { case 1: goto l8; case 2: goto l5000; case 3: goto l4000; case 4: goto l2010; default: bug(22); } l8: switch (march()) { case 2: continue; /* i.e. goto l2 */ case 99: die(99); goto l2000; default: bug(110); } l2800: strlcpy(wd1, wd2, sizeof(wd1)); wd2[0] = 0; goto l2610; l4000: verb = k; spk = actspk[verb]; if (wd2[0] != 0 && verb != say) goto l2800; if (verb == say) obj = wd2[0]; if (obj != 0) goto l4090; l4080: switch (verb) { case 1: /* take = 8010 */ if (atloc[loc] == 0 || linkx[atloc[loc]] != 0) goto l8000; for (i = 1; i <= 5; i++) if (dloc[i] == loc && dflag >= 2) goto l8000; obj = atloc[loc]; goto l9010; case 2: case 3: case 9: /* 8000 : drop, say, wave */ case 10: case 16: case 17: /* calm, rub, toss */ case 19: case 21: case 28: /* find, feed, break */ case 29: /* wake */ l8000: printf("%s what?\n", wd1); obj = 0; goto l2600; case 4: case 6: /* 8040 open, lock */ spk = 28; if (here(clam)) obj = clam; if (here(oyster)) obj = oyster; if (at(door)) obj = door; if (at(grate)) obj = grate; if (obj != 0 && here(chain)) goto l8000; if (here(chain)) obj = chain; if (obj == 0) goto l2011; goto l9040; case 5: goto l2009; /* nothing */ case 7: goto l9070; /* on */ case 8: goto l9080; /* off */ case 11: goto l8000; /* walk */ case 12: goto l9120; /* kill */ case 13: goto l9130; /* pour */ case 14: /* eat: 8140 */ if (!here(food)) goto l8000; l8142: dstroy(food); spk = 72; goto l2011; case 15: goto l9150; /* drink */ case 18: /* quit: 8180 */ gaveup = yes(22, 54, 54); if (gaveup) done(2); /* 8185 */ goto l2012; case 20: /* invent = 8200 */ spk = 98; for (i = 1; i <= 100; i++) { if (i != bear && toting(i)) { if (spk == 98) rspeak(99); blklin = FALSE; pspeak(i, -1); blklin = TRUE; spk = 0; } } if (toting(bear)) spk = 141; goto l2011; case 22: goto l9220; /* fill */ case 23: goto l9230; /* blast */ case 24: /* score: 8240 */ scorng = TRUE; printf("If you were to quit now, you would score"); printf(" %d out of a possible ", score()); printf("%d.", mxscor); scorng = FALSE; gaveup = yes(143, 54, 54); if (gaveup) done(2); goto l2012; case 25: /* foo: 8250 */ k = vocab(wd1, 3, 0); spk = 42; if (foobar == 1 - k) goto l8252; if (foobar != 0) spk = 151; goto l2011; l8252: foobar = k; if (k != 4) goto l2009; foobar = 0; if (place[eggs] == plac[eggs] || (toting(eggs) && loc == plac[eggs])) goto l2011; if (place[eggs] == 0 && place[troll] == 0 && prop[troll] == 0) prop[troll] = 1; k = 2; if (here(eggs)) k = 1; if (loc == plac[eggs]) k = 0; move(eggs, plac[eggs]); pspeak(eggs, k); goto l2012; case 26: /* brief = 8260 */ spk = 156; abbnum = 10000; detail = 3; goto l2011; case 27: /* read = 8270 */ if (here(magzin)) obj = magzin; if (here(tablet)) obj = obj * 100 + tablet; if (here(messag)) obj = obj * 100 + messag; if (closed && toting(oyster)) obj = oyster; if (obj > 100 || obj == 0 || dark()) goto l8000; goto l9270; case 30: /* suspend = 8300 */ spk = 201; if (demo) goto l2011; printf("I can suspend your adventure for you so"); printf(" you can resume later, but\n"); printf("you will have to wait at least"); printf(" %d minutes before continuing.", latncy); if (!yes(200, 54, 54)) goto l2012; time(&savet); ciao(); /* Do we quit? */ continue; /* Maybe not */ case 31: /* hours = 8310 */ printf("Colossal cave is closed 9am-5pm Mon "); printf("through Fri except holidays.\n"); goto l2012; default: bug(23); } l4090: switch (verb) { case 1: /* take = 9010 */ l9010: switch (trtake()) { case 2011: goto l2011; case 9220: goto l9220; case 2009: goto l2009; case 2012: goto l2012; default: bug(102); } l9020: case 2: /* drop = 9020 */ switch (trdrop()) { case 2011: goto l2011; case 19000: done(3); case 2012: goto l2012; default: bug(105); } l9030: case 3: switch (trsay()) { case 2012: goto l2012; case 2630: goto l2630; default: bug(107); } l9040: case 4: case 6: /* open, close */ switch (tropen()) { case 2011: goto l2011; case 2010: goto l2010; default: bug(106); } case 5: goto l2009; /* nothing */ case 7: /* on 9070 */ l9070: if (!here(lamp)) goto l2011; spk = 184; if (limit < 0) goto l2011; prop[lamp] = 1; rspeak(39); if (wzdark) goto l2000; goto l2012; case 8: /* off */ l9080: if (!here(lamp)) goto l2011; prop[lamp] = 0; rspeak(40); if (dark()) rspeak(16); goto l2012; case 9: /* wave */ if ((!toting(obj)) && (obj != rod || !toting(rod2))) spk = 29; if (obj != rod || !at(fissur)||!toting(obj) || closng) goto l2011; prop[fissur] = 1-prop[fissur]; pspeak(fissur, 2-prop[fissur]); goto l2012; case 10: case 11: case 18: /* calm, walk, quit */ case 24: case 25: case 26: /* score, foo, brief */ case 30: case 31: /* suspend, hours */ goto l2011; l9120: case 12: /* kill */ switch (trkill()) { case 8000: goto l8000; case 8: goto l8; case 2011: goto l2011; case 2608: goto l2608; case 19000: done(3); default: bug(112); } l9130: case 13: /* pour */ if (obj == bottle || obj == 0) obj = liq(); if (obj == 0) goto l8000; if (!toting(obj)) goto l2011; spk = 78; if (obj != oil && obj != water) goto l2011; prop[bottle] = 1; place[obj] = 0; spk = 77; if (!(at(plant) || at(door))) goto l2011; if (at(door)) { prop[door] = 0; /* 9132 */ if (obj == oil) prop[door] = 1; spk = 113 + prop[door]; goto l2011; } spk = 112; if (obj != water) goto l2011; pspeak(plant, prop[plant] + 1); prop[plant] = (prop[plant] + 2) % 6; prop[plant2] = prop[plant] / 2; k = null; goto l8; case 14: /* 9140 - eat */ if (obj == food) goto l8142; if (obj == bird || obj == snake || obj == clam || obj == oyster || obj == dwarf || obj == dragon || obj == troll || obj == bear) spk = 71; goto l2011; l9150: case 15: /* 9150 - drink */ if (obj == 0 && liqloc(loc) != water && (liq() != water || !here(bottle))) goto l8000; if (obj != 0 && obj != water) spk = 110; if (spk == 110 || liq() != water || !here(bottle)) goto l2011; prop[bottle] = 1; place[water] = 0; spk = 74; goto l2011; case 16: /* 9160: rub */ if (obj != lamp) spk = 76; goto l2011; case 17: /* 9170: throw */ switch (trtoss()) { case 2011: goto l2011; case 9020: goto l9020; case 9120: goto l9120; case 8: goto l8; case 9210: goto l9210; default: bug(113); } case 19: case 20: /* 9190: find, invent */ if (at(obj) || (liq() == obj && at(bottle)) || k == liqloc(loc)) spk = 94; for (i = 1; i <= 5; i++) if (dloc[i] == loc && dflag >= 2 && obj == dwarf) spk = 94; if (closed) spk = 138; if (toting(obj)) spk = 24; goto l2011; l9210: case 21: /* feed */ switch (trfeed()) { case 2011: goto l2011; default: bug(114); } l9220: case 22: /* fill */ switch (trfill()) { case 2011: goto l2011; case 8000: goto l8000; case 9020: goto l9020; default: bug(115); } l9230: case 23: /* blast */ if (prop[rod2] < 0 || !closed) goto l2011; bonus = 133; if (loc == 115) bonus = 134; if (here(rod2)) bonus = 135; rspeak(bonus); done(2); l9270: case 27: /* read */ if (dark()) goto l5190; if (obj == magzin) spk = 190; if (obj == tablet) spk = 196; if (obj == messag) spk = 191; if (obj == oyster && hinted[2] && toting(oyster)) spk = 194; if (obj != oyster || hinted[2] || !toting(oyster) || !closed) goto l2011; hinted[2] = yes(192, 193, 54); goto l2012; l9280: case 28: /* break */ if (obj == mirror) spk = 148; if (obj == vase && prop[vase] == 0) { spk = 198; if (toting(vase)) drop(vase, loc); prop[vase] = 2; fixed[vase] = -1; goto l2011; } if (obj != mirror||!closed) goto l2011; rspeak(197); done(3); l9290: case 29: /* wake */ if (obj != dwarf||!closed) goto l2011; rspeak(199); done(3); default: bug(24); } l5000: obj = k; if (fixed[k] != loc && !here(k)) goto l5100; l5010: if (wd2[0] != 0) goto l2800; if (verb != 0) goto l4090; printf("What do you want to do with the %s?\n", wd1); goto l2600; l5100: if (k != grate) goto l5110; if (loc == 1 || loc == 4 || loc == 7) k = dprssn; if (loc > 9 && loc < 15) k = entrnc; if (k != grate) goto l8; l5110: if (k != dwarf) goto l5120; for (i = 1; i <= 5; i++) if (dloc[i] == loc && dflag >= 2) goto l5010; l5120: if ((liq() == k && here(bottle)) || k == liqloc(loc)) goto l5010; if (obj != plant || !at(plant2) || prop[plant2] == 0) goto l5130; obj = plant2; goto l5010; l5130: if (obj != knife || knfloc != loc) goto l5140; knfloc = -1; spk = 116; goto l2011; l5140: if (obj != rod || !here(rod2)) goto l5190; obj = rod2; goto l5010; l5190: if ((verb == find || verb == invent) && wd2[0] == 0) goto l5010; printf("I see no %s here\n", wd1); goto l2012; } }
/* Routines to process intransitive verbs */ void itverb() { int i; newtravel = FALSE; switch (verb) { case DROP: case SAY: case WAVE: case CALM: case RUB: case THROW: case FIND: case FEED: case BREAK: case WAKE: case WEAR: case HIT: case DIAL: case PLAY: case PICK: case PUT: case TURN: needobj(); break; case TAKE: case YANK: case GET: case INSRT: case REMOVE: case BURN: ivtake(); break; case OPEN: case CLOSE: case LOCK: case UNLOCK: ivopen(); break; case NOTHING: rspeak(54); break; case ON: case OFF: trverb(); break; case WALK: actspk(verb); break; case KILL: ivkill(); break; case POUR: ivpour(); break; case EAT: iveat(); break; case DRINK: ivdrink(); break; case QUIT: ivquit(); break; case INVENTORY: inventory(); break; case FILL: ivfill(); break; case BLAST: ivblast(); break; case SCORE: score(TRUE); break; case FOO: ivfoo(); break; case BRIEF: ivbrief(); break; case READ: ivread(); break; case SUSPEND: if (g.closing) rspeak(378); else saveadv("advent.sav"); break; case RESTORE: restore("advent.sav"); break; case ANSWER: if ((g.loc != 189) || (g.prop[PHONE] != 0)) needobj(); else { object = PHONE; itverb(); } break; case BLOW: rspeak(268); break; /* Action verb 'LEAVE' has no object */ case LEAVE: bug(29); break; /* Call if no phone is handy, yell. */ case YELL: if (!here(PHONE)) needobj(); else if (!g.closed) rspeak(271); else { rspeak(283); normend(); } break; /* Health. give him a diagnosis. */ case HEALTH: if (g.numdie) fprintf(stdout, "You have been killed %d times otherwise\n", g.numdie); if (g.health >= 95) { if (pct(50)) rspeak(348); else rspeak(349); } else { fprintf(stdout, "Your health rating is %2d out of a possible 100.\n", g.health); rspeak(381 + (100 - g.health) / 20); } break; case LOOK: ivlook(); break; case COMBO: if (at(SAFE)) ivcombo(); break; case SWEEP: /* Dust/sweep */ if (!at(CARVNG) || !athand(BRUSH) || (g.prop[CARVNG] == 1)) rspeak(342); else { g.prop[CARVNG] = 1; rspeak(363); rspeak(372); } break; case TERSE: /* Terse/unterse. supress all long_form descriptions. */ g.terse = !g.terse; g.detail = 3; rspeak(54); break; case WIZ: is_wiz = !is_wiz; case MAP: rspeak(54); break; case GATE: if (is_wiz) { static char buf[INPUTBUFLEN]; sscanf(ask("Location ? ", buf, sizeof(buf)), "%d", &g.loc); } rspeak(54); break; case PIRLOC: if (is_wiz) { fprintf(stdout, "The dwarfs are at locations:\n"); for (i = 1; i < DWARFMAX; i++) fprintf(stdout, " %4d", g.dloc[i]); fprintf(stdout, "\nThe pirate is at location %4d\n", g.dloc[DWARFMAX]); } rspeak(54); break; default: printf("This intransitive not implemented yet\n"); } return; }
/* THROW etc. */ vthrow() { int msg; int i; if (toting(ROD2) && object == ROD && !toting(ROD)) object = ROD2; if (!toting(object)) { actspk(verb); return; } /* treasure to troll */ if (at(TROLL) && object >= 50 && object<MAXOBJ) { rspeak(159); drop(object,0); move(TROLL,0); move((TROLL+MAXOBJ),0); drop(TROLL2,117); drop((TROLL2+MAXOBJ),122); juggle(CHASM); return; } /* feed the bears... */ if (object == FOOD && here(BEAR)) { object = BEAR; vfeed(); return; } /* if not axe, same as drop... */ if (object != AXE) { vdrop(); return; } /* AXE is THROWN */ /* at a dwarf... */ if (i = dcheck()) { msg = 48; if (pct(33)) { dseen[i] = dloc[i] = 0; msg = 47; ++dkill; if (dkill == 1) msg = 149; } } /* at a dragon... */ else if (at(DRAGON) && prop[DRAGON] == 0) msg = 152; /* at the troll... */ else if (at(TROLL)) msg = 158; /* at the bear... */ else if (here(BEAR) && prop[BEAR] == 0) { rspeak(164); drop(AXE,loc); fixed[AXE] = -1; prop[AXE] = 1; juggle(BEAR); return; } /* otherwise it is an attack */ else { verb = KILL; object = 0; itverb(); return; } /* handle the left over axe... */ rspeak(msg); drop(AXE,loc); describe(); }
/* Analyze a two word sentence */ int english() { char *ch_ptr, *word1, *word2; int type, val, type2, val2, adj, k, kk; static int iwest = 0; if (!(words[++wdx])) { getwords(); wdx = 0; } pflag = FALSE; word = words[wdx]; if (word < 0) { /* check first word */ printf("I didn't understand the word \"%s\"\n", txt[wdx]); words[wdx+1] = 0; return (FALSE); /* didn't know it */ } type2 = val2 = -1; type = CLASS(word); clrlin(); val = VAL(word); if (words[wdx + 1] && CLASS(words[wdx + 1]) != CONJUNCTION) { /* 'SAY' or 'CALL'. If no next word, pass on to higher powers. */ if (type == ACTION && (val == SAY || val == YELL)) { word = words[++wdx]; if (!(word == XYZZY || word == PLUGH || word == PLOVER || word == PHUCE)) { if (val == SAY) printf("Okay, \"%s\".\n", txt[wdx]); else { for (ch_ptr = txt[wdx]; *ch_ptr; ch_ptr++) if (islower(*ch_ptr)) *ch_ptr = toupper(*ch_ptr); printf("Okay, \"%s\"!!!!!\n", txt[wdx]); } return (FALSE); } } else { word1 = txt[wdx]; word2 = txt[wdx + 1]; /* Special stuff for 'ENTER'. Can't go into water. 'ENTER BOAT' means 'TAKE BOAT' */ if (word == ENTER) { if (CLASS(words[wdx + 1]) == NOUN && VAL(words[wdx + 1]) == BOAT) word = TAKE + 2000; else if ((strcmp(word2, "stream") == 0) || (strcmp(word2, "water") == 0) || (strcmp(word2, "reservoir") == 0) || (strcmp(word2, "ocean") == 0) || (strcmp(word2, "sea") == 0) || (strcmp(word2, "pool") == 0)) { rspeak(liqloc(g.loc) == WATER ? 70 : 43); wdx++; return (FALSE); } } else { type2 = CLASS(words[wdx + 1]); val2 = VAL(words[wdx + 1]); /* 'LEAVE' is motion verb, unsless leaving an object. E.G., 'LEAVE BOAT' or 'LEAVE BOTTLE'. BUt make sure to leave ('DROP') only totable objects. */ if (strcmp(word1, "leave") == 0 && type2 == NOUN) { if (!hinged(val2) || g.fixed[val2]) word = LEAVE + 2000; /* IF 'LIGHT LAMP', Light must be taken as an action verb, not a noun. */ } else if (strcmp(word1, "light") == 0 && VAL(words[wdx + 1]) == LAMP) { word = ON + 2000; /* 'WATER PLANT' becomes 'POUR WATER', If we are at plant. 'OIL DOOR' becomes 'POUR OIL', etc., etc. */ } else if ((strcmp(word1, "water") == 0 || strcmp(word1, "oil") == 0) && (strcmp(word2, "plant") == 0 || strcmp(word2, "door") == 0 || strcmp(word2, "sword") == 0 || strcmp(word2, "anvil") == 0) && at(val2)) { words[wdx + 1] = word; txt[wdx + 1] = txt[wdx]; word = POUR + 2000; } } } } /* This is the 'inner' loop. Dispatching of all word in a clause after the first comes through here. */ do { switch (CLASS(word)) { case MOTION: { boolean do_part2; int i; do_part2 = FALSE; type = CLASS(verbs[vrbx]); val = VAL(verbs[vrbx]); if (!vrbx) do_part2 = TRUE; else { if (type > ACTION) { rspeak(confuz()); return (FALSE); } } if (type == ACTION) { if (val == GO) do_part2 = TRUE; else { if (val == TAKE) { for (i = 0; i < 20; i++) if (takdir[i] == val) do_part2 = TRUE; } if (!do_part2) { word = vocab(txt[wdx], 1); if (word) words[wdx--] = word; } } } else if (type != CRAWL && type != JUMP && type != CLIMB) do_part2 = TRUE; if (do_part2) { verbs[1] = word; vrbx = 1; if (strcmp(txt[wdx], "west") == 0) { iwest++; if (iwest == 10) rspeak(17); } } break; } case NOUN: if (pflag) { if (!doiobj()) return (FALSE); } else { word = VAL(word); if (word == ALL) { if (!do_scoop_up()) return (FALSE); } else { doobj(&word); if (word > 0) { objs[++objx] = word; otxt[objx] = txt[wdx]; } else { clrlin(); pflag = FALSE; wdx++; while (words[wdx]) { if (CLASS(words[wdx]) == CONJUNCTION) break; wdx++; } if (words[wdx] == 0) return (FALSE); } } } break; case ACTION: if (vrbx == 0) vrbx++; else { if (VAL(verbs[vrbx]) == TAKE) { val = VAL(word); if (val == DRINK || val == INVENTORY || val == SCORE || val == NOTHING || val == LOOK); else if (val == GO && ( strcmp(txt[wdx], "walk") == 0 || strcmp(txt[wdx], "run") == 0 || strcmp(txt[wdx], "hike") == 0)); else { rspeak(confuz()); return (FALSE); } } else if (objx || CLASS(words[wdx - 1]) == CONJUNCTION) { rspeak(confuz()); return (FALSE); } } verbs[vrbx] = word; vtxt[vrbx] = txt[wdx]; break; case MISC: if (vrbx) { rspeak(confuz()); return (FALSE); } verbs[1] = word; vrbx = 1; break; case PREPOSITION: if (CLASS(verbs[vrbx]) != ACTION || iobx) { rspeak(confuz()); return (FALSE); } vrbkey = vkey[VAL(verbs[vrbx])]; if (!vrbkey) { rspeak(confuz()); return (FALSE); } prep = VAL(word); pflag = TRUE; break; case ADJACTIVE: /* Adjective handler. Scarf the next word, make sure it is a valid object for this object. Then call getobj to see if it is really there, Then link into object code. */ adj = VAL(word); if (!check_next()) return (FALSE); else if (CLASS(word) == CONJUNCTION) { printf("%s what?\n", txt[wdx - 1]); return (FALSE); } else { if (CLASS(word) != NOUN) word = vocab(txt[wdx], NOUN); if (word == -1 || CLASS(word) != NOUN || VAL(word) == ALL) { rspeak(confuz()); return (FALSE); } words[wdx] = word; kk = VAL(word); for (k = adjkey[adj]; adjtab[k] >= 0; k++) { if (kk == abs(adjtab[k])) break; } if (adjtab[k] < 0) { rspeak(confuz()); return (FALSE); } } break; case CONJUNCTION: if (!check_next()) return (FALSE); switch (CLASS(word)) { case MOTION: case ACTION: case MISC: words[wdx--] = 0; break; case NOUN: case ADJACTIVE: break; case PREPOSITION: case CONJUNCTION: rspeak(confuz()); return (FALSE); default: bug(33); } break; default: bug(33); } word = words[++wdx]; if (word < 0) { if (pct(50)) printf("I don't understand the word %s?\n", txt[wdx]); else printf("Mumble ? %s\n", txt[wdx]); words[wdx+1] = 0; return (FALSE); } type = CLASS(word); if (type == NOUN) { /* It's not the first: Make sure he included a comma or 'and'. Differenctiate between direct & indirect objects. Check for special case of multiple ofjects: 'feed bear honey' or 'throw troll nugget'. */ if ((pflag ? iobx : objx) && CLASS(words[wdx - 1]) != CONJUNCTION) { val = VAL(verbs[vrbx]); if (!living(objs[objx]) || (val != THROW && val != FEED)) { rspeak(confuz()); return (FALSE); } iobx++; iobjs[iobx] = objs[objx]; objs[objx] = 0; objx++; } } } while (word); if (verbs[1] == 0) { if (objs[1] == 0) { rspeak(confuz()); clrlin(); } else if (objs[2]) printf("What do you want to do with them?\n"); else printf("What do you want to do with %s?\n", otxt[1]); return (FALSE); } else if (objx > 1 && iobx > 1) { rspeak(confuz()); return (FALSE); } return (TRUE); }
void main(int argc, char *argv[]) { int cpus = (int)sysconf(_SC_NPROCESSORS_CONF); size_t page_size = (size_t)sysconf(_SC_PAGESIZE); unsigned long phys_pages = sysconf(_SC_PHYS_PAGES); unsigned long max_pages = (phys_pages * 2); /* 2x is arbitrary */ unsigned long cpu_counters[cpus]; unsigned long mem_random_counter, mem_recent_counter; pthread_t mem_random_worker, mem_recent_worker; unsigned long init_mem_size = calc_init_mem_size(); unsigned long inc_mem_size = calc_inc_mem_size(); unsigned long bl_cpu_count = 0, bl_random_count = 0, bl_recent_count = 0; unsigned long alloc_cpu_count, alloc_random_count, alloc_recent_count, alloc_ms; long alloc_loads; double used_mem; struct timespec before, after; int a; for (a=1; a<argc; a++) { if (!strcmp("-nocpu", argv[a])) no_cpu = 1; else if (!strcmp("-norandom", argv[a])) no_random = 1; else if (!strcmp("-norecent", argv[a])) no_recent = 1; else if (!strcmp("-nofillpages", argv[a])) random_fill_pages = 0; else if (!strcmp("-halffillpages", argv[a])) random_fill_pages = 1; else if (!strcmp("-fillpages", argv[a])) random_fill_pages = 2; else if (!strcmp("-worktime", argv[a])) work_sleep_time = atoi(argv[++a]); else if (!strcmp("-recentpages", argv[a])) recent_pages = atoi(argv[++a]); else if (!strcmp("-help", argv[a]) || !strcmp("-h", argv[a])) { show_help(argv); return; } else { printf("Invalid opt : %s\n",argv[a]); show_help(argv); return; } } pages = calloc(max_pages, sizeof(void*)); create_base_page(page_size); printf("Version %d\n",VERSION); printf("zswap max pool pct %d\n", get_zswap_max_pool()); printf("Getting baseline numbers\n"); fflush(NULL); if (!no_cpu) { start_cpu_workers(cpus, cpu_counters); bzero(cpu_counters, cpus * sizeof(unsigned long)); sleep(work_sleep_time); bl_cpu_count = calc_counter(cpu_counters, cpus); cpu_workers_pause = 1; } page_count += alloc_pages(&pages[page_count], page_size, page_size * recent_pages * 1024); if (!no_random) { pthread_create(&mem_random_worker, NULL, &random_page_worker, &mem_random_counter); mem_random_counter = 0; sleep(work_sleep_time); bl_random_count = mem_random_counter; mem_random_pause = 1; } if (!no_recent) { pthread_create(&mem_recent_worker, NULL, &recent_page_worker, &mem_recent_counter); mem_recent_counter = 0; sleep(work_sleep_time); bl_recent_count = mem_recent_counter; } printf("Baseline CPU %ld MEM random %ld recent %ld\n", bl_cpu_count, bl_random_count, bl_recent_count); printf("Allocating %ldm of initial memory\n", init_mem_size / (1024 * 1024)); fflush(NULL); page_count += alloc_pages(&pages[page_count], page_size, init_mem_size); cpu_workers_pause = 0; mem_random_pause = 0; sleep(1); switch (random_fill_pages) { case 1: printf("Allocated pages half-filled with random numbers\n"); break; case 2: printf("Allocated pages filled with random numbers\n"); break; default: printf("Allocated pages zero-filled (except 1 byte to force physical page allocation)\n"); break; } printf("All mem units %% of total physical mem\n"); printf("CPU and MEMORY units %% of baseline measurement\n"); printf("Allocation time units ms\n"); printf("Alloc period is when new memory is being allocated\n"); printf("Recent page testing %dk most recently allocated pages\n",recent_pages); printf("Measure period is %d secs sleep delay to measure counters\n", work_sleep_time); printf("\n"); printf(" | Measure Period | Alloc Period |\n"); printf("total|used|swap| CPU | MEMORY | MEMORY | zswap | user| sys | idle| iowt| alloc | CPU | MEMORY | MEMORY | zswap |\n"); printf(" mem | mem| mem| | random | recent | loads | | | | | time | | random | recent | loads |\n"); printf("------------------------------------------------------------------------------------------------------------------------\n"); fflush(NULL); do { if (page_count + (inc_mem_size/page_size) > max_pages) { printf("Too many pages allocated, exiting\n"); break; } bzero(cpu_counters, cpus * sizeof(unsigned long)); mem_random_counter = 0; mem_recent_counter = 0; get_frontswap_loads(); if (clock_gettime(CLOCK_MONOTONIC_RAW, &before)) { printf("Error getting timestamp\n"); break; } page_count += alloc_pages(&pages[page_count], page_size, inc_mem_size); if (clock_gettime(CLOCK_MONOTONIC_RAW, &after)) { printf("Error getting timestamp\n"); break; } alloc_cpu_count = calc_counter(cpu_counters, cpus); alloc_random_count = mem_random_counter; alloc_recent_count = mem_recent_counter; alloc_ms = calc_time_diff_ms(before, after); alloc_loads = get_frontswap_loads(); used_mem = calc_used_mem(); bzero(cpu_counters, cpus * sizeof(unsigned long)); mem_random_counter = 0; mem_recent_counter = 0; get_stat_data(); sleep(work_sleep_time); get_stat_data(); printf(" %3.0f | %2.0f | %2.0f | %3.0f | %7.3f | %7.3f | %7ld |%4ld |%4ld |%4ld |%4ld | %5ld | %3.0f | %7.3f | %7.3f | %7ld |\n", used_mem, calc_used_mem_noswap(), calc_used_swap(), pct(calc_counter(cpu_counters, cpus), bl_cpu_count), pct(mem_random_counter, bl_random_count), pct(mem_recent_counter, bl_recent_count), get_frontswap_loads(), stat_user, stat_system, stat_idle, stat_iowait, alloc_ms, adj_counter_pct(alloc_cpu_count, bl_cpu_count, alloc_ms), adj_counter_pct(alloc_random_count, bl_random_count, alloc_ms), adj_counter_pct(alloc_recent_count, bl_recent_count, alloc_ms), alloc_loads); fflush(NULL); } while (used_mem < MAX_USED_MEM); cpu_workers_exit = mem_random_exit = mem_recent_exit = 1; }
void init_RANK_struct_from_SCORES(RANK *rank, SCORES *scor[], int nscor, char *calc_formula) { int blk=0,trt,i,n,mlen=0,msclen=0,g; int c,s,d; /* set it to the max number of speakers for all systems */ for (n=0; n<nscor; n++){ if (blk < scor[n]->num_grp) blk = scor[n]->num_grp; if (msclen < strlen(scor[n]->title)) msclen = strlen(scor[n]->title); for (g=0; g<scor[n]->num_grp; g++) if (mlen < strlen(scor[n]->grp[g].name)) mlen = strlen(scor[n]->grp[g].name); } trt = nscor; rank->n_blk = blk; rank->n_trt = trt; alloc_2dimarr(rank->blk_name,blk,mlen+1,char); /* copy in only what's available from the first system */ for (i=0; i<blk; i++) if (i < scor[0]->num_grp) strcpy(rank->blk_name[i] ,scor[0]->grp[i].name); alloc_2dimarr(rank->trt_name,trt,msclen+1,char); for (i=0; i<trt; i++){ strcpy(rank->trt_name[i],scor[i]->title); } alloc_2dimZ(rank->trt_ranks ,blk,trt,double,0.0); alloc_2dimZ(rank->blk_ranks ,blk,trt,double,0.0); alloc_2dimarr(rank->pcts ,blk,trt,double); alloc_singarr(rank->trt_Ovr_ranks ,trt,double); alloc_singarr(rank->blk_Ovr_ranks ,blk,double); alloc_singarr(rank->blk_srt_ind ,trt,int); alloc_singarr(rank->trt_srt_ind ,blk,int); for (n=0; n<nscor; n++) for (g=0; g<scor[n]->num_grp; g++){ c = scor[n]->grp[g].corr; s = scor[n]->grp[g].sub; d = scor[n]->grp[g].del; i = scor[n]->grp[g].ins; switch (*calc_formula) { case 'R': rank->pcts[g][n] = pct(c, (c + s + d)); break; case 'E': rank->pcts [g][n] = pct((i + s + d),(c + d + s)); break; case 'W': rank->pcts[g][n] = 100.0000 - pct((i + s + d),(c + d + s)); break; default: fprintf(stderr,"You did not give calc_pct a formula\n"); break; } } if (*calc_formula == 'E' ) rank_on_pcts(rank,INCREASING); else rank_on_pcts(rank,DECREASING); }
static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v) { struct timeval now; struct obd_device *dev = seq->private; struct client_obd *cli = &dev->u.cli; unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum; int i; cfs_gettimeofday(&now); client_obd_list_lock(&cli->cl_loi_list_lock); seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n", now.tv_sec, now.tv_usec); seq_printf(seq, "read RPCs in flight: %d\n", cli->cl_r_in_flight); seq_printf(seq, "write RPCs in flight: %d\n", cli->cl_w_in_flight); seq_printf(seq, "pending write pages: %d\n", cli->cl_pending_w_pages); seq_printf(seq, "pending read pages: %d\n", cli->cl_pending_r_pages); seq_printf(seq, "\n\t\t\tread\t\t\twrite\n"); seq_printf(seq, "pages per rpc rpcs %% cum %% |"); seq_printf(seq, " rpcs %% cum %%\n"); read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist); write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist); read_cum = 0; write_cum = 0; for (i = 0; i < OBD_HIST_MAX; i++) { unsigned long r = cli->cl_read_page_hist.oh_buckets[i]; unsigned long w = cli->cl_write_page_hist.oh_buckets[i]; read_cum += r; write_cum += w; seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n", 1 << i, r, pct(r, read_tot), pct(read_cum, read_tot), w, pct(w, write_tot), pct(write_cum, write_tot)); if (read_cum == read_tot && write_cum == write_tot) break; } seq_printf(seq, "\n\t\t\tread\t\t\twrite\n"); seq_printf(seq, "rpcs in flight rpcs %% cum %% |"); seq_printf(seq, " rpcs %% cum %%\n"); read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist); write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist); read_cum = 0; write_cum = 0; for (i = 0; i < OBD_HIST_MAX; i++) { unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i]; unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i]; read_cum += r; write_cum += w; seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n", i, r, pct(r, read_tot), pct(read_cum, read_tot), w, pct(w, write_tot), pct(write_cum, write_tot)); if (read_cum == read_tot && write_cum == write_tot) break; } seq_printf(seq, "\n\t\t\tread\t\t\twrite\n"); seq_printf(seq, "offset rpcs %% cum %% |"); seq_printf(seq, " rpcs %% cum %%\n"); read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist); write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist); read_cum = 0; write_cum = 0; for (i = 0; i < OBD_HIST_MAX; i++) { unsigned long r = cli->cl_read_offset_hist.oh_buckets[i]; unsigned long w = cli->cl_write_offset_hist.oh_buckets[i]; read_cum += r; write_cum += w; seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n", (i == 0) ? 0 : 1 << (i - 1), r, pct(r, read_tot), pct(read_cum, read_tot), w, pct(w, write_tot), pct(write_cum, write_tot)); if (read_cum == read_tot && write_cum == write_tot) break; } client_obd_list_unlock(&cli->cl_loi_list_lock); return 0; }
// ========================================================================= Pruning_table_ct_ef:: Pruning_table_ct_ef(Transform_table *tr, Turn_table *tn, int co, int eo): co(co), eo(eo) // ------------------------------------------------------------------------- // the memory tables are used for state tree pruning where // indices are characteristic numbers of the cube and value is number // that specifies the least length to the goal state that // can be proven // this length is at most the same as the right one // setting of the tables are done as BFS (wave algorithm) on the graph { int n, d, mx = 0; int ct, ef, t; unsigned int sm; Pack_ct pct(co); int Nct = pct.len(); int Sct = pct.startlen(); Pack_ef pef(eo); int Nef = pef.len(); int Sef = pef.startlen(); // set all distances as large for (ct = 0; ct < Nct; ct++) for (ef = 0; ef < Nef; ef++) a[ct][ef] = BIG; // get the maximal length of a single move in the particular metrics for (t = 0; t < A_N_TW; t++) if (mx < tn->a_len(t)) mx = tn->a_len(t); // phase 1 only fprintf(stderr, "\n - corner twists - edge flips (phase 1, %i x %i goal/s):\n", Sct, Sef); // set all goal positions to the length 0 for (ct = 0; ct < Sct; ct++) for (ef = 0; ef < Sef; ef++) a[pct.start(ct)][pef.start(ef)] = 0; d = 0; n = Sct * Sef; // number of all found configurations at the given depth sm = 0; // all found configurations upto now // here starts 'wave' algorithm for graph searching // where vertices are different configurations // and edges are transitions between them while (n) { // while still something have changed do again fprintf(stderr," %2i %8i %10u\n", d, n, sm += n); n = 0; d++; for (ct = 0; ct < Nct; ct++) { for (ef = 0; ef < Nef; ef++) { // process only field with value from d - mx to d - 1 (included) if (d <= a[ct][ef] || d > a[ct][ef] + mx) continue; // try all transitions from the actual state for (t = 0; t < A_N_TW; t++) { // we need to get exactly to the length d if (d == a[ct][ef] + tn->a_len(t)) { // we compute indices of new state after the transition 't' int nct = tr->ct->a_do_tw(t, ct); int nef = tr->ef->a_do_tw(t, ef); // if new length is shorter then write it if (a[nct][nef] > d) { a[nct][nef] = d; n++; // change have happend } } } } } } }
void dosum(void) { struct nchstats nchstats; int mib[2], nselcoll; long long nchtotal; size_t size; if (nlistf == NULL && memf == NULL) { size = sizeof(struct uvmexp); mib[0] = CTL_VM; mib[1] = VM_UVMEXP; if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0) { warn("could not read vm.uvmexp"); bzero(&uvmexp, sizeof(struct uvmexp)); } } else { kread(X_UVMEXP, &uvmexp, sizeof(struct uvmexp)); } /* vm_page constants */ (void)printf("%11u bytes per page\n", uvmexp.pagesize); /* vm_page counters */ (void)printf("%11u pages managed\n", uvmexp.npages); (void)printf("%11u pages free\n", uvmexp.free); (void)printf("%11u pages active\n", uvmexp.active); (void)printf("%11u pages inactive\n", uvmexp.inactive); (void)printf("%11u pages being paged out\n", uvmexp.paging); (void)printf("%11u pages wired\n", uvmexp.wired); (void)printf("%11u pages zeroed\n", uvmexp.zeropages); (void)printf("%11u pages reserved for pagedaemon\n", uvmexp.reserve_pagedaemon); (void)printf("%11u pages reserved for kernel\n", uvmexp.reserve_kernel); /* swap */ (void)printf("%11u swap pages\n", uvmexp.swpages); (void)printf("%11u swap pages in use\n", uvmexp.swpginuse); (void)printf("%11u total anon's in system\n", uvmexp.nanon); (void)printf("%11u free anon's\n", uvmexp.nfreeanon); /* stat counters */ (void)printf("%11u page faults\n", uvmexp.faults); (void)printf("%11u traps\n", uvmexp.traps); (void)printf("%11u interrupts\n", uvmexp.intrs); (void)printf("%11u cpu context switches\n", uvmexp.swtch); (void)printf("%11u fpu context switches\n", uvmexp.fpswtch); (void)printf("%11u software interrupts\n", uvmexp.softs); (void)printf("%11u syscalls\n", uvmexp.syscalls); (void)printf("%11u pagein operations\n", uvmexp.pageins); (void)printf("%11u forks\n", uvmexp.forks); (void)printf("%11u forks where vmspace is shared\n", uvmexp.forks_sharevm); (void)printf("%11u kernel map entries\n", uvmexp.kmapent); /* daemon counters */ (void)printf("%11u number of times the pagedaemon woke up\n", uvmexp.pdwoke); (void)printf("%11u revolutions of the clock hand\n", uvmexp.pdrevs); (void)printf("%11u pages freed by pagedaemon\n", uvmexp.pdfreed); (void)printf("%11u pages scanned by pagedaemon\n", uvmexp.pdscans); (void)printf("%11u pages reactivated by pagedaemon\n", uvmexp.pdreact); (void)printf("%11u busy pages found by pagedaemon\n", uvmexp.pdbusy); if (nlistf == NULL && memf == NULL) { size = sizeof(nchstats); mib[0] = CTL_KERN; mib[1] = KERN_NCHSTATS; if (sysctl(mib, 2, &nchstats, &size, NULL, 0) < 0) { warn("could not read kern.nchstats"); bzero(&nchstats, sizeof(nchstats)); } } else { kread(X_NCHSTATS, &nchstats, sizeof(nchstats)); } nchtotal = nchstats.ncs_goodhits + nchstats.ncs_neghits + nchstats.ncs_badhits + nchstats.ncs_falsehits + nchstats.ncs_miss + nchstats.ncs_long; (void)printf("%11lld total name lookups\n", nchtotal); (void)printf("%11s cache hits (%d%% pos + %d%% neg) system %d%% " "per-directory\n", "", pct(nchstats.ncs_goodhits, nchtotal), pct(nchstats.ncs_neghits, nchtotal), pct(nchstats.ncs_pass2, nchtotal)); (void)printf("%11s deletions %d%%, falsehits %d%%, toolong %d%%\n", "", pct(nchstats.ncs_badhits, nchtotal), pct(nchstats.ncs_falsehits, nchtotal), pct(nchstats.ncs_long, nchtotal)); if (nlistf == NULL && memf == NULL) { size = sizeof(nselcoll); mib[0] = CTL_KERN; mib[1] = KERN_NSELCOLL; if (sysctl(mib, 2, &nselcoll, &size, NULL, 0) < 0) { warn("could not read kern.nselcoll"); nselcoll = 0; } } else { kread(X_NSELCOLL, &nselcoll, sizeof(nselcoll)); } (void)printf("%11d select collisions\n", nselcoll); }