Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libcurses/director tests/libcurses: use common syn...



details:   https://anonhg.NetBSD.org/src/rev/e5aed4811440
branches:  trunk
changeset: 953057:e5aed4811440
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Feb 25 00:42:00 2021 +0000

description:
tests/libcurses: use common syntax for accessing array elements

Writing *(p+1) is needlessly confusing, even though it adds a little
symmetry between *p and *(p+1).  Still, one of these expressions has
parentheses, the other doesn't, which breaks the symmetry.

Wrap overly long code line.

It's confusing to refer to the digits after the backslash once with
index 0 to 2, and the other time with index 1 to 3.

diffstat:

 tests/lib/libcurses/director/testlang_conf.l |  18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)

diffs (42 lines):

diff -r 5f7bde65ce5a -r e5aed4811440 tests/lib/libcurses/director/testlang_conf.l
--- a/tests/lib/libcurses/director/testlang_conf.l      Thu Feb 25 00:32:44 2021 +0000
+++ b/tests/lib/libcurses/director/testlang_conf.l      Thu Feb 25 00:42:00 2021 +0000
@@ -1,5 +1,5 @@
 %{
-/*     $NetBSD: testlang_conf.l,v 1.23 2021/02/25 00:32:44 rillig Exp $        */
+/*     $NetBSD: testlang_conf.l,v 1.24 2021/02/25 00:42:00 rillig Exp $        */
 
 /*-
  * Copyright 2009 Brett Lymn <blymn%NetBSD.org@localhost>
@@ -59,9 +59,8 @@
        *len = 0;
        p = (const unsigned char *)s;
        while (*p) {
-               if (*p == '\\' && *(p+1)) {
-                       if (isdigit(*(p+1)) && *(p+2) && isdigit(*(p+2)) &&
-                           *(p+3) && isdigit(*(p+3)))
+               if (*p == '\\' && p[1]) {
+                       if (isdigit(p[1]) && isdigit(p[2]) && isdigit(p[3]))
                                p += 3;
                        else
                                ++p;
@@ -77,13 +76,14 @@
        p = (const unsigned char *)s;
        q = buf;
        while (*p) {
-               if (*p == '\\' && *(p+1)) {
+               if (*p == '\\' && p[1]) {
                        ++p;
 
-                       if (isdigit(*p)) {
-                               if (*(p+1) && isdigit(*(p+1)) && *(p+2) &&
-                                   isdigit(*(p+2))) {
-                                       *q++ = ((*p - '0') * 8 + (*(p+1) - '0')) * 8 + (*(p+2) - '0');
+                       if (isdigit(p[0])) {
+                               if (isdigit(p[1]) && isdigit(p[2])) {
+                                       *q++ = (p[0] - '0') * 64 +
+                                           (p[1] - '0') * 8 +
+                                           (p[2] - '0');
                                        p += 3;
                                } else {
                                        *q++ = *p++;



Home | Main Index | Thread Index | Old Index