mirror of
https://github.com/tio/tio.git
synced 2026-05-01 23:07:58 +02:00
Function names cleanup
This commit is contained in:
parent
0a1ed5e7bd
commit
1f45b8d91d
4 changed files with 58 additions and 58 deletions
|
|
@ -29,9 +29,9 @@
|
||||||
#define KEY_T 0x74
|
#define KEY_T 0x74
|
||||||
#define KEY_CTRL_T 0x14
|
#define KEY_CTRL_T 0x14
|
||||||
|
|
||||||
void configure_stdout(void);
|
void stdout_configure(void);
|
||||||
void restore_stdout(void);
|
void stdout_restore(void);
|
||||||
int connect_tty(void);
|
int tty_connect(void);
|
||||||
void wait_for_tty_device(void);
|
void tty_wait_for_device(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ int main(int argc, char *argv[])
|
||||||
parse_options(argc, argv);
|
parse_options(argc, argv);
|
||||||
|
|
||||||
/* Configure output terminal */
|
/* Configure output terminal */
|
||||||
configure_stdout();
|
stdout_configure();
|
||||||
|
|
||||||
/* Install log exit handler */
|
/* Install log exit handler */
|
||||||
atexit(&log_exit);
|
atexit(&log_exit);
|
||||||
|
|
@ -51,14 +51,14 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
/* Connect to tty device */
|
/* Connect to tty device */
|
||||||
if (option.no_autoconnect)
|
if (option.no_autoconnect)
|
||||||
status = connect_tty();
|
status = tty_connect();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Enter connect loop */
|
/* Enter connect loop */
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
wait_for_tty_device();
|
tty_wait_for_device();
|
||||||
status = connect_tty();
|
status = tty_connect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ struct option_t option =
|
||||||
"none" // Parity
|
"none" // Parity
|
||||||
};
|
};
|
||||||
|
|
||||||
void print_options_help(char *argv[])
|
void print_help(char *argv[])
|
||||||
{
|
{
|
||||||
printf("Usage: %s [<options>] <tty device>\n", argv[0]);
|
printf("Usage: %s [<options>] <tty device>\n", argv[0]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
@ -74,7 +74,7 @@ void parse_options(int argc, char *argv[])
|
||||||
|
|
||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
{
|
{
|
||||||
print_options_help(argv);
|
print_help(argv);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -336,7 +336,7 @@ void parse_options(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
print_options_help(argv);
|
print_help(argv);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
||||||
94
src/tty.c
94
src/tty.c
|
|
@ -114,7 +114,47 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wait_for_tty_device(void)
|
void stdout_configure(void)
|
||||||
|
{
|
||||||
|
/* Save current stdout settings */
|
||||||
|
if (tcgetattr(STDOUT_FILENO, &old_stdout) < 0)
|
||||||
|
{
|
||||||
|
error_printf("Saving current stdio settings failed");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Prepare new stdout settings */
|
||||||
|
bzero(&new_stdout, sizeof(new_stdout));
|
||||||
|
|
||||||
|
/* Control, input, output, local modes for stdout */
|
||||||
|
new_stdout.c_cflag = 0;
|
||||||
|
new_stdout.c_iflag = 0;
|
||||||
|
new_stdout.c_oflag = 0;
|
||||||
|
new_stdout.c_lflag = 0;
|
||||||
|
|
||||||
|
/* Control characters */
|
||||||
|
new_stdout.c_cc[VTIME] = 0; /* Inter-character timer unused */
|
||||||
|
new_stdout.c_cc[VMIN] = 1; /* Blocking read until 1 character received */
|
||||||
|
|
||||||
|
/* Activate new stdout settings */
|
||||||
|
tcsetattr(STDOUT_FILENO, TCSANOW, &new_stdout);
|
||||||
|
tcsetattr(STDOUT_FILENO, TCSAFLUSH, &new_stdout);
|
||||||
|
|
||||||
|
/* Print launch hints */
|
||||||
|
tio_printf("tio v%s", VERSION);
|
||||||
|
tio_printf("Press ctrl-t + q to quit");
|
||||||
|
|
||||||
|
/* Make sure we restore old stdout settings on exit */
|
||||||
|
atexit(&stdout_restore);
|
||||||
|
}
|
||||||
|
|
||||||
|
void stdout_restore(void)
|
||||||
|
{
|
||||||
|
tcsetattr(STDOUT_FILENO, TCSANOW, &old_stdout);
|
||||||
|
tcsetattr(STDOUT_FILENO, TCSAFLUSH, &old_stdout);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tty_wait_for_device(void)
|
||||||
{
|
{
|
||||||
fd_set rdfs;
|
fd_set rdfs;
|
||||||
int status;
|
int status;
|
||||||
|
|
@ -172,47 +212,7 @@ void wait_for_tty_device(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void configure_stdout(void)
|
void tty_disconnect(void)
|
||||||
{
|
|
||||||
/* Save current stdout settings */
|
|
||||||
if (tcgetattr(STDOUT_FILENO, &old_stdout) < 0)
|
|
||||||
{
|
|
||||||
error_printf("Saving current stdio settings failed");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Prepare new stdout settings */
|
|
||||||
bzero(&new_stdout, sizeof(new_stdout));
|
|
||||||
|
|
||||||
/* Control, input, output, local modes for stdout */
|
|
||||||
new_stdout.c_cflag = 0;
|
|
||||||
new_stdout.c_iflag = 0;
|
|
||||||
new_stdout.c_oflag = 0;
|
|
||||||
new_stdout.c_lflag = 0;
|
|
||||||
|
|
||||||
/* Control characters */
|
|
||||||
new_stdout.c_cc[VTIME] = 0; /* Inter-character timer unused */
|
|
||||||
new_stdout.c_cc[VMIN] = 1; /* Blocking read until 1 character received */
|
|
||||||
|
|
||||||
/* Activate new stdout settings */
|
|
||||||
tcsetattr(STDOUT_FILENO, TCSANOW, &new_stdout);
|
|
||||||
tcsetattr(STDOUT_FILENO, TCSAFLUSH, &new_stdout);
|
|
||||||
|
|
||||||
/* Print launch hints */
|
|
||||||
tio_printf("tio v%s", VERSION);
|
|
||||||
tio_printf("Press ctrl-t + q to quit");
|
|
||||||
|
|
||||||
/* Make sure we restore old stdout settings on exit */
|
|
||||||
atexit(&restore_stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
void restore_stdout(void)
|
|
||||||
{
|
|
||||||
tcsetattr(STDOUT_FILENO, TCSANOW, &old_stdout);
|
|
||||||
tcsetattr(STDOUT_FILENO, TCSAFLUSH, &old_stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
void disconnect_tty(void)
|
|
||||||
{
|
{
|
||||||
if (connected)
|
if (connected)
|
||||||
{
|
{
|
||||||
|
|
@ -223,16 +223,16 @@ void disconnect_tty(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void restore_tty(void)
|
void tty_restore(void)
|
||||||
{
|
{
|
||||||
tcsetattr(fd, TCSANOW, &old_tio);
|
tcsetattr(fd, TCSANOW, &old_tio);
|
||||||
tcsetattr(fd, TCSAFLUSH, &old_tio);
|
tcsetattr(fd, TCSAFLUSH, &old_tio);
|
||||||
|
|
||||||
if (connected)
|
if (connected)
|
||||||
disconnect_tty();
|
tty_disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
int connect_tty(void)
|
int tty_connect(void)
|
||||||
{
|
{
|
||||||
fd_set rdfs; /* Read file descriptor set */
|
fd_set rdfs; /* Read file descriptor set */
|
||||||
int maxfd; /* Maximum file descriptor used */
|
int maxfd; /* Maximum file descriptor used */
|
||||||
|
|
@ -279,7 +279,7 @@ int connect_tty(void)
|
||||||
/* Make sure we restore tty settings on exit */
|
/* Make sure we restore tty settings on exit */
|
||||||
if (first)
|
if (first)
|
||||||
{
|
{
|
||||||
atexit(&restore_tty);
|
atexit(&tty_restore);
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -384,7 +384,7 @@ int connect_tty(void)
|
||||||
error_tcgetattr:
|
error_tcgetattr:
|
||||||
error_isatty:
|
error_isatty:
|
||||||
error_read:
|
error_read:
|
||||||
disconnect_tty();
|
tty_disconnect();
|
||||||
error_open:
|
error_open:
|
||||||
return TIO_ERROR;
|
return TIO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue