From: Ari Johnson Date: Fri, 17 Dec 2010 19:42:04 +0000 (+0000) Subject: New alias_flag() HC function X-Git-Url: https://git.theari.com/?a=commitdiff_plain;h=99fe1e485fae331d227918c94980fbb6c4e8d205;p=cobramush.git New alias_flag() HC function --- diff --git a/hdrs/flags.h b/hdrs/flags.h index 7a45bf7..9d3ebbf 100644 --- a/hdrs/flags.h +++ b/hdrs/flags.h @@ -83,7 +83,7 @@ extern int type_from_old_flags(long old_flags); extern object_flag_type flags_from_old_flags(long old_flags, long old_toggles, int type); extern FLAG *add_flag(const char *name, const char letter, int type, - int perms, int negate_perms); + int perms, int negate_perms); extern void do_list_flags(dbref player, const char *arg, int lc); extern char *list_all_flags(const char *ns, const char *name, dbref privs, int which); extern void do_flag_info(const char *ns, dbref player, const char *name); diff --git a/src/flags.c b/src/flags.c index cfaaef5..9a23158 100644 --- a/src/flags.c +++ b/src/flags.c @@ -2292,16 +2292,44 @@ do_flag_alias(dbref player, const char *name, const char *alias) do_flag_info("FLAG", player, f->name); } else { /* Insert the flag in the ptab by the given alias */ - ptab_start_inserts(n->tab); - ptab_insert(n->tab, alias, f); - ptab_end_inserts(n->tab); - if ((f = match_flag_ns(n, alias))) + if (alias_flag(name, alias)) do_flag_info("FLAG", player, alias); else notify(player, T("Unknown failure adding alias.")); } } + /** Add a new alias for a flag. + * \param ns name of the flagspace to use. + * \param name name of the flag + * \param alias new alias for the flag + * \retval 1 alias added successfully + * \retval 0 failed to add alias + */ +int +alias_flag_generic(const char *ns, const char *name, const char *alias) +{ + FLAG *f; + FLAGSPACE *n; + + Flagspace_Lookup(n, ns); + + f = match_flag_ns(n, name); + if (!f) { + return 0; /* no such flag 'name' */ + } + + if (ptab_find_exact(n->tab, strupper(alias))) { + return 0; /* a flag called 'alias' already exists */ + } + + ptab_start_inserts(n->tab); + ptab_insert(n->tab, strupper(alias), f); + ptab_end_inserts(n->tab); + return ((f = match_flag_ns(n, alias)) ? 1 : 0); +} + + /** Change a flag's alias. * \param player the enactor. * \param name name of the flag.