/* =============== GL_MakeNiceExtensionsList -- johnfitz =============== */ static char *GL_MakeNiceExtensionsList (const char *in) { char *copy, *token, *out; int i, count; if (!in) return Z_Strdup("(none)"); //each space will be replaced by 4 chars, so count the spaces before we malloc for (i = 0, count = 1; i < (int) strlen(in); i++) { if (in[i] == ' ') count++; } out = (char *) Z_Malloc (strlen(in) + count*3 + 1); //usually about 1-2k out[0] = 0; copy = (char *) Z_Strdup(in); for (token = strtok(copy, " "); token; token = strtok(NULL, " ")) { strcat(out, "\n "); strcat(out, token); } Z_Free (copy); return out; }
// // G_KeyActionForName // // Obtain a keyaction from its name // static keyaction_t *G_KeyActionForName(const char *name) { int i; keyaction_t *prev, *temp, *newaction; // sequential search // this is only called every now and then for(i = 0; i < num_keyactions; ++i) { if(!strcasecmp(name, keyactions[i].name)) return &keyactions[i]; } // check console keyactions // haleyjd: TOTALLY rewritten to use linked list if(cons_keyactions) { temp = cons_keyactions; while(temp) { if(!strcasecmp(name, temp->name)) return temp; temp = temp->next; } } else { // first time only - cons_keyactions was NULL cons_keyactions = (keyaction_t *)(Z_Malloc(sizeof(keyaction_t), PU_STATIC, 0)); cons_keyactions->bclass = kac_cmd; cons_keyactions->type = at_conscmd; cons_keyactions->name = Z_Strdup(name, PU_STATIC, 0); cons_keyactions->next = NULL; return cons_keyactions; } // not in list -- add prev = NULL; temp = cons_keyactions; while(temp) { prev = temp; temp = temp->next; } newaction = (keyaction_t *)(Z_Malloc(sizeof(keyaction_t), PU_STATIC, 0)); newaction->bclass = kac_cmd; newaction->type = at_conscmd; newaction->name = Z_Strdup(name, PU_STATIC, 0); newaction->next = NULL; if(prev) prev->next = newaction; return newaction; }
// // G_InitKeyBindings // // Set up key names and various details // void G_InitKeyBindings() { // various names for different keys for(size_t kn = 0; kn < earrlen(keyNames); kn++) keybindings[keyNames[kn].keyCode].name = keyNames[kn].name; for(int i = 0; i < NUMKEYS; i++) { // fill in name if not set yet if(!keybindings[i].name) { char tempstr[32]; // build generic name if(ectype::isPrint(i)) sprintf(tempstr, "%c", i); else sprintf(tempstr, "key%x", i); keybindings[i].name = Z_Strdup(tempstr, PU_STATIC, 0); } memset(keybindings[i].bindings, 0, NUMKEYACTIONCLASSES * sizeof(keyaction_t *)); } for(int i = 0; i < NUMKEYACTIONS; i++) keyactions[i].num = i; }
svariable_t *new_variable(script_t *script, char *name, int vtype) { int n; svariable_t *newvar; int tagtype = script==&global_script || script==&hub_script ? PU_STATIC : PU_LEVEL; // find an empty slot first newvar = Z_Malloc(sizeof(svariable_t), tagtype, 0); newvar->name = (char*)Z_Strdup(name, tagtype, 0); newvar->type = vtype; if(vtype == svt_string) { // 128 bytes for string newvar->value.s = Z_Malloc(128, tagtype, 0); newvar->value.s[0] = 0; } else newvar->value.i = 0; // now hook it into the hashchain n = variable_hash(name); newvar->next = script->variables[n]; script->variables[n] = newvar; return script->variables[n]; }
// create a new variable in a particular script. // returns a pointer to the new variable. svariable_t *script_t::new_variable(const char *name, int vtype) { int tagtype = (this == &global_script || this == &hub_script) ? PU_STATIC : PU_LEVEL; // find an empty slot first svariable_t *newvar = (svariable_t *)Z_Malloc(sizeof(svariable_t), tagtype, 0); newvar->name = (char *)Z_Strdup(name, tagtype, 0); newvar->type = vtype; if (vtype == svt_string) { // 256 bytes for string newvar->value.s = (char *)Z_Malloc(256, tagtype, 0); newvar->value.s[0] = 0; } else newvar->value.i = 0; // now hook it into the hashchain int n = variable_hash(name); newvar->next = variables[n]; variables[n] = newvar; return newvar; }
/* =================== Key_SetBinding =================== */ void Key_SetBinding (int keynum, const char *binding) { if (keynum == -1) return; if (keyreserved[keynum]) return; // free old bindings if (keybindings[keynum]) { Z_Free (keybindings[keynum]); keybindings[keynum] = NULL; } // allocate memory for new binding if (binding) keybindings[keynum] = Z_Strdup(binding); }
/* ============ Cmd_TokenizeString Parses the given string into command line tokens. ============ */ void Cmd_TokenizeString (const char *text) { int i; // clear the args from the last string for (i=0 ; i<cmd_argc ; i++) Z_Free (cmd_argv[i]); cmd_argc = 0; cmd_args = NULL; while (1) { // skip whitespace up to a /n while (*text && *text <= ' ' && *text != '\n') { text++; } if (*text == '\n') { // a newline seperates commands in the buffer text++; break; } if (!*text) return; if (cmd_argc == 1) cmd_args = text; text = COM_Parse (text); if (!text) return; if (cmd_argc < MAX_ARGS) { cmd_argv[cmd_argc] = Z_Strdup (com_token); cmd_argc++; } } }
static void CL_RE_Trigger_f (void) { int c,i,m; char *name; char *regexpstr; pcre_trigger_t *trig; pcre *re; pcre_extra *re_extra; const char *error; int error_offset; qbool newtrigger=false; qbool re_search = false; c = Cmd_Argc(); if (c > 3) { Com_Printf ("re_trigger <trigger name> <regexp>\n"); return; } if (c == 2 && IsRegexp(Cmd_Argv(1))) { re_search = true; } if (c == 1 || re_search) { if (!re_triggers) { Com_Printf ("no regexp_triggers defined\n"); } else { if (re_search && !ReSearchInit(Cmd_Argv(1))) return; Com_Printf ("List of re_triggers:\n"); for (trig=re_triggers, i=m=0; trig; trig=trig->next, i++) { if (!re_search || ReSearchMatch(trig->name)) { Com_Printf ("%s : \"%s\" : %d\n", trig->name, trig->regexpstr, trig->counter); m++; } } Com_Printf ("------------\n%i/%i re_triggers\n", m, i); if (re_search) ReSearchDone(); } return; } name = Cmd_Argv(1); trig = CL_FindReTrigger (name); if (c == 2) { if (trig) { Com_Printf ("%s: \"%s\"\n", trig->name, trig->regexpstr); Com_Printf (" options: mask=%d interval=%g%s%s%s%s%s\n", trig->flags & 0xFF, trig->min_interval, trig->flags & RE_FINAL ? " final" : "", trig->flags & RE_REMOVESTR ? " remove" : "", trig->flags & RE_NOLOG ? " nolog" : "", trig->flags & RE_ENABLED ? "" : " disabled", trig->flags & RE_NOACTION ? " noaction" : "" ); Com_Printf (" matched %d times\n", trig->counter); } else { Com_Printf ("re_trigger \"%s\" not found\n", name); } return; } if (c == 3) { regexpstr = Cmd_Argv(2); if (!trig) { // allocate new trigger newtrigger = true; trig = (pcre_trigger_t *) Z_Malloc (sizeof(pcre_trigger_t)); trig->next = re_triggers; re_triggers = trig; trig->name = Z_Strdup (name); trig->flags = RE_PRINT_ALL | RE_ENABLED; // catch all printed messages by default } error = NULL; if ((re = pcre_compile(regexpstr, 0, &error, &error_offset, NULL))) { error = NULL; re_extra = pcre_study(re, 0, &error); if (error) { Com_Printf ("Regexp study error: %s\n", &error); } else { if (!newtrigger) { (pcre_free)(trig->regexp); if (trig->regexp_extra) (pcre_free)(trig->regexp_extra); Z_Free(trig->regexpstr); } trig->regexpstr = Z_Strdup (regexpstr); trig->regexp = re; trig->regexp_extra = re_extra; return; } } else { Com_Printf ("Invalid regexp: %s\n", error); } prev = NULL; RemoveReTrigger(trig); } }
// // G_InitKeyBindings // // Set up key names and various details // void G_InitKeyBindings(void) { int i; // various names for different keys keybindings[KEYD_RIGHTARROW].name = "rightarrow"; keybindings[KEYD_LEFTARROW].name = "leftarrow"; keybindings[KEYD_UPARROW].name = "uparrow"; keybindings[KEYD_DOWNARROW].name = "downarrow"; keybindings[KEYD_ESCAPE].name = "escape"; keybindings[KEYD_ENTER].name = "enter"; keybindings[KEYD_TAB].name = "tab"; keybindings[KEYD_F1].name = "f1"; keybindings[KEYD_F2].name = "f2"; keybindings[KEYD_F3].name = "f3"; keybindings[KEYD_F4].name = "f4"; keybindings[KEYD_F5].name = "f5"; keybindings[KEYD_F6].name = "f6"; keybindings[KEYD_F7].name = "f7"; keybindings[KEYD_F8].name = "f8"; keybindings[KEYD_F9].name = "f9"; keybindings[KEYD_F10].name = "f10"; keybindings[KEYD_F11].name = "f11"; keybindings[KEYD_F12].name = "f12"; keybindings[KEYD_BACKSPACE].name = "backspace"; keybindings[KEYD_PAUSE].name = "pause"; keybindings[KEYD_MINUS].name = "-"; keybindings[KEYD_RSHIFT].name = "shift"; keybindings[KEYD_RCTRL].name = "ctrl"; keybindings[KEYD_RALT].name = "alt"; keybindings[KEYD_CAPSLOCK].name = "capslock"; keybindings[KEYD_INSERT].name = "insert"; keybindings[KEYD_HOME].name = "home"; keybindings[KEYD_END].name = "end"; keybindings[KEYD_PAGEUP].name = "pgup"; keybindings[KEYD_PAGEDOWN].name = "pgdn"; keybindings[KEYD_SCROLLLOCK].name = "scrolllock"; keybindings[KEYD_SPACEBAR].name = "space"; keybindings[KEYD_NUMLOCK].name = "numlock"; keybindings[KEYD_DEL].name = "delete"; keybindings[KEYD_MOUSE1].name = "mouse1"; keybindings[KEYD_MOUSE2].name = "mouse2"; keybindings[KEYD_MOUSE3].name = "mouse3"; keybindings[KEYD_MOUSE4].name = "mouse4"; keybindings[KEYD_MOUSE5].name = "mouse5"; keybindings[KEYD_MWHEELUP].name = "wheelup"; keybindings[KEYD_MWHEELDOWN].name = "wheeldown"; keybindings[KEYD_JOY1].name = "joy1"; keybindings[KEYD_JOY2].name = "joy2"; keybindings[KEYD_JOY3].name = "joy3"; keybindings[KEYD_JOY4].name = "joy4"; keybindings[KEYD_JOY5].name = "joy5"; keybindings[KEYD_JOY6].name = "joy6"; keybindings[KEYD_JOY7].name = "joy7"; keybindings[KEYD_JOY8].name = "joy8"; keybindings[KEYD_KP0].name = "kp_0"; keybindings[KEYD_KP1].name = "kp_1"; keybindings[KEYD_KP2].name = "kp_2"; keybindings[KEYD_KP3].name = "kp_3"; keybindings[KEYD_KP4].name = "kp_4"; keybindings[KEYD_KP5].name = "kp_5"; keybindings[KEYD_KP6].name = "kp_6"; keybindings[KEYD_KP7].name = "kp_7"; keybindings[KEYD_KP8].name = "kp_8"; keybindings[KEYD_KP9].name = "kp_9"; keybindings[KEYD_KPPERIOD].name = "kp_period"; keybindings[KEYD_KPDIVIDE].name = "kp_slash"; keybindings[KEYD_KPMULTIPLY].name = "kp_star"; keybindings[KEYD_KPMINUS].name = "kp_minus"; keybindings[KEYD_KPPLUS].name = "kp_plus"; keybindings[KEYD_KPENTER].name = "kp_enter"; keybindings[KEYD_KPEQUALS].name = "kp_equals"; keybindings[','].name = "<"; keybindings['.'].name = ">"; keybindings['`'].name = "tilde"; for(i = 0; i < NUM_KEYS; ++i) { // fill in name if not set yet if(!keybindings[i].name) { char tempstr[32]; // build generic name if(isprint(i)) sprintf(tempstr, "%c", i); else sprintf(tempstr, "key%02i", i); keybindings[i].name = Z_Strdup(tempstr, PU_STATIC, 0); } memset(keybindings[i].bindings, 0, NUMKEYACTIONCLASSES * sizeof(keyaction_t *)); } // haleyjd 10/09/05: init callback functions for some keyactions keyactions[ka_map_right].value.Handler = AM_HandlerRight; keyactions[ka_map_left].value.Handler = AM_HandlerLeft; keyactions[ka_map_up].value.Handler = AM_HandlerUp; keyactions[ka_map_down].value.Handler = AM_HandlerDown; keyactions[ka_map_zoomin].value.Handler = AM_HandlerZoomin; keyactions[ka_map_zoomout].value.Handler = AM_HandlerZoomout; }
// // G_KeyActionForName // // Obtain a keyaction from its name // static keyaction_t *G_KeyActionForName(const char *name) { static int cons_actionnum = NUMKEYACTIONS; keyaction_t *prev, *temp, *newaction; // sequential search // this is only called every now and then for(keyaction_t &keyaction : keyactions) { if(!keyaction.name) continue; if(!strcasecmp(name, keyaction.name)) return &keyaction; } // check console keyactions // haleyjd: TOTALLY rewritten to use linked list if(cons_keyactions) { temp = cons_keyactions; while(temp) { if(!strcasecmp(name, temp->name)) return temp; temp = temp->next; } } else { // first time only - cons_keyactions was NULL cons_keyactions = estructalloc(keyaction_t, 1); cons_keyactions->bclass = kac_cmd; cons_keyactions->type = at_conscmd; cons_keyactions->name = Z_Strdup(name, PU_STATIC, 0); cons_keyactions->next = nullptr; cons_keyactions->num = cons_actionnum++; return cons_keyactions; } // not in list -- add prev = nullptr; temp = cons_keyactions; while(temp) { prev = temp; temp = temp->next; } newaction = estructalloc(keyaction_t, 1); newaction->bclass = kac_cmd; newaction->type = at_conscmd; newaction->name = Z_Strdup(name, PU_STATIC, 0); newaction->next = nullptr; newaction->num = cons_actionnum++; if(prev) prev->next = newaction; return newaction; }
/* =============== Cmd_Alias_f -- johnfitz -- rewritten Creates a new command that executes a command string (possibly ; seperated) =============== */ void Cmd_Alias_f (void) { cmdalias_t *a; char cmd[1024]; int i, c; const char *s; switch (Cmd_Argc()) { case 1: //list all aliases for (a = cmd_alias, i = 0; a; a=a->next, i++) Con_SafePrintf (" %s: %s", a->name, a->value); if (i) Con_SafePrintf ("%i alias command(s)\n", i); else Con_SafePrintf ("no alias commands found\n"); break; case 2: //output current alias string for (a = cmd_alias ; a ; a=a->next) if (!strcmp(Cmd_Argv(1), a->name)) Con_Printf (" %s: %s", a->name, a->value); break; default: //set alias string s = Cmd_Argv(1); if (strlen(s) >= MAX_ALIAS_NAME) { Con_Printf ("Alias name is too long\n"); return; } // if the alias allready exists, reuse it for (a = cmd_alias ; a ; a=a->next) { if (!strcmp(s, a->name)) { Z_Free (a->value); break; } } if (!a) { a = (cmdalias_t *) Z_Malloc (sizeof(cmdalias_t)); a->next = cmd_alias; cmd_alias = a; } strcpy (a->name, s); // copy the rest of the command line cmd[0] = 0; // start out with a null string c = Cmd_Argc(); for (i = 2; i < c; i++) { q_strlcat (cmd, Cmd_Argv(i), sizeof(cmd)); if (i != c - 1) q_strlcat (cmd, " ", sizeof(cmd)); } if (q_strlcat(cmd, "\n", sizeof(cmd)) >= sizeof(cmd)) { Con_Printf("alias value too long!\n"); cmd[0] = '\n'; // nullify the string cmd[1] = 0; } a->value = Z_Strdup (cmd); break; } }