Move canonicalisation flags into their own bitfield with their own accessor and named constants
This commit is contained in:
parent
7133517883
commit
2638499648
1
Makefile
1
Makefile
|
@ -67,6 +67,7 @@ install-man:
|
||||||
ln -sf termkey_getkey.3.gz $(DESTDIR)$(MAN3DIR)/termkey_getkey_force.3.gz
|
ln -sf termkey_getkey.3.gz $(DESTDIR)$(MAN3DIR)/termkey_getkey_force.3.gz
|
||||||
ln -sf termkey_set_waittime.3.gz $(DESTDIR)$(MAN3DIR)/termkey_get_waittime.3.gz
|
ln -sf termkey_set_waittime.3.gz $(DESTDIR)$(MAN3DIR)/termkey_get_waittime.3.gz
|
||||||
ln -sf termkey_set_flags.3.gz $(DESTDIR)$(MAN3DIR)/termkey_get_flags.3.gz
|
ln -sf termkey_set_flags.3.gz $(DESTDIR)$(MAN3DIR)/termkey_get_flags.3.gz
|
||||||
|
ln -sf termkey_set_canonflags.3.gz $(DESTDIR)$(MAN3DIR)/termkey_get_canonflags.3.gz
|
||||||
|
|
||||||
# DIST CUT
|
# DIST CUT
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ int main(int argc, char *argv[])
|
||||||
is_str(key.utf8, " ", "key.utf8 for Space/unicode");
|
is_str(key.utf8, " ", "key.utf8 for Space/unicode");
|
||||||
is_str(endp, "", "consumed entire input for Space/unicode");
|
is_str(endp, "", "consumed entire input for Space/unicode");
|
||||||
|
|
||||||
termkey_set_flags(tk, termkey_get_flags(tk) | TERMKEY_FLAG_SPACESYMBOL);
|
termkey_set_canonflags(tk, termkey_get_canonflags(tk) | TERMKEY_CANON_SPACESYMBOL);
|
||||||
|
|
||||||
CLEAR_KEY;
|
CLEAR_KEY;
|
||||||
endp = termkey_strpkey(tk, " ", &key, 0);
|
endp = termkey_strpkey(tk, " ", &key, 0);
|
||||||
|
|
|
@ -33,6 +33,7 @@ struct TermKeyDriverNode {
|
||||||
struct _TermKey {
|
struct _TermKey {
|
||||||
int fd;
|
int fd;
|
||||||
int flags;
|
int flags;
|
||||||
|
int canonflags;
|
||||||
unsigned char *buffer;
|
unsigned char *buffer;
|
||||||
size_t buffstart; // First offset in buffer
|
size_t buffstart; // First offset in buffer
|
||||||
size_t buffcount; // NUMBER of entires valid in buffer
|
size_t buffcount; // NUMBER of entires valid in buffer
|
||||||
|
|
28
termkey.c
28
termkey.c
|
@ -198,6 +198,10 @@ static TermKey *termkey_new_full(int fd, int flags, size_t buffsize, int waittim
|
||||||
|
|
||||||
tk->fd = fd;
|
tk->fd = fd;
|
||||||
tk->flags = flags;
|
tk->flags = flags;
|
||||||
|
tk->canonflags = 0;
|
||||||
|
|
||||||
|
if(flags & TERMKEY_FLAG_SPACESYMBOL)
|
||||||
|
tk->canonflags |= TERMKEY_CANON_SPACESYMBOL;
|
||||||
|
|
||||||
tk->buffer = malloc(buffsize);
|
tk->buffer = malloc(buffsize);
|
||||||
if(!tk->buffer)
|
if(!tk->buffer)
|
||||||
|
@ -373,6 +377,11 @@ int termkey_get_flags(TermKey *tk)
|
||||||
void termkey_set_flags(TermKey *tk, int newflags)
|
void termkey_set_flags(TermKey *tk, int newflags)
|
||||||
{
|
{
|
||||||
tk->flags = newflags;
|
tk->flags = newflags;
|
||||||
|
|
||||||
|
if(tk->flags & TERMKEY_FLAG_SPACESYMBOL)
|
||||||
|
tk->canonflags |= TERMKEY_CANON_SPACESYMBOL;
|
||||||
|
else
|
||||||
|
tk->canonflags &= ~TERMKEY_CANON_SPACESYMBOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void termkey_set_waittime(TermKey *tk, int msec)
|
void termkey_set_waittime(TermKey *tk, int msec)
|
||||||
|
@ -385,6 +394,21 @@ int termkey_get_waittime(TermKey *tk)
|
||||||
return tk->waittime;
|
return tk->waittime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int termkey_get_canonflags(TermKey *tk)
|
||||||
|
{
|
||||||
|
return tk->canonflags;
|
||||||
|
}
|
||||||
|
|
||||||
|
void termkey_set_canonflags(TermKey *tk, int flags)
|
||||||
|
{
|
||||||
|
tk->canonflags = flags;
|
||||||
|
|
||||||
|
if(tk->canonflags & TERMKEY_CANON_SPACESYMBOL)
|
||||||
|
tk->flags |= TERMKEY_FLAG_SPACESYMBOL;
|
||||||
|
else
|
||||||
|
tk->flags &= ~TERMKEY_FLAG_SPACESYMBOL;
|
||||||
|
}
|
||||||
|
|
||||||
static void eat_bytes(TermKey *tk, size_t count)
|
static void eat_bytes(TermKey *tk, size_t count)
|
||||||
{
|
{
|
||||||
if(count >= tk->buffcount) {
|
if(count >= tk->buffcount) {
|
||||||
|
@ -571,9 +595,9 @@ static void emit_codepoint(TermKey *tk, long codepoint, TermKeyKey *key)
|
||||||
|
|
||||||
void termkey_canonicalise(TermKey *tk, TermKeyKey *key)
|
void termkey_canonicalise(TermKey *tk, TermKeyKey *key)
|
||||||
{
|
{
|
||||||
int flags = tk->flags;
|
int flags = tk->canonflags;
|
||||||
|
|
||||||
if(flags & TERMKEY_FLAG_SPACESYMBOL) {
|
if(flags & TERMKEY_CANON_SPACESYMBOL) {
|
||||||
if(key->type == TERMKEY_TYPE_UNICODE && key->code.number == 0x20) {
|
if(key->type == TERMKEY_TYPE_UNICODE && key->code.number == 0x20) {
|
||||||
key->type = TERMKEY_TYPE_KEYSYM;
|
key->type = TERMKEY_TYPE_KEYSYM;
|
||||||
key->code.sym = TERMKEY_SYM_SPACE;
|
key->code.sym = TERMKEY_SYM_SPACE;
|
||||||
|
|
|
@ -144,11 +144,15 @@ enum {
|
||||||
TERMKEY_FLAG_RAW = 1 << 2, // Input is raw bytes, not UTF-8
|
TERMKEY_FLAG_RAW = 1 << 2, // Input is raw bytes, not UTF-8
|
||||||
TERMKEY_FLAG_UTF8 = 1 << 3, // Input is definitely UTF-8
|
TERMKEY_FLAG_UTF8 = 1 << 3, // Input is definitely UTF-8
|
||||||
TERMKEY_FLAG_NOTERMIOS = 1 << 4, // Do not make initial termios calls on construction
|
TERMKEY_FLAG_NOTERMIOS = 1 << 4, // Do not make initial termios calls on construction
|
||||||
TERMKEY_FLAG_SPACESYMBOL = 1 << 5, // Space is symbolic rather than Unicode
|
TERMKEY_FLAG_SPACESYMBOL = 1 << 5, // Sets TERMKEY_CANON_SPACESYMBOL
|
||||||
TERMKEY_FLAG_CTRLC = 1 << 6, // Allow Ctrl-C to be read as normal, disabling SIGINT
|
TERMKEY_FLAG_CTRLC = 1 << 6, // Allow Ctrl-C to be read as normal, disabling SIGINT
|
||||||
TERMKEY_FLAG_EINTR = 1 << 7 // Return ERROR on signal (EINTR) rather than retry
|
TERMKEY_FLAG_EINTR = 1 << 7 // Return ERROR on signal (EINTR) rather than retry
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
TERMKEY_CANON_SPACESYMBOL = 1 << 0, // Space is symbolic rather than Unicode
|
||||||
|
};
|
||||||
|
|
||||||
void termkey_check_version(int major, int minor);
|
void termkey_check_version(int major, int minor);
|
||||||
|
|
||||||
TermKey *termkey_new(int fd, int flags);
|
TermKey *termkey_new(int fd, int flags);
|
||||||
|
@ -163,6 +167,9 @@ void termkey_set_flags(TermKey *tk, int newflags);
|
||||||
int termkey_get_waittime(TermKey *tk);
|
int termkey_get_waittime(TermKey *tk);
|
||||||
void termkey_set_waittime(TermKey *tk, int msec);
|
void termkey_set_waittime(TermKey *tk, int msec);
|
||||||
|
|
||||||
|
int termkey_get_canonflags(TermKey *tk);
|
||||||
|
void termkey_set_canonflags(TermKey *tk, int);
|
||||||
|
|
||||||
void termkey_canonicalise(TermKey *tk, TermKeyKey *key);
|
void termkey_canonicalise(TermKey *tk, TermKeyKey *key);
|
||||||
|
|
||||||
TermKeyResult termkey_getkey(TermKey *tk, TermKeyKey *key);
|
TermKeyResult termkey_getkey(TermKey *tk, TermKeyKey *key);
|
||||||
|
|
|
@ -10,15 +10,15 @@ termkey_canonicalise \- canonicalise a key event
|
||||||
.sp
|
.sp
|
||||||
Link with \fI-ltermkey\fP.
|
Link with \fI-ltermkey\fP.
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
\fBtermkey_canonicalise\fP(3) modifies the key event structure given by \fIkey\fP according to the flags set on the given \fItk\fP instance. This operation is performed implicitly by \fBtermkey_getkey\fP(3), \fBtermkey_waitkey\fP(3) and \fBtermkey_strpkey\fP(3), and is also provided explicitly by this function.
|
\fBtermkey_canonicalise\fP(3) modifies the key event structure given by \fIkey\fP according to the canonicalisation flags set on the given \fItk\fP instance. This operation is performed implicitly by \fBtermkey_getkey\fP(3), \fBtermkey_waitkey\fP(3) and \fBtermkey_strpkey\fP(3), and is also provided explicitly by this function.
|
||||||
.PP
|
.PP
|
||||||
The canonicalisation operation is affected by the following flags:
|
The canonicalisation operation is affected by the following flags:
|
||||||
.TP
|
.TP
|
||||||
.B TERMKEY_FLAG_SPACESYMBOL
|
.B TERMKEY_CANON_SPACESYMBOL
|
||||||
If this flag is set then a Unicode space character is represented using the \fBTERMKEY_SYM_SPACE\fP symbol. If this flag is not set, it is represented by the U+0020 Unicode codepoint.
|
If this flag is set then a Unicode space character is represented using the \fBTERMKEY_SYM_SPACE\fP symbol. If this flag is not set, it is represented by the U+0020 Unicode codepoint.
|
||||||
.SH "RETURN VALUE"
|
.SH "RETURN VALUE"
|
||||||
\fBtermkey_canonicalise\fP() returns no value.
|
\fBtermkey_canonicalise\fP() returns no value.
|
||||||
.SH "SEE ALSO"
|
.SH "SEE ALSO"
|
||||||
.BR termkey_new (3),
|
.BR termkey_set_canonflags (3),
|
||||||
.BR termkey_waitkey (3),
|
.BR termkey_waitkey (3),
|
||||||
.BR termkey_strpkey (3)
|
.BR termkey_strpkey (3)
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
.TH TERMKEY_SET_CANONFLAGS 3
|
||||||
|
.SH NAME
|
||||||
|
termkey_set_canonflags, termkey_get_canonflags \- control the canonicalisation flags
|
||||||
|
.SH SYNOPSIS
|
||||||
|
.nf
|
||||||
|
.B #include <termkey.h>
|
||||||
|
.sp
|
||||||
|
.BI "void termkey_set_canonflags(TermKey *" tk ", int " newflags );
|
||||||
|
.BI "int termkey_get_canonflags(TermKey *" tk );
|
||||||
|
.fi
|
||||||
|
.sp
|
||||||
|
Link with \fI-ltermkey\fP.
|
||||||
|
.SH DESCRIPTION
|
||||||
|
\fBtermkey_set_canonflags\fP() changes the set of canonicalisation flags in the termkey instance to those given by \fInewflags\fP. For detail on the available flags and their meaning, see \fBtermkey_set_canonflags\fP(3).
|
||||||
|
.PP
|
||||||
|
\fBtermkey_get_canonflags\fP() returns the value set by the last call to \fBtermkey_set_canonflags\fP().
|
||||||
|
.SH "RETURN VALUE"
|
||||||
|
\fBtermkey_set_flags\fP() returns no value. \fBtermkey_get_flags\fP() returns the current canonicalisation flags.
|
||||||
|
.SH "SEE ALSO"
|
||||||
|
.BR termkey_new (3),
|
||||||
|
.BR termkey_canonicalise (3)
|
Loading…
Reference in New Issue