Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/indent indent: reduce indentation of check_size func...



details:   https://anonhg.NetBSD.org/src/rev/f362f9b4b93c
branches:  trunk
changeset: 953535:f362f9b4b93c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Mar 11 22:32:06 2021 +0000

description:
indent: reduce indentation of check_size functions

No functional change.

diffstat:

 usr.bin/indent/indent.c     |  46 +++++++++++++++++++++++---------------------
 usr.bin/indent/lexi.c       |  28 +++++++++++++-------------
 usr.bin/indent/pr_comment.c |  35 +++++++++++++++------------------
 3 files changed, 54 insertions(+), 55 deletions(-)

diffs (184 lines):

diff -r fb1a72f85e09 -r f362f9b4b93c usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Thu Mar 11 22:31:19 2021 +0000
+++ b/usr.bin/indent/indent.c   Thu Mar 11 22:32:06 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.42 2021/03/11 22:28:30 rillig Exp $       */
+/*     $NetBSD: indent.c,v 1.43 2021/03/11 22:32:06 rillig Exp $       */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.42 2021/03/11 22:28:30 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.43 2021/03/11 22:32:06 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -136,31 +136,33 @@
 static void
 check_size_code(size_t desired_size)
 {
-    if (e_code + (desired_size) >= l_code) {
-       int nsize = l_code - s_code + 400 + desired_size;
-       int code_len = e_code - s_code;
-       codebuf = realloc(codebuf, nsize);
-       if (codebuf == NULL)
-           err(1, NULL);
-       e_code = codebuf + code_len + 1;
-       l_code = codebuf + nsize - 5;
-       s_code = codebuf + 1;
-    }
+    if (e_code + (desired_size) < l_code)
+        return;
+
+    size_t nsize = l_code - s_code + 400 + desired_size;
+    size_t code_len = e_code - s_code;
+    codebuf = realloc(codebuf, nsize);
+    if (codebuf == NULL)
+       err(1, NULL);
+    e_code = codebuf + code_len + 1;
+    l_code = codebuf + nsize - 5;
+    s_code = codebuf + 1;
 }
 
 static void
 check_size_label(size_t desired_size)
 {
-    if (e_lab + (desired_size) >= l_lab) {
-       int nsize = l_lab - s_lab + 400 + desired_size;
-       int label_len = e_lab - s_lab;
-       labbuf = realloc(labbuf, nsize);
-       if (labbuf == NULL)
-           err(1, NULL);
-       e_lab = labbuf + label_len + 1;
-       l_lab = labbuf + nsize - 5;
-       s_lab = labbuf + 1;
-    }
+    if (e_lab + (desired_size) < l_lab)
+        return;
+
+    size_t nsize = l_lab - s_lab + 400 + desired_size;
+    size_t label_len = e_lab - s_lab;
+    labbuf = realloc(labbuf, nsize);
+    if (labbuf == NULL)
+       err(1, NULL);
+    e_lab = labbuf + label_len + 1;
+    l_lab = labbuf + nsize - 5;
+    s_lab = labbuf + 1;
 }
 
 #if HAVE_CAPSICUM
diff -r fb1a72f85e09 -r f362f9b4b93c usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Thu Mar 11 22:31:19 2021 +0000
+++ b/usr.bin/indent/lexi.c     Thu Mar 11 22:32:06 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lexi.c,v 1.34 2021/03/11 22:28:30 rillig Exp $ */
+/*     $NetBSD: lexi.c,v 1.35 2021/03/11 22:32:06 rillig Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.34 2021/03/11 22:28:30 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.35 2021/03/11 22:32:06 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -196,16 +196,17 @@
 static void
 check_size_token(size_t desired_size)
 {
-    if (e_token + (desired_size) >= l_token) {
-       int nsize = l_token - s_token + 400 + desired_size;
-       int token_len = e_token - s_token;
-       tokenbuf = realloc(tokenbuf, nsize);
-       if (tokenbuf == NULL)
-           err(1, NULL);
-       e_token = tokenbuf + token_len + 1;
-       l_token = tokenbuf + nsize - 5;
-       s_token = tokenbuf + 1;
-    }
+    if (e_token + (desired_size) < l_token)
+        return;
+
+    size_t nsize = l_token - s_token + 400 + desired_size;
+    size_t token_len = e_token - s_token;
+    tokenbuf = realloc(tokenbuf, nsize);
+    if (tokenbuf == NULL)
+       err(1, NULL);
+    e_token = tokenbuf + token_len + 1;
+    l_token = tokenbuf + nsize - 5;
+    s_token = tokenbuf + 1;
 }
 
 static int
@@ -690,8 +691,7 @@
 alloc_typenames(void)
 {
 
-    typenames = malloc(sizeof(typenames[0]) *
-        (typename_count = 16));
+    typenames = malloc(sizeof(typenames[0]) * (typename_count = 16));
     if (typenames == NULL)
        err(1, NULL);
 }
diff -r fb1a72f85e09 -r f362f9b4b93c usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Thu Mar 11 22:31:19 2021 +0000
+++ b/usr.bin/indent/pr_comment.c       Thu Mar 11 22:32:06 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pr_comment.c,v 1.17 2021/03/11 22:28:30 rillig Exp $   */
+/*     $NetBSD: pr_comment.c,v 1.18 2021/03/11 22:32:06 rillig Exp $   */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.17 2021/03/11 22:28:30 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.18 2021/03/11 22:32:06 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -62,23 +62,20 @@
 static void
 check_size_comment(size_t desired_size, char **last_bl_ptr)
 {
-    if (e_com + (desired_size) >= l_com) {
-       int nsize = l_com - s_com + 400 + desired_size;
-       int com_len = e_com - s_com;
-       int blank_pos;
-       if (*last_bl_ptr != NULL)
-           blank_pos = *last_bl_ptr - combuf;
-       else
-           blank_pos = -1;
-       combuf = realloc(combuf, nsize);
-       if (combuf == NULL)
-           err(1, NULL);
-       e_com = combuf + com_len + 1;
-       if (blank_pos > 0)
-           *last_bl_ptr = combuf + blank_pos;
-       l_com = combuf + nsize - 5;
-       s_com = combuf + 1;
-    }
+    if (e_com + (desired_size) < l_com)
+        return;
+
+    size_t nsize = l_com - s_com + 400 + desired_size;
+    size_t com_len = e_com - s_com;
+    ssize_t blank_pos = *last_bl_ptr != NULL ? *last_bl_ptr - combuf : -1;
+    combuf = realloc(combuf, nsize);
+    if (combuf == NULL)
+       err(1, NULL);
+    e_com = combuf + com_len + 1;
+    if (blank_pos > 0)
+       *last_bl_ptr = combuf + blank_pos;
+    l_com = combuf + nsize - 5;
+    s_com = combuf + 1;
 }
 
 /*



Home | Main Index | Thread Index | Old Index