writevt: new aport
This commit is contained in:
parent
1e3ffe04ed
commit
ada06c0cfe
2 changed files with 86 additions and 0 deletions
24
writevt/APKBUILD
Normal file
24
writevt/APKBUILD
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Contributor: Patrycja Rosa <alpine@ptrcnull.me>
|
||||
# Maintainer: Patrycja Rosa <alpine@ptrcnull.me>
|
||||
pkgname=writevt
|
||||
pkgver=1
|
||||
pkgrel=0
|
||||
pkgdesc="simulate input to terminal"
|
||||
url="https://github.com/grawity/code/blob/master/thirdparty/writevt.c"
|
||||
arch="all"
|
||||
license="i have no idea"
|
||||
source="writevt.c"
|
||||
builddir="$srcdir"
|
||||
options="!check"
|
||||
|
||||
build() {
|
||||
gcc -O2 -o writevt writevt.c
|
||||
}
|
||||
|
||||
package() {
|
||||
install -Dm755 writevt -t "$pkgdir"/usr/bin
|
||||
}
|
||||
|
||||
sha512sums="
|
||||
7e73d09a8148f6e69555162f75ea9d63fffc68a5c561f88d0cb81442e6318366ac1ea34632cbd7806c049d6f5b34edbf81e3c8b9ce9d2b559bbe3285ce321481 writevt.c
|
||||
"
|
62
writevt/writevt.c
Normal file
62
writevt/writevt.c
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Mostly ripped off of console-tools' writevt.c
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
char *progname;
|
||||
|
||||
static int usage() {
|
||||
printf("Usage: %s ttydev text\n", progname);
|
||||
return 2;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int fd, argi;
|
||||
char *term = NULL;
|
||||
char *text = NULL;
|
||||
|
||||
progname = argv[0];
|
||||
|
||||
argi = 1;
|
||||
|
||||
if (argi < argc)
|
||||
term = argv[argi++];
|
||||
else {
|
||||
fprintf(stderr, "%s: no tty specified\n", progname);
|
||||
return usage();
|
||||
}
|
||||
|
||||
if (argi < argc)
|
||||
text = argv[argi++];
|
||||
else {
|
||||
fprintf(stderr, "%s: no text specified\n", progname);
|
||||
return usage();
|
||||
}
|
||||
|
||||
if (argi != argc) {
|
||||
fprintf(stderr, "%s: too many arguments\n", progname);
|
||||
return usage();
|
||||
}
|
||||
|
||||
fd = open(term, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
perror(term);
|
||||
fprintf(stderr, "%s: could not open tty\n", progname);
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (*text) {
|
||||
if (ioctl(fd, TIOCSTI, text)) {
|
||||
perror("ioctl");
|
||||
return 1;
|
||||
}
|
||||
text++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue