Re: cu(1)/remote(5): add and document support for escape character capability

2019-03-24 Thread Nicholas Marriott


I personally think -E is enough, I don't know why you would need to
configure this per-host.


On Sun, Mar 24, 2019 at 04:18:58AM +0200, Artturi Alm wrote:
> Hi,
> 
> for completeness, would anything like the diff below be acceptable?
> 
> I might begin using /etc/remote soon, and I found the old remote.5[0]
> to have had this, and also described as such in remote(5) on
> docs.oracle.com, so i chose to reuse "es".
> 
> -Artturi
> 
> [0]: http://man.openbsd.org/OpenBSD-5.7/remote.5
> 
> 
> diff --git a/share/man/man5/remote.5 b/share/man/man5/remote.5
> index 2a50ca97d8a..b0d046a266a 100644
> --- a/share/man/man5/remote.5
> +++ b/share/man/man5/remote.5
> @@ -88,6 +88,15 @@ If this file refers to a terminal line,
>  .Xr cu 1
>  attempts to perform an exclusive open on the device to ensure only
>  one user at a time has access to the port.
> +.It Sy \
> +(str)
> +The escape character for
> +.Xr cu 1 .
> +This should be a single character, or
> +.Ql ^
> +followed by a letter.
> +The default is
> +.Ql ~ .
>  .El
>  .Sh FILES
>  .Bl -tag -width /etc/remote -compact
> diff --git a/usr.bin/cu/cu.1 b/usr.bin/cu/cu.1
> index 5daab4bc074..61c723a45e4 100644
> --- a/usr.bin/cu/cu.1
> +++ b/usr.bin/cu/cu.1
> @@ -105,6 +105,7 @@ uses the
>  .Xr remote 5
>  database to retrieve the
>  .Sy dc Pq directly connected ,
> +.Sy es Pq escape character ,
>  .Sy dv Pq device
>  and
>  .Sy br Pq baud rate
> diff --git a/usr.bin/cu/cu.c b/usr.bin/cu/cu.c
> index 697f72d3418..cba4ff1601d 100644
> --- a/usr.bin/cu/cu.c
> +++ b/usr.bin/cu/cu.c
> @@ -41,7 +41,7 @@ FILE*record_file;
>  struct termiossaved_tio;
>  struct bufferevent   *input_ev;
>  struct bufferevent   *output_ev;
> -int   escape_char = '~';
> +int   escape_char = -1;
>  int   is_direct = -1;
>  int   restricted = 0;
>  const char   *line_path = NULL;
> @@ -159,6 +159,8 @@ main(int argc, char **argv)
>   }
>   }
>  
> + if (escape_char == -1)
> + escape_char = '~';
>   if (line_path == NULL)
>   line_path = "/dev/cua00";
>   if (line_speed == -1)
> @@ -402,6 +404,25 @@ try_remote(const char *host, const char *path, const 
> char *entry)
>   if (line_path == NULL && cgetstr(cp, "dv", ) >= 0)
>   line_path = s;
>  
> + s = NULL;
> + if (escape_char == -1 && cgetustr(cp, "es", ) >= 0) {
> + switch (strnlen(s, 3)) {
> + case 1:
> + escape_char = (u_char)s[0];
> + break;
> + case 2:
> + if (s[0] == '^' &&
> + (u_char)s[1] >= 64 && (u_char)s[1] < 128) {
> + escape_char = (u_char)s[1] & 31;
> + break;
> + }
> + /* FALLTHROUGH */
> + default:
> + cu_warnx("invalid escape character: %s", s);
> + }
> + free(s);
> + }
> +
>   if (line_speed == -1 && cgetnum(cp, "br", ) >= 0) {
>   if (l < 0 || l > INT_MAX)
>   cu_errx(1, "speed out of range");



cu(1)/remote(5): add and document support for escape character capability

2019-03-23 Thread Artturi Alm
Hi,

for completeness, would anything like the diff below be acceptable?

I might begin using /etc/remote soon, and I found the old remote.5[0]
to have had this, and also described as such in remote(5) on
docs.oracle.com, so i chose to reuse "es".

-Artturi

[0]: http://man.openbsd.org/OpenBSD-5.7/remote.5


diff --git a/share/man/man5/remote.5 b/share/man/man5/remote.5
index 2a50ca97d8a..b0d046a266a 100644
--- a/share/man/man5/remote.5
+++ b/share/man/man5/remote.5
@@ -88,6 +88,15 @@ If this file refers to a terminal line,
 .Xr cu 1
 attempts to perform an exclusive open on the device to ensure only
 one user at a time has access to the port.
+.It Sy \
+(str)
+The escape character for
+.Xr cu 1 .
+This should be a single character, or
+.Ql ^
+followed by a letter.
+The default is
+.Ql ~ .
 .El
 .Sh FILES
 .Bl -tag -width /etc/remote -compact
diff --git a/usr.bin/cu/cu.1 b/usr.bin/cu/cu.1
index 5daab4bc074..61c723a45e4 100644
--- a/usr.bin/cu/cu.1
+++ b/usr.bin/cu/cu.1
@@ -105,6 +105,7 @@ uses the
 .Xr remote 5
 database to retrieve the
 .Sy dc Pq directly connected ,
+.Sy es Pq escape character ,
 .Sy dv Pq device
 and
 .Sy br Pq baud rate
diff --git a/usr.bin/cu/cu.c b/usr.bin/cu/cu.c
index 697f72d3418..cba4ff1601d 100644
--- a/usr.bin/cu/cu.c
+++ b/usr.bin/cu/cu.c
@@ -41,7 +41,7 @@ FILE  *record_file;
 struct termios  saved_tio;
 struct bufferevent *input_ev;
 struct bufferevent *output_ev;
-int escape_char = '~';
+int escape_char = -1;
 int is_direct = -1;
 int restricted = 0;
 const char *line_path = NULL;
@@ -159,6 +159,8 @@ main(int argc, char **argv)
}
}
 
+   if (escape_char == -1)
+   escape_char = '~';
if (line_path == NULL)
line_path = "/dev/cua00";
if (line_speed == -1)
@@ -402,6 +404,25 @@ try_remote(const char *host, const char *path, const char 
*entry)
if (line_path == NULL && cgetstr(cp, "dv", ) >= 0)
line_path = s;
 
+   s = NULL;
+   if (escape_char == -1 && cgetustr(cp, "es", ) >= 0) {
+   switch (strnlen(s, 3)) {
+   case 1:
+   escape_char = (u_char)s[0];
+   break;
+   case 2:
+   if (s[0] == '^' &&
+   (u_char)s[1] >= 64 && (u_char)s[1] < 128) {
+   escape_char = (u_char)s[1] & 31;
+   break;
+   }
+   /* FALLTHROUGH */
+   default:
+   cu_warnx("invalid escape character: %s", s);
+   }
+   free(s);
+   }
+
if (line_speed == -1 && cgetnum(cp, "br", ) >= 0) {
if (l < 0 || l > INT_MAX)
cu_errx(1, "speed out of range");