Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
SRB2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
STJr
SRB2
Commits
f26bdf00
Commit
f26bdf00
authored
5 years ago
by
James R.
Browse files
Options
Downloads
Patches
Plain Diff
A system to encode flags in the command buffer
parent
03a3b023
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!734
Rebase Keycodes only branch.
,
!550
Renderer switching
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/command.c
+58
-9
58 additions, 9 deletions
src/command.c
src/command.h
+5
-2
5 additions, 2 deletions
src/command.h
with
63 additions
and
11 deletions
src/command.c
+
58
−
9
View file @
f26bdf00
...
...
@@ -61,6 +61,8 @@ static consvar_t *consvar_vars; // list of registered console variables
static
char
com_token
[
1024
];
static
char
*
COM_Parse
(
char
*
data
);
static
char
*
COM_Purge
(
char
*
text
,
int
*
lenp
);
CV_PossibleValue_t
CV_OnOff
[]
=
{{
0
,
"Off"
},
{
1
,
"On"
},
{
0
,
NULL
}};
CV_PossibleValue_t
CV_YesNo
[]
=
{{
0
,
"No"
},
{
1
,
"Yes"
},
{
0
,
NULL
}};
CV_PossibleValue_t
CV_Unsigned
[]
=
{{
0
,
"MIN"
},
{
999999999
,
"MAX"
},
{
0
,
NULL
}};
...
...
@@ -100,31 +102,61 @@ static cmdalias_t *com_alias; // aliases list
static
vsbuf_t
com_text
;
// variable sized buffer
/** Purges control characters out of some text.
*
* \param s The text.
* \param np Optionally a pointer to fill with the new string length.
* \return The new length.
* \sa COM_ExecuteString
*/
static
char
*
COM_Purge
(
char
*
s
,
int
*
np
)
{
char
*
t
;
char
*
p
;
int
n
;
n
=
strlen
(
s
);
t
=
s
+
n
+
1
;
p
=
s
;
while
((
p
=
strchr
(
p
,
'\033'
)
))
{
memmove
(
p
,
&
p
[
1
],
t
-
p
-
1
);
n
--
;
}
if
(
np
)
(
*
np
)
=
n
;
return
s
;
}
/** Adds text into the command buffer for later execution.
*
* \param ptext The text to add.
* \sa COM_BufInsertText
* \sa COM_BufInsertText
Ex
*/
void
COM_BufAddText
(
const
char
*
ptext
)
void
COM_BufAddText
Ex
(
const
char
*
ptext
,
int
flags
)
{
size_t
l
;
int
l
;
char
*
text
;
l
=
strlen
(
ptext
);
text
=
COM_Purge
(
Z_StrDup
(
ptext
)
,
&
l
)
;
if
(
com_text
.
cursize
+
l
>=
com_text
.
maxsize
)
if
(
com_text
.
cursize
+
2
+
l
>=
com_text
.
maxsize
)
{
CONS_Alert
(
CONS_WARNING
,
M_GetText
(
"Command buffer full!
\n
"
));
return
;
}
VS_Write
(
&
com_text
,
ptext
,
l
);
VS_WriteEx
(
&
com_text
,
text
,
l
,
flags
);
Z_Free
(
text
);
}
/** Adds command text and executes it immediately.
*
* \param ptext The text to execute. A newline is automatically added.
* \sa COM_BufAddText
* \sa COM_BufAddText
Ex
*/
void
COM_BufInsertText
(
const
char
*
ptext
)
void
COM_BufInsertText
Ex
(
const
char
*
ptext
,
int
flags
)
{
char
*
temp
=
NULL
;
size_t
templen
;
...
...
@@ -138,7 +170,7 @@ void COM_BufInsertText(const char *ptext)
}
// add the entire text of the file (or alias)
COM_BufAddText
(
ptext
);
COM_BufAddText
Ex
(
ptext
,
flags
);
COM_BufExecute
();
// do it right away
// add the copied off data
...
...
@@ -272,6 +304,7 @@ static size_t com_argc;
static
char
*
com_argv
[
MAX_ARGS
];
static
const
char
*
com_null_string
=
""
;
static
char
*
com_args
=
NULL
;
// current command args or NULL
static
int
com_flags
;
static
void
Got_NetVar
(
UINT8
**
p
,
INT32
playernum
);
...
...
@@ -394,9 +427,16 @@ static void COM_TokenizeString(char *ptext)
com_argc
=
0
;
com_args
=
NULL
;
com_flags
=
0
;
while
(
com_argc
<
MAX_ARGS
)
{
if
(
ptext
[
0
]
==
'\033'
)
{
com_flags
=
(
unsigned
)
ptext
[
1
];
ptext
+=
2
;
}
// Skip whitespace up to a newline.
while
(
*
ptext
!=
'\0'
&&
*
ptext
<=
' '
&&
*
ptext
!=
'\n'
)
ptext
++
;
...
...
@@ -1016,6 +1056,15 @@ void VS_Write(vsbuf_t *buf, const void *data, size_t length)
M_Memcpy
(
VS_GetSpace
(
buf
,
length
),
data
,
length
);
}
void
VS_WriteEx
(
vsbuf_t
*
buf
,
const
void
*
data
,
size_t
length
,
int
flags
)
{
char
*
p
;
p
=
VS_GetSpace
(
buf
,
2
+
length
);
p
[
0
]
=
'\033'
;
p
[
1
]
=
flags
;
M_Memcpy
(
&
p
[
2
],
data
,
length
);
}
/** Prints text in a variable buffer. Like VS_Write() plus a
* trailing NUL.
*
...
...
This diff is collapsed.
Click to expand it.
src/command.h
+
5
−
2
View file @
f26bdf00
...
...
@@ -36,10 +36,12 @@ size_t COM_FirstOption(void);
const
char
*
COM_CompleteCommand
(
const
char
*
partial
,
INT32
skips
);
// insert at queu (at end of other command)
void
COM_BufAddText
(
const
char
*
btext
);
#define COM_BufAddText(s) COM_BufAddTextEx(s, 0)
void
COM_BufAddTextEx
(
const
char
*
btext
,
int
flags
);
// insert in head (before other command)
void
COM_BufInsertText
(
const
char
*
btext
);
#define COM_BufInsertText(s) COM_BufInsertTextEx(s, 0)
void
COM_BufInsertTextEx
(
const
char
*
btext
,
int
flags
);
// don't bother inserting, just do immediately
void
COM_ImmedExecute
(
const
char
*
ptext
);
...
...
@@ -71,6 +73,7 @@ void VS_Free(vsbuf_t *buf);
void
VS_Clear
(
vsbuf_t
*
buf
);
void
*
VS_GetSpace
(
vsbuf_t
*
buf
,
size_t
length
);
void
VS_Write
(
vsbuf_t
*
buf
,
const
void
*
data
,
size_t
length
);
void
VS_WriteEx
(
vsbuf_t
*
buf
,
const
void
*
data
,
size_t
length
,
int
flags
);
void
VS_Print
(
vsbuf_t
*
buf
,
const
char
*
data
);
// strcats onto the sizebuf
//==================
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment