mirror of
https://github.com/UzixLS/picocom.git
synced 2025-07-19 07:21:18 +03:00
Added field "name" to term struct
This commit is contained in:
@ -2105,9 +2105,11 @@ main (int argc, char *argv[])
|
||||
#endif
|
||||
|
||||
#ifdef USE_RFC2217
|
||||
r = term_add(tty_fd, opts.telnet ? &tn2217_ops : NULL);
|
||||
r = term_add(tty_fd,
|
||||
opts.telnet ? opts.port : NULL,
|
||||
opts.telnet ? &tn2217_ops : NULL);
|
||||
#else
|
||||
r = term_add(tty_fd, NULL);
|
||||
r = term_add(tty_fd, NULL, NULL);
|
||||
#endif
|
||||
if ( r >= 0 && ! opts.noinit ) {
|
||||
r = term_set(tty_fd,
|
||||
@ -2149,7 +2151,7 @@ main (int argc, char *argv[])
|
||||
|
||||
if ( ! opts.exit ) {
|
||||
if ( isatty(STI) ) {
|
||||
r = term_add(STI, NULL);
|
||||
r = term_add(STI, NULL, NULL);
|
||||
if ( r < 0 )
|
||||
fatal("failed to add I/O device: %s",
|
||||
term_strerror(term_errno, errno));
|
||||
|
36
term.c
36
term.c
@ -91,11 +91,20 @@ static int
|
||||
local_init(struct term_s *t)
|
||||
{
|
||||
int rval = 0;
|
||||
const char *n;
|
||||
|
||||
do { /* dummy */
|
||||
if ( ! isatty(t->fd) ) {
|
||||
term_errno = TERM_EISATTY;
|
||||
rval = -1;
|
||||
break;
|
||||
}
|
||||
if ( ! t->name ) {
|
||||
n = ttyname(t->fd);
|
||||
if ( n ) t->name = strdup(n);
|
||||
}
|
||||
} while (0);
|
||||
|
||||
if ( ! isatty(t->fd) ) {
|
||||
term_errno = TERM_EISATTY;
|
||||
rval = -1;
|
||||
}
|
||||
return rval;
|
||||
}
|
||||
|
||||
@ -421,7 +430,7 @@ term_baud_std(int baud)
|
||||
/**************************************************************************/
|
||||
|
||||
static struct term_s *
|
||||
term_new (int fd, const struct term_ops *ops)
|
||||
term_new (int fd, const char *name, const struct term_ops *ops)
|
||||
{
|
||||
int i;
|
||||
struct term_s *rval;
|
||||
@ -446,12 +455,17 @@ term_new (int fd, const struct term_ops *ops)
|
||||
memset(rval, 0, sizeof *rval);
|
||||
rval->fd = fd;
|
||||
rval->ops = ops;
|
||||
if ( name ) rval->name = strdup(name);
|
||||
|
||||
if (ops->init) {
|
||||
int r = ops->init(rval);
|
||||
if ( r < 0 ) {
|
||||
/* Failed to init, abandon allocation */
|
||||
rval->fd = -1;
|
||||
if ( rval->name ) {
|
||||
free(rval->name);
|
||||
rval->name = NULL;
|
||||
}
|
||||
rval = NULL;
|
||||
break;
|
||||
}
|
||||
@ -472,6 +486,10 @@ term_free (int fd)
|
||||
if (term[i].ops->fini)
|
||||
term[i].ops->fini(&term[i]);
|
||||
term[i].fd = -1;
|
||||
if ( term[i].name ) {
|
||||
free(term[i].name);
|
||||
term[i].name=NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -530,7 +548,7 @@ term_exitfunc (void)
|
||||
if ( r < 0 ) {
|
||||
const char *tname;
|
||||
|
||||
tname = ttyname(t->fd);
|
||||
tname = t->name;
|
||||
if ( ! tname ) tname = "UNKNOWN";
|
||||
fprintf(stderr, "%s: reset failed for dev %s: %s\r\n",
|
||||
__FUNCTION__, tname, strerror(errno));
|
||||
@ -575,7 +593,7 @@ term_lib_init (void)
|
||||
if ( r < 0 ) {
|
||||
const char *tname;
|
||||
|
||||
tname = ttyname(t->fd);
|
||||
tname = t->name;
|
||||
if ( ! tname ) tname = "UNKNOWN";
|
||||
fprintf(stderr, "%s: reset failed for dev %s: %s\n",
|
||||
__FUNCTION__, tname, strerror(errno));
|
||||
@ -602,7 +620,7 @@ term_lib_init (void)
|
||||
/***************************************************************************/
|
||||
|
||||
int
|
||||
term_add (int fd, const struct term_ops *ops)
|
||||
term_add (int fd, const char *name, const struct term_ops *ops)
|
||||
{
|
||||
int rval, r;
|
||||
struct term_s *t;
|
||||
@ -620,7 +638,7 @@ term_add (int fd, const struct term_ops *ops)
|
||||
if ( ! ops )
|
||||
ops = &local_term_ops;
|
||||
|
||||
t = term_new(fd, ops);
|
||||
t = term_new(fd, name, ops);
|
||||
if ( ! t ) {
|
||||
rval = -1;
|
||||
break;
|
||||
|
8
term.h
8
term.h
@ -285,14 +285,18 @@ int term_lib_init (void);
|
||||
* custom "ops" tables may be provided in order for them to interface
|
||||
* with the framework. For example, "tn2217.h" defines an "ops" table
|
||||
* that allows an RFC2217 connection filedes to be added to the
|
||||
* framework.
|
||||
* framework. The "name" string is a mnemonic name for the port
|
||||
* corresponding to the filedes. For native ports (ops == NULL) if
|
||||
* "name" is NULL, the ttyname(2) of the port will be used. The "name"
|
||||
* pointer must be valid (or NULL) for the duration of the call to the
|
||||
* function.
|
||||
*
|
||||
* The settings of the terminal device associated with the filedes
|
||||
* are read and stored in the origtermios structure.
|
||||
*
|
||||
* Returns negative on failure, non-negative on success.
|
||||
*/
|
||||
int term_add (int fd, const struct term_ops *ops);
|
||||
int term_add (int fd, const char *name, const struct term_ops *ops);
|
||||
|
||||
/* F term_remove
|
||||
*
|
||||
|
Reference in New Issue
Block a user