mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-17 22:50:51 +00:00
Added some QC-API functions: String_Cut, String_Len, Key_CountBindings.
This commit is contained in:
parent
ecc20a7d17
commit
67d53f4e56
2 changed files with 86 additions and 2 deletions
|
@ -61,11 +61,17 @@ bi_Key_SetBinding (progs_t *pr)
|
|||
Key_SetBinding (target, keynum, binding);
|
||||
}
|
||||
|
||||
/*
|
||||
bi_Key_LookupBinding
|
||||
|
||||
Perform a reverse-binding-lookup
|
||||
*/
|
||||
static void
|
||||
bi_Key_LookupBinding (progs_t *pr)
|
||||
{
|
||||
int target = G_INT (pr, OFS_PARM0);
|
||||
const char *binding = G_STRING (pr, OFS_PARM1);
|
||||
int bindnum = G_INT (pr, OFS_PARM1);
|
||||
const char *binding = G_STRING (pr, OFS_PARM2);
|
||||
int i;
|
||||
knum_t keynum = -1;
|
||||
const char *keybind = NULL;
|
||||
|
@ -74,13 +80,47 @@ bi_Key_LookupBinding (progs_t *pr)
|
|||
keybind = keybindings[target][i];
|
||||
if(keybind == NULL) { continue; }
|
||||
if(strcmp(keybind, binding) == 0) {
|
||||
keynum = i;
|
||||
bindnum--;
|
||||
if(bindnum == 0) {
|
||||
keynum = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
G_INT (pr, OFS_RETURN) = keynum;
|
||||
};
|
||||
|
||||
/*
|
||||
bi_Key_CountBinding
|
||||
|
||||
Counts how often a binding is assigned to a key
|
||||
*/
|
||||
static void
|
||||
bi_Key_CountBinding (progs_t *pr)
|
||||
{
|
||||
int target = G_INT (pr, OFS_PARM0);
|
||||
const char *binding = G_STRING (pr, OFS_PARM1);
|
||||
int i, res = 0;
|
||||
const char *keybind = NULL;
|
||||
|
||||
for (i = 0; i < QFK_LAST; i++) {
|
||||
keybind = keybindings[target][i];
|
||||
if(keybind == NULL) { continue; }
|
||||
if(strcmp(keybind, binding) == 0) {
|
||||
res++;
|
||||
}
|
||||
}
|
||||
|
||||
G_INT (pr, OFS_RETURN) = res;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
bi_Key_LookupBinding
|
||||
|
||||
Convertes a keynum to a string
|
||||
*/
|
||||
static void
|
||||
bi_Key_KeynumToString (progs_t *pr)
|
||||
{
|
||||
|
@ -95,6 +135,7 @@ Key_Progs_Init (progs_t *pr)
|
|||
{
|
||||
PR_AddBuiltin (pr, "Key_SetBinding", bi_Key_SetBinding, -1);
|
||||
PR_AddBuiltin (pr, "Key_LookupBinding", bi_Key_LookupBinding, -1);
|
||||
PR_AddBuiltin (pr, "Key_CountBinding", bi_Key_CountBinding, -1);
|
||||
PR_AddBuiltin (pr, "Key_KeynumToString", bi_Key_KeynumToString, -1);
|
||||
// NEED THIS ?// PR_AddBuiltin (pr, "Key_StringToKeynum", bi_Key_KeynumToString, -1);
|
||||
}
|
||||
|
|
|
@ -41,6 +41,11 @@ static const char rcsid[] =
|
|||
#include "QF/progs.h"
|
||||
#include "QF/zone.h"
|
||||
|
||||
/*
|
||||
bi_String_ReplaceChar
|
||||
|
||||
Repalces a special character in a string with another
|
||||
*/
|
||||
static void
|
||||
bi_String_ReplaceChar (progs_t *pr)
|
||||
{
|
||||
|
@ -60,8 +65,46 @@ bi_String_ReplaceChar (progs_t *pr)
|
|||
RETURN_STRING (pr, dst);
|
||||
}
|
||||
|
||||
/*
|
||||
bi_String_Cut
|
||||
|
||||
Cuts a specified part from a string
|
||||
*/
|
||||
static void
|
||||
bi_String_Cut (progs_t *pr)
|
||||
{
|
||||
char pos = G_INT (pr, OFS_PARM0);
|
||||
char len = G_INT (pr, OFS_PARM1);
|
||||
const char *str = G_STRING (pr, OFS_PARM2);
|
||||
char *dst = Hunk_TempAlloc ((strlen (str) - len) + 1);
|
||||
int cnt;
|
||||
|
||||
memset (dst, 0, (strlen (str) - len) + 1);
|
||||
strncpy(dst, str, pos);
|
||||
str += pos;
|
||||
for (cnt = 0; cnt < len; cnt++)
|
||||
str++;
|
||||
strcpy(dst, str);
|
||||
RETURN_STRING (pr, dst);
|
||||
}
|
||||
|
||||
/*
|
||||
bi_String_Len
|
||||
|
||||
Gives back the length of the string
|
||||
*/
|
||||
static void
|
||||
bi_String_Len (progs_t *pr)
|
||||
{
|
||||
const char *str = G_STRING (pr, OFS_PARM0);
|
||||
|
||||
G_INT (pr, OFS_RETURN) = strlen(str);
|
||||
}
|
||||
|
||||
void
|
||||
String_Progs_Init (progs_t *pr)
|
||||
{
|
||||
PR_AddBuiltin (pr, "String_ReplaceChar", bi_String_ReplaceChar, -1);
|
||||
PR_AddBuiltin (pr, "String_Cut", bi_String_Cut, -1);
|
||||
PR_AddBuiltin (pr, "String_Len", bi_String_Len, -1);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue