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

detabbing (by tab with 4)

This commit is contained in:
Joe Merten
2016-12-16 10:41:23 +01:00
parent b601136f56
commit 13fd331d41
7 changed files with 2338 additions and 2338 deletions

View File

@ -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

View File

@ -57,8 +57,8 @@ 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.
@ -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:

View File

@ -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);

2338
picocom.c

File diff suppressed because it is too large Load Diff

1986
term.c

File diff suppressed because it is too large Load Diff

64
term.h
View File

@ -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,11 +160,11 @@ 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
}; };
/* /*
@ -178,10 +178,10 @@ enum parity_e {
* 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
}; };
/* /*
@ -524,9 +524,9 @@ 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
* *

View File

@ -54,59 +54,59 @@
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++) for (i = K_NCCS; i < NCCS; i++)
tios->c_cc[i] = _POSIX_VDISABLE; tios->c_cc[i] = _POSIX_VDISABLE;
return 0; 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;
} }
/***************************************************************************/ /***************************************************************************/