hyphenated Unix user names

Fix for $USER, $LOGNAME, getlogin() values that have dashes in them:
keep dash and whatever follows as part of the name instead of stripping
it off for role/race/gender/alignment.

Before:
% USER=test-bar-fem ./nethack
|Shall I pick your female Barbarian's race and alignment for you?
and character ended up named 'test'.

After:
% USER=test-bar-fem ./nethack
|Shall I pick character's race, role, gender and alignment for you?
and character ends up named 'test-bar-fem'.  However,
% ./nethack -u test-bar-fem
still behaves like the 'before' case.
|Shall I pick your female Barbarian's race and alignment for you?

Dash handling is only changed when the dash comes from user name (or
from envionment overriding user name), not from direct player input
or run-time config file.
This commit is contained in:
PatR
2020-05-12 16:38:12 -07:00
parent 1afa961416
commit 41ae223585
6 changed files with 26 additions and 30 deletions

View File

@@ -1,4 +1,4 @@
$NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.217 $ $NHDT-Date: 1589322383 2020/05/12 22:26:23 $
$NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.218 $ $NHDT-Date: 1589323704 2020/05/12 22:48:24 $
General Fixes and Modified Features
-----------------------------------
@@ -254,6 +254,9 @@ msdos: Add -DSTATUES_LOOK_LIKE_MONSTERS to Makefile1.cross so the VESA mode
can display statue glyphs.
tty: role and race selection menus weren't filtering out potential choices
which got excluded by OPTIONS=align:!lawful or !neutral or !chaotic
Unix: when user name is used as default character name, keep hyphenated value
intact instead stripping off dash and whatever follows as if that
specified role/race/&c (worked once upon a time; broken since 3.3.0)
windows: update for new status condition fields
X11: substantial overhaul of status display, both 'fancy' and 'tty-style'
X11: extend fancy status one-turn inverse video status-change highlighting to

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 decl.h $NHDT-Date: 1586815081 2020/04/13 21:58:01 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.230 $ */
/* NetHack 3.6 decl.h $NHDT-Date: 1589326665 2020/05/12 23:37:45 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.236 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Michael Allison, 2007. */
/* NetHack may be freely redistributed. See license for details. */
@@ -735,6 +735,7 @@ struct instance_globals {
#define DOMOVE_RUSH 0x00000002
const char *nomovemsg;
char plname[PL_NSIZ]; /* player name */
int plnamelen; /* length of plname[] if that came from getlogin() */
char pl_character[PL_CSIZ];
char pl_race; /* character's race */
char pl_fruit[PL_FSIZ];

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 decl.c $NHDT-Date: 1586815084 2020/04/13 21:58:04 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.209 $ */
/* NetHack 3.6 decl.c $NHDT-Date: 1589326673 2020/05/12 23:37:53 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.212 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Michael Allison, 2009. */
/* NetHack may be freely redistributed. See license for details. */
@@ -285,6 +285,7 @@ const struct instance_globals g_init = {
0L, /* domove_succeeded */
NULL, /* nomovemsg */
DUMMY, /* plname */
0, /* plnamelen */
DUMMY, /* pl_character */
'\0', /* pl_race */
DUMMY, /* pl_fruit */

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 options.c $NHDT-Date: 1584350350 2020/03/16 09:19:10 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.459 $ */
/* NetHack 3.7 options.c $NHDT-Date: 1589326675 2020/05/12 23:37:55 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.464 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Michael Allison, 2008. */
/* NetHack may be freely redistributed. See license for details. */
@@ -8520,7 +8520,7 @@ set_playmode()
{
if (wizard) {
if (authorize_wizard_mode())
Strcpy(g.plname, "wizard");
g.plnamelen = (int) strlen(strcpy(g.plname, "wizard"));
else
wizard = FALSE; /* not allowed or not available */
/* force explore mode if we didn't make it into wizard mode */

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 role.c $NHDT-Date: 1583102142 2020/03/01 22:35:42 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.69 $ */
/* NetHack 3.6 role.c $NHDT-Date: 1589326676 2020/05/12 23:37:56 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.70 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985-1999. */
/*-Copyright (c) Robert Patrick Rankin, 2012. */
/* NetHack may be freely redistributed. See license for details. */
@@ -1657,14 +1657,19 @@ plnamesuffix()
&& (sptr[i] == ' ' || sptr[i] == '\0'))
*g.plname = '\0'; /* call askname() */
}
if (!*g.plname)
g.plnamelen = 0;
}
do {
if (!*g.plname)
if (!*g.plname) {
askname(); /* fill g.plname[] if necessary, or set defer_plname */
g.plnamelen = 0; /* plname[] might have -role-race-&c attached */
}
/* Look for tokens delimited by '-' */
if ((eptr = index(g.plname, '-')) != (char *) 0)
sptr = g.plname + g.plnamelen;
if ((eptr = index(sptr, '-')) != (char *) 0)
*eptr++ = '\0';
while (eptr) {
/* Isolate the next token */
@@ -1685,10 +1690,7 @@ plnamesuffix()
} while (!*g.plname && !iflags.defer_plname);
/* commas in the g.plname confuse the record file, convert to spaces */
for (sptr = g.plname; *sptr; sptr++) {
if (*sptr == ',')
*sptr = ' ';
}
(void) strNsubst(g.plname, ",", " ", 0);
}
/* show current settings for name, role, race, gender, and alignment
@@ -1739,7 +1741,8 @@ winid where;
to narrow something done to a single choice] */
Sprintf(buf, "%12s ", "name:");
Strcat(buf, (which == RS_NAME) ? choosing : !*g.plname ? not_yet : g.plname);
Strcat(buf, (which == RS_NAME) ? choosing
: !*g.plname ? not_yet : g.plname);
putstr(where, 0, buf);
Sprintf(buf, "%12s ", "role:");
Strcat(buf, (which == RS_ROLE) ? choosing : (r == ROLE_NONE)

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 unixmain.c $NHDT-Date: 1570408210 2019/10/07 00:30:10 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.70 $ */
/* NetHack 3.6 unixmain.c $NHDT-Date: 1589326677 2020/05/12 23:37:57 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.86 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2011. */
/* NetHack may be freely redistributed. See license for details. */
@@ -228,22 +228,8 @@ char *argv[];
/* wizard mode access is deferred until here */
set_playmode(); /* sets plname to "wizard" for wizard mode */
if (exact_username) {
/*
* FIXME: this no longer works, ever since 3.3.0
* when plnamesuffix() was changed to find
* Name-Role-Race-Gender-Alignment. It removes
* all dashes rather than just the last one,
* regardless of whether whatever follows each
* dash matches role, race, gender, or alignment.
*/
/* guard against user names with hyphens in them */
int len = (int) strlen(g.plname);
/* append the current role, if any, so that last dash is ours */
if (++len < (int) sizeof g.plname)
(void) strncat(strcat(g.plname, "-"), g.pl_character,
sizeof g.plname - len - 1);
}
/* hide any hyphens from plnamesuffix() */
g.plnamelen = exact_username ? (int) strlen(g.plname) : 0;
/* strip role,race,&c suffix; calls askname() if plname[] is empty
or holds a generic user name like "player" or "games" */
plnamesuffix();
@@ -398,10 +384,12 @@ char *argv[];
case 'u':
if (argv[0][2]) {
(void) strncpy(g.plname, argv[0] + 2, sizeof g.plname - 1);
g.plnamelen = 0; /* plname[] might have -role-race attached */
} else if (argc > 1) {
argc--;
argv++;
(void) strncpy(g.plname, argv[0], sizeof g.plname - 1);
g.plnamelen = 0;
} else {
raw_print("Player name expected after -u");
}