mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-29 20:50:58 +00:00
Put the word jumping code in functions
This commit is contained in:
parent
0d3c03ccd6
commit
702b23ec3f
4 changed files with 52 additions and 44 deletions
|
@ -32,6 +32,7 @@
|
|||
#include "d_main.h"
|
||||
#include "m_menu.h"
|
||||
#include "filesrch.h"
|
||||
#include "m_misc.h"
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include "win32/win_main.h"
|
||||
|
@ -41,8 +42,6 @@
|
|||
#include "hardware/hw_main.h"
|
||||
#endif
|
||||
|
||||
#define PUNCTUATION "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
|
||||
|
||||
#define MAXHUDLINES 20
|
||||
|
||||
static boolean con_started = false; // console has been initialised
|
||||
|
@ -822,61 +821,23 @@ boolean CON_Responder(event_t *ev)
|
|||
if (input_cur != 0)
|
||||
{
|
||||
if (ctrldown)
|
||||
{
|
||||
int (*is)(int);
|
||||
char *line;
|
||||
int c;
|
||||
line = inputlines[inputline];
|
||||
c = line[--input_cur];
|
||||
if (isspace(c))
|
||||
is = isspace;
|
||||
else if (ispunct(c))
|
||||
is = ispunct;
|
||||
else
|
||||
is = isalnum;
|
||||
c = (*is)(line[input_cur]);
|
||||
while (input_cur > 0 &&
|
||||
(*is)(line[input_cur - 1]) == c)
|
||||
input_cur--;
|
||||
}
|
||||
input_cur = M_JumpWordReverse(inputlines[inputline], input_cur);
|
||||
else
|
||||
{
|
||||
--input_cur;
|
||||
}
|
||||
}
|
||||
|
||||
if (!shiftdown)
|
||||
input_sel = input_cur;
|
||||
return true;
|
||||
}
|
||||
else if (key == KEY_RIGHTARROW)
|
||||
{
|
||||
if (ctrldown)
|
||||
if (input_cur < input_len)
|
||||
{
|
||||
char *line;
|
||||
int c;
|
||||
|
||||
line = &inputlines[inputline][input_cur];
|
||||
c = line[0];
|
||||
|
||||
if (isspace(c))
|
||||
input_cur += strspn(line, " ");
|
||||
else if (ispunct(c))
|
||||
input_cur += strspn(line, PUNCTUATION);
|
||||
if (ctrldown)
|
||||
input_cur += M_JumpWord(&inputlines[inputline][input_cur]);
|
||||
else
|
||||
{
|
||||
if (isspace(line[1]))
|
||||
input_cur += 1 + strspn(&line[1], " ");
|
||||
else
|
||||
input_cur += strcspn(line, " "PUNCTUATION);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (input_cur < input_len)
|
||||
++input_cur;
|
||||
}
|
||||
|
||||
if (!shiftdown)
|
||||
input_sel = input_cur;
|
||||
return true;
|
||||
|
|
|
@ -541,6 +541,8 @@ INT32 I_GetKey(void);
|
|||
#define PATHSEP "/"
|
||||
#endif
|
||||
|
||||
#define PUNCTUATION "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
|
||||
|
||||
// Compile date and time and revision.
|
||||
extern const char *compdate, *comptime, *comprevision, *compbranch;
|
||||
|
||||
|
|
37
src/m_misc.c
37
src/m_misc.c
|
@ -2540,3 +2540,40 @@ void M_MkdirEach(const char *path, int start, int mode)
|
|||
{
|
||||
M_MkdirEachUntil(path, start, -1, mode);
|
||||
}
|
||||
|
||||
int M_JumpWord(const char *line)
|
||||
{
|
||||
int c;
|
||||
|
||||
c = line[0];
|
||||
|
||||
if (isspace(c))
|
||||
return strspn(line, " ");
|
||||
else if (ispunct(c))
|
||||
return strspn(line, PUNCTUATION);
|
||||
else
|
||||
{
|
||||
if (isspace(line[1]))
|
||||
return 1 + strspn(&line[1], " ");
|
||||
else
|
||||
return strcspn(line, " "PUNCTUATION);
|
||||
}
|
||||
}
|
||||
|
||||
int M_JumpWordReverse(const char *line, int offset)
|
||||
{
|
||||
int (*is)(int);
|
||||
int c;
|
||||
c = line[--offset];
|
||||
if (isspace(c))
|
||||
is = isspace;
|
||||
else if (ispunct(c))
|
||||
is = ispunct;
|
||||
else
|
||||
is = isalnum;
|
||||
c = (*is)(line[offset]);
|
||||
while (offset > 0 &&
|
||||
(*is)(line[offset - 1]) == c)
|
||||
offset--;
|
||||
return offset;
|
||||
}
|
||||
|
|
|
@ -101,6 +101,14 @@ boolean M_IsPathAbsolute (const char *path);
|
|||
void M_MkdirEach (const char *path, int start, int mode);
|
||||
void M_MkdirEachUntil (const char *path, int start, int end, int mode);
|
||||
|
||||
/* Return offset to the first word in a string. */
|
||||
/* E.g. cursor += M_JumpWord(line + cursor); */
|
||||
int M_JumpWord (const char *s);
|
||||
|
||||
/* Return index of the last word behind offset bytes in a string. */
|
||||
/* E.g. cursor = M_JumpWordReverse(line, cursor); */
|
||||
int M_JumpWordReverse (const char *line, int offset);
|
||||
|
||||
// counting bits, for weapon ammo code, usually
|
||||
FUNCMATH UINT8 M_CountBits(UINT32 num, UINT8 size);
|
||||
|
||||
|
|
Loading…
Reference in a new issue