CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Mar 26 22:33:54 UTC 2021 Modified Files: src/usr.bin/indent: README Log Message: indent: don't claim that indent is "the nicest C pretty printer around" That statement may have been true in 1993, but definitely is not true anymore, as of 2021. The part about "needs to be completely redone" is still true though since indent cannot even format its own source code in an acceptable way. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/usr.bin/indent/README Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/README diff -u src/usr.bin/indent/README:1.2 src/usr.bin/indent/README:1.3 --- src/usr.bin/indent/README:1.2 Thu Apr 4 15:22:13 2019 +++ src/usr.bin/indent/README Fri Mar 26 22:33:54 2021 @@ -2,7 +2,7 @@ This is the C indenter, it originally ca via some distribution tape for PDP-11 Unix. It has subsequently been hacked upon by James Gosling @ CMU. It isn't very pretty, and really needs to be completely redone, but it is probably the nicest C pretty printer -around. +around (as of 1993 or even earlier). Further additions to provide "Kernel Normal Form" were contributed by the folks at Sun Microsystems. @@ -94,4 +94,3 @@ regards.. oz cc: ccvaxa!willcox sun.com!jar uunet!rsalz -
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Mar 26 22:27:43 UTC 2021 Modified Files: src/usr.bin/indent: Makefile Log Message: indent: remove workaround for array initialization bug in lint The bug has been fixed in init.c 1.133 from 2021-03-25. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/usr.bin/indent/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/Makefile diff -u src/usr.bin/indent/Makefile:1.11 src/usr.bin/indent/Makefile:1.12 --- src/usr.bin/indent/Makefile:1.11 Sun Mar 14 00:22:16 2021 +++ src/usr.bin/indent/Makefile Fri Mar 26 22:27:43 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.11 2021/03/14 00:22:16 rillig Exp $ +# $NetBSD: Makefile,v 1.12 2021/03/26 22:27:43 rillig Exp $ # from: @(#)Makefile 8.1 (Berkeley) 6/6/93 PROG= indent @@ -7,7 +7,4 @@ SRCS= indent.c io.c lexi.c parse.c pr_co CPPFLAGS+= ${DEBUG:D-Ddebug} LINTFLAGS+= -e -w -# bug in lint; see tests/usr.bin/lint/lint1/msg_168.c -LINTFLAGS.lexi.c+= -X 168 - .include
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Mar 26 22:02:00 UTC 2021 Modified Files: src/usr.bin/indent: indent.c Log Message: indent: fix Clang build everywhere but on amd64 No idea why Clang didn't complain about this on amd64, only on all other platforms. To generate a diff of this commit: cvs rdiff -u -r1.59 -r1.60 src/usr.bin/indent/indent.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.59 src/usr.bin/indent/indent.c:1.60 --- src/usr.bin/indent/indent.c:1.59 Sun Mar 14 00:22:16 2021 +++ src/usr.bin/indent/indent.c Fri Mar 26 22:02:00 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.59 2021/03/14 00:22:16 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.60 2021/03/26 22:02:00 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.59 2021/03/14 00:22:16 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.60 2021/03/26 22:02:00 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -546,7 +546,7 @@ main_prepare_parsing(void) ps.ind_level = ps.i_l_follow = col / opt.indent_size; } -static void +static void __attribute__((__noreturn__)) process_end_of_file(void) { if (s_lab != e_lab || s_code != e_code || s_com != e_com) @@ -1269,7 +1269,7 @@ process_preprocessing(void) */ } -static void +static void __attribute__((__noreturn__)) main_loop(void) { token_type type_code; @@ -1313,7 +1313,7 @@ main_loop(void) if (type_code == end_of_file) { process_end_of_file(); - return; + /* NOTREACHED */ } if (
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Mar 14 05:26:42 UTC 2021 Modified Files: src/usr.bin/indent: pr_comment.c Log Message: indent: clean up check_size_comment The additional parameter last_bl_ptr was only necessary because the last blank was stored as a pointer into the buffer. By storing the index in the buffer instead, it doesn't need to be updated all the time. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/pr_comment.c diff -u src/usr.bin/indent/pr_comment.c:1.34 src/usr.bin/indent/pr_comment.c:1.35 --- src/usr.bin/indent/pr_comment.c:1.34 Sun Mar 14 04:52:10 2021 +++ src/usr.bin/indent/pr_comment.c Sun Mar 14 05:26:42 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: pr_comment.c,v 1.34 2021/03/14 04:52:10 rillig Exp $ */ +/* $NetBSD: pr_comment.c,v 1.35 2021/03/14 05:26:42 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)pr_comment.c #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: pr_comment.c,v 1.34 2021/03/14 04:52:10 rillig Exp $"); +__RCSID("$NetBSD: pr_comment.c,v 1.35 2021/03/14 05:26:42 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -60,22 +60,19 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/ #include "indent.h" static void -check_size_comment(size_t desired_size, char **last_bl_ptr) +check_size_comment(size_t desired_size) { 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; +e_com = s_com + com_len; +l_com = combuf + nsize - 5; } /* @@ -101,15 +98,14 @@ process_comment(void) { int adj_max_line_length; /* Adjusted max_line_length for comments * that spill over the right margin */ -char *last_bl; /* points to the last blank in the output - * buffer */ +ssize_t last_blank; /* index of the last blank in combuf */ char *t_ptr; /* used for moving string */ int break_delim = opt.comment_delimiter_on_blankline; int l_just_saw_decl = ps.just_saw_decl; adj_max_line_length = opt.max_line_length; ps.just_saw_decl = 0; -last_bl = NULL; /* no blanks found so far */ +last_blank = -1; /* no blanks found so far */ ps.box_com = false; /* at first, assume that we are not in * a boxed comment or some other * comment that should not be touched */ @@ -232,12 +228,12 @@ process_comment(void) * copied */ switch (*buf_ptr) { /* this checks for various special cases */ case 014: /* check for a form feed */ - check_size_comment(3, _bl); + check_size_comment(3); if (!ps.box_com) { /* in a text comment, break the line here */ ps.use_ff = true; /* fix so dump_line uses a form feed */ dump_line(); - last_bl = NULL; + last_blank = -1; if (!ps.box_com && opt.star_comment_cont) *e_com++ = ' ', *e_com++ = '*', *e_com++ = ' '; while (*++buf_ptr == ' ' || *buf_ptr == '\t') @@ -259,8 +255,8 @@ process_comment(void) dump_line(); return; } - last_bl = NULL; - check_size_comment(4, _bl); + last_blank = -1; + check_size_comment(4); if (ps.box_com || ps.last_nl) { /* if this is a boxed comment, * we dont ignore the newline */ if (s_com == e_com) @@ -275,16 +271,9 @@ process_comment(void) *e_com++ = ' ', *e_com++ = '*', *e_com++ = ' '; } else { ps.last_nl = 1; - if (e_com[-1] == ' ' || e_com[-1] == '\t') - last_bl = e_com - 1; - /* - * if there was a space at the end of the last line, remember - * where it was - */ - else { /* otherwise, insert one */ - last_bl = e_com; + if (!(e_com[-1] == ' ' || e_com[-1] == '\t')) *e_com++ = ' '; - } + last_blank = e_com - 1 - combuf; } ++line_no; /* keep track of input line number */ if (!ps.box_com) { @@ -308,7 +297,7 @@ process_comment(void) * of comment */ if (++buf_ptr >= buf_end) /* get to next char after * */ fill_buffer(); - check_size_comment(4, _bl); + check_size_comment(4); if (*buf_ptr == '/') { /* it is the end!!! */ end_of_comment: if (++buf_ptr >= buf_end) @@ -335,16 +324,16 @@ process_comment(void) ; int now_len = indentation_after_range(ps.com_col - 1, s_com, e_com); do { - check_size_comment(1, _bl); +
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Mar 14 04:52:10 UTC 2021 Modified Files: src/usr.bin/indent: pr_comment.c Log Message: indent: remove trailing whitespace To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.34 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/pr_comment.c diff -u src/usr.bin/indent/pr_comment.c:1.33 src/usr.bin/indent/pr_comment.c:1.34 --- src/usr.bin/indent/pr_comment.c:1.33 Sun Mar 14 04:42:17 2021 +++ src/usr.bin/indent/pr_comment.c Sun Mar 14 04:52:10 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: pr_comment.c,v 1.33 2021/03/14 04:42:17 rillig Exp $ */ +/* $NetBSD: pr_comment.c,v 1.34 2021/03/14 04:52:10 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)pr_comment.c #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: pr_comment.c,v 1.33 2021/03/14 04:42:17 rillig Exp $"); +__RCSID("$NetBSD: pr_comment.c,v 1.34 2021/03/14 04:52:10 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -146,15 +146,15 @@ process_comment(void) ps.com_col = 1 + !opt.format_col1_comments; } else { break_delim = false; - + int target_col; if (s_code != e_code) target_col = 1 + indentation_after(compute_code_indent(), s_code); else if (s_lab != e_lab) target_col = 1 + indentation_after(compute_label_indent(), s_lab); - else + else target_col = 1; - + ps.com_col = ps.decl_on_line || ps.ind_level == 0 ? opt.decl_comment_column : opt.comment_column; if (ps.com_col <= target_col)
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Mar 14 04:42:17 UTC 2021 Modified Files: src/usr.bin/indent: pr_comment.c Log Message: indent: clean up target column computation in process_comment No functional change. To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/pr_comment.c diff -u src/usr.bin/indent/pr_comment.c:1.32 src/usr.bin/indent/pr_comment.c:1.33 --- src/usr.bin/indent/pr_comment.c:1.32 Sun Mar 14 01:34:13 2021 +++ src/usr.bin/indent/pr_comment.c Sun Mar 14 04:42:17 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: pr_comment.c,v 1.32 2021/03/14 01:34:13 rillig Exp $ */ +/* $NetBSD: pr_comment.c,v 1.33 2021/03/14 04:42:17 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)pr_comment.c #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: pr_comment.c,v 1.32 2021/03/14 01:34:13 rillig Exp $"); +__RCSID("$NetBSD: pr_comment.c,v 1.33 2021/03/14 04:42:17 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -145,15 +145,16 @@ process_comment(void) if (ps.com_col <= 1) ps.com_col = 1 + !opt.format_col1_comments; } else { - int target_col; break_delim = false; + + int target_col; if (s_code != e_code) target_col = 1 + indentation_after(compute_code_indent(), s_code); - else { + else if (s_lab != e_lab) + target_col = 1 + indentation_after(compute_label_indent(), s_lab); + else target_col = 1; - if (s_lab != e_lab) - target_col = 1 + indentation_after(compute_label_indent(), s_lab); - } + ps.com_col = ps.decl_on_line || ps.ind_level == 0 ? opt.decl_comment_column : opt.comment_column; if (ps.com_col <= target_col)
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Mar 14 01:44:37 UTC 2021 Modified Files: src/usr.bin/indent: io.c Log Message: indent: make compute_code_indent more readable The '?:' operator computing the factor was too hard to read. When quickly scanning the code, the 1 in the expression looked too much like it would be added to the indentation, which would turn the indentation length into a column number, and that again would smell like an off-by-one error. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.48 -r1.49 src/usr.bin/indent/io.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.48 src/usr.bin/indent/io.c:1.49 --- src/usr.bin/indent/io.c:1.48 Sun Mar 14 00:22:16 2021 +++ src/usr.bin/indent/io.c Sun Mar 14 01:44:37 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.48 2021/03/14 00:22:16 rillig Exp $ */ +/* $NetBSD: io.c,v 1.49 2021/03/14 01:44:37 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.48 2021/03/14 00:22:16 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.49 2021/03/14 01:44:37 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -291,8 +291,10 @@ compute_code_indent(void) if (ps.paren_level != 0) { if (!opt.lineup_to_parens) - target_ind += opt.continuation_indent * - (2 * opt.continuation_indent == opt.indent_size ? 1 : ps.paren_level); + if (2 * opt.continuation_indent == opt.indent_size) + target_ind += opt.continuation_indent; + else + target_ind += opt.continuation_indent * ps.paren_level; else if (opt.lineup_to_parens_always) /* * XXX: where does this '- 1' come from? It looks strange but is
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Mar 14 00:33:25 UTC 2021 Modified Files: src/usr.bin/indent: indent.h Log Message: indent: give indent a try at formatting its own code Formatting indent.h required the following manual corrections afterwards: The first tab in the comment in line 1 was replaced with a space but shouldn't be. The spacing around the '...' in function prototypes was completely wrong. It looked like 'const char *,...)__printflike', without any spaces. The '*' of the return type 'const char *' was tied to the function name, even though this declaration was only for a single function. In such a case, it's more appropriate to line up the function names. The function-like macros were not indented to -di. This is something that I would not expect from indent, so it's ok to do that manually. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/usr.bin/indent/indent.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.15 src/usr.bin/indent/indent.h:1.16 --- src/usr.bin/indent/indent.h:1.15 Sat Mar 13 23:42:23 2021 +++ src/usr.bin/indent/indent.h Sun Mar 14 00:33:25 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.15 2021/03/13 23:42:23 rillig Exp $ */ +/* $NetBSD: indent.h,v 1.16 2021/03/14 00:33:25 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -41,29 +41,30 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/ #define nitems(array) (sizeof (array) / sizeof (array[0])) #endif -void add_typename(const char *); -void alloc_typenames(void); -int compute_code_indent(void); -int compute_label_indent(void); -int indentation_after_range(int, const char *, const char *); -int indentation_after(int, const char *); -void init_constant_tt(void); +void add_typename(const char *); +void alloc_typenames(void); +int compute_code_indent(void); +int compute_label_indent(void); +int indentation_after_range(int, const char *, const char *); +int indentation_after(int, const char *); +void init_constant_tt(void); #ifdef debug -void debug_vis_range(const char *, const char *, const char *, const char *); -void debug_printf(const char *, ...) __printflike(1, 2); -void debug_println(const char *, ...) __printflike(1, 2); -const char *token_type_name(token_type); +void debug_vis_range(const char *, const char *, const char *, + const char *); +void debug_printf(const char *, ...) __printflike(1, 2); +void debug_println(const char *, ...) __printflike(1, 2); +const char * token_type_name(token_type); #else -#define debug_printf(fmt, ...) do { } while (false) -#define debug_println(fmt, ...) do { } while (false) -#define debug_vis_range(prefix, s, e, suffix) do { } while (false) +#define debug_printf(fmt, ...) do { } while (false) +#define debug_println(fmt, ...) do { } while (false) +#define debug_vis_range(prefix, s, e, suffix) do { } while (false) #endif -token_type lexi(struct parser_state *); -void diag(int, const char *, ...) __printflike(2, 3); -void dump_line(void); -void fill_buffer(void); -void parse(token_type); -void process_comment(void); -void set_defaults(void); -void set_option(char *); -void set_profile(const char *); +token_type lexi(struct parser_state *); +void diag(int, const char *, ...) __printflike(2, 3); +void dump_line(void); +void fill_buffer(void); +void parse(token_type); +void process_comment(void); +void set_defaults(void); +void set_option(char *); +void set_profile(const char *);
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Mar 14 00:22:16 UTC 2021 Modified Files: src/usr.bin/indent: Makefile args.c indent.c io.c lexi.c pr_comment.c Log Message: indent: fix lint warnings No functional change. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/usr.bin/indent/Makefile cvs rdiff -u -r1.21 -r1.22 src/usr.bin/indent/args.c cvs rdiff -u -r1.58 -r1.59 src/usr.bin/indent/indent.c cvs rdiff -u -r1.47 -r1.48 src/usr.bin/indent/io.c cvs rdiff -u -r1.40 -r1.41 src/usr.bin/indent/lexi.c cvs rdiff -u -r1.30 -r1.31 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/Makefile diff -u src/usr.bin/indent/Makefile:1.10 src/usr.bin/indent/Makefile:1.11 --- src/usr.bin/indent/Makefile:1.10 Fri Mar 12 19:11:29 2021 +++ src/usr.bin/indent/Makefile Sun Mar 14 00:22:16 2021 @@ -1,10 +1,13 @@ -# $NetBSD: Makefile,v 1.10 2021/03/12 19:11:29 rillig Exp $ +# $NetBSD: Makefile,v 1.11 2021/03/14 00:22:16 rillig Exp $ # from: @(#)Makefile 8.1 (Berkeley) 6/6/93 PROG= indent SRCS= indent.c io.c lexi.c parse.c pr_comment.c args.c CPPFLAGS+= ${DEBUG:D-Ddebug} -LINTFLAGS+= -e +LINTFLAGS+= -e -w + +# bug in lint; see tests/usr.bin/lint/lint1/msg_168.c +LINTFLAGS.lexi.c+= -X 168 .include Index: src/usr.bin/indent/args.c diff -u src/usr.bin/indent/args.c:1.21 src/usr.bin/indent/args.c:1.22 --- src/usr.bin/indent/args.c:1.21 Sat Mar 13 13:51:08 2021 +++ src/usr.bin/indent/args.c Sun Mar 14 00:22:16 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: args.c,v 1.21 2021/03/13 13:51:08 rillig Exp $ */ +/* $NetBSD: args.c,v 1.22 2021/03/14 00:22:16 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)args.c 8.1 ( #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: args.c,v 1.21 2021/03/13 13:51:08 rillig Exp $"); +__RCSID("$NetBSD: args.c,v 1.22 2021/03/14 00:22:16 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $"); #endif @@ -212,12 +212,12 @@ scan_profile(FILE *f) char *p; charbuf[BUFSIZ]; -while (1) { +for (;;) { p = buf; comment_index = 0; while ((i = getc(f)) != EOF) { if (i == '*' && !comment_index && p > buf && p[-1] == '/') { - comment_index = p - buf; + comment_index = (int)(p - buf); *p++ = i; } else if (i == '/' && comment_index && p > buf && p[-1] == '*') { p = buf + comment_index - 1; @@ -314,6 +314,7 @@ found: case VERSION: printf("FreeBSD indent %s\n", INDENT_VERSION); exit(0); + /*NOTREACHED*/ default: errx(1, "set_option: internal error: p_special %d", p->p_special); Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.58 src/usr.bin/indent/indent.c:1.59 --- src/usr.bin/indent/indent.c:1.58 Sat Mar 13 18:46:39 2021 +++ src/usr.bin/indent/indent.c Sun Mar 14 00:22:16 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.58 2021/03/13 18:46:39 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.59 2021/03/14 00:22:16 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.58 2021/03/13 18:46:39 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.59 2021/03/14 00:22:16 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -206,6 +206,7 @@ search_brace(token_type *inout_type_code * done earlier. */ *inout_force_nl = false; + break; case form_feed: break; case comment: @@ -215,7 +216,7 @@ search_brace(token_type *inout_type_code * process_comment() will use that to calculate original * indentation of a boxed comment. */ - memcpy(sc_buf, in_buffer, buf_ptr - in_buffer - 4); + memcpy(sc_buf, in_buffer, (size_t)(buf_ptr - in_buffer) - 4); save_com = sc_buf + (buf_ptr - in_buffer - 4); save_com[0] = save_com[1] = ' '; sc_end = _com[2]; @@ -532,7 +533,7 @@ main_prepare_parsing(void) char *p = buf_ptr; int col = 1; -while (1) { +for (;;) { if (*p == ' ') col++; else if (*p == '\t') @@ -585,7 +586,7 @@ process_comment_in_code(token_type type_ * '}' */ if (s_com != e_com) { /* the turkey has embedded a comment * in a line. fix it */ - int len = e_com - s_com; + size_t len = e_com - s_com; check_size_code(len + 3); *e_code++ = ' '; @@ -724,7 +725,7 @@ process_unary_op(int dec_ind, int tabs_t *e_code++ = ' '; { - int len = e_token - s_token; + size_t len = e_token - s_token; check_size_code(len); memcpy(e_code, token, len); @@ -736,7 +737,7 @@ process_unary_op(int dec_ind, int tabs_t static void process_binary_op(void) { -int len = e_token - s_token;
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 13 23:42:23 UTC 2021 Modified Files: src/usr.bin/indent: indent.h Log Message: indent: remove disabled duplicate RCS ID from header By convention, headers don't record their RCS ID. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/usr.bin/indent/indent.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.14 src/usr.bin/indent/indent.h:1.15 --- src/usr.bin/indent/indent.h:1.14 Sat Mar 13 13:25:23 2021 +++ src/usr.bin/indent/indent.h Sat Mar 13 23:42:23 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.14 2021/03/13 13:25:23 rillig Exp $ */ +/* $NetBSD: indent.h,v 1.15 2021/03/13 23:42:23 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -29,9 +29,7 @@ */ #if 0 -#if defined(__NetBSD__) -__RCSID("$NetBSD: indent.h,v 1.14 2021/03/13 13:25:23 rillig Exp $"); -#elif defined(__FreeBSD__) +#if defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 336333 2018-07-16 05:46:50Z pstef $"); #endif #endif
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 13 23:36:10 UTC 2021 Modified Files: src/usr.bin/indent: indent_globs.h Log Message: indent: fix documentation of parser_state.paren_indents The column position is not the same as the indentation (off-by-one). To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/usr.bin/indent/indent_globs.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent_globs.h diff -u src/usr.bin/indent/indent_globs.h:1.20 src/usr.bin/indent/indent_globs.h:1.21 --- src/usr.bin/indent/indent_globs.h:1.20 Sat Mar 13 13:51:08 2021 +++ src/usr.bin/indent/indent_globs.h Sat Mar 13 23:36:10 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent_globs.h,v 1.20 2021/03/13 13:51:08 rillig Exp $ */ +/* $NetBSD: indent_globs.h,v 1.21 2021/03/13 23:36:10 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -261,7 +261,9 @@ extern struct parser_state { * statement */ int paren_level; /* parenthesization level. used to indent * within statements */ -short paren_indents[20]; /* column positions of each paren */ +short paren_indents[20]; /* indentation of the operand/argument of + * each level of parentheses or brackets, + * relative to the enclosing statement */ int pcase; /* set to 1 if the current line label is a * case. It is printed differently from a * regular label */
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 13 18:46:39 UTC 2021 Modified Files: src/usr.bin/indent: indent.c io.c Log Message: indent: add debug logging for switching the input buffer No functional change outside debug mode. To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.58 src/usr.bin/indent/indent.c cvs rdiff -u -r1.46 -r1.47 src/usr.bin/indent/io.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.57 src/usr.bin/indent/indent.c:1.58 --- src/usr.bin/indent/indent.c:1.57 Sat Mar 13 13:51:08 2021 +++ src/usr.bin/indent/indent.c Sat Mar 13 18:46:39 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.57 2021/03/13 13:51:08 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.58 2021/03/13 18:46:39 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.57 2021/03/13 13:51:08 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.58 2021/03/13 18:46:39 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -314,6 +314,7 @@ search_brace(token_type *inout_type_code *sc_end++ = ' '; /* add trailing blank, just in case */ buf_end = sc_end; sc_end = NULL; + debug_println("switched buf_ptr to save_com"); break; } } /* end of switch */ @@ -640,11 +641,17 @@ process_lparen_or_lbracket(int dec_ind, *e_code++ = ' '; ps.want_blank = false; *e_code++ = token[0]; + ps.paren_indents[ps.p_l_follow - 1] = indentation_after_range(0, s_code, e_code); +debug_println("paren_indent[%d] is now %d", + ps.p_l_follow - 1, ps.paren_indents[ps.p_l_follow - 1]); + if (sp_sw && ps.p_l_follow == 1 && opt.extra_expression_indent - && ps.paren_indents[0] < 2 * opt.indent_size) + && ps.paren_indents[0] < 2 * opt.indent_size) { ps.paren_indents[0] = 2 * opt.indent_size; + debug_println("paren_indent[0] is now %d", ps.paren_indents[0]); +} if (ps.in_or_st && *token == '(' && ps.tos <= 2) { /* * this is a kluge to make sure that declarations will be @@ -1196,12 +1203,12 @@ process_preprocessing(void) e_lab--; bp_save = buf_ptr; /* save current input buffer */ be_save = buf_end; - buf_ptr = save_com; /* fix so that subsequent calls to - * lexi will take tokens out of - * save_com */ + buf_ptr = save_com; /* fix so that subsequent calls to lexi will + * take tokens out of save_com */ *sc_end++ = ' '; /* add trailing blank, just in case */ buf_end = sc_end; sc_end = NULL; + debug_println("switched buf_ptr to save_com"); } check_size_label(1); *e_lab = '\0'; /* null terminate line */ Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.46 src/usr.bin/indent/io.c:1.47 --- src/usr.bin/indent/io.c:1.46 Sat Mar 13 18:24:56 2021 +++ src/usr.bin/indent/io.c Sat Mar 13 18:46:39 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.46 2021/03/13 18:24:56 rillig Exp $ */ +/* $NetBSD: io.c,v 1.47 2021/03/13 18:46:39 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.46 2021/03/13 18:24:56 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.47 2021/03/13 18:46:39 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -346,6 +346,7 @@ fill_buffer(void) buf_ptr = bp_save; /* do not read anything, just switch buffers */ buf_end = be_save; bp_save = be_save = NULL; + debug_println("switched buf_ptr back to bp_save"); if (buf_ptr < buf_end) return; /* only return if there is really something in * this buffer */
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 13 18:24:56 UTC 2021 Modified Files: src/usr.bin/indent: io.c Log Message: indent: align comments in indent's own code No functional change. To generate a diff of this commit: cvs rdiff -u -r1.45 -r1.46 src/usr.bin/indent/io.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.45 src/usr.bin/indent/io.c:1.46 --- src/usr.bin/indent/io.c:1.45 Sat Mar 13 13:55:42 2021 +++ src/usr.bin/indent/io.c Sat Mar 13 18:24:56 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.45 2021/03/13 13:55:42 rillig Exp $ */ +/* $NetBSD: io.c,v 1.46 2021/03/13 18:24:56 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.45 2021/03/13 13:55:42 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.46 2021/03/13 18:24:56 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -223,7 +223,7 @@ dump_line(void) target_col += ps.comment_delta; while (*com_st == '\t') /* consider original indentation in - * case this is a box comment */ + * case this is a box comment */ com_st++, target_col += opt.tabsize; while (target_col <= 0) if (*com_st == ' ') @@ -234,7 +234,7 @@ dump_line(void) } else target_col = 1; if (cur_col > target_col) { /* if comment can't fit on this line, - * put it on next line */ + * put it on next line */ output_char('\n'); cur_col = 1; ++ps.out_lines; @@ -263,14 +263,12 @@ dump_line(void) if (e_com - s_com > 1 && s_com[1] == '/') output_range(s_token, e_token); -ps.decl_on_line = ps.in_decl; /* if we are in the middle of a - * declaration, remember that fact for - * proper comment indentation */ -ps.ind_stmt = ps.in_stmt & ~ps.in_decl; /* next line should be - * indented if we have not - * completed this stmt and if - * we are not in the middle of - * a declaration */ +ps.decl_on_line = ps.in_decl; /* if we are in the middle of a declaration, + * remember that fact for proper comment + * indentation */ +ps.ind_stmt = ps.in_stmt & ~ps.in_decl; /* next line should be indented if + * we have not completed this stmt and if we + * are not in the middle of a declaration */ ps.use_ff = false; ps.dumped_decl_indent = 0; *(e_lab = s_lab) = '\0'; /* reset buffers */
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 13 18:11:31 UTC 2021 Modified Files: src/usr.bin/indent: pr_comment.c Log Message: indent: remove the '+ 1' from right margin calculation in comment No functional change. To generate a diff of this commit: cvs rdiff -u -r1.29 -r1.30 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/pr_comment.c diff -u src/usr.bin/indent/pr_comment.c:1.29 src/usr.bin/indent/pr_comment.c:1.30 --- src/usr.bin/indent/pr_comment.c:1.29 Sat Mar 13 13:51:08 2021 +++ src/usr.bin/indent/pr_comment.c Sat Mar 13 18:11:31 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: pr_comment.c,v 1.29 2021/03/13 13:51:08 rillig Exp $ */ +/* $NetBSD: pr_comment.c,v 1.30 2021/03/13 18:11:31 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)pr_comment.c #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: pr_comment.c,v 1.29 2021/03/13 13:51:08 rillig Exp $"); +__RCSID("$NetBSD: pr_comment.c,v 1.30 2021/03/13 18:11:31 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -200,8 +200,9 @@ process_comment(void) if (t_ptr >= buf_end) fill_buffer(); if (t_ptr[0] == '*' && t_ptr[1] == '/') { - /* XXX: strange mixture between indentation, column, length */ - if (adj_max_line_length >= 1 + indentation_after_range(ps.com_col - 1, buf_ptr, t_ptr + 2)) + int right_margin = indentation_after_range(ps.com_col - 1, + buf_ptr, t_ptr + 2); + if (right_margin < adj_max_line_length) break_delim = false; break; }
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 13 13:55:42 UTC 2021 Modified Files: src/usr.bin/indent: io.c Log Message: indent: rename local variable in dump_line This clarifies that the variable names a column, not an indentation. To generate a diff of this commit: cvs rdiff -u -r1.44 -r1.45 src/usr.bin/indent/io.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.44 src/usr.bin/indent/io.c:1.45 --- src/usr.bin/indent/io.c:1.44 Sat Mar 13 13:54:01 2021 +++ src/usr.bin/indent/io.c Sat Mar 13 13:55:42 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.44 2021/03/13 13:54:01 rillig Exp $ */ +/* $NetBSD: io.c,v 1.45 2021/03/13 13:55:42 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.44 2021/03/13 13:54:01 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.45 2021/03/13 13:55:42 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -218,22 +218,22 @@ dump_line(void) cur_col = 1 + indentation_after(cur_col - 1, s_code); } if (s_com != e_com) { /* print comment, if any */ - int target = ps.com_col; + int target_col = ps.com_col; char *com_st = s_com; - target += ps.comment_delta; + target_col += ps.comment_delta; while (*com_st == '\t') /* consider original indentation in * case this is a box comment */ - com_st++, target += opt.tabsize; - while (target <= 0) + com_st++, target_col += opt.tabsize; + while (target_col <= 0) if (*com_st == ' ') - target++, com_st++; + target_col++, com_st++; else if (*com_st == '\t') { - target = opt.tabsize * (1 + (target - 1) / opt.tabsize) + 1; + target_col = opt.tabsize * (1 + (target_col - 1) / opt.tabsize) + 1; com_st++; } else - target = 1; - if (cur_col > target) { /* if comment can't fit on this line, + target_col = 1; + if (cur_col > target_col) { /* if comment can't fit on this line, * put it on next line */ output_char('\n'); cur_col = 1; @@ -241,7 +241,7 @@ dump_line(void) } while (e_com > com_st && isspace((unsigned char)e_com[-1])) e_com--; - (void)output_indent(cur_col - 1, target - 1); + (void)output_indent(cur_col - 1, target_col - 1); output_range(com_st, e_com); ps.comment_delta = ps.n_comment_delta; ++ps.com_lines; /* count lines with comments */
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 13 13:54:01 UTC 2021 Modified Files: src/usr.bin/indent: io.c Log Message: indent: in dump_line, reduce scope of local variable This allows the variable 'target' in the lower half of the function to get a more specific name. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/usr.bin/indent/io.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.43 src/usr.bin/indent/io.c:1.44 --- src/usr.bin/indent/io.c:1.43 Sat Mar 13 13:51:08 2021 +++ src/usr.bin/indent/io.c Sat Mar 13 13:54:01 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.43 2021/03/13 13:51:08 rillig Exp $ */ +/* $NetBSD: io.c,v 1.44 2021/03/13 13:54:01 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.43 2021/03/13 13:51:08 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.44 2021/03/13 13:54:01 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -115,7 +115,7 @@ output_indent(int old_ind, int new_ind) void dump_line(void) { -int cur_col, target_col; +int cur_col; static int not_first_line; if (ps.procname[0]) { @@ -195,7 +195,7 @@ dump_line(void) comment_open = 0; output_string(".*/\n"); } - target_col = 1 + compute_code_indent(); + int target_col = 1 + compute_code_indent(); { int i;
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 13 13:51:08 UTC 2021 Modified Files: src/usr.bin/indent: args.c indent.c indent_globs.h io.c pr_comment.c Log Message: indent: distinguish between 'column' and 'indentation' column == 1 + indentation. In addition, indentation is a relative distance while column is an absolute position. Therefore, don't confuse these two concepts, to prevent off-by-one errors. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/usr.bin/indent/args.c cvs rdiff -u -r1.56 -r1.57 src/usr.bin/indent/indent.c cvs rdiff -u -r1.19 -r1.20 src/usr.bin/indent/indent_globs.h cvs rdiff -u -r1.42 -r1.43 src/usr.bin/indent/io.c cvs rdiff -u -r1.28 -r1.29 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/args.c diff -u src/usr.bin/indent/args.c:1.20 src/usr.bin/indent/args.c:1.21 --- src/usr.bin/indent/args.c:1.20 Sat Mar 13 11:19:43 2021 +++ src/usr.bin/indent/args.c Sat Mar 13 13:51:08 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: args.c,v 1.20 2021/03/13 11:19:43 rillig Exp $ */ +/* $NetBSD: args.c,v 1.21 2021/03/13 13:51:08 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)args.c 8.1 ( #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: args.c,v 1.20 2021/03/13 11:19:43 rillig Exp $"); +__RCSID("$NetBSD: args.c,v 1.21 2021/03/13 13:51:08 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $"); #endif @@ -119,12 +119,12 @@ const struct pro { {"br", PRO_BOOL, true, ON, _2}, {"bs", PRO_BOOL, false, ON, _Shannon}, {"cdb", PRO_BOOL, true, ON, _delimiter_on_blankline}, -{"cd", PRO_INT, 0, 0, _com_ind}, +{"cd", PRO_INT, 0, 0, _comment_column}, {"ce", PRO_BOOL, true, ON, _else}, {"ci", PRO_INT, 0, 0, _indent}, {"cli", PRO_SPECIAL, 0, CLI, 0}, {"cs", PRO_BOOL, false, ON, _after_cast}, -{"c", PRO_INT, 33, 0, _ind}, +{"c", PRO_INT, 33, 0, _column}, {"di", PRO_INT, 16, 0, _indent}, {"dj", PRO_BOOL, false, ON, _decl}, {"d", PRO_INT, 0, 0, _displace}, @@ -134,7 +134,7 @@ const struct pro { {"fc1", PRO_BOOL, true, ON, _col1_comments}, {"fcb", PRO_BOOL, true, ON, _block_comments}, {"ip", PRO_BOOL, true, ON, _parameters}, -{"i", PRO_INT, 8, 0, _size}, +{"i", PRO_INT, 8, 0, _size}, {"lc", PRO_INT, 0, 0, _comment_max_line_length}, {"ldi", PRO_INT, -1, 0, _decl_indent}, {"lpl", PRO_BOOL, false, ON, _to_parens_always}, Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.56 src/usr.bin/indent/indent.c:1.57 --- src/usr.bin/indent/indent.c:1.56 Sat Mar 13 13:25:23 2021 +++ src/usr.bin/indent/indent.c Sat Mar 13 13:51:08 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.56 2021/03/13 13:25:23 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.57 2021/03/13 13:51:08 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.56 2021/03/13 13:25:23 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.57 2021/03/13 13:51:08 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -507,16 +507,18 @@ main_parse_command_line(int argc, char * } } -if (opt.com_ind <= 1) - opt.com_ind = 2; /* don't put normal comments before column 2 */ +if (opt.comment_column <= 1) + opt.comment_column = 2; /* don't put normal comments before column 2 */ if (opt.block_comment_max_line_length <= 0) opt.block_comment_max_line_length = opt.max_line_length; if (opt.local_decl_indent < 0) /* if not specified by user, set this */ opt.local_decl_indent = opt.decl_indent; -if (opt.decl_com_ind <= 0) /* if not specified by user, set this */ - opt.decl_com_ind = opt.ljust_decl ? (opt.com_ind <= 10 ? 2 : opt.com_ind - 8) : opt.com_ind; +if (opt.decl_comment_column <= 0) /* if not specified by user, set this */ + opt.decl_comment_column = opt.ljust_decl + ? (opt.comment_column <= 10 ? 2 : opt.comment_column - 8) + : opt.comment_column; if (opt.continuation_indent == 0) - opt.continuation_indent = opt.ind_size; + opt.continuation_indent = opt.indent_size; } static void @@ -538,8 +540,8 @@ main_prepare_parsing(void) break; p++; } -if (col > opt.ind_size) - ps.ind_level = ps.i_l_follow = col / opt.ind_size; +if (col > opt.indent_size) + ps.ind_level = ps.i_l_follow = col / opt.indent_size; } static void @@ -641,8 +643,8 @@ process_lparen_or_lbracket(int dec_ind, ps.paren_indents[ps.p_l_follow - 1] = indentation_after_range(0, s_code, e_code); if (sp_sw && ps.p_l_follow == 1 &&
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 13 13:25:23 UTC 2021 Modified Files: src/usr.bin/indent: indent.c indent.h indent_globs.h pr_comment.c Log Message: indent: rename pr_comment to process_comment, clean up documentation No functional change. To generate a diff of this commit: cvs rdiff -u -r1.55 -r1.56 src/usr.bin/indent/indent.c cvs rdiff -u -r1.13 -r1.14 src/usr.bin/indent/indent.h cvs rdiff -u -r1.18 -r1.19 src/usr.bin/indent/indent_globs.h cvs rdiff -u -r1.27 -r1.28 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.55 src/usr.bin/indent/indent.c:1.56 --- src/usr.bin/indent/indent.c:1.55 Sat Mar 13 13:14:14 2021 +++ src/usr.bin/indent/indent.c Sat Mar 13 13:25:23 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.55 2021/03/13 13:14:14 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.56 2021/03/13 13:25:23 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.55 2021/03/13 13:14:14 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.56 2021/03/13 13:25:23 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -212,7 +212,7 @@ search_brace(token_type *inout_type_code if (sc_end == NULL) { /* * Copy everything from the start of the line, because - * pr_comment() will use that to calculate original + * process_comment() will use that to calculate original * indentation of a boxed comment. */ memcpy(sc_buf, in_buffer, buf_ptr - in_buffer - 4); @@ -1439,8 +1439,8 @@ main_loop(void) case preprocessing: /* '#' */ process_preprocessing(); break; - case comment: /* we have gotten a '/' followed by '*' */ - pr_comment(); + case comment: /* the initial '/' '*' or '//' of a comment */ + process_comment(); break; default: Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.13 src/usr.bin/indent/indent.h:1.14 --- src/usr.bin/indent/indent.h:1.13 Sat Mar 13 10:32:25 2021 +++ src/usr.bin/indent/indent.h Sat Mar 13 13:25:23 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.13 2021/03/13 10:32:25 rillig Exp $ */ +/* $NetBSD: indent.h,v 1.14 2021/03/13 13:25:23 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -30,7 +30,7 @@ #if 0 #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.h,v 1.13 2021/03/13 10:32:25 rillig Exp $"); +__RCSID("$NetBSD: indent.h,v 1.14 2021/03/13 13:25:23 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 336333 2018-07-16 05:46:50Z pstef $"); #endif @@ -65,7 +65,7 @@ void diag(int, const char *, ...) __prin void dump_line(void); void fill_buffer(void); void parse(token_type); -void pr_comment(void); +void process_comment(void); void set_defaults(void); void set_option(char *); void set_profile(const char *); Index: src/usr.bin/indent/indent_globs.h diff -u src/usr.bin/indent/indent_globs.h:1.18 src/usr.bin/indent/indent_globs.h:1.19 --- src/usr.bin/indent/indent_globs.h:1.18 Sat Mar 13 11:19:43 2021 +++ src/usr.bin/indent/indent_globs.h Sat Mar 13 13:25:23 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent_globs.h,v 1.18 2021/03/13 11:19:43 rillig Exp $ */ +/* $NetBSD: indent_globs.h,v 1.19 2021/03/13 13:25:23 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -254,7 +254,7 @@ extern struct parser_state { int last_u_d; /* set to true after scanning a token which * forces a following operator to be unary */ int out_coms; /* the number of comments processed, set by - * pr_comment */ + * process_comment */ int out_lines; /* the number of lines written, set by * dump_line */ int p_l_follow; /* used to remember how to indent following Index: src/usr.bin/indent/pr_comment.c diff -u src/usr.bin/indent/pr_comment.c:1.27 src/usr.bin/indent/pr_comment.c:1.28 --- src/usr.bin/indent/pr_comment.c:1.27 Sat Mar 13 11:27:01 2021 +++ src/usr.bin/indent/pr_comment.c Sat Mar 13 13:25:23 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: pr_comment.c,v 1.27 2021/03/13 11:27:01 rillig Exp $ */ +/* $NetBSD: pr_comment.c,v 1.28 2021/03/13 13:25:23 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)pr_comment.c #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: pr_comment.c,v 1.27 2021/03/13 11:27:01 rillig Exp $"); +__RCSID("$NetBSD: pr_comment.c,v 1.28 2021/03/13 13:25:23 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -79,38 +79,25 @@ check_size_comment(size_t desired_size,
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 13 12:52:24 UTC 2021 Modified Files: src/usr.bin/indent: indent.c Log Message: indent: split 'main_loop' into several functions No functional change. To generate a diff of this commit: cvs rdiff -u -r1.53 -r1.54 src/usr.bin/indent/indent.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.53 src/usr.bin/indent/indent.c:1.54 --- src/usr.bin/indent/indent.c:1.53 Sat Mar 13 11:47:22 2021 +++ src/usr.bin/indent/indent.c Sat Mar 13 12:52:24 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.53 2021/03/13 11:47:22 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.54 2021/03/13 12:52:24 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.53 2021/03/13 11:47:22 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.54 2021/03/13 12:52:24 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -543,6 +543,719 @@ main_prepare_parsing(void) } static void +process_end_of_file(void) +{ +if (s_lab != e_lab || s_code != e_code || s_com != e_com) + dump_line(); + +if (ps.tos > 1) /* check for balanced braces */ + diag(1, "Stuff missing from end of file"); + +if (opt.verbose) { + printf("There were %d output lines and %d comments\n", + ps.out_lines, ps.out_coms); + printf("(Lines with comments)/(Lines with code): %6.3f\n", + (1.0 * ps.com_lines) / code_lines); +} + +fflush(output); +exit(found_err); +} + +static void +process_comment_in_code(token_type type_code, int *inout_force_nl) +{ +if (*inout_force_nl && + type_code != semicolon && + (type_code != lbrace || !opt.btype_2)) { + + /* we should force a broken line here */ + if (opt.verbose) + diag(0, "Line broken"); + dump_line(); + ps.want_blank = false; /* dont insert blank at line start */ + *inout_force_nl = false; +} + +ps.in_stmt = true; /* turn on flag which causes an extra level of + * indentation. this is turned off by a ; or + * '}' */ +if (s_com != e_com) { /* the turkey has embedded a comment + * in a line. fix it */ + int len = e_com - s_com; + + check_size_code(len + 3); + *e_code++ = ' '; + memcpy(e_code, s_com, len); + e_code += len; + *e_code++ = ' '; + *e_code = '\0'; /* null terminate code sect */ + ps.want_blank = false; + e_com = s_com; +} +} + +static void +process_form_feed(void) +{ +ps.use_ff = true; /* a form feed is treated much like a newline */ +dump_line(); +ps.want_blank = false; +} + +static void +process_newline(void) +{ +if (ps.last_token != comma || ps.p_l_follow > 0 + || !opt.leave_comma || ps.block_init || !break_comma || s_com != e_com) { + dump_line(); + ps.want_blank = false; +} +++line_no; /* keep track of input line number */ +} + +static void +process_lparen_or_lbracket(int dec_ind, int tabs_to_var, int sp_sw) +{ +/* count parens to make Healy happy */ +if (++ps.p_l_follow == nitems(ps.paren_indents)) { + diag(0, "Reached internal limit of %zu unclosed parens", + nitems(ps.paren_indents)); + ps.p_l_follow--; +} +if (*token == '[') + /* not a function pointer declaration or a function call */; +else if (ps.in_decl && !ps.block_init && !ps.dumped_decl_indent && + ps.procname[0] == '\0' && ps.paren_level == 0) { + /* function pointer declarations */ + indent_declaration(dec_ind, tabs_to_var); + ps.dumped_decl_indent = true; +} else if (ps.want_blank && + ((ps.last_token != ident && ps.last_token != funcname) || + opt.proc_calls_space || + (ps.keyword == rw_sizeof ? opt.Bill_Shannon : + ps.keyword != rw_0 && ps.keyword != rw_offsetof))) + *e_code++ = ' '; +ps.want_blank = false; +*e_code++ = token[0]; +ps.paren_indents[ps.p_l_follow - 1] = + indentation_after_range(0, s_code, e_code); +if (sp_sw && ps.p_l_follow == 1 && opt.extra_expression_indent + && ps.paren_indents[0] < 2 * opt.ind_size) + ps.paren_indents[0] = 2 * opt.ind_size; +if (ps.in_or_st && *token == '(' && ps.tos <= 2) { + /* + * this is a kluge to make sure that declarations will be + * aligned right if proc decl has an explicit type on it, i.e. + * "int a(x) {..." + */ + parse(semicolon); /* I said this was a kluge... */ + ps.in_or_st = false; /* turn off flag for structure decl or + * initialization */ +} +/* parenthesized type following sizeof or offsetof is not a cast */ +if (ps.keyword == rw_offsetof || ps.keyword == rw_sizeof) + ps.not_cast_mask |= 1 << ps.p_l_follow; +} + +static void +process_rparen_or_rbracket(int *inout_sp_sw, int *inout_force_nl, + token_type hd_type) +{ +if (ps.cast_mask & (1 <<
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 13 11:47:22 UTC 2021 Modified Files: src/usr.bin/indent: indent.c Log Message: indent: split 'main' into manageable parts Since several years (maybe even decades) compilers know how to inline static functions that are only used once. Therefore there is no need to have overly long functions anymore, especially not 'main', which is only called a single time and thus does not add any noticeable performance degradation. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.52 -r1.53 src/usr.bin/indent/indent.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.52 src/usr.bin/indent/indent.c:1.53 --- src/usr.bin/indent/indent.c:1.52 Sat Mar 13 11:27:01 2021 +++ src/usr.bin/indent/indent.c Sat Mar 13 11:47:22 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.52 2021/03/13 11:27:01 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.53 2021/03/13 11:47:22 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.52 2021/03/13 11:27:01 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.53 2021/03/13 11:47:22 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -366,33 +366,9 @@ search_brace(token_type *inout_type_code *inout_last_else = 0; } -int -main(int argc, char **argv) +static void +main_init_globals(void) { -int dec_ind; /* current indentation for declarations */ -int di_stack[20]; /* a stack of structure indentation levels */ -int force_nl; /* when true, code must be broken */ -token_type hd_type = end_of_file; /* used to store type of stmt - * for if (...), for (...), etc */ -int i; /* local loop counter */ -int scase; /* set to true when we see a case, so we will - * know what to do with the following colon */ -int sp_sw; /* when true, we are in the expression of - * if(...), while(...), etc. */ -int squest; /* when this is positive, we have seen a ? - * without the matching : in a ?: - * construct */ -int tabs_to_var; /* true if using tabs to indent to var name */ -token_type type_code; /* returned by lexi */ - -int last_else = 0; /* true iff last keyword was an else */ -const char *profile_name = NULL; -const char *envval = NULL; - -/*---*\ -| INITIALIZATION | -\*---*/ - found_err = 0; ps.p_stack[0] = stmt; /* this is the parser's stack */ @@ -433,31 +409,29 @@ main(int argc, char **argv) buf_ptr = buf_end = in_buffer; line_no = 1; had_eof = ps.in_decl = ps.decl_on_line = break_comma = false; -sp_sw = force_nl = false; ps.in_or_st = false; ps.bl_line = true; -dec_ind = 0; -di_stack[ps.dec_nest = 0] = 0; ps.want_blank = ps.in_stmt = ps.ind_stmt = false; -scase = ps.pcase = false; -squest = 0; +ps.pcase = false; sc_end = NULL; bp_save = NULL; be_save = NULL; output = NULL; -tabs_to_var = 0; -envval = getenv("SIMPLE_BACKUP_SUFFIX"); -if (envval) -simple_backup_suffix = envval; - -/*--*\ -| COMMAND LINE SCAN | -\*--*/ +const char *suffix = getenv("SIMPLE_BACKUP_SUFFIX"); +if (suffix != NULL) + simple_backup_suffix = suffix; +} + +static void +main_parse_command_line(int argc, char **argv) +{ +int i; +const char *profile_name = NULL; -#ifdef undef +#if 0 max_line_length = 78; /* -l78 */ lineup_to_parens = 1; /* -lp */ lineup_to_parens_always = 0; /* -nlpl */ @@ -533,10 +507,6 @@ main(int argc, char **argv) } } -#if HAVE_CAPSICUM -init_capsicum(); -#endif - if (opt.com_ind <= 1) opt.com_ind = 2; /* don't put normal comments before column 2 */ if (opt.block_comment_max_line_length <= 0) @@ -547,29 +517,56 @@ main(int argc, char **argv) opt.decl_com_ind = opt.ljust_decl ? (opt.com_ind <= 10 ? 2 : opt.com_ind - 8) : opt.com_ind; if (opt.continuation_indent == 0) opt.continuation_indent = opt.ind_size; +} + +static void +main_prepare_parsing(void) +{ fill_buffer(); /* get first batch of stuff into input buffer */ parse(semicolon); -{ - char *p = buf_ptr; - int col = 1; - - while (1) { - if (*p == ' ') - col++; - else if (*p == '\t') - col = opt.tabsize * (1 + (col - 1) / opt.tabsize) + 1; - else - break; - p++; - } - if (col > opt.ind_size) - ps.ind_level =
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 13 11:27:01 UTC 2021 Modified Files: src/usr.bin/indent: indent.c lexi.c pr_comment.c Log Message: indent: remove redundant parentheses No functional change. To generate a diff of this commit: cvs rdiff -u -r1.51 -r1.52 src/usr.bin/indent/indent.c cvs rdiff -u -r1.39 -r1.40 src/usr.bin/indent/lexi.c cvs rdiff -u -r1.26 -r1.27 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.51 src/usr.bin/indent/indent.c:1.52 --- src/usr.bin/indent/indent.c:1.51 Sat Mar 13 11:19:43 2021 +++ src/usr.bin/indent/indent.c Sat Mar 13 11:27:01 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.51 2021/03/13 11:19:43 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.52 2021/03/13 11:27:01 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.51 2021/03/13 11:19:43 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.52 2021/03/13 11:27:01 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -604,12 +604,12 @@ main(int argc, char **argv) exit(found_err); } if ( - (type_code != comment) && - (type_code != newline) && - (type_code != preprocessing) && - (type_code != form_feed)) { + type_code != comment && + type_code != newline && + type_code != preprocessing && + type_code != form_feed) { if (force_nl && - (type_code != semicolon) && + type_code != semicolon && (type_code != lbrace || !opt.btype_2)) { /* we should force a broken line here */ if (opt.verbose) @@ -1159,9 +1159,7 @@ main(int argc, char **argv) break; case preprocessing: /* '#' */ - if ((s_com != e_com) || - (s_lab != e_lab) || - (s_code != e_code)) + if (s_com != e_com || s_lab != e_lab || s_code != e_code) dump_line(); check_size_label(1); *e_lab++ = '#'; /* move whole line to 'label' buffer */ Index: src/usr.bin/indent/lexi.c diff -u src/usr.bin/indent/lexi.c:1.39 src/usr.bin/indent/lexi.c:1.40 --- src/usr.bin/indent/lexi.c:1.39 Sat Mar 13 09:21:57 2021 +++ src/usr.bin/indent/lexi.c Sat Mar 13 11:27:01 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lexi.c,v 1.39 2021/03/13 09:21:57 rillig Exp $ */ +/* $NetBSD: lexi.c,v 1.40 2021/03/13 11:27:01 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)lexi.c 8.1 ( #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: lexi.c,v 1.39 2021/03/13 09:21:57 rillig Exp $"); +__RCSID("$NetBSD: lexi.c,v 1.40 2021/03/13 11:27:01 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $"); #endif @@ -502,14 +502,14 @@ stop_lit: code = ident; break; -case ('('): -case ('['): +case '(': +case '[': unary_delim = true; code = lparen; break; -case (')'): -case (']'): +case ')': +case ']': code = rparen; break; @@ -523,17 +523,17 @@ stop_lit: code = question; break; -case (':'): +case ':': code = colon; unary_delim = true; break; -case (';'): +case ';': unary_delim = true; code = semicolon; break; -case ('{'): +case '{': unary_delim = true; /* @@ -543,7 +543,7 @@ stop_lit: code = lbrace; break; -case ('}'): +case '}': unary_delim = true; /* ? code = state->block_init ? rparen : rbrace; */ code = rbrace; @@ -556,7 +556,7 @@ stop_lit: code = form_feed; break; -case (','): +case ',': unary_delim = true; code = comma; break; Index: src/usr.bin/indent/pr_comment.c diff -u src/usr.bin/indent/pr_comment.c:1.26 src/usr.bin/indent/pr_comment.c:1.27 --- src/usr.bin/indent/pr_comment.c:1.26 Sat Mar 13 11:19:43 2021 +++ src/usr.bin/indent/pr_comment.c Sat Mar 13 11:27:01 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: pr_comment.c,v 1.26 2021/03/13 11:19:43 rillig Exp $ */ +/* $NetBSD: pr_comment.c,v 1.27 2021/03/13 11:27:01 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)pr_comment.c #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: pr_comment.c,v 1.26 2021/03/13 11:19:43 rillig Exp $"); +__RCSID("$NetBSD: pr_comment.c,v 1.27 2021/03/13 11:27:01 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -147,7 +147,7 @@ pr_comment(void) * is nonzero (the default). */ break_delim = false; } - if ( /* ps.bl_line && */ (s_lab == e_lab) && (s_code == e_code)) { + if ( /* ps.bl_line && */ s_lab == e_lab && s_code == e_code) { /* klg:
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 13 11:19:43 UTC 2021 Modified Files: src/usr.bin/indent: args.c indent.c indent_globs.h io.c pr_comment.c Log Message: indent: fix confusing variable names The word 'col' should only be used for the 1-based column number. This name is completely inappropriate for a line length since that provokes off-by-one errors. The name 'cols' would be acceptable although confusing since it sounds so similar to 'col'. Therefore, rename variables that are related to the maximum line length to 'line_length' since that makes for obvious code and nicely relates to the description of the option in the manual page. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/usr.bin/indent/args.c cvs rdiff -u -r1.50 -r1.51 src/usr.bin/indent/indent.c cvs rdiff -u -r1.17 -r1.18 src/usr.bin/indent/indent_globs.h cvs rdiff -u -r1.41 -r1.42 src/usr.bin/indent/io.c cvs rdiff -u -r1.25 -r1.26 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/args.c diff -u src/usr.bin/indent/args.c:1.19 src/usr.bin/indent/args.c:1.20 --- src/usr.bin/indent/args.c:1.19 Fri Mar 12 23:10:18 2021 +++ src/usr.bin/indent/args.c Sat Mar 13 11:19:43 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: args.c,v 1.19 2021/03/12 23:10:18 rillig Exp $ */ +/* $NetBSD: args.c,v 1.20 2021/03/13 11:19:43 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)args.c 8.1 ( #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: args.c,v 1.19 2021/03/12 23:10:18 rillig Exp $"); +__RCSID("$NetBSD: args.c,v 1.20 2021/03/13 11:19:43 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $"); #endif @@ -135,11 +135,11 @@ const struct pro { {"fcb", PRO_BOOL, true, ON, _block_comments}, {"ip", PRO_BOOL, true, ON, _parameters}, {"i", PRO_INT, 8, 0, _size}, -{"lc", PRO_INT, 0, 0, _comment_max_col}, +{"lc", PRO_INT, 0, 0, _comment_max_line_length}, {"ldi", PRO_INT, -1, 0, _decl_indent}, {"lpl", PRO_BOOL, false, ON, _to_parens_always}, {"lp", PRO_BOOL, true, ON, _to_parens}, -{"l", PRO_INT, 78, 0, _col}, +{"l", PRO_INT, 78, 0, _line_length}, {"nbacc", PRO_BOOL, false, OFF, _around_conditional_compilation}, {"nbadp", PRO_BOOL, false, OFF, _after_declarations_at_proctop}, {"nbad", PRO_BOOL, false, OFF, _after_declarations}, Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.50 src/usr.bin/indent/indent.c:1.51 --- src/usr.bin/indent/indent.c:1.50 Sat Mar 13 10:32:25 2021 +++ src/usr.bin/indent/indent.c Sat Mar 13 11:19:43 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.50 2021/03/13 10:32:25 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.51 2021/03/13 11:19:43 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.50 2021/03/13 10:32:25 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.51 2021/03/13 11:19:43 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -458,9 +458,9 @@ main(int argc, char **argv) \*--*/ #ifdef undef -max_col = 78; /* -l78 */ +max_line_length = 78; /* -l78 */ lineup_to_parens = 1; /* -lp */ -lineup_to_parens_always = 0; /* -nlpl */ +lineup_to_parens_always = 0; /* -nlpl */ ps.ljust_decl = 0; /* -ndj */ ps.com_ind = 33; /* -c33 */ star_comment_cont = 1; /* -sc */ @@ -539,8 +539,8 @@ main(int argc, char **argv) if (opt.com_ind <= 1) opt.com_ind = 2; /* don't put normal comments before column 2 */ -if (opt.block_comment_max_col <= 0) - opt.block_comment_max_col = opt.max_col; +if (opt.block_comment_max_line_length <= 0) + opt.block_comment_max_line_length = opt.max_line_length; if (opt.local_decl_indent < 0) /* if not specified by user, set this */ opt.local_decl_indent = opt.decl_indent; if (opt.decl_com_ind <= 0) /* if not specified by user, set this */ @@ -1151,9 +1151,9 @@ main(int argc, char **argv) if (ps.block_init_level <= 0) ps.block_init = 0; if (break_comma && (!opt.leave_comma || - 1 + indentation_after_range( + indentation_after_range( compute_code_indent(), s_code, e_code) - > opt.max_col - opt.tabsize)) + >= opt.max_line_length - opt.tabsize)) force_nl = true; } break; Index: src/usr.bin/indent/indent_globs.h diff -u src/usr.bin/indent/indent_globs.h:1.17 src/usr.bin/indent/indent_globs.h:1.18 --- src/usr.bin/indent/indent_globs.h:1.17 Mon Mar 8 20:20:11 2021 +++
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 13 10:47:59 UTC 2021 Modified Files: src/usr.bin/indent: pr_comment.c Log Message: indent: document undefined behavior in processing of comments No functional change. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/pr_comment.c diff -u src/usr.bin/indent/pr_comment.c:1.24 src/usr.bin/indent/pr_comment.c:1.25 --- src/usr.bin/indent/pr_comment.c:1.24 Sat Mar 13 10:32:25 2021 +++ src/usr.bin/indent/pr_comment.c Sat Mar 13 10:47:59 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: pr_comment.c,v 1.24 2021/03/13 10:32:25 rillig Exp $ */ +/* $NetBSD: pr_comment.c,v 1.25 2021/03/13 10:47:59 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)pr_comment.c #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: pr_comment.c,v 1.24 2021/03/13 10:32:25 rillig Exp $"); +__RCSID("$NetBSD: pr_comment.c,v 1.25 2021/03/13 10:47:59 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -186,6 +186,10 @@ pr_comment(void) */ char *start; + /* + * XXX: ordered comparison between pointers from different objects + * invokes undefined behavior (C99 6.5.8). + */ start = buf_ptr >= save_com && buf_ptr < save_com + sc_size ? sc_buf : in_buffer; ps.n_comment_delta = -indentation_after_range(0, start, buf_ptr - 2);
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 13 10:32:25 UTC 2021 Modified Files: src/usr.bin/indent: indent.c indent.h io.c pr_comment.c Log Message: indent: inline calls to count_spaces and count_spaces_until These two functions operated on column numbers instead of indentation, which required adjustments of '+ 1' and '- 1'. Their names were completely wrong since these functions did not count anything, instead they computed the column. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.49 -r1.50 src/usr.bin/indent/indent.c cvs rdiff -u -r1.12 -r1.13 src/usr.bin/indent/indent.h cvs rdiff -u -r1.40 -r1.41 src/usr.bin/indent/io.c cvs rdiff -u -r1.23 -r1.24 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.49 src/usr.bin/indent/indent.c:1.50 --- src/usr.bin/indent/indent.c:1.49 Sat Mar 13 10:06:47 2021 +++ src/usr.bin/indent/indent.c Sat Mar 13 10:32:25 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.49 2021/03/13 10:06:47 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.50 2021/03/13 10:32:25 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.49 2021/03/13 10:06:47 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.50 2021/03/13 10:32:25 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -686,7 +686,8 @@ main(int argc, char **argv) *e_code++ = ' '; ps.want_blank = false; *e_code++ = token[0]; - ps.paren_indents[ps.p_l_follow - 1] = count_spaces_until(1, s_code, e_code) - 1; + ps.paren_indents[ps.p_l_follow - 1] = + indentation_after_range(0, s_code, e_code); if (sp_sw && ps.p_l_follow == 1 && opt.extra_expression_indent && ps.paren_indents[0] < 2 * opt.ind_size) ps.paren_indents[0] = 2 * opt.ind_size; @@ -1150,8 +1151,9 @@ main(int argc, char **argv) if (ps.block_init_level <= 0) ps.block_init = 0; if (break_comma && (!opt.leave_comma || - count_spaces_until(1 + compute_code_indent(), s_code, e_code) > - opt.max_col - opt.tabsize)) + 1 + indentation_after_range( + compute_code_indent(), s_code, e_code) + > opt.max_col - opt.tabsize)) force_nl = true; } break; Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.12 src/usr.bin/indent/indent.h:1.13 --- src/usr.bin/indent/indent.h:1.12 Sat Mar 13 10:20:54 2021 +++ src/usr.bin/indent/indent.h Sat Mar 13 10:32:25 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.12 2021/03/13 10:20:54 rillig Exp $ */ +/* $NetBSD: indent.h,v 1.13 2021/03/13 10:32:25 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -30,7 +30,7 @@ #if 0 #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.h,v 1.12 2021/03/13 10:20:54 rillig Exp $"); +__RCSID("$NetBSD: indent.h,v 1.13 2021/03/13 10:32:25 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 336333 2018-07-16 05:46:50Z pstef $"); #endif @@ -47,8 +47,6 @@ void add_typename(const char *); void alloc_typenames(void); int compute_code_indent(void); int compute_label_indent(void); -int count_spaces(int, const char *); -int count_spaces_until(int, const char *, const char *); int indentation_after_range(int, const char *, const char *); int indentation_after(int, const char *); void init_constant_tt(void); Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.40 src/usr.bin/indent/io.c:1.41 --- src/usr.bin/indent/io.c:1.40 Sat Mar 13 10:20:54 2021 +++ src/usr.bin/indent/io.c Sat Mar 13 10:32:25 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.40 2021/03/13 10:20:54 rillig Exp $ */ +/* $NetBSD: io.c,v 1.41 2021/03/13 10:32:25 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.40 2021/03/13 10:20:54 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.41 2021/03/13 10:32:25 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -184,7 +184,7 @@ dump_line(void) } } else output_range(s_lab, e_lab); - cur_col = count_spaces(cur_col, s_lab); + cur_col = 1 + indentation_after(cur_col - 1, s_lab); } else cur_col = 1; /* there is no label section */ @@ -215,7 +215,7 @@ dump_line(void) } cur_col = 1 + output_indent(cur_col - 1, target_col - 1); output_range(s_code, e_code); - cur_col = count_spaces(cur_col, s_code); + cur_col = 1 + indentation_after(cur_col - 1, s_code); } if (s_com != e_com) {
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 13 10:20:54 UTC 2021 Modified Files: src/usr.bin/indent: indent.h io.c Log Message: indent: replace column computation with indentation computation No functional change. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/usr.bin/indent/indent.h cvs rdiff -u -r1.39 -r1.40 src/usr.bin/indent/io.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.11 src/usr.bin/indent/indent.h:1.12 --- src/usr.bin/indent/indent.h:1.11 Sat Mar 13 10:06:47 2021 +++ src/usr.bin/indent/indent.h Sat Mar 13 10:20:54 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.11 2021/03/13 10:06:47 rillig Exp $ */ +/* $NetBSD: indent.h,v 1.12 2021/03/13 10:20:54 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -30,7 +30,7 @@ #if 0 #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.h,v 1.11 2021/03/13 10:06:47 rillig Exp $"); +__RCSID("$NetBSD: indent.h,v 1.12 2021/03/13 10:20:54 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 336333 2018-07-16 05:46:50Z pstef $"); #endif @@ -49,6 +49,8 @@ int compute_code_indent(void); int compute_label_indent(void); int count_spaces(int, const char *); int count_spaces_until(int, const char *, const char *); +int indentation_after_range(int, const char *, const char *); +int indentation_after(int, const char *); void init_constant_tt(void); #ifdef debug void debug_vis_range(const char *, const char *, const char *, const char *); Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.39 src/usr.bin/indent/io.c:1.40 --- src/usr.bin/indent/io.c:1.39 Sat Mar 13 10:06:47 2021 +++ src/usr.bin/indent/io.c Sat Mar 13 10:20:54 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.39 2021/03/13 10:06:47 rillig Exp $ */ +/* $NetBSD: io.c,v 1.40 2021/03/13 10:20:54 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.39 2021/03/13 10:06:47 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.40 2021/03/13 10:20:54 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -425,42 +425,38 @@ fill_buffer(void) } } -/* - * Copyright (C) 1976 by the Board of Trustees of the University of Illinois - * - * All rights reserved - */ int -count_spaces_until(int col, const char *buffer, const char *end) +indentation_after_range(int ind, const char *start, const char *end) { -for (const char *p = buffer; *p != '\0' && p != end; ++p) { - switch (*p) { - - case '\n': - case 014: /* form feed */ - col = 1; - break; - - case '\t': - col = 1 + opt.tabsize * ((col - 1) / opt.tabsize + 1); - break; +for (const char *p = start; *p != '\0' && p != end; ++p) { + if (*p == '\n' || *p == '\f') + ind = 0; + else if (*p == '\t') + ind = opt.tabsize * (ind / opt.tabsize + 1); + else if (*p == '\b') + --ind; + else + ++ind; +} +return ind; +} - case 010: /* backspace */ - --col; - break; +int +indentation_after(int ind, const char *s) +{ +return indentation_after_range(ind, s, NULL); +} - default: - ++col; - break; - } /* end of switch */ -}/* end of for loop */ -return col; +int +count_spaces_until(int col, const char *s, const char *e) +{ +return 1 + indentation_after_range(col - 1, s, e); } int -count_spaces(int col, const char *buffer) +count_spaces(int col, const char *s) { -return count_spaces_until(col, buffer, NULL); +return 1 + indentation_after(col - 1, s); } void
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 13 10:06:47 UTC 2021 Modified Files: src/usr.bin/indent: indent.c indent.h io.c pr_comment.c Log Message: indent: replace compute_code_column with compute_code_indent The goal is to only ever be concerned about the _indentation_ of a token, never the _column_ it appears in. Having only one of these avoids off-by-one errors. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.48 -r1.49 src/usr.bin/indent/indent.c cvs rdiff -u -r1.10 -r1.11 src/usr.bin/indent/indent.h cvs rdiff -u -r1.38 -r1.39 src/usr.bin/indent/io.c cvs rdiff -u -r1.22 -r1.23 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.48 src/usr.bin/indent/indent.c:1.49 --- src/usr.bin/indent/indent.c:1.48 Sat Mar 13 09:21:57 2021 +++ src/usr.bin/indent/indent.c Sat Mar 13 10:06:47 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.48 2021/03/13 09:21:57 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.49 2021/03/13 10:06:47 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.48 2021/03/13 09:21:57 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.49 2021/03/13 10:06:47 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -1150,7 +1150,7 @@ main(int argc, char **argv) if (ps.block_init_level <= 0) ps.block_init = 0; if (break_comma && (!opt.leave_comma || - count_spaces_until(compute_code_column(), s_code, e_code) > + count_spaces_until(1 + compute_code_indent(), s_code, e_code) > opt.max_col - opt.tabsize)) force_nl = true; } Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.10 src/usr.bin/indent/indent.h:1.11 --- src/usr.bin/indent/indent.h:1.10 Sat Mar 13 09:54:11 2021 +++ src/usr.bin/indent/indent.h Sat Mar 13 10:06:47 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.10 2021/03/13 09:54:11 rillig Exp $ */ +/* $NetBSD: indent.h,v 1.11 2021/03/13 10:06:47 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -30,7 +30,7 @@ #if 0 #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.h,v 1.10 2021/03/13 09:54:11 rillig Exp $"); +__RCSID("$NetBSD: indent.h,v 1.11 2021/03/13 10:06:47 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 336333 2018-07-16 05:46:50Z pstef $"); #endif @@ -45,7 +45,7 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/ void add_typename(const char *); void alloc_typenames(void); -int compute_code_column(void); +int compute_code_indent(void); int compute_label_indent(void); int count_spaces(int, const char *); int count_spaces_until(int, const char *, const char *); Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.38 src/usr.bin/indent/io.c:1.39 --- src/usr.bin/indent/io.c:1.38 Sat Mar 13 09:54:11 2021 +++ src/usr.bin/indent/io.c Sat Mar 13 10:06:47 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.38 2021/03/13 09:54:11 rillig Exp $ */ +/* $NetBSD: io.c,v 1.39 2021/03/13 10:06:47 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.38 2021/03/13 09:54:11 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.39 2021/03/13 10:06:47 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -195,7 +195,7 @@ dump_line(void) comment_open = 0; output_string(".*/\n"); } - target_col = compute_code_column(); + target_col = 1 + compute_code_indent(); { int i; @@ -287,31 +287,36 @@ dump_line(void) } int -compute_code_column(void) +compute_code_indent(void) { -int target_col = opt.ind_size * ps.ind_level + 1; +int target_ind = opt.ind_size * ps.ind_level; -if (ps.paren_level) { +if (ps.paren_level != 0) { if (!opt.lineup_to_parens) - target_col += opt.continuation_indent * + target_ind += opt.continuation_indent * (2 * opt.continuation_indent == opt.ind_size ? 1 : ps.paren_level); else if (opt.lineup_to_parens_always) - target_col = paren_indent; + /* + * XXX: where does this '- 1' come from? It looks strange but is + * nevertheless needed for proper indentation, as demonstrated in + * the test opt-lpl.0. + */ + target_ind = paren_indent - 1; else { int w; int t = paren_indent; if ((w = count_spaces(t, s_code) - opt.max_col) > 0 - && count_spaces(target_col, s_code) <= opt.max_col) { + && count_spaces(target_ind + 1, s_code) <=
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 13 09:54:12 UTC 2021 Modified Files: src/usr.bin/indent: indent.h io.c pr_comment.c Log Message: indent: replace compute_label_column with compute_label_indent Using the invariant 'column == 1 + indent'. This removes several overly complicated '+ 1' from the code that are not needed conceptually. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/usr.bin/indent/indent.h cvs rdiff -u -r1.37 -r1.38 src/usr.bin/indent/io.c cvs rdiff -u -r1.21 -r1.22 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.9 src/usr.bin/indent/indent.h:1.10 --- src/usr.bin/indent/indent.h:1.9 Sat Mar 13 09:21:57 2021 +++ src/usr.bin/indent/indent.h Sat Mar 13 09:54:11 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.9 2021/03/13 09:21:57 rillig Exp $ */ +/* $NetBSD: indent.h,v 1.10 2021/03/13 09:54:11 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -30,7 +30,7 @@ #if 0 #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.h,v 1.9 2021/03/13 09:21:57 rillig Exp $"); +__RCSID("$NetBSD: indent.h,v 1.10 2021/03/13 09:54:11 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 336333 2018-07-16 05:46:50Z pstef $"); #endif @@ -46,7 +46,7 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/ void add_typename(const char *); void alloc_typenames(void); int compute_code_column(void); -int compute_label_column(void); +int compute_label_indent(void); int count_spaces(int, const char *); int count_spaces_until(int, const char *, const char *); void init_constant_tt(void); Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.37 src/usr.bin/indent/io.c:1.38 --- src/usr.bin/indent/io.c:1.37 Sat Mar 13 09:48:04 2021 +++ src/usr.bin/indent/io.c Sat Mar 13 09:54:11 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.37 2021/03/13 09:48:04 rillig Exp $ */ +/* $NetBSD: io.c,v 1.38 2021/03/13 09:54:11 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.37 2021/03/13 09:48:04 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.38 2021/03/13 09:54:11 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -162,7 +162,7 @@ dump_line(void) while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == '\t')) e_lab--; *e_lab = '\0'; - cur_col = 1 + output_indent(0, compute_label_column() - 1); + cur_col = 1 + output_indent(0, compute_label_indent()); if (s_lab[0] == '#' && (strncmp(s_lab, "#else", 5) == 0 || strncmp(s_lab, "#endif", 6) == 0)) { char *s = s_lab; @@ -315,12 +315,13 @@ compute_code_column(void) } int -compute_label_column(void) +compute_label_indent(void) { -return - ps.pcase ? (int) (case_ind * opt.ind_size) + 1 - : *s_lab == '#' ? 1 - : opt.ind_size * (ps.ind_level - label_offset) + 1; +if (ps.pcase) + return (int) (case_ind * opt.ind_size); +if (s_lab[0] == '#') +return 0; +return opt.ind_size * (ps.ind_level - label_offset); } Index: src/usr.bin/indent/pr_comment.c diff -u src/usr.bin/indent/pr_comment.c:1.21 src/usr.bin/indent/pr_comment.c:1.22 --- src/usr.bin/indent/pr_comment.c:1.21 Sat Mar 13 00:26:56 2021 +++ src/usr.bin/indent/pr_comment.c Sat Mar 13 09:54:11 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: pr_comment.c,v 1.21 2021/03/13 00:26:56 rillig Exp $ */ +/* $NetBSD: pr_comment.c,v 1.22 2021/03/13 09:54:11 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)pr_comment.c #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: pr_comment.c,v 1.21 2021/03/13 00:26:56 rillig Exp $"); +__RCSID("$NetBSD: pr_comment.c,v 1.22 2021/03/13 09:54:11 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -166,7 +166,7 @@ pr_comment(void) else { target_col = 1; if (s_lab != e_lab) - target_col = count_spaces(compute_label_column(), s_lab); + target_col = count_spaces(compute_label_indent() + 1, s_lab); } ps.com_col = ps.decl_on_line || ps.ind_level == 0 ? opt.decl_com_ind : opt.com_ind; if (ps.com_col <= target_col)
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 13 09:48:04 UTC 2021 Modified Files: src/usr.bin/indent: io.c Log Message: indent: manually fix indentation in indent's own source code To generate a diff of this commit: cvs rdiff -u -r1.36 -r1.37 src/usr.bin/indent/io.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.36 src/usr.bin/indent/io.c:1.37 --- src/usr.bin/indent/io.c:1.36 Sat Mar 13 09:21:57 2021 +++ src/usr.bin/indent/io.c Sat Mar 13 09:48:04 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.36 2021/03/13 09:21:57 rillig Exp $ */ +/* $NetBSD: io.c,v 1.37 2021/03/13 09:48:04 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.36 2021/03/13 09:21:57 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.37 2021/03/13 09:48:04 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -357,15 +357,15 @@ fill_buffer(void) in_buffer_limit = in_buffer + size - 2; } if ((i = getc(f)) == EOF) { - *p++ = ' '; - *p++ = '\n'; - had_eof = true; - break; + *p++ = ' '; + *p++ = '\n'; + had_eof = true; + break; } if (i != '\0') *p++ = i; if (i == '\n') - break; + break; } buf_ptr = in_buffer; buf_end = p; @@ -373,7 +373,7 @@ fill_buffer(void) if (in_buffer[3] == 'I' && strncmp(in_buffer, "/**INDENT**", 11) == 0) fill_buffer(); /* flush indent error message */ else { - int com = 0; + int com = 0; p = in_buffer; while (*p == ' ' || *p == '\t')
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 13 09:21:57 UTC 2021 Modified Files: src/usr.bin/indent: indent.c indent.h io.c lexi.c Log Message: indent: add debug logging for actually writing to the output file Together with the results of the tokenizer and the 4 buffers for token, label, code and comment, the debug log now provides a good high-level view on how the indentation happens and where to look for the many remaining bugs. To generate a diff of this commit: cvs rdiff -u -r1.47 -r1.48 src/usr.bin/indent/indent.c cvs rdiff -u -r1.8 -r1.9 src/usr.bin/indent/indent.h cvs rdiff -u -r1.35 -r1.36 src/usr.bin/indent/io.c cvs rdiff -u -r1.38 -r1.39 src/usr.bin/indent/lexi.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.47 src/usr.bin/indent/indent.c:1.48 --- src/usr.bin/indent/indent.c:1.47 Sat Mar 13 00:26:56 2021 +++ src/usr.bin/indent/indent.c Sat Mar 13 09:21:57 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.47 2021/03/13 00:26:56 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.48 2021/03/13 09:21:57 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.47 2021/03/13 00:26:56 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.48 2021/03/13 09:21:57 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -1389,3 +1389,46 @@ indent_declaration(int cur_dec_ind, int ps.want_blank = false; } } + +#ifdef debug +void +debug_printf(const char *fmt, ...) +{ +FILE *f = output == stdout ? stderr : stdout; +va_list ap; + +va_start(ap, fmt); +vfprintf(f, fmt, ap); +va_end(ap); +} + +void +debug_println(const char *fmt, ...) +{ +FILE *f = output == stdout ? stderr : stdout; +va_list ap; + +va_start(ap, fmt); +vfprintf(f, fmt, ap); +va_end(ap); +fprintf(f, "\n"); +} + +void +debug_vis_range(const char *prefix, const char *s, const char *e, + const char *suffix) +{ +debug_printf("%s", prefix); +for (const char *p = s; p < e; p++) { + if (isprint((unsigned char)*p) && *p != '\\' && *p != '"') + debug_printf("%c", *p); + else if (*p == '\n') + debug_printf("\\n"); + else if (*p == '\t') + debug_printf("\\t"); + else + debug_printf("\\x%02x", *p); +} +debug_printf("%s", suffix); +} +#endif Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.8 src/usr.bin/indent/indent.h:1.9 --- src/usr.bin/indent/indent.h:1.8 Sat Mar 13 00:26:56 2021 +++ src/usr.bin/indent/indent.h Sat Mar 13 09:21:57 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.8 2021/03/13 00:26:56 rillig Exp $ */ +/* $NetBSD: indent.h,v 1.9 2021/03/13 09:21:57 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -30,7 +30,7 @@ #if 0 #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.h,v 1.8 2021/03/13 00:26:56 rillig Exp $"); +__RCSID("$NetBSD: indent.h,v 1.9 2021/03/13 09:21:57 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 336333 2018-07-16 05:46:50Z pstef $"); #endif @@ -51,7 +51,14 @@ int count_spaces(int, const char *); int count_spaces_until(int, const char *, const char *); void init_constant_tt(void); #ifdef debug +void debug_vis_range(const char *, const char *, const char *, const char *); +void debug_printf(const char *, ...) __printflike(1, 2); +void debug_println(const char *, ...) __printflike(1, 2); const char *token_type_name(token_type); +#else +#define debug_printf(fmt, ...) do { } while (false) +#define debug_println(fmt, ...) do { } while (false) +#define debug_vis_range(prefix, s, e, suffix) do { } while (false) #endif token_type lexi(struct parser_state *); void diag(int, const char *, ...) __printflike(2, 3); Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.35 src/usr.bin/indent/io.c:1.36 --- src/usr.bin/indent/io.c:1.35 Sat Mar 13 09:06:12 2021 +++ src/usr.bin/indent/io.c Sat Mar 13 09:21:57 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.35 2021/03/13 09:06:12 rillig Exp $ */ +/* $NetBSD: io.c,v 1.36 2021/03/13 09:21:57 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.35 2021/03/13 09:06:12 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.36 2021/03/13 09:21:57 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -68,12 +68,14 @@ static void output_char(char ch) { fputc(ch, output); +debug_vis_range("output_char '", , + 1, "'\n"); } static void output_range(const char *s, const
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 13 09:06:12 UTC 2021 Modified Files: src/usr.bin/indent: io.c Log Message: indent: remove strange debugging code that went in the output file Whenever the code to be output contained the magic byte 0x80, instead of writing this byte, indent wrote the column number at the beginning of the code snippet, times 7. Especially the 'times 7' does not make any sense at all. In ISO-8859-1, this character position is not assigned. In Microsoft Codepage 1252 it is the Euro sign. In UTF-8 (which was probably not on the author's list when the code was originally written) it occurs as the middle byte for code points like U+2026 (horizontal ellipsis) from the block General Punctuation. Remove this strange code, thereby fixing indent for UTF-8 code. The code had been there since at least 1993-04-09, when it was first imported to NetBSD. To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/usr.bin/indent/io.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.34 src/usr.bin/indent/io.c:1.35 --- src/usr.bin/indent/io.c:1.34 Sat Mar 13 00:26:56 2021 +++ src/usr.bin/indent/io.c Sat Mar 13 09:06:12 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.34 2021/03/13 00:26:56 rillig Exp $ */ +/* $NetBSD: io.c,v 1.35 2021/03/13 09:06:12 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.34 2021/03/13 00:26:56 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.35 2021/03/13 09:06:12 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -82,12 +82,6 @@ output_string(const char *s) output_range(s, s + strlen(s)); } -static void -output_int(int i) -{ -fprintf(output, "%d", i); -} - static int output_indent(int old_ind, int new_ind) { @@ -194,8 +188,6 @@ dump_line(void) ps.pcase = false; if (s_code != e_code) { /* print code section, if any */ - char *p; - if (comment_open) { comment_open = 0; output_string(".*/\n"); @@ -209,11 +201,7 @@ dump_line(void) ps.paren_indents[i] = -(ps.paren_indents[i] + target_col); } cur_col = 1 + output_indent(cur_col - 1, target_col - 1); - for (p = s_code; p < e_code; p++) - if (*p == (char) 0200) - output_int(target_col * 7); - else - output_char(*p); + output_range(s_code, e_code); cur_col = count_spaces(cur_col, s_code); } if (s_com != e_com) { /* print comment, if any */
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 13 00:26:56 UTC 2021 Modified Files: src/usr.bin/indent: indent.c indent.h io.c pr_comment.c Log Message: indent: replace pad_output with output_indent Calculating the indentation is simpler than calculating the column, since that saves the constant addition and subtraction of the 1. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.46 -r1.47 src/usr.bin/indent/indent.c cvs rdiff -u -r1.7 -r1.8 src/usr.bin/indent/indent.h cvs rdiff -u -r1.33 -r1.34 src/usr.bin/indent/io.c cvs rdiff -u -r1.20 -r1.21 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.46 src/usr.bin/indent/indent.c:1.47 --- src/usr.bin/indent/indent.c:1.46 Fri Mar 12 23:16:00 2021 +++ src/usr.bin/indent/indent.c Sat Mar 13 00:26:56 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.46 2021/03/12 23:16:00 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.47 2021/03/13 00:26:56 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.46 2021/03/12 23:16:00 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.47 2021/03/13 00:26:56 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -1150,7 +1150,7 @@ main(int argc, char **argv) if (ps.block_init_level <= 0) ps.block_init = 0; if (break_comma && (!opt.leave_comma || - count_spaces_until(compute_code_indent(), s_code, e_code) > + count_spaces_until(compute_code_column(), s_code, e_code) > opt.max_col - opt.tabsize)) force_nl = true; } Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.7 src/usr.bin/indent/indent.h:1.8 --- src/usr.bin/indent/indent.h:1.7 Fri Mar 12 23:27:41 2021 +++ src/usr.bin/indent/indent.h Sat Mar 13 00:26:56 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.7 2021/03/12 23:27:41 rillig Exp $ */ +/* $NetBSD: indent.h,v 1.8 2021/03/13 00:26:56 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -30,7 +30,7 @@ #if 0 #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.h,v 1.7 2021/03/12 23:27:41 rillig Exp $"); +__RCSID("$NetBSD: indent.h,v 1.8 2021/03/13 00:26:56 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 336333 2018-07-16 05:46:50Z pstef $"); #endif @@ -45,8 +45,8 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/ void add_typename(const char *); void alloc_typenames(void); -int compute_code_indent(void); -int compute_label_indent(void); +int compute_code_column(void); +int compute_label_column(void); int count_spaces(int, const char *); int count_spaces_until(int, const char *, const char *); void init_constant_tt(void); Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.33 src/usr.bin/indent/io.c:1.34 --- src/usr.bin/indent/io.c:1.33 Sat Mar 13 00:03:29 2021 +++ src/usr.bin/indent/io.c Sat Mar 13 00:26:56 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.33 2021/03/13 00:03:29 rillig Exp $ */ +/* $NetBSD: io.c,v 1.34 2021/03/13 00:26:56 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.33 2021/03/13 00:03:29 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.34 2021/03/13 00:26:56 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -63,7 +63,6 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/ int comment_open; static int paren_indent; -static int pad_output(int current, int target); static void output_char(char ch) @@ -89,6 +88,28 @@ output_int(int i) fprintf(output, "%d", i); } +static int +output_indent(int old_ind, int new_ind) +{ +int ind = old_ind; + +if (opt.use_tabs) { + int tabsize = opt.tabsize; + int n = new_ind / tabsize - ind / tabsize; + if (n > 0) + ind -= ind % tabsize; + for (int i = 0; i < n; i++) { + output_char('\t'); + ind += tabsize; + } +} + +for (; ind < new_ind; ind++) +output_char(' '); + +return ind; +} + /* * dump_line is the routine that actually effects the printing of the new * source. It prints the label section, followed by the code section with @@ -144,7 +165,7 @@ dump_line(void) while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == '\t')) e_lab--; *e_lab = '\0'; - cur_col = pad_output(1, compute_label_indent()); + cur_col = 1 + output_indent(0, compute_label_column() - 1); if (s_lab[0] == '#' && (strncmp(s_lab, "#else", 5) == 0 || strncmp(s_lab, "#endif", 6)
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 13 00:03:30 UTC 2021 Modified Files: src/usr.bin/indent: io.c Log Message: indent: clean up verbose documentation comments from the 1970s Since C90, there is no need to repeat the type of the function parameters. In the whole code of indent, there is a lot of confusion between the concepts of a 'column' (which is a position on the screen, counting starts at 1) and 'indentation' (which is a length, not a position). To avoid this confusion, the code will be rewritten anyway very soon. Repeatedly adding and subtracting 1 from the 'current column' is not elegant, this should rather be done by consistently measuring only the indentation from the left border (at offset 0), as a distance, not as an absolute position. To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 src/usr.bin/indent/io.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.32 src/usr.bin/indent/io.c:1.33 --- src/usr.bin/indent/io.c:1.32 Fri Mar 12 23:27:41 2021 +++ src/usr.bin/indent/io.c Sat Mar 13 00:03:29 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.32 2021/03/12 23:27:41 rillig Exp $ */ +/* $NetBSD: io.c,v 1.33 2021/03/13 00:03:29 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.32 2021/03/12 23:27:41 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.33 2021/03/13 00:03:29 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -304,15 +304,7 @@ compute_label_indent(void) * * All rights reserved * - * - * NAME: fill_buffer - * - * FUNCTION: Reads one block of input into input_buffer - * - * HISTORY: initial coding November 1976 D A Willcox of CAC 1/7/77 A - * Willcox of CAC Added check for switch back to partly full input - * buffer from temporary buffer - * + * FUNCTION: Reads one block of input into the input buffer */ void fill_buffer(void) @@ -407,28 +399,8 @@ fill_buffer(void) * * All rights reserved * - * - * NAME: pad_output - * - * FUNCTION: Writes tabs and spaces to move the current column up to the desired + * Writes tabs and spaces to move the current column up to the desired * position. - * - * ALGORITHM: Put tabs and/or blanks into pobuf, then write pobuf. - * - * PARAMETERS: current integer The current column target - * nteger The desired column - * - * RETURNS: Integer value of the new column. (If current >= target, no action is - * taken, and current is returned. - * - * GLOBALS: None - * - * CALLS: write (sys) - * - * CALLED BY: dump_line - * - * HISTORY: initial coding November 1976 D A Willcox of CAC - * */ static int pad_output(int current, int target) @@ -461,28 +433,9 @@ pad_output(int current, int target) * Copyright (C) 1976 by the Board of Trustees of the University of Illinois * * All rights reserved - * - * - * NAME: count_spaces - * - * FUNCTION: Find out where printing of a given string will leave the current - * character position on output. - * - * ALGORITHM: Run thru input string and add appropriate values to current - * position. - * - * RETURNS: Integer value of position after printing "buffer" starting in column - * "current". - * - * HISTORY: initial coding November 1976 D A Willcox of CAC - * */ int count_spaces_until(int col, const char *buffer, const char *end) -/* - * this routine figures out where the character position will be after - * printing the text in buffer starting at column "current" - */ { for (const char *p = buffer; *p != '\0' && p != end; ++p) { switch (*p) {
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Mar 12 23:27:41 UTC 2021 Modified Files: src/usr.bin/indent: indent.h io.c Log Message: indent: add 'const', rename variables, reorder formula for tab width Column counting starts at 1. This 1 should rather be at the beginning of the formula since it is thought of being added at the very beginning of the line, not at the end. When adding a tab, the newly added tab is added at the end of the string, therefore that '+ 1' should be at the end of the formula as well. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/usr.bin/indent/indent.h cvs rdiff -u -r1.31 -r1.32 src/usr.bin/indent/io.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.6 src/usr.bin/indent/indent.h:1.7 --- src/usr.bin/indent/indent.h:1.6 Fri Mar 12 23:16:00 2021 +++ src/usr.bin/indent/indent.h Fri Mar 12 23:27:41 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.6 2021/03/12 23:16:00 rillig Exp $ */ +/* $NetBSD: indent.h,v 1.7 2021/03/12 23:27:41 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -30,7 +30,7 @@ #if 0 #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.h,v 1.6 2021/03/12 23:16:00 rillig Exp $"); +__RCSID("$NetBSD: indent.h,v 1.7 2021/03/12 23:27:41 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 336333 2018-07-16 05:46:50Z pstef $"); #endif @@ -47,8 +47,8 @@ void add_typename(const char *); void alloc_typenames(void); int compute_code_indent(void); int compute_label_indent(void); -int count_spaces(int, char *); -int count_spaces_until(int, char *, char *); +int count_spaces(int, const char *); +int count_spaces_until(int, const char *, const char *); void init_constant_tt(void); #ifdef debug const char *token_type_name(token_type); Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.31 src/usr.bin/indent/io.c:1.32 --- src/usr.bin/indent/io.c:1.31 Fri Mar 12 23:16:00 2021 +++ src/usr.bin/indent/io.c Fri Mar 12 23:27:41 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.31 2021/03/12 23:16:00 rillig Exp $ */ +/* $NetBSD: io.c,v 1.32 2021/03/12 23:27:41 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.31 2021/03/12 23:16:00 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.32 2021/03/12 23:27:41 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -478,42 +478,40 @@ pad_output(int current, int target) * */ int -count_spaces_until(int cur, char *buffer, char *end) +count_spaces_until(int col, const char *buffer, const char *end) /* * this routine figures out where the character position will be after * printing the text in buffer starting at column "current" */ { -char *buf; /* used to look thru buffer */ - -for (buf = buffer; *buf != '\0' && buf != end; ++buf) { - switch (*buf) { +for (const char *p = buffer; *p != '\0' && p != end; ++p) { + switch (*p) { case '\n': case 014: /* form feed */ - cur = 1; + col = 1; break; case '\t': - cur = opt.tabsize * (1 + (cur - 1) / opt.tabsize) + 1; + col = 1 + opt.tabsize * ((col - 1) / opt.tabsize + 1); break; case 010: /* backspace */ - --cur; + --col; break; default: - ++cur; + ++col; break; } /* end of switch */ }/* end of for loop */ -return cur; +return col; } int -count_spaces(int cur, char *buffer) +count_spaces(int col, const char *buffer) { -return count_spaces_until(cur, buffer, NULL); +return count_spaces_until(col, buffer, NULL); } void
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Mar 12 23:16:00 UTC 2021 Modified Files: src/usr.bin/indent: indent.c indent.h io.c pr_comment.c Log Message: indent: replace 'target' with 'indent' in function names The word 'target' was not as specific as possible. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.45 -r1.46 src/usr.bin/indent/indent.c cvs rdiff -u -r1.5 -r1.6 src/usr.bin/indent/indent.h cvs rdiff -u -r1.30 -r1.31 src/usr.bin/indent/io.c cvs rdiff -u -r1.19 -r1.20 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.45 src/usr.bin/indent/indent.c:1.46 --- src/usr.bin/indent/indent.c:1.45 Fri Mar 12 23:10:18 2021 +++ src/usr.bin/indent/indent.c Fri Mar 12 23:16:00 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.45 2021/03/12 23:10:18 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.46 2021/03/12 23:16:00 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.45 2021/03/12 23:10:18 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.46 2021/03/12 23:16:00 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -1150,7 +1150,7 @@ main(int argc, char **argv) if (ps.block_init_level <= 0) ps.block_init = 0; if (break_comma && (!opt.leave_comma || - count_spaces_until(compute_code_target(), s_code, e_code) > + count_spaces_until(compute_code_indent(), s_code, e_code) > opt.max_col - opt.tabsize)) force_nl = true; } Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.5 src/usr.bin/indent/indent.h:1.6 --- src/usr.bin/indent/indent.h:1.5 Sun Mar 7 11:32:05 2021 +++ src/usr.bin/indent/indent.h Fri Mar 12 23:16:00 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.5 2021/03/07 11:32:05 rillig Exp $ */ +/* $NetBSD: indent.h,v 1.6 2021/03/12 23:16:00 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -30,7 +30,7 @@ #if 0 #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.h,v 1.5 2021/03/07 11:32:05 rillig Exp $"); +__RCSID("$NetBSD: indent.h,v 1.6 2021/03/12 23:16:00 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 336333 2018-07-16 05:46:50Z pstef $"); #endif @@ -45,8 +45,8 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/ void add_typename(const char *); void alloc_typenames(void); -int compute_code_target(void); -int compute_label_target(void); +int compute_code_indent(void); +int compute_label_indent(void); int count_spaces(int, char *); int count_spaces_until(int, char *, char *); void init_constant_tt(void); Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.30 src/usr.bin/indent/io.c:1.31 --- src/usr.bin/indent/io.c:1.30 Fri Mar 12 23:10:18 2021 +++ src/usr.bin/indent/io.c Fri Mar 12 23:16:00 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.30 2021/03/12 23:10:18 rillig Exp $ */ +/* $NetBSD: io.c,v 1.31 2021/03/12 23:16:00 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.30 2021/03/12 23:10:18 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.31 2021/03/12 23:16:00 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -62,7 +62,7 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/ #include "indent.h" int comment_open; -static int paren_target; +static int paren_indent; static int pad_output(int current, int target); static void @@ -144,7 +144,7 @@ dump_line(void) while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == '\t')) e_lab--; *e_lab = '\0'; - cur_col = pad_output(1, compute_label_target()); + cur_col = pad_output(1, compute_label_indent()); if (s_lab[0] == '#' && (strncmp(s_lab, "#else", 5) == 0 || strncmp(s_lab, "#endif", 6) == 0)) { char *s = s_lab; @@ -179,7 +179,7 @@ dump_line(void) comment_open = 0; output_string(".*/\n"); } - target_col = compute_code_target(); + target_col = compute_code_indent(); { int i; @@ -257,12 +257,12 @@ dump_line(void) ps.ind_level = ps.i_l_follow; ps.paren_level = ps.p_l_follow; if (ps.paren_level > 0) - paren_target = -ps.paren_indents[ps.paren_level - 1]; + paren_indent = -ps.paren_indents[ps.paren_level - 1]; not_first_line = 1; } int -compute_code_target(void) +compute_code_indent(void) { int target_col = opt.ind_size * ps.ind_level + 1; @@ -271,10 +271,10 @@ compute_code_target(void) target_col +=
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Mar 12 23:10:18 UTC 2021 Modified Files: src/usr.bin/indent: args.c indent.c io.c lexi.c parse.c pr_comment.c Log Message: indent: use consistent indentation for 'else' Half of the code used -ce, the other half the opposite -nce. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/usr.bin/indent/args.c \ src/usr.bin/indent/pr_comment.c cvs rdiff -u -r1.44 -r1.45 src/usr.bin/indent/indent.c cvs rdiff -u -r1.29 -r1.30 src/usr.bin/indent/io.c cvs rdiff -u -r1.37 -r1.38 src/usr.bin/indent/lexi.c cvs rdiff -u -r1.17 -r1.18 src/usr.bin/indent/parse.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/args.c diff -u src/usr.bin/indent/args.c:1.18 src/usr.bin/indent/args.c:1.19 --- src/usr.bin/indent/args.c:1.18 Tue Mar 9 16:48:28 2021 +++ src/usr.bin/indent/args.c Fri Mar 12 23:10:18 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: args.c,v 1.18 2021/03/09 16:48:28 rillig Exp $ */ +/* $NetBSD: args.c,v 1.19 2021/03/12 23:10:18 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)args.c 8.1 ( #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: args.c,v 1.18 2021/03/09 16:48:28 rillig Exp $"); +__RCSID("$NetBSD: args.c,v 1.19 2021/03/12 23:10:18 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $"); #endif @@ -234,8 +234,7 @@ scan_profile(FILE *f) if (opt.verbose) printf("profile: %s\n", buf); set_option(buf); - } - else if (i == EOF) + } else if (i == EOF) return; } } Index: src/usr.bin/indent/pr_comment.c diff -u src/usr.bin/indent/pr_comment.c:1.18 src/usr.bin/indent/pr_comment.c:1.19 --- src/usr.bin/indent/pr_comment.c:1.18 Thu Mar 11 22:32:06 2021 +++ src/usr.bin/indent/pr_comment.c Fri Mar 12 23:10:18 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: pr_comment.c,v 1.18 2021/03/11 22:32:06 rillig Exp $ */ +/* $NetBSD: pr_comment.c,v 1.19 2021/03/12 23:10:18 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)pr_comment.c #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: pr_comment.c,v 1.18 2021/03/11 22:32:06 rillig Exp $"); +__RCSID("$NetBSD: pr_comment.c,v 1.19 2021/03/12 23:10:18 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -136,8 +136,7 @@ pr_comment(void) ps.box_com = true; break_delim = false; ps.com_col = 1; -} -else { +} else { if (*buf_ptr == '-' || *buf_ptr == '*' || e_token[-1] == '/' || (*buf_ptr == '\n' && !opt.format_block_comments)) { ps.box_com = true; /* A comment with a '-' or '*' immediately @@ -159,8 +158,7 @@ pr_comment(void) adj_max_col = opt.block_comment_max_col; if (ps.com_col <= 1) ps.com_col = 1 + !opt.format_col1_comments; - } - else { + } else { int target_col; break_delim = false; if (s_code != e_code) @@ -191,8 +189,7 @@ pr_comment(void) start = buf_ptr >= save_com && buf_ptr < save_com + sc_size ? sc_buf : in_buffer; ps.n_comment_delta = 1 - count_spaces_until(1, start, buf_ptr - 2); -} -else { +} else { ps.n_comment_delta = 0; while (*buf_ptr == ' ' || *buf_ptr == '\t') buf_ptr++; @@ -245,8 +242,7 @@ pr_comment(void) *e_com++ = ' ', *e_com++ = '*', *e_com++ = ' '; while (*++buf_ptr == ' ' || *buf_ptr == '\t') ; - } - else { + } else { if (++buf_ptr >= buf_end) fill_buffer(); *e_com++ = 014; @@ -277,8 +273,7 @@ pr_comment(void) dump_line(); if (!ps.box_com && opt.star_comment_cont) *e_com++ = ' ', *e_com++ = '*', *e_com++ = ' '; - } - else { + } else { ps.last_nl = 1; if (e_com[-1] == ' ' || e_com[-1] == '\t') last_bl = e_com - 1; @@ -305,8 +300,7 @@ pr_comment(void) goto end_of_comment; } } while (*buf_ptr == ' ' || *buf_ptr == '\t'); - } - else if (++buf_ptr >= buf_end) + } else if (++buf_ptr >= buf_end) fill_buffer(); break; /* end of case for newline */ @@ -320,9 +314,8 @@ pr_comment(void) if (++buf_ptr >= buf_end) fill_buffer(); if (break_delim) { - if (e_com > s_com + 3) { + if (e_com > s_com + 3) dump_line(); - } else s_com = e_com; *e_com++ = ' '; @@ -335,8 +328,7 @@ pr_comment(void) *e_com++ = '*', *e_com++ = '/', *e_com = '\0'; ps.just_saw_decl = l_just_saw_decl; return; - } - else /* handle isolated '*' */ + } else /* handle isolated '*' */ *e_com++ = '*'; break; default: /* we have a random char */ Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.44 src/usr.bin/indent/indent.c:1.45 ---
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Mar 12 19:14:18 UTC 2021 Modified Files: src/usr.bin/indent: io.c Log Message: indent: make output_string inline GCC 9.3.0 didn't notice that the argument to this function is always a string literal, which makes it worthwhile to inline the call. To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/usr.bin/indent/io.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.28 src/usr.bin/indent/io.c:1.29 --- src/usr.bin/indent/io.c:1.28 Fri Mar 12 19:11:29 2021 +++ src/usr.bin/indent/io.c Fri Mar 12 19:14:18 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.28 2021/03/12 19:11:29 rillig Exp $ */ +/* $NetBSD: io.c,v 1.29 2021/03/12 19:14:18 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.28 2021/03/12 19:11:29 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.29 2021/03/12 19:14:18 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -77,7 +77,7 @@ output_range(const char *s, const char * fwrite(s, 1, (size_t)(e - s), output); } -static void +static inline void output_string(const char *s) { output_range(s, s + strlen(s));
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Mar 12 19:11:29 UTC 2021 Modified Files: src/usr.bin/indent: Makefile io.c Log Message: indent: add helper functions for doing the actual output This allows to add debug logging to these few functions instead of all other places that might output something. Reducing the possible output formats to a few primitives makes dump_line simpler, especially the fprintf calls. It also removes the non-constant printf string. The call to output_int may be meant for debugging, as the character 0x80 is unlikely to appear in any real-world code. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/usr.bin/indent/Makefile cvs rdiff -u -r1.27 -r1.28 src/usr.bin/indent/io.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/Makefile diff -u src/usr.bin/indent/Makefile:1.9 src/usr.bin/indent/Makefile:1.10 --- src/usr.bin/indent/Makefile:1.9 Mon Mar 8 19:21:41 2021 +++ src/usr.bin/indent/Makefile Fri Mar 12 19:11:29 2021 @@ -1,12 +1,10 @@ -# $NetBSD: Makefile,v 1.9 2021/03/08 19:21:41 rillig Exp $ +# $NetBSD: Makefile,v 1.10 2021/03/12 19:11:29 rillig Exp $ # from: @(#)Makefile 8.1 (Berkeley) 6/6/93 PROG= indent SRCS= indent.c io.c lexi.c parse.c pr_comment.c args.c -COPTS.io.c += -Wno-error=format-nonliteral CPPFLAGS+= ${DEBUG:D-Ddebug} - LINTFLAGS+= -e .include Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.27 src/usr.bin/indent/io.c:1.28 --- src/usr.bin/indent/io.c:1.27 Mon Mar 8 22:28:31 2021 +++ src/usr.bin/indent/io.c Fri Mar 12 19:11:29 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.27 2021/03/08 22:28:31 rillig Exp $ */ +/* $NetBSD: io.c,v 1.28 2021/03/12 19:11:29 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.27 2021/03/08 22:28:31 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.28 2021/03/12 19:11:29 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -65,6 +65,30 @@ int comment_open; static int paren_target; static int pad_output(int current, int target); +static void +output_char(char ch) +{ +fputc(ch, output); +} + +static void +output_range(const char *s, const char *e) +{ +fwrite(s, 1, (size_t)(e - s), output); +} + +static void +output_string(const char *s) +{ +output_range(s, s + strlen(s)); +} + +static void +output_int(int i) +{ +fprintf(output, "%d", i); +} + /* * dump_line is the routine that actually effects the printing of the new * source. It prints the label section, followed by the code section with @@ -102,7 +126,7 @@ dump_line(void) } } while (--n_real_blanklines >= 0) - putc('\n', output); + output_char('\n'); n_real_blanklines = 0; if (ps.ind_level == 0) ps.ind_stmt = 0; /* this is a class A kludge. dont do @@ -116,7 +140,7 @@ dump_line(void) if (e_lab != s_lab) { /* print lab, if any */ if (comment_open) { comment_open = 0; - fprintf(output, ".*/\n"); + output_string(".*/\n"); } while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == '\t')) e_lab--; @@ -127,15 +151,22 @@ dump_line(void) char *s = s_lab; if (e_lab[-1] == '\n') e_lab--; do { - putc(*s++, output); + output_char(*s++); } while (s < e_lab && 'a' <= *s && *s <= 'z'); while ((*s == ' ' || *s == '\t') && s < e_lab) s++; - if (s < e_lab) - fprintf(output, s[0]=='/' && s[1]=='*' ? "\t%.*s" : "\t/* %.*s */", - (int)(e_lab - s), s); - } - else fprintf(output, "%.*s", (int)(e_lab - s_lab), s_lab); + if (s < e_lab) { + if (s[0] == '/' && s[1] == '*') { + output_char('\t'); + output_range(s, e_lab); + } else { + output_string("\t/* "); + output_range(s, e_lab); + output_string(" */"); + } + } + } else + output_range(s_lab, e_lab); cur_col = count_spaces(cur_col, s_lab); } else @@ -148,7 +179,7 @@ dump_line(void) if (comment_open) { comment_open = 0; - fprintf(output, ".*/\n"); + output_string(".*/\n"); } target_col = compute_code_target(); { @@ -161,9 +192,9 @@ dump_line(void) cur_col = pad_output(cur_col, target_col); for (p = s_code; p < e_code; p++) if (*p == (char) 0200) - fprintf(output, "%d", target_col * 7); + output_int(target_col * 7); else - putc(*p, output); + output_char(*p); cur_col = count_spaces(cur_col, s_code); } if (s_com != e_com) { /* print comment, if any */ @@ -185,21 +216,21 @@ dump_line(void) target = 1; if (cur_col > target) { /* if comment can't fit on this line, * put it on next line */ - putc('\n', output); + output_char('\n');
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Mar 12 18:11:50 UTC 2021 Modified Files: src/usr.bin/indent: lexi.c Log Message: indent: fix misleading indentation in indent's own code No functional change. To generate a diff of this commit: cvs rdiff -u -r1.36 -r1.37 src/usr.bin/indent/lexi.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/lexi.c diff -u src/usr.bin/indent/lexi.c:1.36 src/usr.bin/indent/lexi.c:1.37 --- src/usr.bin/indent/lexi.c:1.36 Fri Mar 12 17:46:48 2021 +++ src/usr.bin/indent/lexi.c Fri Mar 12 18:11:50 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lexi.c,v 1.36 2021/03/12 17:46:48 rillig Exp $ */ +/* $NetBSD: lexi.c,v 1.37 2021/03/12 18:11:50 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)lexi.c 8.1 ( #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: lexi.c,v 1.36 2021/03/12 17:46:48 rillig Exp $"); +__RCSID("$NetBSD: lexi.c,v 1.37 2021/03/12 18:11:50 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $"); #endif @@ -352,8 +352,8 @@ lexi(struct parser_state *state) buf_ptr += 2; if (buf_ptr >= buf_end) fill_buffer(); - } else - break; + } else + break; } check_size_token(1); *e_token++ = inbuf_next();
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Mar 12 17:46:49 UTC 2021 Modified Files: src/usr.bin/indent: lexi.c Log Message: indent: move code for tokenizing numbers further up Having it directly below the table makes it easier understandable. I also tried to omit this function entirely by moving the code into the initializer itself, but that made the code redundant and furthermore increased the size of the resulting binary, probably because of the new relocation records. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/usr.bin/indent/lexi.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/lexi.c diff -u src/usr.bin/indent/lexi.c:1.35 src/usr.bin/indent/lexi.c:1.36 --- src/usr.bin/indent/lexi.c:1.35 Thu Mar 11 22:32:06 2021 +++ src/usr.bin/indent/lexi.c Fri Mar 12 17:46:48 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lexi.c,v 1.35 2021/03/11 22:32:06 rillig Exp $ */ +/* $NetBSD: lexi.c,v 1.36 2021/03/12 17:46:48 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)lexi.c 8.1 ( #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: lexi.c,v 1.35 2021/03/11 22:32:06 rillig Exp $"); +__RCSID("$NetBSD: lexi.c,v 1.36 2021/03/12 17:46:48 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $"); #endif @@ -171,6 +171,22 @@ static char const *table[] = { [0] = "uuiifuufiuuiiuiuiu", }; +/* Initialize constant transition table */ +void +init_constant_tt(void) +{ +table['-'] = table['+']; +table['8'] = table['9']; +table['2'] = table['3'] = table['4'] = table['5'] = table['6'] = table['7']; +table['A'] = table['C'] = table['D'] = table['c'] = table['d'] = table['a']; +table['B'] = table['b']; +table['E'] = table['e']; +table['U'] = table['u']; +table['X'] = table['x']; +table['P'] = table['p']; +table['F'] = table['f']; +} + static char inbuf_peek(void) { @@ -671,22 +687,6 @@ stop_lit: return lexi_end(code); } -/* Initialize constant transition table */ -void -init_constant_tt(void) -{ -table['-'] = table['+']; -table['8'] = table['9']; -table['2'] = table['3'] = table['4'] = table['5'] = table['6'] = table['7']; -table['A'] = table['C'] = table['D'] = table['c'] = table['d'] = table['a']; -table['B'] = table['b']; -table['E'] = table['e']; -table['U'] = table['u']; -table['X'] = table['x']; -table['P'] = table['p']; -table['F'] = table['f']; -} - void alloc_typenames(void) {
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Mar 12 00:15:34 UTC 2021 Modified Files: src/usr.bin/indent: indent.c Log Message: indent: manually fix indentation No functional change. To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/usr.bin/indent/indent.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.43 src/usr.bin/indent/indent.c:1.44 --- src/usr.bin/indent/indent.c:1.43 Thu Mar 11 22:32:06 2021 +++ src/usr.bin/indent/indent.c Fri Mar 12 00:15:34 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.43 2021/03/11 22:32:06 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.44 2021/03/12 00:15:34 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.43 2021/03/11 22:32:06 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.44 2021/03/12 00:15:34 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -995,7 +995,7 @@ main(int argc, char **argv) prefix_blankline_requested = 0; parse(rbrace); /* let parser know about this */ ps.search_brace = opt.cuddle_else - && ps.p_stack[ps.tos] == if_expr_stmt + && ps.p_stack[ps.tos] == if_expr_stmt && ps.il[ps.tos] >= ps.ind_level; if (ps.tos <= 1 && opt.blanklines_after_procs && ps.dec_nest <= 0) postfix_blankline_requested = 1;
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Thu Mar 11 22:32:06 UTC 2021 Modified Files: src/usr.bin/indent: indent.c lexi.c pr_comment.c Log Message: indent: reduce indentation of check_size functions No functional change. To generate a diff of this commit: cvs rdiff -u -r1.42 -r1.43 src/usr.bin/indent/indent.c cvs rdiff -u -r1.34 -r1.35 src/usr.bin/indent/lexi.c cvs rdiff -u -r1.17 -r1.18 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.42 src/usr.bin/indent/indent.c:1.43 --- src/usr.bin/indent/indent.c:1.42 Thu Mar 11 22:28:30 2021 +++ src/usr.bin/indent/indent.c Thu Mar 11 22:32:06 2021 @@ -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 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #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 @@ charbakfile[MAXPATHLEN] = ""; 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 Index: src/usr.bin/indent/lexi.c diff -u src/usr.bin/indent/lexi.c:1.34 src/usr.bin/indent/lexi.c:1.35 --- src/usr.bin/indent/lexi.c:1.34 Thu Mar 11 22:28:30 2021 +++ src/usr.bin/indent/lexi.c Thu Mar 11 22:32:06 2021 @@ -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 @@ static char sccsid[] = "@(#)lexi.c 8.1 ( #include #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 @@ inbuf_next(void) 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 @@ void 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); } Index: src/usr.bin/indent/pr_comment.c diff -u src/usr.bin/indent/pr_comment.c:1.17 src/usr.bin/indent/pr_comment.c:1.18 --- src/usr.bin/indent/pr_comment.c:1.17 Thu Mar 11 22:28:30 2021 +++ src/usr.bin/indent/pr_comment.c Thu Mar 11 22:32:06 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: pr_comment.c,v 1.17 2021/03/11
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Thu Mar 11 22:28:30 UTC 2021 Modified Files: src/usr.bin/indent: indent.c lexi.c pr_comment.c Log Message: indent: remove redundant cast after allocation functions No functional change. To generate a diff of this commit: cvs rdiff -u -r1.41 -r1.42 src/usr.bin/indent/indent.c cvs rdiff -u -r1.33 -r1.34 src/usr.bin/indent/lexi.c cvs rdiff -u -r1.16 -r1.17 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.41 src/usr.bin/indent/indent.c:1.42 --- src/usr.bin/indent/indent.c:1.41 Tue Mar 9 19:46:28 2021 +++ src/usr.bin/indent/indent.c Thu Mar 11 22:28:30 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.41 2021/03/09 19:46:28 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.42 2021/03/11 22:28:30 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.41 2021/03/09 19:46:28 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.42 2021/03/11 22:28:30 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -139,7 +139,7 @@ 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 = (char *)realloc(codebuf, nsize); + codebuf = realloc(codebuf, nsize); if (codebuf == NULL) err(1, NULL); e_code = codebuf + code_len + 1; @@ -154,7 +154,7 @@ 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 = (char *)realloc(labbuf, nsize); + labbuf = realloc(labbuf, nsize); if (labbuf == NULL) err(1, NULL); e_lab = labbuf + label_len + 1; @@ -397,16 +397,16 @@ main(int argc, char **argv) ps.last_nl = true; /* this is true if the last thing scanned was * a newline */ ps.last_token = semicolon; -combuf = (char *) malloc(bufsize); +combuf = malloc(bufsize); if (combuf == NULL) err(1, NULL); -labbuf = (char *) malloc(bufsize); +labbuf = malloc(bufsize); if (labbuf == NULL) err(1, NULL); -codebuf = (char *) malloc(bufsize); +codebuf = malloc(bufsize); if (codebuf == NULL) err(1, NULL); -tokenbuf = (char *) malloc(bufsize); +tokenbuf = malloc(bufsize); if (tokenbuf == NULL) err(1, NULL); alloc_typenames(); @@ -424,7 +424,7 @@ main(int argc, char **argv) s_com = e_com = combuf + 1; s_token = e_token = tokenbuf + 1; -in_buffer = (char *) malloc(10); +in_buffer = malloc(10); if (in_buffer == NULL) err(1, NULL); in_buffer_limit = in_buffer + 8; Index: src/usr.bin/indent/lexi.c diff -u src/usr.bin/indent/lexi.c:1.33 src/usr.bin/indent/lexi.c:1.34 --- src/usr.bin/indent/lexi.c:1.33 Thu Mar 11 22:15:44 2021 +++ src/usr.bin/indent/lexi.c Thu Mar 11 22:28:30 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lexi.c,v 1.33 2021/03/11 22:15:44 rillig Exp $ */ +/* $NetBSD: lexi.c,v 1.34 2021/03/11 22:28:30 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)lexi.c 8.1 ( #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: lexi.c,v 1.33 2021/03/11 22:15:44 rillig Exp $"); +__RCSID("$NetBSD: lexi.c,v 1.34 2021/03/11 22:28:30 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $"); #endif @@ -199,7 +199,7 @@ 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 = (char *)realloc(tokenbuf, nsize); + tokenbuf = realloc(tokenbuf, nsize); if (tokenbuf == NULL) err(1, NULL); e_token = tokenbuf + token_len + 1; @@ -690,7 +690,7 @@ void alloc_typenames(void) { -typenames = (const char **)malloc(sizeof(typenames[0]) * +typenames = malloc(sizeof(typenames[0]) * (typename_count = 16)); if (typenames == NULL) err(1, NULL); Index: src/usr.bin/indent/pr_comment.c diff -u src/usr.bin/indent/pr_comment.c:1.16 src/usr.bin/indent/pr_comment.c:1.17 --- src/usr.bin/indent/pr_comment.c:1.16 Thu Mar 11 22:15:44 2021 +++ src/usr.bin/indent/pr_comment.c Thu Mar 11 22:28:30 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: pr_comment.c,v 1.16 2021/03/11 22:15:44 rillig Exp $ */ +/* $NetBSD: pr_comment.c,v 1.17 2021/03/11 22:28:30 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)pr_comment.c #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: pr_comment.c,v 1.16
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Thu Mar 11 22:15:44 UTC 2021 Modified Files: src/usr.bin/indent: lexi.c pr_comment.c Log Message: indent: use consistent array indexing No functional change. To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 src/usr.bin/indent/lexi.c cvs rdiff -u -r1.15 -r1.16 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/lexi.c diff -u src/usr.bin/indent/lexi.c:1.32 src/usr.bin/indent/lexi.c:1.33 --- src/usr.bin/indent/lexi.c:1.32 Thu Mar 11 21:47:36 2021 +++ src/usr.bin/indent/lexi.c Thu Mar 11 22:15:44 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lexi.c,v 1.32 2021/03/11 21:47:36 rillig Exp $ */ +/* $NetBSD: lexi.c,v 1.33 2021/03/11 22:15:44 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)lexi.c 8.1 ( #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: lexi.c,v 1.32 2021/03/11 21:47:36 rillig Exp $"); +__RCSID("$NetBSD: lexi.c,v 1.33 2021/03/11 22:15:44 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $"); #endif @@ -331,7 +331,7 @@ lexi(struct parser_state *state) *buf_ptr == '_' || *buf_ptr == '$') { /* fill_buffer() terminates buffer with newline */ if (*buf_ptr == '\\') { - if (*(buf_ptr + 1) == '\n') { + if (buf_ptr[1] == '\n') { buf_ptr += 2; if (buf_ptr >= buf_end) fill_buffer(); @@ -650,7 +650,7 @@ stop_lit: unary_delim = state->last_u_d; break; } - while (*(e_token - 1) == *buf_ptr || *buf_ptr == '=') { + while (e_token[-1] == *buf_ptr || *buf_ptr == '=') { /* * handle ||, &&, etc, and also things as in int *i */ Index: src/usr.bin/indent/pr_comment.c diff -u src/usr.bin/indent/pr_comment.c:1.15 src/usr.bin/indent/pr_comment.c:1.16 --- src/usr.bin/indent/pr_comment.c:1.15 Tue Mar 9 16:48:28 2021 +++ src/usr.bin/indent/pr_comment.c Thu Mar 11 22:15:44 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: pr_comment.c,v 1.15 2021/03/09 16:48:28 rillig Exp $ */ +/* $NetBSD: pr_comment.c,v 1.16 2021/03/11 22:15:44 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)pr_comment.c #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: pr_comment.c,v 1.15 2021/03/09 16:48:28 rillig Exp $"); +__RCSID("$NetBSD: pr_comment.c,v 1.16 2021/03/11 22:15:44 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -283,7 +283,7 @@ pr_comment(void) } else { ps.last_nl = 1; - if (*(e_com - 1) == ' ' || *(e_com - 1) == '\t') + if (e_com[-1] == ' ' || e_com[-1] == '\t') last_bl = e_com - 1; /* * if there was a space at the end of the last line, remember
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Thu Mar 11 21:47:36 UTC 2021 Modified Files: src/usr.bin/indent: lexi.c Log Message: indent: merge duplicate code for reading from the input buffer No functional change. To generate a diff of this commit: cvs rdiff -u -r1.31 -r1.32 src/usr.bin/indent/lexi.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/lexi.c diff -u src/usr.bin/indent/lexi.c:1.31 src/usr.bin/indent/lexi.c:1.32 --- src/usr.bin/indent/lexi.c:1.31 Tue Mar 9 19:23:08 2021 +++ src/usr.bin/indent/lexi.c Thu Mar 11 21:47:36 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lexi.c,v 1.31 2021/03/09 19:23:08 rillig Exp $ */ +/* $NetBSD: lexi.c,v 1.32 2021/03/11 21:47:36 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)lexi.c 8.1 ( #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: lexi.c,v 1.31 2021/03/09 19:23:08 rillig Exp $"); +__RCSID("$NetBSD: lexi.c,v 1.32 2021/03/11 21:47:36 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $"); #endif @@ -171,6 +171,28 @@ static char const *table[] = { [0] = "uuiifuufiuuiiuiuiu", }; +static char +inbuf_peek(void) +{ +return *buf_ptr; +} + +static void +inbuf_skip(void) +{ +buf_ptr++; +if (buf_ptr >= buf_end) + fill_buffer(); +} + +static char +inbuf_next(void) +{ +char ch = inbuf_peek(); +inbuf_skip(); +return ch; +} + static void check_size_token(size_t desired_size) { @@ -273,8 +295,7 @@ lexi(struct parser_state *state) while (*buf_ptr == ' ' || *buf_ptr == '\t') { /* get rid of blanks */ state->col_1 = false; /* leading blanks imply token is not in column * 1 */ - if (++buf_ptr >= buf_end) - fill_buffer(); + inbuf_skip(); } /* Scan an alphanumeric token */ @@ -300,9 +321,7 @@ lexi(struct parser_state *state) } s = table[i][s - 'A']; check_size_token(1); - *e_token++ = *buf_ptr++; - if (buf_ptr >= buf_end) - fill_buffer(); + *e_token++ = inbuf_next(); } /* s now indicates the type: f(loating), i(integer), u(nknown) */ } @@ -320,10 +339,7 @@ lexi(struct parser_state *state) break; } check_size_token(1); - /* copy it over */ - *e_token++ = *buf_ptr++; - if (buf_ptr >= buf_end) - fill_buffer(); + *e_token++ = inbuf_next(); } *e_token = '\0'; @@ -331,10 +347,8 @@ lexi(struct parser_state *state) (*buf_ptr == '"' || *buf_ptr == '\'')) return lexi_end(string_prefix); - while (*buf_ptr == ' ' || *buf_ptr == '\t') { /* get rid of blanks */ - if (++buf_ptr >= buf_end) - fill_buffer(); - } + while (*buf_ptr == ' ' || *buf_ptr == '\t') /* get rid of blanks */ + inbuf_next(); state->keyword = rw_0; if (state->last_token == keyword_struct_union_enum && !state->p_l_follow) { @@ -440,11 +454,9 @@ lexi(struct parser_state *state) /* Scan a non-alphanumeric token */ check_size_token(3); /* things like "<<=" */ -*e_token++ = *buf_ptr; /* if it is only a one-character token, it is +*e_token++ = inbuf_next(); /* if it is only a one-character token, it is * moved here */ *e_token = '\0'; -if (++buf_ptr >= buf_end) - fill_buffer(); switch (*token) { case '\n': @@ -468,17 +480,13 @@ lexi(struct parser_state *state) goto stop_lit; } check_size_token(2); - *e_token = *buf_ptr++; - if (buf_ptr >= buf_end) - fill_buffer(); + *e_token = inbuf_next(); if (*e_token == '\\') { /* if escape, copy extra char */ if (*buf_ptr == '\n') /* check for escaped newline */ ++line_no; - *++e_token = *buf_ptr++; + *++e_token = inbuf_next(); ++e_token; /* we must increment this again because we * copied two chars */ - if (buf_ptr >= buf_end) - fill_buffer(); } else break; /* we copied one character */ @@ -596,11 +604,8 @@ stop_lit: case '>': case '<': case '!': /* ops like <, <<, <=, !=, etc */ - if (*buf_ptr == '>' || *buf_ptr == '<' || *buf_ptr == '=') { - *e_token++ = *buf_ptr; - if (++buf_ptr >= buf_end) - fill_buffer(); - } + if (*buf_ptr == '>' || *buf_ptr == '<' || *buf_ptr == '=') + *e_token++ = inbuf_next(); if (*buf_ptr == '=') *e_token++ = *buf_ptr++; code = (state->last_u_d ? unary_op : binary_op); @@ -620,8 +625,7 @@ stop_lit: check_size_token(1); *e_token++ = *buf_ptr; } - if (++buf_ptr >= buf_end) - fill_buffer(); + inbuf_skip(); } if (ps.in_decl) { char *tp = buf_ptr; @@ -640,10 +644,7 @@ stop_lit: default: if (token[0] == '/' && (*buf_ptr == '*' || *buf_ptr == '/')) { /* it is start of comment */ - *e_token++ = *buf_ptr; - - if (++buf_ptr >= buf_end) - fill_buffer(); + *e_token++ = inbuf_next(); code = comment;
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Tue Mar 9 19:46:28 UTC 2021 Modified Files: src/usr.bin/indent: indent.c Log Message: indent: extract search_brace from main No functional change. To generate a diff of this commit: cvs rdiff -u -r1.40 -r1.41 src/usr.bin/indent/indent.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.40 src/usr.bin/indent/indent.c:1.41 --- src/usr.bin/indent/indent.c:1.40 Tue Mar 9 19:32:41 2021 +++ src/usr.bin/indent/indent.c Tue Mar 9 19:46:28 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.40 2021/03/09 19:32:41 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.41 2021/03/09 19:46:28 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.40 2021/03/09 19:32:41 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.41 2021/03/09 19:46:28 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -179,9 +179,191 @@ init_capsicum(void) if (caph_enter() < 0) err(EXIT_FAILURE, "unable to enter capability mode"); } - #endif +static void +search_brace(token_type *inout_type_code, int *inout_force_nl, + int *inout_comment_buffered, int *inout_last_else) +{ +while (ps.search_brace) { + switch (*inout_type_code) { + case newline: + if (sc_end == NULL) { + save_com = sc_buf; + save_com[0] = save_com[1] = ' '; + sc_end = _com[2]; + } + *sc_end++ = '\n'; + /* + * We may have inherited a force_nl == true from the previous + * token (like a semicolon). But once we know that a newline + * has been scanned in this loop, force_nl should be false. + * + * However, the force_nl == true must be preserved if newline + * is never scanned in this loop, so this assignment cannot be + * done earlier. + */ + *inout_force_nl = false; + case form_feed: + break; + case comment: + if (sc_end == NULL) { + /* + * Copy everything from the start of the line, because + * pr_comment() will use that to calculate original + * indentation of a boxed comment. + */ + memcpy(sc_buf, in_buffer, buf_ptr - in_buffer - 4); + save_com = sc_buf + (buf_ptr - in_buffer - 4); + save_com[0] = save_com[1] = ' '; + sc_end = _com[2]; + } + *inout_comment_buffered = true; + *sc_end++ = '/'; /* copy in start of comment */ + *sc_end++ = '*'; + for (;;) { /* loop until the end of the comment */ + *sc_end = *buf_ptr++; + if (buf_ptr >= buf_end) + fill_buffer(); + if (*sc_end++ == '*' && *buf_ptr == '/') + break; /* we are at end of comment */ + if (sc_end >= _com[sc_size]) { /* check for temp buffer + * overflow */ + diag(1, "Internal buffer overflow - Move big comment from right after if, while, or whatever"); + fflush(output); + exit(1); + } + } + *sc_end++ = '/'; /* add ending slash */ + if (++buf_ptr >= buf_end) /* get past / in buffer */ + fill_buffer(); + break; + case lbrace: + /* + * Put KNF-style lbraces before the buffered up tokens and + * jump out of this loop in order to avoid copying the token + * again under the default case of the switch below. + */ + if (sc_end != NULL && opt.btype_2) { + save_com[0] = '{'; + /* + * Originally the lbrace may have been alone on its own + * line, but it will be moved into "the else's line", so + * if there was a newline resulting from the "{" before, + * it must be scanned now and ignored. + */ + while (isspace((unsigned char)*buf_ptr)) { + if (++buf_ptr >= buf_end) + fill_buffer(); + if (*buf_ptr == '\n') + break; + } + goto sw_buffer; + } + /* FALLTHROUGH */ + default: /* it is the start of a normal statement */ + { + int remove_newlines; + + remove_newlines = + /* "} else" */ + (*inout_type_code == keyword_do_else && *token == 'e' && + e_code != s_code && e_code[-1] == '}') + /* "else if" */ + || (*inout_type_code == keyword_for_if_while && + *token == 'i' && *inout_last_else && opt.else_if); + if (remove_newlines) + *inout_force_nl = false; + if (sc_end == NULL) { /* ignore buffering if + * comment wasn't saved up */ + ps.search_brace = false; + return; + } + while (sc_end > save_com && isblank((unsigned char)sc_end[-1])) { + sc_end--; + } + if (opt.swallow_optional_blanklines || + (!*inout_comment_buffered && remove_newlines)) { + *inout_force_nl = !remove_newlines; + while (sc_end > save_com && sc_end[-1] == '\n') { + sc_end--; + } + } + if (*inout_force_nl) { /* if we should insert a nl here, put + * it into the buffer */ + *inout_force_nl = false; +
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Tue Mar 9 19:32:41 UTC 2021 Modified Files: src/usr.bin/indent: indent.c Log Message: indent: extract capsicum code out of the main function No functional change. To generate a diff of this commit: cvs rdiff -u -r1.39 -r1.40 src/usr.bin/indent/indent.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.39 src/usr.bin/indent/indent.c:1.40 --- src/usr.bin/indent/indent.c:1.39 Tue Mar 9 19:23:08 2021 +++ src/usr.bin/indent/indent.c Tue Mar 9 19:32:41 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.39 2021/03/09 19:23:08 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.40 2021/03/09 19:32:41 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.39 2021/03/09 19:23:08 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.40 2021/03/09 19:32:41 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -163,13 +163,28 @@ check_size_label(size_t desired_size) } } -int -main(int argc, char **argv) -{ #if HAVE_CAPSICUM +static void +init_capsicum(void) +{ cap_rights_t rights; + +/* Restrict input/output descriptors and enter Capsicum sandbox. */ +cap_rights_init(, CAP_FSTAT, CAP_WRITE); +if (caph_rights_limit(fileno(output), ) < 0) + err(EXIT_FAILURE, "unable to limit rights for %s", out_name); +cap_rights_init(, CAP_FSTAT, CAP_READ); +if (caph_rights_limit(fileno(input), ) < 0) + err(EXIT_FAILURE, "unable to limit rights for %s", in_name); +if (caph_enter() < 0) + err(EXIT_FAILURE, "unable to enter capability mode"); +} + #endif +int +main(int argc, char **argv) +{ int dec_ind; /* current indentation for declarations */ int di_stack[20]; /* a stack of structure indentation levels */ int force_nl; /* when true, code must be broken */ @@ -339,15 +354,7 @@ main(int argc, char **argv) } #if HAVE_CAPSICUM -/* Restrict input/output descriptors and enter Capsicum sandbox. */ -cap_rights_init(, CAP_FSTAT, CAP_WRITE); -if (caph_rights_limit(fileno(output), ) < 0) - err(EXIT_FAILURE, "unable to limit rights for %s", out_name); -cap_rights_init(, CAP_FSTAT, CAP_READ); -if (caph_rights_limit(fileno(input), ) < 0) - err(EXIT_FAILURE, "unable to limit rights for %s", in_name); -if (caph_enter() < 0) - err(EXIT_FAILURE, "unable to enter capability mode"); +init_capsicum(); #endif if (opt.com_ind <= 1)
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Tue Mar 9 19:23:08 UTC 2021 Modified Files: src/usr.bin/indent: indent.c indent_codes.h lexi.c Log Message: indent: rename a few more token types The previous names were either too short or ambiguous. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.38 -r1.39 src/usr.bin/indent/indent.c cvs rdiff -u -r1.10 -r1.11 src/usr.bin/indent/indent_codes.h cvs rdiff -u -r1.30 -r1.31 src/usr.bin/indent/lexi.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.38 src/usr.bin/indent/indent.c:1.39 --- src/usr.bin/indent/indent.c:1.38 Tue Mar 9 19:14:39 2021 +++ src/usr.bin/indent/indent.c Tue Mar 9 19:23:08 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.38 2021/03/09 19:14:39 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.39 2021/03/09 19:23:08 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.38 2021/03/09 19:14:39 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.39 2021/03/09 19:23:08 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -595,7 +595,7 @@ check_type: if ( (type_code != comment) && (type_code != newline) && - (type_code != preesc) && + (type_code != preprocessing) && (type_code != form_feed)) { if (force_nl && (type_code != semicolon) && @@ -770,7 +770,7 @@ check_type: ps.want_blank = true; break; - case postop: /* got a trailing ++ or -- */ + case postfix_op: /* got a trailing ++ or -- */ *e_code++ = token[0]; *e_code++ = token[1]; ps.want_blank = true; @@ -1032,11 +1032,11 @@ check_type: goto copy_id; /* move the token into line */ case type_def: - case storage: + case storage_class: prefix_blankline_requested = 0; goto copy_id; - case structure: + case keyword_struct_union_enum: if (ps.p_l_follow > 0) goto copy_id; /* FALLTHROUGH */ @@ -1114,7 +1114,7 @@ check_type: ps.want_blank = true; break; - case strpfx: + case string_prefix: { int len = e_token - s_token; @@ -1154,7 +1154,7 @@ check_type: } break; - case preesc: /* got the character '#' */ + case preprocessing: /* '#' */ if ((s_com != e_com) || (s_lab != e_lab) || (s_code != e_code)) @@ -1308,7 +1308,9 @@ check_type: } /* end of big switch stmt */ *e_code = '\0'; /* make sure code section is null terminated */ - if (type_code != comment && type_code != newline && type_code != preesc) + if (type_code != comment && + type_code != newline && + type_code != preprocessing) ps.last_token = type_code; }/* end of main while (1) loop */ } Index: src/usr.bin/indent/indent_codes.h diff -u src/usr.bin/indent/indent_codes.h:1.10 src/usr.bin/indent/indent_codes.h:1.11 --- src/usr.bin/indent/indent_codes.h:1.10 Tue Mar 9 19:14:39 2021 +++ src/usr.bin/indent/indent_codes.h Tue Mar 9 19:23:08 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent_codes.h,v 1.10 2021/03/09 19:14:39 rillig Exp $ */ +/* $NetBSD: indent_codes.h,v 1.11 2021/03/09 19:23:08 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -47,7 +47,7 @@ typedef enum token_type { rparen, /* ')' or ']' */ unary_op, /* e.g. '+' or '&' */ binary_op, /* e.g. '<<' or '+' or '&&' or '/=' */ -postop, /* trailing '++' or '--' */ +postfix_op, /* trailing '++' or '--' */ question, /* the '?' from a '?:' expression */ case_label, colon, @@ -58,7 +58,7 @@ typedef enum token_type { comma, comment, switch_expr, /* 'switch' '(' ')' */ -preesc, +preprocessing, /* '#' */ form_feed, decl, keyword_for_if_while, /* 'for', 'if' or 'while' */ @@ -74,9 +74,9 @@ typedef enum token_type { if_expr_stmt, /* 'if' '(' ')' */ if_expr_stmt_else, /* 'if' '(' ')' 'else' */ period, -strpfx, -storage, +string_prefix, /* 'L' */ +storage_class, funcname, type_def, -structure +keyword_struct_union_enum } token_type; Index: src/usr.bin/indent/lexi.c diff -u src/usr.bin/indent/lexi.c:1.30 src/usr.bin/indent/lexi.c:1.31 --- src/usr.bin/indent/lexi.c:1.30 Tue Mar 9 19:14:39 2021 +++ src/usr.bin/indent/lexi.c Tue Mar 9 19:23:08 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lexi.c,v 1.30 2021/03/09 19:14:39 rillig Exp $ */ +/* $NetBSD: lexi.c,v 1.31 2021/03/09 19:23:08 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)lexi.c 8.1 ( #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: lexi.c,v 1.30 2021/03/09 19:14:39 rillig Exp $"); +__RCSID("$NetBSD:
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Tue Mar 9 19:14:39 UTC 2021 Modified Files: src/usr.bin/indent: indent.c indent_codes.h lexi.c parse.c Log Message: indent: make token names more precise The previous 'casestmt' was wrong since a case label is not a statement at all. The previous 'swstmt' was overly short, and wrong as well, since it represents only the 'switch (expr)' part, which is not a complete switch statement. Same for 'ifstmt', 'whilestmt', 'forstmt'. The previous word 'head' was not precise enough since it didn't specify exactly where the head ends and the body starts. Especially for handling the dangling else, this distinction is important. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.37 -r1.38 src/usr.bin/indent/indent.c cvs rdiff -u -r1.9 -r1.10 src/usr.bin/indent/indent_codes.h cvs rdiff -u -r1.29 -r1.30 src/usr.bin/indent/lexi.c cvs rdiff -u -r1.16 -r1.17 src/usr.bin/indent/parse.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.37 src/usr.bin/indent/indent.c:1.38 --- src/usr.bin/indent/indent.c:1.37 Tue Mar 9 18:28:10 2021 +++ src/usr.bin/indent/indent.c Tue Mar 9 19:14:39 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.37 2021/03/09 18:28:10 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.38 2021/03/09 19:14:39 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.37 2021/03/09 18:28:10 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.38 2021/03/09 19:14:39 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -786,7 +786,7 @@ check_type: ps.want_blank = true; break; - case casestmt: /* got word 'case' or 'default' */ + case case_label: /* got word 'case' or 'default' */ scase = true; /* so we can process the later colon properly */ goto copy_id; @@ -853,7 +853,7 @@ check_type: * structure declaration, we * arent any more */ - if ((!sp_sw || hd_type != forstmt) && ps.p_l_follow > 0) { + if ((!sp_sw || hd_type != for_exprs) && ps.p_l_follow > 0) { /* * This should be true iff there were unbalanced parens in the @@ -981,23 +981,24 @@ check_type: } prefix_blankline_requested = 0; parse(rbrace); /* let parser know about this */ - ps.search_brace = opt.cuddle_else && ps.p_stack[ps.tos] == ifhead + ps.search_brace = opt.cuddle_else + && ps.p_stack[ps.tos] == if_expr_stmt && ps.il[ps.tos] >= ps.ind_level; if (ps.tos <= 1 && opt.blanklines_after_procs && ps.dec_nest <= 0) postfix_blankline_requested = 1; break; - case swstmt: /* got keyword "switch" */ + case switch_expr: /* got keyword "switch" */ sp_sw = true; - hd_type = swstmt; /* keep this for when we have seen the + hd_type = switch_expr; /* keep this for when we have seen the * expression */ goto copy_id; /* go move the token into buffer */ case keyword_for_if_while: sp_sw = true; /* the interesting stuff is done after the * expression is scanned */ - hd_type = (*token == 'i' ? ifstmt : - (*token == 'w' ? whilestmt : forstmt)); + hd_type = (*token == 'i' ? if_expr : + (*token == 'w' ? while_expr : for_exprs)); /* * remember the type of header for later use by parser @@ -1015,7 +1016,7 @@ check_type: } force_nl = true;/* also, following stuff must go onto new line */ last_else = 1; - parse(elselit); + parse(keyword_else); } else { if (e_code != s_code) { /* make sure this starts a line */ @@ -1026,7 +1027,7 @@ check_type: } force_nl = true;/* also, following stuff must go onto new line */ last_else = 0; - parse(dolit); + parse(keyword_do); } goto copy_id; /* move the token into line */ Index: src/usr.bin/indent/indent_codes.h diff -u src/usr.bin/indent/indent_codes.h:1.9 src/usr.bin/indent/indent_codes.h:1.10 --- src/usr.bin/indent/indent_codes.h:1.9 Tue Mar 9 18:28:10 2021 +++ src/usr.bin/indent/indent_codes.h Tue Mar 9 19:14:39 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent_codes.h,v 1.9 2021/03/09 18:28:10 rillig Exp $ */ +/* $NetBSD: indent_codes.h,v 1.10 2021/03/09 19:14:39 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -49,7 +49,7 @@ typedef enum token_type { binary_op, /* e.g. '<<' or '+' or '&&' or '/=' */ postop, /* trailing '++' or '--' */ question, /* the '?' from a '?:' expression */ -casestmt, +case_label, colon, semicolon, lbrace, @@ -57,22 +57,22 @@ typedef enum token_type { ident, comma, comment, -swstmt, +switch_expr, /* 'switch' '(' ')' */
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Tue Mar 9 18:28:10 UTC 2021 Modified Files: src/usr.bin/indent: indent.c indent_codes.h lexi.c Log Message: indent: rename a few tokens to be more obvious For casual readers it is not obvious whether the 'sp' meant 'special' or 'space' or something entirely different. To generate a diff of this commit: cvs rdiff -u -r1.36 -r1.37 src/usr.bin/indent/indent.c cvs rdiff -u -r1.8 -r1.9 src/usr.bin/indent/indent_codes.h cvs rdiff -u -r1.28 -r1.29 src/usr.bin/indent/lexi.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.36 src/usr.bin/indent/indent.c:1.37 --- src/usr.bin/indent/indent.c:1.36 Tue Mar 9 16:48:28 2021 +++ src/usr.bin/indent/indent.c Tue Mar 9 18:28:10 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.36 2021/03/09 16:48:28 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.37 2021/03/09 18:28:10 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.36 2021/03/09 16:48:28 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.37 2021/03/09 18:28:10 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -481,11 +481,11 @@ main(int argc, char **argv) remove_newlines = /* "} else" */ - (type_code == sp_nparen && *token == 'e' && + (type_code == keyword_do_else && *token == 'e' && e_code != s_code && e_code[-1] == '}') /* "else if" */ - || (type_code == sp_paren && *token == 'i' && - last_else && opt.else_if); + || (type_code == keyword_for_if_while && + *token == 'i' && last_else && opt.else_if); if (remove_newlines) force_nl = false; if (sc_end == NULL) { /* ignore buffering if @@ -993,7 +993,7 @@ check_type: * expression */ goto copy_id; /* go move the token into buffer */ - case sp_paren: /* token is if, while, for */ + case keyword_for_if_while: sp_sw = true; /* the interesting stuff is done after the * expression is scanned */ hd_type = (*token == 'i' ? ifstmt : @@ -1004,7 +1004,7 @@ check_type: */ goto copy_id; /* copy the token into line */ - case sp_nparen: /* got else, do */ + case keyword_do_else: ps.in_stmt = false; if (*token == 'e') { if (e_code != s_code && (!opt.cuddle_else || e_code[-1] != '}')) { Index: src/usr.bin/indent/indent_codes.h diff -u src/usr.bin/indent/indent_codes.h:1.8 src/usr.bin/indent/indent_codes.h:1.9 --- src/usr.bin/indent/indent_codes.h:1.8 Sun Mar 7 20:30:48 2021 +++ src/usr.bin/indent/indent_codes.h Tue Mar 9 18:28:10 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent_codes.h,v 1.8 2021/03/07 20:30:48 rillig Exp $ */ +/* $NetBSD: indent_codes.h,v 1.9 2021/03/09 18:28:10 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -61,8 +61,8 @@ typedef enum token_type { preesc, form_feed, decl, -sp_paren, -sp_nparen, +keyword_for_if_while, +keyword_do_else, ifstmt, whilestmt, forstmt, Index: src/usr.bin/indent/lexi.c diff -u src/usr.bin/indent/lexi.c:1.28 src/usr.bin/indent/lexi.c:1.29 --- src/usr.bin/indent/lexi.c:1.28 Tue Mar 9 16:48:28 2021 +++ src/usr.bin/indent/lexi.c Tue Mar 9 18:28:10 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lexi.c,v 1.28 2021/03/09 16:48:28 rillig Exp $ */ +/* $NetBSD: lexi.c,v 1.29 2021/03/09 18:28:10 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)lexi.c 8.1 ( #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: lexi.c,v 1.28 2021/03/09 16:48:28 rillig Exp $"); +__RCSID("$NetBSD: lexi.c,v 1.29 2021/03/09 18:28:10 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $"); #endif @@ -207,7 +207,8 @@ token_type_name(token_type tk) "binary_op", "postop", "question", "casestmt", "colon", "semicolon", "lbrace", "rbrace", "ident", "comma", "comment", "swstmt", "preesc", "form_feed", "decl", - "sp_paren", "sp_nparen", "ifstmt", "whilestmt", "forstmt", + "keyword_for_if_while", "keyword_do_else", + "ifstmt", "whilestmt", "forstmt", "stmt", "stmtl", "elselit", "dolit", "dohead", "ifhead", "elsehead", "period", "strpfx", "storage", "funcname", "type_def", "structure" @@ -387,10 +388,10 @@ lexi(struct parser_state *state) return lexi_end(decl); case rw_for_or_if_or_while: - return lexi_end(sp_paren); + return lexi_end(keyword_for_if_while); case rw_do_or_else: - return lexi_end(sp_nparen); + return lexi_end(keyword_do_else); case rw_storage_class: return lexi_end(storage);
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Tue Mar 9 18:21:01 UTC 2021 Modified Files: src/usr.bin/indent: parse.c Log Message: indent: extract reduce_stmt from reduce This refactoring reduces the indentation of the code, as well as removing any ambiguity as to which 'switch' statement a 'break' belongs, as there are no more nested 'switch' statements. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/usr.bin/indent/parse.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/parse.c diff -u src/usr.bin/indent/parse.c:1.15 src/usr.bin/indent/parse.c:1.16 --- src/usr.bin/indent/parse.c:1.15 Tue Mar 9 16:48:28 2021 +++ src/usr.bin/indent/parse.c Tue Mar 9 18:21:01 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.15 2021/03/09 16:48:28 rillig Exp $ */ +/* $NetBSD: parse.c,v 1.16 2021/03/09 18:21:01 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -232,116 +232,78 @@ parse(token_type tk) /* tk: the code fo #endif } -/* - * NAME: reduce - * - * FUNCTION: Implements the reduce part of the parsing algorithm - * - * ALGORITHM: The following reductions are done. Reductions are repeated - * until no more are possible. - * - * Old TOS New TOS - * - * - * do "dostmt" - * if "ifstmt" - * switch - * decl - * "ifelse" - * for - * while - * "dostmt" while - * - * On each reduction, ps.i_l_follow (the indentation for the following line) - * is set to the indentation level associated with the old TOS. - * - * PARAMETERS: None - * - * RETURNS: Nothing - * - * GLOBALS: ps.cstk ps.i_l_follow = ps.il ps.p_stack = ps.tos = - * - * CALLS: None - * - * CALLED BY: parse - * - * HISTORY: initial coding November 1976 D A Willcox of CAC - * - */ /*--*\ | REDUCTION PHASE | \*--*/ -static void -reduce(void) -{ -int i; -for (;;) { /* keep looping until there is nothing left to - * reduce */ +/* + * Try to combine the statement on the top of the parse stack with the symbol + * directly below it, replacing these two symbols with a single symbol. + */ +static int +reduce_stmt(void) +{ +switch (ps.p_stack[ps.tos - 1]) { - switch (ps.p_stack[ps.tos]) { +case stmt: /* stmt stmt */ +case stmtl: /* stmtl stmt */ + ps.p_stack[--ps.tos] = stmtl; + return true; + +case dolit: /* do */ + ps.p_stack[--ps.tos] = dohead; + ps.i_l_follow = ps.il[ps.tos]; + return true; + +case ifstmt: /* if () */ + ps.p_stack[--ps.tos] = ifhead; + int i = ps.tos - 1; + while (ps.p_stack[i] != stmt && + ps.p_stack[i] != stmtl && + ps.p_stack[i] != lbrace) + --i; + ps.i_l_follow = ps.il[i]; + /* + * for the time being, we will assume that there is no else on + * this if, and set the indentation level accordingly. If an + * else is scanned, it will be fixed up later + */ + return true; - case stmt: - switch (ps.p_stack[ps.tos - 1]) { - - case stmt: /* stmt stmt */ - case stmtl: /* stmtl stmt */ - ps.p_stack[--ps.tos] = stmtl; - break; - - case dolit: /* */ - ps.p_stack[--ps.tos] = dohead; - ps.i_l_follow = ps.il[ps.tos]; - break; - - case ifstmt: /* */ - ps.p_stack[--ps.tos] = ifhead; - for (i = ps.tos - 1; - ( - ps.p_stack[i] != stmt - && - ps.p_stack[i] != stmtl - && - ps.p_stack[i] != lbrace - ); - --i); - ps.i_l_follow = ps.il[i]; - /* - * for the time being, we will assume that there is no else on - * this if, and set the indentation level accordingly. If an - * else is scanned, it will be fixed up later - */ - break; - - case swstmt: /* */ - case_ind = ps.cstk[ps.tos - 1]; - /* FALLTHROUGH */ - case decl: /* finish of a declaration */ - case elsehead: /* else> */ - case forstmt: /* */ - case whilestmt: /* */ - ps.p_stack[--ps.tos] = stmt; - ps.i_l_follow = ps.il[ps.tos]; - break; - - default: /* */ - return; - - } /* end of section for on top of stack */ - break; - - case whilestmt: /* while (...) on top */ - if (ps.p_stack[ps.tos - 1] == dohead) { - /* it is termination of a do while */ - ps.tos -= 2; - break; - } - else - return; +case swstmt: /* switch () */ + case_ind = ps.cstk[ps.tos - 1]; + /* FALLTHROUGH */ +case decl: /* finish of a declaration */ +case elsehead: /* if () else */ +case forstmt: /* for (<...>) */ +case whilestmt: /* while () */ + ps.p_stack[--ps.tos] = stmt; + ps.i_l_follow = ps.il[ps.tos]; + return true; - default: /* anything else on top */ - return; +default: /* */ + return false; +} +} +/* + * Repeatedly try to reduce the top two symbols on the parse stack to a + * single symbol, until no more reductions are possible. + * + * On each reduction, ps.i_l_follow (the indentation for
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Tue Mar 9 16:48:28 UTC 2021 Modified Files: src/usr.bin/indent: args.c indent.c lexi.c parse.c pr_comment.c Log Message: indent: manually indent comments It's strange that indent's own code is not formatted by indent itself, which would be a good demonstration of its capabilities. In its current state, I don't trust indent to get even the tokenization correct, therefore the only safe way is to format the code manually. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/usr.bin/indent/args.c cvs rdiff -u -r1.35 -r1.36 src/usr.bin/indent/indent.c cvs rdiff -u -r1.27 -r1.28 src/usr.bin/indent/lexi.c cvs rdiff -u -r1.14 -r1.15 src/usr.bin/indent/parse.c \ src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/args.c diff -u src/usr.bin/indent/args.c:1.17 src/usr.bin/indent/args.c:1.18 --- src/usr.bin/indent/args.c:1.17 Sun Mar 7 20:52:11 2021 +++ src/usr.bin/indent/args.c Tue Mar 9 16:48:28 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: args.c,v 1.17 2021/03/07 20:52:11 rillig Exp $ */ +/* $NetBSD: args.c,v 1.18 2021/03/09 16:48:28 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)args.c 8.1 ( #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: args.c,v 1.17 2021/03/07 20:52:11 rillig Exp $"); +__RCSID("$NetBSD: args.c,v 1.18 2021/03/09 16:48:28 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $"); #endif @@ -85,8 +85,8 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/ static void scan_profile(FILE *); -#define KEY_FILE 5 /* only used for args */ -#define VERSION 6 /* only used for args */ +#define KEY_FILE 5 /* only used for args */ +#define VERSION 6 /* only used for args */ const char *option_source = "?"; Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.35 src/usr.bin/indent/indent.c:1.36 --- src/usr.bin/indent/indent.c:1.35 Mon Mar 8 20:20:11 2021 +++ src/usr.bin/indent/indent.c Tue Mar 9 16:48:28 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.35 2021/03/08 20:20:11 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.36 2021/03/09 16:48:28 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.35 2021/03/08 20:20:11 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.36 2021/03/09 16:48:28 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -435,7 +435,7 @@ main(int argc, char **argv) comment_buffered = true; *sc_end++ = '/'; /* copy in start of comment */ *sc_end++ = '*'; - for (;;) { /* loop until we get to the end of the comment */ + for (;;) { /* loop until the end of the comment */ *sc_end = *buf_ptr++; if (buf_ptr >= buf_end) fill_buffer(); @@ -525,7 +525,7 @@ main(int argc, char **argv) buf_ptr = save_com; /* fix so that subsequent calls to * lexi will take tokens out of * save_com */ - *sc_end++ = ' ';/* add trailing blank, just in case */ + *sc_end++ = ' '; /* add trailing blank, just in case */ buf_end = sc_end; sc_end = NULL; break; @@ -639,7 +639,7 @@ check_type: * final increment for the null character. */ switch (type_code) { /* now, decide what to do with the token */ - case form_feed: /* found a form feed in line */ + case form_feed: /* found a form feed in line */ ps.use_ff = true; /* a form feed is treated much like a newline */ dump_line(); ps.want_blank = false; @@ -716,7 +716,7 @@ check_type: if (sp_sw && (ps.p_l_follow == 0)) { /* check for end of if * (...), or some such */ sp_sw = false; - force_nl = true;/* must force newline after if */ + force_nl = true; /* must force newline after if */ ps.last_u_d = true; /* inform lexi that a following * operator is unary */ ps.in_stmt = false; /* dont use stmt continuation @@ -757,7 +757,7 @@ check_type: ps.want_blank = false; break; - case binary_op: /* any binary operation */ + case binary_op: /* any binary operation */ { int len = e_token - s_token; @@ -830,8 +830,8 @@ check_type: case semicolon: /* got a ';' */ if (ps.dec_nest == 0) - ps.in_or_st = false;/* we are not in an initialization or - * structure declaration */ + ps.in_or_st = false; /* we are not in an initialization or + * structure declaration */ scase = false; /* these will only need resetting in an error */ squest = 0; if (ps.last_token == rparen) @@ -1004,7 +1004,7 @@ check_type: */ goto copy_id; /* copy the token into line */
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon Mar 8 22:28:31 UTC 2021 Modified Files: src/usr.bin/indent: io.c Log Message: indent: remove redundant initializer in dump_line No functional change. To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/usr.bin/indent/io.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.26 src/usr.bin/indent/io.c:1.27 --- src/usr.bin/indent/io.c:1.26 Mon Mar 8 22:26:17 2021 +++ src/usr.bin/indent/io.c Mon Mar 8 22:28:31 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.26 2021/03/08 22:26:17 rillig Exp $ */ +/* $NetBSD: io.c,v 1.27 2021/03/08 22:28:31 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.26 2021/03/08 22:26:17 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.27 2021/03/08 22:28:31 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -73,8 +73,7 @@ static int pad_output(int current, int t void dump_line(void) { -int cur_col, -target_col = 1; +int cur_col, target_col; static int not_first_line; if (ps.procname[0]) {
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon Mar 8 22:26:17 UTC 2021 Modified Files: src/usr.bin/indent: io.c Log Message: indent: move comment about dump_line to column 1 It looked misplaced on the right side since that area is usually reserved for small remarks, not long explanations. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/usr.bin/indent/io.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.25 src/usr.bin/indent/io.c:1.26 --- src/usr.bin/indent/io.c:1.25 Mon Mar 8 22:23:58 2021 +++ src/usr.bin/indent/io.c Mon Mar 8 22:26:17 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.25 2021/03/08 22:23:58 rillig Exp $ */ +/* $NetBSD: io.c,v 1.26 2021/03/08 22:26:17 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.25 2021/03/08 22:23:58 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.26 2021/03/08 22:26:17 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -65,13 +65,14 @@ int comment_open; static int paren_target; static int pad_output(int current, int target); +/* + * dump_line is the routine that actually effects the printing of the new + * source. It prints the label section, followed by the code section with + * the appropriate nesting level, followed by any comments. + */ void dump_line(void) -{/* dump_line is the routine that actually - * effects the printing of the new source. It - * prints the label section, followed by the - * code section with the appropriate nesting - * level, followed by any comments */ +{ int cur_col, target_col = 1; static int not_first_line;
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon Mar 8 22:23:58 UTC 2021 Modified Files: src/usr.bin/indent: io.c Log Message: indent: always use braces in do-while loops Having a 'while' at the beginning of a line looks as if it would start a loop. It's confusing when it _ends_ a loop instead. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/usr.bin/indent/io.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.24 src/usr.bin/indent/io.c:1.25 --- src/usr.bin/indent/io.c:1.24 Sun Mar 7 22:11:01 2021 +++ src/usr.bin/indent/io.c Mon Mar 8 22:23:58 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.24 2021/03/07 22:11:01 rillig Exp $ */ +/* $NetBSD: io.c,v 1.25 2021/03/08 22:23:58 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.24 2021/03/07 22:11:01 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.25 2021/03/08 22:23:58 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -126,8 +126,9 @@ dump_line(void) || strncmp(s_lab, "#endif", 6) == 0)) { char *s = s_lab; if (e_lab[-1] == '\n') e_lab--; - do putc(*s++, output); - while (s < e_lab && 'a' <= *s && *s<='z'); + do { + putc(*s++, output); + } while (s < e_lab && 'a' <= *s && *s <= 'z'); while ((*s == ' ' || *s == '\t') && s < e_lab) s++; if (s < e_lab) @@ -369,9 +370,9 @@ fill_buffer(void) } if (inhibit_formatting) { p = in_buffer; - do + do { putc(*p, output); - while (*p++ != '\n'); + } while (*p++ != '\n'); } }
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon Mar 8 21:13:34 UTC 2021 Modified Files: src/usr.bin/indent: lexi.c Log Message: indent: split bsearch comparison function It may have been a clever trick to use the same memory layout for struct templ and a string pointer, but it's not worth the extra comment and difficulty in understanding the code. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/usr.bin/indent/lexi.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/lexi.c diff -u src/usr.bin/indent/lexi.c:1.26 src/usr.bin/indent/lexi.c:1.27 --- src/usr.bin/indent/lexi.c:1.26 Mon Mar 8 20:20:11 2021 +++ src/usr.bin/indent/lexi.c Mon Mar 8 21:13:33 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lexi.c,v 1.26 2021/03/08 20:20:11 rillig Exp $ */ +/* $NetBSD: lexi.c,v 1.27 2021/03/08 21:13:33 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)lexi.c 8.1 ( #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: lexi.c,v 1.26 2021/03/08 20:20:11 rillig Exp $"); +__RCSID("$NetBSD: lexi.c,v 1.27 2021/03/08 21:13:33 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $"); #endif @@ -75,9 +75,9 @@ struct templ { /* * This table has to be sorted alphabetically, because it'll be used in binary - * search. For the same reason, string must be the first thing in struct templ. + * search. */ -struct templ specials[] = +const struct templ specials[] = { {"_Bool", rw_type}, {"_Complex", rw_type}, @@ -187,9 +187,15 @@ check_size_token(size_t desired_size) } static int -strcmp_type(const void *e1, const void *e2) +compare_templ_array(const void *key, const void *elem) { -return strcmp(e1, *(const char *const *)e2); +return strcmp(key, ((const struct templ *)elem)->rwd); +} + +static int +compare_string_array(const void *key, const void *elem) +{ +return strcmp(key, *((const char *const *)elem)); } #ifdef debug @@ -341,11 +347,8 @@ lexi(struct parser_state *state) */ state->last_u_d = (state->last_token == structure); - p = bsearch(s_token, - specials, - sizeof(specials) / sizeof(specials[0]), - sizeof(specials[0]), - strcmp_type); + p = bsearch(s_token, specials, sizeof specials / sizeof specials[0], + sizeof specials[0], compare_templ_array); if (p == NULL) { /* not a special keyword... */ char *u; @@ -353,7 +356,7 @@ lexi(struct parser_state *state) if ((opt.auto_typedefs && ((u = strrchr(s_token, '_')) != NULL) && strcmp(u, "_t") == 0) || (typename_top >= 0 && bsearch(s_token, typenames, typename_top + 1, - sizeof(typenames[0]), strcmp_type))) { + sizeof typenames[0], compare_string_array))) { state->keyword = rw_type; state->last_u_d = true; goto found_typename;
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon Mar 8 20:20:11 UTC 2021 Modified Files: src/usr.bin/indent: indent.c indent_globs.h lexi.c Log Message: indent: inline macro for backslash No functional change. To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/usr.bin/indent/indent.c cvs rdiff -u -r1.16 -r1.17 src/usr.bin/indent/indent_globs.h cvs rdiff -u -r1.25 -r1.26 src/usr.bin/indent/lexi.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.34 src/usr.bin/indent/indent.c:1.35 --- src/usr.bin/indent/indent.c:1.34 Mon Mar 8 20:15:42 2021 +++ src/usr.bin/indent/indent.c Mon Mar 8 20:20:11 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.34 2021/03/08 20:15:42 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.35 2021/03/08 20:20:11 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.34 2021/03/08 20:15:42 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.35 2021/03/08 20:20:11 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -1177,7 +1177,7 @@ check_type: if (buf_ptr >= buf_end) fill_buffer(); switch (*e_lab++) { - case BACKSLASH: + case '\\': if (!in_comment) { *e_lab++ = *buf_ptr++; if (buf_ptr >= buf_end) Index: src/usr.bin/indent/indent_globs.h diff -u src/usr.bin/indent/indent_globs.h:1.16 src/usr.bin/indent/indent_globs.h:1.17 --- src/usr.bin/indent/indent_globs.h:1.16 Mon Mar 8 20:15:42 2021 +++ src/usr.bin/indent/indent_globs.h Mon Mar 8 20:20:11 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent_globs.h,v 1.16 2021/03/08 20:15:42 rillig Exp $ */ +/* $NetBSD: indent_globs.h,v 1.17 2021/03/08 20:20:11 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -40,7 +40,6 @@ * $FreeBSD: head/usr.bin/indent/indent_globs.h 337651 2018-08-11 19:20:06Z pstef $ */ -#define BACKSLASH '\\' #define bufsize 200 /* size of internal buffers */ #define sc_size 5000 /* size of save_com buffer */ #define label_offset 2 /* number of levels a label is placed to left Index: src/usr.bin/indent/lexi.c diff -u src/usr.bin/indent/lexi.c:1.25 src/usr.bin/indent/lexi.c:1.26 --- src/usr.bin/indent/lexi.c:1.25 Mon Mar 8 20:15:42 2021 +++ src/usr.bin/indent/lexi.c Mon Mar 8 20:20:11 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lexi.c,v 1.25 2021/03/08 20:15:42 rillig Exp $ */ +/* $NetBSD: lexi.c,v 1.26 2021/03/08 20:20:11 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)lexi.c 8.1 ( #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: lexi.c,v 1.25 2021/03/08 20:15:42 rillig Exp $"); +__RCSID("$NetBSD: lexi.c,v 1.26 2021/03/08 20:20:11 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $"); #endif @@ -301,10 +301,10 @@ lexi(struct parser_state *state) } else while (isalnum((unsigned char)*buf_ptr) || - *buf_ptr == BACKSLASH || + *buf_ptr == '\\' || *buf_ptr == '_' || *buf_ptr == '$') { /* fill_buffer() terminates buffer with newline */ - if (*buf_ptr == BACKSLASH) { + if (*buf_ptr == '\\') { if (*(buf_ptr + 1) == '\n') { buf_ptr += 2; if (buf_ptr >= buf_end) @@ -467,7 +467,7 @@ lexi(struct parser_state *state) *e_token = *buf_ptr++; if (buf_ptr >= buf_end) fill_buffer(); - if (*e_token == BACKSLASH) { /* if escape, copy extra char */ + if (*e_token == '\\') { /* if escape, copy extra char */ if (*buf_ptr == '\n') /* check for escaped newline */ ++line_no; *++e_token = *buf_ptr++;
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon Mar 8 20:15:42 UTC 2021 Modified Files: src/usr.bin/indent: indent.c indent_globs.h lexi.c pr_comment.c Log Message: indent: convert big macros to functions Each of these buffers is only modified in a single file. This makes it unnecessary to declare the macros in the global header. To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.34 src/usr.bin/indent/indent.c cvs rdiff -u -r1.15 -r1.16 src/usr.bin/indent/indent_globs.h cvs rdiff -u -r1.24 -r1.25 src/usr.bin/indent/lexi.c cvs rdiff -u -r1.13 -r1.14 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.33 src/usr.bin/indent/indent.c:1.34 --- src/usr.bin/indent/indent.c:1.33 Mon Mar 8 19:06:48 2021 +++ src/usr.bin/indent/indent.c Mon Mar 8 20:15:42 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.33 2021/03/08 19:06:48 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.34 2021/03/08 20:15:42 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.33 2021/03/08 19:06:48 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.34 2021/03/08 20:15:42 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -133,6 +133,36 @@ const char *simple_backup_suffix = ".BAK * files */ charbakfile[MAXPATHLEN] = ""; +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 = (char *)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 = (char *)realloc(labbuf, nsize); + if (labbuf == NULL) + err(1, NULL); + e_lab = labbuf + label_len + 1; + l_lab = labbuf + nsize - 5; + s_lab = labbuf + 1; +} +} + int main(int argc, char **argv) { @@ -584,7 +614,7 @@ check_type: * in a line. fix it */ int len = e_com - s_com; - CHECK_SIZE_CODE(len + 3); + check_size_code(len + 3); *e_code++ = ' '; memcpy(e_code, s_com, len); e_code += len; @@ -603,8 +633,8 @@ check_type: /*-*\ | do switch on type of token scanned | \*-*/ - CHECK_SIZE_CODE(3); /* maximum number of increments of e_code - * before the next CHECK_SIZE_CODE or + check_size_code(3); /* maximum number of increments of e_code + * before the next check_size_code or * dump_line() is 2. After that there's the * final increment for the null character. */ switch (type_code) { /* now, decide what to do with the token */ @@ -720,7 +750,7 @@ check_type: { int len = e_token - s_token; - CHECK_SIZE_CODE(len); + check_size_code(len); memcpy(e_code, token, len); e_code += len; } @@ -731,7 +761,7 @@ check_type: { int len = e_token - s_token; - CHECK_SIZE_CODE(len + 1); + check_size_code(len + 1); if (ps.want_blank) *e_code++ = ' '; memcpy(e_code, token, len); @@ -782,7 +812,7 @@ check_type: { int len = e_code - s_code; - CHECK_SIZE_LAB(len + 3); + check_size_label(len + 3); memcpy(e_lab, s_code, len); e_lab += len; *e_lab++ = ':'; @@ -1073,7 +1103,7 @@ check_type: { int len = e_token - s_token; - CHECK_SIZE_CODE(len + 1); + check_size_code(len + 1); if (ps.want_blank) *e_code++ = ' '; memcpy(e_code, s_token, len); @@ -1087,7 +1117,7 @@ check_type: { int len = e_token - s_token; - CHECK_SIZE_CODE(len + 1); + check_size_code(len + 1); if (ps.want_blank) *e_code++ = ' '; memcpy(e_code, token, len); @@ -1128,7 +1158,7 @@ check_type: (s_lab != e_lab) || (s_code != e_code)) dump_line(); - CHECK_SIZE_LAB(1); + check_size_label(1); *e_lab++ = '#'; /* move whole line to 'label' buffer */ { int in_comment = 0; @@ -1142,7 +1172,7 @@ check_type: fill_buffer(); } while (*buf_ptr != '\n' || (in_comment && !had_eof)) { - CHECK_SIZE_LAB(2); + check_size_label(2); *e_lab = *buf_ptr++; if (buf_ptr >= buf_end) fill_buffer(); @@ -1210,7 +1240,7 @@ check_type: buf_end = sc_end; sc_end = NULL; } - CHECK_SIZE_LAB(1); + check_size_label(1); *e_lab = '\0'; /* null terminate line */ ps.pcase = false; } @@ -1343,13 +1373,13 @@
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon Mar 8 19:21:41 UTC 2021 Modified Files: src/usr.bin/indent: Makefile Log Message: indent: make it easy to compile indent in debug mode To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/usr.bin/indent/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/Makefile diff -u src/usr.bin/indent/Makefile:1.8 src/usr.bin/indent/Makefile:1.9 --- src/usr.bin/indent/Makefile:1.8 Sun Mar 7 10:56:18 2021 +++ src/usr.bin/indent/Makefile Mon Mar 8 19:21:41 2021 @@ -1,10 +1,11 @@ -# $NetBSD: Makefile,v 1.8 2021/03/07 10:56:18 rillig Exp $ +# $NetBSD: Makefile,v 1.9 2021/03/08 19:21:41 rillig Exp $ # from: @(#)Makefile 8.1 (Berkeley) 6/6/93 PROG= indent SRCS= indent.c io.c lexi.c parse.c pr_comment.c args.c COPTS.io.c += -Wno-error=format-nonliteral +CPPFLAGS+= ${DEBUG:D-Ddebug} LINTFLAGS+= -e
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon Mar 8 19:06:49 UTC 2021 Modified Files: src/usr.bin/indent: indent.c Log Message: indent: fix printing of uninitialized 'token' in debug output To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 src/usr.bin/indent/indent.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.32 src/usr.bin/indent/indent.c:1.33 --- src/usr.bin/indent/indent.c:1.32 Sun Mar 7 20:52:11 2021 +++ src/usr.bin/indent/indent.c Mon Mar 8 19:06:48 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.32 2021/03/07 20:52:11 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.33 2021/03/08 19:06:48 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.32 2021/03/07 20:52:11 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.33 2021/03/08 19:06:48 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -192,7 +192,7 @@ main(int argc, char **argv) l_token = tokenbuf + bufsize - 5; combuf[0] = codebuf[0] = labbuf[0] = ' '; /* set up code, label, and * comment buffers */ -combuf[1] = codebuf[1] = labbuf[1] = '\0'; +combuf[1] = codebuf[1] = labbuf[1] = tokenbuf[1] = '\0'; opt.else_if = 1; /* Default else-if special processing to on */ s_lab = e_lab = labbuf + 1; s_code = e_code = codebuf + 1;
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Mar 7 20:52:11 UTC 2021 Modified Files: src/usr.bin/indent: args.c indent.c Log Message: indent: sprinkle a few const No functional change. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/usr.bin/indent/args.c cvs rdiff -u -r1.31 -r1.32 src/usr.bin/indent/indent.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/args.c diff -u src/usr.bin/indent/args.c:1.16 src/usr.bin/indent/args.c:1.17 --- src/usr.bin/indent/args.c:1.16 Sun Mar 7 20:47:13 2021 +++ src/usr.bin/indent/args.c Sun Mar 7 20:52:11 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: args.c,v 1.16 2021/03/07 20:47:13 rillig Exp $ */ +/* $NetBSD: args.c,v 1.17 2021/03/07 20:52:11 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)args.c 8.1 ( #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: args.c,v 1.16 2021/03/07 20:47:13 rillig Exp $"); +__RCSID("$NetBSD: args.c,v 1.17 2021/03/07 20:52:11 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $"); #endif @@ -98,14 +98,13 @@ void add_typedefs_from_file(const char * * must be first. Also, while (most) booleans occur more than once, the last * default value is the one actually assigned. */ -struct pro { +const struct pro { const char *p_name; /* name, e.g. -bl, -cli */ int p_type; /* type (int, bool, special) */ int p_default; /* the default value (if int) */ int p_special; /* depends on type */ int*p_obj; /* the associated variable */ } pro[] = { - {"T", PRO_SPECIAL, 0, KEY, 0}, {"U", PRO_SPECIAL, 0, KEY_FILE, 0}, {"-version", PRO_SPECIAL, 0, VERSION, 0}, @@ -257,14 +256,13 @@ eqin(const char *s1, const char *s2) void set_defaults(void) { -struct pro *p; - /* * Because ps.case_indent is a float, we can't initialize it from the * table: */ -opt.case_indent = 0.0; /* -cli0.0 */ -for (p = pro; p->p_name; p++) +opt.case_indent = 0.0F; /* -cli0.0 */ + +for (const struct pro *p = pro; p->p_name; p++) if (p->p_type != PRO_SPECIAL) *p->p_obj = p->p_default; } @@ -272,7 +270,7 @@ set_defaults(void) void set_option(char *arg) { -struct pro *p; +const struct pro *p; const char *param_start; arg++; /* ignore leading "-" */ Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.31 src/usr.bin/indent/indent.c:1.32 --- src/usr.bin/indent/indent.c:1.31 Sun Mar 7 20:30:48 2021 +++ src/usr.bin/indent/indent.c Sun Mar 7 20:52:11 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.31 2021/03/07 20:30:48 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.32 2021/03/07 20:52:11 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.31 2021/03/07 20:30:48 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.32 2021/03/07 20:52:11 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -1237,11 +1237,10 @@ check_type: else ifdef_level--; } else { - struct directives { + static const struct directives { int size; const char *string; - } - recognized[] = { + } recognized[] = { {7, "include"}, {6, "define"}, {5, "undef"},
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Mar 7 20:47:13 UTC 2021 Modified Files: src/usr.bin/indent: args.c io.c lexi.c Log Message: indent: remove redundant parentheses around return value No functional change. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/usr.bin/indent/args.c cvs rdiff -u -r1.22 -r1.23 src/usr.bin/indent/io.c src/usr.bin/indent/lexi.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/args.c diff -u src/usr.bin/indent/args.c:1.15 src/usr.bin/indent/args.c:1.16 --- src/usr.bin/indent/args.c:1.15 Sun Mar 7 10:42:48 2021 +++ src/usr.bin/indent/args.c Sun Mar 7 20:47:13 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: args.c,v 1.15 2021/03/07 10:42:48 rillig Exp $ */ +/* $NetBSD: args.c,v 1.16 2021/03/07 20:47:13 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)args.c 8.1 ( #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: args.c,v 1.15 2021/03/07 10:42:48 rillig Exp $"); +__RCSID("$NetBSD: args.c,v 1.16 2021/03/07 20:47:13 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $"); #endif @@ -246,9 +246,9 @@ eqin(const char *s1, const char *s2) { while (*s1) { if (*s1++ != *s2++) - return (NULL); + return NULL; } -return (s2); +return s2; } /* Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.22 src/usr.bin/indent/io.c:1.23 --- src/usr.bin/indent/io.c:1.22 Sun Mar 7 10:42:48 2021 +++ src/usr.bin/indent/io.c Sun Mar 7 20:47:13 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.22 2021/03/07 10:42:48 rillig Exp $ */ +/* $NetBSD: io.c,v 1.23 2021/03/07 20:47:13 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.22 2021/03/07 10:42:48 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.23 2021/03/07 20:47:13 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -409,7 +409,7 @@ pad_output(int current, int target) int curr; /* internal column pointer */ if (current >= target) - return (current); /* line is already long enough */ + return current; /* line is already long enough */ curr = current; if (opt.use_tabs) { int tcur; @@ -422,7 +422,7 @@ pad_output(int current, int target) while (curr++ < target) putc(' ', output); /* pad with final blanks */ -return (target); +return target; } /* @@ -475,13 +475,13 @@ count_spaces_until(int cur, char *buffer break; } /* end of switch */ }/* end of for loop */ -return (cur); +return cur; } int count_spaces(int cur, char *buffer) { -return (count_spaces_until(cur, buffer, NULL)); +return count_spaces_until(cur, buffer, NULL); } void Index: src/usr.bin/indent/lexi.c diff -u src/usr.bin/indent/lexi.c:1.22 src/usr.bin/indent/lexi.c:1.23 --- src/usr.bin/indent/lexi.c:1.22 Sun Mar 7 20:40:18 2021 +++ src/usr.bin/indent/lexi.c Sun Mar 7 20:47:13 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lexi.c,v 1.22 2021/03/07 20:40:18 rillig Exp $ */ +/* $NetBSD: lexi.c,v 1.23 2021/03/07 20:47:13 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)lexi.c 8.1 ( #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: lexi.c,v 1.22 2021/03/07 20:40:18 rillig Exp $"); +__RCSID("$NetBSD: lexi.c,v 1.23 2021/03/07 20:47:13 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $"); #endif @@ -174,7 +174,7 @@ static char const *table[] = { static int strcmp_type(const void *e1, const void *e2) { -return (strcmp(e1, *(const char * const *)e2)); +return strcmp(e1, *(const char *const *)e2); } #ifdef debug
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Mar 7 20:40:18 UTC 2021 Modified Files: src/usr.bin/indent: indent_globs.h lexi.c Log Message: lint: move keyword 'continue' over to the other control flow keywords No functional change since neither rw_jump nor rw_inline_or_restrict is mentioned in any switch statement, and lint didn't find any other suspicious enum operations. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/usr.bin/indent/indent_globs.h cvs rdiff -u -r1.21 -r1.22 src/usr.bin/indent/lexi.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent_globs.h diff -u src/usr.bin/indent/indent_globs.h:1.14 src/usr.bin/indent/indent_globs.h:1.15 --- src/usr.bin/indent/indent_globs.h:1.14 Sun Mar 7 20:30:48 2021 +++ src/usr.bin/indent/indent_globs.h Sun Mar 7 20:40:18 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent_globs.h,v 1.14 2021/03/07 20:30:48 rillig Exp $ */ +/* $NetBSD: indent_globs.h,v 1.15 2021/03/07 20:40:18 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -231,10 +231,10 @@ enum rwcode { rw_do_or_else, rw_switch, rw_case_or_default, -rw_break_or_goto_or_return, +rw_jump, rw_storage_class, rw_typedef, -rw_continue_or_inline_or_restrict +rw_inline_or_restrict }; Index: src/usr.bin/indent/lexi.c diff -u src/usr.bin/indent/lexi.c:1.21 src/usr.bin/indent/lexi.c:1.22 --- src/usr.bin/indent/lexi.c:1.21 Sun Mar 7 20:30:48 2021 +++ src/usr.bin/indent/lexi.c Sun Mar 7 20:40:18 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lexi.c,v 1.21 2021/03/07 20:30:48 rillig Exp $ */ +/* $NetBSD: lexi.c,v 1.22 2021/03/07 20:40:18 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)lexi.c 8.1 ( #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: lexi.c,v 1.21 2021/03/07 20:30:48 rillig Exp $"); +__RCSID("$NetBSD: lexi.c,v 1.22 2021/03/07 20:40:18 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $"); #endif @@ -84,12 +84,12 @@ struct templ specials[] = {"_Imaginary", rw_type}, {"auto", rw_storage_class}, {"bool", rw_type}, -{"break", rw_break_or_goto_or_return}, +{"break", rw_jump}, {"case", rw_case_or_default}, {"char", rw_type}, {"complex", rw_type}, {"const", rw_type}, -{"continue", rw_continue_or_inline_or_restrict}, +{"continue", rw_jump}, {"default", rw_case_or_default}, {"do", rw_do_or_else}, {"double", rw_type}, @@ -99,16 +99,16 @@ struct templ specials[] = {"float", rw_type}, {"for", rw_for_or_if_or_while}, {"global", rw_type}, -{"goto", rw_break_or_goto_or_return}, +{"goto", rw_jump}, {"if", rw_for_or_if_or_while}, {"imaginary", rw_type}, -{"inline", rw_continue_or_inline_or_restrict}, +{"inline", rw_inline_or_restrict}, {"int", rw_type}, {"long", rw_type}, {"offsetof", rw_offsetof}, {"register", rw_storage_class}, -{"restrict", rw_continue_or_inline_or_restrict}, -{"return", rw_break_or_goto_or_return}, +{"restrict", rw_inline_or_restrict}, +{"return", rw_jump}, {"short", rw_type}, {"signed", rw_type}, {"sizeof", rw_sizeof},
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Mar 7 20:30:48 UTC 2021 Modified Files: src/usr.bin/indent: indent.c indent_codes.h indent_globs.h lexi.c Log Message: indent: use named constants for the different types of keywords This reduces the magic numbers in the code. Most of these had their designated constant name written in a nearby comment anyway. The one instance where arithmetic was performed on this new enum type (in indent.c) was a bit tricky to understand. The combination rw_continue_or_inline_or_restrict looks strange, the 'continue' should intuitively belong to the other control flow keywords in rw_break_or_goto_or_return. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.30 -r1.31 src/usr.bin/indent/indent.c cvs rdiff -u -r1.7 -r1.8 src/usr.bin/indent/indent_codes.h cvs rdiff -u -r1.13 -r1.14 src/usr.bin/indent/indent_globs.h cvs rdiff -u -r1.20 -r1.21 src/usr.bin/indent/lexi.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.30 src/usr.bin/indent/indent.c:1.31 --- src/usr.bin/indent/indent.c:1.30 Sun Mar 7 10:56:18 2021 +++ src/usr.bin/indent/indent.c Sun Mar 7 20:30:48 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.30 2021/03/07 10:56:18 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.31 2021/03/07 20:30:48 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.30 2021/03/07 10:56:18 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.31 2021/03/07 20:30:48 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -642,10 +642,8 @@ check_type: else if (ps.want_blank && ((ps.last_token != ident && ps.last_token != funcname) || opt.proc_calls_space || - /* offsetof (1) is never allowed a space; sizeof (2) gets - * one iff -bs; all other keywords (>2) always get a space - * before lparen */ - ps.keyword + opt.Bill_Shannon > 2)) + (ps.keyword == rw_sizeof ? opt.Bill_Shannon : + ps.keyword != rw_0 && ps.keyword != rw_offsetof))) *e_code++ = ' '; ps.want_blank = false; *e_code++ = token[0]; @@ -664,7 +662,7 @@ check_type: * initialization */ } /* parenthesized type following sizeof or offsetof is not a cast */ - if (ps.keyword == 1 || ps.keyword == 2) + if (ps.keyword == rw_offsetof || ps.keyword == rw_sizeof) ps.not_cast_mask |= 1 << ps.p_l_follow; break; Index: src/usr.bin/indent/indent_codes.h diff -u src/usr.bin/indent/indent_codes.h:1.7 src/usr.bin/indent/indent_codes.h:1.8 --- src/usr.bin/indent/indent_codes.h:1.7 Sun Mar 7 10:56:18 2021 +++ src/usr.bin/indent/indent_codes.h Sun Mar 7 20:30:48 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent_codes.h,v 1.7 2021/03/07 10:56:18 rillig Exp $ */ +/* $NetBSD: indent_codes.h,v 1.8 2021/03/07 20:30:48 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -43,12 +43,12 @@ typedef enum token_type { end_of_file, newline, -lparen, -rparen, -unary_op, -binary_op, -postop, -question, +lparen, /* '(' or '[' */ +rparen, /* ')' or ']' */ +unary_op, /* e.g. '+' or '&' */ +binary_op, /* e.g. '<<' or '+' or '&&' or '/=' */ +postop, /* trailing '++' or '--' */ +question, /* the '?' from a '?:' expression */ casestmt, colon, semicolon, Index: src/usr.bin/indent/indent_globs.h diff -u src/usr.bin/indent/indent_globs.h:1.13 src/usr.bin/indent/indent_globs.h:1.14 --- src/usr.bin/indent/indent_globs.h:1.13 Sun Mar 7 10:56:18 2021 +++ src/usr.bin/indent/indent_globs.h Sun Mar 7 20:30:48 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent_globs.h,v 1.13 2021/03/07 10:56:18 rillig Exp $ */ +/* $NetBSD: indent_globs.h,v 1.14 2021/03/07 20:30:48 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -221,6 +221,23 @@ extern struct options { * are printed */ } opt; +enum rwcode { +rw_0, +rw_offsetof, +rw_sizeof, +rw_struct_or_union_or_enum, +rw_type, +rw_for_or_if_or_while, +rw_do_or_else, +rw_switch, +rw_case_or_default, +rw_break_or_goto_or_return, +rw_storage_class, +rw_typedef, +rw_continue_or_inline_or_restrict +}; + + extern int found_err; extern int n_real_blanklines; extern int prefix_blankline_requested; @@ -308,7 +325,7 @@ extern struct parser_state { int want_blank; /* set to true when the following token should * be prefixed by a blank. (Said prefixing is * ignored in some cases.) */ -int keyword; /* the type of a keyword or 0 */ +enum rwcode keyword; /* the type of a keyword or 0 */ int
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Mar 7 11:32:06 UTC 2021 Modified Files: src/usr.bin/indent: indent.h lexi.c parse.c Log Message: indent: in debug mode, output detailed token information The main ingredient for understanding how indent works is the tokenizer and the 4 buffers in which the text is collected. Inspecting this debug log for the test comment-line-end makes it obvious why indent messes up code that contains '//' comments. The cause is that indent interprets '//' as an operator, just like '&&' or '||'. The sequence '/' is interpreted as a single operator as well, by the way. Since '//' is interpreted as an ordinary operator, any words following it are plain identifiers, usually several of them in a row, which is a syntax error. Depending on the context, the operator '//' is either a unary operator (no space around) or a binary operator (space around). This explains why the word 'line-end' is expanded to 'line - end'. No functional change outside of debug mode. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/usr.bin/indent/indent.h cvs rdiff -u -r1.19 -r1.20 src/usr.bin/indent/lexi.c cvs rdiff -u -r1.13 -r1.14 src/usr.bin/indent/parse.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.4 src/usr.bin/indent/indent.h:1.5 --- src/usr.bin/indent/indent.h:1.4 Sun Mar 7 10:56:18 2021 +++ src/usr.bin/indent/indent.h Sun Mar 7 11:32:05 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.4 2021/03/07 10:56:18 rillig Exp $ */ +/* $NetBSD: indent.h,v 1.5 2021/03/07 11:32:05 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -30,7 +30,7 @@ #if 0 #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.h,v 1.4 2021/03/07 10:56:18 rillig Exp $"); +__RCSID("$NetBSD: indent.h,v 1.5 2021/03/07 11:32:05 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 336333 2018-07-16 05:46:50Z pstef $"); #endif @@ -50,6 +50,9 @@ int compute_label_target(void); int count_spaces(int, char *); int count_spaces_until(int, char *, char *); void init_constant_tt(void); +#ifdef debug +const char *token_type_name(token_type); +#endif token_type lexi(struct parser_state *); void diag(int, const char *, ...) __printflike(2, 3); void dump_line(void); Index: src/usr.bin/indent/lexi.c diff -u src/usr.bin/indent/lexi.c:1.19 src/usr.bin/indent/lexi.c:1.20 --- src/usr.bin/indent/lexi.c:1.19 Sun Mar 7 10:56:18 2021 +++ src/usr.bin/indent/lexi.c Sun Mar 7 11:32:05 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lexi.c,v 1.19 2021/03/07 10:56:18 rillig Exp $ */ +/* $NetBSD: lexi.c,v 1.20 2021/03/07 11:32:05 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)lexi.c 8.1 ( #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: lexi.c,v 1.19 2021/03/07 10:56:18 rillig Exp $"); +__RCSID("$NetBSD: lexi.c,v 1.20 2021/03/07 11:32:05 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $"); #endif @@ -58,6 +58,7 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/ * of token scanned. */ +#include #include #include #include @@ -176,6 +177,62 @@ strcmp_type(const void *e1, const void * return (strcmp(e1, *(const char * const *)e2)); } +#ifdef debug +const char * +token_type_name(token_type tk) +{ +static const char *const name[] = { + "end_of_file", "newline", "lparen", "rparen", "unary_op", + "binary_op", "postop", "question", "casestmt", "colon", + "semicolon", "lbrace", "rbrace", "ident", "comma", + "comment", "swstmt", "preesc", "form_feed", "decl", + "sp_paren", "sp_nparen", "ifstmt", "whilestmt", "forstmt", + "stmt", "stmtl", "elselit", "dolit", "dohead", + "ifhead", "elsehead", "period", "strpfx", "storage", + "funcname", "type_def", "structure" +}; + +assert(0 <= tk && tk < sizeof name / sizeof name[0]); + +return name[tk]; +} + +static void +print_buf(const char *name, const char *s, const char *e) +{ +if (s == e) + return; + +printf(" %s \"", name); +for (const char *p = s; p < e; p++) { + if (isprint((unsigned char)*p) && *p != '\\' && *p != '"') + printf("%c", *p); + else if (*p == '\n') + printf("\\n"); + else if (*p == '\t') + printf("\\t"); + else + printf("\\x%02x", *p); +} +printf("\""); +} + +static token_type +lexi_end(token_type code) +{ +printf("in line %d, lexi returns '%s'", line_no, token_type_name(code)); +print_buf("token", s_token, e_token); +print_buf("label", s_lab, e_lab); +print_buf("code", s_code, e_code); +print_buf("comment", s_com, e_com); +printf("\n"); + +return code; +} +#else +# define lexi_end(tk) (tk) +#endif + token_type lexi(struct parser_state *state) { @@ -250,7 +307,7 @@ lexi(struct parser_state
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Mar 7 10:56:18 UTC 2021 Modified Files: src/usr.bin/indent: Makefile indent.c indent.h indent_codes.h indent_globs.h lexi.c parse.c Log Message: indent: for the token types, use enum instead of #define This makes it easier to step through the code in a debugger. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/usr.bin/indent/Makefile cvs rdiff -u -r1.29 -r1.30 src/usr.bin/indent/indent.c cvs rdiff -u -r1.3 -r1.4 src/usr.bin/indent/indent.h cvs rdiff -u -r1.6 -r1.7 src/usr.bin/indent/indent_codes.h cvs rdiff -u -r1.12 -r1.13 src/usr.bin/indent/indent_globs.h \ src/usr.bin/indent/parse.c cvs rdiff -u -r1.18 -r1.19 src/usr.bin/indent/lexi.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/Makefile diff -u src/usr.bin/indent/Makefile:1.7 src/usr.bin/indent/Makefile:1.8 --- src/usr.bin/indent/Makefile:1.7 Thu Apr 4 15:22:13 2019 +++ src/usr.bin/indent/Makefile Sun Mar 7 10:56:18 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.7 2019/04/04 15:22:13 kamil Exp $ +# $NetBSD: Makefile,v 1.8 2021/03/07 10:56:18 rillig Exp $ # from: @(#)Makefile 8.1 (Berkeley) 6/6/93 PROG= indent @@ -6,4 +6,6 @@ SRCS= indent.c io.c lexi.c parse.c pr_co COPTS.io.c += -Wno-error=format-nonliteral +LINTFLAGS+= -e + .include Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.29 src/usr.bin/indent/indent.c:1.30 --- src/usr.bin/indent/indent.c:1.29 Sun Mar 7 10:42:48 2021 +++ src/usr.bin/indent/indent.c Sun Mar 7 10:56:18 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.29 2021/03/07 10:42:48 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.30 2021/03/07 10:56:18 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.29 2021/03/07 10:42:48 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.30 2021/03/07 10:56:18 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -143,8 +143,8 @@ main(int argc, char **argv) int dec_ind; /* current indentation for declarations */ int di_stack[20]; /* a stack of structure indentation levels */ int force_nl; /* when true, code must be broken */ -int hd_type = 0; /* used to store type of stmt for if (...), - * for (...), etc */ +token_type hd_type = end_of_file; /* used to store type of stmt + * for if (...), for (...), etc */ int i; /* local loop counter */ int scase; /* set to true when we see a case, so we will * know what to do with the following colon */ @@ -155,7 +155,7 @@ main(int argc, char **argv) * construct */ const char *t_ptr; /* used for copying tokens */ int tabs_to_var; /* true if using tabs to indent to var name */ -int type_code; /* the type of token, returned by lexi */ +token_type type_code; /* returned by lexi */ int last_else = 0; /* true iff last keyword was an else */ const char *profile_name = NULL; @@ -505,7 +505,7 @@ main(int argc, char **argv) * We must make this check, just in case there was an unexpected * EOF. */ - if (type_code != 0) { + if (type_code != end_of_file) { /* * The only intended purpose of calling lexi() below is to * categorize the next token in order to decide whether to @@ -546,7 +546,7 @@ main(int argc, char **argv) } /* end of while (search_brace) */ last_else = 0; check_type: - if (type_code == 0) { /* we got eof */ + if (type_code == end_of_file) { /* we got eof */ if (s_lab != e_lab || s_code != e_code || s_com != e_com) /* must dump end of line */ dump_line(); @@ -1274,6 +1274,9 @@ check_type: case comment: /* we have gotten a / followed by * this is a biggie */ pr_comment(); break; + + default: + break; } /* end of big switch stmt */ *e_code = '\0'; /* make sure code section is null terminated */ Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.3 src/usr.bin/indent/indent.h:1.4 --- src/usr.bin/indent/indent.h:1.3 Sun Mar 7 10:42:48 2021 +++ src/usr.bin/indent/indent.h Sun Mar 7 10:56:18 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.3 2021/03/07 10:42:48 rillig Exp $ */ +/* $NetBSD: indent.h,v 1.4 2021/03/07 10:56:18 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -30,7 +30,7 @@ #if 0 #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.h,v 1.3 2021/03/07 10:42:48 rillig Exp $"); +__RCSID("$NetBSD: indent.h,v 1.4 2021/03/07 10:56:18 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 336333 2018-07-16 05:46:50Z pstef $"); #endif
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Mar 7 10:42:49 UTC 2021 Modified Files: src/usr.bin/indent: args.c indent.c indent.h io.c lexi.c parse.c pr_comment.c Log Message: indent: use all headers in all files This is a prerequisite for converting the token types to an enum instead of a preprocessor define, since the return type of lexi will become token_type. Having the enum will make debugging easier. There was a single naming collision, which forced the variable in scan_profile to be renamed. All other token names are used nowhere else. No change to the resulting binary. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/usr.bin/indent/args.c cvs rdiff -u -r1.28 -r1.29 src/usr.bin/indent/indent.c cvs rdiff -u -r1.2 -r1.3 src/usr.bin/indent/indent.h cvs rdiff -u -r1.21 -r1.22 src/usr.bin/indent/io.c cvs rdiff -u -r1.17 -r1.18 src/usr.bin/indent/lexi.c cvs rdiff -u -r1.11 -r1.12 src/usr.bin/indent/parse.c \ src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/args.c diff -u src/usr.bin/indent/args.c:1.14 src/usr.bin/indent/args.c:1.15 --- src/usr.bin/indent/args.c:1.14 Thu Apr 4 15:22:13 2019 +++ src/usr.bin/indent/args.c Sun Mar 7 10:42:48 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: args.c,v 1.14 2019/04/04 15:22:13 kamil Exp $ */ +/* $NetBSD: args.c,v 1.15 2021/03/07 10:42:48 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)args.c 8.1 ( #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: args.c,v 1.14 2019/04/04 15:22:13 kamil Exp $"); +__RCSID("$NetBSD: args.c,v 1.15 2021/03/07 10:42:48 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $"); #endif @@ -63,7 +63,7 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/ #include #include #include -#include "indent_globs.h" + #include "indent.h" #define INDENT_VERSION "2.0" @@ -209,22 +209,22 @@ set_profile(const char *profile_name) static void scan_profile(FILE *f) { -int comment, i; +int comment_index, i; char *p; charbuf[BUFSIZ]; while (1) { p = buf; - comment = 0; + comment_index = 0; while ((i = getc(f)) != EOF) { - if (i == '*' && !comment && p > buf && p[-1] == '/') { - comment = p - buf; + if (i == '*' && !comment_index && p > buf && p[-1] == '/') { + comment_index = p - buf; *p++ = i; - } else if (i == '/' && comment && p > buf && p[-1] == '*') { - p = buf + comment - 1; - comment = 0; + } else if (i == '/' && comment_index && p > buf && p[-1] == '*') { + p = buf + comment_index - 1; + comment_index = 0; } else if (isspace((unsigned char)i)) { - if (p > buf && !comment) + if (p > buf && !comment_index) break; } else { *p++ = i; Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.28 src/usr.bin/indent/indent.c:1.29 --- src/usr.bin/indent/indent.c:1.28 Sat Mar 6 20:30:06 2021 +++ src/usr.bin/indent/indent.c Sun Mar 7 10:42:48 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.28 2021/03/06 20:30:06 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.29 2021/03/07 10:42:48 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.28 2021/03/06 20:30:06 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.29 2021/03/07 10:42:48 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -65,8 +65,7 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/ #include #include #include -#include "indent_globs.h" -#include "indent_codes.h" + #include "indent.h" struct options opt; Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.2 src/usr.bin/indent/indent.h:1.3 --- src/usr.bin/indent/indent.h:1.2 Sat Oct 19 15:44:31 2019 +++ src/usr.bin/indent/indent.h Sun Mar 7 10:42:48 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.2 2019/10/19 15:44:31 christos Exp $ */ +/* $NetBSD: indent.h,v 1.3 2021/03/07 10:42:48 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -30,12 +30,15 @@ #if 0 #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.h,v 1.2 2019/10/19 15:44:31 christos Exp $"); +__RCSID("$NetBSD: indent.h,v 1.3 2021/03/07 10:42:48 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 336333 2018-07-16 05:46:50Z pstef $"); #endif #endif +#include "indent_codes.h" +#include "indent_globs.h" + #ifndef nitems #define nitems(array) (sizeof (array) / sizeof (array[0])) #endif Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.21 src/usr.bin/indent/io.c:1.22 --- src/usr.bin/indent/io.c:1.21
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 6 21:08:08 UTC 2021 Modified Files: src/usr.bin/indent: indent.1 Log Message: indent.1: sort options alphabetically To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/usr.bin/indent/indent.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.1 diff -u src/usr.bin/indent/indent.1:1.28 src/usr.bin/indent/indent.1:1.29 --- src/usr.bin/indent/indent.1:1.28 Thu Apr 4 22:02:06 2019 +++ src/usr.bin/indent/indent.1 Sat Mar 6 21:08:08 2021 @@ -1,4 +1,4 @@ -.\" $NetBSD: indent.1,v 1.28 2019/04/04 22:02:06 wiz Exp $ +.\" $NetBSD: indent.1,v 1.29 2021/03/06 21:08:08 rillig Exp $ .\" .\" Copyright (c) 1980, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -32,7 +32,7 @@ .\" @(#)indent.1 8.1 (Berkeley) 7/1/93 .\" $FreeBSD: head/usr.bin/indent/indent.1 334944 2018-06-11 05:35:57Z pstef $ .\" -.Dd June 11, 2018 +.Dd March 6, 2021 .Dt INDENT 1 .Os .Sh NAME @@ -62,8 +62,8 @@ .Op Fl \ Ns Ar n .Op Fl dj | Fl ndj .Bk -words -.Op Fl ei | Fl nei .Op Fl eei | Fl neei +.Op Fl ei | Fl nei .Ek .Bk -words .Op Fl fbs | Fl nfbs @@ -292,6 +292,16 @@ left justifies declarations. indents declarations the same as code. The default is .Fl ndj . +.It Fl eei , neei +Enables (disables) extra indentation on continuation lines of +the expression part of +.Ic if +and +.Ic while +statements. +These continuation lines will be indented one extra level. +The default is +.Fl neei . .It Fl \ , nei Enables (disables) special .Ic else-if @@ -305,16 +315,6 @@ will have the same indentation as the pr statement. The default is .Fl ei . -.It Fl eei , neei -Enables (disables) extra indentation on continuation lines of -the expression part of -.Ic if -and -.Ic while -statements. -These continuation lines will be indented one extra level. -The default is -.Fl neei . .It Fl fbs , nfbs Enables (disables) splitting the function declaration and opening brace across two lines.
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Mar 6 20:30:07 UTC 2021 Modified Files: src/usr.bin/indent: indent.c io.c parse.c Log Message: indent: fix space-tab alignment in indent's own code These parts are not fixed automatically by indent since they are in box comments. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.27 -r1.28 src/usr.bin/indent/indent.c cvs rdiff -u -r1.20 -r1.21 src/usr.bin/indent/io.c cvs rdiff -u -r1.10 -r1.11 src/usr.bin/indent/parse.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.27 src/usr.bin/indent/indent.c:1.28 --- src/usr.bin/indent/indent.c:1.27 Thu Apr 23 00:17:34 2020 +++ src/usr.bin/indent/indent.c Sat Mar 6 20:30:06 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.27 2020/04/23 00:17:34 joerg Exp $ */ +/* $NetBSD: indent.c,v 1.28 2021/03/06 20:30:06 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.27 2020/04/23 00:17:34 joerg Exp $"); +__RCSID("$NetBSD: indent.c,v 1.28 2021/03/06 20:30:06 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -228,7 +228,7 @@ main(int argc, char **argv) simple_backup_suffix = envval; /*--*\ -| COMMAND LINE SCAN | +| COMMAND LINE SCAN | \*--*/ #ifdef undef Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.20 src/usr.bin/indent/io.c:1.21 --- src/usr.bin/indent/io.c:1.20 Sat Oct 19 15:44:31 2019 +++ src/usr.bin/indent/io.c Sat Mar 6 20:30:06 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.20 2019/10/19 15:44:31 christos Exp $ */ +/* $NetBSD: io.c,v 1.21 2021/03/06 20:30:06 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.20 2019/10/19 15:44:31 christos Exp $"); +__RCSID("$NetBSD: io.c,v 1.21 2021/03/06 20:30:06 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -277,7 +277,7 @@ compute_label_target(void) * * FUNCTION: Reads one block of input into input_buffer * - * HISTORY: initial coding November 1976 D A Willcox of CAC 1/7/77 A + * HISTORY: initial coding November 1976 D A Willcox of CAC 1/7/77 A * Willcox of CAC Added check for switch back to partly full input * buffer from temporary buffer * @@ -395,7 +395,7 @@ fill_buffer(void) * * CALLED BY: dump_line * - * HISTORY: initial coding November 1976 D A Willcox of CAC + * HISTORY: initial coding November 1976 D A Willcox of CAC * */ static int @@ -442,7 +442,7 @@ pad_output(int current, int target) * RETURNS: Integer value of position after printing "buffer" starting in column * "current". * - * HISTORY: initial coding November 1976 D A Willcox of CAC + * HISTORY: initial coding November 1976 D A Willcox of CAC * */ int Index: src/usr.bin/indent/parse.c diff -u src/usr.bin/indent/parse.c:1.10 src/usr.bin/indent/parse.c:1.11 --- src/usr.bin/indent/parse.c:1.10 Sat Oct 19 15:44:31 2019 +++ src/usr.bin/indent/parse.c Sat Mar 6 20:30:06 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.10 2019/10/19 15:44:31 christos Exp $ */ +/* $NetBSD: parse.c,v 1.11 2021/03/06 20:30:06 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -265,7 +265,7 @@ parse(int tk) /* tk: the code for the co * * CALLED BY: parse * - * HISTORY: initial coding November 1976 D A Willcox of CAC + * HISTORY: initial coding November 1976 D A Willcox of CAC * */ /*--*\
CVS commit: src/usr.bin/indent
Module Name:src Committed By: joerg Date: Thu Apr 23 00:17:34 UTC 2020 Modified Files: src/usr.bin/indent: indent.c indent_globs.h Log Message: Avoid common symbol declarations To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/usr.bin/indent/indent.c cvs rdiff -u -r1.11 -r1.12 src/usr.bin/indent/indent_globs.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.26 src/usr.bin/indent/indent.c:1.27 --- src/usr.bin/indent/indent.c:1.26 Sat Oct 19 15:44:31 2019 +++ src/usr.bin/indent/indent.c Thu Apr 23 00:17:34 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.26 2019/10/19 15:44:31 christos Exp $ */ +/* $NetBSD: indent.c,v 1.27 2020/04/23 00:17:34 joerg Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.26 2019/10/19 15:44:31 christos Exp $"); +__RCSID("$NetBSD: indent.c,v 1.27 2020/04/23 00:17:34 joerg Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -69,6 +69,60 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/ #include "indent_codes.h" #include "indent.h" +struct options opt; +struct parser_state ps; + +char *labbuf; +char *s_lab; +char *e_lab; +char *l_lab; + +char *codebuf; +char *s_code; +char *e_code; +char *l_code; + +char *combuf; +char *s_com; +char *e_com; +char *l_com; + +char *tokenbuf; +char *s_token; +char *e_token; +char *l_token; + +char *in_buffer; +char *in_buffer_limit; +char *buf_ptr; +char *buf_end; + +charsc_buf[sc_size]; +char *save_com; +char *sc_end; + +char *bp_save; +char *be_save; + +int found_err; +int n_real_blanklines; +int prefix_blankline_requested; +int postfix_blankline_requested; +int break_comma; +float case_ind; +int code_lines; +int had_eof; +int line_no; +int inhibit_formatting; +int suppress_blanklines; + +int ifdef_level; +struct parser_state state_stack[5]; +struct parser_state match_state[5]; + +FILE *input; +FILE *output; + static void bakcopy(void); static void indent_declaration(int, int); Index: src/usr.bin/indent/indent_globs.h diff -u src/usr.bin/indent/indent_globs.h:1.11 src/usr.bin/indent/indent_globs.h:1.12 --- src/usr.bin/indent/indent_globs.h:1.11 Thu Apr 4 15:22:13 2019 +++ src/usr.bin/indent/indent_globs.h Thu Apr 23 00:17:34 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: indent_globs.h,v 1.11 2019/04/04 15:22:13 kamil Exp $ */ +/* $NetBSD: indent_globs.h,v 1.12 2020/04/23 00:17:34 joerg Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -51,8 +51,8 @@ #define true 1 -FILE *input; /* the fid for the input file */ -FILE *output; /* the output file */ +extern FILE *input; /* the fid for the input file */ +extern FILE *output; /* the output file */ #define CHECK_SIZE_CODE(desired_size) \ if (e_code + (desired_size) >= l_code) { \ @@ -106,44 +106,44 @@ FILE *output; /* the output file s_token = tokenbuf + 1; \ } -char *labbuf; /* buffer for label */ -char *s_lab; /* start ... */ -char *e_lab; /* .. and end of stored label */ -char *l_lab; /* limit of label buffer */ - -char *codebuf; /* buffer for code section */ -char *s_code; /* start ... */ -char *e_code; /* .. and end of stored code */ -char *l_code; /* limit of code section */ - -char *combuf; /* buffer for comments */ -char *s_com; /* start ... */ -char *e_com; /* ... and end of stored comments */ -char *l_com; /* limit of comment buffer */ +extern char *labbuf; /* buffer for label */ +extern char *s_lab; /* start ... */ +extern char *e_lab; /* .. and end of stored label */ +extern char *l_lab; /* limit of label buffer */ + +extern char *codebuf; /* buffer for code section */ +extern char *s_code; /* start ... */ +extern char *e_code; /* .. and end of stored code */ +extern char *l_code; /* limit of code section */ + +extern char *combuf; /* buffer for comments */ +extern char *s_com; /* start ... */ +extern char *e_com; /* ... and end of stored comments */ +extern char *l_com; /* limit of comment buffer */ #define token s_token -char *tokenbuf; /* the last token scanned */ -char *s_token; -char *e_token; -char *l_token; - -char *in_buffer; /* input buffer */ -char *in_buffer_limit; /* the end of the input buffer */ -char *buf_ptr; /* ptr to next character to be taken
CVS commit: src/usr.bin/indent
Module Name:src Committed By: wiz Date: Thu Apr 4 22:02:06 UTC 2019 Modified Files: src/usr.bin/indent: indent.1 Log Message: New sentence, new line. Whitespace fixes. To generate a diff of this commit: cvs rdiff -u -r1.27 -r1.28 src/usr.bin/indent/indent.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.1 diff -u src/usr.bin/indent/indent.1:1.27 src/usr.bin/indent/indent.1:1.28 --- src/usr.bin/indent/indent.1:1.27 Thu Apr 4 15:22:13 2019 +++ src/usr.bin/indent/indent.1 Thu Apr 4 22:02:06 2019 @@ -1,4 +1,4 @@ -.\" $NetBSD: indent.1,v 1.27 2019/04/04 15:22:13 kamil Exp $ +.\" $NetBSD: indent.1,v 1.28 2019/04/04 22:02:06 wiz Exp $ .\" .\" Copyright (c) 1980, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -124,7 +124,8 @@ is named .Sq Pa /blah/blah/file , the backup file is named .Sq Pa file.BAK -by default. The extension used for the backup file may be overridden using the +by default. +The extension used for the backup file may be overridden using the .Ev SIMPLE_BACKUP_SUFFIX environment variable. .Pp @@ -161,7 +162,7 @@ except that it only applies to the first in a procedure (just after the first `{') and it causes a blank line to be generated even if there are no declarations. The default is -.Fl nbadp. +.Fl nbadp . .It Fl bap , nbap If .Fl bap @@ -204,7 +205,7 @@ if (...) { .It Fl bs , nbs Whether a blank should always be inserted after sizeof. The default is -.Fl nbs. +.Fl nbs . .It Fl c Ns Ar n The column in which comments on code start. The default is 33. @@ -355,7 +356,7 @@ The default is 78. .It Fl lc Ns Ar n Maximum length of an output line in a block comment. The default is 0, which means to limit block comment lines in accordance with -.Fl l. +.Fl l . .It Fl \ Ns Ar n Specifies the indentation, in character positions, of local variable names @@ -515,7 +516,6 @@ defaults. Switches on the command line, though, always override profile switches. The switches should be separated by spaces, tabs or newlines. -.Pp .Ss Comments .Sq Em Box .Em comments .
CVS commit: src/usr.bin/indent
Module Name:src Committed By: dholland Date: Sun Jun 5 18:35:32 UTC 2016 Modified Files: src/usr.bin/indent: lexi.c Log Message: Fix CSRG-era typo: typedef, not typdef. Spotted by Piotr Stefaniak. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/usr.bin/indent/lexi.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/lexi.c diff -u src/usr.bin/indent/lexi.c:1.13 src/usr.bin/indent/lexi.c:1.14 --- src/usr.bin/indent/lexi.c:1.13 Sun Apr 12 11:09:49 2009 +++ src/usr.bin/indent/lexi.c Sun Jun 5 18:35:32 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: lexi.c,v 1.13 2009/04/12 11:09:49 lukem Exp $ */ +/* $NetBSD: lexi.c,v 1.14 2016/06/05 18:35:32 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -68,7 +68,7 @@ #if 0 static char sccsid[] = "@(#)lexi.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lexi.c,v 1.13 2009/04/12 11:09:49 lukem Exp $"); +__RCSID("$NetBSD: lexi.c,v 1.14 2016/06/05 18:35:32 dholland Exp $"); #endif #endif/* not lint */ @@ -108,7 +108,7 @@ struct templ specials[1000] = {"double", 4}, {"long", 4}, {"short", 4}, - {"typdef", 4}, + {"typedef", 4}, {"unsigned", 4}, {"register", 4}, {"static", 4},
CVS commit: src/usr.bin/indent
Module Name:src Committed By: wiz Date: Thu Feb 25 14:55:56 UTC 2016 Modified Files: src/usr.bin/indent: indent.1 Log Message: Remove trailing whitespace. To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/usr.bin/indent/indent.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.1 diff -u src/usr.bin/indent/indent.1:1.25 src/usr.bin/indent/indent.1:1.26 --- src/usr.bin/indent/indent.1:1.25 Wed Feb 24 17:38:15 2016 +++ src/usr.bin/indent/indent.1 Thu Feb 25 14:55:56 2016 @@ -1,4 +1,4 @@ -.\" $NetBSD: indent.1,v 1.25 2016/02/24 17:38:15 ginsbach Exp $ +.\" $NetBSD: indent.1,v 1.26 2016/02/25 14:55:56 wiz Exp $ .\" .\" Copyright (c) 1980, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -141,7 +141,7 @@ checks to make sure it is different from If no .Ar input-file is specified -input is read from stdin and the formatted file is written to stdout. +input is read from stdin and the formatted file is written to stdout. .Pp The options listed below control the formatting style imposed by .Nm .
CVS commit: src/usr.bin/indent
Module Name:src Committed By: ginsbach Date: Thu Feb 25 13:23:27 UTC 2016 Modified Files: src/usr.bin/indent: indent.c io.c pr_comment.c Log Message: Fix obvious contraction spelling mistakes by adding missing apostrophes. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/usr.bin/indent/indent.c cvs rdiff -u -r1.16 -r1.17 src/usr.bin/indent/io.c cvs rdiff -u -r1.9 -r1.10 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.21 src/usr.bin/indent/indent.c:1.22 --- src/usr.bin/indent/indent.c:1.21 Mon Feb 22 22:01:48 2016 +++ src/usr.bin/indent/indent.c Thu Feb 25 13:23:27 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.21 2016/02/22 22:01:48 ginsbach Exp $ */ +/* $NetBSD: indent.c,v 1.22 2016/02/25 13:23:27 ginsbach Exp $ */ /* * Copyright (c) 1980, 1993 @@ -75,7 +75,7 @@ __COPYRIGHT("@(#) Copyright (c) 1985 Sun #if 0 static char sccsid[] = "@(#)indent.c 5.17 (Berkeley) 6/7/93"; #else -__RCSID("$NetBSD: indent.c,v 1.21 2016/02/22 22:01:48 ginsbach Exp $"); +__RCSID("$NetBSD: indent.c,v 1.22 2016/02/25 13:23:27 ginsbach Exp $"); #endif #endif/* not lint */ @@ -260,7 +260,7 @@ main(int argc, char **argv) } } if (ps.com_ind <= 1) - ps.com_ind = 2; /* dont put normal comments before column 2 */ + ps.com_ind = 2; /* don't put normal comments before column 2 */ if (troff) { if (bodyf.font[0] == 0) parsefont(, "R"); @@ -355,7 +355,7 @@ main(int argc, char **argv) case lbrace: /* this is a brace that starts the * compound stmt */ if (sc_end == 0) { /* ignore buffering if a - * comment wasnt stored + * comment wasn't stored * up */ ps.search_brace = false; goto check_type; @@ -420,7 +420,7 @@ main(int argc, char **argv) force_nl = false; if (sc_end == 0) { /* ignore buffering if - * comment wasnt saved + * comment wasn't saved * up */ ps.search_brace = false; goto check_type; @@ -503,7 +503,7 @@ check_type: diag(0, "Line broken"); flushed_nl = false; dump_line(); -ps.want_blank = false; /* dont insert blank at +ps.want_blank = false; /* don't insert blank at * line start */ force_nl = false; } @@ -623,7 +623,7 @@ check_type: ps.last_u_d = true; /* inform lexi that a * following operator is * unary */ -ps.in_stmt = false; /* dont use stmt +ps.in_stmt = false; /* don't use stmt * continuation * indentation */ @@ -785,8 +785,8 @@ check_type: ps.in_decl = (ps.dec_nest > 0); /* if we were in a first * level structure - * declaration, we arent - * any more */ + * declaration, we + * aren't any more */ if ((!sp_sw || hd_type != forstmt) && ps.p_l_follow > 0) { @@ -801,8 +801,8 @@ check_type: * while, etc. with unbalanced * parens */ sp_sw = false; - parse(hd_type); /* dont lose the if, or - * whatever */ + parse(hd_type); /* don't lose the if, + * or whatever */ } } *e_code++ = ';'; @@ -819,7 +819,7 @@ check_type: break; case lbrace: /* got a '{' */ - ps.in_stmt = false; /* dont indent the {} */ + ps.in_stmt = false; /* don't indent the {} */ if (!ps.block_init) force_nl = true; /* force other stuff on * same line as '{' onto @@ -856,7 +856,7 @@ check_type: } } if (s_code == e_code) -ps.ind_stmt = false; /* dont put extra +ps.ind_stmt = false; /* don't put extra * indentation on line * with '{' */ if (ps.in_decl && ps.in_or_st) { /* this is either a @@ -865,9 +865,9 @@ check_type: di_stack[ps.dec_nest++] = dec_ind; /* ? dec_ind = 0; */ } else { -ps.decl_on_line = false; /* we cant be in the +ps.decl_on_line = false; /* we can't be in the * middle of a - * declaration, so dont + * declaration, so don't * do special * indentation of * comments */ @@ -1088,7 +1088,7 @@ check_type: case period: /* treat a period kind of like a binary * operation */ *e_code++ = '.'; /* move the period into line */ - ps.want_blank = false; /* dont put a blank after a + ps.want_blank = false; /* don't put a blank after a * period */ break; @@ -1256,7 +1256,7 @@ check_type: * line here */ flushed_nl = false; dump_line(); -ps.want_blank = false; /* dont insert blank at +ps.want_blank = false; /* don't insert blank at * line start */ force_nl = false; } Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.16 src/usr.bin/indent/io.c:1.17 --- src/usr.bin/indent/io.c:1.16 Mon Feb 22 19:04:18 2016 +++ src/usr.bin/indent/io.c Thu Feb 25 13:23:27 2016 @@ -1,4 +1,4 @@ -/*
CVS commit: src/usr.bin/indent
Module Name:src Committed By: ginsbach Date: Wed Feb 24 17:38:15 UTC 2016 Modified Files: src/usr.bin/indent: indent.1 Log Message: Remove double space before [.,:] in macro arguments. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/usr.bin/indent/indent.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.1 diff -u src/usr.bin/indent/indent.1:1.24 src/usr.bin/indent/indent.1:1.25 --- src/usr.bin/indent/indent.1:1.24 Wed Feb 24 17:13:48 2016 +++ src/usr.bin/indent/indent.1 Wed Feb 24 17:38:15 2016 @@ -1,4 +1,4 @@ -.\" $NetBSD: indent.1,v 1.24 2016/02/24 17:13:48 ginsbach Exp $ +.\" $NetBSD: indent.1,v 1.25 2016/02/24 17:38:15 ginsbach Exp $ .\" .\" Copyright (c) 1980, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -115,9 +115,9 @@ according to the switches. The switches which can be specified are described below. They may appear before or after the file names. .Pp -.Sy NOTE : +.Sy NOTE : If you only specify an -.Ar input-file , +.Ar input-file , the formatting is done `in-place', that is, the formatted file is written back into .Ar input-file @@ -136,7 +136,7 @@ If is specified, .Nm checks to make sure it is different from -.Ar input-file . +.Ar input-file . .Pp If no .Ar input-file @@ -144,7 +144,7 @@ is specified input is read from stdin and the formatted file is written to stdout. .Pp The options listed below control the formatting style imposed by -.Nm . +.Nm . .Bl -tag -width Op .It Fl bacc , nbacc If @@ -154,26 +154,26 @@ compilation block. For example, in front of every #ifdef and after every #endif. Other blank lines surrounding such blocks will be swallowed. Default: -.Fl nbacc . +.Fl nbacc . .It Fl bad , nbad If .Fl bad is specified, a blank line is forced after every block of declarations. Default: -.Fl nbad . +.Fl nbad . .It Fl bap , nbap If .Fl bap is specified, a blank line is forced after every procedure body. Default: -.Fl nbap . +.Fl nbap . .It Fl bbb , nbbb If .Fl bbb is specified, a blank line is forced before every block comment. Default: -.Fl nbbb . +.Fl nbbb . .It Fl \ , nbc If .Fl \ @@ -181,7 +181,7 @@ is specified, then a newline is forced a .Fl nbc turns off this option. Default: -.Fl \ . +.Fl \ . .It Fl \ , \ Specifying .Fl \ @@ -207,11 +207,11 @@ If is specified, a blank is forced after .Ic sizeof . Default: -.Fl nbs . +.Fl nbs . .It Fl c Ns Ar n The column in which comments on code start. Default: -.Fl c33 . +.Fl c33 . .It Fl cd Ns Ar n The column in which comments on declarations start. The default @@ -233,15 +233,15 @@ Rather than like this: This only affects block comments, not comments to the right of code. Default: -.Fl cdb . +.Fl cdb . .It Fl ce , nce Enables (disables) forcing `else's to cuddle up to the immediately preceding `}'. Default: -.Fl \ . +.Fl \ . .It Fl \ Ns Ar n Sets the continuation indent to be -.Ar n . +.Ar n . Continuation lines will be indented that far from the beginning of the first line of the statement. @@ -251,7 +251,7 @@ indicate the nesting, unless is in effect. .Fl \ defaults to the same value as -.Fl i . +.Fl i . .It Fl cli Ns Ar n Causes case labels to be indented .Ar n @@ -261,7 +261,7 @@ statement. .Fl cli0.5 causes case labels to be indented half a tab stop. Default: -.Fl cli0 . +.Fl cli0 . .It Fl d Ns Ar n Controls the placement of comments which are not to the right of code. For example, @@ -276,14 +276,14 @@ indentation below. Specifies the indentation, in character positions, from a declaration keyword to the following identifier. Default: -.Fl di16 . +.Fl di16 . .It Fl dj , ndj .Fl \ left justifies declarations. .Fl ndj indents declarations the same as code. Default: -.Fl ndj . +.Fl ndj . .It Fl \ , nei Enables (disables) special .Ic else-if @@ -296,7 +296,7 @@ will have the same indentation as the pr .Ic \ statement. Default: -.Fl ei . +.Fl ei . .It Fl eei , neei Enables (disables) extra indentation on continuation lines of the expression part of @@ -306,7 +306,7 @@ and statements. These continuation lines will be indented one extra level. Default: -.Fl neei . +.Fl neei . .It Fl fc1 , nfc1 Enables (disables) the formatting of comments that start in column 1. Often, comments whose leading `/' is in column 1 have been carefully @@ -315,7 +315,7 @@ In such cases, .Fl nfc1 should be used. Default: -.Fl fc1 . +.Fl fc1 . .It Fl i Ns Ar n The number of spaces for one indentation level. Default: @@ -324,11 +324,11 @@ Default: Enables (disables) the indentation of parameter declarations from the left margin. Default: -.Fl \ . +.Fl \ . .It Fl l Ns Ar n Maximum length of an output line. Default: -.Fl l78 . +.Fl l78 . .It Fl \ , nlp Lines up code surrounded by parenthesis in continuation lines. If a line has a
CVS commit: src/usr.bin/indent
Module Name:src Committed By: ginsbach Date: Wed Feb 24 17:13:48 UTC 2016 Modified Files: src/usr.bin/indent: indent.1 Log Message: Add the [n]ei and [n]eei options to the synopsis; already documented in description. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/usr.bin/indent/indent.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.1 diff -u src/usr.bin/indent/indent.1:1.23 src/usr.bin/indent/indent.1:1.24 --- src/usr.bin/indent/indent.1:1.23 Thu Sep 4 04:06:07 2014 +++ src/usr.bin/indent/indent.1 Wed Feb 24 17:13:48 2016 @@ -1,4 +1,4 @@ -.\" $NetBSD: indent.1,v 1.23 2014/09/04 04:06:07 mrg Exp $ +.\" $NetBSD: indent.1,v 1.24 2016/02/24 17:13:48 ginsbach Exp $ .\" .\" Copyright (c) 1980, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -61,7 +61,7 @@ .\" .\" from: @(#)indent.1 8.1 (Berkeley) 7/1/93 .\" -.Dd September 2, 2014 +.Dd February 24, 2016 .Dt INDENT 1 .Os .Sh NAME @@ -85,6 +85,8 @@ .Op Fl cli Ns Ar n .Op Fl d Ns Ar n .Op Fl \ Ns Ar n +.Op Fl ei | Fl nei +.Op Fl eei | Fl neei .Op Fl fc1 | Fl nfc1 .Op Fl i Ns Ar n .Op Fl \ | Fl nip
CVS commit: src/usr.bin/indent
Module Name:src Committed By: ginsbach Date: Mon Feb 22 22:01:48 UTC 2016 Modified Files: src/usr.bin/indent: indent.c Log Message: Use warnx(3). To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/usr.bin/indent/indent.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.20 src/usr.bin/indent/indent.c:1.21 --- src/usr.bin/indent/indent.c:1.20 Mon Feb 22 19:04:18 2016 +++ src/usr.bin/indent/indent.c Mon Feb 22 22:01:48 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.20 2016/02/22 19:04:18 ginsbach Exp $ */ +/* $NetBSD: indent.c,v 1.21 2016/02/22 22:01:48 ginsbach Exp $ */ /* * Copyright (c) 1980, 1993 @@ -75,7 +75,7 @@ __COPYRIGHT("@(#) Copyright (c) 1985 Sun #if 0 static char sccsid[] = "@(#)indent.c 5.17 (Berkeley) 6/7/93"; #else -__RCSID("$NetBSD: indent.c,v 1.20 2016/02/22 19:04:18 ginsbach Exp $"); +__RCSID("$NetBSD: indent.c,v 1.21 2016/02/22 22:01:48 ginsbach Exp $"); #endif #endif/* not lint */ @@ -134,7 +134,7 @@ main(int argc, char **argv) \*---*/ if (!setlocale(LC_ALL, "")) - fprintf(stderr, "indent: can't set locale.\n"); + warnx("can't set locale."); hd_type = 0; ps.p_stack[0] = stmt; /* this is the parser's stack */
CVS commit: src/usr.bin/indent
Module Name:src Committed By: ginsbach Date: Mon Feb 22 21:20:29 UTC 2016 Modified Files: src/usr.bin/indent: args.c Log Message: Stray '\n' in errx(3) format. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/usr.bin/indent/args.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/args.c diff -u src/usr.bin/indent/args.c:1.12 src/usr.bin/indent/args.c:1.13 --- src/usr.bin/indent/args.c:1.12 Mon Feb 22 19:04:18 2016 +++ src/usr.bin/indent/args.c Mon Feb 22 21:20:29 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: args.c,v 1.12 2016/02/22 19:04:18 ginsbach Exp $ */ +/* $NetBSD: args.c,v 1.13 2016/02/22 21:20:29 ginsbach Exp $ */ /* * Copyright (c) 1980, 1993 @@ -68,7 +68,7 @@ #if 0 static char sccsid[] = "@(#)args.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: args.c,v 1.12 2016/02/22 19:04:18 ginsbach Exp $"); +__RCSID("$NetBSD: args.c,v 1.13 2016/02/22 21:20:29 ginsbach Exp $"); #endif #endif/* not lint */ @@ -432,7 +432,7 @@ found: break; default: - errx(1, "set_option: internal error: p_special %d\n", + errx(1, "set_option: internal error: p_special %d", p->p_special); } break;
CVS commit: src/usr.bin/indent
Module Name:src Committed By: ginsbach Date: Mon Feb 22 19:04:18 UTC 2016 Modified Files: src/usr.bin/indent: args.c indent.c io.c Log Message: Use errx(3). To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/usr.bin/indent/args.c cvs rdiff -u -r1.19 -r1.20 src/usr.bin/indent/indent.c cvs rdiff -u -r1.15 -r1.16 src/usr.bin/indent/io.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/args.c diff -u src/usr.bin/indent/args.c:1.11 src/usr.bin/indent/args.c:1.12 --- src/usr.bin/indent/args.c:1.11 Thu Sep 4 04:06:07 2014 +++ src/usr.bin/indent/args.c Mon Feb 22 19:04:18 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: args.c,v 1.11 2014/09/04 04:06:07 mrg Exp $ */ +/* $NetBSD: args.c,v 1.12 2016/02/22 19:04:18 ginsbach Exp $ */ /* * Copyright (c) 1980, 1993 @@ -68,7 +68,7 @@ #if 0 static char sccsid[] = "@(#)args.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: args.c,v 1.11 2014/09/04 04:06:07 mrg Exp $"); +__RCSID("$NetBSD: args.c,v 1.12 2016/02/22 19:04:18 ginsbach Exp $"); #endif #endif/* not lint */ @@ -78,6 +78,7 @@ __RCSID("$NetBSD: args.c,v 1.11 2014/09/ */ #include +#include #include #include #include @@ -396,8 +397,7 @@ set_option(char *arg) for (p = pro; p->p_name; p++) if (*p->p_name == *arg && eqin(p->p_name, arg)) goto found; - fprintf(stderr, "indent: %s: unknown parameter \"%s\"\n", option_source, arg - 1); - exit(1); + errx(1, "%s: unknown parameter \"%s\"", option_source, arg - 1); found: switch (p->p_type) { @@ -432,9 +432,8 @@ found: break; default: - fprintf(stderr, "\ -indent: set_option: internal error: p_special %d\n", p->p_special); - exit(1); + errx(1, "set_option: internal error: p_special %d\n", + p->p_special); } break; @@ -448,9 +447,8 @@ indent: set_option: internal error: p_sp case PRO_INT: if (!isdigit((unsigned char)*param_start)) { need_param: - fprintf(stderr, "indent: %s: ``%s'' requires a parameter\n", - option_source, arg - 1); - exit(1); + errx(1, "%s: ``%s'' requires a parameter", + option_source, arg - 1); } *p->p_obj = atoi(param_start); break; @@ -460,8 +458,6 @@ indent: set_option: internal error: p_sp break; default: - fprintf(stderr, "indent: set_option: internal error: p_type %d\n", - p->p_type); - exit(1); + errx(1, "set_option: internal error: p_type %d", p->p_type); } } Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.19 src/usr.bin/indent/indent.c:1.20 --- src/usr.bin/indent/indent.c:1.19 Thu Sep 4 04:06:07 2014 +++ src/usr.bin/indent/indent.c Mon Feb 22 19:04:18 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.19 2014/09/04 04:06:07 mrg Exp $ */ +/* $NetBSD: indent.c,v 1.20 2016/02/22 19:04:18 ginsbach Exp $ */ /* * Copyright (c) 1980, 1993 @@ -75,7 +75,7 @@ __COPYRIGHT("@(#) Copyright (c) 1985 Sun #if 0 static char sccsid[] = "@(#)indent.c 5.17 (Berkeley) 6/7/93"; #else -__RCSID("$NetBSD: indent.c,v 1.19 2014/09/04 04:06:07 mrg Exp $"); +__RCSID("$NetBSD: indent.c,v 1.20 2016/02/22 19:04:18 ginsbach Exp $"); #endif #endif/* not lint */ @@ -236,8 +236,7 @@ main(int argc, char **argv) * output file */ if (strcmp(in_name, out_name) == 0) { /* attempt to overwrite * the file */ - fprintf(stderr, "indent: input and output files must be different\n"); - exit(1); + errx(1, "input and output files must be different"); } output = fopen(out_name, "w"); if (output == 0) /* check for create @@ -245,8 +244,7 @@ main(int argc, char **argv) err(1, "%s", out_name); continue; } - fprintf(stderr, "indent: unknown parameter: %s\n", argv[i]); - exit(1); + errx(1, "unknown parameter: %s", argv[i]); } else set_option(argv[i]); } /* end of for */ Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.15 src/usr.bin/indent/io.c:1.16 --- src/usr.bin/indent/io.c:1.15 Thu Sep 4 04:06:07 2014 +++ src/usr.bin/indent/io.c Mon Feb 22 19:04:18 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.15 2014/09/04 04:06:07 mrg Exp $ */ +/* $NetBSD: io.c,v 1.16 2016/02/22 19:04:18 ginsbach Exp $ */ /* * Copyright (c) 1980, 1993 @@ -68,7 +68,7 @@ #if 0 static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: io.c,v 1.15 2014/09/04 04:06:07 mrg Exp $"); +__RCSID("$NetBSD: io.c,v 1.16 2016/02/22 19:04:18 ginsbach Exp $"); #endif #endif/* not lint */ @@ -668,8 +668,7 @@ parsefont(struct fstate *f, const char * if (*s == '-') sizedelta--; else { - fprintf(stderr, "indent: bad font specification: %s\n", s0); - exit(1); + errx(1, "bad font specification: %s", s0); } s++; }
CVS commit: src/usr.bin/indent
Module Name:src Committed By: mrg Date: Thu Sep 4 04:06:07 UTC 2014 Modified Files: src/usr.bin/indent: args.c indent.1 indent.c indent_globs.h io.c Log Message: port the -ut / -nut options from freebsd. -ut (default) enables tabs in output, the -nut uses spaces. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/usr.bin/indent/args.c cvs rdiff -u -r1.22 -r1.23 src/usr.bin/indent/indent.1 cvs rdiff -u -r1.18 -r1.19 src/usr.bin/indent/indent.c cvs rdiff -u -r1.9 -r1.10 src/usr.bin/indent/indent_globs.h cvs rdiff -u -r1.14 -r1.15 src/usr.bin/indent/io.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/args.c diff -u src/usr.bin/indent/args.c:1.10 src/usr.bin/indent/args.c:1.11 --- src/usr.bin/indent/args.c:1.10 Sun Apr 12 11:09:49 2009 +++ src/usr.bin/indent/args.c Thu Sep 4 04:06:07 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: args.c,v 1.10 2009/04/12 11:09:49 lukem Exp $ */ +/* $NetBSD: args.c,v 1.11 2014/09/04 04:06:07 mrg Exp $ */ /* * Copyright (c) 1980, 1993 @@ -68,7 +68,7 @@ #if 0 static char sccsid[] = @(#)args.c 8.1 (Berkeley) 6/6/93; #else -__RCSID($NetBSD: args.c,v 1.10 2009/04/12 11:09:49 lukem Exp $); +__RCSID($NetBSD: args.c,v 1.11 2014/09/04 04:06:07 mrg Exp $); #endif #endif/* not lint */ @@ -274,6 +274,9 @@ struct pro { nsc, PRO_BOOL, true, OFF, star_comment_cont }, { + nut, PRO_BOOL, true, OFF, use_tabs + }, + { nsob, PRO_BOOL, false, OFF, swallow_optional_blanklines }, { @@ -301,6 +304,9 @@ struct pro { troff, PRO_BOOL, false, ON, troff }, { + ut, PRO_BOOL, true, ON, use_tabs + }, + { v, PRO_BOOL, false, ON, verbose }, /* whew! */ Index: src/usr.bin/indent/indent.1 diff -u src/usr.bin/indent/indent.1:1.22 src/usr.bin/indent/indent.1:1.23 --- src/usr.bin/indent/indent.1:1.22 Sat Oct 13 14:18:17 2012 +++ src/usr.bin/indent/indent.1 Thu Sep 4 04:06:07 2014 @@ -1,4 +1,4 @@ -.\ $NetBSD: indent.1,v 1.22 2012/10/13 14:18:17 njoly Exp $ +.\ $NetBSD: indent.1,v 1.23 2014/09/04 04:06:07 mrg Exp $ .\ .\ Copyright (c) 1980, 1990, 1993 .\ The Regents of the University of California. All rights reserved. @@ -61,7 +61,7 @@ .\ .\ from: @(#)indent.1 8.1 (Berkeley) 7/1/93 .\ -.Dd July 1, 1993 +.Dd September 2, 2014 .Dt INDENT 1 .Os .Sh NAME @@ -98,6 +98,7 @@ .Op Fl sob | Fl nsob .Op Fl \st .Op Fl troff +.Op Fl ut | Fl nut .Op Fl v | Fl \nv .Sh DESCRIPTION .Nm @@ -135,6 +136,11 @@ is specified, checks to make sure it is different from .Ar input-file . .Pp +If no +.Ar input-file +is specified +input is read from stdin and the formatted file is written to stdout. +.Pp The options listed below control the formatting style imposed by .Nm . .Bl -tag -width Op @@ -417,6 +423,11 @@ listing in much the same spirit as .Xr vgrind 1 . If the output file is not specified, the default is standard output, rather than formatting in place. +.It Fl ut , nut +Enables (disables) the use of tab characters in the output. +Tabs are assumed to be aligned on columns divisible by 8. +The default is +.Fl ut . .It Fl v , \nv .Fl v turns on `verbose' mode; Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.18 src/usr.bin/indent/indent.c:1.19 --- src/usr.bin/indent/indent.c:1.18 Sun Apr 12 11:09:49 2009 +++ src/usr.bin/indent/indent.c Thu Sep 4 04:06:07 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.18 2009/04/12 11:09:49 lukem Exp $ */ +/* $NetBSD: indent.c,v 1.19 2014/09/04 04:06:07 mrg Exp $ */ /* * Copyright (c) 1980, 1993 @@ -75,7 +75,7 @@ __COPYRIGHT(@(#) Copyright (c) 1985 Sun #if 0 static char sccsid[] = @(#)indent.c 5.17 (Berkeley) 6/7/93; #else -__RCSID($NetBSD: indent.c,v 1.18 2009/04/12 11:09:49 lukem Exp $); +__RCSID($NetBSD: indent.c,v 1.19 2014/09/04 04:06:07 mrg Exp $); #endif #endif/* not lint */ @@ -123,6 +123,7 @@ main(int argc, char **argv) * without the matching : in a c?s:s * construct */ const char *t_ptr; /* used for copying tokens */ + int tabs_to_var = 0; /* true if using tabs to indent to var name */ int type_code; /* the type of token, returned by lexi */ int last_else = 0; /* true iff last keyword was an else */ @@ -998,6 +999,7 @@ check_type: * : i); */ dec_ind = ps.decl_indent 0 ? ps.decl_indent : i; + tabs_to_var = (use_tabs ? ps.decl_indent 0 : 0); goto copy_id; case ident: /* got an identifier or constant */ @@ -1012,11 +1014,44 @@ check_type: sprintf(e_code, \n.De %dp+\200p\n, dec_ind * 7); ps.dumped_decl_indent = 1; e_code += strlen(e_code); - } else - while ((e_code - s_code) dec_ind) { + CHECK_SIZE_CODE; + } else { + int cur_dec_ind; + int pos, startpos; + + /* + * in order to get the tab math right for + * indentations that are not multiples of 8 we + * need to modify both startpos and
CVS commit: src/usr.bin/indent
Module Name:src Committed By: wiz Date: Wed Jan 12 06:17:52 UTC 2011 Modified Files: src/usr.bin/indent: indent.1 Log Message: Spell out parenthesis. From Ryo HAYASAKA in PR 44372. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/usr.bin/indent/indent.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.1 diff -u src/usr.bin/indent/indent.1:1.19 src/usr.bin/indent/indent.1:1.20 --- src/usr.bin/indent/indent.1:1.19 Tue Mar 24 00:17:25 2009 +++ src/usr.bin/indent/indent.1 Wed Jan 12 06:17:52 2011 @@ -1,4 +1,4 @@ -.\ $NetBSD: indent.1,v 1.19 2009/03/24 00:17:25 joerg Exp $ +.\ $NetBSD: indent.1,v 1.20 2011/01/12 06:17:52 wiz Exp $ .\ .\ Copyright (c) 1980, 1990, 1993 .\ The Regents of the University of California. All rights reserved. @@ -356,9 +356,9 @@ .Fl l78 . .It Fl \lp , nlp Lines up code surrounded by parenthesis in continuation lines. -If a line has a left paren which is not closed on that line, then +If a line has a left parenthesis which is not closed on that line, then continuation lines will be lined up to start at the character -position just after the left paren. +position just after the left parenthesis. For example, here is how a piece of continued code looks with .Fl nlp in effect:
CVS commit: src/usr.bin/indent
Module Name:src Committed By: joerg Date: Tue Mar 24 00:17:25 UTC 2009 Modified Files: src/usr.bin/indent: indent.1 Log Message: Remove physical markup. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/usr.bin/indent/indent.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/indent/indent.1 diff -u src/usr.bin/indent/indent.1:1.18 src/usr.bin/indent/indent.1:1.19 --- src/usr.bin/indent/indent.1:1.18 Sun Sep 11 23:17:34 2005 +++ src/usr.bin/indent/indent.1 Tue Mar 24 00:17:25 2009 @@ -1,4 +1,4 @@ -.\ $NetBSD: indent.1,v 1.18 2005/09/11 23:17:34 wiz Exp $ +.\ $NetBSD: indent.1,v 1.19 2009/03/24 00:17:25 joerg Exp $ .\ .\ Copyright (c) 1980, 1990, 1993 .\ The Regents of the University of California. All rights reserved. @@ -210,7 +210,6 @@ Specifying .Fl \bl lines up compound statements like this: -.ne 4 .Bd -literal -offset indent if (...) { @@ -221,7 +220,6 @@ Specifying .Fl \br (the default) makes them look like this: -.ne 3 .Bd -literal -offset indent if (...) { code @@ -246,7 +244,6 @@ .It Fl cdb , ncdb Enables (disables) the placement of comment delimiters on blank lines. With this option enabled, comments look like this: -.ne 3 .Bd -literal -offset indent /* * this is a comment @@ -365,13 +362,11 @@ For example, here is how a piece of continued code looks with .Fl nlp in effect: -.ne 2 .Bd -literal -offset indent p1 = first_procedure(second_procedure(p2, p3), \ \ third_procedure(p4,p5)); .Ed .Pp -.ne 5 With .Fl lp in effect (the default) the code looks somewhat clearer: @@ -380,7 +375,6 @@ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,p5)); .Ed .Pp -.ne 5 Inserting two more newlines we get: .Bd -literal -offset indent p1\ =\ first_procedure(second_procedure(p2, @@ -558,7 +552,6 @@ has even more switches than .Xr ls 1 . .Pp -.ne 5 A common mistake that often causes grief is typing: .Pp .Dl indent *.c