#include "copyright.h"
#include "config.h"
#include "mudconf.h"
#include "vattr.h"
#include "alloc.h"
#include "htab.h"
#include "externs.h"
Include dependency graph for vattr.c:
Go to the source code of this file.
Defines | |
#define | STRINGBLOCK 1000 |
Functions | |
static void | fixcase (char *) |
static char * | store_string (char *) |
void | vattr_init (void) |
VATTR * | vattr_find (char *name) |
VATTR * | vattr_alloc (char *name, int flags) |
VATTR * | vattr_define (char *name, int number, int flags) |
void | do_dbclean (dbref player, dbref cause, int key) |
void | vattr_delete (char *name) |
VATTR * | vattr_rename (char *name, char *newname) |
VATTR * | vattr_first (void) |
VATTR * | vattr_next (VATTR *vp) |
Variables | |
static char * | stringblock = (char *) 0 |
static int | stringblock_hwm = 0 |
#define STRINGBLOCK 1000 |
Definition at line 97 of file vattr.c.
References anum_set, atr_get_raw(), DO_WHOLE_DB, hash_firstentry(), hash_nextentry(), hashdelete(), mudstate, user_attribute::name, notify, user_attribute::number, and statedata::vattr_name_htab.
00098 { 00099 VATTR *vp; 00100 dbref i; 00101 int notfree; 00102 00103 for(vp = (VATTR *) hash_firstentry(&mudstate.vattr_name_htab); 00104 vp != NULL; 00105 vp = (VATTR *) hash_nextentry(&mudstate.vattr_name_htab)) { 00106 notfree = 0; 00107 00108 DO_WHOLE_DB(i) { 00109 if(atr_get_raw(i, vp->number) != NULL) { 00110 notfree = 1; 00111 break; 00112 } 00113 } 00114 00115 if(!notfree) { 00116 anum_set(vp->number, NULL); 00117 hashdelete(vp->name, &mudstate.vattr_name_htab); 00118 free((char *) vp); 00119 } 00120 } 00121 notify(player, "Database cleared of stale attribute entries."); 00122 }
static void fixcase | ( | char * | ) | [static] |
Definition at line 187 of file vattr.c.
References ToUpper.
Referenced by vattr_define(), vattr_delete(), and vattr_rename().
00188 { 00189 char *cp = name; 00190 00191 while (*cp) { 00192 *cp = ToUpper(*cp); 00193 cp++; 00194 } 00195 00196 return; 00197 }
static char * store_string | ( | char * | str | ) | [static] |
Some goop for efficiently storing strings we expect to keep forever. There is no freeing mechanism.
Definition at line 203 of file vattr.c.
References STRINGBLOCK, stringblock, stringblock_hwm, and StringCopy.
Referenced by vattr_define(), and vattr_rename().
00204 { 00205 int len; 00206 char *ret; 00207 00208 len = strlen(str); 00209 00210 /* 00211 * If we have no block, or there's not enough room left in the * * * 00212 * current one, get a new one. 00213 */ 00214 00215 if(!stringblock || (STRINGBLOCK - stringblock_hwm) < (len + 1)) { 00216 stringblock = (char *) malloc(STRINGBLOCK); 00217 if(!stringblock) 00218 return ((char *) 0); 00219 stringblock_hwm = 0; 00220 } 00221 ret = stringblock + stringblock_hwm; 00222 StringCopy(ret, str); 00223 stringblock_hwm += (len + 1); 00224 return (ret); 00225 }
VATTR* vattr_alloc | ( | char * | name, | |
int | flags | |||
) |
Definition at line 56 of file vattr.c.
References anum_extend(), statedata::attr_next, mudstate, number, and vattr_define().
Referenced by mkattr().
00057 { 00058 int number; 00059 00060 if(((number = mudstate.attr_next++) & 0x7f) == 0) 00061 number = mudstate.attr_next++; 00062 anum_extend(number); 00063 return (vattr_define(name, number, flags)); 00064 }
VATTR* vattr_define | ( | char * | name, | |
int | number, | |||
int | flags | |||
) |
Definition at line 66 of file vattr.c.
References anum_extend(), anum_set, fixcase(), hashadd(), mudstate, ok_attr_name(), store_string(), vattr_find(), statedata::vattr_name_htab, and VNAME_SIZE.
Referenced by db_read(), mmdb_db_read(), and vattr_alloc().
00067 { 00068 VATTR *vp; 00069 00070 /* 00071 * Be ruthless. 00072 */ 00073 00074 if(strlen(name) > VNAME_SIZE) 00075 name[VNAME_SIZE - 1] = '\0'; 00076 00077 fixcase(name); 00078 if(!ok_attr_name(name)) 00079 return (NULL); 00080 00081 if((vp = vattr_find(name)) != NULL) 00082 return (vp); 00083 00084 vp = (VATTR *) malloc(sizeof(VATTR)); 00085 00086 vp->name = store_string(name); 00087 vp->flags = flags; 00088 vp->number = number; 00089 00090 hashadd(vp->name, (int *) vp, &mudstate.vattr_name_htab); 00091 00092 anum_extend(vp->number); 00093 anum_set(vp->number, (ATTR *) vp); 00094 return (vp); 00095 }
void vattr_delete | ( | char * | name | ) |
Definition at line 124 of file vattr.c.
References anum_set, fixcase(), hashdelete(), hashfind(), mudstate, number, user_attribute::number, ok_attr_name(), and statedata::vattr_name_htab.
Referenced by do_attribute().
00125 { 00126 VATTR *vp; 00127 int number; 00128 00129 fixcase(name); 00130 if(!ok_attr_name(name)) 00131 return; 00132 00133 number = 0; 00134 00135 vp = (VATTR *) hashfind(name, &mudstate.vattr_name_htab); 00136 00137 if(vp) { 00138 number = vp->number; 00139 anum_set(number, NULL); 00140 hashdelete(name, &mudstate.vattr_name_htab); 00141 free((char *) vp); 00142 } 00143 00144 return; 00145 }
VATTR* vattr_find | ( | char * | name | ) |
Definition at line 41 of file vattr.c.
References hashfind(), mudstate, ok_attr_name(), and statedata::vattr_name_htab.
Referenced by atr_str(), do_attribute(), and vattr_define().
00042 { 00043 register VATTR *vp; 00044 00045 if(!ok_attr_name(name)) 00046 return (NULL); 00047 00048 vp = (VATTR *) hashfind(name, &mudstate.vattr_name_htab); 00049 00050 /* 00051 * vp is NULL or the right thing. It's right, either way. 00052 */ 00053 return (vp); 00054 }
VATTR* vattr_first | ( | void | ) |
Definition at line 174 of file vattr.c.
References hash_firstentry(), mudstate, and statedata::vattr_name_htab.
Referenced by db_write(), list_vattrs(), and vattr_next().
00175 { 00176 return (VATTR *) hash_firstentry(&mudstate.vattr_name_htab); 00177 }
void vattr_init | ( | void | ) |
Definition at line 36 of file vattr.c.
References hashinit(), mudstate, and statedata::vattr_name_htab.
Referenced by main().
00037 { 00038 hashinit(&mudstate.vattr_name_htab, 65536); 00039 }
Definition at line 179 of file vattr.c.
References hash_nextentry(), mudstate, vattr_first(), and statedata::vattr_name_htab.
Referenced by db_write(), and list_vattrs().
00180 { 00181 if(vp == NULL) 00182 return (vattr_first()); 00183 00184 return ((VATTR *) hash_nextentry(&mudstate.vattr_name_htab)); 00185 }
VATTR* vattr_rename | ( | char * | name, | |
char * | newname | |||
) |
Definition at line 147 of file vattr.c.
References fixcase(), hashfind(), mudstate, user_attribute::name, ok_attr_name(), store_string(), statedata::vattr_name_htab, and VNAME_SIZE.
00148 { 00149 VATTR *vp; 00150 00151 fixcase(name); 00152 if(!ok_attr_name(name)) 00153 return (NULL); 00154 00155 /* 00156 * Be ruthless. 00157 */ 00158 00159 if(strlen(newname) > VNAME_SIZE) 00160 newname[VNAME_SIZE - 1] = '\0'; 00161 00162 fixcase(newname); 00163 if(!ok_attr_name(newname)) 00164 return (NULL); 00165 00166 vp = (VATTR *) hashfind(name, &mudstate.vattr_name_htab); 00167 00168 if(vp) 00169 vp->name = store_string(newname); 00170 00171 return (vp); 00172 }
char* stringblock = (char *) 0 [static] |
int stringblock_hwm = 0 [static] |