Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Napisz program, po którego uruchomieniu terminal będzie wypisywał wszystkie informacje dużymi literami (niezależnie od ustawienia CapsLock). Efekt ten powinno usuwać ponowne uruchomienie programu.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <termios.h>
- #include <string.h>
- #define BUFFER_SIZE 128
- void restore_settings(struct termios default_settings)
- {
- if(tcsetattr(STDIN_FILENO, TCSANOW, &default_settings) == -1) {
- perror("tcsetattr restore_settings");
- exit(EXIT_FAILURE);
- }
- }
- void set_terminal_attr()
- {
- struct termios attr;
- if(tcgetattr(STDIN_FILENO, &attr) == -1) {
- perror("tcgetattr set_terminal_attr");
- exit(EXIT_FAILURE);
- }
- attr.c_oflag |= OLCUC;
- if(tcsetattr(STDIN_FILENO, TCSANOW, &attr) == -1) {
- perror("tcsetattr set_terminal_attr");
- exit(EXIT_FAILURE);
- }
- }
- int main(void)
- {
- struct termios default_settings;
- const char *write_something = "Napisz cos: ";
- char write_buffer[BUFFER_SIZE];
- if(!isatty(STDIN_FILENO)) {
- perror("isatty");
- return EXIT_FAILURE;
- }
- if(tcgetattr(STDIN_FILENO, &default_settings) == -1) {
- perror("tcgetattr");
- return EXIT_FAILURE;
- }
- write(STDIN_FILENO, write_something, strlen(write_something));
- set_terminal_attr();
- read(STDIN_FILENO, write_buffer, BUFFER_SIZE);
- restore_settings(default_settings);
- return EXIT_SUCCESS;
- }
Add Comment
Please, Sign In to add comment