#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <termios.h>
#include <assert.h>
#include <string.h>

struct {
	int index;
	char tab[1024];
} buf = {0};

struct termios term, previous; // the previous state has to be restored... if not the term stay in that mode

void handler(int sig){
	switch (sig) {
		case SIGALRM:
			for (int i = 0; i < buf.index; ++i) {
				if(!buf.tab[i])
					continue;
				printf("%c", buf.tab[i] + 'A' - 'a');
			}
			alarm(5);
			break;
		default:
			tcsetattr(STDIN_FILENO, TCSANOW, &previous);
			raise(sig);
			assert(1);
			break;
	}
}

int main(int argc, char *argv[])
{
	signal(SIGALRM, handler);
	signal(SIGINT, handler);

	tcgetattr(STDIN_FILENO, &previous);
    memcpy(&term, &previous, sizeof(struct termios));
	term.c_lflag &= ~ICANON;
	tcsetattr(STDIN_FILENO, TCSANOW, &term);

	alarm(5);
	
	while(1){
		buf.tab[buf.index++] = getchar();
	}
	assert(1);
}
