src/nametab.c

Go to the documentation of this file.
00001 /*
00002  * htab.c - table hashing routines 
00003  */
00004 
00005 #include "copyright.h"
00006 #include "config.h"
00007 
00008 #include "db.h"
00009 #include "externs.h"
00010 #include "htab.h"
00011 #include "alloc.h"
00012 
00013 #include "mudconf.h"
00014 
00015 /*
00016  * ---------------------------------------------------------------------------
00017  * * search_nametab: Search a name table for a match and return the flag value.
00018  */
00019 int search_nametab(dbref player, NAMETAB * ntab, char *flagname)
00020 {
00021         NAMETAB *nt;
00022 
00023         for(nt = ntab; nt->name; nt++) {
00024                 if(minmatch(flagname, nt->name, nt->minlen)) {
00025                         if(check_access(player, nt->perm)) {
00026                                 return nt->flag;
00027                         } else
00028                                 return -2;
00029                 }
00030         }
00031         return -1;
00032 }
00033 
00034 /*
00035  * ---------------------------------------------------------------------------
00036  * * find_nametab_ent: Search a name table for a match and return a pointer to it.
00037  */
00038 
00039 NAMETAB *find_nametab_ent(dbref player, NAMETAB * ntab, char *flagname)
00040 {
00041         NAMETAB *nt;
00042 
00043         for(nt = ntab; nt->name; nt++) {
00044                 if(minmatch(flagname, nt->name, nt->minlen)) {
00045                         if(check_access(player, nt->perm)) {
00046                                 return nt;
00047                         }
00048                 }
00049         }
00050         return NULL;
00051 }
00052 
00053 /*
00054  * ---------------------------------------------------------------------------
00055  * * display_nametab: Print out the names of the entries in a name table.
00056  */
00057 
00058 void display_nametab(dbref player, NAMETAB * ntab, char *prefix,
00059                                          int list_if_none)
00060 {
00061         char *buf, *bp, *cp;
00062         NAMETAB *nt;
00063         int got_one;
00064 
00065         buf = alloc_lbuf("display_nametab");
00066         bp = buf;
00067         got_one = 0;
00068         for(cp = prefix; *cp; cp++)
00069                 *bp++ = *cp;
00070         for(nt = ntab; nt->name; nt++) {
00071                 if(God(player) || check_access(player, nt->perm)) {
00072                         *bp++ = ' ';
00073                         for(cp = nt->name; *cp; cp++)
00074                                 *bp++ = *cp;
00075                         got_one = 1;
00076                 }
00077         }
00078         *bp = '\0';
00079         if(got_one || list_if_none)
00080                 notify(player, buf);
00081         free_lbuf(buf);
00082 }
00083 
00084 /*
00085  * ---------------------------------------------------------------------------
00086  * * interp_nametab: Print values for flags defined in name table.
00087  */
00088 
00089 void interp_nametab(dbref player, NAMETAB * ntab, int flagword, char *prefix,
00090                                         char *true_text, char *false_text)
00091 {
00092         char *buf, *bp, *cp;
00093         NAMETAB *nt;
00094 
00095         buf = alloc_lbuf("interp_nametab");
00096         bp = buf;
00097         for(cp = prefix; *cp; cp++)
00098                 *bp++ = *cp;
00099         nt = ntab;
00100         while (nt->name) {
00101                 if(God(player) || check_access(player, nt->perm)) {
00102                         *bp++ = ' ';
00103                         for(cp = nt->name; *cp; cp++)
00104                                 *bp++ = *cp;
00105                         *bp++ = '.';
00106                         *bp++ = '.';
00107                         *bp++ = '.';
00108                         if((flagword & nt->flag) != 0)
00109                                 cp = true_text;
00110                         else
00111                                 cp = false_text;
00112                         while (*cp)
00113                                 *bp++ = *cp++;
00114                         if((++nt)->name)
00115                                 *bp++ = ';';
00116                 }
00117         }
00118         *bp = '\0';
00119         notify(player, buf);
00120         free_lbuf(buf);
00121 }
00122 
00123 /*
00124  * ---------------------------------------------------------------------------
00125  * * listset_nametab: Print values for flags defined in name table.
00126  */
00127 
00128 void listset_nametab(dbref player, NAMETAB * ntab, int flagword, char *prefix,
00129                                          int list_if_none)
00130 {
00131         char *buf, *bp, *cp;
00132         NAMETAB *nt;
00133         int got_one;
00134 
00135         buf = bp = alloc_lbuf("listset_nametab");
00136         for(cp = prefix; *cp; cp++)
00137                 *bp++ = *cp;
00138         nt = ntab;
00139         got_one = 0;
00140         while (nt->name) {
00141                 if(((flagword & nt->flag) != 0) && (God(player) ||
00142                                                                                         check_access(player, nt->perm))) {
00143                         *bp++ = ' ';
00144                         for(cp = nt->name; *cp; cp++)
00145                                 *bp++ = *cp;
00146                         got_one = 1;
00147                 }
00148                 nt++;
00149         }
00150         *bp = '\0';
00151         if(got_one || list_if_none)
00152                 notify(player, buf);
00153         free_lbuf(buf);
00154 }
00155 
00156 extern void cf_log_notfound(dbref, char *, const char *, char *);
00157 
00158 int cf_ntab_access(int *vp, char *str, long extra, dbref player, char *cmd)
00159 {
00160         NAMETAB *np;
00161         char *ap;
00162 
00163         for(ap = str; *ap && !isspace(*ap); ap++);
00164         if(*ap)
00165                 *ap++ = '\0';
00166         while (*ap && isspace(*ap))
00167                 ap++;
00168         for(np = (NAMETAB *) vp; np->name; np++) {
00169                 if(minmatch(str, np->name, np->minlen)) {
00170                         return cf_modify_bits(&(np->perm), ap, extra, player, cmd);
00171                 }
00172         }
00173         cf_log_notfound(player, cmd, "Entry", str);
00174         return -1;
00175 }

Generated on Mon May 28 04:25:25 2007 for BattletechMUX by  doxygen 1.4.7