#include <stdio.h>
#include <string.h>
#include "mech.h"
#include "htab.h"
#include "create.h"
#include "mech.partnames.h"
Include dependency graph for mech.partnames.c:
Go to the source code of this file.
Defines | |
#define | BRANDCOUNT 5 |
#define | UGLY_SORT(b, a) |
#define | SILLINESS(fun, val, fl) |
#define | DASH(fromval, tohash) |
#define | SILLY_GET(fun, value) |
#define | wildcard_match quick_wild |
Functions | |
void | list_hashstat (dbref player, const char *tab_name, HASHTAB *htab) |
static void | insert_sorted_brandname (int ind, PN *e) |
char * | part_figure_out_name (int i) |
char * | part_figure_out_sname (int i) |
char * | part_figure_out_shname (int i) |
char * | GetPartBrandName (int, int) |
char * | my_shortform (char *) |
static int | create_brandname (int id, int b) |
void | initialize_partname_tables () |
SILLY_GET (get_parts_short_name, shorty) | |
SILLY_GET (get_parts_long_name, longy) | |
SILLY_GET (get_parts_vlong_name, vlongy) | |
int | wildcard_match (char *, char *) |
int | find_matching_vlong_part (char *wc, int *ind, int *id, int *brand) |
int | find_matching_long_part (char *wc, int *i, int *id, int *brand) |
int | find_matching_short_part (char *wc, int *ind, int *id, int *brand) |
void | ListForms (dbref player, void *data, char *buffer) |
void | fun_btpartmatch (char *buff, char **bufc, dbref player, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs) |
void | fun_btpartname (char *buff, char **bufc, dbref player, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs) |
char * | partname_func (int index, int size) |
Variables | |
static PN * | index_sorted [BRANDCOUNT+1][NUM_ITEMS] |
PN ** | short_sorted = NULL |
PN ** | long_sorted = NULL |
PN ** | vlong_sorted = NULL |
int | object_count |
int | temp_brand_flag |
static HASHTAB | short_hash |
static HASHTAB | vlong_hash |
#define BRANDCOUNT 5 |
Definition at line 30 of file mech.partnames.c.
#define DASH | ( | fromval, | |||
tohash | ) |
Value:
for (tmpc1 = short_sorted[i]->fromval, tmpc2 = tmpbuf ; *tmpc1 ; tmpc1++, tmpc2++) \ *tmpc2 = ToLower(*tmpc1); \ *tmpc2 = 0; \ hashadd(tmpbuf, (int *) (i+1), &tohash);
Referenced by initialize_partname_tables().
#define SILLINESS | ( | fun, | |||
val, | |||||
fl | ) |
Value:
if (!(c=fun(id))) \ { free ((void *) p->val); free((void *) p); return 0; } \ if (b) \ { strcpy(buf2, c); \ if (fl) \ strcpy(buf3, my_shortform(brn)); \ sprintf(buf, "%s.%s", fl ? buf3 : brn, buf2); } \ else \ strcpy(buf, c); \ p->val = strdup(buf)
Referenced by create_brandname().
#define SILLY_GET | ( | fun, | |||
value | ) |
Value:
char * fun (int i, int b) { if (!(index_sorted[b][i])) \ { if (b) return fun(i,0); else { SendError(tprintf("No index for %d/%d", i, b)); return NULL; } }\ return index_sorted[b][i]->value; }
Definition at line 130 of file mech.partnames.c.
#define UGLY_SORT | ( | b, | |||
a | ) |
Value:
for (i = 0 ; i < ind; i++) if (strcmp(e->a, b[i]->a)<0) break; \ for (j = ind ; j > i ; j--) b[j] = b[j-1]; b[i] = e
Referenced by insert_sorted_brandname().
#define wildcard_match quick_wild |
static int create_brandname | ( | int | id, | |
int | b | |||
) | [static] |
Definition at line 59 of file mech.partnames.c.
References c, Create, GetPartBrandName(), PN::index, index_sorted, MBUF_SIZE, PACKED_PART, part_figure_out_name(), part_figure_out_shname(), part_figure_out_sname(), SILLINESS, and temp_brand_flag.
Referenced by initialize_partname_tables().
00060 { 00061 char buf[MBUF_SIZE]; 00062 char buf2[MBUF_SIZE]; 00063 char buf3[MBUF_SIZE]; 00064 char *c, *brn = NULL; 00065 PN *p; 00066 00067 if(b) 00068 if(!(brn = GetPartBrandName(id, b))) 00069 return 0; 00070 temp_brand_flag = b; 00071 Create(p, PN, 1); 00072 /* \todo Remove this stupid #define and make the code readable */ 00073 #define SILLINESS(fun,val,fl) \ 00074 if (!(c=fun(id))) \ 00075 { free ((void *) p->val); free((void *) p); return 0; } \ 00076 if (b) \ 00077 { strcpy(buf2, c); \ 00078 if (fl) \ 00079 strcpy(buf3, my_shortform(brn)); \ 00080 sprintf(buf, "%s.%s", fl ? buf3 : brn, buf2); } \ 00081 else \ 00082 strcpy(buf, c); \ 00083 p->val = strdup(buf) 00084 SILLINESS(part_figure_out_name, vlongy, 0); 00085 SILLINESS(part_figure_out_sname, longy, 0); 00086 SILLINESS(part_figure_out_shname, shorty, 1); 00087 p->index = PACKED_PART(id, b); 00088 index_sorted[b][id] = p; 00089 return 1; 00090 }
int find_matching_long_part | ( | char * | wc, | |
int * | i, | |||
int * | id, | |||
int * | brand | |||
) |
Definition at line 166 of file mech.partnames.c.
References PN::index, long_sorted, object_count, UNPACK_PART, and wildcard_match.
Referenced by fun_btaddstores(), fun_btgetpartcost(), fun_btgetweight(), fun_btpartmatch(), fun_btparttype(), fun_btremovestores(), fun_btsetpartcost(), fun_btstores(), fun_btweapstat(), list_matching(), stuff_change_sub(), and tech_parsegun().
00167 { 00168 PN *p; 00169 00170 for((*i)++; *i < object_count; (*i)++) 00171 if(wildcard_match(wc, (p = long_sorted[*i])->longy)) { 00172 UNPACK_PART(p->index, *id, *brand); 00173 return 1; 00174 } 00175 return 0; 00176 }
int find_matching_short_part | ( | char * | wc, | |
int * | ind, | |||
int * | id, | |||
int * | brand | |||
) |
Definition at line 178 of file mech.partnames.c.
References hashfind(), PN::index, MBUF_SIZE, short_hash, short_sorted, ToLower, and UNPACK_PART.
Referenced by fun_btaddstores(), fun_btpartmatch(), and stuff_change_sub().
00179 { 00180 PN *p; 00181 char *tmpc1, *tmpc2; 00182 char tmpbuf[MBUF_SIZE]; 00183 int *i; 00184 00185 if(*ind >= 0) 00186 return 0; 00187 for(tmpc1 = wc, tmpc2 = tmpbuf; *tmpc1; tmpc1++, tmpc2++) { 00188 *tmpc2 = ToLower(*tmpc1); 00189 } 00190 *tmpc2 = 0; 00191 if((i = hashfind(tmpbuf, &short_hash))) { 00192 if((p = short_sorted[((int) i) - 1])) { 00193 *ind = ((int) i); 00194 UNPACK_PART(p->index, *id, *brand); 00195 return 1; 00196 } 00197 } 00198 return 0; 00199 }
int find_matching_vlong_part | ( | char * | wc, | |
int * | ind, | |||
int * | id, | |||
int * | brand | |||
) |
Definition at line 142 of file mech.partnames.c.
References hashfind(), PN::index, MBUF_SIZE, short_sorted, ToLower, UNPACK_PART, and vlong_hash.
Referenced by FindSpecialItemCodeFromString(), fun_btaddstores(), fun_btgetpartcost(), fun_btgetweight(), fun_btpartmatch(), fun_btparttype(), fun_btremovestores(), fun_btsetpartcost(), fun_btstores(), fun_btweapstat(), initialize_pc(), load_template(), LoadSpecialObjects(), stuff_change_sub(), and WeaponIndexFromString().
00143 { 00144 PN *p; 00145 char *tmpc1, *tmpc2; 00146 char tmpbuf[MBUF_SIZE]; 00147 int *i; 00148 00149 if(ind && *ind >= 0) 00150 return 0; 00151 for(tmpc1 = wc, tmpc2 = tmpbuf; *tmpc1; tmpc1++, tmpc2++) { 00152 *tmpc2 = ToLower(*tmpc1); 00153 } 00154 *tmpc2 = 0; 00155 if((i = hashfind(tmpbuf, &vlong_hash))) { 00156 if((p = short_sorted[((int) i) - 1])) { 00157 if(ind) 00158 *ind = ((int) i); 00159 UNPACK_PART(p->index, *id, *brand); 00160 return 1; 00161 } 00162 } 00163 return 0; 00164 }
void fun_btpartmatch | ( | char * | buff, | |
char ** | bufc, | |||
dbref | player, | |||
dbref | cause, | |||
char * | fargs[], | |||
int | nfargs, | |||
char * | cargs[], | |||
int | ncargs | |||
) |
Definition at line 213 of file mech.partnames.c.
References find_matching_long_part(), find_matching_short_part(), find_matching_vlong_part(), FUNCHECK, MBUF_SIZE, PACKED_PART, safe_tprintf_str(), and WizR.
00215 { 00216 /* fargs[0] = name to match on 00217 */ 00218 00219 /* Added check to see if anything was found, if not 00220 * send error message 00221 * Dany - 06/2005 00222 */ 00223 00224 int partindex = 0, id = 0, brand = 0; 00225 int part_count = 0; 00226 00227 FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED"); 00228 FUNCHECK(strlen(fargs[0]) >= MBUF_SIZE, "#-1 PARTNAME TOO LONG"); 00229 FUNCHECK(!fargs[0], "#-1 NEED PARTNAME"); 00230 00231 partindex = -1; 00232 while (find_matching_short_part(fargs[0], &partindex, &id, &brand)) { 00233 safe_tprintf_str(buff, bufc, "%d ", PACKED_PART(id, brand)); 00234 part_count++; 00235 } 00236 00237 partindex = 0; 00238 while (find_matching_long_part(fargs[0], &partindex, &id, &brand)) { 00239 safe_tprintf_str(buff, bufc, "%d ", PACKED_PART(id, brand)); 00240 part_count++; 00241 } 00242 00243 partindex = -1; 00244 while (find_matching_vlong_part(fargs[0], &partindex, &id, &brand)) { 00245 safe_tprintf_str(buff, bufc, "%d ", PACKED_PART(id, brand)); 00246 part_count++; 00247 } 00248 00249 if(part_count == 0) 00250 safe_tprintf_str(buff, bufc, "#-1 INVALID PARTNAME"); 00251 }
void fun_btpartname | ( | char * | buff, | |
char ** | bufc, | |||
dbref | player, | |||
dbref | cause, | |||
char * | fargs[], | |||
int | nfargs, | |||
char * | cargs[], | |||
int | ncargs | |||
) |
Definition at line 253 of file mech.partnames.c.
References FUNCHECK, partname_func(), safe_tprintf_str(), and WizR.
00255 { 00256 /* fargs[0] = partnumer to find name for 00257 * fargs[1] = 'short', 'long' or 'vlong' 00258 */ 00259 00260 int index; 00261 char *cptr; 00262 char *infostr; 00263 00264 FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED"); 00265 FUNCHECK(!fargs[0], "#-1 NEED PARTNAME"); 00266 index = strtol(fargs[0], &cptr, 10); 00267 FUNCHECK(cptr == fargs[0], "#-1 INVALID PART NUMBER"); 00268 00269 infostr = partname_func(index, fargs[1][0]); 00270 safe_tprintf_str(buff, bufc, "%s", infostr); 00271 }
char* GetPartBrandName | ( | int | , | |
int | ||||
) |
Definition at line 52 of file failures.c.
00053 { 00054 int i; 00055 00056 if(!level) 00057 return NULL; 00058 i = GetBrandIndex(type); 00059 if(i < 0) 00060 return NULL; 00061 return brands[i * 5 / 6 + level - 1].name; 00062 }
void initialize_partname_tables | ( | void | ) |
Definition at line 94 of file mech.partnames.c.
References BRANDCOUNT, c, Create, create_brandname(), DASH, HASH_FACTOR, hashinit(), index_sorted, insert_sorted_brandname(), long_sorted, MBUF_SIZE, NUM_ITEMS, object_count, short_hash, short_sorted, vlong_hash, and vlong_sorted.
Referenced by LoadSpecialObjects().
00095 { 00096 int i, j, c = 0, m, n; 00097 char tmpbuf[MBUF_SIZE]; 00098 char *tmpc1, *tmpc2; 00099 00100 bzero(index_sorted, sizeof(index_sorted)); 00101 for(j = 0; j <= BRANDCOUNT; j++) 00102 for(i = 0; i < NUM_ITEMS; i++) 00103 c += create_brandname(i, j); 00104 Create(short_sorted, PN *, c); 00105 Create(long_sorted, PN *, c); 00106 Create(vlong_sorted, PN *, c); 00107 /* bubble-sort 'em and insert to array */ 00108 i = 0; 00109 for(m = 0; m <= BRANDCOUNT; m++) 00110 for(n = 0; n < NUM_ITEMS; n++) 00111 if(index_sorted[m][n]) 00112 insert_sorted_brandname(i++, index_sorted[m][n]); 00113 hashinit(&short_hash, 20 * HASH_FACTOR); 00114 hashinit(&vlong_hash, 20 * HASH_FACTOR); 00115 #define DASH(fromval,tohash) \ 00116 for (tmpc1 = short_sorted[i]->fromval, tmpc2 = tmpbuf ; *tmpc1 ; tmpc1++, tmpc2++) \ 00117 *tmpc2 = ToLower(*tmpc1); \ 00118 *tmpc2 = 0; \ 00119 hashadd(tmpbuf, (int *) (i+1), &tohash); 00120 00121 for(i = 0; i < c; i++) { 00122 DASH(shorty, short_hash); 00123 00124 /* DASH(longy, long_hash); */ 00125 DASH(vlongy, vlong_hash); 00126 } 00127 object_count = c; 00128 }
static void insert_sorted_brandname | ( | int | ind, | |
PN * | e | |||
) | [static] |
Definition at line 39 of file mech.partnames.c.
References long_sorted, short_sorted, UGLY_SORT, and vlong_sorted.
Referenced by initialize_partname_tables().
00040 { 00041 int i, j; 00042 00043 #define UGLY_SORT(b,a) \ 00044 for (i = 0 ; i < ind; i++) if (strcmp(e->a, b[i]->a)<0) break; \ 00045 for (j = ind ; j > i ; j--) b[j] = b[j-1]; b[i] = e 00046 UGLY_SORT(short_sorted, shorty); 00047 UGLY_SORT(long_sorted, longy); 00048 UGLY_SORT(vlong_sorted, vlongy); 00049 }
void ListForms | ( | dbref | player, | |
void * | data, | |||
char * | buffer | |||
) |
Definition at line 201 of file mech.partnames.c.
References notify, notify_printf(), object_count, and short_sorted.
00202 { 00203 int i; 00204 00205 notify(player, "Listing of forms:"); 00206 for(i = 0; i < object_count; i++) 00207 notify_printf(player, "%3d %-20s %-25s %s", i, 00208 short_sorted[i]->shorty, short_sorted[i]->longy, 00209 short_sorted[i]->vlongy); 00210 00211 }
char* my_shortform | ( | char * | ) |
Definition at line 1420 of file template.c.
Referenced by part_figure_out_shname().
01421 { 01422 static char buf2[MBUF_SIZE]; 01423 char *c, *d; 01424 01425 if(!buf) 01426 return NULL; 01427 if(strlen(buf) <= 4 && !strchr(buf, '/')) 01428 strcpy(buf2, buf); 01429 else { 01430 for(c = buf, d = buf2; *c; c++) 01431 if(isdigit(*c) || isupper(*c) || *c == '_') 01432 *d++ = *c; 01433 *d = 0; 01434 if(strlen(buf2) == 1) 01435 strcat(d, tprintf("%c", buf[1])); 01436 } 01437 return buf2; 01438 }
char* part_figure_out_name | ( | int | i | ) |
Definition at line 1470 of file template.c.
Referenced by create_brandname().
01471 { 01472 return part_figure_out_name_sub(i, 0); 01473 }
char* part_figure_out_shname | ( | int | i | ) |
Definition at line 1447 of file template.c.
Referenced by create_brandname().
01448 { 01449 char buf[MBUF_SIZE]; 01450 01451 if(!i) 01452 return NULL; 01453 buf[0] = 0; 01454 if(IsWeapon(i) && i < I2Weapon(num_def_weapons)) { 01455 strcpy(buf, &MechWeapons[Weapon2I(i)].name[CLCH(Weapon2I(i))]); 01456 } else if(IsAmmo(i) && i < I2Ammo(num_def_weapons)) { 01457 sprintf(buf, "Ammo_%s", 01458 &MechWeapons[Ammo2WeaponI(i)].name[CLCH(Ammo2WeaponI(i))]); 01459 } else if(IsBomb(i)) 01460 sprintf(buf, "Bomb_%s", bomb_name(Bomb2I(i))); 01461 else if(IsSpecial(i) && i < I2Special(internal_count)) 01462 strcpy(buf, internals[Special2I(i)]); 01463 if(IsCargo(i) && i < I2Cargo(cargo_count)) 01464 strcpy(buf, cargo[Cargo2I(i)]); 01465 if(!buf[0]) 01466 return NULL; 01467 return my_shortform(buf); 01468 }
char* part_figure_out_sname | ( | int | i | ) |
Definition at line 1475 of file template.c.
Referenced by create_brandname().
01476 { 01477 return part_figure_out_name_sub(i, 1); 01478 }
char* partname_func | ( | int | index, | |
int | size | |||
) |
Definition at line 273 of file mech.partnames.c.
References BRANDCOUNT, index_sorted, PN::longy, MBUF_SIZE, PN::shorty, UNPACK_PART, and PN::vlongy.
Referenced by fun_btpartname(), and payloadlist_func().
00274 { 00275 00276 static char buffer[MBUF_SIZE]; 00277 int id, brand; 00278 PN *p; 00279 00280 UNPACK_PART(index, id, brand); 00281 if(brand < 0 || brand > BRANDCOUNT || id < 0) { 00282 snprintf(buffer, MBUF_SIZE, "%s", "#-1 INVALID PART NUMBER"); 00283 return buffer; 00284 } 00285 00286 p = index_sorted[brand][id]; 00287 if(!p) { 00288 snprintf(buffer, MBUF_SIZE, "%s", "#-1 INVALID PART NUMBER"); 00289 return buffer; 00290 } 00291 00292 switch (size) { 00293 case 's': 00294 case 'S': 00295 snprintf(buffer, MBUF_SIZE, "%s", p->shorty); 00296 break; 00297 case 'l': 00298 case 'L': 00299 snprintf(buffer, MBUF_SIZE, "%s", p->longy); 00300 break; 00301 case 'v': 00302 case 'V': 00303 snprintf(buffer, MBUF_SIZE, "%s", p->vlongy); 00304 break; 00305 default: 00306 snprintf(buffer, MBUF_SIZE, "%s", "#-1 INVALID NAME TYPE"); 00307 break; 00308 } 00309 00310 return buffer; 00311 }
SILLY_GET | ( | get_parts_vlong_name | , | |
vlongy | ||||
) |
SILLY_GET | ( | get_parts_long_name | , | |
longy | ||||
) |
SILLY_GET | ( | get_parts_short_name | , | |
shorty | ||||
) |
int wildcard_match | ( | char * | , | |
char * | ||||
) |
PN* index_sorted[BRANDCOUNT+1][NUM_ITEMS] [static] |
Definition at line 31 of file mech.partnames.c.
Referenced by create_brandname(), initialize_partname_tables(), and partname_func().
PN** long_sorted = NULL |
Definition at line 35 of file mech.partnames.c.
Referenced by find_matching_long_part(), initialize_partname_tables(), and insert_sorted_brandname().
int object_count |
Definition at line 37 of file mech.partnames.c.
Referenced by find_matching_long_part(), fun_btstores(), initialize_partname_tables(), list_matching(), ListForms(), and mmdb_db_read().
HASHTAB short_hash [static] |
Definition at line 92 of file mech.partnames.c.
Referenced by find_matching_short_part(), and initialize_partname_tables().
PN** short_sorted = NULL |
Definition at line 34 of file mech.partnames.c.
Referenced by find_matching_short_part(), find_matching_vlong_part(), fun_btstores(), initialize_partname_tables(), insert_sorted_brandname(), list_matching(), and ListForms().
int temp_brand_flag |
HASHTAB vlong_hash [static] |
Definition at line 92 of file mech.partnames.c.
Referenced by find_matching_vlong_part(), and initialize_partname_tables().
PN** vlong_sorted = NULL |
Definition at line 36 of file mech.partnames.c.
Referenced by initialize_partname_tables(), and insert_sorted_brandname().