Module Name: src Committed By: rillig Date: Thu Nov 4 20:31:05 UTC 2021
Modified Files: src/usr.bin/indent: indent.c Log Message: indent: split process_comment_in_code into separate functions No functional change. To generate a diff of this commit: cvs rdiff -u -r1.206 -r1.207 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.206 src/usr.bin/indent/indent.c:1.207 --- src/usr.bin/indent/indent.c:1.206 Thu Nov 4 17:12:12 2021 +++ src/usr.bin/indent/indent.c Thu Nov 4 20:31:04 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.206 2021/11/04 17:12:12 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.207 2021/11/04 20:31:04 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include <sys/cdefs.h> #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.206 2021/11/04 17:12:12 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.207 2021/11/04 20:31:04 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -685,31 +685,31 @@ process_end_of_file(void) } static void -process_comment_in_code(lexer_symbol lsym, bool *force_nl) +maybe_break_line(lexer_symbol lsym, bool *force_nl) { - if (*force_nl && - lsym != lsym_semicolon && - (lsym != lsym_lbrace || !opt.brace_same_line)) { - - /* we should force a broken line here */ - if (opt.verbose) - diag(0, "Line broken"); - dump_line(); - ps.want_blank = false; /* don't insert blank at line start */ - *force_nl = false; - } + if (!*force_nl) + return; + if (lsym == lsym_semicolon) + return; + else if (lsym == lsym_lbrace && opt.brace_same_line) + return; - /* add an extra level of indentation; turned off again by a ';' or '}' */ - ps.in_stmt = true; + if (opt.verbose) + diag(0, "Line broken"); + dump_line(); + ps.want_blank = false; + *force_nl = false; +} - if (com.s != com.e) { /* a comment embedded in a line */ - buf_add_char(&code, ' '); - buf_add_buf(&code, &com); - buf_add_char(&code, ' '); - buf_terminate(&code); - buf_reset(&com); - ps.want_blank = false; - } +static void +move_com_to_code(void) +{ + buf_add_char(&code, ' '); + buf_add_buf(&code, &com); + buf_add_char(&code, ' '); + buf_terminate(&code); + buf_reset(&com); + ps.want_blank = false; } static void @@ -1402,8 +1402,13 @@ main_loop(void) if (lsym == lsym_newline || lsym == lsym_form_feed || lsym == lsym_preprocessing) force_nl = false; - else if (lsym != lsym_comment) - process_comment_in_code(lsym, &force_nl); + else if (lsym != lsym_comment) { + maybe_break_line(lsym, &force_nl); + ps.in_stmt = true; /* add an extra level of indentation; turned + * off again by a ';' or '}' */ + if (com.s != com.e) + move_com_to_code(); + } buf_reserve(&code, 3); /* space for 2 characters plus '\0' */