1 /* strobe.c (<~Harvie 2oo9)
2 * Dream Machine implementation for GNU/Linux
3 * usage ./strobe [frequency]
11 void signal_handler(int signo
) {
12 if(signo
== SIGTERM
|| signo
== SIGINT
|| signo
== SIGQUIT
) {
13 fputs("\033[0m" "\033[2J" "\033[0;0H", stdout
); fflush(stdout
); //restore default terminal settings
18 int main(int argc
, char *argv
[]) {
20 char bg_black
[] = "\033[40m\033[1;37m"; //set black background
21 char bg_white
[] = "\033[47m\033[1;30m"; //set white background
22 char cls
[] = "\033[2J" "\033[0;0H"; //clear screen and return to begining of it
23 char format_str
[] = "%s%s" //"\033[40m\033[1;37m"
24 "Warning: this software can cause seizures. Use it on your own risk only! Don't forget to close your eyes! Running at %g Hz (Press ^C to exit)";
25 double frequency
= 10; //Hz
30 frequency
= strtod(argv
[1], NULL
); //get frequency from argv[1] (if present)
31 cache_size
+= sizeof(argv
[1]);
33 useconds_t half_interval
= (1000000/frequency
)/2; //uSeconds
35 //Pre-cache output strings
36 cache_size
+= sizeof(bg_black
) + sizeof(cls
) + sizeof(format_str
) + 5;
37 char state_a
[cache_size
];
38 char state_b
[cache_size
];
40 sprintf(state_a
, format_str
, bg_black
, cls
, frequency
);
41 sprintf(state_b
, format_str
, bg_white
, cls
, frequency
);
44 signal(SIGINT
, signal_handler
); signal(SIGTERM
, signal_handler
); signal(SIGQUIT
, signal_handler
);
48 fputs(state_a
, stdout
);
50 usleep(half_interval
);
51 fputs(state_b
, stdout
);
53 usleep(half_interval
);
This page took 0.281526 seconds and 4 git commands to generate.