From c333bfbb58169c0b99aafaf1491514649955a499 Mon Sep 17 00:00:00 2001 From: Ari Johnson Date: Wed, 21 Feb 2007 04:58:18 +0000 Subject: [PATCH] @NAMEFORMAT receives the default name as %1 --- game/txt/hlp/cobra_cmd.hlp | 5 +++-- hdrs/externs.h | 2 +- src/fundb.c | 3 ++- src/unparse.c | 34 +++++++++++++++++++--------------- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/game/txt/hlp/cobra_cmd.hlp b/game/txt/hlp/cobra_cmd.hlp index ac673ae..5fdd351 100644 --- a/game/txt/hlp/cobra_cmd.hlp +++ b/game/txt/hlp/cobra_cmd.hlp @@ -755,12 +755,13 @@ See also: @create Customizes the usual display of the object's name to people who are inside it and 'look'. It is evaluated as if it were a description - or similar message on the room. The room's dbref is passed as %0. + or similar message on the room. The room's dbref is passed as %0, + and the default-formatted name as %1. @nameformat is not used when people outside the object look at it. Example: Show the room's zone after its name. - @nameformat here = [name(%0)] [if(isdbref(zone(%0)),<[name(zone(%0))]>)] + @nameformat here = %1 [if(isdbref(zone(%0)),<[name(zone(%0))]>)] See also: @exitformat, @conformat, @descformat & @cost diff --git a/hdrs/externs.h b/hdrs/externs.h index b0f15df..9d383ae 100644 --- a/hdrs/externs.h +++ b/hdrs/externs.h @@ -550,7 +550,7 @@ extern int safe_ansi_string2(ansi_string *as, size_t start, size_t len, char *bu #define object_header(p,l) unparse_object(p,l) extern const char *unparse_object_myopic(dbref player, dbref loc); extern const char *unparse_room(dbref player, dbref loc); - extern int nameformat(dbref player, dbref loc, char *tbuf1); + extern int nameformat(dbref player, dbref loc, char *tbuf1, char *defname); extern const char *accented_name(dbref thing); /* From utils.c */ diff --git a/src/fundb.c b/src/fundb.c index 65af2d3..ba3eafa 100644 --- a/src/fundb.c +++ b/src/fundb.c @@ -1540,7 +1540,8 @@ FUNCTION(fun_iname) safe_str(T(e_perm), buff, bp); return; } - if (nameformat(executor, it, tbuf1)) + if (nameformat(executor, it, tbuf1, + IsExit(it) ? shortname(it) : (char *) accented_name(it))) safe_str(tbuf1, buff, bp); else if (IsExit(it)) safe_str(shortname(it), buff, bp); diff --git a/src/unparse.c b/src/unparse.c index 1acc2f4..cd35e8e 100644 --- a/src/unparse.c +++ b/src/unparse.c @@ -135,16 +135,10 @@ real_unparse(dbref player, dbref loc, int obey_myopic, int use_nameformat, case HOME: return T("*HOME*"); default: - if (use_nameformat && nameformat(player, loc, buf)) { - strcpy(tbuf1, buf); - got_nameformat = 1; - } else { - /* Not using @nameformat or couldn't get one */ - if (use_nameaccent) - strcpy(tbuf1, accented_name(loc)); - else - strcpy(tbuf1, Name(loc)); - } + if (use_nameaccent) + strcpy(tbuf1, accented_name(loc)); + else + strcpy(tbuf1, Name(loc)); if (IsExit(loc) && obey_myopic) { if ((p = strchr(tbuf1, ';'))) *p = '\0'; @@ -166,18 +160,23 @@ real_unparse(dbref player, dbref loc, int obey_myopic, int use_nameformat, safe_format(buf, &bp, "%s(#%d%s)", tbuf1, loc, unparse_flags(loc, player)); *bp = '\0'; - return buf; } else { /* show only the name */ if (ANSI_NAMES && ShowAnsi(player) && !got_nameformat) { bp = buf; safe_format(buf, &bp, "%s%s%s", ANSI_HILITE, tbuf1, ANSI_NORMAL); *bp = '\0'; - return buf; } else - return tbuf1; + strcpy(buf, tbuf1); } } + /* buf now contains the default formatting of the name. If we + * have @nameaccent, though, we might change to that. + */ + if (use_nameformat && nameformat(player, loc, tbuf1, buf)) + return tbuf1; + else + return buf; } /** Build the name of loc as seen by a player inside it, but only @@ -187,21 +186,23 @@ real_unparse(dbref player, dbref loc, int obey_myopic, int use_nameformat, * \param player the looker. * \param loc dbref of location being looked at. * \param tbuf1 address to store formatted name of loc. + * \param defname the name as it would be formatted without NAMEFORMAT. * \retval 1 a NAMEFORMAT was found, and tbuf1 contains formatted name. * \retval 0 no NAMEFORMAT on loc, tbuf1 is undefined. */ int -nameformat(dbref player, dbref loc, char *tbuf1) +nameformat(dbref player, dbref loc, char *tbuf1, char *defname) { ATTR *a; char *wsave[10], *rsave[NUMQ]; - char *arg, *bp; + char *arg, *bp, *arg2; char const *sp, *save; int j; a = atr_get(loc, "NAMEFORMAT"); if (a) { arg = (char *) mush_malloc(BUFFER_LEN, "string"); + arg2 = (char *) mush_malloc(BUFFER_LEN, "string"); if (!arg) mush_panic("Unable to allocate memory in nameformat"); save_global_regs("nameformat", rsave); @@ -213,6 +214,8 @@ nameformat(dbref player, dbref loc, char *tbuf1) global_eval_context.renv[j][0] = '\0'; strcpy(arg, unparse_dbref(loc)); global_eval_context.wenv[0] = arg; + strcpy(arg2, defname); + global_eval_context.wenv[1] = defname; sp = save = safe_atr_value(a); bp = tbuf1; process_expression(tbuf1, &bp, &sp, loc, player, player, @@ -224,6 +227,7 @@ nameformat(dbref player, dbref loc, char *tbuf1) } restore_global_regs("nameformat", rsave); mush_free((Malloc_t) arg, "string"); + mush_free((Malloc_t) arg2, "string"); return 1; } else { /* No @nameformat attribute */ -- 2.30.2