3 * Copyright (C) 2001 Yan "Warrior" Gurtovoy (ymg@azstarnet.com)
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #include <sys/types.h>
33 #ifdef HAVE_SYS_TIMEB_H
34 #include <sys/timeb.h>
41 #define OPTSTR "bnhtp:l:s:" /* list of short options for getopt_long() */
42 #define PORT_OUT "\nHost --> "
43 #define PORT_IN "\nDevice --> "
44 #define DEFPTRNAME "/dev/pty??"
45 #define TOTALBYTES "Total bytes transmitted:"
46 #define MEMFAIL "Memory allocation failed"
47 #define PTYFAIL "Failed to open a pty"
48 #define PORTFAIL "Failed to open port"
49 #define LOGFAIL "Failed to open log file, defaulting to stdout"
50 #define SELFAIL "`Select` failed"
51 #define RPORTFAIL "Error reading from port"
52 #define RPTYFAIL "Error reading from pty"
53 #define CLOSEFAIL "Failed to close file - data loss may occur"
54 #define RAWFAIL "Failed to switch into raw mode"
55 #define SYNCFAIL "Failed to syncronize ttys"
56 #define PIPEFAIL "Failed to create pipe"
57 #define FORKFAIL "Failed to create child process"
58 #define RPIPEFAIL "Error reading from pipe"
60 #define max(x,y) ((x) > (y) ? (x) : (y))
64 #define DEFBAUDRATE B9600
66 #define PORTNAMELEN 11
68 static tty_struct tty_data;
69 static pid_t pid = -1;
72 typedef struct _spd_struct {
77 static spd_struct baudrates[] = {
78 {B50, "50"}, {B75, "75"}, {B110, "110"},
79 {B134, "134"}, {B150, "150"}, {B200, "200"},
80 {B300, "300"}, {B600, "600"}, {B1200, "1200"},
81 {B1800, "1800"}, {B2400, "2400"}, {B4800, "4800"},
82 {B9600, "9600"}, {B19200, "19200"}, {B38400, "38400"},
83 {B57600, "57600"}, {B115200, "115200"}, {0, NULL}
86 static clr_struct colors[] = {
87 {"black", "\033[0;30m"},
88 {"red", "\033[0;31m"},
89 {"green", "\033[0;32m"},
90 {"yellow", "\033[0;33m"},
91 {"blue", "\033[0;34m"},
92 {"magenta", "\033[0;35m"},
93 {"cyan", "\033[0;36m"},
94 {"white", "\033[0;37m"},
95 {"brightblack", "\033[1;30m"},
96 {"brightred", "\033[1;31m"},
97 {"brightgreen", "\033[1;32m"},
98 {"brightyellow", "\033[1;33m"},
99 {"brightblue", "\033[1;34m"},
100 {"brightmagenta", "\033[1;35m"},
101 {"brightcyan", "\033[1;36m"},
102 {"brightwhite", "\033[1;37m"},
106 /* function prototypes */
107 pid_t dev_getlock(char *dev);
108 pid_t dev_setlock(char *dev);
109 int dev_unlock(char *dev);
110 void readRC(tty_struct *ptr);