Re: [hackers] [dwm] [PATCH] add a comment to clarify a potential overflow of ltsymbol

2023-02-15 Thread Hiltjo Posthuma
On Wed, Feb 15, 2023 at 05:28:43PM +, Tom Schwindl wrote:
> Hi Hiltjo,
> 
> > Hi,
> >
> > I think it is too verbose and don't think the comment is neccesary.
> >
> 
> I can understand the verbosity part, but that's something I can change.
> My point here was more that bug reports get posted to the ML and I even
> get them in private or from people I know in person. So I think a comment,
> as you, yourself suggested, might be helpful.
> A simple "Hey, if you're exceeding 16 bytes we cannot guarantee for anything"
> would be enough (not in that tone, of course) for me.
> 
> -- 
> Best Regards,
> Tom Schwindl
> 
> > -- 
> > Kind regards,
> > Hiltjo
> 
> 
> 

NO

-- 
Kind regards,
Hiltjo



Re: [hackers] [dwm] [PATCH] add a comment to clarify a potential overflow of ltsymbol

2023-02-15 Thread Tom Schwindl
Hi Hiltjo,

> Hi,
>
> I think it is too verbose and don't think the comment is neccesary.
>

I can understand the verbosity part, but that's something I can change.
My point here was more that bug reports get posted to the ML and I even
get them in private or from people I know in person. So I think a comment,
as you, yourself suggested, might be helpful.
A simple "Hey, if you're exceeding 16 bytes we cannot guarantee for anything"
would be enough (not in that tone, of course) for me.

-- 
Best Regards,
Tom Schwindl

> -- 
> Kind regards,
> Hiltjo





Re: [hackers] [dwm] [PATCH] add a comment to clarify a potential overflow of ltsymbol

2023-02-15 Thread Hiltjo Posthuma
On Wed, Feb 15, 2023 at 11:29:26AM +, Tom Schwindl wrote:
> In case the strncpy() call is advised to copy >=16 characters, ltsymbol 
> overflows.
> As dwm does not expect to have a ltsymbol bigger than 15 characters, there 
> will be
> no length check[0]. Our target audience are programmers, they should be able
> to figure out how to extend the length by themselves. The reason to add this 
> comment
> is that some inexperienced users are easily confused by this and the topic 
> comes up
> from time to time[1].
> 
> [0] https://lists.suckless.org/hackers/2208/18484.html
> [1] https://lists.suckless.org/dev/2210/35000.html
> 
> ---
> I know that this patch looks like bikeshedding, but the comment is convenient.
> I also got messaged in private a few(!) times about that exact issue, but
> I'm not sure if I'm allowed to quote these mails here. Anyways, the point is
> that this issue arises from time to time and a comment would make our/their
> lifes easier.
> 
> ---
>  dwm.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/dwm.c b/dwm.c
> index c2bd8710544e..e400aa028587 100644
> --- a/dwm.c
> +++ b/dwm.c
> @@ -396,6 +396,9 @@ arrange(Monitor *m)
>  void
>  arrangemon(Monitor *m)
>  {
> + /* dwm supports a ltsymbol size up to 15 chars (plus terminating 
> NUL-byte).
> +  * Anything greater than that will cause issues. If the user wants a 
> name
> +  * containing more chars, they need to modify the code to fit their 
> needs */
>   strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol);
>   if (m->lt[m->sellt]->arrange)
>   m->lt[m->sellt]->arrange(m);
> -- 
> 2.39.1
> 
> 

Hi,

I think it is too verbose and don't think the comment is neccesary.

-- 
Kind regards,
Hiltjo



[hackers] [dwm] [PATCH] add a comment to clarify a potential overflow of ltsymbol

2023-02-15 Thread Tom Schwindl
In case the strncpy() call is advised to copy >=16 characters, ltsymbol 
overflows.
As dwm does not expect to have a ltsymbol bigger than 15 characters, there will 
be
no length check[0]. Our target audience are programmers, they should be able
to figure out how to extend the length by themselves. The reason to add this 
comment
is that some inexperienced users are easily confused by this and the topic 
comes up
from time to time[1].

[0] https://lists.suckless.org/hackers/2208/18484.html
[1] https://lists.suckless.org/dev/2210/35000.html

---
I know that this patch looks like bikeshedding, but the comment is convenient.
I also got messaged in private a few(!) times about that exact issue, but
I'm not sure if I'm allowed to quote these mails here. Anyways, the point is
that this issue arises from time to time and a comment would make our/their
lifes easier.

---
 dwm.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/dwm.c b/dwm.c
index c2bd8710544e..e400aa028587 100644
--- a/dwm.c
+++ b/dwm.c
@@ -396,6 +396,9 @@ arrange(Monitor *m)
 void
 arrangemon(Monitor *m)
 {
+   /* dwm supports a ltsymbol size up to 15 chars (plus terminating 
NUL-byte).
+* Anything greater than that will cause issues. If the user wants a 
name
+* containing more chars, they need to modify the code to fit their 
needs */
strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol);
if (m->lt[m->sellt]->arrange)
m->lt[m->sellt]->arrange(m);
-- 
2.39.1




[hackers] [lchat] update copyright || Tom Schwindl

2023-02-15 Thread git
commit e413932d58bda64d7e9e34ca1e455d13bad17a3e
Author: Tom Schwindl 
AuthorDate: Sat Jan 14 18:35:52 2023 +0100
Commit: Jan Klemkow 
CommitDate: Tue Jan 24 17:00:30 2023 +0100

update copyright

diff --git a/lchat.c b/lchat.c
index 4a59760..0df653d 100644
--- a/lchat.c
+++ b/lchat.c
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2015-2022 Jan Klemkow 
- * Copyright (c) 2022 Tom Schwindl 
+ * Copyright (c) 2015-2023 Jan Klemkow 
+ * Copyright (c) 2022-2023 Tom Schwindl 
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
diff --git a/slackline.c b/slackline.c
index a56c030..8668534 100644
--- a/slackline.c
+++ b/slackline.c
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2015-2022 Jan Klemkow 
- * Copyright (c) 2022 Tom Schwindl 
+ * Copyright (c) 2015-2023 Jan Klemkow 
+ * Copyright (c) 2022-2023 Tom Schwindl 
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
diff --git a/slackline_emacs.c b/slackline_emacs.c
index 352b226..fc95d82 100644
--- a/slackline_emacs.c
+++ b/slackline_emacs.c
@@ -1,3 +1,19 @@
+/*
+ * Copyright (c) 2022-2023 Tom Schwindl 
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
 #include 
 #include 
 #include 
diff --git a/util.c b/util.c
index 0516577..14e9d53 100644
--- a/util.c
+++ b/util.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Jan Klemkow 
+ * Copyright (c) 2018-2023 Jan Klemkow 
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above



[hackers] [lchat] slackline.h: fix typo in include guard || Tom Schwindl

2023-02-15 Thread git
commit d9d4077f33f59df8579af2866cea73d0664e9add
Author: Tom Schwindl 
AuthorDate: Sun Jan 15 01:01:06 2023 +0100
Commit: Jan Klemkow 
CommitDate: Tue Jan 24 16:59:40 2023 +0100

slackline.h: fix typo in include guard

diff --git a/slackline.h b/slackline.h
index 5039704..d2e0334 100644
--- a/slackline.h
+++ b/slackline.h
@@ -1,5 +1,5 @@
-#ifndef SLACKLIINE_H
-#define SLACKLIINE_H
+#ifndef SLACKLINE_H
+#define SLACKLINE_H
 
 enum esc_seq {ESC_NONE, ESC, ESC_BRACKET, ESC_BRACKET_NUM};
 enum mode {SL_DEFAULT, SL_EMACS, SL_VI};



[hackers] [lchat] slackline: restore some comments || Tom Schwindl

2023-02-15 Thread git
commit 8ce1eb2bb5bac39ed33dd3aace28d40a53878c16
Author: Tom Schwindl 
AuthorDate: Wed Jan 11 16:08:36 2023 +0100
Commit: Jan Klemkow 
CommitDate: Tue Jan 24 16:59:40 2023 +0100

slackline: restore some comments

diff --git a/slackline.c b/slackline.c
index 4573899..a56c030 100644
--- a/slackline.c
+++ b/slackline.c
@@ -164,7 +164,7 @@ sl_default(struct slackline *sl, int key)
case CTRL_U:
sl_reset(sl);
break;
-   case CTRL_W:
+   case CTRL_W: /* erase previous word */
while (sl->rcur != 0 && isspace((unsigned char) *(sl->ptr-1)))
sl_backspace(sl);
while (sl->rcur != 0 && !isspace((unsigned char) *(sl->ptr-1)))
diff --git a/slackline_emacs.c b/slackline_emacs.c
index a5ed7ab..352b226 100644
--- a/slackline_emacs.c
+++ b/slackline_emacs.c
@@ -15,13 +15,13 @@ sl_emacs(struct slackline *sl, int key)
case ESC_KEY:
sl->esc = ESC;
break;
-   case CTRL_A:
+   case CTRL_A:/* start of line */
sl_move(sl, HOME);
break;
-   case CTRL_B:
+   case CTRL_B: /* previous char */
sl_move(sl, LEFT);
break;
-   case CTRL_D:
+   case CTRL_D:/* delete char in front of the cursor or exit */
if (sl->rcur < sl->rlen) {
sl_move(sl, RIGHT);
sl_backspace(sl);
@@ -29,19 +29,19 @@ sl_emacs(struct slackline *sl, int key)
exit(EXIT_SUCCESS);
}
break;
-   case CTRL_E:
+   case CTRL_E:/* end of line */
sl_move(sl, END);
break;
-   case CTRL_F:
+   case CTRL_F:/* next char */
sl_move(sl, RIGHT);
break;
-   case CTRL_K:
+   case CTRL_K:/* delete line from cursor to end */
for (int i = sl->rlen - sl->rcur; i > 0; --i) {
sl_move(sl, RIGHT);
sl_backspace(sl);
}
break;
-   case CTRL_T:
+   case CTRL_T:/* swap last two chars */
if (sl->rcur >= 2) {
tmp = *sl_postoptr(sl, sl->rcur-1);
sl->buf[sl->rcur-1] = *sl_postoptr(sl, sl->rcur-2);



[hackers] [lchat] slackline: ctrl+w: stop deleting when certain characters occur || Tom Schwindl

2023-02-15 Thread git
commit 9778b6b675462220fa133aa7a13fe8e5d45be6d1
Author: Tom Schwindl 
AuthorDate: Mon Feb 6 15:42:58 2023 +0100
Commit: Jan Klemkow 
CommitDate: Wed Feb 15 09:30:17 2023 +0100

slackline: ctrl+w: stop deleting when certain characters occur

diff --git a/slackline.c b/slackline.c
index 8668534..889165a 100644
--- a/slackline.c
+++ b/slackline.c
@@ -26,6 +26,9 @@
 #include "slackline.h"
 #include "util.h"
 
+/* CTRL+W: stop erasing if certain characters are reached. */
+#define IS_WORD_BREAK "\f\n\r\t\v (){}[]\\/#,.=-+|%$!@^&*"
+
 struct slackline *
 sl_init(void)
 {
@@ -165,9 +168,9 @@ sl_default(struct slackline *sl, int key)
sl_reset(sl);
break;
case CTRL_W: /* erase previous word */
-   while (sl->rcur != 0 && isspace((unsigned char) *(sl->ptr-1)))
+   while (sl->rcur != 0 && strchr(IS_WORD_BREAK, *(sl->ptr-1)) != 
NULL)
sl_backspace(sl);
-   while (sl->rcur != 0 && !isspace((unsigned char) *(sl->ptr-1)))
+   while (sl->rcur != 0 && strchr(IS_WORD_BREAK, *(sl->ptr-1)) == 
NULL)
sl_backspace(sl);
break;
case BACKSPACE:



[hackers] [lchat] replace "magic"-numbers with symbolic constants || Tom Schwindl

2023-02-15 Thread git
commit 6d306ad60a3ed0d9e721a43fb121804974a41b6c
Author: Tom Schwindl 
AuthorDate: Wed Jan 11 09:05:39 2023 +0100
Commit: Jan Klemkow 
CommitDate: Tue Jan 24 16:59:40 2023 +0100

replace "magic"-numbers with symbolic constants

diff --git a/slackline.c b/slackline.c
index f23671e..4573899 100644
--- a/slackline.c
+++ b/slackline.c
@@ -158,20 +158,20 @@ static void
 sl_default(struct slackline *sl, int key)
 {
switch (key) {
-   case 27:/* Escape */
+   case ESC_KEY:
sl->esc = ESC;
break;
-   case 21:
+   case CTRL_U:
sl_reset(sl);
break;
-   case 23: /* ctrl+w -- erase previous word */
+   case CTRL_W:
while (sl->rcur != 0 && isspace((unsigned char) *(sl->ptr-1)))
sl_backspace(sl);
while (sl->rcur != 0 && !isspace((unsigned char) *(sl->ptr-1)))
sl_backspace(sl);
break;
-   case 127:   /* backspace */
-   case 8: /* backspace */
+   case BACKSPACE:
+   case VT_BACKSPACE:
sl_backspace(sl);
break;
default:
diff --git a/slackline_emacs.c b/slackline_emacs.c
index bd51042..fc58bd2 100644
--- a/slackline_emacs.c
+++ b/slackline_emacs.c
@@ -11,16 +11,16 @@ sl_emacs(struct slackline *sl, int key)
char tmp;
 
switch (key) {
-   case 27:/* Escape */
+   case ESC_KEY:
sl->esc = ESC;
break;
-   case 1: /* ctrl+a -- start of line */
+   case CTRL_A:
sl_move(sl, HOME);
break;
-   case 2: /* ctrl+b -- previous char */
+   case CTRL_B:
sl_move(sl, LEFT);
break;
-   case 4: /* ctrl+d -- delete char in front of the cursor or exit */
+   case CTRL_D:
if (sl->rcur < sl->rlen) {
sl_move(sl, RIGHT);
sl_backspace(sl);
@@ -28,19 +28,19 @@ sl_emacs(struct slackline *sl, int key)
exit(EXIT_SUCCESS);
}
break;
-   case 5: /* ctrl+e -- end of line */
+   case CTRL_E:
sl_move(sl, END);
break;
-   case 6: /* ctrl+f -- next char */
+   case CTRL_F:
sl_move(sl, RIGHT);
break;
-   case 11: /* ctrl+k -- delete line from cursor to end */
+   case CTRL_K:
for (int i = sl->rlen - sl->rcur; i > 0; --i) {
sl_move(sl, RIGHT);
sl_backspace(sl);
}
break;
-   case 20: /* ctrl+t -- swap last two chars */
+   case CTRL_T:
if (sl->rcur >= 2) {
tmp = *sl_postoptr(sl, sl->rcur-1);
sl->buf[sl->rcur-1] = *sl_postoptr(sl, sl->rcur-2);
diff --git a/slackline_internals.h b/slackline_internals.h
index aa22a4e..2f419e0 100644
--- a/slackline_internals.h
+++ b/slackline_internals.h
@@ -5,6 +5,23 @@
 
 enum direction {LEFT, RIGHT, HOME, END};
 
+enum {
+   CTRL_A = 1,
+   CTRL_B = 2,
+   CTRL_D = 4,
+   CTRL_E = 5,
+   CTRL_F = 6,
+   CTRL_K = 11,
+   CTRL_U = 21,
+   CTRL_T = 20,
+   CTRL_W = 23,
+
+   BACKSPACE = 127,
+   VT_BACKSPACE = 8,
+
+   ESC_KEY = 27
+};
+
 size_t sl_postobyte(struct slackline *sl, size_t pos);
 char *sl_postoptr(struct slackline *sl, size_t pos);
 void sl_backspace(struct slackline *sl);



[hackers] [lchat] slackline: do not include slackline.h in slackline_internals.h || Tom Schwindl

2023-02-15 Thread git
commit f730489e0a632bd738ade1e91c85c6ffdad21ba8
Author: Tom Schwindl 
AuthorDate: Wed Jan 11 09:17:47 2023 +0100
Commit: Jan Klemkow 
CommitDate: Tue Jan 24 16:59:40 2023 +0100

slackline: do not include slackline.h in slackline_internals.h

Although it's likely that slackline.h will be included alongside
slackline_internals.h, including headers in headers often results in 
confusion.

diff --git a/slackline_emacs.c b/slackline_emacs.c
index fc58bd2..a5ed7ab 100644
--- a/slackline_emacs.c
+++ b/slackline_emacs.c
@@ -3,6 +3,7 @@
 #include 
 #include 
 
+#include "slackline.h"
 #include "slackline_internals.h"
 
 void
diff --git a/slackline_internals.h b/slackline_internals.h
index 2f419e0..5206557 100644
--- a/slackline_internals.h
+++ b/slackline_internals.h
@@ -1,7 +1,7 @@
 #ifndef SLACKLINE_INTERNALS_H
 #define SLACKLINE_INTERNALS_H
 
-#include "slackline.h"
+struct slackline;
 
 enum direction {LEFT, RIGHT, HOME, END};
 



[hackers] [lchat] lchat: in case the `-m` flag receives an invalid mode, abort || Tom Schwindl

2023-02-15 Thread git
commit 3fc9c4d7ee1bd9a05b7bed3e835861923b6c9b28
Author: Tom Schwindl 
AuthorDate: Wed Jan 11 09:59:12 2023 +0100
Commit: Jan Klemkow 
CommitDate: Tue Jan 24 16:59:40 2023 +0100

lchat: in case the `-m` flag receives an invalid mode, abort

diff --git a/lchat.c b/lchat.c
index 35c5463..4a59760 100644
--- a/lchat.c
+++ b/lchat.c
@@ -221,6 +221,8 @@ main(int argc, char *argv[])
case 'm':
if (strcmp(optarg, "emacs") == 0)
sl_mode(sl, SL_EMACS);
+   else
+   die("lchat: invalid mode");
break;
case 'h':
default:



[hackers] [lchat] lchat.1: mention modes briefly || Tom Schwindl

2023-02-15 Thread git
commit 6dd484ff2d2a417037e56a205fc5ae22adaa6335
Author: Tom Schwindl 
AuthorDate: Wed Jan 11 08:56:10 2023 +0100
Commit: Jan Klemkow 
CommitDate: Tue Jan 24 16:59:40 2023 +0100

lchat.1: mention modes briefly

diff --git a/lchat.1 b/lchat.1
index df6b6ae..ebd172f 100644
--- a/lchat.1
+++ b/lchat.1
@@ -12,6 +12,7 @@
 .Op Fl t Ar title
 .Op Fl i Ar in
 .Op Fl o Ar out
+.Op Fl m Ar mode
 .Op directory
 .Sh DESCRIPTION
 The
@@ -69,6 +70,14 @@ as out-file.
 Default is 'out'.
 This overrides
 .Ar directory .
+.It Fl m Ar mode
+Use the specified
+.Ar mode .
+Currently, the only valid argument is
+.Ar emacs .
+See
+.Sy MODES
+for more information
 .It Ar directory
 Uses
 .Ar directory
@@ -89,6 +98,13 @@ contains the prompt string.
 .It .title
 contains the terminal window title.
 .El
+.Sh MODES
+.Nm
+is able to interpret keypresses differently depending on the mode it is
+operating in. Each mode defines a set of keybindings and corresponding actions.
+The mode cannot be changed while
+.Nm
+is running.
 .Sh SEE ALSO
 .Xr ii 1 ,
 .Xr tail 1