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: remove unnecessary forward declarations



details:   https://anonhg.NetBSD.org/src/rev/175076543057
branches:  trunk
changeset: 988657:175076543057
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Oct 08 20:33:18 2021 +0000

description:
indent: remove unnecessary forward declarations

No functional change.

diffstat:

 usr.bin/indent/indent.c |  159 +++++++++++++++++++++++------------------------
 1 files changed, 78 insertions(+), 81 deletions(-)

diffs (201 lines):

diff -r dfb3d2206ede -r 175076543057 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Fri Oct 08 20:28:56 2021 +0000
+++ b/usr.bin/indent/indent.c   Fri Oct 08 20:33:18 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.130 2021/10/08 20:28:56 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.131 2021/10/08 20:33:18 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.130 2021/10/08 20:28:56 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.131 2021/10/08 20:33:18 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -117,9 +117,6 @@
 FILE *input;
 FILE *output;
 
-static void bakcopy(void);
-static void indent_declaration(int, bool);
-
 static const char *in_name = "Standard Input";
 static const char *out_name = "Standard Output";
 static const char *backup_suffix = ".BAK";
@@ -461,6 +458,47 @@
        backup_suffix = suffix;
 }
 
+/*
+ * Copy the input file to the backup file, then make the backup file the input
+ * and the original input file the output.
+ */
+static void
+bakcopy(void)
+{
+    ssize_t n;
+    int bak_fd;
+    char buff[8 * 1024];
+
+    const char *last_slash = strrchr(in_name, '/');
+    snprintf(bakfile, sizeof(bakfile), "%s%s",
+            last_slash != NULL ? last_slash + 1 : in_name, backup_suffix);
+
+    /* copy in_name to backup file */
+    bak_fd = creat(bakfile, 0600);
+    if (bak_fd < 0)
+       err(1, "%s", bakfile);
+
+    while ((n = read(fileno(input), buff, sizeof(buff))) > 0)
+       if (write(bak_fd, buff, (size_t)n) != n)
+           err(1, "%s", bakfile);
+    if (n < 0)
+       err(1, "%s", in_name);
+
+    close(bak_fd);
+    (void)fclose(input);
+
+    /* re-open backup file as the input file */
+    input = fopen(bakfile, "r");
+    if (input == NULL)
+       err(1, "%s", bakfile);
+    /* now the original input file will be the output */
+    output = fopen(in_name, "w");
+    if (output == NULL) {
+       unlink(bakfile);
+       err(1, "%s", in_name);
+    }
+}
+
 static void
 main_parse_command_line(int argc, char **argv)
 {
@@ -549,6 +587,41 @@
        ps.ind_level = ps.ind_level_follow = ind / opt.indent_size;
 }
 
+static void
+indent_declaration(int cur_decl_ind, bool tabs_to_var)
+{
+    int pos = (int)buf_len(&code);
+    char *orig_code_e = code.e;
+
+    /*
+     * get the tab math right for indentations that are not multiples of
+     * tabsize
+     */
+    if ((ps.ind_level * opt.indent_size) % opt.tabsize != 0) {
+       pos += (ps.ind_level * opt.indent_size) % opt.tabsize;
+       cur_decl_ind += (ps.ind_level * opt.indent_size) % opt.tabsize;
+    }
+
+    if (tabs_to_var) {
+       int tpos;
+
+       while ((tpos = opt.tabsize * (1 + pos / opt.tabsize)) <= cur_decl_ind) {
+           buf_add_char(&code, '\t');
+           pos = tpos;
+       }
+    }
+
+    while (pos < cur_decl_ind) {
+       buf_add_char(&code, ' ');
+       pos++;
+    }
+
+    if (code.e == orig_code_e && ps.want_blank) {
+       *code.e++ = ' ';
+       ps.want_blank = false;
+    }
+}
+
 static void __attribute__((__noreturn__))
 process_end_of_file(void)
 {
@@ -1448,82 +1521,6 @@
     main_loop();
 }
 
-/*
- * Copy the input file to the backup file, then make the backup file the input
- * and the original input file the output.
- */
-static void
-bakcopy(void)
-{
-    ssize_t n;
-    int bak_fd;
-    char buff[8 * 1024];
-
-    const char *last_slash = strrchr(in_name, '/');
-    snprintf(bakfile, sizeof(bakfile), "%s%s",
-       last_slash != NULL ? last_slash + 1 : in_name, backup_suffix);
-
-    /* copy in_name to backup file */
-    bak_fd = creat(bakfile, 0600);
-    if (bak_fd < 0)
-       err(1, "%s", bakfile);
-
-    while ((n = read(fileno(input), buff, sizeof(buff))) > 0)
-       if (write(bak_fd, buff, (size_t)n) != n)
-           err(1, "%s", bakfile);
-    if (n < 0)
-       err(1, "%s", in_name);
-
-    close(bak_fd);
-    (void)fclose(input);
-
-    /* re-open backup file as the input file */
-    input = fopen(bakfile, "r");
-    if (input == NULL)
-       err(1, "%s", bakfile);
-    /* now the original input file will be the output */
-    output = fopen(in_name, "w");
-    if (output == NULL) {
-       unlink(bakfile);
-       err(1, "%s", in_name);
-    }
-}
-
-static void
-indent_declaration(int cur_decl_ind, bool tabs_to_var)
-{
-    int pos = (int)(code.e - code.s);
-    char *startpos = code.e;
-
-    /*
-     * get the tab math right for indentations that are not multiples of
-     * tabsize
-     */
-    if ((ps.ind_level * opt.indent_size) % opt.tabsize != 0) {
-       pos += (ps.ind_level * opt.indent_size) % opt.tabsize;
-       cur_decl_ind += (ps.ind_level * opt.indent_size) % opt.tabsize;
-    }
-
-    if (tabs_to_var) {
-       int tpos;
-
-       while ((tpos = opt.tabsize * (1 + pos / opt.tabsize)) <= cur_decl_ind) {
-           buf_add_char(&code, '\t');
-           pos = tpos;
-       }
-    }
-
-    while (pos < cur_decl_ind) {
-       buf_add_char(&code, ' ');
-       pos++;
-    }
-
-    if (code.e == startpos && ps.want_blank) {
-       *code.e++ = ' ';
-       ps.want_blank = false;
-    }
-}
-
 #ifdef debug
 void
 debug_printf(const char *fmt, ...)



Home | Main Index | Thread Index | Old Index