#define CMSPAR 010000000000
#endif
+#define LINE_SIZE_MAX 1000
+
#define KEY_0 0x30
#define KEY_1 0x31
#define KEY_2 0x32
#define KEY_T 0x74
#define KEY_U 0x55
#define KEY_V 0x76
+#define KEY_X 0x78
+#define KEY_Y 0x79
#define KEY_Z 0x7a
enum line_mode_t
bool map_i_cr_nl = false;
bool map_ign_cr = false;
+char key_hit = 0xff;
+
static struct termios tio, tio_old, stdout_new, stdout_old, stdin_new, stdin_old;
static unsigned long rx_total = 0, tx_total = 0;
static bool connected = false;
static pthread_t thread;
static int pipefd[2];
static pthread_mutex_t mutex_input_ready = PTHREAD_MUTEX_INITIALIZER;
+static char line[LINE_SIZE_MAX];
static void optional_local_echo(char c)
{
byte_count = read(STDIN_FILENO, input_buffer, BUFSIZ);
if (byte_count < 0)
{
+ /* No error actually occurred */
+ if (errno == EINTR)
+ {
+ continue;
+ }
tio_warning_printf("Could not read from stdin (%s)", strerror(errno));
}
else if (byte_count == 0)
// Process quit and flush key command
for (int i = 0; i<byte_count; i++)
{
+ // first do key hit check for xmodem abort
+ if (!key_hit) {
+ key_hit = input_buffer[i];
+ byte_count--;
+ memcpy(input_buffer+i, input_buffer+i+1, byte_count-i);
+ continue;
+ }
+
input_char = input_buffer[i];
if (previous_char == option.prefix_code)
}
// Write all bytes read to pipe
- while (byte_count)
+ while (byte_count > 0)
{
bytes_written = write(pipefd[1], input_buffer, byte_count);
if (bytes_written < 0)
}
}
+static int tio_readln(void)
+{
+ char *p = line;
+
+ /* Read line, accept BS and DEL as rubout characters */
+ for (p = line ; p < &line[LINE_SIZE_MAX-1]; )
+ {
+ if (read(pipefd[0], p, 1) > 0)
+ {
+ if (*p == 0x08 || *p == 0x7f)
+ {
+ if (p > line )
+ {
+ write(STDOUT_FILENO, "\b \b", 3);
+ p--;
+ }
+ continue;
+ }
+ write(STDOUT_FILENO, p, 1);
+ if (*p == '\r') break;
+ p++;
+ }
+ }
+ *p = 0;
+ return (p - line);
+}
+
void handle_command_sequence(char input_char, char *output_char, bool *forward)
{
char unused_char;
tio_printf(" ctrl-%c t Toggle line timestamp mode", option.prefix_key);
tio_printf(" ctrl-%c U Toggle conversion to uppercase on output", option.prefix_key);
tio_printf(" ctrl-%c v Show version", option.prefix_key);
- tio_printf(" ctrl-%c ctrl-%c Send ctrl-%c character", option.prefix_key, option.prefix_key, option.prefix_key);
+ tio_printf(" ctrl-%c x Send file via Xmodem-1K", option.prefix_key);
+ tio_printf(" ctrl-%c y Send file via Ymodem", option.prefix_key);
+ tio_printf(" ctrl-%c ctrl-%c Send ctrl-%c character", option.prefix_key, option.prefix_key, option.prefix_key);
break;
case KEY_SHIFT_L:
tio_printf("tio v%s", VERSION);
break;
+ case KEY_X:
+ case KEY_Y:
+ tio_printf("Send file with %cMODEM", toupper(input_char));
+ tio_printf_raw("Enter file name: ");
+ if (tio_readln()) {
+ tio_printf("Sending file '%s' ", line);
+ tio_printf("Press any key to abort transfer");
+ tio_printf("%s", xymodem_send(fd, line, input_char) < 0 ? "Aborted" : "Done");
+ }
+ break;
+
case KEY_Z:
tio_printf_array(random_array);
break;