#include <string.h>
#include <stdio.h>
#include <termios.h>
#include <unistd.h>

// un espèce de "hexdump -C" mais avec entrées/sorties en direct

int main(int argc, char **argv)
{
	struct termios mode;
	tcgetattr(0,&mode);
	while (argc > 1)
	{
		argc--;

		// désactiver echo
		if (!strcmp(argv[argc],"-e"))
			mode.c_lflag &= ~ECHO;

		// touches disponibles sans attendre nouvelle ligne
		if (!strcmp(argv[argc],"-i"))
			mode.c_lflag &= ~ICANON;
	}
	tcsetattr(0,TCSANOW,&mode);
	setbuf(stdout,NULL);		// affichage printf même sans newline

	printf("taper Ctrl+C pour terminer\n");

	while (1)
	{
		unsigned char c;
		read(0,&c,1);		// lire un octet
		printf(" %02x",c);	// l'afficher en hex
		if (c == 10) printf("\n");
	}
}
