Skip to content

Instantly share code, notes, and snippets.

@kirelagin
Created March 17, 2012 16:34
Show Gist options
  • Save kirelagin/2061898 to your computer and use it in GitHub Desktop.
Save kirelagin/2061898 to your computer and use it in GitHub Desktop.
Flusher for myreverse testing
/***
* 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