Re: [PATCH 1/1] termbits: Convert octal defines to hex

2022-05-05 Thread Arnd Bergmann
On Thu, May 5, 2022 at 10:56 AM Ilpo Järvinen
 wrote:
> On Wed, 4 May 2022, Arnd Bergmann wrote:
> > On Wed, May 4, 2022 at 10:33 AM Ilpo Järvinen
> >  wrote:
> > > On Wed, 4 May 2022, Arnd Bergmann wrote:
> > > > On Wed, May 4, 2022 at 9:20 AM Ilpo Järvinen 
> > > >  wrote:
> > > > >
> > > > After applying the patch locally, I still see a bunch of whitespace
> > > > differences in the
> > > > changed lines if I run
> > > >
> > > > vimdiff arch/*/include/uapi/asm/termbits.h 
> > > > include/uapi/asm-generic/termbits.h
> > > >
> > > > I think this mostly because you left the sparc version alone (it already
> > > > uses hex constants), but it may be nice to edit this a little more to
> > > > make the actual differences stick out more.
> > >
> > > I took a look on further harmonizing, however, it turned out to be not
> > > that simple. This is basically the pipeline I use to further cleanup the
> > > differences and remove comments if you want to play yourself, just remove
> > > stages from the tail to get the intermediate datas (gawk is required for
> > > --non-decimal-data):
> >
> > I've played around with it some more to adjust the number of leading
> > zeroes and the type of whitespace. This is what I ended up with on top
> > of your patch: https://pastebin.com/raw/pkDPaKN1
> >
> > Feel free to fold it into yours.
>
> Ok thanks. With that it seems to go a bit beyond octal to hex conversion
> so I'll make a series out of it. The series will also introduce
> include/uapi/asm-generic/termbits-common.h for the most obvious
> intersection.

Ok, sounds good. Here's a retroactive

Signed-off-by: Arnd Bergmann 

for my changes so you can put them into a separate patch. I assume
you will change it some more in the process, so maybe retain
your ownership and just mark the bits a 'Co-developed-by: Arnd...'.

Arnd


Re: [PATCH 1/1] termbits: Convert octal defines to hex

2022-05-05 Thread Ilpo Järvinen
On Wed, 4 May 2022, Arnd Bergmann wrote:

> On Wed, May 4, 2022 at 10:33 AM Ilpo Järvinen
>  wrote:
> > On Wed, 4 May 2022, Arnd Bergmann wrote:
> > > On Wed, May 4, 2022 at 9:20 AM Ilpo Järvinen 
> > >  wrote:
> > > >
> > > After applying the patch locally, I still see a bunch of whitespace
> > > differences in the
> > > changed lines if I run
> > >
> > > vimdiff arch/*/include/uapi/asm/termbits.h 
> > > include/uapi/asm-generic/termbits.h
> > >
> > > I think this mostly because you left the sparc version alone (it already
> > > uses hex constants), but it may be nice to edit this a little more to
> > > make the actual differences stick out more.
> >
> > I took a look on further harmonizing, however, it turned out to be not
> > that simple. This is basically the pipeline I use to further cleanup the
> > differences and remove comments if you want to play yourself, just remove
> > stages from the tail to get the intermediate datas (gawk is required for
> > --non-decimal-data):
> 
> I've played around with it some more to adjust the number of leading
> zeroes and the type of whitespace. This is what I ended up with on top
> of your patch: https://pastebin.com/raw/pkDPaKN1
> 
> Feel free to fold it into yours.

Ok thanks. With that it seems to go a bit beyond octal to hex conversion 
so I'll make a series out of it. The series will also introduce 
include/uapi/asm-generic/termbits-common.h for the most obvious 
intersection.


-- 
 i.


Re: [PATCH 1/1] termbits: Convert octal defines to hex

2022-05-04 Thread Arnd Bergmann
On Wed, May 4, 2022 at 10:33 AM Ilpo Järvinen
 wrote:
> On Wed, 4 May 2022, Arnd Bergmann wrote:
> > On Wed, May 4, 2022 at 9:20 AM Ilpo Järvinen 
> >  wrote:
> > >
> > After applying the patch locally, I still see a bunch of whitespace
> > differences in the
> > changed lines if I run
> >
> > vimdiff arch/*/include/uapi/asm/termbits.h 
> > include/uapi/asm-generic/termbits.h
> >
> > I think this mostly because you left the sparc version alone (it already
> > uses hex constants), but it may be nice to edit this a little more to
> > make the actual differences stick out more.
>
> I took a look on further harmonizing, however, it turned out to be not
> that simple. This is basically the pipeline I use to further cleanup the
> differences and remove comments if you want to play yourself, just remove
> stages from the tail to get the intermediate datas (gawk is required for
> --non-decimal-data):

I've played around with it some more to adjust the number of leading
zeroes and the type of whitespace. This is what I ended up with on top
of your patch: https://pastebin.com/raw/pkDPaKN1

Feel free to fold it into yours.

Arnd


Re: [PATCH 1/1] termbits: Convert octal defines to hex

2022-05-04 Thread Michael Ellerman
Ilpo Järvinen  writes:
> Many archs have termbits.h as octal numbers. It makes hard for humans
> to parse the magnitude of large numbers correctly and to compare with
> hex ones of the same define.
>
> Convert octal values to hex.
>
> First step is an automated conversion with:
>
> for i in $(git ls-files | grep 'termbits\.h'); do
>   awk --non-decimal-data '/^#define\s+[A-Z][A-Z0-9]*\s+0[0-9]/ {
>   l=int(((length($3) - 1) * 3 + 3) / 4);
>   repl = sprintf("0x%0" l "x", $3);
>   print gensub(/[^[:blank:]]+/, repl, 3);
>   next} {print}' $i > $i~;
>   mv $i~ $i;
> done
>
> On top of that, some manual processing on alignment and number of zeros.
> In addition, small tweaks to formatting of a few comments on the same 
> lines.
>
> Signed-off-by: Ilpo Järvinen 
> ---
>
> I prefer this to go in though Greg's tty tree.
>
>  arch/alpha/include/uapi/asm/termbits.h   | 202 ++---
>  arch/mips/include/uapi/asm/termbits.h| 222 +++
>  arch/parisc/include/uapi/asm/termbits.h  | 220 +++---
>  arch/powerpc/include/uapi/asm/termbits.h | 202 ++---

I ran some horrible awk/sed/python mess over the before and after and
they seem to be numerically identical, so LGTM.

Acked-by: Michael Ellerman  (powerpc)

cheers


Re: [PATCH 1/1] termbits: Convert octal defines to hex

2022-05-04 Thread Ilpo Järvinen
On Wed, 4 May 2022, Arnd Bergmann wrote:

> On Wed, May 4, 2022 at 9:20 AM Ilpo Järvinen
>  wrote:
> >
> > Many archs have termbits.h as octal numbers. It makes hard for humans
> > to parse the magnitude of large numbers correctly and to compare with
> > hex ones of the same define.
> >
> > Convert octal values to hex.
> >
> > First step is an automated conversion with:
> >
> > for i in $(git ls-files | grep 'termbits\.h'); do
> > awk --non-decimal-data '/^#define\s+[A-Z][A-Z0-9]*\s+0[0-9]/ {
> > l=int(((length($3) - 1) * 3 + 3) / 4);
> > repl = sprintf("0x%0" l "x", $3);
> > print gensub(/[^[:blank:]]+/, repl, 3);
> > next} {print}' $i > $i~;
> > mv $i~ $i;
> > done
> >
> > On top of that, some manual processing on alignment and number of zeros.
> > In addition, small tweaks to formatting of a few comments on the same
> > lines.
> >
> > Signed-off-by: Ilpo Järvinen 
> 
> Good idea!
> 
> I assume you already checked if additional file contents can be shared across
> architectures? I think I've tried in the past but didn't really get
> anywhere with
> that.
> 
> After applying the patch locally, I still see a bunch of whitespace
> differences in the
> changed lines if I run
> 
> vimdiff arch/*/include/uapi/asm/termbits.h include/uapi/asm-generic/termbits.h
> 
> I think this mostly because you left the sparc version alone (it already
> uses hex constants), but it may be nice to edit this a little more to
> make the actual differences stick out more.

I took a look on further harmonizing, however, it turned out to be not 
that simple. This is basically the pipeline I use to further cleanup the 
differences and remove comments if you want to play yourself, just remove 
stages from the tail to get the intermediate datas (gawk is required for 
--non-decimal-data):

$ git ls-files | grep 'termbits\.h' | xargs grep -h -e '#define' | awk 
--non-decimal-data '{if (NF < 3) {next}; printf("#define %s\t0x%08x\n", $2, 
$3)}' | sort | uniq -c | sort | awk '{print $1}' | uniq -c
 82 1
 74 2
 14 3
 58 4
 11 5
 54 6

So only 54 are the same for all archs (non-numeric defines such as EXT[AB] 
will appear as 0x0 but at least those two seem the same across archs 
anyway):
  6 #define B0  0x
  6 #define B1100x0003
  6 #define B1200   0x0009
  6 #define B1340x0004
  6 #define B1500x0005
  6 #define B1800   0x000a
  6 #define B19200  0x000e
  6 #define B2000x0006
  6 #define B2400   0x000b
  6 #define B3000x0007
  6 #define B38400  0x000f
  6 #define B4800   0x000c
  6 #define B50 0x0001
  6 #define B6000x0008
  6 #define B75 0x0002
  6 #define B9600   0x000d
  6 #define BRKINT  0x0002
  6 #define BS0 0x
  6 #define CMSPAR  0x4000
  6 #define CR0 0x
  6 #define CRTSCTS 0x8000
  6 #define CS5 0x
  6 #define ECHO0x0008
  6 #define EXTA0x
  6 #define EXTB0x
  6 #define FF0 0x
  6 #define IBSHIFT 0x0010
  6 #define ICRNL   0x0100
  6 #define IGNBRK  0x0001
  6 #define IGNCR   0x0080
  6 #define IGNPAR  0x0004
  6 #define INLCR   0x0040
  6 #define INPCK   0x0010
  6 #define ISTRIP  0x0020
  6 #define IXANY   0x0800
  6 #define NL0 0x
  6 #define NL1 0x0100
  6 #define OCRNL   0x0008
  6 #define OFDEL   0x0080
  6 #define OFILL   0x0040
  6 #define ONLRET  0x0020
  6 #define ONOCR   0x0010
  6 #define OPOST   0x0001
  6 #define PARMRK  0x0008
  6 #define TAB00x
  6 #define TCIFLUSH0x
  6 #define TCIOFF  0x0002
  6 #define TCIOFLUSH   0x0002
  6 #define TCION   0x0003
  6 #define TCOFLUSH0x0001
  6 #define TCOOFF  0x
  6 #define TCOON   0x0001
  6 #define TCSANOW 0x
  6 #define VT0 0x

Sadly for the others, it just tends to be that one or two are different 
from the rest.



-- 
 i.


Re: [PATCH 1/1] termbits: Convert octal defines to hex

2022-05-04 Thread Arnd Bergmann
On Wed, May 4, 2022 at 9:20 AM Ilpo Järvinen
 wrote:
>
> Many archs have termbits.h as octal numbers. It makes hard for humans
> to parse the magnitude of large numbers correctly and to compare with
> hex ones of the same define.
>
> Convert octal values to hex.
>
> First step is an automated conversion with:
>
> for i in $(git ls-files | grep 'termbits\.h'); do
> awk --non-decimal-data '/^#define\s+[A-Z][A-Z0-9]*\s+0[0-9]/ {
> l=int(((length($3) - 1) * 3 + 3) / 4);
> repl = sprintf("0x%0" l "x", $3);
> print gensub(/[^[:blank:]]+/, repl, 3);
> next} {print}' $i > $i~;
> mv $i~ $i;
> done
>
> On top of that, some manual processing on alignment and number of zeros.
> In addition, small tweaks to formatting of a few comments on the same
> lines.
>
> Signed-off-by: Ilpo Järvinen 

Good idea!

I assume you already checked if additional file contents can be shared across
architectures? I think I've tried in the past but didn't really get
anywhere with
that.

After applying the patch locally, I still see a bunch of whitespace
differences in the
changed lines if I run

vimdiff arch/*/include/uapi/asm/termbits.h include/uapi/asm-generic/termbits.h

I think this mostly because you left the sparc version alone (it already
uses hex constants), but it may be nice to edit this a little more to
make the actual differences stick out more.

> I prefer this to go in though Greg's tty tree.

Acked-by: Arnd Bergmann 


[PATCH 1/1] termbits: Convert octal defines to hex

2022-05-04 Thread Ilpo Järvinen
Many archs have termbits.h as octal numbers. It makes hard for humans
to parse the magnitude of large numbers correctly and to compare with
hex ones of the same define.

Convert octal values to hex.

First step is an automated conversion with:

for i in $(git ls-files | grep 'termbits\.h'); do
awk --non-decimal-data '/^#define\s+[A-Z][A-Z0-9]*\s+0[0-9]/ {
l=int(((length($3) - 1) * 3 + 3) / 4);
repl = sprintf("0x%0" l "x", $3);
print gensub(/[^[:blank:]]+/, repl, 3);
next} {print}' $i > $i~;
mv $i~ $i;
done

On top of that, some manual processing on alignment and number of zeros.
In addition, small tweaks to formatting of a few comments on the same 
lines.

Signed-off-by: Ilpo Järvinen 
---

I prefer this to go in though Greg's tty tree.

 arch/alpha/include/uapi/asm/termbits.h   | 202 ++---
 arch/mips/include/uapi/asm/termbits.h| 222 +++
 arch/parisc/include/uapi/asm/termbits.h  | 220 +++---
 arch/powerpc/include/uapi/asm/termbits.h | 202 ++---
 include/uapi/asm-generic/termbits.h  | 220 +++---
 5 files changed, 533 insertions(+), 533 deletions(-)

diff --git a/arch/alpha/include/uapi/asm/termbits.h 
b/arch/alpha/include/uapi/asm/termbits.h
index 4575ba34a0ea..30dc7ff777b8 100644
--- a/arch/alpha/include/uapi/asm/termbits.h
+++ b/arch/alpha/include/uapi/asm/termbits.h
@@ -72,57 +72,57 @@ struct ktermios {
 #define VTIME 17
 
 /* c_iflag bits */
-#define IGNBRK 001
-#define BRKINT 002
-#define IGNPAR 004
-#define PARMRK 010
-#define INPCK  020
-#define ISTRIP 040
-#define INLCR  100
-#define IGNCR  200
-#define ICRNL  400
-#define IXON   0001000
-#define IXOFF  0002000
-#define IXANY  0004000
-#define IUCLC  001
-#define IMAXBEL002
-#define IUTF8  004
+#define IGNBRK 0x1
+#define BRKINT 0x2
+#define IGNPAR 0x4
+#define PARMRK 0x8
+#define INPCK  0x00010
+#define ISTRIP 0x00020
+#define INLCR  0x00040
+#define IGNCR  0x00080
+#define ICRNL  0x00100
+#define IXON   0x00200
+#define IXOFF  0x00400
+#define IXANY  0x00800
+#define IUCLC  0x01000
+#define IMAXBEL0x02000
+#define IUTF8  0x04000
 
 /* c_oflag bits */
-#define OPOST  001
-#define ONLCR  002
-#define OLCUC  004
-
-#define OCRNL  010
-#define ONOCR  020
-#define ONLRET 040
-
-#define OFILL  0100
-#define OFDEL  0200
-#define NLDLY  1400
-#define   NL0  
-#define   NL1  0400
-#define   NL2  1000
-#define   NL3  1400
-#define TABDLY 6000
-#define   TAB0 
-#define   TAB1 2000
-#define   TAB2 4000
-#define   TAB3 6000
-#define CRDLY  0003
-#define   CR0  
-#define   CR1  0001
-#define   CR2  0002
-#define   CR3  0003
-#define FFDLY  0004
-#define   FF0  
-#define   FF1  0004
-#define BSDLY  0010
-#define   BS0  
-#define   BS1  0010
-#define VTDLY  0020
-#define   VT0  
-#define   VT1  0020
+#define OPOST  0x1
+#define ONLCR  0x2
+#define OLCUC  0x4
+
+#define OCRNL  0x8
+#define ONOCR  0x00010
+#define ONLRET 0x00020
+
+#define OFILL  0x40
+#define OFDEL  0x80
+#define NLDLY  0x000300
+#define   NL0  0x00
+#define   NL1  0x000100
+#define   NL2  0x000200
+#define   NL3  0x000300
+#define TABDLY 0x000c00
+#define   TAB0 0x00
+#define   TAB1 0x000400
+#define   TAB2 0x000800
+#define   TAB3 0x000c00
+#define CRDLY  0x003000
+#define   CR0  0x00
+#define   CR1  0x001000
+#define   CR2  0x002000
+#define   CR3  0x003000
+#define FFDLY  0x004000
+#define   FF0  0x00
+#define   FF1  0x004000
+#define BSDLY  0x008000
+#define   BS0  0x00
+#define   BS1  0x008000
+#define VTDLY  0x01
+#define   VT0  0x00
+#define   VT1  0x01
 /*
  * Should be equivalent to TAB3, see description of TAB3 in
  * POSIX.1-2008, Ch. 11.2.3 "Output Modes"
@@ -130,60 +130,60 @@ struct ktermios {
 #define XTABS  TAB3
 
 /* c_cflag bit meaning */
-#define CBAUD  037
-#define  B0000 /* hang up */
-#define  B50   001
-#define  B75   002
-#define  B110  003
-#define  B134  004
-#define  B150  005
-#define  B200  006
-#define  B300  007
-#define  B600  010
-#define  B1200 011
-#define  B1800 012
-#define  B2400 013
-#define  B4800 014
-#define  B9600 015
-#define  B19200016
-#define  B38400017
+#define CBAUD  0x001f
+#define  B00x  /* hang up */
+#define  B50   0x0001
+#define  B75   0x0002
+#define  B110  0x0003
+#define  B134  0x0004
+#define  B150  0x0005
+#define  B200  0x0006
+#define  B300  0x0007
+#define  B600  0x0008
+#define  B1200 0x0009
+#define  B1800 0x000a
+#define  B2400