ktrans: use stdio by default

The kbdtap is now given as the first argument instead.
The use of stdio allows for multiple taps to be chained
together in something like:

; </dev/kbdtap ktrans | progB | progC >/dev/kbdtap
This commit is contained in:
Jacob Moody 2022-08-17 14:20:56 +00:00
parent 3331ccc6a4
commit 7828ffb8a4
2 changed files with 40 additions and 36 deletions

View file

@ -4,39 +4,41 @@ ktrans \- language transliterator
.SH SYNOPSIS
.B ktrans
[
.B -t
.I kbdtap
]
[
.B -l
.I lang
]
[
.I kbdtap
]
.SH DESCRIPTION
.I Ktrans
provides a transliteration layer
to keyboard input through reads and
writes to
.BR /dev/kbdtap .
The
.B -t
flag changes the
transliterates a stream of keyboard
events. Without any arguments,
.I ktrans
reads events from standard input
and writes out converted events to stdout.
If a
.I kbdtap
file used. The
.B -l
flag changes the initial
language.
file is given, it is used for both
input and output instead.
.SH CONVERSION
Conversion is done in two steps: An implicit layer
that is used for direct mappings between ascii characters and
an explicit multi rune conversion used for compound mappings.
Conversion is done in two layers, an implicit
layer for unambigious mappings, and an explicit
layer for selecting one match out of a list of
ambigious matches.
.PP
The implicit layer happens automatically as characters
are input, transforming a consecutive set of key strokes
in to their rune counterpart. A series of these runes can
then be explicitely converted using ctrl-\\. Consecutive
inputs of ctrl-\\ can then be used to cycle through all the
matches. A newline may also be used to perform an explicit
conversion, but will not cycle through other possible matches.
.PP
Input is always passed along, when a match is found
.I Ktrans
does implicit conversion by passing through characters
as they are input. Then when a sequence of input is matched,
backspaces are emitted to clear the input sequence and the matched
rune sequence is emitted. The last 'word' of input may be then
explicitely transliterated by typing ctrl-\\. A newline character also
performs this lookup, but additional newline characters will not
cycle through alternatives.
will emit backspaces to clear the input sequence and replace
it with the matched sequence.
.SH CONTROL
The language is selected by typing a control character:
.TP

View file

@ -581,7 +581,7 @@ kbdsink(void*)
void
usage(void)
{
fprint(2, "usage: %s [ -t tap ] [ -l lang ]\n", argv0);
fprint(2, "usage: %s [ -l lang ] [ kbdtap ]\n", argv0);
threadexits("usage");
}
@ -592,14 +592,9 @@ threadmain(int argc, char *argv[])
{
char *jishoname, *zidianname;
char *tap;
tap = "/dev/kbdtap";
deflang = LangEN;
ARGBEGIN{
case 't':
tap = EARGF(usage());
break;
case 'l':
deflang = parselang(EARGF(usage()));
if(deflang < 0)
@ -608,12 +603,19 @@ threadmain(int argc, char *argv[])
default:
usage();
}ARGEND;
if(argc != 0)
switch(argc){
case 0:
kbdin = 0;
kbdout = 1;
break;
case 1:
kbdin = kbdout = open(argv[0], ORDWR);
if(kbdin < 0)
sysfatal("failed to open kbdtap: %r");
break;
default:
usage();
kbdin = kbdout = open(tap, ORDWR);
if(kbdin < 0 || kbdout < 0)
sysfatal("failed to get keyboard: %r");
}
memset(backspace, '\b', sizeof backspace-1);
backspace[sizeof backspace-1] = '\0';