symtab_t * symtab_flat_copy (symtab_t *symtab, symtab_t *parent) { symtab_t *newtab; symbol_t *newsym; symbol_t *symbol; newtab = new_symtab (parent, stab_local); do { for (symbol = symtab->symbols; symbol; symbol = symbol->next) { if (Hash_Find (newtab->tab, symbol->name)) continue; newsym = copy_symbol (symbol); symtab_addsymbol (newtab, newsym); } symtab = symtab->parent; // Set the tail pointer so symbols in ancestor tables come before // those in decendent tables. newtab->symtail = &newtab->symbols; } while (symtab); // Reset the tail pointer so any symbols added to newtab come after // those copied from the input symbol table chain. for (symbol = newtab->symbols; symbol && symbol->next; symbol = symbol->next) ; newtab->symtail = symbol ? &symbol->next : &newtab->symbols; return newtab; }
/* Registers a command and handler function */ VISIBLE int Cmd_AddCommand (const char *cmd_name, xcommand_t function, const char *description) { cmd_function_t *cmd; cmd_function_t **c; // fail if the command already exists cmd = (cmd_function_t *) Hash_Find (cmd_hash, cmd_name); if (cmd) { Sys_MaskPrintf (SYS_DEV, "Cmd_AddCommand: %s already defined\n", cmd_name); return 0; } cmd = calloc (1, sizeof (cmd_function_t)); SYS_CHECKMEM (cmd); cmd->name = cmd_name; cmd->function = function; cmd->description = description; Hash_Add (cmd_hash, cmd); for (c = &cmd_functions; *c; c = &(*c)->next) if (strcmp ((*c)->name, cmd->name) >= 0) break; cmd->next = *c; *c = cmd; return 1; }
VISIBLE int Cmd_Command (cbuf_args_t *args) { cmd_function_t *cmd; cmd_args = args; //cmd_source = src; if (!args->argc) return 0; // no tokens // check functions cmd = (cmd_function_t *) Hash_Find (cmd_hash, args->argv[0]->str); if (cmd) { if (cmd->function) { cmd->function (); } return 0; } // check cvars if (Cvar_Command ()) return 0; if (cbuf_active->unknown_command && cbuf_active->unknown_command ()) return 0; if (cbuf_active->strict) return -1; else if (cmd_warncmd->int_val || developer->int_val & SYS_DEV) Sys_Printf ("Unknown command \"%s\"\n", Cmd_Argv (0)); return 0; }
static void bi_Menu_SelectMenu (progs_t *pr) { const char *name = P_GSTRING (pr, 0); menu = 0; if (name && *name) menu = Hash_Find (menu_hash, name); if (menu) { Key_SetKeyDest (key_menu); if (menu->enter_hook) { run_menu_pre (); PR_ExecuteProgram (&menu_pr_state, menu->enter_hook); run_menu_post (); } } else { if (name && *name) Sys_Printf ("no menu \"%s\"\n", name); if (con_data.force_commandline) { Key_SetKeyDest (key_console); } else { Key_SetKeyDest (key_game); } } }
VISIBLE cbuf_interpreter_t * Cmd_GetProvider(const char *name) { cmd_provider_t *p = (cmd_provider_t *) Hash_Find (cmd_provider_hash, name); if (!p) return NULL; else return p->interp; }
symbol_t * symtab_lookup (symtab_t *symtab, const char *name) { symbol_t *symbol; do { if ((symbol = Hash_Find (symtab->tab, name))) return symbol; symtab = symtab->parent; } while (symtab); return 0; }
static void Cmd_Alias_f (void) { cmdalias_t *alias; dstring_t *cmd; int i, c; const char *s; if (Cmd_Argc () == 1) { Sys_Printf ("Current alias commands:\n"); for (alias = cmd_alias; alias; alias = alias->next) Sys_Printf ("alias %s \"%s\"\n", alias->name, alias->value); return; } s = Cmd_Argv (1); // if the alias already exists, reuse it alias = (cmdalias_t *) Hash_Find (cmd_alias_hash, s); if (Cmd_Argc () == 2) { if (alias) Sys_Printf ("alias %s \"%s\"\n", alias->name, alias->value); return; } if (alias) free ((char *) alias->value); else if (!Cmd_Exists (s)) { cmdalias_t **a; alias = calloc (1, sizeof (cmdalias_t)); SYS_CHECKMEM (alias); alias->name = strdup (s); Hash_Add (cmd_alias_hash, alias); for (a = &cmd_alias; *a; a = &(*a)->next) if (strcmp ((*a)->name, alias->name) >= 0) break; alias->next = *a; *a = alias; Cmd_AddCommand (alias->name, Cmd_Runalias_f, "Alias command."); } else { Sys_Printf ("alias: a command with the name \"%s\" already exists.\n", s); return; } // copy the rest of the command line cmd = dstring_newstr (); c = Cmd_Argc (); for (i = 2; i < c; i++) { dstring_appendstr (cmd, Cmd_Argv (i)); if (i != c - 1) dstring_appendstr (cmd, " "); } alias->value = dstring_freeze (cmd); }
/* Checks for the existance of a command */ VISIBLE qboolean Cmd_Exists (const char *cmd_name) { cmd_function_t *cmd; cmd = (cmd_function_t *) Hash_Find (cmd_hash, cmd_name); if (cmd) { return true; } return false; }
VISIBLE void Cmd_AddProvider(const char *name, cbuf_interpreter_t *interp) { cmd_provider_t *p = (cmd_provider_t *) Hash_Find (cmd_provider_hash, name); if (!p) { cmd_provider_t *p = malloc(sizeof(cmd_provider_t)); p->name = strdup(name); p->interp = interp; Hash_Add(cmd_provider_hash, p); } }
static void Cmd_Runalias_f (void) { cmdalias_t *a; a = (cmdalias_t *) Hash_Find (cmd_alias_hash, Cmd_Argv (0)); if (a) { Cbuf_InsertText (cbuf_active, a->value); return; } else { Sys_Printf ("BUG: No alias found for registered command. Please report this to the QuakeForge development team."); } }
void Menu_Enter () { if (!top_menu) { Key_SetKeyDest (key_console); return; } Key_SetKeyDest (key_menu); menu = Hash_Find (menu_hash, top_menu); if (menu && menu->enter_hook) { run_menu_pre (); PR_ExecuteProgram (&menu_pr_state, menu->enter_hook); run_menu_post (); } }
symbol_t * symtab_addsymbol (symtab_t *symtab, symbol_t *symbol) { symbol_t *s; if (symbol->table) internal_error (0, "symbol '%s' is already in another symbol table", symbol->name); if ((s = Hash_Find (symtab->tab, symbol->name))) return s; Hash_Add (symtab->tab, symbol); symbol->next = *symtab->symtail; *symtab->symtail = symbol; symtab->symtail = &symbol->next; symbol->table = symtab; return symbol; }