forked from ahurac/dotfiles
Ajout : programme C inutile mais marrant
This commit is contained in:
parent
74f9066cde
commit
4fa22b2801
1 changed files with 43 additions and 0 deletions
43
src/hackertyper.c
Normal file
43
src/hackertyper.c
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define COMMAND "source-highlight --failsafe -f esc --style-file=esc.style -o STDOUT -i "
|
||||
#define READ "r"
|
||||
#define CHARS_TO_WRITE 10
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc < 2) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
setbuf(stdout, NULL);
|
||||
|
||||
struct termios terminal_settings;
|
||||
char current_char;
|
||||
char *command = malloc(sizeof(char) * (strlen(COMMAND) + strlen(argv[1])));
|
||||
|
||||
tcgetattr(STDIN_FILENO, &terminal_settings);
|
||||
terminal_settings.c_lflag &= ~(ICANON | ECHO);
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &terminal_settings);
|
||||
sprintf(command, "%s%s", COMMAND, argv[1]);
|
||||
|
||||
FILE *command_output_fptr = popen(command, READ);
|
||||
|
||||
free(command);
|
||||
|
||||
while (!feof(command_output_fptr)) {
|
||||
getchar();
|
||||
|
||||
for (unsigned int i = 0; i < CHARS_TO_WRITE; i++) {
|
||||
current_char = fgetc(command_output_fptr);
|
||||
printf("%c", current_char);
|
||||
}
|
||||
}
|
||||
|
||||
pclose(command_output_fptr);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Reference in a new issue