yet more nethack -s
For nethack -s name1 [name2 [name3]] allow any or all of the name arguments to be preceded by -u. Both '-u name1' and '-uname2' forms are accepted same as when specifying character name at start of play. It has been accepting '-s<anything>' and ignoring the <anything>. Treat such as a separate argument instead. That means it will accept '-s-v' which is silly but if used intentionally, <anything> would most likely be a name. 'nethack -s' without any character name(s) supplied and PERS_IS_UID set to 0 now defaults to "all" instead of to "hackplayer". For Unix, the default name will be in place, so that gets used instead of "all". 'nethack -s all' or 'nethack -s -u all' can be used to see all scores. When no matches are found, feedback is a full sentence but terminating punctuation was omitted except for the special case of "Cannot find any entries for you." Add the final period all the time.
This commit is contained in:
+57
-41
@@ -1099,31 +1099,36 @@ score_wanted(
|
|||||||
const char **players,
|
const char **players,
|
||||||
int uid)
|
int uid)
|
||||||
{
|
{
|
||||||
|
const char *arg, *nxt;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (current_ver
|
if (current_ver && (t1->ver_major != VERSION_MAJOR
|
||||||
&& (t1->ver_major != VERSION_MAJOR || t1->ver_minor != VERSION_MINOR
|
|| t1->ver_minor != VERSION_MINOR
|
||||||
|| t1->patchlevel != PATCHLEVEL))
|
|| t1->patchlevel != PATCHLEVEL))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (sysopt.pers_is_uid && !playerct && t1->uid == uid)
|
if (sysopt.pers_is_uid && !playerct && t1->uid == uid)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
for (i = 0; i < playerct; i++) {
|
for (i = 0; i < playerct; i++) {
|
||||||
if (players[i][0] == '-' && strchr("pr", players[i][1])
|
arg = players[i];
|
||||||
&& players[i][2] == 0 && i + 1 < playerct) {
|
if (arg[0] == '-' && arg[1] == 'u' && arg[2] != '\0')
|
||||||
const char *arg = players[i + 1];
|
arg += 2; /* handle '-uname' */
|
||||||
if ((players[i][1] == 'p'
|
|
||||||
&& str2role(arg) == str2role(t1->plrole))
|
if (arg[0] == '-' && strchr("pru", arg[1]) && !arg[2]
|
||||||
|| (players[i][1] == 'r'
|
&& i + 1 < playerct) {
|
||||||
&& str2race(arg) == str2race(t1->plrace)))
|
nxt = players[i + 1];
|
||||||
|
if ((arg[1] == 'p' && str2role(nxt) == str2role(t1->plrole))
|
||||||
|
|| (arg[1] == 'r' && str2race(nxt) == str2race(t1->plrace))
|
||||||
|
/* handle '-u name' */
|
||||||
|
|| (arg[1] == 'u' && (!strcmp(nxt, "all")
|
||||||
|
|| !strncmp(t1->name, nxt, NAMSZ))))
|
||||||
return 1;
|
return 1;
|
||||||
i++;
|
i++;
|
||||||
} else if (strcmp(players[i], "all") == 0
|
} else if (!strcmp(arg, "all")
|
||||||
|| strncmp(t1->name, players[i], NAMSZ) == 0
|
|| !strncmp(t1->name, arg, NAMSZ)
|
||||||
|| (players[i][0] == '-' && players[i][1] == t1->plrole[0]
|
|| (arg[0] == '-' && arg[1] == t1->plrole[0] && !arg[2])
|
||||||
&& players[i][2] == 0)
|
|| (digit(arg[0]) && rank <= atoi(arg)))
|
||||||
|| (digit(players[i][0]) && rank <= atoi(players[i])))
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1138,21 +1143,21 @@ score_wanted(
|
|||||||
void
|
void
|
||||||
prscore(int argc, char **argv)
|
prscore(int argc, char **argv)
|
||||||
{
|
{
|
||||||
const char **players;
|
const char **players, *player0;
|
||||||
int playerct, rank;
|
int i, playerct, rank;
|
||||||
boolean current_ver = TRUE, init_done = FALSE;
|
|
||||||
register struct toptenentry *t1;
|
register struct toptenentry *t1;
|
||||||
FILE *rfile;
|
FILE *rfile;
|
||||||
boolean match_found = FALSE;
|
char pbuf[BUFSZ], *p;
|
||||||
register int i;
|
unsigned ln;
|
||||||
char pbuf[BUFSZ];
|
|
||||||
unsigned ln = 0;
|
|
||||||
int uid = -1;
|
int uid = -1;
|
||||||
const char *player0;
|
boolean current_ver = TRUE, init_done = FALSE, match_found = FALSE;
|
||||||
|
|
||||||
if (argc < 2 || (ln = Strlen(argv[1])) < 2
|
/* expect "-s" or "--scores"; "-s<anything> is accepted */
|
||||||
|| (strncmp(argv[1], "-s", 2)
|
ln = (argc < 2) ? 0U
|
||||||
&& (ln < 4 || strncmp(argv[1], "--scores", ln)))) {
|
: ((p = strchr(argv[1], ' ')) != 0) ? (unsigned) (p - argv[1])
|
||||||
|
: Strlen(argv[1]);
|
||||||
|
if (ln < 2 || (strncmp(argv[1], "-s", 2)
|
||||||
|
&& strcmp(argv[1], "--scores"))) {
|
||||||
raw_printf("prscore: bad arguments (%d)", argc);
|
raw_printf("prscore: bad arguments (%d)", argc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1180,13 +1185,16 @@ prscore(int argc, char **argv)
|
|||||||
init_done = TRUE;
|
init_done = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 'ln' is 2 for -s, longer for --scores */
|
/* to get here, argv[1] either starts with "-s" or is "--scores" without
|
||||||
if (!argv[1][ln]) { /* plain "-s" */
|
trailing stuff; for "-s<anything>" treat <anything> as separate arg */
|
||||||
|
if (argv[1][1] == '-' || !argv[1][2]) {
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
} else
|
} else { /* concatenated arg string; use up "-s" but keep argc,argv */
|
||||||
argv[1] += ln;
|
argv[1] += 2;
|
||||||
|
}
|
||||||
|
/* -v doesn't take a version number arg; it means 'current vers only';
|
||||||
|
unlike -s, we don't accept "-v<anything>" for non-empty <anything> */
|
||||||
if (argc > 1 && !strcmp(argv[1], "-v")) {
|
if (argc > 1 && !strcmp(argv[1], "-v")) {
|
||||||
current_ver = FALSE;
|
current_ver = FALSE;
|
||||||
argc--;
|
argc--;
|
||||||
@@ -1201,11 +1209,8 @@ prscore(int argc, char **argv)
|
|||||||
} else {
|
} else {
|
||||||
player0 = g.plname;
|
player0 = g.plname;
|
||||||
if (!*player0)
|
if (!*player0)
|
||||||
#ifdef AMIGA
|
player0 = "all"; /* if no plname[], show all scores
|
||||||
player0 = "all"; /* single user system */
|
* (possibly filtered by '-v') */
|
||||||
#else
|
|
||||||
player0 = "hackplayer";
|
|
||||||
#endif
|
|
||||||
playerct = 1;
|
playerct = 1;
|
||||||
players = &player0;
|
players = &player0;
|
||||||
}
|
}
|
||||||
@@ -1216,7 +1221,7 @@ prscore(int argc, char **argv)
|
|||||||
raw_print("");
|
raw_print("");
|
||||||
|
|
||||||
t1 = tt_head = newttentry();
|
t1 = tt_head = newttentry();
|
||||||
for (rank = 1;; rank++) {
|
for (rank = 1; ; rank++) {
|
||||||
readentry(rfile, t1);
|
readentry(rfile, t1);
|
||||||
if (t1->points == 0)
|
if (t1->points == 0)
|
||||||
break;
|
break;
|
||||||
@@ -1243,12 +1248,21 @@ prscore(int argc, char **argv)
|
|||||||
} else {
|
} else {
|
||||||
Sprintf(pbuf, "Cannot find any %sentries for ",
|
Sprintf(pbuf, "Cannot find any %sentries for ",
|
||||||
current_ver ? "current " : "");
|
current_ver ? "current " : "");
|
||||||
if (playerct < 1)
|
if (playerct < 1) {
|
||||||
Strcat(pbuf, "you.");
|
Strcat(pbuf, "you");
|
||||||
else {
|
} else {
|
||||||
|
/* minor bug: 'nethack -s -u ziggy' will say "any of"
|
||||||
|
even though the '-u' doesn't indicate multiple names */
|
||||||
if (playerct > 1)
|
if (playerct > 1)
|
||||||
Strcat(pbuf, "any of ");
|
Strcat(pbuf, "any of ");
|
||||||
for (i = 0; i < playerct; i++) {
|
for (i = 0; i < playerct; i++) {
|
||||||
|
/* accept '-u name' and '-uname' as well as just 'name'
|
||||||
|
so skip '-u' for the none-found feedback */
|
||||||
|
if (!strncmp(players[i], "-u", 2)) {
|
||||||
|
if (!players[i][2])
|
||||||
|
continue;
|
||||||
|
players[i] += 2;
|
||||||
|
}
|
||||||
/* stop printing players if there are too many to fit */
|
/* stop printing players if there are too many to fit */
|
||||||
if (strlen(pbuf) + strlen(players[i]) + 2 >= BUFSZ) {
|
if (strlen(pbuf) + strlen(players[i]) + 2 >= BUFSZ) {
|
||||||
if (strlen(pbuf) < BUFSZ - 4)
|
if (strlen(pbuf) < BUFSZ - 4)
|
||||||
@@ -1267,9 +1281,11 @@ prscore(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* append end-of-sentence punctuation if there is room */
|
||||||
|
if (strlen(pbuf) < BUFSZ - 1)
|
||||||
|
Strcat(pbuf, ".");
|
||||||
raw_print(pbuf);
|
raw_print(pbuf);
|
||||||
raw_printf("Usage: %s -s [-v] <playertypes> [maxrank] [playernames]",
|
raw_printf("Usage: %s -s [-v] <playertypes> [maxrank] [playernames]",
|
||||||
|
|
||||||
g.hname);
|
g.hname);
|
||||||
raw_printf("Player types are: [-p role] [-r race]");
|
raw_printf("Player types are: [-p role] [-r race]");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user