walloftext/tprint/tprint.c
2015-06-19 02:58:58 +02:00

43 lines
818 B
C

/***
* 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;
}