/* * Give the abbreviated dump of the file names */ void dump(const char *nfile, const char *file, int copies) { short n, fill; struct stat lbuf; /* * Print as many files as will fit * (leaving room for the total size) */ fill = first ? 0 : 2; /* fill space for ``, '' */ if (((n = strlen(nfile)) + col + fill) >= SIZCOL-4) { if (col < SIZCOL) { printf(" ..."), col += 4; blankfill(SIZCOL); } } else { if (first) first = 0; else printf(", "); printf("%s", nfile); col += n+fill; } seteuid(euid); if (*file && !stat(file, &lbuf)) totsize += copies * (long)lbuf.st_size; seteuid(uid); }
/* * Give the abbreviated dump of the file names */ void dump(char *nfile, char *file, int copies) { int n, fill; struct stat lbuf; /* * Print as many files as will fit * (leaving room for the total size) */ fill = first ? 0 : 2; /* fill space for ``, '' */ if (((n = strlen(nfile)) + col + fill) >= (termwidth - (80 - SIZCOL)) - 4) { if (col < (termwidth - (80 - SIZCOL))) { printf(" ..."), col += 4; blankfill(termwidth - (80 - SIZCOL)); } } else { if (first) first = 0; else printf(", "); printf("%s", nfile); col += n+fill; } PRIV_START; if (*file && !stat(file, &lbuf)) totsize += copies * lbuf.st_size; PRIV_END; }
/* * Print the header for the short listing format */ void header(void) { printf("%s", head0); col = strlen(head0)+1; blankfill(SIZCOL); printf("%s", head1); }
/* * Print the header for the short listing format */ void header(void) { printf(head0); col = strlen(head0)+1; blankfill(termwidth - (80 - SIZCOL)); printf(head1); }
/* * Give the abbreviated dump of the file names */ void dump(const char *nfile, const char *datafile, int copies) { struct stat lbuf; const char etctmpl[] = ", ..."; char etc[sizeof(etctmpl)]; char *lastsep; short fill, nlen; short rem, remetc; /* * Print as many filenames as will fit * (leaving room for the 'total size' field) */ fill = first ? 0 : 2; /* fill space for ``, '' */ nlen = strlen(nfile); rem = SIZCOL - 1 - col; if (nlen + fill > rem) { if (first) { /* print the right-most part of the name */ printf("...%s ", &nfile[3+nlen-rem]); col = SIZCOL; } else if (rem > 0) { /* fit as much of the etc-string as we can */ remetc = rem; if (rem > strlen(etctmpl)) remetc = strlen(etctmpl); etc[0] = '\0'; strncat(etc, etctmpl, remetc); printf("%s", etc); col += remetc; rem -= remetc; /* room for the last segment of this filename? */ lastsep = strrchr(nfile, '/'); if ((lastsep != NULL) && (rem > strlen(lastsep))) { /* print the right-most part of this name */ printf("%s", lastsep); col += strlen(lastsep); } else { /* do not pack any more names in here */ blankfill(SIZCOL); } } } else { if (!first) printf(", "); printf("%s", nfile); col += nlen + fill; } first = 0; PRIV_START if (*datafile && !stat(datafile, &lbuf)) totsize += copies * lbuf.st_size; PRIV_END }
int sona(void) { struct nstr_item ni, nit; struct sctstr sect; struct shpstr ship; struct shpstr targ; struct natstr *natp; struct mchrstr *mcp; struct mchrstr *tmcp; struct nstr_sect ns; int range; int visib, pingrange; int srange; int vrange; int dist; int x, y; int cx, cy; int changed = 0; int row; /* Where these are used are non-re-entrant, so we keep 'em around */ static char **rad = NULL; static char *radbuf = NULL; static signed char **vis = NULL; static signed char *visbuf = NULL; if (!snxtitem(&ni, EF_SHIP, player->argp[1], NULL)) return RET_SYN; if (!radbuf) radbuf = malloc(WORLD_Y * MAPWIDTH(1)); if (!visbuf) visbuf = malloc(WORLD_Y * MAPWIDTH(1)); if (!rad && radbuf) { rad = malloc(WORLD_Y * sizeof(char *)); if (rad) { for (x = 0; x < WORLD_Y; x++) { rad[x] = &radbuf[(WORLD_X + 1) * x]; } } } if (!vis && visbuf) { vis = malloc(WORLD_Y * sizeof(signed char *)); if (vis) { for (x = 0; x < WORLD_Y; x++) { vis[x] = &visbuf[(WORLD_X + 1) * x]; } } } if (!radbuf || !visbuf || !rad || !vis) { pr("Memory error, tell the deity.\n"); logerror("malloc failed in sona\n"); return RET_FAIL; } while (nxtitem(&ni, &ship)) { if (!player->owner) continue; mcp = &mchr[(int)ship.shp_type]; if (!(mcp->m_flags & M_SONAR)) continue; getsect(ship.shp_x, ship.shp_y, §); if (sect.sct_type != SCT_WATER) continue; range = (int)techfact(ship.shp_tech, mcp->m_vrnge); srange = MIN(7, 7 * range * ship.shp_effic / 200); pr("%s at %s efficiency %d%%, max range %d\n", prship(&ship), xyas(ship.shp_x, ship.shp_y, player->cnum), ship.shp_effic, srange); snxtsct_dist(&ns, ship.shp_x, ship.shp_y, srange); blankfill(radbuf, &ns.range, 1); while (nxtsct(&ns, §)) { if (player->owner || sect.sct_type == SCT_WATER) rad[ns.dy][ns.dx] = dchr[sect.sct_type].d_mnem; else { rad[ns.dy][ns.dx] = '?'; } } snxtsct_dist(&ns, ship.shp_x, ship.shp_y, srange); cx = deltx(&ns.range, ship.shp_x); cy = delty(&ns.range, ship.shp_y); while (nxtsct(&ns, §)) { if (!line_of_sight(rad, cx, cy, ns.dx, ns.dy)) { rad[ns.dy][ns.dx] = ' '; continue; } if (ship.shp_tech >= 310 && sect.sct_type == SCT_WATER) { if (sect.sct_mines) { pr("Sonar detects %d mines in %s!\n", sect.sct_mines, xyas(sect.sct_x, sect.sct_y, player->cnum)); rad[ns.dy][ns.dx] = 'X'; } } changed |= map_set(player->cnum, sect.sct_x, sect.sct_y, rad[ns.dy][ns.dx], 0); } memset(visbuf, 0, (WORLD_Y * (WORLD_X + 1))); snxtitem_dist(&nit, EF_SHIP, ship.shp_x, ship.shp_y, range); while (nxtitem(&nit, &targ)) { if (targ.shp_own == player->cnum || targ.shp_own == 0) continue; tmcp = &mchr[(int)targ.shp_type]; visib = shp_visib(&targ); pingrange = MIN(7, MAX(visib, 10) * range / 10); vrange = pingrange * ship.shp_effic / 200; dist = mapdist(targ.shp_x, targ.shp_y, ship.shp_x, ship.shp_y); pingrange = (MAX(pingrange, 2) * targ.shp_effic) / 100; if (dist > pingrange) continue; if (tmcp->m_flags & M_SONAR && targ.shp_own) { natp = getnatp(targ.shp_own); if (natp->nat_flags & NF_SONAR) wu(0, targ.shp_own, "Sonar ping from %s detected by %s!\n", xyas(ship.shp_x, ship.shp_y, targ.shp_own), prship(&targ)); if (targ.shp_rflags & RET_SONARED) retreat_ship(&targ, targ.shp_own, 's'); } if (dist > vrange) continue; x = deltx(&ns.range, (int)targ.shp_x); y = delty(&ns.range, (int)targ.shp_y); if (rad[y][x] != dchr[SCT_WATER].d_mnem && rad[y][x] != 'X') continue; if (tmcp->m_flags & M_SUB && relations_with(targ.shp_own, player->cnum) < FRIENDLY) { if (mcp->m_vrnge + visib < 8) pr("Sonar detects sub #%d @ %s\n", targ.shp_uid, xyas(targ.shp_x, targ.shp_y, player->cnum)); else if (mcp->m_vrnge + visib < 10) pr("Sonar detects %s @ %s\n", prship(&targ), xyas(targ.shp_x, targ.shp_y, player->cnum)); else pr("Sonar detects %s %s @ %s\n", cname(targ.shp_own), prship(&targ), xyas(targ.shp_x, targ.shp_y, player->cnum)); } else pr("Sonar detects %s %s @ %s\n", cname(targ.shp_own), prship(&targ), xyas(targ.shp_x, targ.shp_y, player->cnum)); if (visib > vis[y][x]) { vis[y][x] = visib; /* &~0x20 makes it a cap letter */ rad[y][x] = (*mchr[(int)targ.shp_type].m_name) & ~0x20; } } if (!player->argp[2]) { rad[cy][cx] = '0'; for (row = 0; row < ns.range.height; row++) if (!blankrow(rad[row])) pr("%s\n", rad[row]); } pr("\n"); } if (changed) writemap(player->cnum); return RET_OK; }
void inform(const struct printer *pp, char *cf) { int copycnt, jnum; char savedname[MAXPATHLEN+1]; FILE *cfp; /* * There's a chance the control file has gone away * in the meantime; if this is the case just keep going */ PRIV_START if ((cfp = fopen(cf, "r")) == NULL) return; PRIV_END if (rank < 0) rank = 0; if (pp->remote || garbage || strcmp(cf, current)) rank++; /* * The cf-file may include commands to print more than one datafile * from the user. For each datafile, the cf-file contains at least * one line which starts with some format-specifier ('a'-'z'), and * a second line ('N'ame) which indicates the original name the user * specified for that file. There can be multiple format-spec lines * for a single Name-line, if the user requested multiple copies of * that file. Standard lpr puts the format-spec line(s) before the * Name-line, while lprNG puts the Name-line before the format-spec * line(s). This section needs to handle the lines in either order. */ copycnt = 0; file[0] = '\0'; savedname[0] = '\0'; jnum = calc_jobnum(cf, NULL); while (getline(cfp)) { switch (line[0]) { case 'P': /* Was this file specified in the user's list? */ if (!inlist(line+1, cf)) { fclose(cfp); return; } if (lflag) { printf("\n%s: ", line+1); col = strlen(line+1) + 2; prank(rank); blankfill(JOBCOL); printf(" [job %s]\n", cf+3); } else { col = 0; prank(rank); blankfill(OWNCOL); printf("%-10s %-3d ", line+1, jnum); col += 16; first = 1; } continue; default: /* some format specifer and file name? */ if (line[0] < 'a' || line[0] > 'z') break; if (copycnt == 0 || strcmp(file, line+1) != 0) { strlcpy(file, line + 1, sizeof(file)); } copycnt++; /* * deliberately 'continue' to another getline(), so * all format-spec lines for this datafile are read * in and counted before calling show() */ continue; case 'N': strlcpy(savedname, line + 1, sizeof(savedname)); break; } if ((file[0] != '\0') && (savedname[0] != '\0')) { show(savedname, file, copycnt); copycnt = 0; file[0] = '\0'; savedname[0] = '\0'; } } fclose(cfp); /* check for a file which hasn't been shown yet */ if (file[0] != '\0') { if (savedname[0] == '\0') { /* a safeguard in case the N-ame line is missing */ strlcpy(savedname, file, sizeof(savedname)); } show(savedname, file, copycnt); } if (!lflag) { blankfill(SIZCOL); printf("%ld bytes\n", totsize); totsize = 0; } }
/* * Draw a radar map for radar at @cx,@cy. * @eff is the radar's efficiency, @tlev its tech level, @spy its power. * Submarines are detected at fraction @seesub of the range. */ void radmap(int cx, int cy, int eff, double tlev, int spy, double seesub) { int visib, rng; struct sctstr sect; struct shpstr ship; struct plnstr plane; struct nstr_sect ns; struct nstr_item ni; int x, y; int row; int n; int range = rad_range(eff, tlev, spy); int changed = 0; if (!radbuf) radbuf = malloc(WORLD_Y * MAPWIDTH(1)); if (!visbuf) visbuf = malloc(WORLD_Y * MAPWIDTH(1)); if (!rad) { rad = malloc(WORLD_Y * sizeof(char *)); if (rad && radbuf) { for (x = 0; x < WORLD_Y; x++) rad[x] = &radbuf[(WORLD_X + 1) * x]; } } if (!vis) { vis = malloc(WORLD_Y * sizeof(signed char *)); if (vis && visbuf) { for (x = 0; x < WORLD_Y; x++) vis[x] = &visbuf[(WORLD_X + 1) * x]; } } if (!radbuf || !visbuf || !rad || !vis) { pr("Memory error in radmap2, tell the deity.\n"); return; } memset(visbuf, 0, (WORLD_Y * (WORLD_X + 1))); pr("%s efficiency %d%%, max range %d\n", xyas(cx, cy, player->cnum), eff, range); snxtsct_dist(&ns, cx, cy, range); blankfill(radbuf, &ns.range, 1); while (nxtsct(&ns, §)) { rad[ns.dy][ns.dx] = rad_char(§, ns.curdist, range, player->cnum); changed += map_set(player->cnum, ns.x, ns.y, rad[ns.dy][ns.dx], 0); } if (changed) writemap(player->cnum); snxtitem_dist(&ni, EF_PLANE, cx, cy, range); while (nxtitem(&ni, &plane)) { if (plane.pln_own == 0) continue; /* Used to have 'ghosts' when scanning whole world --ts */ x = deltx(&ns.range, (int)plane.pln_x); y = delty(&ns.range, (int)plane.pln_y); if (pln_is_in_orbit(&plane) && plane.pln_own != player->cnum) { vis[y][x] = 100; rad[y][x] = '$'; } } snxtitem_dist(&ni, EF_SHIP, cx, cy, range); while (nxtitem(&ni, &ship)) { if (ship.shp_own == 0) continue; /* Used to have 'ghosts' when scanning whole world --ts */ x = deltx(&ns.range, (int)ship.shp_x); y = delty(&ns.range, (int)ship.shp_y); visib = shp_visib(&ship); rng = (int)(range * visib / 20.0); if (ni.curdist > rng) continue; if ((mchr[(int)ship.shp_type].m_flags & M_SUB) && ni.curdist > rng * seesub) continue; if (visib > vis[y][x]) { vis[y][x] = visib; /* &~0x20 makes it a cap letter */ rad[y][x] = (*mchr[(int)ship.shp_type].m_name) & ~0x20; } } /* * make the center of the display 0 * so ve et al can find it. */ rad[delty(&ns.range, cy)][deltx(&ns.range, cx)] = '0'; n = ns.range.height; for (row = 0; row < n; row++) pr("%s\n", rad[row]); pr("\n"); }
static void inform(char *cf, int rank) { int fd, j; FILE *cfp = NULL; /* * There's a chance the control file has gone away * in the meantime; if this is the case just keep going */ PRIV_START; fd = safe_open(cf, O_RDONLY|O_NOFOLLOW, 0); PRIV_END; if (fd < 0 || (cfp = fdopen(fd, "r")) == NULL) { if (fd >= 0) close(fd); return; } j = 0; while (getcfline(cfp)) { switch (line[0]) { case 'P': /* Was this file specified in the user's list? */ if (!inlist(line+1, cf)) { fclose(cfp); return; } if (lflag) { printf("\n%s: ", line+1); col = strlen(line+1) + 2; prank(rank); blankfill(JOBCOL); printf(" [job %s]\n", cf+3); } else { col = 0; prank(rank); blankfill(OWNCOL); printf("%-10s %-3d ", line+1, atoi(cf+3)); col += 16; first = 1; } continue; default: /* some format specifer and file name? */ if (line[0] < 'a' || line[0] > 'z') continue; if (j == 0 || strcmp(file, line+1) != 0) (void)strlcpy(file, line+1, sizeof(file)); j++; continue; case 'N': show(line+1, file, j); file[0] = '\0'; j = 0; } } fclose(cfp); if (!lflag) { blankfill(termwidth - (80 - SIZCOL)); printf("%lld bytes\n", (long long)totsize); totsize = 0; } }
void inform(const char *cf) { int j; FILE *cfp; /* * There's a chance the control file has gone away * in the meantime; if this is the case just keep going */ seteuid(euid); if ((cfp = fopen(cf, "r")) == NULL) return; seteuid(uid); if (rank < 0) rank = 0; if (remote || garbage || strcmp(cf, current)) rank++; j = 0; while (get_line(cfp)) { switch (line[0]) { case 'P': /* Was this file specified in the user's list? */ if (!inlist(line+1, cf)) { fclose(cfp); return; } if (lflag) { printf("\n%s: ", line+1); col = strlen(line+1) + 2; prank(rank); blankfill(JOBCOL); printf(" [job %s]\n", cf+3); } else { col = 0; prank(rank); blankfill(OWNCOL); printf("%-10s %-3d ", line+1, atoi(cf+3)); col += 16; first = 1; } continue; default: /* some format specifer and file name? */ if (line[0] < 'a' || line[0] > 'z') continue; if (j == 0 || strcmp(fname, line+1) != 0) { (void)strlcpy(fname, line+1, sizeof(fname)); } j++; continue; case 'N': show(line + 1, fname, j); fname[0] = '\0'; j = 0; } } fclose(cfp); if (!lflag) { blankfill(SIZCOL); printf("%ld bytes\n", totsize); totsize = 0; } }
/* * survey type <sarg> ?cond * */ int surv(void) { int nsect; struct nstr_sect nstr; int y; struct valstr val; struct natstr *np; struct sctstr sect; struct range range; char *ptr; struct nscstr cond[NS_NCOND]; int ncond; int i; char buf[1024]; /* Note this is not re-entrant anyway, so we keep the buffers around */ static char *mapbuf = NULL; static char **map = NULL; nsect = 0; ptr = getstarg(player->argp[1], "commodity or variable? ", buf); if (!ptr || !*ptr) return RET_SYN; ptr = nstr_comp_val(ptr, &val, EF_SECTOR); if (!ptr) return RET_SYN; if (val.val_cat != NSC_OFF || nstr_promote(val.val_type) != NSC_LONG) { pr("Can't survey this\n"); return RET_SYN; } for (; isspace(*ptr); ++ptr) ; if (*ptr) return RET_SYN; if (!snxtsct(&nstr, player->argp[2])) return RET_SYN; if (!mapbuf) mapbuf = malloc(WORLD_Y * MAPWIDTH(1)); if (!map) { map = malloc(WORLD_Y * sizeof(char *)); if (map && mapbuf) { for (i = 0; i < WORLD_Y; i++) map[i] = &mapbuf[MAPWIDTH(1) * i]; } else if (map) { free(map); map = NULL; } } if (!mapbuf || !map) { pr("Memory error, tell the deity.\n"); logerror("malloc failed in sect\n"); return RET_FAIL; } ncond = nstr.ncond; memcpy(cond, nstr.cond, sizeof(struct nscstr) * ncond); nstr.ncond = 0; np = getnatp(player->cnum); xyrelrange(np, &nstr.range, &range); border(&range, " ", ""); blankfill(mapbuf, &nstr.range, 1); while (nxtsct(&nstr, §)) { if (!player->owner) continue; ptr = &map[nstr.dy][nstr.dx]; if (nstr_exec(cond, ncond, §)) { ++nsect; *ptr = 0x80 | code_char(val, §); } else { *ptr = dchr[sect.sct_type].d_mnem; } } for (y = nstr.range.ly, i = 0; i < nstr.range.height; y++, i++) { int yval; yval = yrel(np, y); pr("%4d %s %4d\n", yval, map[i], yval); if (y >= WORLD_Y) y -= WORLD_Y; } border(&range, " ", ""); if (nsect > 0) pr("\n%d sector%s.\n", nsect, splur(nsect)); return RET_OK; }
int rout(void) { struct ichrstr *ip; struct nstr_sect ns; struct natstr *natp; struct sctstr sect; struct nscstr cond[NS_NCOND]; int ncond; struct range relrange; int row; int y; int ry; i_type i_del; int dir; char *p; /* Note this is not re-entrant anyway, so we keep the buffers around */ static char *mapbuf = NULL; static char **map = NULL; int i; if (!(ip = whatitem(player->argp[1], "What item? "))) return RET_SYN; i_del = ip->i_uid;; if (!snxtsct(&ns, player->argp[2])) return RET_SYN; if (!mapbuf) mapbuf = malloc(WORLD_Y * MAPWIDTH(3)); if (!map) { map = malloc(WORLD_Y * sizeof(char *)); if (map && mapbuf) { for (i = 0; i < WORLD_Y; i++) map[i] = &mapbuf[MAPWIDTH(3) * i]; } else if (map) { free(map); map = NULL; } } if (!mapbuf || !map) { pr("Memory error, tell the deity.\n"); logerror("malloc failed in rout\n"); return RET_FAIL; } ncond = ns.ncond; memcpy(cond, ns.cond, sizeof(struct nscstr) * ncond); ns.ncond = 0; natp = getnatp(player->cnum); xyrelrange(natp, &ns.range, &relrange); blankfill(mapbuf, &ns.range, 3); border(&relrange, " ", " "); while (nxtsct(&ns, §)) { if (!player->owner) continue; p = &map[ns.dy][ns.dx * 2]; dir = sect.sct_del[i_del] & 0x7; if (dir && nstr_exec(cond, ncond, §)) memcpy(p, routech[dir], 3); p[1] = dchr[sect.sct_type].d_mnem; } for (row = 0, y = ns.range.ly; row < ns.range.height; y++, row++) { ry = yrel(natp, y); pr("%4d %s %-4d\n", ry, map[row], ry); if (y >= WORLD_Y) y -= WORLD_Y; } border(&relrange, " ", " "); return RET_OK; }