/*** * Small program to output stdin or a file one character a time, like it would be typed * Author: madmaurice * License: GPL */ #include #include #include #include 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 if(strcmp(*argv,"-h") == 0) { printf("usage: tprint [-h] [-s speed] [filename]\n"); printf("\t-h: Print this help.\n"); printf("\t-s speed: speed in characters per second (default: 3)\n"); exit(0); } else if(**argv == '-' && strlen(*argv) > 1) { printf("Unkown option %s\n",*argv); exit(1); } else { if(strcmp(*argv,"-")==0) { fh = stdin; } else { fh = fopen(*argv,"r"); if(fh == NULL) { printf("Unable to open %s\n", *argv); exit(2); } } } } while((c = fgetc(fh)) != EOF) { fputc(c,stdout); fflush(stdout); usleep(speed * 1000000); } return 0; }