1
0
mirror of https://github.com/UzixLS/picocom.git synced 2025-07-18 23:11:18 +03:00

stripped trailing whitespace

This commit is contained in:
Joe Merten
2016-12-16 10:29:20 +01:00
parent 196d36aa05
commit b601136f56
18 changed files with 225 additions and 225 deletions

View File

@ -52,7 +52,7 @@ Changed paths:
Added support for UUCP-style locks. Lock handling is compiled-in if
the macro UUCP_LOCK_DIR is defined; if it is, it must contain the name
of the lock directory. Locking can be disabled at runtime using the
"--no<l>ock" option.
"--no<l>ock" option.
UUCP-locks support is based on a patch submitted by Julius
P. Malkiewicz <julius@sonartech.com.au>

View File

@ -56,4 +56,4 @@ comments:
- Joe Merten (https://github.com/Joe-Merten) contributed the
--lower-rts and --lower-dtr options, custom baudrate support for
OSX, the --logfile option implementation, and several bug-fixes.
OSX, the --logfile option implementation, and several bug-fixes.

View File

@ -9,7 +9,7 @@ The latest release can be downloaded from:
As its name suggests, *picocom* is a minimal dumb-terminal emulation
program. It is, in principle, very much like minicom, only it's "pico"
instead of "mini"!
instead of "mini"!
It was designed to serve as a simple, manual, modem configuration,
testing, and debugging tool. It has also served (quite well) as a
@ -61,7 +61,7 @@ example:
cp picocom.1 ~/man/man1
Again, this is not strictly necessary. You can run picocom and read
its man-page directly from the source directory.
its man-page directly from the source directory.
If something goes wrong and picocom can't compile cleanly, or if it's
lacking a feature you need, take a look at the included Makefile. It's

2
TODO
View File

@ -1 +1 @@

48
fdio.c
View File

@ -19,7 +19,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
* USA
*/
#include <stdlib.h>
@ -34,7 +34,7 @@
ssize_t
writen_ni(int fd, const void *buff, size_t n)
{
size_t nl;
size_t nl;
ssize_t nw;
const char *p;
@ -48,7 +48,7 @@ writen_ni(int fd, const void *buff, size_t n)
nl -= nw;
p += nw;
}
return n - nl;
}
@ -58,12 +58,12 @@ fd_printf (int fd, const char *format, ...)
char buf[256];
va_list args;
int len;
va_start(args, format);
len = vsnprintf(buf, sizeof(buf), format, args);
buf[sizeof(buf) - 1] = '\0';
va_end(args);
return writen_ni(fd, buf, len);
}
@ -71,30 +71,30 @@ fd_printf (int fd, const char *format, ...)
#ifndef LINENOISE
static int
cput(int fd, char c)
{
return write(fd, &c, 1);
static int
cput(int fd, char c)
{
return write(fd, &c, 1);
}
static int
static int
cdel (int fd)
{
const char del[] = "\b \b";
return write(fd, del, sizeof(del) - 1);
}
static int
static int
xput (int fd, unsigned char c)
{
const char hex[] = "0123456789abcdef";
const char hex[] = "0123456789abcdef";
char b[4];
b[0] = '\\'; b[1] = 'x'; b[2] = hex[c >> 4]; b[3] = hex[c & 0x0f];
return write(fd, b, sizeof(b));
}
static int
static int
xdel (int fd)
{
const char del[] = "\b\b\b\b \b\b\b\b";
@ -107,7 +107,7 @@ fd_readline (int fdi, int fdo, char *b, int bsz)
int r;
unsigned char c;
unsigned char *bp, *bpe;
bp = (unsigned char *)b;
bpe = (unsigned char *)b + bsz - 1;
@ -118,11 +118,11 @@ fd_readline (int fdi, int fdo, char *b, int bsz)
switch (c) {
case '\b':
case '\x7f':
if ( bp > (unsigned char *)b ) {
if ( bp > (unsigned char *)b ) {
bp--;
if ( isprint(*bp) )
if ( isprint(*bp) )
cdel(fdo);
else
else
xdel(fdo);
} else {
cput(fdo, '\x07');
@ -134,17 +134,17 @@ fd_readline (int fdi, int fdo, char *b, int bsz)
goto out;
case '\r':
*bp = '\0';
r = bp - (unsigned char *)b;
r = bp - (unsigned char *)b;
goto out;
default:
if ( bp < bpe ) {
if ( bp < bpe ) {
*bp++ = c;
if ( isprint(c) )
cput(fdo, c);
else
if ( isprint(c) )
cput(fdo, c);
else
xput(fdo, c);
} else {
cput(fdo, '\x07');
} else {
cput(fdo, '\x07');
}
break;
}

2
fdio.h
View File

@ -19,7 +19,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
* USA
*/
#ifndef FDIO_H

View File

@ -17,7 +17,7 @@ So what usually happens is either:
* Large programs with configure scripts disabling line editing if readline is not present in the system, or not supporting it at all since readline is GPL licensed and libedit (the BSD clone) is not as known and available as readline is (Real world example of this problem: Tclsh).
* Smaller programs not using a configure script not supporting line editing at all (A problem we had with Redis-cli for instance).
The result is a pollution of binaries without line editing support.
So I spent more or less two hours doing a reality check resulting in this little library: is it *really* needed for a line editing library to be 20k lines of code? Apparently not, it is possibe to get a very small, zero configuration, trivial to embed library, that solves the problem. Smaller programs will just include this, supporing line editing out of the box. Larger programs may use this little library or just checking with configure if readline/libedit is available and resorting to linenoise if not.

View File

@ -387,7 +387,7 @@ Example:
.IP
.nf
\f[C]
***\ baud:\ 115200\ (9600)\
***\ baud:\ 115200\ (9600)\
\f[]
.fi
.PP

View File

@ -9,7 +9,7 @@ header: User Commands
picocom - minimal dumb-terminal emulation program
# SYNOPSIS
**picocom** [ _options_ ] _device_
# DESCRIPTION
@ -46,7 +46,7 @@ Commands are given to picocom by first keying the *espace character*
which by default is **C-a** (see **[OPTIONS]** below for how to change
it), and then keying one of the function (command) characters shown
here.
*escape character*
: Send the escape character to the serial port and return to
@ -146,7 +146,7 @@ here.
: Send (upload) a file. See **[SENDING AND RECEIVING FILES]**
below.
**C-r**
: Receive (download) a file. See **[SENDING AND RECEIVING FILES]**
@ -174,7 +174,7 @@ Picocom accepts the following command-line options.
one of: **x** for xon/xoff (software) mode, **h** for hardware
flow control (RTS/CTS), **n** for no flow control. (Default:
**n**)
**--parity** | **-y**
: Defines the parity mode to set the serial-port to. Must be one
@ -190,13 +190,13 @@ Picocom accepts the following command-line options.
: Defines the number of stop bits in every character. Must be one
of: **1**, or **2**. (Default: **1**)
**--escape** | **-e**
: Defines the character that will make picocom enter command-mode
(see description above). If **x** is given, then **C-x** will make
picocom enter command mode. (Default: **a**)
**--echo** | **-c**
: Enable local echo. Every character being read from the terminal
@ -213,7 +213,7 @@ Picocom accepts the following command-line options.
connection, or altering the settings. If required, serial port
parameters can then be adjusted at run-time by commands.
(Default: Disabled)
**--noreset** | **-r**
: If given, picocom will not reset the serial port when exiting. It
@ -224,7 +224,7 @@ Picocom accepts the following command-line options.
"Exit"), which never resets the serial port. If **--noreset** is
given then "Quit" and "Exit" behave essentially the
same. (Default: Disabled)
**--nolock** | **-l**
: If given, picocom will _not_ attempt to lock the serial port
@ -236,14 +236,14 @@ Picocom accepts the following command-line options.
is possible that your picocom binary is compiled without support
for locking. In this case the **--nolock** option is accepted, but
has no effect. (Default: Disabled)
**--send-cmd** | **-s**
: Specifies the external program (and any arguments to it) that will
be used for transmitting files. If the argument to **--send-cmd**
is the empty string (''), the send-file command is disabled. See
**[SENDING AND RECEIVING FILES]**. (Default: **sz -vv**)
**--receive-cmd** | **-v**
: Specifies the external program (and any arguments to it) that will
@ -251,19 +251,19 @@ Picocom accepts the following command-line options.
is the empty string (''), the receive-file command is
disabled. See **[SENDING AND RECEIVING FILES]**. (Default: **rz
-vv**)
**--imap**
: Specifies the input character map (i.e. special characters to be
replaced when read from the serial port). See
**[INPUT, OUTPUT, AND ECHO MAPPING]**. (Defaul: Empty)
**--omap**
: Specifies the output character map (i.e. special characters to be
replaced before being written to serial port). See
**[INPUT, OUTPUT, AND ECHO MAPPING]**. (Defaul: Empty)
**--emap**
: Specifies the local-echo character map (i.e. special characters to
@ -302,7 +302,7 @@ Picocom accepts the following command-line options.
features are also shown.
# DISPLAY OF OPTIONS AND PORT SETTINGS
# DISPLAY OF OPTIONS AND PORT SETTINGS
The "show program options" command (**C-v**), as well as the commands
that change program options (**C-b**, **C-u**, **C-d**, **C-f**, etc)
@ -313,7 +313,7 @@ respective option (for whatever reason), then the value of the option
is shown followed by the value of the actual serial-port setting in
parenthesis. Example:
*** baud: 115200 (9600)
*** baud: 115200 (9600)
This means that a baud rate of 115200bps has been selected (from the
command line, or using commands that change the baudrate) but the
@ -343,7 +343,7 @@ programs for this purpose are:
- **sb(1)** - send using the Y-MODEM protocol
- **sz(1)** - send using the Z-MODEM protocol
- **ascii-xfr(1)** - receive or transmit ASCII files
The name of, and the command-line options to, the program to be used
for transmitting files are given by the **--send-cmd**
option. Similarly the program to receive files, and its arguments, are
@ -397,20 +397,20 @@ the terminal (standard output) if local echo is enabled (with
**--emap**). These mapping options take, each, a single argument which
is a comma-separated list of one or more of the following identifiers:
- **crlf** (map CR to LF),
- **crcrlf** (map CR to CR + LF),
- **igncr** (ignore CR),
- **crlf** (map CR to LF),
- **crcrlf** (map CR to CR + LF),
- **igncr** (ignore CR),
- **lfcr** (map LF to CR),
- **lfcrlf** (map LF to CR + LF),
- **ignlf** (ignore LF),
- **bsdel** (map BS to DEL),
- **lfcrlf** (map LF to CR + LF),
- **ignlf** (ignore LF),
- **bsdel** (map BS to DEL),
- **delbs** (map DEL to BS)
For example the command:
picocom --omap crlf,delbs --imap ignlf,bsdel --emap crcrlf ...
will:
will:
- Replace every CR (carriage return, 0x0d) character with LF (line
feed, 0x0a) and every DEL (delete, 0x7f) character with BS

138
picocom.c
View File

@ -20,7 +20,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
* USA
*/
#include <stdlib.h>
@ -88,12 +88,12 @@ const char *flow_str[] = {
#define KEY_TOG_RTS CKEY('g') /* toggle RTS */
#define KEY_BAUD CKEY('b') /* set baudrate */
#define KEY_BAUD_UP CKEY('u') /* increase baudrate (up) */
#define KEY_BAUD_DN CKEY('d') /* decrase baudrate (down) */
#define KEY_FLOW CKEY('f') /* change flowcntrl mode */
#define KEY_PARITY CKEY('y') /* change parity mode */
#define KEY_BITS CKEY('i') /* change number of databits */
#define KEY_STOP CKEY('j') /* change number of stopbits */
#define KEY_LECHO CKEY('c') /* toggle local echo */
#define KEY_BAUD_DN CKEY('d') /* decrase baudrate (down) */
#define KEY_FLOW CKEY('f') /* change flowcntrl mode */
#define KEY_PARITY CKEY('y') /* change parity mode */
#define KEY_BITS CKEY('i') /* change number of databits */
#define KEY_STOP CKEY('j') /* change number of stopbits */
#define KEY_LECHO CKEY('c') /* toggle local echo */
#define KEY_STATUS CKEY('v') /* show program options */
#define KEY_HELP CKEY('h') /* show help (same as [C-k]) */
#define KEY_KEYS CKEY('k') /* show available command keys */
@ -133,7 +133,7 @@ struct map_names_s {
{ "delbs", M_DELBS },
{ "bsdel", M_BSDEL },
/* Sentinel */
{ NULL, 0 }
{ NULL, 0 }
};
int
@ -292,12 +292,12 @@ uucp_lock(void)
fd = open(lockname, O_RDONLY);
if ( fd >= 0 ) {
r = read(fd, buf, sizeof(buf));
r = read(fd, buf, sizeof(buf));
close(fd);
/* if r == 4, lock file is binary (old-style) */
pid = (r == 4) ? *(int *)buf : strtol(buf, NULL, 10);
if ( pid > 0
&& kill((pid_t)pid, 0) < 0
if ( pid > 0
&& kill((pid_t)pid, 0) < 0
&& errno == ESRCH ) {
/* stale lock file */
printf("Removing stale lock: %s\n", lockname);
@ -341,12 +341,12 @@ fatal (const char *format, ...)
term_reset(STO);
term_reset(STI);
va_start(args, format);
len = vsnprintf(buf, sizeof(buf), format, args);
buf[sizeof(buf) - 1] = '\0';
va_end(args);
s = "\r\nFATAL: ";
writen_ni(STO, s, strlen(s));
writen_ni(STO, buf, len);
@ -359,7 +359,7 @@ fatal (const char *format, ...)
#ifdef UUCP_LOCK_DIR
uucp_unlock();
#endif
free(opts.port);
if (opts.log_filename) {
free(opts.log_filename);
@ -382,7 +382,7 @@ read_filename (void)
fd_printf(STO, "\r\n*** file: ");
r = fd_readline(STI, STO, fname, sizeof(fname));
fd_printf(STO, "\r\n");
if ( r < 0 )
if ( r < 0 )
return NULL;
else
return strdup(fname);
@ -412,8 +412,8 @@ read_baud (void)
#else /* LINENOISE defined */
void
file_completion_cb (const char *buf, linenoiseCompletions *lc)
void
file_completion_cb (const char *buf, linenoiseCompletions *lc)
{
DIR *dirp;
struct dirent *dp;
@ -457,14 +457,14 @@ file_completion_cb (const char *buf, linenoiseCompletions *lc)
static char *history_file_path = NULL;
void
void
init_history (void)
{
char *home_directory;
home_directory = getenv("HOME");
if (home_directory) {
history_file_path = malloc(strlen(home_directory) + 2 +
history_file_path = malloc(strlen(home_directory) + 2 +
strlen(HISTFILE));
strcpy(history_file_path, home_directory);
if (home_directory[strlen(home_directory)-1] != '/') {
@ -475,14 +475,14 @@ init_history (void)
}
}
void
void
cleanup_history (void)
{
if (history_file_path)
free(history_file_path);
}
void
void
add_history (char *fname)
{
linenoiseHistoryAdd(fname);
@ -592,16 +592,16 @@ do_map (char *b, int map, char c)
return n;
}
void
void
map_and_write (int fd, int map, char c)
{
char b[M_MAXMAP];
int n;
n = do_map(b, map, c);
if ( n )
if ( writen_ni(fd, b, n) < n )
fatal("write to stdout failed: %s", strerror(errno));
fatal("write to stdout failed: %s", strerror(errno));
}
/**********************************************************************/
@ -683,7 +683,7 @@ stopbits_next (int bits)
}
void
show_status (int dtr_up, int rts_up)
show_status (int dtr_up, int rts_up)
{
int baud, bits, stopbits, mctl;
enum flowcntrl_e flow;
@ -696,22 +696,22 @@ show_status (int dtr_up, int rts_up)
parity = term_get_parity(tty_fd);
bits = term_get_databits(tty_fd);
stopbits = term_get_stopbits(tty_fd);
fd_printf(STO, "\r\n");
if ( baud != opts.baud ) {
fd_printf(STO, "*** baud: %d (%d)\r\n", opts.baud, baud);
} else {
} else {
fd_printf(STO, "*** baud: %d\r\n", opts.baud);
}
if ( flow != opts.flow ) {
fd_printf(STO, "*** flow: %s (%s)\r\n",
fd_printf(STO, "*** flow: %s (%s)\r\n",
flow_str[opts.flow], flow_str[flow]);
} else {
fd_printf(STO, "*** flow: %s\r\n", flow_str[opts.flow]);
}
if ( parity != opts.parity ) {
fd_printf(STO, "*** parity: %s (%s)\r\n",
fd_printf(STO, "*** parity: %s (%s)\r\n",
parity_str[opts.parity], parity_str[parity]);
} else {
fd_printf(STO, "*** parity: %s\r\n", parity_str[opts.parity]);
@ -732,13 +732,13 @@ show_status (int dtr_up, int rts_up)
if ( ((mctl & MCTL_DTR) ? 1 : 0) == dtr_up )
fd_printf(STO, "*** dtr: %s\r\n", dtr_up ? "up" : "down");
else
fd_printf(STO, "*** dtr: %s (%s)\r\n",
fd_printf(STO, "*** dtr: %s (%s)\r\n",
dtr_up ? "up" : "down",
(mctl & MCTL_DTR) ? "up" : "down");
if ( ((mctl & MCTL_RTS) ? 1 : 0) == rts_up )
fd_printf(STO, "*** rts: %s\r\n", rts_up ? "up" : "down");
else
fd_printf(STO, "*** rts: %s (%s)\r\n",
fd_printf(STO, "*** rts: %s (%s)\r\n",
rts_up ? "up" : "down",
(mctl & MCTL_RTS) ? "up" : "down");
fd_printf(STO, "*** mctl: ");
@ -763,13 +763,13 @@ show_keys()
fd_printf(STO, "*** Picocom commands (all prefixed by [C-%c])\r\n",
KEYC(opts.escape));
fd_printf(STO, "\r\n");
fd_printf(STO, "*** [C-%c] : Exit picocom\r\n",
fd_printf(STO, "*** [C-%c] : Exit picocom\r\n",
KEYC(KEY_EXIT));
fd_printf(STO, "*** [C-%c] : Exit without reseting serial port\r\n",
fd_printf(STO, "*** [C-%c] : Exit without reseting serial port\r\n",
KEYC(KEY_QUIT));
fd_printf(STO, "*** [C-%c] : Set baudrate\r\n",
fd_printf(STO, "*** [C-%c] : Set baudrate\r\n",
KEYC(KEY_BAUD));
fd_printf(STO, "*** [C-%c] : Increase baudrate (baud-up)\r\n",
fd_printf(STO, "*** [C-%c] : Increase baudrate (baud-up)\r\n",
KEYC(KEY_BAUD_UP));
fd_printf(STO, "*** [C-%c] : Decrease baudrate (baud-down)\r\n",
KEYC(KEY_BAUD_DN));;
@ -819,7 +819,7 @@ establish_child_signal_handlers (void)
dfl_action.sa_handler = SIG_DFL;
sigemptyset (&dfl_action.sa_mask);
dfl_action.sa_flags = 0;
sigaction (SIGINT, &dfl_action, NULL);
sigaction (SIGTERM, &dfl_action, NULL);
}
@ -853,12 +853,12 @@ run_cmd(int fd, const char *cmd, const char *args_extra)
/* reset terminal (back to raw mode) */
term_apply(STI, 0);
/* check and report child return status */
if ( WIFEXITED(status) ) {
fd_printf(STO, "\r\n*** exit status: %d ***\r\n",
if ( WIFEXITED(status) ) {
fd_printf(STO, "\r\n*** exit status: %d ***\r\n",
WEXITSTATUS(status));
return WEXITSTATUS(status);
} else if ( WIFSIGNALED(status) ) {
fd_printf(STO, "\r\n*** killed by signal: %d ***\r\n",
fd_printf(STO, "\r\n*** killed by signal: %d ***\r\n",
WTERMSIG(status));
return -1;
} else {
@ -871,13 +871,13 @@ run_cmd(int fd, const char *cmd, const char *args_extra)
int argc;
char *argv[RUNCMD_ARGS_MAX + 1];
int r;
/* unmanage terminal, and reset it to canonical mode */
term_remove(STI);
/* unmanage serial port fd, without reset */
term_erase(fd);
/* set serial port fd to blocking mode */
fl = fcntl(fd, F_GETFL);
fl = fcntl(fd, F_GETFL);
fl &= ~O_NONBLOCK;
fcntl(fd, F_SETFL, fl);
/* connect stdin and stdout to serial port */
@ -885,7 +885,7 @@ run_cmd(int fd, const char *cmd, const char *args_extra)
close(STO);
dup2(fd, STI);
dup2(fd, STO);
/* build command arguments vector */
argc = 0;
r = split_quoted(cmd, &argc, argv, RUNCMD_ARGS_MAX);
@ -901,9 +901,9 @@ run_cmd(int fd, const char *cmd, const char *args_extra)
if ( argc < 1 ) {
fd_printf(STDERR_FILENO, "No command given\n");
exit(RUNCMD_EXEC_FAIL);
}
}
argv[argc] = NULL;
/* run extenral command */
fd_printf(STDERR_FILENO, "$ %s %s\n", cmd, args_extra);
establish_child_signal_handlers();
@ -956,7 +956,7 @@ do_command (unsigned char c)
else
r = term_raise_dtr(tty_fd);
if ( r >= 0 ) dtr_up = ! dtr_up;
fd_printf(STO, "\r\n*** DTR: %s ***\r\n",
fd_printf(STO, "\r\n*** DTR: %s ***\r\n",
dtr_up ? "up" : "down");
break;
case KEY_TOG_RTS:
@ -965,7 +965,7 @@ do_command (unsigned char c)
else
r = term_raise_rts(tty_fd);
if ( r >= 0 ) rts_up = ! rts_up;
fd_printf(STO, "\r\n*** RTS: %s ***\r\n",
fd_printf(STO, "\r\n*** RTS: %s ***\r\n",
rts_up ? "up" : "down");
break;
case KEY_BAUD:
@ -988,7 +988,7 @@ do_command (unsigned char c)
term_apply(tty_fd, 1);
newbaud = term_get_baudrate(tty_fd, NULL);
if ( opts.baud != newbaud ) {
fd_printf(STO, "\r\n*** baud: %d (%d) ***\r\n",
fd_printf(STO, "\r\n*** baud: %d (%d) ***\r\n",
opts.baud, newbaud);
} else {
fd_printf(STO, "\r\n*** baud: %d ***\r\n", opts.baud);
@ -1002,10 +1002,10 @@ do_command (unsigned char c)
term_apply(tty_fd, 1);
newflow = term_get_flowcntrl(tty_fd);
if ( opts.flow != newflow ) {
fd_printf(STO, "\r\n*** flow: %s (%s) ***\r\n",
fd_printf(STO, "\r\n*** flow: %s (%s) ***\r\n",
flow_str[opts.flow], flow_str[newflow]);
} else {
fd_printf(STO, "\r\n*** flow: %s ***\r\n",
fd_printf(STO, "\r\n*** flow: %s ***\r\n",
flow_str[opts.flow]);
}
break;
@ -1017,10 +1017,10 @@ do_command (unsigned char c)
newparity = term_get_parity(tty_fd);
if (opts.parity != newparity ) {
fd_printf(STO, "\r\n*** parity: %s (%s) ***\r\n",
parity_str[opts.parity],
parity_str[opts.parity],
parity_str[newparity]);
} else {
fd_printf(STO, "\r\n*** parity: %s ***\r\n",
fd_printf(STO, "\r\n*** parity: %s ***\r\n",
parity_str[opts.parity]);
}
break;
@ -1034,7 +1034,7 @@ do_command (unsigned char c)
fd_printf(STO, "\r\n*** databits: %d (%d) ***\r\n",
opts.databits, newbits);
} else {
fd_printf(STO, "\r\n*** databits: %d ***\r\n",
fd_printf(STO, "\r\n*** databits: %d ***\r\n",
opts.databits);
}
break;
@ -1048,13 +1048,13 @@ do_command (unsigned char c)
fd_printf(STO, "\r\n*** stopbits: %d (%d) ***\r\n",
opts.stopbits, newstopbits);
} else {
fd_printf(STO, "\r\n*** stopbits: %d ***\r\n",
fd_printf(STO, "\r\n*** stopbits: %d ***\r\n",
opts.stopbits);
}
break;
case KEY_LECHO:
opts.lecho = ! opts.lecho;
fd_printf(STO, "\r\n*** local echo: %s ***\r\n",
fd_printf(STO, "\r\n*** local echo: %s ***\r\n",
opts.lecho ? "yes" : "no");
break;
case KEY_SEND:
@ -1125,7 +1125,7 @@ loop(void)
fatal("stdin closed");
} else if (n < 0) {
/* is this really necessary? better safe than sory! */
if ( errno != EAGAIN && errno != EWOULDBLOCK )
if ( errno != EAGAIN && errno != EWOULDBLOCK )
fatal("read from stdin failed: %s", strerror(errno));
else
goto skip_proc_STI;
@ -1136,10 +1136,10 @@ loop(void)
if ( c == opts.escape ) {
/* pass the escape character down */
if (tty_q.len + M_MAXMAP <= TTY_Q_SZ) {
n = do_map((char *)tty_q.buff + tty_q.len,
n = do_map((char *)tty_q.buff + tty_q.len,
opts.omap, c);
tty_q.len += n;
if ( opts.lecho )
if ( opts.lecho )
map_and_write(STO, opts.emap, c);
} else {
fd_printf(STO, "\x07");
@ -1157,12 +1157,12 @@ loop(void)
state = ST_COMMAND;
} else {
if (tty_q.len + M_MAXMAP <= TTY_Q_SZ) {
n = do_map((char *)tty_q.buff + tty_q.len,
n = do_map((char *)tty_q.buff + tty_q.len,
opts.omap, c);
tty_q.len += n;
if ( opts.lecho )
if ( opts.lecho )
map_and_write(STO, opts.emap, c);
} else
} else
fd_printf(STO, "\x07");
}
break;
@ -1251,7 +1251,7 @@ establish_signal_handlers (void)
sigaction (SIGTERM, &exit_action, NULL);
sigaction (SIGINT, &ign_action, NULL);
sigaction (SIGINT, &ign_action, NULL);
sigaction (SIGHUP, &ign_action, NULL);
sigaction (SIGQUIT, &ign_action, NULL);
sigaction (SIGALRM, &ign_action, NULL);
@ -1291,7 +1291,7 @@ show_usage(char *name)
#ifdef USE_CUSTOM_BAUD
printf(" USE_CUSTOM_BAUD is enabled\n");
#endif
printf("\nUsage is: %s [options] <tty device>\n", s);
printf("Options are:\n");
printf(" --<b>aud <baudrate>\n");
@ -1553,9 +1553,9 @@ parse_args(int argc, char *argv[])
#if defined (UUCP_LOCK_DIR) || defined (USE_FLOCK)
printf("nolock is : %s\n", opts.nolock ? "yes" : "no");
#endif
printf("send_cmd is : %s\n",
printf("send_cmd is : %s\n",
(opts.send_cmd[0] == '\0') ? "disabled" : opts.send_cmd);
printf("receive_cmd is : %s\n",
printf("receive_cmd is : %s\n",
(opts.receive_cmd[0] == '\0') ? "disabled" : opts.receive_cmd);
printf("imap is : "); print_map(opts.imap);
printf("omap is : "); print_map(opts.omap);
@ -1619,7 +1619,7 @@ main(int argc, char *argv[])
!opts.noreset); /* hup-on-close. */
}
if ( r < 0 )
fatal("failed to add device %s: %s",
fatal("failed to add device %s: %s",
opts.port, term_strerror(term_errno, errno));
if ( opts.lower_rts ) {
@ -1635,14 +1635,14 @@ main(int argc, char *argv[])
r = term_apply(tty_fd, 0);
if ( r < 0 )
fatal("failed to config device %s: %s",
fatal("failed to config device %s: %s",
opts.port, term_strerror(term_errno, errno));
set_tty_write_sz(term_get_baudrate(tty_fd, NULL));
r = term_add(STI);
if ( r < 0 )
fatal("failed to add I/O device: %s",
fatal("failed to add I/O device: %s",
term_strerror(term_errno, errno));
term_set_raw(STI);
r = term_apply(STI, 0);

10
split.c
View File

@ -19,7 +19,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
* USA
*/
#include <stdlib.h>
@ -81,7 +81,7 @@ enum states {
} else { \
flags |= SPLIT_TRUNC; \
} \
} while (0)
} while (0)
int
split_quoted (const char *s, int *argc, char *argv[], int argv_sz)
@ -107,7 +107,7 @@ split_quoted (const char *s, int *argc, char *argv[], int argv_sz)
case ST_DELIM:
while ( is_delim(*c) ) c++;
if ( *c == SQ || *c == DQ ) {
qc = *c; c++; state = ST_QUOTE;
qc = *c; c++; state = ST_QUOTE;
break;
}
if ( *c == EOS ) {
@ -187,7 +187,7 @@ split_quoted (const char *s, int *argc, char *argv[], int argv_sz)
assert(0);
}
}
return ( err != ERR_OK ) ? -1 : flags;
}
@ -205,7 +205,7 @@ main (int argc, char *argv[])
printf("Usage is: %s: <string to split>\n", argv[0]);
exit(EXIT_FAILURE);
}
printf("String to split is: [%s]\n", argv[1]);
r = split_quoted(argv[1], &my_argc, my_argv, 12);
if ( r < 0 ) {

View File

@ -19,7 +19,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
* USA
*/
#ifndef SPLIT_H
@ -88,7 +88,7 @@
* 'a "b"' c d --> [a "b"] [c] [d]
* "a 'b'" c d --> [a 'b'] [c] [d]
* a"b c" d --> [ab c] [d]
* a\ b c d --> [a b] [c] [d]
* a\ b c d --> [a b] [c] [d]
* \a\b c d --> [ab] [c] [d]
* \a\\b \\ c d --> [a\b] [\] [c] [d]
* "a\$\b" c d --> [a$\b] [c] [d]

90
term.c
View File

@ -7,7 +7,7 @@
* Nick Patavalis (npat@inaccessnetworks.com)
*
* originaly by Pantelis Antoniou (panto@intranet.gr), Nick Patavalis
*
*
* Documentation can be found in the header file "term.h".
*
* This program is free software; you can redistribute it and/or
@ -23,7 +23,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
* USA
*
* $Id$
*/
@ -484,7 +484,7 @@ term_lib_init (void)
} while ( r < 0 && errno == EINTR );
if ( r < 0 ) {
char *tname;
tname = ttyname(term.fd[i]);
if ( ! tname ) tname = "UNKNOWN";
fprintf(stderr, "%s: reset failed for dev %s: %s\n",
@ -498,7 +498,7 @@ term_lib_init (void)
term.fd[i] = -1;
if ( atexit(term_exitfunc) != 0 ) {
term_errno = TERM_EATEXIT;
rval = -1;
rval = -1;
break;
}
/* ok. term struct is now initialized. */
@ -568,10 +568,10 @@ term_remove(int fd)
rval = -1;
break;
}
do { /* dummy */
r = tcflush(term.fd[i], TCIOFLUSH);
if ( r < 0 ) {
if ( r < 0 ) {
term_errno = TERM_EFLUSH;
rval = -1;
break;
@ -583,7 +583,7 @@ term_remove(int fd)
break;
}
} while (0);
term.fd[i] = -1;
} while (0);
@ -605,7 +605,7 @@ term_erase(int fd)
rval = -1;
break;
}
term.fd[i] = -1;
} while (0);
@ -623,7 +623,7 @@ term_replace (int oldfd, int newfd)
do { /* dummy */
i = term_find(oldfd);
i = term_find(oldfd);
if ( i < 0 ) {
rval = -1;
break;
@ -762,7 +762,7 @@ term_apply (int fd, int now)
rval = -1;
break;
}
r = tcsetattr(term.fd[i], when, &term.nexttermios[i]);
if ( r < 0 ) {
term_errno = TERM_ESETATTR;
@ -793,7 +793,7 @@ term_set_raw (int fd)
rval = 0;
do { /* dummy */
i = term_find(fd);
if ( i < 0 ) {
rval = -1;
@ -807,7 +807,7 @@ term_set_raw (int fd)
term.nexttermios[i].c_cc[VTIME] = 0;
} while (0);
return rval;
}
@ -863,7 +863,7 @@ term_set_baudrate (int fd, int baudrate)
return rval;
}
int
int
term_get_baudrate (int fd, int *ispeed)
{
speed_t code;
@ -907,7 +907,7 @@ term_get_baudrate (int fd, int *ispeed)
/***************************************************************************/
int
term_set_parity (int fd, enum parity_e parity)
term_set_parity (int fd, enum parity_e parity)
{
int rval, i;
struct termios *tiop;
@ -941,7 +941,7 @@ term_set_parity (int fd, enum parity_e parity)
tiop->c_cflag |= PARENB | CMSPAR;
break;
case P_NONE:
tiop->c_cflag &= ~(PARENB | PARODD | CMSPAR);
tiop->c_cflag &= ~(PARENB | PARODD | CMSPAR);
break;
default:
term_errno = TERM_EPARITY;
@ -979,7 +979,7 @@ term_get_parity (int fd)
}
} while (0);
return parity;
}
@ -1002,7 +1002,7 @@ term_set_databits (int fd, int databits)
}
tiop = &term.nexttermios[i];
switch (databits) {
case 5:
tiop->c_cflag = (tiop->c_cflag & ~CSIZE) | CS5;
@ -1083,7 +1083,7 @@ term_set_stopbits (int fd, int stopbits)
}
tiop = &term.nexttermios[i];
switch (stopbits) {
case 1:
tiop->c_cflag &= ~CSTOPB;
@ -1140,7 +1140,7 @@ term_set_flowcntrl (int fd, enum flowcntrl_e flowcntl)
rval = -1;
break;
}
tiop = &term.nexttermios[i];
switch (flowcntl) {
@ -1197,7 +1197,7 @@ term_get_flowcntrl (int fd)
}
} while (0);
return flow;
}
@ -1266,8 +1266,8 @@ term_set_hupcl (int fd, int on)
int
term_set(int fd,
int raw,
int baud,
enum parity_e parity,
int baud,
enum parity_e parity,
int databits, int stopbits,
enum flowcntrl_e fc,
int local, int hup_close)
@ -1298,31 +1298,31 @@ term_set(int fd,
r = term_set_raw(fd);
if ( r < 0 ) { rval = -1; break; }
}
r = term_set_baudrate(fd, baud);
if ( r < 0 ) { rval = -1; break; }
r = term_set_parity(fd, parity);
if ( r < 0 ) { rval = -1; break; }
r = term_set_databits(fd, databits);
if ( r < 0 ) { rval = -1; break; }
r = term_set_stopbits(fd, stopbits);
if ( r < 0 ) { rval = -1; break; }
r = term_set_flowcntrl(fd, fc);
if ( r < 0 ) { rval = -1; break; }
r = term_set_local(fd, local);
if ( r < 0 ) { rval = -1; break; }
r = term_set_hupcl(fd, hup_close);
if ( r < 0 ) { rval = -1; break; }
} while (0);
if ( rval < 0 ) {
if ( rval < 0 ) {
if ( i < 0 )
/* new addition. must be removed */
term.fd[ni] = -1;
@ -1383,9 +1383,9 @@ term_pulse_dtr (int fd)
rval = -1;
break;
}
tioold = tio;
cfsetospeed(&tio, B0);
cfsetispeed(&tio, B0);
r = tcsetattr(fd, TCSANOW, &tio);
@ -1394,9 +1394,9 @@ term_pulse_dtr (int fd)
rval = -1;
break;
}
sleep(1);
r = tcsetattr(fd, TCSANOW, &tioold);
if ( r < 0 ) {
term.currtermios[i] = tio;
@ -1406,7 +1406,7 @@ term_pulse_dtr (int fd)
}
}
#endif /* of __linux__ or __APPLE__ */
} while (0);
return rval;
@ -1467,7 +1467,7 @@ term_lower_dtr(int fd)
do { /* dummy */
i = term_find(fd);
if ( i < 0 ) {
if ( i < 0 ) {
rval = -1;
break;
}
@ -1494,10 +1494,10 @@ term_lower_dtr(int fd)
break;
}
term.currtermios[i] = tio;
cfsetospeed(&tio, B0);
cfsetispeed(&tio, B0);
r = tcsetattr(fd, TCSANOW, &tio);
if ( r < 0 ) {
term_errno = TERM_ESETATTR;
@ -1507,7 +1507,7 @@ term_lower_dtr(int fd)
}
#endif /* of __linux__ or __APPLE__ */
} while (0);
return rval;
}
@ -1561,7 +1561,7 @@ term_lower_rts(int fd)
do { /* dummy */
i = term_find(fd);
if ( i < 0 ) {
if ( i < 0 ) {
rval = -1;
break;
}
@ -1583,7 +1583,7 @@ term_lower_rts(int fd)
rval = -1;
#endif /* of __linux__ or __APPLE__ */
} while (0);
return rval;
}
@ -1598,15 +1598,15 @@ term_get_mctl (int fd)
do { /* dummy */
i = term_find(fd);
if ( i < 0 ) {
if ( i < 0 ) {
mctl = -1;
break;
}
#if defined(__linux__) || defined(__APPLE__)
{
{
int r, pmctl;
r = ioctl(fd, TIOCMGET, &pmctl);
if (r < 0) {
mctl = -1;
@ -1706,7 +1706,7 @@ term_break(int fd)
rval = -1;
break;
}
r = tcsendbreak(fd, 0);
if ( r < 0 ) {
term_errno = TERM_EBREAK;

68
term.h
View File

@ -94,7 +94,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
* USA
*
* $Id: term.h,v 1.1 2003/05/07 18:00:05 npat Exp $
*/
@ -160,32 +160,32 @@ enum term_errno_e {
* P_SPACE - space parity (parity bit always 0)
*/
enum parity_e {
P_NONE = 0,
P_EVEN,
P_NONE = 0,
P_EVEN,
P_ODD,
P_MARK,
P_SPACE
};
/*
/*
* E flowcntrl_e
*
* Flow control modes, supported by the library.
*
* FC_NONE - no flow control
* FC_RTSCTS - RTS/CTS handshaking, also known as hardware
* FC_RTSCTS - RTS/CTS handshaking, also known as hardware
* flow-control.
* FC_XONXOFF - xon/xoff flow control.
* FC_XONXOFF - xon/xoff flow control.
*/
enum flowcntrl_e {
FC_NONE = 0,
FC_RTSCTS,
FC_NONE = 0,
FC_RTSCTS,
FC_XONXOFF,
FC_OTHER
};
/*
* C MCTL_xxx
/*
* C MCTL_xxx
*
* Modem control line bits. Used against the return value of
* term_get_mctl().
@ -229,7 +229,7 @@ const char *term_strerror (int terrnum, int errnum);
* Emit a description of the current library (and possibly system)
* error condition to the standard-error stream. The description is
* prefixed by a user-supplied string. What is actually emmited is:
*
*
* <prefix><space><description>\n
*
* The description emitted is the string returned by term_strerror().
@ -319,7 +319,7 @@ int term_erase (int fd);
int term_replace (int oldfd, int newfd);
/*
* F term_apply
* F term_apply
*
* Applies the settings stored in the "nexttermios" structure
* associated with the managed filedes "fd", to the respective
@ -338,7 +338,7 @@ int term_replace (int oldfd, int newfd);
int term_apply (int fd, int now);
/*
* F term_revert
* F term_revert
*
* Discards all the changes made to the nexttermios structure
* associated with the managed filedes "fd" that have not been applied
@ -365,7 +365,7 @@ int term_revert (int fd);
int term_reset (int fd);
/*
* F term_refresh
* F term_refresh
*
* Updates the contents of the currtermios structure associated with
* the managed filedes "fd", by reading the settings from the
@ -377,11 +377,11 @@ int term_reset (int fd);
int term_refresh (int fd);
/* F term_set_raw
*
*
* Sets the "nexttermios" structure associated with the managed
* filedes "fd" to raw mode. The effective settings of the device are
* not affected by this function.
*
*
* Returns negative on failure, non-negative on success. Returns
* failure only to indicate invalid arguments, so the return value can
* be safely ignored.
@ -392,7 +392,7 @@ int term_refresh (int fd);
* terminal settings as indicated:
*
* -ignbrk -brkint -parmrk -istrip -inlcr -igncr -icrnl -ixon
* -opost -echo -echonl -icannon -isig -iexten -csize -parenb
* -opost -echo -echonl -icannon -isig -iexten -csize -parenb
* cs8 min=1 time=0
*/
int term_set_raw (int fd);
@ -427,7 +427,7 @@ int term_set_baudrate (int fd, int baudrate);
int term_set_parity (int fd, enum parity_e parity);
/* F term_set_databits
*
*
* Sets the databits number in the "nexttermios" structure associated
* with the managed filedes "fd" to "databits". The effective settings
* of the device are not affected by this function.
@ -441,7 +441,7 @@ int term_set_parity (int fd, enum parity_e parity);
int term_set_databits (int fd, int databits);
/* F term_set_stopbits
*
*
* Sets the stopbits number in the "nexttermios" structure associated
* with the managed filedes "fd" to "stopbits". The effective settings
* of the device are not affected by this function.
@ -459,7 +459,7 @@ int term_set_stopbits (int fd, int stopbits);
* Sets the folwcontrol mode in the "nexttermios" structure associated
* with the managed filedes "fd" to "flowcntl". The effective settings
* of the device are not affected by this function.
*
*
* The following flow control modes are supportd by the library:
* FC_NONE, FC_RTSCTS, FC_XONXOFF.
*
@ -478,7 +478,7 @@ int term_set_flowcntrl (int fd, enum flowcntrl_e flowcntl);
*
* Returns negative on failure, non negative on success. Returns
* failure only to indicate invalid arguments, so the return value can
* be safely ignored.
* be safely ignored.
*/
int term_set_hupcl (int fd, int on);
@ -491,7 +491,7 @@ int term_set_hupcl (int fd, int on);
*
* Returns negative on failure, non negative on success. Returns
* failure only to indicate invalid arguments, so the return value can
* be safely ignored.
* be safely ignored.
*/
int term_set_local (int fd, int local);
@ -501,11 +501,11 @@ int term_set_local (int fd, int local);
* associated with the managed filedes "fd". Actually sets the
* following:
*
* Raw mode if "raw" is nonzero.
* Baudrate to "baud".
* Parity mode to "parity".
* Flow control mode to "fc".
* Enables local mode if "local" is nonzero, dis. otherwise.
* Raw mode if "raw" is nonzero.
* Baudrate to "baud".
* Parity mode to "parity".
* Flow control mode to "fc".
* Enables local mode if "local" is nonzero, dis. otherwise.
* Enables HUP-on-close if "hupcl" is nonzero, dis. otherwise
*
* The effective settings of the device are not affected by this
@ -520,11 +520,11 @@ int term_set_local (int fd, int local);
* filedes to the framework, and following this it fails, then it will
* remove the filedes before returning.
*/
int term_set (int fd,
int raw,
int baud,
enum parity_e parity,
int databits, int stopbits,
int term_set (int fd,
int raw,
int baud,
enum parity_e parity,
int databits, int stopbits,
enum flowcntrl_e fc,
int local, int hupcl);
@ -638,7 +638,7 @@ int term_raise_rts (int fd);
*/
int term_get_mctl (int fd);
/* F term_drain
/* F term_drain
*
* Drains (flushes) the output queue of the device associated with the
* managed filedes "fd". This functions blocks until all the contents
@ -649,7 +649,7 @@ int term_get_mctl (int fd);
int term_drain (int fd);
/* F term_flush
*
*
* Discards all the contents of the input AND output queues of the
* device associated with the managed filedes "fd". Although it is
* called flush this functions does NOT FLUSHES the terminal

View File

@ -6,7 +6,7 @@
*
* by Nick Patavalis (npat@efault.net)
*
* ATTENTION: Linux-specific kludge!
* ATTENTION: Linux-specific kludge!
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@ -21,7 +21,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
* USA
*/
#ifndef TERMBITS2_H
@ -56,7 +56,7 @@
cannot get the definion of "struct termios2" from the above header
files, since this would also bring-in the clashing definition of the
kernel version of "struct termios". If you have an idea for a better
way out of this mess, I would REALLY like to hear it.
way out of this mess, I would REALLY like to hear it.
I hope that soon GLIBC will pick-up termios2 and all these will be
useless. Until then ...

View File

@ -5,7 +5,7 @@
*
* by Nick Patavalis (npat@efault.net)
*
* ATTENTION: Linux-specific kludge!
* ATTENTION: Linux-specific kludge!
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@ -20,7 +20,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
* USA
*/
#if defined(__linux__) && defined(USE_CUSTOM_BAUD)
@ -45,9 +45,9 @@
/* GLIBC termios use an (otherwise unused) bit in c_iflags to
internally record the fact that ispeed was set to zero (which is
special behavior and means "same as ospeed". We want to clear this
bit before passing c_iflags back to the kernel. See:
<glibc-source>/sysdeps/unix/sysv/linux/speed.c
bit before passing c_iflags back to the kernel. See:
<glibc-source>/sysdeps/unix/sysv/linux/speed.c
*/
#define IBAUD0 020000000000
@ -80,7 +80,7 @@ tc2setattr(int fd, int optional_actions, const struct termios *tios)
t2.c_ispeed = tios->c_ispeed;
t2.c_ospeed = tios->c_ospeed;
memcpy(&t2.c_cc[0], &tios->c_cc[0], K_NCCS * sizeof (cc_t));
return ioctl(fd, cmd, &t2);
}
@ -102,7 +102,7 @@ tc2getattr(int fd, struct termios *tios)
tios->c_ispeed = t2.c_ispeed;
tios->c_ospeed = t2.c_ospeed;
memcpy(&tios->c_cc[0], &t2.c_cc[0], K_NCCS * sizeof (cc_t));
for (i = K_NCCS; i < NCCS; i++)
tios->c_cc[i] = _POSIX_VDISABLE;
@ -124,7 +124,7 @@ tc2getattr(int fd, struct termios *tios)
int
cf2setispeed(struct termios *tios, speed_t speed)
{
if ( (speed & ~CBAUD) != 0
if ( (speed & ~CBAUD) != 0
&& (speed < B57600 || speed > __MAX_BAUD) ) {
errno = EINVAL;
return -1;
@ -151,7 +151,7 @@ cf2setospeed_custom(struct termios *tios, int speed)
if ( speed <= 0 ) {
errno = EINVAL;
return -1;
}
}
tios->c_cflag &= ~(CBAUD | CBAUDEX);
tios->c_cflag |= BOTHER;
tios->c_ospeed = speed;

View File

@ -5,7 +5,7 @@
*
* by Nick Patavalis (npat@efault.net)
*
* ATTENTION: Linux-specific kludge!
* ATTENTION: Linux-specific kludge!
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@ -20,7 +20,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
* USA
*/
#ifndef TERMIOS2_H

View File

@ -7,7 +7,7 @@ through the "new" "termios2" terminal-attributes structure, and the
respective ioctls: TCSETS2, TCSETSW2, TCSETSF2, and TCGETS2.
The "termios2" structure is defined in:
<linux-kernel>/arch/<arch>/include/uapi/asm/termbits.h
or <linux-kernel>/include/uapi/asm-generic/termbits.h