Created
March 17, 2012 16:34
-
-
Save kirelagin/2061898 to your computer and use it in GitHub Desktop.
Flusher for myreverse testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** | |
* Flusher by Kirill Elagin <[email protected]> [http://kirelagin.ru/] | |
* | |
* Use it this way: | |
* ./flusher < testfile | ./myreverse | |
* Exclamation marks in input file will flush the buffer. | |
**/ | |
#include <stdio.h> | |
#include <time.h> | |
int main(int argc, char **argv) | |
{ | |
int sleep_milisec = 100; | |
if (argc > 1) { | |
sleep_milisec = atoi(argv[1]); | |
} | |
struct timespec t1, t2; | |
t1.tv_sec = sleep_milisec / 1000; | |
t1.tv_nsec = (sleep_milisec % 1000) * 1000000; | |
int c; | |
while (1) { | |
c = getc(stdin); | |
if (c == EOF) { | |
break; | |
} | |
if (c == '!') { | |
fflush(stdout); | |
nanosleep(&t1, &t2); | |
} else { | |
putc(c, stdout); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment