-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconsoleCommands.d
72 lines (58 loc) · 1.86 KB
/
consoleCommands.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Modified version of LeGo CC_Active function, checks existence of both function and commandPrefix
*/
func int CC_Exists(var func function, var string commandPrefix) {
if (!_CC_List) {
return FALSE;
};
var int symID; symID = MEM_GetFuncID(function);
commandPrefix = STR_Upper (commandPrefix);
// Iterate over all registered CCs
var zCArray a; a = _^(_CC_List);
repeat(i, a.numInArray); var int i;
var CCItem cc; cc = _^(MEM_ReadIntArray(a.array, i));
if ((cc.fncID == symID) && (Hlp_StrCmp (cc.cmd, commandPrefix))) {
return TRUE;
};
end;
return FALSE;
};
/*
* Modified version of LeGo CC_Register function - allows multiple entries for same function (because of autocompletion :) )
*/
func void CC_RegisterMulti(var func function, var string commandPrefix, var string description) {
//If function was already registered ... then we cannot use LeGo version - as it does not allow multiple console commands for same function :-/
if (CC_Active(function)) {
//Allow only unique entries
if (CC_Exists (function, commandPrefix)) {
return;
};
commandPrefix = STR_Upper (commandPrefix);
CC_AutoComplete (commandPrefix, description);
var int symID; symID = MEM_GetFuncID(function);
// Create CC object
var int ccPtr; ccPtr = create(CCItem@);
var CCItem cc; cc = _^(ccPtr);
cc.fncID = symID;
cc.cmd = commandPrefix;
// Add CC to 'list'
MEM_ArrayInsert(_CC_List, ccPtr);
return;
};
CC_Register (function, commandPrefix, description);
};
/*
* Function returns auto-completed command from CC_List
*/
func string CC_GetAutoCompletedQuery (var string query) {
if (!_CC_List) { return query; };
// Iterate over all registered CCs
var zCArray a; a = _^(_CC_List);
repeat(i, a.numInArray); var int i;
var CCItem cc; cc = _^(MEM_ReadIntArray(a.array, i));
if (STR_StartsWith (cc.cmd, query)) {
return cc.cmd;
};
end;
return query;
};