Added tprint

This commit is contained in:
madmaurice 2015-06-19 02:58:58 +02:00
parent 73de097471
commit 1f0bd271b9
2 changed files with 51 additions and 0 deletions

9
tprint/Makefile Normal file
View file

@ -0,0 +1,9 @@
PREFIX ?= /usr
tprint: tprint.c
gcc -o tprint tprint.c
install: tprint
install -D -m 755 tprint ${DESTDIR}${PREFIX}/bin/tprint
.PHONY: tprint

42
tprint/tprint.c Normal file
View file

@ -0,0 +1,42 @@
/***
* Small program to output stdin or a file one character a time, like it would be typed
* Author: madmaurice <madmaurice@zom.bi>
* License: GPL
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char** argv) {
//Options
float speed = 0.3;
char* file = NULL;
FILE* fh = stdin;
char c;
int v;
argv++; // Cut first element
for(int i = 1; i < argc; i++, argv++) {
if(strcmp(*argv,"-s") == 0) {
argv++; i++;
v = atoi(*argv);
if(v == 0) v = 1000;
speed = 1.0/v;
} else {
fh = fopen(*argv,"r");
}
}
while((c = fgetc(fh)) != EOF) {
fputc(c,stdout);
fflush(stdout);
usleep(speed * 1000000);
}
return 0;
}