/* 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; }
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); }
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 bi_Menu_Begin (progs_t *pr) { int x = P_INT (pr, 0); int y = P_INT (pr, 1); const char *text = P_GSTRING (pr, 2); menu_item_t *m = calloc (sizeof (menu_item_t), 1); m->x = x; m->y = y; m->text = text && text[0] ? strdup (text) : 0; if (menu) menu_add_item (menu, m); menu = m; if (m->text) Hash_Add (menu_hash, m); }
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; }
void opcode_init (void) { opcode_t *op, *mop; if (opcode_type_table) { Hash_FlushTable (opcode_void_table); Hash_FlushTable (opcode_type_table); } else { PR_Opcode_Init (); opcode_type_table = Hash_NewTable (1021, 0, opcode_free, 0); Hash_SetHashCompare (opcode_type_table, get_hash, compare); opcode_void_table = Hash_NewTable (1021, get_key, 0, 0); } for (op = pr_opcodes; op->name; op++) { if (op->min_version > options.code.progsversion) continue; mop = malloc (sizeof (opcode_t)); *mop = *op; if (options.code.progsversion == PROG_ID_VERSION) { // v6 progs have no concept of integer, but the QF engine // treats the operands of certain operands as integers // irrespective the progs version, so convert the engine's // view of the operands to the prog's view. if (mop->type_a == ev_integer) mop->type_a = ev_float; if (mop->type_b == ev_integer) mop->type_b = ev_float; if (mop->type_c == ev_integer) mop->type_c = ev_float; } Hash_AddElement (opcode_type_table, mop); if (mop->type_a == ev_void || mop->type_b == ev_void || mop->type_c == ev_void) Hash_Add (opcode_void_table, mop); } }
List_ptr MF_Edges_R4(MFace_ptr f, int dir, MVertex_ptr v0) { MFace_Adj_R4 *adj = (MFace_Adj_R4 *) f->adj; int i, j, k, ne, nv; List_ptr fedges; MVertex_ptr v, evtx[2], vtmp; MEdge_ptr e; k = 0; if (v0) { int fnd = 0, idx = 0; while (!fnd && (v = List_Next_Entry(adj->fvertices,&idx))) { if (v == v0) fnd = 1; else k++; } if (!fnd) { MSTK_Report("MF_Edges_R4","Cannot find vertex in face",MSTK_ERROR); return NULL; } } nv = ne = List_Num_Entries(adj->fvertices); fedges = List_New(ne); for (i = 0; i < ne; i++) { j = dir ? (k+i)%ne : (k-i+ne)%ne; evtx[0] = List_Entry(adj->fvertices,j); j = dir ? (k+(i+1))%ne : (k-(i+1)+ne)%ne; evtx[1] = List_Entry(adj->fvertices,j); #ifdef HASHTABLE if (evtx[0]>evtx[1]) { vtmp = evtx[0]; evtx[0] = evtx[1]; evtx[1] = vtmp; } e = Hash_Entry(MESH_Hash_Edges(MEnt_Mesh((MEntity_ptr) f)), 2, evtx); if (e == NULL) { e = ME_New(MEnt_Mesh((MEntity_ptr) f)); MEnt_Set_Volatile(e); ME_Set_Vertex(e,0,evtx[0]); ME_Set_Vertex(e,1,evtx[1]); ME_Set_GInfo_Auto(e); Hash_Add(MESH_Hash_Edges(MEnt_Mesh((MEntity_ptr) f)), e, 2, evtx); } #else e = ME_New(MEnt_Mesh((MEntity_ptr)f)); MEnt_Set_Volatile(e); ME_Set_Vertex(e,0,evtx[0]); ME_Set_Vertex(e,1,evtx[1]); ME_Set_GInfo_Auto(e); #endif List_Add(fedges,e); ME_Lock(e); } if (!MESH_AutoLock(MEnt_Mesh((MEntity_ptr) f))) { i = 0; while ((e = List_Next_Entry(fedges, &i))) { ME_UnLock(e); } } return fedges; }