diff options
author | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2011-08-28 17:50:18 +0100 |
---|---|---|
committer | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2011-08-28 17:50:18 +0100 |
commit | 26384996486963bc2f097f44a82a5c07e0dfe69e (patch) | |
tree | 58c7da5748c3a635ff4cb49e419f3153552e6ca6 | |
parent | 713351788373e764fc1c66ae1960b36ea6096b02 (diff) | |
download | termo-26384996486963bc2f097f44a82a5c07e0dfe69e.tar.gz termo-26384996486963bc2f097f44a82a5c07e0dfe69e.tar.xz termo-26384996486963bc2f097f44a82a5c07e0dfe69e.zip |
Move canonicalisation flags into their own bitfield with their own accessor and named constants
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | t/20canon.c | 2 | ||||
-rw-r--r-- | termkey-internal.h | 1 | ||||
-rw-r--r-- | termkey.c | 28 | ||||
-rw-r--r-- | termkey.h.in | 9 | ||||
-rw-r--r-- | termkey_canonicalise.3 | 6 | ||||
-rw-r--r-- | termkey_set_canonflags.3 | 21 |
7 files changed, 61 insertions, 7 deletions
@@ -67,6 +67,7 @@ install-man: 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_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 diff --git a/t/20canon.c b/t/20canon.c index b407f9f..eccf2c6 100644 --- a/t/20canon.c +++ b/t/20canon.c @@ -29,7 +29,7 @@ int main(int argc, char *argv[]) is_str(key.utf8, " ", "key.utf8 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; endp = termkey_strpkey(tk, " ", &key, 0); diff --git a/termkey-internal.h b/termkey-internal.h index 608457b..c1f4cd6 100644 --- a/termkey-internal.h +++ b/termkey-internal.h @@ -33,6 +33,7 @@ struct TermKeyDriverNode { struct _TermKey { int fd; int flags; + int canonflags; unsigned char *buffer; size_t buffstart; // First offset in buffer size_t buffcount; // NUMBER of entires valid in buffer @@ -198,6 +198,10 @@ static TermKey *termkey_new_full(int fd, int flags, size_t buffsize, int waittim tk->fd = fd; tk->flags = flags; + tk->canonflags = 0; + + if(flags & TERMKEY_FLAG_SPACESYMBOL) + tk->canonflags |= TERMKEY_CANON_SPACESYMBOL; tk->buffer = malloc(buffsize); if(!tk->buffer) @@ -373,6 +377,11 @@ int termkey_get_flags(TermKey *tk) void termkey_set_flags(TermKey *tk, int 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) @@ -385,6 +394,21 @@ int termkey_get_waittime(TermKey *tk) 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) { 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) { - 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) { key->type = TERMKEY_TYPE_KEYSYM; key->code.sym = TERMKEY_SYM_SPACE; diff --git a/termkey.h.in b/termkey.h.in index 59a4f02..8c58eea 100644 --- a/termkey.h.in +++ b/termkey.h.in @@ -144,11 +144,15 @@ enum { TERMKEY_FLAG_RAW = 1 << 2, // Input is raw bytes, not 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_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_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); 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); 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); TermKeyResult termkey_getkey(TermKey *tk, TermKeyKey *key); diff --git a/termkey_canonicalise.3 b/termkey_canonicalise.3 index d208251..eda0fdc 100644 --- a/termkey_canonicalise.3 +++ b/termkey_canonicalise.3 @@ -10,15 +10,15 @@ termkey_canonicalise \- canonicalise a key event .sp Link with \fI-ltermkey\fP. .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 The canonicalisation operation is affected by the following flags: .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. .SH "RETURN VALUE" \fBtermkey_canonicalise\fP() returns no value. .SH "SEE ALSO" -.BR termkey_new (3), +.BR termkey_set_canonflags (3), .BR termkey_waitkey (3), .BR termkey_strpkey (3) diff --git a/termkey_set_canonflags.3 b/termkey_set_canonflags.3 new file mode 100644 index 0000000..f5332be --- /dev/null +++ b/termkey_set_canonflags.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) |