END_TEST START_TEST(getversion_returns_a_version) { ck_assert_int_gt((int)strlen(getversion()), 1); ck_assert(strchr(getversion(), '_') == NULL); ck_assert(strchr(getversion(), '.') != NULL); }
int os_getversion(lua_State* L) { struct OsVersionInfo info = {0, 0, 0, NULL, 0}; getversion(&info); lua_newtable(L); lua_pushstring(L, "majorversion"); lua_pushnumber(L, (lua_Number)info.majorversion); lua_settable(L, -3); lua_pushstring(L, "minorversion"); lua_pushnumber(L, (lua_Number)info.minorversion); lua_settable(L, -3); lua_pushstring(L, "revision"); lua_pushnumber(L, (lua_Number)info.revision); lua_settable(L, -3); lua_pushstring(L, "description"); lua_pushstring(L, info.description); lua_settable(L, -3); if (info.isalloc) { free((void*)info.description); } return 1; }
void usage() { std::fprintf(stderr, "mp4fpsmod %s\n" "(libmp4v2 " MP4V2_PROJECT_version ")\n" "usage: mp4fpsmod [options] FILE\n" " -o <file> Specify MP4 output filename.\n" " -i, --inplace Edit in-place instead of creating a new file.\n" " -p, --print <file> Output current timecodes into timecode-v2 format.\n" " -t, --tcfile <file> Edit timecodes with timecode-v2 file.\n" " -x, --optimize Optimize timecode\n" " -r, --fps <nframes:fps>\n" " Edit timecodes with the spec.\n" " You can specify -r more than two times, to produce\n" " VFR movie.\n" " \"nframes\" is number of frames, which \"fps\" is\n" " aplied to.\n" " 0 as nframes means \"rest of the movie\"\n" " \"fps\" is a rational or integer.\n" " For example, 25 or 30000/1001.\n" " -c, --compress-dts Enable DTS compression.\n" " -d, --delay <n> Delay audio by n millisecond.\n" " -T, --timescale <keep|n>\n" " keep: Keep original timescale.\n" " n: Set timescale of videotrack to n.\n" , getversion()); std::exit(1); }
void savestate(string pattern) { char namebuf[256]; stream str; sprintf(namebuf, pattern, nstep & 1); // construct alternate name str = stropen(namebuf, "w!"); // open state output file put_string(str, "program", getprog()); put_string(str, "version", getversion()); put_string(str, "headline", headline); // save control parameters put_data(str, "dtime", RealType, &dtime, 0); put_data(str, "nstatic", IntType, &nstatic, 0); #if !defined(QUICKSCAN) put_data(str, "theta", RealType, &theta, 0); #endif put_data(str, "usequad", BoolType, &usequad, 0); put_data(str, "eps", RealType, &eps, 0); put_string(str, "options", options); put_string(str, "outputs", outputs); put_data(str, "tstop", RealType, &tstop, 0); put_data(str, "dtout", RealType, &dtout, 0); put_data(str, "tnow", RealType, &tnow, 0); // save state variables put_data(str, "tout", RealType, &tout, 0); put_data(str, "nstep", IntType, &nstep, 0); put_data(str, "rsize", RealType, &rsize, 0); put_data(str, "nbody", IntType, &nbody, 0); put_data(str, "timesteps", IntType, &nbody, 0); put_data(str, "bodytab", AnyType, bodytab, nbody, sizeof(body), 0); strclose(str); }
void restorestate(string file) { stream str; string program, version; str = stropen(file, "r"); // open state input file program = get_string(str, "program"); version = get_string(str, "version"); if (! streq(program, getprog()) || // check program, version ! streq(version, getversion())) eprintf("[%s: warning: state file may be outdated]\n", getprog()); headline = get_string(str, "headline"); // read control parameters get_data(str, "dtime", RealType, &dtime, 0); get_data(str, "nstatic", IntType, &nstatic, 0); #if !defined(QUICKSCAN) get_data(str, "theta", RealType, &theta, 0); #endif get_data(str, "usequad", BoolType, &usequad, 0); get_data(str, "eps", RealType, &eps, 0); options = get_string(str, "options"); outputs = get_string(str, "outputs"); get_data(str, "tstop", RealType, &tstop, 0); get_data(str, "dtout", RealType, &dtout, 0); get_data(str, "tnow", RealType, &tnow, 0); // read state variables get_data(str, "tout", RealType, &tout, 0); get_data(str, "nstep", IntType, &nstep, 0); get_data(str, "rsize", RealType, &rsize, 0); get_data(str, "nbody", IntType, &nbody, 0); get_data(str, "timesteps", IntType, &nbody, 0); bodytab = (bodyptr) allocate(nbody * sizeof(body)); get_data(str, "bodytab", AnyType, bodytab, nbody, sizeof(body), 0); strclose(str); }
void runsyslinuximage(const char*cmd, long ipappend) { unsigned int numfun = 0; char *ptr,*cmdline; getversion(NULL,&numfun); // Function 16h not supported Fall back to runcommand if (numfun < 0x16) runsyslinuxcmd(cmd); // Try the Run Kernel Image function // Split command line into strcpy(__com32.cs_bounce,cmd); ptr = __com32.cs_bounce; // serach for first space or end of string while ( (*ptr) && (*ptr != ' ')) ptr++; if (!*ptr) cmdline = ptr; // no command line else { *ptr++='\0'; // terminate kernal name cmdline = ptr+1; while (*cmdline != ' ') cmdline++; // find first non-space } // Now call the interrupt REG_BX(inreg) = OFFS(cmdline); REG_ES(inreg) = SEG(cmdline); REG_SI(inreg) = OFFS(__com32.cs_bounce); REG_DS(inreg) = SEG(__com32.cs_bounce); REG_EDX(inreg) = 0; __intcall(0x22,&inreg,&outreg); // If successful does not return }
int main(int argc, string *argv) { initparam(argv, defv); printf("program %s:\n", getprog()); printf(" input = \"%s\" [%o]\n", getparam("input"), getparamstat("input")); printf(" output = \"%s\" [%o]\n", getparam("output"), getparamstat("output")); printf(" answer = %d [%o]\n", getiparam("answer"), getparamstat("answer")); printf(" value = %g [%o]\n", getdparam("value"), getparamstat("value")); printf(" flag = %s [%o]\n", getbparam("flag") ? "TRUE" : "FALSE", getparamstat("flag")); printf(" foobar = \"%s\" [%o]\n", getparam("foobar"), getparamstat("foobar")); printf(" VERSION = \"%s\" [%o]\n", getversion(), getparamstat("VERSION")); if (getbparam("flag")) { printf("getparamstat(\"junk\") = %o\n", getparamstat("junk")); printf("calling getparam(\"junk\")\n"); (void) getparam("junk"); } return (0); }
int os_getversion(lua_State* L) { struct OsVersionInfo info; getversion(&info); lua_newtable(L); lua_pushstring(L, "majorversion"); lua_pushnumber(L, info.majorversion); lua_settable(L, -3); lua_pushstring(L, "minorversion"); lua_pushnumber(L, info.minorversion); lua_settable(L, -3); lua_pushstring(L, "revision"); lua_pushnumber(L, info.revision); lua_settable(L, -3); lua_pushstring(L, "description"); lua_pushstring(L, info.description); lua_settable(L, -3); return 1; }
/* ARGSUSED */ int showversion(int f GCC_UNUSED, int n) { personals(n); mlforce("%s", getversion()); return TRUE; }
/* * The Beginning */ int main(int argc, char **argv, char **envp) { extern char *__progname; char *cp; int c; progname = __progname; if (init(argc, argv, envp) < 0) exit(1); while ((c = getopt(argc, argv, "SDV")) != -1) switch (c) { case 'S': isserver++; break; case 'D': debug++; break; case 'V': printf("%s\n", getversion()); exit(0); case '?': default: error("Bad command line option."); usage(); } if (!isserver) { error("Use the -S option to run this program in server mode."); exit(1); } /* Use stdin and stdout for remote descriptors */ rem_r = fileno(stdin); rem_w = fileno(stdout); /* Set logging */ if ((cp = msgparseopts(localmsglist, TRUE)) != NULL) fatalerr("Bad message logging option (%s): %s", localmsglist, cp); /* * Main processing function */ server(); exit(nerrs != 0); }
int main(int argc, char **argv) { int c; int mask = 0; int minor = 0; int interval = 0; int fd; char buf[64]; int i; while ((c = getopt(argc, argv, "avmcsbM:i:")) != EOF) switch (c) { case 'a': mask = ~0; break; case 'v': mask |= DRM_VERSION; break; case 'm': mask |= DRM_MEMORY; break; case 'c': mask |= DRM_CLIENTS; break; case 's': mask |= DRM_STATS; break; case 'b': mask |= DRM_BUSID; break; case 'i': interval = strtol(optarg, NULL, 0); break; case 'M': minor = strtol(optarg, NULL, 0); break; default: fprintf( stderr, "Usage: dristat [options]\n\n" ); fprintf( stderr, "Displays DRM information. Use with no arguments to display available cards.\n\n" ); fprintf( stderr, " -a Show all available information\n" ); fprintf( stderr, " -b Show DRM bus ID's\n" ); fprintf( stderr, " -c Display information about DRM clients\n" ); fprintf( stderr, " -i [interval] Continuously display statistics every [interval] seconds\n" ); fprintf( stderr, " -v Display DRM module and card version information\n" ); fprintf( stderr, " -m Display memory use information\n" ); fprintf( stderr, " -s Display DRM statistics\n" ); fprintf( stderr, " -M [minor] Select card by minor number\n" ); return 1; } for (i = 0; i < 16; i++) if (!minor || i == minor) { sprintf(buf, DRM_DEV_NAME, DRM_DIR_NAME, i); fd = drmOpenMinor(i, 1, DRM_NODE_PRIMARY); if (fd >= 0) { printf("%s\n", buf); if (mask & DRM_BUSID) getbusid(fd); if (mask & DRM_VERSION) getversion(fd); if (mask & DRM_MEMORY) getvm(fd); if (mask & DRM_CLIENTS) getclients(fd); if (mask & DRM_STATS) getstats(fd, interval); close(fd); } } return 0; }
// --------------------------------------------------------------------- string qtstate(string p) { QStringList s=s2q(p).split(" ",QString::SkipEmptyParts); QString c; string r; if (s.size()==0) return ""; bool all="all"==s.at(0); c="debugpos"; if (all || s.contains(c)) r+=qpair(c,p2q(config.DebugPosX)); c="profont"; if (all || s.contains(c)) r+=qpair(c,fontspec(app->font())); c="project"; if (all || s.contains(c)) r+=qpair(c,recent.ProjectOpen ? project.Path : ""); c="version"; if (all || s.contains(c)) r+=qpair(c,getversion()); return r; }
void printcfgfile(void) { ibwnode *p = ifacebw; printf("# vnStat %s config file\n", getversion()); printf("##\n\n"); printf("# default interface\n"); printf("Interface \"%s\"\n\n", cfg.iface); printf("# location of the database directory\n"); printf("DatabaseDir \"%s\"\n\n", cfg.dbdir); printf("# locale (LC_ALL) (\"-\" = use system locale)\n"); printf("Locale \"%s\"\n\n", cfg.locale); printf("# on which day should months change\n"); printf("MonthRotate %d\n\n", cfg.monthrotate); printf("# date output formats for -d, -m, -t and -w\n"); printf("# see 'man date' for control codes\n"); printf("DayFormat \"%s\"\n", cfg.dformat); printf("MonthFormat \"%s\"\n", cfg.mformat); printf("TopFormat \"%s\"\n\n", cfg.tformat); printf("# characters used for visuals\n"); printf("RXCharacter \"%c\"\n", cfg.rxchar[0]); printf("TXCharacter \"%c\"\n", cfg.txchar[0]); printf("RXHourCharacter \"%c\"\n", cfg.rxhourchar[0]); printf("TXHourCharacter \"%c\"\n\n", cfg.txhourchar[0]); printf("# how units are prefixed when traffic is shown\n"); printf("# 0 = IEC standard prefixes (KiB/MiB/GiB/TiB)\n"); printf("# 1 = old style binary prefixes (KB/MB/GB/TB)\n"); printf("UnitMode %d\n\n", cfg.unitmode); printf("# how units are prefixed when traffic rate is shown\n"); printf("# 0 = IEC binary prefixes (Kibit/s...)\n"); printf("# 1 = SI decimal prefixes (kbit/s...)\n"); printf("RateUnitMode %d\n\n", cfg.rateunitmode); printf("# output style\n"); printf("# 0 = minimal & narrow, 1 = bar column visible\n"); printf("# 2 = same as 1 except rate in summary and weekly\n"); printf("# 3 = rate column visible\n"); printf("OutputStyle %d\n\n", cfg.ostyle); printf("# used rate unit (0 = bytes, 1 = bits)\n"); printf("RateUnit %d\n\n", cfg.rateunit); printf("# try to detect interface maximum bandwidth, 0 = disable feature\n"); printf("# MaxBandwidth will be used as fallback value when enabled\n"); printf("BandwidthDetection %d\n\n", cfg.bwdetection); printf("# maximum bandwidth (Mbit) for all interfaces, 0 = disable feature\n# (unless interface specific limit is given)\n"); printf("MaxBandwidth %d\n\n", cfg.maxbw); printf("# interface specific limits\n"); printf("# example 8Mbit limit for eth0 (remove # to activate):\n"); printf("#MaxBWeth0 8\n"); while (p != NULL) { printf("MaxBW%s %d\n", p->interface, p->limit); p = p->next; } printf("\n"); printf("# how many seconds should sampling for -tr take by default\n"); printf("Sampletime %d\n\n", cfg.sampletime); printf("# default query mode\n"); printf("# 0 = normal, 1 = days, 2 = months, 3 = top10\n"); printf("# 4 = exportdb, 5 = short, 6 = weeks, 7 = hours\n"); printf("QueryMode %d\n\n", cfg.qmode); printf("# filesystem disk space check (1 = enabled, 0 = disabled)\n"); printf("CheckDiskSpace %d\n\n", cfg.spacecheck); printf("# database file locking (1 = enabled, 0 = disabled)\n"); printf("UseFileLocking %d\n\n", cfg.flock); printf("# how much the boot time can variate between updates (seconds)\n"); printf("BootVariation %d\n\n", cfg.bvar); printf("# log days without traffic to daily list (1 = enabled, 0 = disabled)\n"); printf("TrafficlessDays %d\n", cfg.traflessday); printf("\n\n"); printf("# vnstatd\n##\n\n"); printf("# switch to given user when started as root (leave empty to disable)\n"); printf("DaemonUser \"%s\"\n\n", cfg.daemonuser); printf("# switch to given user when started as root (leave empty to disable)\n"); printf("DaemonGroup \"%s\"\n\n", cfg.daemongroup); printf("# how often (in seconds) interface data is updated\n"); printf("UpdateInterval %d\n\n", cfg.updateinterval); printf("# how often (in seconds) interface status changes are checked\n"); printf("PollInterval %d\n\n", cfg.pollinterval); printf("# how often (in minutes) data is saved to file\n"); printf("SaveInterval %d\n\n", cfg.saveinterval); printf("# how often (in minutes) data is saved when all interface are offline\n"); printf("OfflineSaveInterval %d\n\n", cfg.offsaveinterval); printf("# how often (in minutes) bandwidth detection is redone when\n"); printf("# BandwidthDetection is enabled (0 = disabled)\n"); printf("BandwidthDetectionInterval %d\n\n", cfg.bwdetectioninterval); printf("# force data save when interface status changes (1 = enabled, 0 = disabled)\n"); printf("SaveOnStatusChange %d\n\n", cfg.savestatus); printf("# enable / disable logging (0 = disabled, 1 = logfile, 2 = syslog)\n"); printf("UseLogging %d\n\n", cfg.uselogging); printf("# create dirs if needed (1 = enabled, 0 = disabled)\n"); printf("CreateDirs %d\n\n", cfg.createdirs); printf("# update ownership of files if needed (1 = enabled, 0 = disabled)\n"); printf("UpdateFileOwner %d\n\n", cfg.updatefileowner); printf("# file used for logging if UseLogging is set to 1\n"); printf("LogFile \"%s\"\n\n", cfg.logfile); printf("# file used as daemon pid / lock file\n"); printf("PidFile \"%s\"\n", cfg.pidfile); printf("\n\n"); printf("# vnstati\n##\n\n"); printf("# title timestamp format\n"); printf("HeaderFormat \"%s\"\n\n", cfg.hformat); printf("# show hours with rate (1 = enabled, 0 = disabled)\n"); printf("HourlyRate %d\n\n", cfg.hourlyrate); printf("# show rate in summary (1 = enabled, 0 = disabled)\n"); printf("SummaryRate %d\n\n", cfg.summaryrate); printf("# layout of summary (1 = with monthly, 0 = without monthly)\n"); printf("SummaryLayout %d\n\n", cfg.slayout); printf("# transparent background (1 = enabled, 0 = disabled)\n"); printf("TransparentBg %d\n\n", cfg.transbg); printf("# image colors\n"); printf("CBackground \"%s\"\n", cfg.cbg); printf("CEdge \"%s\"\n", cfg.cedge); printf("CHeader \"%s\"\n", cfg.cheader); printf("CHeaderTitle \"%s\"\n", cfg.cheadertitle); printf("CHeaderDate \"%s\"\n", cfg.cheaderdate); printf("CText \"%s\"\n", cfg.ctext); printf("CLine \"%s\"\n", cfg.cline); printf("CLineL \"%s\"\n", cfg.clinel); printf("CRx \"%s\"\n", cfg.crx); printf("CTx \"%s\"\n", cfg.ctx); printf("CRxD \"%s\"\n", cfg.crxd); printf("CTxD \"%s\"\n", cfg.ctxd); }
int main(void){ get_symbol("/tmp/proftpd.so", "pr_version_get_str"); printf("Using proftpd.so version: %s\n", getversion()); print_map(); return 0; }
void trafficmeter(char iface[], unsigned int sampletime) { /* received bytes packets errs drop fifo frame compressed multicast */ /* transmitted bytes packets errs drop fifo colls carrier compressed */ uint64_t rx, tx, rxp, txp; int json = 0; IFINFO firstinfo; char buffer[256]; if (cfg.qmode == 10) { json = 1; } /* less than 2 seconds doesn't produce good results */ if (sampletime < 2) { printf("Error: Time for sampling too short.\n"); exit(EXIT_FAILURE); } /* read interface info and get values to the first list */ if (!getifinfo(iface)) { printf("Error: Interface \"%s\" not available, exiting.\n", iface); exit(EXIT_FAILURE); } firstinfo.rx = ifinfo.rx; firstinfo.tx = ifinfo.tx; firstinfo.rxp = ifinfo.rxp; firstinfo.txp = ifinfo.txp; /* wait sampletime and print some nice dots so that the user thinks something is done :) */ if (!json) { snprintf(buffer, 256, "Sampling %s (%u seconds average)", iface, sampletime); printf("%s", buffer); fflush(stdout); sleep(sampletime / 3); printf("."); fflush(stdout); sleep(sampletime / 3); printf("."); fflush(stdout); sleep(sampletime / 3); printf("."); fflush(stdout); if ((sampletime / 3) * 3 != sampletime) { sleep(sampletime - ((sampletime / 3) * 3)); } cursortocolumn(1); eraseline(); } else { sleep(sampletime); } /* read those values again... */ if (!getifinfo(iface)) { printf("Error: Interface \"%s\" not available, exiting.\n", iface); exit(EXIT_FAILURE); } /* calculate traffic and packets seen between updates */ rx = countercalc(&firstinfo.rx, &ifinfo.rx, ifinfo.is64bit); tx = countercalc(&firstinfo.tx, &ifinfo.tx, ifinfo.is64bit); rxp = countercalc(&firstinfo.rxp, &ifinfo.rxp, ifinfo.is64bit); txp = countercalc(&firstinfo.txp, &ifinfo.txp, ifinfo.is64bit); /* show the difference in a readable format or json */ if (!json) { printf("%" PRIu64 " packets sampled in %d seconds\n", rxp + txp, sampletime); printf("Traffic average for %s\n", iface); printf("\n rx %s %5" PRIu64 " packets/s\n", gettrafficrate(rx, sampletime, 15), (uint64_t)(rxp / sampletime)); printf(" tx %s %5" PRIu64 " packets/s\n\n", gettrafficrate(tx, sampletime, 15), (uint64_t)(txp / sampletime)); } else { printf("{\"jsonversion\":\"%d\",", JSONVERSION_TR); printf("\"vnstatversion\":\"%s\",", getversion()); printf("\"interface\":\"%s\",", iface); printf("\"sampletime\":%u,", sampletime); printf("\"rx\":{"); printf("\"ratestring\":\"%s\",", gettrafficrate(rx, sampletime, 0)); printf("\"bytespersecond\":%" PRIu64 ",", (uint64_t)(rx / sampletime)); printf("\"packetspersecond\":%" PRIu64 ",", (uint64_t)(rxp / sampletime)); printf("\"bytes\":%" PRIu64 ",", rx); printf("\"packets\":%" PRIu64 "", rxp); printf("},"); printf("\"tx\":{"); printf("\"ratestring\":\"%s\",", gettrafficrate(tx, sampletime, 0)); printf("\"bytespersecond\":%" PRIu64 ",", (uint64_t)(tx / sampletime)); printf("\"packetspersecond\":%" PRIu64 ",", (uint64_t)(txp / sampletime)); printf("\"bytes\":%" PRIu64 ",", tx); printf("\"packets\":%" PRIu64 "", txp); printf("}}\n"); } }
void livetrafficmeter(char iface[32], int mode) { /* received bytes packets errs drop fifo frame compressed multicast */ /* transmitted bytes packets errs drop fifo colls carrier compressed */ uint64_t rx, tx, rxp, txp, timespent, timeslept; uint64_t rxtotal, txtotal, rxptotal, txptotal; uint64_t rxpmin, txpmin, rxpmax, txpmax; uint64_t rxmin, txmin, rxmax, txmax; uint64_t index = 1; int ratewidth, ppswidth, paddingwidth, json = 0; char buffer[256], buffer2[256]; IFINFO previnfo; if (cfg.qmode == 10) { json = 1; } if (!json) { printf("Monitoring %s... (press CTRL-C to stop)\n\n", iface); if (cfg.ostyle != 4) { printf(" getting traffic..."); fflush(stdout); } } /* enable signal trap */ intsignal = 0; if (signal(SIGINT, sighandler) == SIG_ERR) { perror("signal"); exit(EXIT_FAILURE); } /* set some defaults */ rxtotal = txtotal = rxptotal = txptotal = rxpmax = txpmax = 0; rxpmin = txpmin = rxmin = txmin = MAX64; rxmax = txmax = 0; timeslept = 0; timespent = (uint64_t)time(NULL); /* read /proc/net/dev and get values to the first list */ if (!getifinfo(iface)) { printf("Error: Interface \"%s\" not available, exiting.\n", iface); exit(EXIT_FAILURE); } ratewidth = 15; ppswidth = 5; paddingwidth = 8; /* narrow output mode */ if (cfg.ostyle == 0) { ratewidth = 12; ppswidth = 3; paddingwidth = 4; } if (!json) { cursorhide(); } else { printf("{\"jsonversion\":\"%d\",", JSONVERSION_LIVE); printf("\"vnstatversion\":\"%s\",", getversion()); printf("\"interface\":\"%s\",", iface); printf("\"sampletime\":%d}\n", LIVETIME); } /* loop until user gets bored */ while (intsignal == 0) { timeslept = (uint64_t)time(NULL); /* wait 2 seconds for more traffic */ sleep(LIVETIME); timeslept = (uint64_t)time(NULL) - timeslept; /* break loop without calculations because sleep was probably interrupted */ if (intsignal) { break; } /* use values from previous loop if this isn't the first time */ previnfo.rx = ifinfo.rx; previnfo.tx = ifinfo.tx; previnfo.rxp = ifinfo.rxp; previnfo.txp = ifinfo.txp; /* read those values again... */ if (!getifinfo(iface)) { cursorshow(); printf("Error: Interface \"%s\" not available, exiting.\n", iface); exit(EXIT_FAILURE); } /* calculate traffic and packets seen between updates */ rx = countercalc(&previnfo.rx, &ifinfo.rx, ifinfo.is64bit); tx = countercalc(&previnfo.tx, &ifinfo.tx, ifinfo.is64bit); rxp = countercalc(&previnfo.rxp, &ifinfo.rxp, ifinfo.is64bit); txp = countercalc(&previnfo.txp, &ifinfo.txp, ifinfo.is64bit); /* update totals */ rxtotal += rx; txtotal += tx; rxptotal += rxp; txptotal += txp; /* update min & max */ if (rxmin > rx) { rxmin = rx; } if (txmin > tx) { txmin = tx; } if (rxmax < rx) { rxmax = rx; } if (txmax < tx) { txmax = tx; } if (rxpmin > rxp) { rxpmin = rxp; } if (txpmin > txp) { txpmin = txp; } if (rxpmax < rxp) { rxpmax = rxp; } if (txpmax < txp) { txpmax = txp; } /* show the difference in a readable format or json */ if (!json) { if (mode == 0) { /* packets per second visible */ snprintf(buffer, 128, " rx: %s %*" PRIu64 " p/s", gettrafficrate(rx, LIVETIME, ratewidth), ppswidth, (uint64_t)rxp / LIVETIME); snprintf(buffer2, 128, " %*s tx: %s %*" PRIu64 " p/s", paddingwidth, " ", gettrafficrate(tx, LIVETIME, ratewidth), ppswidth, (uint64_t)txp / LIVETIME); } else { /* total transfer amount visible */ snprintf(buffer, 128, " rx: %s %s", gettrafficrate(rx, LIVETIME, ratewidth), getvalue(rxtotal, 1, RT_Normal)); snprintf(buffer2, 128, " %*s tx: %s %s", paddingwidth, " ", gettrafficrate(tx, LIVETIME, ratewidth), getvalue(txtotal, 1, RT_Normal)); } strcat(buffer, buffer2); if (cfg.ostyle != 4 || !debug) { cursortocolumn(1); eraseline(); } if (cfg.ostyle != 4) { printf("%s", buffer); fflush(stdout); } else { printf("%s\n", buffer); } } else { printf("{\"index\":%" PRIu64 ",", index); printf("\"seconds\":%" PRIu64 ",", (uint64_t)time(NULL) - timespent); printf("\"rx\":{"); printf("\"ratestring\":\"%s\",", gettrafficrate(rx, LIVETIME, 0)); printf("\"bytespersecond\":%" PRIu64 ",", (uint64_t)(rx / LIVETIME)); printf("\"packetspersecond\":%" PRIu64 ",", (uint64_t)(rxp / LIVETIME)); printf("\"bytes\":%" PRIu64 ",", rx); printf("\"packets\":%" PRIu64 ",", rxp); printf("\"totalbytes\":%" PRIu64 ",", rxtotal); printf("\"totalpackets\":%" PRIu64 "", rxptotal); printf("},"); printf("\"tx\":{"); printf("\"ratestring\":\"%s\",", gettrafficrate(tx, LIVETIME, 0)); printf("\"bytespersecond\":%" PRIu64 ",", (uint64_t)(tx / LIVETIME)); printf("\"packetspersecond\":%" PRIu64 ",", (uint64_t)(txp / LIVETIME)); printf("\"bytes\":%" PRIu64 ",", tx); printf("\"packets\":%" PRIu64 ",", txp); printf("\"totalbytes\":%" PRIu64 ",", txtotal); printf("\"totalpackets\":%" PRIu64 "", txptotal); printf("}}\n"); index++; } } timespent = (uint64_t)time(NULL) - timespent - timeslept; if (!json) { cursorshow(); printf("\n\n"); } /* print some statistics if enough time did pass */ if (!json && timespent >= 10) { printf("\n %s / traffic statistics\n\n", iface); printf(" rx | tx\n"); printf("--------------------------------------+------------------\n"); printf(" bytes %s", getvalue(rxtotal, 15, RT_Normal)); printf(" | %s", getvalue(txtotal, 15, RT_Normal)); printf("\n"); printf("--------------------------------------+------------------\n"); printf(" max %s", gettrafficrate(rxmax, LIVETIME, 15)); printf(" | %s\n", gettrafficrate(txmax, LIVETIME, 15)); printf(" average %s", gettrafficrate(rxtotal, (time_t)timespent, 15)); printf(" | %s\n", gettrafficrate(txtotal, (time_t)timespent, 15)); printf(" min %s", gettrafficrate(rxmin, LIVETIME, 15)); printf(" | %s\n", gettrafficrate(txmin, LIVETIME, 15)); printf("--------------------------------------+------------------\n"); printf(" packets %12" PRIu64 " | %12" PRIu64 "\n", rxptotal, txptotal); printf("--------------------------------------+------------------\n"); printf(" max %9" PRIu64 " p/s | %9" PRIu64 " p/s\n", rxpmax / LIVETIME, txpmax / LIVETIME); printf(" average %9" PRIu64 " p/s | %9" PRIu64 " p/s\n", rxptotal / timespent, txptotal / timespent); printf(" min %9" PRIu64 " p/s | %9" PRIu64 " p/s\n", rxpmin / LIVETIME, txpmin / LIVETIME); printf("--------------------------------------+------------------\n"); if (timespent <= 60) { printf(" time %9" PRIu64 " seconds\n", timespent); } else { printf(" time %7.2f minutes\n", timespent / (double)60); } printf("\n"); } else if (json) { printf("{\"seconds\":%" PRIu64 ",", timespent); printf("\"rx\":{"); printf("\"maxratestring\":\"%s\",", gettrafficrate(rxmax, LIVETIME, 0)); printf("\"averageratestring\":\"%s\",", gettrafficrate(rxtotal, (time_t)timespent, 0)); printf("\"minratestring\":\"%s\",", gettrafficrate(rxmin, LIVETIME, 0)); printf("\"totalbytes\":%" PRIu64 ",", rxtotal); printf("\"maxbytes\":%" PRIu64 ",", rxmax); printf("\"minbytes\":%" PRIu64 ",", rxmin); printf("\"totalpackets\":%" PRIu64 ",", rxptotal); printf("\"maxpackets\":%" PRIu64 ",", rxpmax); printf("\"minpackets\":%" PRIu64 "", rxpmin); printf("},"); printf("\"tx\":{"); printf("\"maxratestring\":\"%s\",", gettrafficrate(txmax, LIVETIME, 0)); printf("\"averageratestring\":\"%s\",", gettrafficrate(txtotal, (time_t)timespent, 0)); printf("\"minratestring\":\"%s\",", gettrafficrate(txmin, LIVETIME, 0)); printf("\"totalbytes\":%" PRIu64 ",", txtotal); printf("\"maxbytes\":%" PRIu64 ",", txmax); printf("\"minbytes\":%" PRIu64 ",", txmin); printf("\"totalpackets\":%" PRIu64 ",", txptotal); printf("\"maxpackets\":%" PRIu64 ",", txpmax); printf("\"minpackets\":%" PRIu64 "", txpmin); printf("}}\n"); } }
/****WinMain()**************************************************************/ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) /*HINSTANCE hInstance; current instance HINSTANCE hPrevInstance; previous instance LPSTR lpCmdLine; command line int nCmdShow; show-window type (open/icon) */ { MSG msg; /* message*/ if (*lpCmdLine != '\0') filearg = lpCmdLine; else filearg = NULL; IPC = 1; IMAC = 0; /*Ltestprint = TRUE;*/ /*test option, compile as TRUE to invoke,*/ Ltestprint = 0; /* as FALSE for distribution, can also set in Kludges */ Lerr =0; initialvalues(); /*starting general values */ getversion(); if (filearg) { dissectcommandline(filearg); } if (Lquiet == 0) {/*running with GUI*/ if (!InitInstance(hInstance, nCmdShow)) { return (FALSE); } beginnings(); } else {/*running quiet from commandline*/ for (;;) { mainlooprouter(); if(Lerr) break; /*030228 to fail gracefully*/ } return(0); } /*Drop through to here if running NOT Lquiet, i.e. using GUI */ /*Acquire and dispatch messages until a WM_QUIT message is received.*/ /* Master endless loop for GUI*/ /*this GetMessage stuff should be equivalent to Mac HandleEvent stuff*/ /* besides working as the endless Loop */ while (GetMessage(&msg, /* message structure */ NULL, /* handle of window receiving the message*/ 0, /* lowest message to examine */ 0)) /* highest message to examine*/ { mainlooprouter(); /*PKININIT, common router*/ if(Lerr) break; if(Lquiet==0) /*was Lcommanded 990402*/ { if (!TranslateAccelerator (PrekinWindow, PrekinAccel, &msg)) { TranslateMessage(&msg); /* Translates virtual key codes */ DispatchMessage(&msg); /* Dispatches message to window */ } } } return (msg.wParam); /* Returns the value from PostQuitMessage*/ }
int main(int argc, char *argv[]) // arg1: controller number { int nolog = 0; struct sockaddr_in serv_addr; struct hostent *server; char buffer[256]; int run = 1; // set to 0 to stop main loop fd_set readfd; int numfds; int interval = 60; int tmout = 90; // seconds to wait in select() int saveInterval = 600; // Save to NVRAM every 10 mins int logerror = 0; int option; int delay = 1000; // usec to sleep (but it rounds up to 20mSec anyway time_t update = 0, now; pthread_t tid; time_t nextSave; // Command line arguments opterr = 0; while ((option = getopt(argc, argv, "di:slVZ1:2:")) != -1) { switch (option) { case 's': noserver = 1; break; case 'l': nolog = 1; break; case '?': usage(); exit(1); case 'i': interval = atoi(optarg); break; case 'd': debug++; break; case '1': rate1 = rate2 = atof(optarg); break; case '2': rate2 = atof(optarg); break; case 'V': printf("Version %s %s\n", getversion(), id); exit(0); case 'Z': decode("(b+#Gjv~z`mcx-@ndd`rxbwcl9Vox=,/\x10\x17\x0e\x11\x14\x15\x11\x0b\x1a" "\x19\x1a\x13\x0cx@NEEZ\\F\\ER\\\x19YTLDWQ'a-1d()#!/#(-9' >q\"!;=?51-??r"); exit(0); } } DEBUG printf("Debug %d. optind %d argc %d\n", debug, optind, argc); if (optind < argc) controllernum = atoi(argv[optind]); // get optional controller number: parameter 1 sprintf(buffer, LOGFILE, controllernum); if (!nolog) if ((logfp = fopen(buffer, "a")) == NULL) logerror = errno; // There is no point in logging the failure to open the logfile // to the logfile, and the socket is not yet open. sprintf(buffer, "STARTED %s as %d interval %d %s", argv[0], controllernum, interval, nolog ? "nolog" : ""); logmsg(INFO, buffer); // Set up socket if (!noserver) { sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) logmsg(FATAL, "FATAL " PROGNAME " Creating socket"); server = gethostbyname("localhost"); if (server == NULL) { logmsg(FATAL, "FATAL " PROGNAME " Cannot resolve localhost"); } bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length); serv_addr.sin_port = htons(PORTNO); if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) { sockfd = 0; logmsg(ERROR, "ERROR " PROGNAME " Connecting to socket"); } if (flock(fileno(logfp), LOCK_EX | LOCK_NB) == -1) { logmsg(FATAL, "FATAL " PROGNAME " is already running, cannot start another one"); } // Logon to server as meter sprintf(buffer, "logon " progname " %s %d %d", getversion(), getpid(), controllernum); sockSend(buffer); } else sockfd = 1; // noserver: use stdout // If we failed to open the logfile and were NOT called with nolog, warn server // Obviously don't use logmsg! if (logfp == NULL && nolog == 0) { sprintf(buffer, "event WARN " PROGNAME " %d could not open logfile %s: %s", controllernum, LOGFILE, strerror(logerror)); sockSend(buffer); } // Set up hardware int mem = open("/dev/mem", O_RDWR); unsigned char * start = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, mem, 0x80840000); pbdata = (unsigned int*)(start + 0x04); pbddr = (unsigned int *)(start + 0x14); // All inputs *pbddr = DIO4 | DIO5; // DIO 4/5 outputs. *pbdata = 0xff; // set to all 1's numfds = sockfd + 1; // nfds parameter to select. One more than highest descriptor // Main Loop count1 = count2 = 0; readCMOS(); DEBUG fprintf(stderr, "Got values from NVRAM: %d %d (%f %f)\n", count1, count2, (count1 / rate1), (count2 / rate2)); // Start count thread if (pthread_create(&tid, NULL, count_pulses, NULL) < 0) perror("count_pulse"); DEBUG fprintf(stderr, "Thread started as %d (0x%x)\n", tid, tid); FD_ZERO(&readfd); update = timeMod(interval); nextSave = timeMod(saveInterval); while(run) { struct timeval tv1; now = time(NULL); if (now > nextSave) { DEBUG fprintf(stderr, "Saving to NVRAM "); writeCMOS(); nextSave = timeMod(saveInterval); DEBUG { struct tm * t; t = localtime(&nextSave); strftime(buffer, sizeof(buffer), "%F %T", t); fprintf(stderr, "Next save at %s\n", buffer); } } if (now > update) { // message time. Will always send out 0 0 at startup. int fd; sprintf(buffer, "meter 2 %.1f %.1f", (count1 / rate1), (count2 / rate2)); sockSend(buffer); update = timeMod(interval); // Write to /tmp/pulse fd = open("/tmp/pulse", O_RDWR | O_CREAT | O_TRUNC); if (fd < 0) perror("/tmp/pulse"); if (fd > 0) { strcat(buffer, "\n"); write(fd, buffer, strlen(buffer)); close(fd); } } FD_SET(sockfd, &readfd); tv1.tv_sec = 0; tv1.tv_usec = tmout; if (select(sockfd + 1, &readfd, NULL, NULL, &tv1) && sockfd > 1) // anything from server? run = processSocket(); // the server may request a shutdown by setting run to 0 usleep(delay); }
int main(int argc, char **argv) { int c; int r = 0; int fd = -1; drm_handle_t handle; void *address; char *pt; unsigned long count; unsigned long offset; unsigned long size; drm_context_t context; int loops; char buf[1024]; int i; drmBufInfoPtr info; drmBufMapPtr bufs; drmLockPtr lock; int secs; while ((c = getopt(argc, argv, "lc:vo:O:f:s:w:W:b:r:R:P:L:C:XS:B:F:")) != EOF) switch (c) { case 'F': count = strtoul(optarg, NULL, 0); if (!fork()) { dup(fd); sleep(count); } close(fd); break; case 'v': getversion(fd); break; case 'X': if ((r = drmCreateContext(fd, &context))) { drmError(r, argv[0]); return 1; } printf( "Got %d\n", context); break; case 'S': process_sigio(optarg); break; case 'C': if ((r = drmSwitchToContext(fd, strtoul(optarg, NULL, 0)))) { drmError(r, argv[0]); return 1; } break; case 'c': if ((r = drmSetBusid(fd,optarg))) { drmError(r, argv[0]); return 1; } break; case 'o': if ((fd = drmOpen(optarg, NULL)) < 0) { drmError(fd, argv[0]); return 1; } break; case 'O': if ((fd = drmOpen(NULL, optarg)) < 0) { drmError(fd, argv[0]); return 1; } break; case 'B': /* Test buffer allocation */ count = strtoul(optarg, &pt, 0); size = strtoul(pt+1, &pt, 0); secs = strtoul(pt+1, NULL, 0); { drmDMAReq dma; int *indices, *sizes; indices = alloca(sizeof(*indices) * count); sizes = alloca(sizeof(*sizes) * count); dma.context = context; dma.send_count = 0; dma.request_count = count; dma.request_size = size; dma.request_list = indices; dma.request_sizes = sizes; dma.flags = DRM_DMA_WAIT; if ((r = drmDMA(fd, &dma))) { drmError(r, argv[0]); return 1; } for (i = 0; i < dma.granted_count; i++) { printf("%5d: index = %d, size = %d\n", i, dma.request_list[i], dma.request_sizes[i]); } sleep(secs); drmFreeBufs(fd, dma.granted_count, indices); } break; case 'b': count = strtoul(optarg, &pt, 0); size = strtoul(pt+1, NULL, 0); if ((r = drmAddBufs(fd, count, size, 0, 65536)) < 0) { drmError(r, argv[0]); return 1; } if (!(info = drmGetBufInfo(fd))) { drmError(0, argv[0]); return 1; } for (i = 0; i < info->count; i++) { printf("%5d buffers of size %6d (low = %d, high = %d)\n", info->list[i].count, info->list[i].size, info->list[i].low_mark, info->list[i].high_mark); } if ((r = drmMarkBufs(fd, 0.50, 0.80))) { drmError(r, argv[0]); return 1; } if (!(info = drmGetBufInfo(fd))) { drmError(0, argv[0]); return 1; } for (i = 0; i < info->count; i++) { printf("%5d buffers of size %6d (low = %d, high = %d)\n", info->list[i].count, info->list[i].size, info->list[i].low_mark, info->list[i].high_mark); } printf("===== /proc/dri/0/mem =====\n"); snprintf(buf, sizeof(buf), "cat /proc/dri/0/mem"); system(buf); #if 1 if (!(bufs = drmMapBufs(fd))) { drmError(0, argv[0]); return 1; } printf("===============================\n"); printf( "%d bufs\n", bufs->count); for (i = 0; i < bufs->count; i++) { printf( " %4d: %8d bytes at %p\n", i, bufs->list[i].total, bufs->list[i].address); } printf("===== /proc/dri/0/vma =====\n"); snprintf(buf, sizeof(buf), "cat /proc/dri/0/vma"); system(buf); #endif break; case 'f': offset = strtoul(optarg, &pt, 0); size = strtoul(pt+1, NULL, 0); handle = 0; if ((r = drmAddMap(fd, offset, size, DRM_FRAME_BUFFER, 0, &handle))) { drmError(r, argv[0]); return 1; } printf("0x%08lx:0x%04lx added\n", offset, size); printf("===== /proc/dri/0/mem =====\n"); snprintf(buf, sizeof(buf), "cat /proc/dri/0/mem"); system(buf); break; case 'r': case 'R': offset = strtoul(optarg, &pt, 0); size = strtoul(pt+1, NULL, 0); handle = 0; if ((r = drmAddMap(fd, offset, size, DRM_REGISTERS, c == 'R' ? DRM_READ_ONLY : 0, &handle))) { drmError(r, argv[0]); return 1; } printf("0x%08lx:0x%04lx added\n", offset, size); printf("===== /proc/dri/0/mem =====\n"); snprintf(buf, sizeof(buf), "cat /proc/dri/0/mem"); system(buf); break; case 's': size = strtoul(optarg, &pt, 0); handle = 0; if ((r = drmAddMap(fd, 0, size, DRM_SHM, DRM_CONTAINS_LOCK, &handle))) { drmError(r, argv[0]); return 1; } printf("0x%04lx byte shm added at 0x%08lx\n", size, handle); snprintf(buf, sizeof(buf), "cat /proc/dri/0/vm"); system(buf); break; case 'P': offset = strtoul(optarg, &pt, 0); size = strtoul(pt+1, NULL, 0); address = NULL; if ((r = drmMap(fd, offset, size, &address))) { drmError(r, argv[0]); return 1; } printf("0x%08lx:0x%04lx mapped at %p for pid %d\n", offset, size, address, getpid()); printf("===== /proc/dri/0/vma =====\n"); snprintf(buf, sizeof(buf), "cat /proc/dri/0/vma"); system(buf); mprotect((void *)offset, size, PROT_READ); printf("===== /proc/dri/0/vma =====\n"); snprintf(buf, sizeof(buf), "cat /proc/dri/0/vma"); system(buf); break; case 'w': case 'W': offset = strtoul(optarg, &pt, 0); size = strtoul(pt+1, NULL, 0); address = NULL; if ((r = drmMap(fd, offset, size, &address))) { drmError(r, argv[0]); return 1; } printf("0x%08lx:0x%04lx mapped at %p for pid %d\n", offset, size, address, getpid()); printf("===== /proc/%d/maps =====\n", getpid()); snprintf(buf, sizeof(buf), "cat /proc/%d/maps", getpid()); system(buf); printf("===== /proc/dri/0/mem =====\n"); snprintf(buf, sizeof(buf), "cat /proc/dri/0/mem"); system(buf); printf("===== /proc/dri/0/vma =====\n"); snprintf(buf, sizeof(buf), "cat /proc/dri/0/vma"); system(buf); printf("===== READING =====\n"); for (i = 0; i < 0x10; i++) printf("%02x ", (unsigned int)((unsigned char *)address)[i]); printf("\n"); if (c == 'w') { printf("===== WRITING =====\n"); for (i = 0; i < size; i+=2) { ((char *)address)[i] = i & 0xff; ((char *)address)[i+1] = i & 0xff; } } printf("===== READING =====\n"); for (i = 0; i < 0x10; i++) printf("%02x ", (unsigned int)((unsigned char *)address)[i]); printf("\n"); printf("===== /proc/dri/0/vma =====\n"); snprintf(buf, sizeof(buf), "cat /proc/dri/0/vma"); system(buf); break; case 'L': context = strtoul(optarg, &pt, 0); offset = strtoul(pt+1, &pt, 0); size = strtoul(pt+1, &pt, 0); loops = strtoul(pt+1, NULL, 0); address = NULL; if ((r = drmMap(fd, offset, size, &address))) { drmError(r, argv[0]); return 1; } lock = address; #if 1 { int counter = 0; struct timeval loop_start, loop_end; struct timeval lock_start, lock_end; double wt; #define HISTOSIZE 9 int histo[HISTOSIZE]; int output = 0; int fast = 0; if (loops < 0) { loops = -loops; ++output; } for (i = 0; i < HISTOSIZE; i++) histo[i] = 0; gettimeofday(&loop_start, NULL); for (i = 0; i < loops; i++) { gettimeofday(&lock_start, NULL); DRM_LIGHT_LOCK_COUNT(fd,lock,context,fast); gettimeofday(&lock_end, NULL); DRM_UNLOCK(fd,lock,context); ++counter; wt = usec(&lock_end, &lock_start); if (wt <= 2.5) ++histo[8]; if (wt < 5.0) ++histo[0]; else if (wt < 50.0) ++histo[1]; else if (wt < 500.0) ++histo[2]; else if (wt < 5000.0) ++histo[3]; else if (wt < 50000.0) ++histo[4]; else if (wt < 500000.0) ++histo[5]; else if (wt < 5000000.0) ++histo[6]; else ++histo[7]; if (output) printf( "%.2f uSec, %d fast\n", wt, fast); } gettimeofday(&loop_end, NULL); printf( "Average wait time = %.2f usec, %d fast\n", usec(&loop_end, &loop_start) / counter, fast); printf( "%9d <= 2.5 uS\n", histo[8]); printf( "%9d < 5 uS\n", histo[0]); printf( "%9d < 50 uS\n", histo[1]); printf( "%9d < 500 uS\n", histo[2]); printf( "%9d < 5000 uS\n", histo[3]); printf( "%9d < 50000 uS\n", histo[4]); printf( "%9d < 500000 uS\n", histo[5]); printf( "%9d < 5000000 uS\n", histo[6]); printf( "%9d >= 5000000 uS\n", histo[7]); } #else printf( "before lock: 0x%08x\n", lock->lock); printf( "lock: 0x%08x\n", lock->lock); sleep(5); printf( "unlock: 0x%08x\n", lock->lock); #endif break; default: fprintf( stderr, "Usage: drmstat [options]\n" ); return 1; } return r; }
void LMP_readheader(LMP_t *l) { int i; /* totally rubbish code but I had no better idea */ if (l->game==(DOOM_old|DOOM_new)) { rewind(l->file); if (fread(l->header,1,1,l->file)==0) syserror(FIREAD,l->filename); l->game=(l->header[0]>=104?DOOM_new:DOOM_old); } if (l->game==(HEXEN_old|HEXEN_new)) { l->game=((((l->filesize-1-HEADER_HEXEN_old)%LONG_TIC)==0)?HEXEN_old:HEXEN_new); } /* end of rubbish */ switch (l->game) { case DOOM_old: l->headersize = HEADER_DOOM_old; l->ticsize = SHORT_TIC; l->maxplayer = MAXPLAYER_DOOM_old; break; case HERETIC: l->headersize = HEADER_HERETIC; l->ticsize = LONG_TIC; l->maxplayer = MAXPLAYER_HERETIC; break; case HEXEN_old: l->headersize = HEADER_HEXEN_old; l->ticsize = LONG_TIC; l->maxplayer = MAXPLAYER_HEXEN_old; break; case HEXEN_new: l->headersize = HEADER_HEXEN_new; l->ticsize = LONG_TIC; l->maxplayer = MAXPLAYER_HEXEN_new; break; case DOOM_new: l->headersize = HEADER_DOOM_new; l->ticsize = SHORT_TIC; l->maxplayer = MAXPLAYER_DOOM_new; break; case DOOM2: l->headersize = HEADER_DOOM_new; l->ticsize = SHORT_TIC; l->maxplayer = MAXPLAYER_DOOM_new; break; case DOOM_new|DOOM2: l->headersize = HEADER_DOOM_new; l->ticsize = SHORT_TIC; l->maxplayer = MAXPLAYER_DOOM_new; break; case STRIFE: l->headersize = HEADER_STRIFE; l->ticsize = LONG_TIC; l->maxplayer = MAXPLAYER_STRIFE; break; } rewind(l->file); if (fread(l->header,1,l->headersize,l->file)==0) syserror(FIREAD,l->filename); fseek(l->file,l->headersize,SEEK_SET); switch (l->headersize) { case HEADER_DOOM_old: case HEADER_HEXEN_old: case HEADER_HEXEN_new: l->versionbyte = ((l->game==DOOM_old || l->game==HERETIC)?0:l->game); l->skill = l->header[0]; l->episode = l->header[1]; l->map = l->header[2]; l->multirule = 0; l->respawn = 0; l->fast = 0; l->nomonsters = 0; l->mainplayer = 0; break; case HEADER_DOOM_new: l->versionbyte = l->header[0]; l->skill = l->header[1]; l->episode = l->header[2]; l->map = l->header[3]; l->multirule = l->header[4]; l->respawn = l->header[5]; l->fast = l->header[6]; l->nomonsters = l->header[7]; l->mainplayer = l->header[8]; break; case HEADER_STRIFE: l->versionbyte = l->header[0]; l->skill = l->header[1]; l->episode = 1; l->map = l->header[2]; l->multirule = l->header[3]; l->respawn = l->header[4]; l->fast = l->header[5]; l->nomonsters = l->header[6]; l->mainplayer = l->header[7]; break; } if (l->game&(HEXEN_old|HEXEN_new)) { for (i=0, l->playernum=0;i<l->maxplayer;i++) { if (l->header[l->headersize-l->maxplayer*2+i*2]) { l->num[l->playernum] = i; l->playerclass[l->playernum++] = l->header[l->headersize-l->maxplayer*2+i*2+1]; } } } else { for (i=0, l->playernum=0;i<l->maxplayer;i++) { if (l->header[l->headersize-l->maxplayer+i]) { l->num[l->playernum++] = i; } } } if (!l->playernum) syserror(WLMP,l->filename); getversion(l->versionbyte,&(l->game),&l->gs,&l->ns); l->datasize=l->filesize-l->headersize-1; if (l->datasize % l->ticsize) syserror(WLMP,l->filename); l->stics=l->datasize / l->ticsize; /* number of single tics */ l->tics=l->stics / l->playernum; /* complete multi tics */ l->incomplete=l->stics % l->playernum; /* incomplete single tics */ l->time=l->tics*TICTIME; }