--- old/mapchan.c Thu Sep 16 17:14:21 1999 +++ mapchan/mapchan.c Thu Oct 26 14:54:23 2000 @@ -39,18 +39,16 @@ /* - mapchan -q -s shell -p pty -f file -h -? + mapchan -q -s shell -f file -h -? */ -char usage[] = { "\nUsage:\n\nmapchan [-q] [-s shell] [-p pty_no] [-f file]\ +char usage[] = { "\nUsage:\n\nmapchan [-q] [-s shell] [-f file]\ [-h]\n\nwhere:\n\ \tshell - shell, if not /bin/sh -\tpty_no - number of pty for mapchan (0-64). Default - 32\n\ \tfile - input file\n\ \t-q - force and quiet \t-h - print this screen and exit.\n" }; -char *tty_name; /* полное имя псевдотерминала */ int pty_fd; /* дескриптор master */ int tty_fd; /* дескриптор slave */ pid_t pid; /* child's PID */ @@ -58,7 +56,6 @@ fd_set readfds; /* select flags */ char *shell_prog; -unsigned int first_pty; int quiet = 0; int fast_quit = 0; @@ -66,68 +63,12 @@ extern int optind, opterr, optopt; extern char *optarg; -#ifdef DEBUG -FILE *console; -#endif - help() { if (!quiet) printf("\r\nmapchan started\r\n"); } /* - * Конструирование имени терминала - */ -char * -pty_name(unsigned int i) -{ - static char buf[3]; - - if (i < 64) { - sprintf(buf, "%c%x", 'p' + (i / 16), i % 16); - return buf; - } else - return NULL; -} - -/* - * Поиск свободного псевдотерминала - */ -int -next_pty() -{ - register int i; - unsigned char buf[20]; - - for (i=first_pty; i < 64; i++) { - sprintf(buf, "/dev/pty%s", pty_name(i)); - pty_fd = open(buf, O_RDWR); - if (pty_fd < 0) { - i++; - continue; - } - sprintf(buf, "/dev/tty%s", pty_name(i)); - tty_fd = open(buf, O_RDWR); - if (tty_fd < 0) { - close(pty_fd); - i++; - continue; - } - break; - } - if (i == 64) return(-1); - else { - tty_name = malloc(strlen(buf) + 1); - strcpy(tty_name, buf); -#ifdef DEBUG - fprintf(stderr, "Using: %s\n", tty_name); -#endif - i++; - return(0); - } -} - -/* * деИнициализация окна */ int @@ -135,7 +76,7 @@ { #ifdef DEBUG - fprintf(stderr, "Close pty\n"); + fprintf(stderr, "Closing pty\n"); #endif kill(pid, SIGHUP); close(tty_fd); @@ -192,13 +133,10 @@ pid = waitpid(WAIT_ANY, &status, WNOHANG); #ifdef DEBUG - fprintf(stderr, "\nChild %d is die with status %d ", pid, status); + fprintf(stderr, "\nChild %d died with status %d \n", pid, status); #endif fast_quit = 1; -#ifdef DEBUG - putchar('\n'); -#endif signal(SIGCHLD, sigchld); } @@ -208,7 +146,7 @@ int i; #ifdef DEBUG -fprintf(console, "HUP signal detected: %d\n", sig); +fprintf(stderr, "HUP signal detected: %d\n", sig); #endif for (i=1; i 64) { - fprintf(stderr, - "First no. of pty is too big. Max = 64\n"); - errflg++; - } - break; case 'f': /* таблица перекодировки */ tbl_file = optarg; break; @@ -581,12 +502,8 @@ signal(SIGCHLD, sigchld); for (i=1; i