#include #include #include #include #include #include #include #include #include #include #include "eterm.h" #include "init.h" #include "inout.h" #include "file.h" #include "misc.h" #include "yapp.h" #include "help.h" #define TAB 9 #define ESC 27 #define SEVENPL_START 0 #define SEVENPL_STOP 1 #define SEVENPL_FALSE 2 unsigned char pc2latin[128] = { 199, 252, 233, 226, 228, 224, 229, 231, 234, 235, 232, 239, 238, 236, 196, 197, 201, 230, 198, 244, 246, 242, 251, 249, 255, 214, 220, 162, 163, 165, 0, 0, 225, 237, 243, 250, 241, 209, 170, 186, 191, 0, 172, 189, 188, 161, 171, 187, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 223, 0, 0, 0, 0, 181, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 177, 0, 0, 0, 0, 247, 0, 176, 0, 183, 0, 0, 178, 0, 160 }; unsigned char latin2pc[128] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 173, 155, 156, 254, 157, 124, 21, 254, 254, 166, 174, 170, 45, 254, 254, 248, 241, 253, 254, 254, 230, 20, 249, 254, 254, 167, 175, 172, 171, 254, 168, 254, 254, 254, 254, 142, 143, 146, 128, 254, 144, 254, 254, 254, 254, 254, 254, 254, 165, 254, 254, 254, 254, 153, 254, 232, 254, 254, 254, 154, 254, 254, 225, 133, 160, 131, 254, 132, 134, 145, 135, 138, 130, 136, 137, 141, 161, 140, 139, 254, 164, 149, 162, 147, 254, 148, 246, 237, 151, 163, 150, 129, 254, 254, 152 }; static FILE *capf; unsigned char caps[256], *caps_p; static int sevenpl = SEVENPL_FALSE; void conv_caps(void) { int i, c; for (i = 0; i < strlen(caps); i++) { c = caps[i]; if (c >= 128) { c = pc2latin[c - 128]; if (c == 0) c = '.'; caps[i] = c; } } } void read_console(void) { static int tilde = FALSE, ndx = 1; static unsigned char send_fname[82] = "", cap_fname[82] = "eterm.cap"; static unsigned char yapp_fname[82] = ""; int i, n, mode; unsigned char *p = NULL; unsigned char buf[512], tmp[82]; n = read(STDIN_FILENO, buf, 511); if (buf[0] == '~') { putchar(buf[0]); tilde = TRUE; if (n == 1) { ndx = 0; return; } else ndx = 1; } if (tilde) { tilde = FALSE; putchar(buf[ndx]); switch(buf[ndx]) { case 'c': if(! cap) { printf("\n* Error: no capture file open\n"); return; } if (caps_p != caps) fprintf(capf, "%s\n", caps); fclose(capf); cap = FALSE; sevenpl = SEVENPL_FALSE; printf("\n"); return; case 'd': printf("\n"); send_daytime(); return; case 'h': show_help(); return; case 'i': printf("\n"); init_tnc_parms(); return; case 'o': if (ndx) { buf[n - 1] = 0; p = &buf[ndx + 1]; printf("%s\n", p); } else { printf("\n"); p = rl_gets("File to capture to: ", cap_fname); } if (cap) { printf("\n* Error: capture file already open\n"); return; } while (isspace(*p)) p++; strcpy(cap_fname, p); if (! strlen(cap_fname)) return; capf = fopen(cap_fname, "a"); memset(caps, 0, 256); caps_p = caps; cap = TRUE; return; case 'q': printf("\n"); quit(0); case 'u': if (ndx) { buf[n - 1] = 0; p = &buf[ndx + 1]; printf("%s\n", p); } else { printf("\n"); p = rl_gets("File to upload: ", send_fname); } while (isspace(*p)) p++; strcpy(send_fname, p); send_file(send_fname); return; case 'y': if (ndx) mode = buf[ndx + 1]; else mode = getchar(); putchar(mode); if ((mode != 'u') && (mode != 'd')) { printf("\n* Error: unknown '~y' escape\n"); return; } if (ndx) { buf[n - 1] = 0; p = &buf[ndx + 2]; printf("%s\n", p); } else { printf("\n"); sprintf(tmp, "YAPP %s filename: ", (mode == 'u') ? "upload" : "download"); p = rl_gets(tmp, yapp_fname); } while (isspace(*p)) p++; strcpy(yapp_fname, p); if ((mode == 'u') && (! strlen(yapp_fname))) { printf("* Error: YAPP upload requires a filename\n"); return; } yapp(mode, yapp_fname); return; default: printf("\n* Error: unknown '~' escape\n"); return; } } for (i = 0; i < n; i++) { if (chk_incoming(tnc)) read_tnc(1); write_tnc(buf[i]); usleep(5000); } } int chk_incoming(int fd) { fd_set io_set; struct timeval timeout; FD_ZERO(&io_set); FD_SET(fd, &io_set); timeout.tv_sec = 0; timeout.tv_usec = 0; return select(fd + 1, &io_set, NULL, NULL, &timeout); } void send_string(unsigned char *s, int lfeed) { int i; for (i = 0; i < strlen(s); i++) { if (chk_incoming(tnc)) read_tnc(1); write_tnc(s[i]); usleep(5000); } if (lfeed) { if (chk_incoming(tnc)) read_tnc(1); write_tnc(10); } } void write_tnc(unsigned char c) { switch(c) { case 10: c = 13; break; case 127: c = 8; break; } if (c >= 128) { c = latin2pc[c - 128]; if (c == 0) c = ' '; } write(tnc, &c, 1); } void read_tnc(int echo) { static unsigned char buf[512]; unsigned char c; int i, n; while ((n = read(tnc, buf, 511)) > 0) { for (i = 0; i < n; i++) { c = buf[i]; if (cap) { *(caps_p++) = c; if (c == 10) { if (! strncmp(caps, " go_7+", 6)) sevenpl = SEVENPL_START; else if (! strncmp(caps, " stop_7+", 8)) sevenpl = SEVENPL_STOP; switch(sevenpl) { case SEVENPL_START: break; case SEVENPL_STOP: sevenpl = SEVENPL_FALSE; break; case SEVENPL_FALSE: conv_caps(); } fprintf(capf, "%s", caps); memset(caps, 0, 256); caps_p = caps; } } if (c < 0x20) { switch(c) { case 8: case 9: case 10: case 13: break; default: c = '.'; } } if (c >= 128) { c = pc2latin[c - 128]; if (c == 0) c = '.'; } if ((c == 127) || (c == 128+27)) c = '.'; if (echo) putchar(c); } } } .