void TABLE::insert(SYM *sp) { int nn; TypeArray *ta = sp->GetProtoTypes(); TABLE *tab = this; SYM *p; int s1,s2,s3; std::string nm; // std::string sig; if (sp == nullptr || this == nullptr ) { dfs.printf("Null pointer at insert\n"); throw new C64PException(ERR_NULLPOINTER,1); } if (this==&tagtable) { dfs.printf("Insert into tagtable:%s|\n",(char *)sp->name->c_str()); } else dfs.printf("Insert %s into %p", (char *)sp->name->c_str(), (char *)this); dfs.printf("(%s)\n",owner ? (char *)SYM::GetPtr(owner)->name->c_str(): (char *)""); // sig = sp->BuildSignature(); if (tab==&gsyms[0]) { dfs.printf("Insert into global table\n"); s1 = hashadd((char *)sp->name->c_str()); s2 = hashadd((char *)sp->name2->c_str()); s3 = hashadd((char *)sp->name3->c_str()); // tab = &gsyms[(s1&s2)|(s1&s3)|(s2&s3)]; tab = &gsyms[s1]; } nm = *sp->name; // The symbol may not have a type if it's just a label. Find doens't // look at the return type parameter anyway, so we just set it to bt_long // if tp isn't set. nn = tab->Find(nm,sp->tp ? sp->tp->typeno : bt_long,ta,true); if(nn == 0) { if( tab->head == 0) { tab->SetHead(sp->GetIndex()); tab->SetTail(sp->GetIndex()); } else { sp->GetPtr(tab->tail)->next = sp->GetIndex(); tab->SetTail(sp->GetIndex()); } sp->SetNext(0); dfs.printf("At insert:\n"); sp->GetProtoTypes()->Print(); } else error(ERR_DUPSYM); if (ta) delete ta; // p = tab->GetHead(); // while(p) { // printf("Xele:%p|%s|\r\n", p, p->name.c_str()); // p = p->GetNext(); // } }
static void start_log(struct log_stream *log) { static int ht_initialized = 0; FILE *f; if (!log->filename || !*log->filename) { log->fp = stderr; } else { if (!ht_initialized) { hashinit(&htab_logfiles, 8); ht_initialized = 1; } if ((f = hashfind(strupper(log->filename), &htab_logfiles))) { /* We've already opened this file for another log, so just use that pointer */ log->fp = f; } else { log->fp = fopen(log->filename, "a+"); if (log->fp == NULL) { fprintf(stderr, "WARNING: cannot open log %s: %s\n", log->filename, strerror(errno)); log->fp = stderr; } else { hashadd(strupper(log->filename), log->fp, &htab_logfiles); fputs("START OF LOG.\n", log->fp); fflush(log->fp); } } } if (!log->buffer) log->buffer = allocate_bufferq(LOG_BUFFER_SIZE); }
/** Add a player's alias list to the player list htab. * \param player dbref of player to add. * \param alias list of names ot use as hash table keys for player, * semicolon-separated. */ void add_player_alias(dbref player, const char *alias) { char tbuf1[BUFFER_LEN], *s, *sp; if (!hft_initialized) init_hft(); if (!alias) { add_player(player); return; } mush_strncpy(tbuf1, alias, BUFFER_LEN); s = trim_space_sep(tbuf1, ALIAS_DELIMITER); while (s) { sp = split_token(&s, ALIAS_DELIMITER); while (sp && *sp && *sp == ' ') sp++; if (sp && *sp) { dbref *p; p = slab_malloc(player_dbref_slab, NULL); if (!p) mush_panic("Unable to allocate memory in plyrlist!"); *p = player; hashadd(strupper(sp), p, &htab_player_list); } } }
VATTR *vattr_define( char *name, int number, int flags ) { VATTR *vp; /* * Be ruthless. */ if( strlen( name ) >= VNAME_SIZE ) { name[VNAME_SIZE - 1] = '\0'; } fixcase( name ); if( !ok_attr_name( name ) ) { return ( NULL ); } if( ( vp = vattr_find( name ) ) != NULL ) { return ( vp ); } vp = ( VATTR * ) XMALLOC( sizeof( VATTR ), "vattr_define" ); vp->name = store_string( name ); vp->flags = flags; vp->number = number; hashadd( vp->name, ( int * ) vp, &mudstate.vattr_name_htab, 0 ); anum_extend( vp->number ); anum_set( vp->number, ( ATTR * ) vp ); return ( vp ); }
/** Add new help command. This function is * the basis for the help_command directive in mush.cnf. It creates * a new help entry for the hash table, builds a help index, * and adds the new command to the command table. * \param command_name name of help command to add. * \param filename name of the help file to use for this command. * \param admin if 1, this command reads admin topics, rather than standard. */ void add_help_file(const char *command_name, const char *filename, int admin) { help_file *h; if (help_init == 0) init_help_files(); if (!command_name || !filename || !*command_name || !*filename) return; /* If there's already an entry for it, complain */ h = hashfind(strupper(command_name), &help_files); if (h) { do_rawlog(LT_ERR, "Duplicate help_command %s ignored.", command_name); return; } h = mush_malloc(sizeof *h, "help_file.entry"); h->command = mush_strdup(strupper(command_name), "help_file.command"); h->file = mush_strdup(filename, "help_file.filename"); h->entries = 0; h->indx = NULL; h->admin = admin; help_build_index(h, h->admin); if (!h->indx) { mush_free(h->command, "help_file.command"); mush_free(h->file, "help_file.filename"); mush_free(h, "help_file.entry"); return; } (void) command_add(h->command, CMD_T_ANY | CMD_T_NOPARSE, NULL, 0, NULL, cmd_helpcmd); hashadd(h->command, h, &help_files); }
void init_powertab(void) { POWERENT *fp; hashinit(&mudstate.powers_htab, 25 * mudconf.hash_factor, HT_STR | HT_KEYREF); for (fp = gen_powers; fp->powername; fp++) { hashadd((char *) fp->powername, (int *) fp, &mudstate.powers_htab, 0); } }
void init_flagtab( void ) { FLAGENT *fp; hashinit( &mudstate.flags_htab, 100 * HASH_FACTOR, HT_STR | HT_KEYREF ); for( fp = gen_flags; fp->flagname; fp++ ) { hashadd( ( char * ) fp->flagname, ( int * ) fp, &mudstate.flags_htab, 0 ); } }
/** Add a player to the player list htab. * \param player dbref of player to add. */ void add_player(dbref player) { dbref *p; if (!hft_initialized) init_hft(); p = slab_malloc(player_dbref_slab, NULL); if (!p) mush_panic("Unable to allocate memory in plyrlist!"); *p = player; hashadd(strupper(Name(player)), p, &htab_player_list); }
static int h_nsrecord(int argc, unsigned char **argv){ #ifndef NOIPV6 struct sockaddr_in6 sa; #else struct sockaddr_in sa; #endif memset(&sa, 0, sizeof(sa)); if(!getip46(46, argv[2], (struct sockaddr *)&sa)) return 1; hashadd(*SAFAMILY(&sa)==AF_INET6?&dns6_table:&dns_table, argv[1], SAADDR(&sa), (time_t)0xffffffff); return 0; }
/** Add a new lock to the table. * \param name The name of the lock * \param flags The default flags. */ void define_lock(lock_type name, privbits flags) { lock_list *newlock; newlock = mush_malloc(sizeof *newlock, "lock"); newlock->type = mush_strdup(strupper(name), "lock.name"); newlock->flags = flags; newlock->creator = GOD; newlock->key = TRUE_BOOLEXP; newlock->next = NULL; hashadd((char *) newlock->type, newlock, &htab_locks); }
/** Initialize the lock strtree. */ void init_locks(void) { lock_list *ll; st_init(&lock_names, "LockNameTree"); hashinit(&htab_locks, 25); for (ll = lock_types; ll->type && *ll->type; ll++) hashadd(strupper(ll->type), ll, &htab_locks); local_locks(); }
SYM *search(char *na,TABLE *tbl) { SYM *thead; if (tbl==&gsyms[0]) thead = gsyms[hashadd(na)].head; else thead = tbl->head; while( thead != NULL) { if (thead->name != NULL) if(strcmp(thead->name,na) == 0) return thead; thead = thead->next; } return NULL; }
void insert(SYM* sp, TABLE *table) { if (table==&gsyms[0]) table = &gsyms[hashadd(sp->name)]; if( search(sp->name,table) == NULL) { if( table->head == NULL) table->head = table->tail = sp; else { table->tail->next = sp; table->tail = sp; } sp->next = NULL; } else error(ERR_DUPSYM); }
void local_mysql_init(void) { /* Setup our local command and function tables */ static CMDENT mysql_cmd_table[] = { {(char *) "@sql", NULL, CA_WIZARD, 0, 0, CS_ONE_ARG, 0, do_sql}, {(char *) "@sqlconnect", NULL, CA_WIZARD, 0, 0, CS_NO_ARGS, 0, do_sql_connect}, {(char *) "@sqldisconnect", NULL, CA_WIZARD, 0, 0, CS_NO_ARGS, 0, do_sql_shutdown}, {(char *) NULL, NULL, 0, 0, 0, 0, 0, NULL} }; static FUN mysql_fun_table[] = { {"SQL", local_fun_sql, 0, FN_VARARGS, CA_WIZARD, 0}, {"SQLESCAPE", local_fun_sql_escape, 1, 0, CA_WIZARD, 0}, {"SQLON", local_fun_sql_connect, 0, 0, CA_WIZARD, 0}, {"SQLOFF", local_fun_sql_disconnect, 0, 0, CA_WIZARD, 0}, {NULL, NULL, 0, 0, 0, 0} }; CMDENT *cmdp; FUN *fp; char *buff, *cp, *dp; /* Add the commands to the command table */ for (cmdp = mysql_cmd_table; cmdp->cmdname; cmdp++) { cmdp->cmdtype = CMD_LOCAL_e; hashadd(cmdp->cmdname, (int *) cmdp, &mudstate.command_htab); } /* Register the functions */ buff = alloc_sbuf("init_mysql_functab"); for (fp = mysql_fun_table ; fp->name ; fp++) { cp = (char *) fp->name; dp = buff; while (*cp) { *dp = ToLower(*cp); cp++; dp++; } *dp = '\0'; hashadd2(buff, (int *) fp, &mudstate.func_htab, 1); } sql_init(-1); }
/** Add new help command. This function is * the basis for the help_command directive in mush.cnf. It creates * a new help entry for the hash table, builds a help index, * and adds the new command to the command table. * \param command_name name of help command to add. * \param filename name of the help file to use for this command. * \param admin if 1, this command reads admin topics, rather than standard. */ void add_help_file(const char *command_name, const char *filename, int admin) { help_file *h; char newfilename[256] = "\0"; /* Must use a buffer for MacOS file path conversion */ strncpy(newfilename, filename, 256); if (help_init == 0) init_help_files(); if (!command_name || !filename || !*command_name || !*newfilename) return; /* If there's already an entry for it, complain */ h = hashfind(strupper(command_name), &help_files); if (h) { do_rawlog(LT_ERR, T("Duplicate help_command %s ignored."), command_name); return; } h = mush_malloc(sizeof *h, "help_file.entry"); h->command = mush_strdup(strupper(command_name), "help_file.command"); h->file = mush_strdup(newfilename, "help_file.filename"); h->entries = 0; h->indx = NULL; h->admin = admin; help_build_index(h, h->admin); if (!h->indx) { mush_free(h->command, "help_file.command"); mush_free(h->file, "help_file.filename"); mush_free(h, "help_file.entry"); return; } (void) command_add(h->command, CMD_T_ANY | CMD_T_NOPARSE, NULL, cmd_helpcmd, NULL); hashadd(h->command, h, &help_files); }
VATTR *vattr_rename( char *name, char *newname ) { VATTR *vp; fixcase( name ); if( !ok_attr_name( name ) ) { return ( NULL ); } /* * Be ruthless. */ if( strlen( newname ) >= VNAME_SIZE ) { newname[VNAME_SIZE - 1] = '\0'; } fixcase( newname ); if( !ok_attr_name( newname ) ) { return ( NULL ); } /* * We must explicitly delete and add the name to the hashtable, * * since we are changing the data. */ vp = ( VATTR * ) hashfind( name, &mudstate.vattr_name_htab ); if( vp ) { vp->name = store_string( newname ); hashdelete( name, &mudstate.vattr_name_htab ); hashadd( newname, ( int * ) vp, &mudstate.vattr_name_htab, 0 ); } return ( vp ); }
int cf_flag_name( int *vp, char *str, long extra, dbref player, char *cmd ) { char *numstr, *namestr, *tokst; FLAGENT *fp; int flagnum = -1; char *flagstr, *cp; numstr = strtok_r( str, " \t=,", &tokst ); namestr = strtok_r( NULL, " \t=,", &tokst ); if( numstr && ( strlen( numstr ) == 1 ) ) { flagnum = ( int ) strtol( numstr, ( char ** ) NULL, 10 ); } if( ( flagnum < 0 ) || ( flagnum > 9 ) ) { cf_log_notfound( player, cmd, "Not a marker flag", numstr ); return -1; } if( ( fp = letter_to_flag( *numstr ) ) == NULL ) { cf_log_notfound( player, cmd, "Marker flag", numstr ); return -1; } /* * Our conditions: The flag name MUST start with an underscore. It * must not conflict with the name of any existing flag. There is a * KNOWN MEMORY LEAK here -- if you name the flag and rename it * later, the old bit of memory for the name won't get freed. This * should pretty much never happen, since you're not going to run * around arbitrarily giving your flags new names all the time. */ flagstr = xstrprintf( "cf_flag_name", "_%s", namestr ); if( strlen( flagstr ) > 31 ) { cf_log_syntax( player, cmd, "Marker flag name too long: %s", namestr ); XFREE( flagstr, "cf_flag_name" ); } for( cp = flagstr; cp && *cp; cp++ ) { if( !isalnum( *cp ) && ( *cp != '_' ) ) { cf_log_syntax( player, cmd, "Illegal marker flag name: %s", namestr ); XFREE( flagstr, "cf_flag_name" ); return -1; } *cp = tolower( *cp ); } if( hashfind( flagstr, &mudstate.flags_htab ) ) { XFREE( flagstr, "cf_flag_name" ); cf_log_syntax( player, cmd, "Marker flag name in use: %s", namestr ); return -1; } for( cp = flagstr; cp && *cp; cp++ ) { *cp = toupper( *cp ); } fp->flagname = ( const char * ) flagstr; hashadd( ( char * ) fp->flagname, ( int * ) fp, &mudstate.flags_htab, 0 ); return 0; }
int TABLE::Find(std::string na,__int16 rettype, TypeArray *typearray, bool exact) { SYM *thead, *first; int nn; TypeArray *ta; char namebuf[1000]; int s1,s2,s3; std::string name; dfs.puts("</Find>\n"); dfs.puts((char *)na.c_str()); if (this==nullptr) { matchno = 0; return 0; } if (na.length()==0) { dfs.printf("name is empty string\n"); throw new C64PException(ERR_NULLPOINTER,1); } matchno = 0; if (this==&gsyms[0]) thead = SYM::GetPtr(gsyms[hashadd((char *)na.c_str())].GetHead()); else thead = SYM::GetPtr(head); first = thead; // while(thead != NULL) { // lfs.printf("Ele:%s|\n", (char *)thead->name->c_str()); // thead = thead->GetNext(); // } thead = first; while( thead != NULL) { // dfs.printf((char *)"|%s|,|%s|\n",(char *)thead->name->c_str(),(char *)na.c_str()); name = *thead->name; s1 = thead->name->compare(na); s2 = thead->name2->compare(na); s3 = thead->name3->compare(na); // dfs.printf("s1:%d ",s1); // dfs.printf("s2:%d ",s2); // dfs.printf("s3:%d\n",s3); if(((s1&s2)|(s1&s3)|(s2&s3))==0) { dfs.printf("Match\n"); match[matchno] = thead; matchno++; if (matchno > 98) break; if (exact) { ta = thead->GetProtoTypes(); if (ta->IsEqual(typearray)) { dfs.printf("Exact match"); ta->Print(); typearray->Print(); delete ta; return 1; } ta->Print(); delete ta; } } thead = thead->GetNextPtr(); if (thead==first) { dfs.printf("Circular list.\n"); throw new C64PException(ERR_CIRCULAR_LIST,1); } } dfs.puts("</Find>\n"); return exact ? 0 : matchno; }