mirror of
https://github.com/UzixLS/picocom.git
synced 2025-07-19 07:21:18 +03:00
Merge branch 'Joe-Merten-whitespace-cleanup'
This commit is contained in:
@ -52,7 +52,7 @@ Changed paths:
|
|||||||
Added support for UUCP-style locks. Lock handling is compiled-in if
|
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
|
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
|
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
|
UUCP-locks support is based on a patch submitted by Julius
|
||||||
P. Malkiewicz <julius@sonartech.com.au>
|
P. Malkiewicz <julius@sonartech.com.au>
|
||||||
|
@ -56,4 +56,4 @@ comments:
|
|||||||
|
|
||||||
- Joe Merten (https://github.com/Joe-Merten) contributed the
|
- Joe Merten (https://github.com/Joe-Merten) contributed the
|
||||||
--lower-rts and --lower-dtr options, custom baudrate support for
|
--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.
|
||||||
|
14
LICENSE.txt
14
LICENSE.txt
@ -1,12 +1,12 @@
|
|||||||
GNU GENERAL PUBLIC LICENSE
|
GNU GENERAL PUBLIC LICENSE
|
||||||
Version 2, June 1991
|
Version 2, June 1991
|
||||||
|
|
||||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
of this license document, but changing it is not allowed.
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
Preamble
|
Preamble
|
||||||
|
|
||||||
The licenses for most software are designed to take away your
|
The licenses for most software are designed to take away your
|
||||||
freedom to share and change it. By contrast, the GNU General Public
|
freedom to share and change it. By contrast, the GNU General Public
|
||||||
@ -56,7 +56,7 @@ patent must be licensed for everyone's free use or not licensed at all.
|
|||||||
The precise terms and conditions for copying, distribution and
|
The precise terms and conditions for copying, distribution and
|
||||||
modification follow.
|
modification follow.
|
||||||
|
|
||||||
GNU GENERAL PUBLIC LICENSE
|
GNU GENERAL PUBLIC LICENSE
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
0. This License applies to any program or other work which contains
|
0. This License applies to any program or other work which contains
|
||||||
@ -255,7 +255,7 @@ make exceptions for this. Our decision will be guided by the two goals
|
|||||||
of preserving the free status of all derivatives of our free software and
|
of preserving the free status of all derivatives of our free software and
|
||||||
of promoting the sharing and reuse of software generally.
|
of promoting the sharing and reuse of software generally.
|
||||||
|
|
||||||
NO WARRANTY
|
NO WARRANTY
|
||||||
|
|
||||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||||
@ -277,9 +277,9 @@ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
|||||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||||
POSSIBILITY OF SUCH DAMAGES.
|
POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
If you develop a new program, and you want it to be of the greatest
|
||||||
possible use to the public, the best way to achieve this is to make it
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
90
README.md
90
README.md
@ -9,7 +9,7 @@ The latest release can be downloaded from:
|
|||||||
|
|
||||||
As its name suggests, *picocom* is a minimal dumb-terminal emulation
|
As its name suggests, *picocom* is a minimal dumb-terminal emulation
|
||||||
program. It is, in principle, very much like minicom, only it's "pico"
|
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,
|
It was designed to serve as a simple, manual, modem configuration,
|
||||||
testing, and debugging tool. It has also served (quite well) as a
|
testing, and debugging tool. It has also served (quite well) as a
|
||||||
@ -57,11 +57,11 @@ man-page, to wherever you put your binaries and man-pages. For
|
|||||||
example:
|
example:
|
||||||
|
|
||||||
|
|
||||||
cp picocom ~/bin
|
cp picocom ~/bin
|
||||||
cp picocom.1 ~/man/man1
|
cp picocom.1 ~/man/man1
|
||||||
|
|
||||||
Again, this is not strictly necessary. You can run picocom and read
|
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
|
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
|
lacking a feature you need, take a look at the included Makefile. It's
|
||||||
@ -71,15 +71,15 @@ by commenting in or out the respective lines. Once you edit the
|
|||||||
Makefile, to recompile say:
|
Makefile, to recompile say:
|
||||||
|
|
||||||
|
|
||||||
make clean
|
make clean
|
||||||
make
|
make
|
||||||
|
|
||||||
If your system's default make(1) command is not GNU Make (or
|
If your system's default make(1) command is not GNU Make (or
|
||||||
compatible enough), find out how you can run GNU Make on your
|
compatible enough), find out how you can run GNU Make on your
|
||||||
system. For example:
|
system. For example:
|
||||||
|
|
||||||
gmake clean
|
gmake clean
|
||||||
gmake
|
gmake
|
||||||
|
|
||||||
Alternatively, you might have to make some trivial edits to the
|
Alternatively, you might have to make some trivial edits to the
|
||||||
Makefile for it to work with your system's make(1) command.
|
Makefile for it to work with your system's make(1) command.
|
||||||
@ -102,22 +102,22 @@ through a device node named `/dev/ttyS0`.
|
|||||||
You can start picocom with its default option values (default serial
|
You can start picocom with its default option values (default serial
|
||||||
port settings) like this:
|
port settings) like this:
|
||||||
|
|
||||||
picocom /dev/ttyS0
|
picocom /dev/ttyS0
|
||||||
|
|
||||||
If you have not installed the picocom binary to a suitable place, then
|
If you have not installed the picocom binary to a suitable place, then
|
||||||
you can run it directly from the source distribution directory like
|
you can run it directly from the source distribution directory like
|
||||||
this:
|
this:
|
||||||
|
|
||||||
./picocom /dev/ttyS0
|
./picocom /dev/ttyS0
|
||||||
|
|
||||||
If this fails with a message like:
|
If this fails with a message like:
|
||||||
|
|
||||||
FATAL: cannot open /dev/ttyS0: Permission denied
|
FATAL: cannot open /dev/ttyS0: Permission denied
|
||||||
|
|
||||||
This means that you do not have permissions to access the serial
|
This means that you do not have permissions to access the serial
|
||||||
port's device node. To overcome this you can run picocom as root:
|
port's device node. To overcome this you can run picocom as root:
|
||||||
|
|
||||||
sudo picocom /dev/ttyS0
|
sudo picocom /dev/ttyS0
|
||||||
|
|
||||||
Alternatively, and preferably, you can add yourself to the user-group
|
Alternatively, and preferably, you can add yourself to the user-group
|
||||||
that your system has for allowing access to serial ports. For most
|
that your system has for allowing access to serial ports. For most
|
||||||
@ -125,7 +125,7 @@ Unix-like systems this group is called "dialout". Consult you system's
|
|||||||
documentation to find out how you can do this (as it differs form
|
documentation to find out how you can do this (as it differs form
|
||||||
system to system). On most Linux systems you can do it like this:
|
system to system). On most Linux systems you can do it like this:
|
||||||
|
|
||||||
sudo usermod -a -G dialout username
|
sudo usermod -a -G dialout username
|
||||||
|
|
||||||
You will need to log-out and then log-in back again for this change to
|
You will need to log-out and then log-in back again for this change to
|
||||||
take effect.
|
take effect.
|
||||||
@ -135,20 +135,20 @@ desired values using picocom's command line options. For example, to
|
|||||||
set the baud-rate to 115200bps (the default is 9600bps), and enable
|
set the baud-rate to 115200bps (the default is 9600bps), and enable
|
||||||
hardware flow-control (RTS/CTS handshake) you can say:
|
hardware flow-control (RTS/CTS handshake) you can say:
|
||||||
|
|
||||||
picocom -b 115200 -f h /dev/ttyS0
|
picocom -b 115200 -f h /dev/ttyS0
|
||||||
|
|
||||||
or:
|
or:
|
||||||
|
|
||||||
picocom --baud 115200 --flow h /dev/ttyS0
|
picocom --baud 115200 --flow h /dev/ttyS0
|
||||||
|
|
||||||
To see all available options run picocom like this:
|
To see all available options run picocom like this:
|
||||||
|
|
||||||
picocom --help
|
picocom --help
|
||||||
|
|
||||||
Once picocom starts, it initializes the serial port and prints the
|
Once picocom starts, it initializes the serial port and prints the
|
||||||
message:
|
message:
|
||||||
|
|
||||||
Terminal is ready
|
Terminal is ready
|
||||||
|
|
||||||
From now on, every character you type is sent to the serial port, and
|
From now on, every character you type is sent to the serial port, and
|
||||||
every character received from the serial port is sent ro your
|
every character received from the serial port is sent ro your
|
||||||
@ -160,7 +160,7 @@ terminal. This is normal.
|
|||||||
|
|
||||||
To exit picocom you have to type:
|
To exit picocom you have to type:
|
||||||
|
|
||||||
C-a, C-x
|
C-a, C-x
|
||||||
|
|
||||||
Which means you have to type [Control-A] followed by [Control-X]. You
|
Which means you have to type [Control-A] followed by [Control-X]. You
|
||||||
can do this by pressing and holding down the [Control] key, then
|
can do this by pressing and holding down the [Control] key, then
|
||||||
@ -177,11 +177,11 @@ Next you should take a look at the very detailed picocom manual
|
|||||||
page. It can be accessed like this (assuming you are inside the
|
page. It can be accessed like this (assuming you are inside the
|
||||||
picocom distribution source directory):
|
picocom distribution source directory):
|
||||||
|
|
||||||
man ./picocom.1
|
man ./picocom.1
|
||||||
|
|
||||||
or (assuming you have installed the manual page to a suitable place):
|
or (assuming you have installed the manual page to a suitable place):
|
||||||
|
|
||||||
man picocom
|
man picocom
|
||||||
|
|
||||||
Thanks for using picocom
|
Thanks for using picocom
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ access these console ports remotely.
|
|||||||
If you provide shell-access to termbox for your users, then it's as
|
If you provide shell-access to termbox for your users, then it's as
|
||||||
simple as having the users say (from their remote workstations):
|
simple as having the users say (from their remote workstations):
|
||||||
|
|
||||||
$ ssh -t user@termbox picocom -b 115200 /dev/ttyS0
|
$ ssh -t user@termbox picocom -b 115200 /dev/ttyS0
|
||||||
|
|
||||||
Or make a convenient script/alias for this. Remember the `-t` switch
|
Or make a convenient script/alias for this. Remember the `-t` switch
|
||||||
which instructs ssh to create a pseudo-tty, otherwise picocom won't
|
which instructs ssh to create a pseudo-tty, otherwise picocom won't
|
||||||
@ -213,7 +213,7 @@ go from Linux to other Unix-like systems.
|
|||||||
|
|
||||||
Login to termbox and create a user called _termbox_:
|
Login to termbox and create a user called _termbox_:
|
||||||
|
|
||||||
$ sudo useradd -r -m termbox
|
$ sudo useradd -r -m termbox
|
||||||
|
|
||||||
The `-r` means "system account", and the `-m` means *do* make the
|
The `-r` means "system account", and the `-m` means *do* make the
|
||||||
home-directory. Mostly we need this account's home-directory as a
|
home-directory. Mostly we need this account's home-directory as a
|
||||||
@ -223,48 +223,48 @@ password.
|
|||||||
Switch to the _termbox_ account and create a `bin` directory in its
|
Switch to the _termbox_ account and create a `bin` directory in its
|
||||||
home-dir.
|
home-dir.
|
||||||
|
|
||||||
$ sudo su termbox
|
$ sudo su termbox
|
||||||
$ cd ~
|
$ cd ~
|
||||||
$ mkdir bin
|
$ mkdir bin
|
||||||
|
|
||||||
Copy the picocom binary in `~termbox/bin` (if you don't have it
|
Copy the picocom binary in `~termbox/bin` (if you don't have it
|
||||||
globally installed):
|
globally installed):
|
||||||
|
|
||||||
$ cp /path/to/picocom ./bin
|
$ cp /path/to/picocom ./bin
|
||||||
|
|
||||||
For every serial port you want to provide access to, create a file
|
For every serial port you want to provide access to, create a file
|
||||||
named after the port and put it in `~termbox/bin`. It should look like
|
named after the port and put it in `~termbox/bin`. It should look like
|
||||||
this:
|
this:
|
||||||
|
|
||||||
$ cat ./bin/ttyS0
|
$ cat ./bin/ttyS0
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
exec /home/termbox/bin/picocom \
|
exec /home/termbox/bin/picocom \
|
||||||
--send-cmd '' \
|
--send-cmd '' \
|
||||||
--receive-cmd '' \
|
--receive-cmd '' \
|
||||||
-b 115200 \
|
-b 115200 \
|
||||||
/dev/ttyS0
|
/dev/ttyS0
|
||||||
|
|
||||||
And make it executable:
|
And make it executable:
|
||||||
|
|
||||||
$ chmod +x ./bin/ttyS0
|
$ chmod +x ./bin/ttyS0
|
||||||
|
|
||||||
Repeat accordingly for every other port. Now the contents of
|
Repeat accordingly for every other port. Now the contents of
|
||||||
`~termbox/bin` should look like this:
|
`~termbox/bin` should look like this:
|
||||||
|
|
||||||
$ ls -l ./bin
|
$ ls -l ./bin
|
||||||
-rwxrwxr-x 1 termbox termbox 102128 Aug 29 13:56 picocom*
|
-rwxrwxr-x 1 termbox termbox 102128 Aug 29 13:56 picocom*
|
||||||
-rwxrwxr-x 1 termbox termbox 108 Aug 29 14:07 ttyS0*
|
-rwxrwxr-x 1 termbox termbox 108 Aug 29 14:07 ttyS0*
|
||||||
-rwxrwxr-x 1 termbox termbox 108 Aug 29 14:07 ttyS1*
|
-rwxrwxr-x 1 termbox termbox 108 Aug 29 14:07 ttyS1*
|
||||||
... and so on ...
|
... and so on ...
|
||||||
|
|
||||||
Exit the _termbox_ account:
|
Exit the _termbox_ account:
|
||||||
|
|
||||||
$ exit
|
$ exit
|
||||||
|
|
||||||
Now, for every serial port, create a user account named after the
|
Now, for every serial port, create a user account named after the
|
||||||
port, like this:
|
port, like this:
|
||||||
|
|
||||||
$ sudo useradd -r -g dialout -d ~termbox -M -s ~termbox/bin/ttyS0 ttyS0
|
$ sudo useradd -r -g dialout -d ~termbox -M -s ~termbox/bin/ttyS0 ttyS0
|
||||||
|
|
||||||
Observe that we make `dialout` the default group for this account, so
|
Observe that we make `dialout` the default group for this account, so
|
||||||
the account has access to the serial ports. Also observe that we make
|
the account has access to the serial ports. Also observe that we make
|
||||||
@ -280,9 +280,9 @@ useradd create the usual `/home/ttyS0`.
|
|||||||
|
|
||||||
Then set a password for the newly created account:
|
Then set a password for the newly created account:
|
||||||
|
|
||||||
$ sudo passwd ttyS0
|
$ sudo passwd ttyS0
|
||||||
Enter new UNIX password: ******
|
Enter new UNIX password: ******
|
||||||
Retype new UNIX password: ******
|
Retype new UNIX password: ******
|
||||||
|
|
||||||
Repeat (create user account, set password) for every port you want to
|
Repeat (create user account, set password) for every port you want to
|
||||||
give access to.
|
give access to.
|
||||||
@ -290,7 +290,7 @@ give access to.
|
|||||||
You 're set. All a user has to do to remotely access the console
|
You 're set. All a user has to do to remotely access the console
|
||||||
connected to termbox's `/dev/ttyS0` port, is:
|
connected to termbox's `/dev/ttyS0` port, is:
|
||||||
|
|
||||||
ssh ttyS0@termbox
|
ssh ttyS0@termbox
|
||||||
|
|
||||||
Some interesting points:
|
Some interesting points:
|
||||||
|
|
||||||
|
48
fdio.c
48
fdio.c
@ -19,7 +19,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
* USA
|
* USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -34,7 +34,7 @@
|
|||||||
ssize_t
|
ssize_t
|
||||||
writen_ni(int fd, const void *buff, size_t n)
|
writen_ni(int fd, const void *buff, size_t n)
|
||||||
{
|
{
|
||||||
size_t nl;
|
size_t nl;
|
||||||
ssize_t nw;
|
ssize_t nw;
|
||||||
const char *p;
|
const char *p;
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ writen_ni(int fd, const void *buff, size_t n)
|
|||||||
nl -= nw;
|
nl -= nw;
|
||||||
p += nw;
|
p += nw;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n - nl;
|
return n - nl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,12 +58,12 @@ fd_printf (int fd, const char *format, ...)
|
|||||||
char buf[256];
|
char buf[256];
|
||||||
va_list args;
|
va_list args;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
len = vsnprintf(buf, sizeof(buf), format, args);
|
len = vsnprintf(buf, sizeof(buf), format, args);
|
||||||
buf[sizeof(buf) - 1] = '\0';
|
buf[sizeof(buf) - 1] = '\0';
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
return writen_ni(fd, buf, len);
|
return writen_ni(fd, buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,30 +71,30 @@ fd_printf (int fd, const char *format, ...)
|
|||||||
|
|
||||||
#ifndef LINENOISE
|
#ifndef LINENOISE
|
||||||
|
|
||||||
static int
|
static int
|
||||||
cput(int fd, char c)
|
cput(int fd, char c)
|
||||||
{
|
{
|
||||||
return write(fd, &c, 1);
|
return write(fd, &c, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
cdel (int fd)
|
cdel (int fd)
|
||||||
{
|
{
|
||||||
const char del[] = "\b \b";
|
const char del[] = "\b \b";
|
||||||
return write(fd, del, sizeof(del) - 1);
|
return write(fd, del, sizeof(del) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
xput (int fd, unsigned char c)
|
xput (int fd, unsigned char c)
|
||||||
{
|
{
|
||||||
const char hex[] = "0123456789abcdef";
|
const char hex[] = "0123456789abcdef";
|
||||||
char b[4];
|
char b[4];
|
||||||
|
|
||||||
b[0] = '\\'; b[1] = 'x'; b[2] = hex[c >> 4]; b[3] = hex[c & 0x0f];
|
b[0] = '\\'; b[1] = 'x'; b[2] = hex[c >> 4]; b[3] = hex[c & 0x0f];
|
||||||
return write(fd, b, sizeof(b));
|
return write(fd, b, sizeof(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
xdel (int fd)
|
xdel (int fd)
|
||||||
{
|
{
|
||||||
const char del[] = "\b\b\b\b \b\b\b\b";
|
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;
|
int r;
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
unsigned char *bp, *bpe;
|
unsigned char *bp, *bpe;
|
||||||
|
|
||||||
bp = (unsigned char *)b;
|
bp = (unsigned char *)b;
|
||||||
bpe = (unsigned char *)b + bsz - 1;
|
bpe = (unsigned char *)b + bsz - 1;
|
||||||
|
|
||||||
@ -118,11 +118,11 @@ fd_readline (int fdi, int fdo, char *b, int bsz)
|
|||||||
switch (c) {
|
switch (c) {
|
||||||
case '\b':
|
case '\b':
|
||||||
case '\x7f':
|
case '\x7f':
|
||||||
if ( bp > (unsigned char *)b ) {
|
if ( bp > (unsigned char *)b ) {
|
||||||
bp--;
|
bp--;
|
||||||
if ( isprint(*bp) )
|
if ( isprint(*bp) )
|
||||||
cdel(fdo);
|
cdel(fdo);
|
||||||
else
|
else
|
||||||
xdel(fdo);
|
xdel(fdo);
|
||||||
} else {
|
} else {
|
||||||
cput(fdo, '\x07');
|
cput(fdo, '\x07');
|
||||||
@ -134,17 +134,17 @@ fd_readline (int fdi, int fdo, char *b, int bsz)
|
|||||||
goto out;
|
goto out;
|
||||||
case '\r':
|
case '\r':
|
||||||
*bp = '\0';
|
*bp = '\0';
|
||||||
r = bp - (unsigned char *)b;
|
r = bp - (unsigned char *)b;
|
||||||
goto out;
|
goto out;
|
||||||
default:
|
default:
|
||||||
if ( bp < bpe ) {
|
if ( bp < bpe ) {
|
||||||
*bp++ = c;
|
*bp++ = c;
|
||||||
if ( isprint(c) )
|
if ( isprint(c) )
|
||||||
cput(fdo, c);
|
cput(fdo, c);
|
||||||
else
|
else
|
||||||
xput(fdo, c);
|
xput(fdo, c);
|
||||||
} else {
|
} else {
|
||||||
cput(fdo, '\x07');
|
cput(fdo, '\x07');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
2
fdio.h
2
fdio.h
@ -19,7 +19,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
* USA
|
* USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef FDIO_H
|
#ifndef FDIO_H
|
||||||
|
@ -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).
|
* 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).
|
* 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.
|
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.
|
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.
|
||||||
|
@ -150,25 +150,25 @@ struct linenoiseState {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum KEY_ACTION{
|
enum KEY_ACTION{
|
||||||
KEY_NULL = 0, /* NULL */
|
KEY_NULL = 0, /* NULL */
|
||||||
CTRL_A = 1, /* Ctrl+a */
|
CTRL_A = 1, /* Ctrl+a */
|
||||||
CTRL_B = 2, /* Ctrl-b */
|
CTRL_B = 2, /* Ctrl-b */
|
||||||
CTRL_C = 3, /* Ctrl-c */
|
CTRL_C = 3, /* Ctrl-c */
|
||||||
CTRL_D = 4, /* Ctrl-d */
|
CTRL_D = 4, /* Ctrl-d */
|
||||||
CTRL_E = 5, /* Ctrl-e */
|
CTRL_E = 5, /* Ctrl-e */
|
||||||
CTRL_F = 6, /* Ctrl-f */
|
CTRL_F = 6, /* Ctrl-f */
|
||||||
CTRL_H = 8, /* Ctrl-h */
|
CTRL_H = 8, /* Ctrl-h */
|
||||||
TAB = 9, /* Tab */
|
TAB = 9, /* Tab */
|
||||||
CTRL_K = 11, /* Ctrl+k */
|
CTRL_K = 11, /* Ctrl+k */
|
||||||
CTRL_L = 12, /* Ctrl+l */
|
CTRL_L = 12, /* Ctrl+l */
|
||||||
ENTER = 13, /* Enter */
|
ENTER = 13, /* Enter */
|
||||||
CTRL_N = 14, /* Ctrl-n */
|
CTRL_N = 14, /* Ctrl-n */
|
||||||
CTRL_P = 16, /* Ctrl-p */
|
CTRL_P = 16, /* Ctrl-p */
|
||||||
CTRL_T = 20, /* Ctrl-t */
|
CTRL_T = 20, /* Ctrl-t */
|
||||||
CTRL_U = 21, /* Ctrl+u */
|
CTRL_U = 21, /* Ctrl+u */
|
||||||
CTRL_W = 23, /* Ctrl+w */
|
CTRL_W = 23, /* Ctrl+w */
|
||||||
ESC = 27, /* Escape */
|
ESC = 27, /* Escape */
|
||||||
BACKSPACE = 127 /* Backspace */
|
BACKSPACE = 127 /* Backspace */
|
||||||
};
|
};
|
||||||
|
|
||||||
static void linenoiseAtExit(void);
|
static void linenoiseAtExit(void);
|
||||||
|
@ -387,7 +387,7 @@ Example:
|
|||||||
.IP
|
.IP
|
||||||
.nf
|
.nf
|
||||||
\f[C]
|
\f[C]
|
||||||
***\ baud:\ 115200\ (9600)\
|
***\ baud:\ 115200\ (9600)\
|
||||||
\f[]
|
\f[]
|
||||||
.fi
|
.fi
|
||||||
.PP
|
.PP
|
||||||
|
46
picocom.1.md
46
picocom.1.md
@ -9,7 +9,7 @@ header: User Commands
|
|||||||
picocom - minimal dumb-terminal emulation program
|
picocom - minimal dumb-terminal emulation program
|
||||||
|
|
||||||
# SYNOPSIS
|
# SYNOPSIS
|
||||||
|
|
||||||
**picocom** [ _options_ ] _device_
|
**picocom** [ _options_ ] _device_
|
||||||
|
|
||||||
# DESCRIPTION
|
# 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
|
which by default is **C-a** (see **[OPTIONS]** below for how to change
|
||||||
it), and then keying one of the function (command) characters shown
|
it), and then keying one of the function (command) characters shown
|
||||||
here.
|
here.
|
||||||
|
|
||||||
*escape character*
|
*escape character*
|
||||||
|
|
||||||
: Send the escape character to the serial port and return to
|
: 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]**
|
: Send (upload) a file. See **[SENDING AND RECEIVING FILES]**
|
||||||
below.
|
below.
|
||||||
|
|
||||||
**C-r**
|
**C-r**
|
||||||
|
|
||||||
: Receive (download) a file. See **[SENDING AND RECEIVING FILES]**
|
: 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
|
one of: **x** for xon/xoff (software) mode, **h** for hardware
|
||||||
flow control (RTS/CTS), **n** for no flow control. (Default:
|
flow control (RTS/CTS), **n** for no flow control. (Default:
|
||||||
**n**)
|
**n**)
|
||||||
|
|
||||||
**--parity** | **-y**
|
**--parity** | **-y**
|
||||||
|
|
||||||
: Defines the parity mode to set the serial-port to. Must be one
|
: 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
|
: Defines the number of stop bits in every character. Must be one
|
||||||
of: **1**, or **2**. (Default: **1**)
|
of: **1**, or **2**. (Default: **1**)
|
||||||
|
|
||||||
**--escape** | **-e**
|
**--escape** | **-e**
|
||||||
|
|
||||||
: Defines the character that will make picocom enter command-mode
|
: Defines the character that will make picocom enter command-mode
|
||||||
(see description above). If **x** is given, then **C-x** will make
|
(see description above). If **x** is given, then **C-x** will make
|
||||||
picocom enter command mode. (Default: **a**)
|
picocom enter command mode. (Default: **a**)
|
||||||
|
|
||||||
**--echo** | **-c**
|
**--echo** | **-c**
|
||||||
|
|
||||||
: Enable local echo. Every character being read from the terminal
|
: 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
|
connection, or altering the settings. If required, serial port
|
||||||
parameters can then be adjusted at run-time by commands.
|
parameters can then be adjusted at run-time by commands.
|
||||||
(Default: Disabled)
|
(Default: Disabled)
|
||||||
|
|
||||||
**--noreset** | **-r**
|
**--noreset** | **-r**
|
||||||
|
|
||||||
: If given, picocom will not reset the serial port when exiting. It
|
: 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
|
"Exit"), which never resets the serial port. If **--noreset** is
|
||||||
given then "Quit" and "Exit" behave essentially the
|
given then "Quit" and "Exit" behave essentially the
|
||||||
same. (Default: Disabled)
|
same. (Default: Disabled)
|
||||||
|
|
||||||
**--nolock** | **-l**
|
**--nolock** | **-l**
|
||||||
|
|
||||||
: If given, picocom will _not_ attempt to lock the serial port
|
: 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
|
is possible that your picocom binary is compiled without support
|
||||||
for locking. In this case the **--nolock** option is accepted, but
|
for locking. In this case the **--nolock** option is accepted, but
|
||||||
has no effect. (Default: Disabled)
|
has no effect. (Default: Disabled)
|
||||||
|
|
||||||
**--send-cmd** | **-s**
|
**--send-cmd** | **-s**
|
||||||
|
|
||||||
: Specifies the external program (and any arguments to it) that will
|
: Specifies the external program (and any arguments to it) that will
|
||||||
be used for transmitting files. If the argument to **--send-cmd**
|
be used for transmitting files. If the argument to **--send-cmd**
|
||||||
is the empty string (''), the send-file command is disabled. See
|
is the empty string (''), the send-file command is disabled. See
|
||||||
**[SENDING AND RECEIVING FILES]**. (Default: **sz -vv**)
|
**[SENDING AND RECEIVING FILES]**. (Default: **sz -vv**)
|
||||||
|
|
||||||
**--receive-cmd** | **-v**
|
**--receive-cmd** | **-v**
|
||||||
|
|
||||||
: Specifies the external program (and any arguments to it) that will
|
: 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
|
is the empty string (''), the receive-file command is
|
||||||
disabled. See **[SENDING AND RECEIVING FILES]**. (Default: **rz
|
disabled. See **[SENDING AND RECEIVING FILES]**. (Default: **rz
|
||||||
-vv**)
|
-vv**)
|
||||||
|
|
||||||
**--imap**
|
**--imap**
|
||||||
|
|
||||||
: Specifies the input character map (i.e. special characters to be
|
: Specifies the input character map (i.e. special characters to be
|
||||||
replaced when read from the serial port). See
|
replaced when read from the serial port). See
|
||||||
**[INPUT, OUTPUT, AND ECHO MAPPING]**. (Defaul: Empty)
|
**[INPUT, OUTPUT, AND ECHO MAPPING]**. (Defaul: Empty)
|
||||||
|
|
||||||
**--omap**
|
**--omap**
|
||||||
|
|
||||||
: Specifies the output character map (i.e. special characters to be
|
: Specifies the output character map (i.e. special characters to be
|
||||||
replaced before being written to serial port). See
|
replaced before being written to serial port). See
|
||||||
**[INPUT, OUTPUT, AND ECHO MAPPING]**. (Defaul: Empty)
|
**[INPUT, OUTPUT, AND ECHO MAPPING]**. (Defaul: Empty)
|
||||||
|
|
||||||
**--emap**
|
**--emap**
|
||||||
|
|
||||||
: Specifies the local-echo character map (i.e. special characters to
|
: 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.
|
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
|
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)
|
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
|
is shown followed by the value of the actual serial-port setting in
|
||||||
parenthesis. Example:
|
parenthesis. Example:
|
||||||
|
|
||||||
*** baud: 115200 (9600)
|
*** baud: 115200 (9600)
|
||||||
|
|
||||||
This means that a baud rate of 115200bps has been selected (from the
|
This means that a baud rate of 115200bps has been selected (from the
|
||||||
command line, or using commands that change the baudrate) but 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
|
- **sb(1)** - send using the Y-MODEM protocol
|
||||||
- **sz(1)** - send using the Z-MODEM protocol
|
- **sz(1)** - send using the Z-MODEM protocol
|
||||||
- **ascii-xfr(1)** - receive or transmit ASCII files
|
- **ascii-xfr(1)** - receive or transmit ASCII files
|
||||||
|
|
||||||
The name of, and the command-line options to, the program to be used
|
The name of, and the command-line options to, the program to be used
|
||||||
for transmitting files are given by the **--send-cmd**
|
for transmitting files are given by the **--send-cmd**
|
||||||
option. Similarly the program to receive files, and its arguments, are
|
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
|
**--emap**). These mapping options take, each, a single argument which
|
||||||
is a comma-separated list of one or more of the following identifiers:
|
is a comma-separated list of one or more of the following identifiers:
|
||||||
|
|
||||||
- **crlf** (map CR to LF),
|
- **crlf** (map CR to LF),
|
||||||
- **crcrlf** (map CR to CR + LF),
|
- **crcrlf** (map CR to CR + LF),
|
||||||
- **igncr** (ignore CR),
|
- **igncr** (ignore CR),
|
||||||
- **lfcr** (map LF to CR),
|
- **lfcr** (map LF to CR),
|
||||||
- **lfcrlf** (map LF to CR + LF),
|
- **lfcrlf** (map LF to CR + LF),
|
||||||
- **ignlf** (ignore LF),
|
- **ignlf** (ignore LF),
|
||||||
- **bsdel** (map BS to DEL),
|
- **bsdel** (map BS to DEL),
|
||||||
- **delbs** (map DEL to BS)
|
- **delbs** (map DEL to BS)
|
||||||
|
|
||||||
For example the command:
|
For example the command:
|
||||||
|
|
||||||
picocom --omap crlf,delbs --imap ignlf,bsdel --emap crcrlf ...
|
picocom --omap crlf,delbs --imap ignlf,bsdel --emap crcrlf ...
|
||||||
|
|
||||||
will:
|
will:
|
||||||
|
|
||||||
- Replace every CR (carriage return, 0x0d) character with LF (line
|
- Replace every CR (carriage return, 0x0d) character with LF (line
|
||||||
feed, 0x0a) and every DEL (delete, 0x7f) character with BS
|
feed, 0x0a) and every DEL (delete, 0x7f) character with BS
|
||||||
|
10
split.c
10
split.c
@ -19,7 +19,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
* USA
|
* USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -81,7 +81,7 @@ enum states {
|
|||||||
} else { \
|
} else { \
|
||||||
flags |= SPLIT_TRUNC; \
|
flags |= SPLIT_TRUNC; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
int
|
int
|
||||||
split_quoted (const char *s, int *argc, char *argv[], int argv_sz)
|
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:
|
case ST_DELIM:
|
||||||
while ( is_delim(*c) ) c++;
|
while ( is_delim(*c) ) c++;
|
||||||
if ( *c == SQ || *c == DQ ) {
|
if ( *c == SQ || *c == DQ ) {
|
||||||
qc = *c; c++; state = ST_QUOTE;
|
qc = *c; c++; state = ST_QUOTE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ( *c == EOS ) {
|
if ( *c == EOS ) {
|
||||||
@ -187,7 +187,7 @@ split_quoted (const char *s, int *argc, char *argv[], int argv_sz)
|
|||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ( err != ERR_OK ) ? -1 : flags;
|
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]);
|
printf("Usage is: %s: <string to split>\n", argv[0]);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("String to split is: [%s]\n", argv[1]);
|
printf("String to split is: [%s]\n", argv[1]);
|
||||||
r = split_quoted(argv[1], &my_argc, my_argv, 12);
|
r = split_quoted(argv[1], &my_argc, my_argv, 12);
|
||||||
if ( r < 0 ) {
|
if ( r < 0 ) {
|
||||||
|
4
split.h
4
split.h
@ -19,7 +19,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
* USA
|
* USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SPLIT_H
|
#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 --> [a 'b'] [c] [d]
|
* "a 'b'" c d --> [a 'b'] [c] [d]
|
||||||
* a"b c" d --> [ab 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 --> [ab] [c] [d]
|
||||||
* \a\\b \\ c d --> [a\b] [\] [c] [d]
|
* \a\\b \\ c d --> [a\b] [\] [c] [d]
|
||||||
* "a\$\b" c d --> [a$\b] [c] [d]
|
* "a\$\b" c d --> [a$\b] [c] [d]
|
||||||
|
122
term.h
122
term.h
@ -94,7 +94,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
* 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 $
|
* $Id: term.h,v 1.1 2003/05/07 18:00:05 npat Exp $
|
||||||
*/
|
*/
|
||||||
@ -122,31 +122,31 @@
|
|||||||
* See the error strings in "term.c" for a description of each.
|
* See the error strings in "term.c" for a description of each.
|
||||||
*/
|
*/
|
||||||
enum term_errno_e {
|
enum term_errno_e {
|
||||||
TERM_EOK = 0,
|
TERM_EOK = 0,
|
||||||
TERM_ENOINIT,
|
TERM_ENOINIT,
|
||||||
TERM_EFULL,
|
TERM_EFULL,
|
||||||
TERM_ENOTFOUND,
|
TERM_ENOTFOUND,
|
||||||
TERM_EEXISTS,
|
TERM_EEXISTS,
|
||||||
TERM_EATEXIT,
|
TERM_EATEXIT,
|
||||||
TERM_EISATTY,
|
TERM_EISATTY,
|
||||||
TERM_EFLUSH, /* see errno */
|
TERM_EFLUSH, /* see errno */
|
||||||
TERM_EGETATTR, /* see errno */
|
TERM_EGETATTR, /* see errno */
|
||||||
TERM_ESETATTR, /* see errno */
|
TERM_ESETATTR, /* see errno */
|
||||||
TERM_EBAUD,
|
TERM_EBAUD,
|
||||||
TERM_ESETOSPEED,
|
TERM_ESETOSPEED,
|
||||||
TERM_ESETISPEED,
|
TERM_ESETISPEED,
|
||||||
TERM_EGETSPEED,
|
TERM_EGETSPEED,
|
||||||
TERM_EPARITY,
|
TERM_EPARITY,
|
||||||
TERM_EDATABITS,
|
TERM_EDATABITS,
|
||||||
TERM_ESTOPBITS,
|
TERM_ESTOPBITS,
|
||||||
TERM_EFLOW,
|
TERM_EFLOW,
|
||||||
TERM_EDTRDOWN,
|
TERM_EDTRDOWN,
|
||||||
TERM_EDTRUP,
|
TERM_EDTRUP,
|
||||||
TERM_EMCTL,
|
TERM_EMCTL,
|
||||||
TERM_EDRAIN, /* see errno */
|
TERM_EDRAIN, /* see errno */
|
||||||
TERM_EBREAK,
|
TERM_EBREAK,
|
||||||
TERM_ERTSDOWN,
|
TERM_ERTSDOWN,
|
||||||
TERM_ERTSUP
|
TERM_ERTSUP
|
||||||
};
|
};
|
||||||
|
|
||||||
/* E parity_e
|
/* E parity_e
|
||||||
@ -160,32 +160,32 @@ enum term_errno_e {
|
|||||||
* P_SPACE - space parity (parity bit always 0)
|
* P_SPACE - space parity (parity bit always 0)
|
||||||
*/
|
*/
|
||||||
enum parity_e {
|
enum parity_e {
|
||||||
P_NONE = 0,
|
P_NONE = 0,
|
||||||
P_EVEN,
|
P_EVEN,
|
||||||
P_ODD,
|
P_ODD,
|
||||||
P_MARK,
|
P_MARK,
|
||||||
P_SPACE
|
P_SPACE
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* E flowcntrl_e
|
* E flowcntrl_e
|
||||||
*
|
*
|
||||||
* Flow control modes, supported by the library.
|
* Flow control modes, supported by the library.
|
||||||
*
|
*
|
||||||
* FC_NONE - no flow control
|
* 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.
|
* flow-control.
|
||||||
* FC_XONXOFF - xon/xoff flow control.
|
* FC_XONXOFF - xon/xoff flow control.
|
||||||
*/
|
*/
|
||||||
enum flowcntrl_e {
|
enum flowcntrl_e {
|
||||||
FC_NONE = 0,
|
FC_NONE = 0,
|
||||||
FC_RTSCTS,
|
FC_RTSCTS,
|
||||||
FC_XONXOFF,
|
FC_XONXOFF,
|
||||||
FC_OTHER
|
FC_OTHER
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* C MCTL_xxx
|
* C MCTL_xxx
|
||||||
*
|
*
|
||||||
* Modem control line bits. Used against the return value of
|
* Modem control line bits. Used against the return value of
|
||||||
* term_get_mctl().
|
* 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)
|
* Emit a description of the current library (and possibly system)
|
||||||
* error condition to the standard-error stream. The description is
|
* error condition to the standard-error stream. The description is
|
||||||
* prefixed by a user-supplied string. What is actually emmited is:
|
* prefixed by a user-supplied string. What is actually emmited is:
|
||||||
*
|
*
|
||||||
* <prefix><space><description>\n
|
* <prefix><space><description>\n
|
||||||
*
|
*
|
||||||
* The description emitted is the string returned by term_strerror().
|
* 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);
|
int term_replace (int oldfd, int newfd);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* F term_apply
|
* F term_apply
|
||||||
*
|
*
|
||||||
* Applies the settings stored in the "nexttermios" structure
|
* Applies the settings stored in the "nexttermios" structure
|
||||||
* associated with the managed filedes "fd", to the respective
|
* 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);
|
int term_apply (int fd, int now);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* F term_revert
|
* F term_revert
|
||||||
*
|
*
|
||||||
* Discards all the changes made to the nexttermios structure
|
* Discards all the changes made to the nexttermios structure
|
||||||
* associated with the managed filedes "fd" that have not been applied
|
* 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);
|
int term_reset (int fd);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* F term_refresh
|
* F term_refresh
|
||||||
*
|
*
|
||||||
* Updates the contents of the currtermios structure associated with
|
* Updates the contents of the currtermios structure associated with
|
||||||
* the managed filedes "fd", by reading the settings from the
|
* the managed filedes "fd", by reading the settings from the
|
||||||
@ -377,11 +377,11 @@ int term_reset (int fd);
|
|||||||
int term_refresh (int fd);
|
int term_refresh (int fd);
|
||||||
|
|
||||||
/* F term_set_raw
|
/* F term_set_raw
|
||||||
*
|
*
|
||||||
* Sets the "nexttermios" structure associated with the managed
|
* Sets the "nexttermios" structure associated with the managed
|
||||||
* filedes "fd" to raw mode. The effective settings of the device are
|
* filedes "fd" to raw mode. The effective settings of the device are
|
||||||
* not affected by this function.
|
* not affected by this function.
|
||||||
*
|
*
|
||||||
* Returns negative on failure, non-negative on success. Returns
|
* Returns negative on failure, non-negative on success. Returns
|
||||||
* failure only to indicate invalid arguments, so the return value can
|
* failure only to indicate invalid arguments, so the return value can
|
||||||
* be safely ignored.
|
* be safely ignored.
|
||||||
@ -392,7 +392,7 @@ int term_refresh (int fd);
|
|||||||
* terminal settings as indicated:
|
* terminal settings as indicated:
|
||||||
*
|
*
|
||||||
* -ignbrk -brkint -parmrk -istrip -inlcr -igncr -icrnl -ixon
|
* -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
|
* cs8 min=1 time=0
|
||||||
*/
|
*/
|
||||||
int term_set_raw (int fd);
|
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);
|
int term_set_parity (int fd, enum parity_e parity);
|
||||||
|
|
||||||
/* F term_set_databits
|
/* F term_set_databits
|
||||||
*
|
*
|
||||||
* Sets the databits number in the "nexttermios" structure associated
|
* Sets the databits number in the "nexttermios" structure associated
|
||||||
* with the managed filedes "fd" to "databits". The effective settings
|
* with the managed filedes "fd" to "databits". The effective settings
|
||||||
* of the device are not affected by this function.
|
* 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);
|
int term_set_databits (int fd, int databits);
|
||||||
|
|
||||||
/* F term_set_stopbits
|
/* F term_set_stopbits
|
||||||
*
|
*
|
||||||
* Sets the stopbits number in the "nexttermios" structure associated
|
* Sets the stopbits number in the "nexttermios" structure associated
|
||||||
* with the managed filedes "fd" to "stopbits". The effective settings
|
* with the managed filedes "fd" to "stopbits". The effective settings
|
||||||
* of the device are not affected by this function.
|
* 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
|
* Sets the folwcontrol mode in the "nexttermios" structure associated
|
||||||
* with the managed filedes "fd" to "flowcntl". The effective settings
|
* with the managed filedes "fd" to "flowcntl". The effective settings
|
||||||
* of the device are not affected by this function.
|
* of the device are not affected by this function.
|
||||||
*
|
*
|
||||||
* The following flow control modes are supportd by the library:
|
* The following flow control modes are supportd by the library:
|
||||||
* FC_NONE, FC_RTSCTS, FC_XONXOFF.
|
* 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
|
* Returns negative on failure, non negative on success. Returns
|
||||||
* failure only to indicate invalid arguments, so the return value can
|
* 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);
|
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
|
* Returns negative on failure, non negative on success. Returns
|
||||||
* failure only to indicate invalid arguments, so the return value can
|
* 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);
|
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
|
* associated with the managed filedes "fd". Actually sets the
|
||||||
* following:
|
* following:
|
||||||
*
|
*
|
||||||
* Raw mode if "raw" is nonzero.
|
* Raw mode if "raw" is nonzero.
|
||||||
* Baudrate to "baud".
|
* Baudrate to "baud".
|
||||||
* Parity mode to "parity".
|
* Parity mode to "parity".
|
||||||
* Flow control mode to "fc".
|
* Flow control mode to "fc".
|
||||||
* Enables local mode if "local" is nonzero, dis. otherwise.
|
* Enables local mode if "local" is nonzero, dis. otherwise.
|
||||||
* Enables HUP-on-close if "hupcl" 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
|
* The effective settings of the device are not affected by this
|
||||||
@ -520,13 +520,13 @@ int term_set_local (int fd, int local);
|
|||||||
* filedes to the framework, and following this it fails, then it will
|
* filedes to the framework, and following this it fails, then it will
|
||||||
* remove the filedes before returning.
|
* remove the filedes before returning.
|
||||||
*/
|
*/
|
||||||
int term_set (int fd,
|
int term_set (int fd,
|
||||||
int raw,
|
int raw,
|
||||||
int baud,
|
int baud,
|
||||||
enum parity_e parity,
|
enum parity_e parity,
|
||||||
int databits, int stopbits,
|
int databits, int stopbits,
|
||||||
enum flowcntrl_e fc,
|
enum flowcntrl_e fc,
|
||||||
int local, int hupcl);
|
int local, int hupcl);
|
||||||
|
|
||||||
/* F term_get_baudrate
|
/* F term_get_baudrate
|
||||||
*
|
*
|
||||||
@ -638,7 +638,7 @@ int term_raise_rts (int fd);
|
|||||||
*/
|
*/
|
||||||
int term_get_mctl (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
|
* Drains (flushes) the output queue of the device associated with the
|
||||||
* managed filedes "fd". This functions blocks until all the contents
|
* 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);
|
int term_drain (int fd);
|
||||||
|
|
||||||
/* F term_flush
|
/* F term_flush
|
||||||
*
|
*
|
||||||
* Discards all the contents of the input AND output queues of the
|
* Discards all the contents of the input AND output queues of the
|
||||||
* device associated with the managed filedes "fd". Although it is
|
* device associated with the managed filedes "fd". Although it is
|
||||||
* called flush this functions does NOT FLUSHES the terminal
|
* called flush this functions does NOT FLUSHES the terminal
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
*
|
*
|
||||||
* by Nick Patavalis (npat@efault.net)
|
* 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
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License as
|
* 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
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
* USA
|
* USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TERMBITS2_H
|
#ifndef TERMBITS2_H
|
||||||
@ -56,7 +56,7 @@
|
|||||||
cannot get the definion of "struct termios2" from the above header
|
cannot get the definion of "struct termios2" from the above header
|
||||||
files, since this would also bring-in the clashing definition of the
|
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
|
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
|
I hope that soon GLIBC will pick-up termios2 and all these will be
|
||||||
useless. Until then ...
|
useless. Until then ...
|
||||||
|
164
termios2.c
164
termios2.c
@ -5,7 +5,7 @@
|
|||||||
*
|
*
|
||||||
* by Nick Patavalis (npat@efault.net)
|
* 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
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License as
|
* 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
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
* USA
|
* USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(__linux__) && defined(USE_CUSTOM_BAUD)
|
#if defined(__linux__) && defined(USE_CUSTOM_BAUD)
|
||||||
@ -45,68 +45,68 @@
|
|||||||
/* GLIBC termios use an (otherwise unused) bit in c_iflags to
|
/* GLIBC termios use an (otherwise unused) bit in c_iflags to
|
||||||
internally record the fact that ispeed was set to zero (which is
|
internally record the fact that ispeed was set to zero (which is
|
||||||
special behavior and means "same as ospeed". We want to clear this
|
special behavior and means "same as ospeed". We want to clear this
|
||||||
bit before passing c_iflags back to the kernel. See:
|
bit before passing c_iflags back to the kernel. See:
|
||||||
|
|
||||||
<glibc-source>/sysdeps/unix/sysv/linux/speed.c
|
<glibc-source>/sysdeps/unix/sysv/linux/speed.c
|
||||||
*/
|
*/
|
||||||
#define IBAUD0 020000000000
|
#define IBAUD0 020000000000
|
||||||
|
|
||||||
int
|
int
|
||||||
tc2setattr(int fd, int optional_actions, const struct termios *tios)
|
tc2setattr(int fd, int optional_actions, const struct termios *tios)
|
||||||
{
|
{
|
||||||
struct termios2 t2;
|
struct termios2 t2;
|
||||||
int cmd;
|
int cmd;
|
||||||
|
|
||||||
switch (optional_actions) {
|
switch (optional_actions) {
|
||||||
case TCSANOW:
|
case TCSANOW:
|
||||||
cmd = IOCTL_SETS;
|
cmd = IOCTL_SETS;
|
||||||
break;
|
break;
|
||||||
case TCSADRAIN:
|
case TCSADRAIN:
|
||||||
cmd = IOCTL_SETSW;
|
cmd = IOCTL_SETSW;
|
||||||
break;
|
break;
|
||||||
case TCSAFLUSH:
|
case TCSAFLUSH:
|
||||||
cmd = IOCTL_SETSF;
|
cmd = IOCTL_SETSF;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
t2.c_iflag = tios->c_iflag & ~IBAUD0;
|
t2.c_iflag = tios->c_iflag & ~IBAUD0;
|
||||||
t2.c_oflag = tios->c_oflag;
|
t2.c_oflag = tios->c_oflag;
|
||||||
t2.c_cflag = tios->c_cflag;
|
t2.c_cflag = tios->c_cflag;
|
||||||
t2.c_lflag = tios->c_lflag;
|
t2.c_lflag = tios->c_lflag;
|
||||||
t2.c_line = tios->c_line;
|
t2.c_line = tios->c_line;
|
||||||
t2.c_ispeed = tios->c_ispeed;
|
t2.c_ispeed = tios->c_ispeed;
|
||||||
t2.c_ospeed = tios->c_ospeed;
|
t2.c_ospeed = tios->c_ospeed;
|
||||||
memcpy(&t2.c_cc[0], &tios->c_cc[0], K_NCCS * sizeof (cc_t));
|
memcpy(&t2.c_cc[0], &tios->c_cc[0], K_NCCS * sizeof (cc_t));
|
||||||
|
|
||||||
return ioctl(fd, cmd, &t2);
|
return ioctl(fd, cmd, &t2);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
tc2getattr(int fd, struct termios *tios)
|
tc2getattr(int fd, struct termios *tios)
|
||||||
{
|
{
|
||||||
struct termios2 t2;
|
struct termios2 t2;
|
||||||
size_t i;
|
size_t i;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = ioctl(fd, IOCTL_GETS, &t2);
|
r = ioctl(fd, IOCTL_GETS, &t2);
|
||||||
if (r < 0) return r;
|
if (r < 0) return r;
|
||||||
|
|
||||||
tios->c_iflag = t2.c_iflag;
|
tios->c_iflag = t2.c_iflag;
|
||||||
tios->c_oflag = t2.c_oflag;
|
tios->c_oflag = t2.c_oflag;
|
||||||
tios->c_cflag = t2.c_cflag;
|
tios->c_cflag = t2.c_cflag;
|
||||||
tios->c_lflag = t2.c_lflag;
|
tios->c_lflag = t2.c_lflag;
|
||||||
tios->c_line = t2.c_line;
|
tios->c_line = t2.c_line;
|
||||||
tios->c_ispeed = t2.c_ispeed;
|
tios->c_ispeed = t2.c_ispeed;
|
||||||
tios->c_ospeed = t2.c_ospeed;
|
tios->c_ospeed = t2.c_ospeed;
|
||||||
memcpy(&tios->c_cc[0], &t2.c_cc[0], K_NCCS * sizeof (cc_t));
|
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;
|
|
||||||
|
|
||||||
return 0;
|
for (i = K_NCCS; i < NCCS; i++)
|
||||||
|
tios->c_cc[i] = _POSIX_VDISABLE;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The termios2 interface supports separate input and output
|
/* The termios2 interface supports separate input and output
|
||||||
@ -124,22 +124,22 @@ tc2getattr(int fd, struct termios *tios)
|
|||||||
int
|
int
|
||||||
cf2setispeed(struct termios *tios, speed_t speed)
|
cf2setispeed(struct termios *tios, speed_t speed)
|
||||||
{
|
{
|
||||||
if ( (speed & ~CBAUD) != 0
|
if ( (speed & ~CBAUD) != 0
|
||||||
&& (speed < B57600 || speed > __MAX_BAUD) ) {
|
&& (speed < B57600 || speed > __MAX_BAUD) ) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
tios->c_ispeed = speed;
|
tios->c_ispeed = speed;
|
||||||
tios->c_cflag &= ~((CBAUD | CBAUDEX) << IBSHIFT);
|
tios->c_cflag &= ~((CBAUD | CBAUDEX) << IBSHIFT);
|
||||||
tios->c_cflag |= (speed << IBSHIFT);
|
tios->c_cflag |= (speed << IBSHIFT);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
speed_t
|
speed_t
|
||||||
cf2getispeed(struct termios *tios)
|
cf2getispeed(struct termios *tios)
|
||||||
{
|
{
|
||||||
return (tios->c_cflag >> IBSHIFT) & (CBAUD | CBAUDEX);
|
return (tios->c_cflag >> IBSHIFT) & (CBAUD | CBAUDEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Use these to set custom input or output speeds (i.e. speeds that do
|
/* Use these to set custom input or output speeds (i.e. speeds that do
|
||||||
@ -148,37 +148,37 @@ cf2getispeed(struct termios *tios)
|
|||||||
int
|
int
|
||||||
cf2setospeed_custom(struct termios *tios, int speed)
|
cf2setospeed_custom(struct termios *tios, int speed)
|
||||||
{
|
{
|
||||||
if ( speed <= 0 ) {
|
if ( speed <= 0 ) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
tios->c_cflag &= ~(CBAUD | CBAUDEX);
|
tios->c_cflag &= ~(CBAUD | CBAUDEX);
|
||||||
tios->c_cflag |= BOTHER;
|
tios->c_cflag |= BOTHER;
|
||||||
tios->c_ospeed = speed;
|
tios->c_ospeed = speed;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
cf2setispeed_custom(struct termios *tios, int speed)
|
cf2setispeed_custom(struct termios *tios, int speed)
|
||||||
{
|
{
|
||||||
if ( speed < 0 ) {
|
if ( speed < 0 ) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if ( speed == 0 ) {
|
if ( speed == 0 ) {
|
||||||
/* Special case: ispeed == 0 means "same as ospeed". Kernel
|
/* Special case: ispeed == 0 means "same as ospeed". Kernel
|
||||||
does this if it sees B0 in the "CIBAUD" field (i.e. in
|
does this if it sees B0 in the "CIBAUD" field (i.e. in
|
||||||
CBAUD << IBSHIFT) */
|
CBAUD << IBSHIFT) */
|
||||||
tios->c_cflag &= ~((CBAUD | CBAUDEX) << IBSHIFT);
|
tios->c_cflag &= ~((CBAUD | CBAUDEX) << IBSHIFT);
|
||||||
tios->c_cflag |= (B0 << IBSHIFT);
|
tios->c_cflag |= (B0 << IBSHIFT);
|
||||||
} else {
|
} else {
|
||||||
tios->c_cflag &= ~((CBAUD | CBAUDEX) << IBSHIFT);
|
tios->c_cflag &= ~((CBAUD | CBAUDEX) << IBSHIFT);
|
||||||
tios->c_cflag |= (BOTHER << IBSHIFT);
|
tios->c_cflag |= (BOTHER << IBSHIFT);
|
||||||
tios->c_ispeed = speed;
|
tios->c_ispeed = speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
*
|
*
|
||||||
* by Nick Patavalis (npat@efault.net)
|
* 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
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License as
|
* 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
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
* USA
|
* USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TERMIOS2_H
|
#ifndef TERMIOS2_H
|
||||||
|
@ -7,7 +7,7 @@ through the "new" "termios2" terminal-attributes structure, and the
|
|||||||
respective ioctls: TCSETS2, TCSETSW2, TCSETSF2, and TCGETS2.
|
respective ioctls: TCSETS2, TCSETSW2, TCSETSF2, and TCGETS2.
|
||||||
|
|
||||||
The "termios2" structure is defined in:
|
The "termios2" structure is defined in:
|
||||||
|
|
||||||
<linux-kernel>/arch/<arch>/include/uapi/asm/termbits.h
|
<linux-kernel>/arch/<arch>/include/uapi/asm/termbits.h
|
||||||
or <linux-kernel>/include/uapi/asm-generic/termbits.h
|
or <linux-kernel>/include/uapi/asm-generic/termbits.h
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user