History log of /freebsd-current/usr.bin/indent/pr_comment.c
Revision Date Author Comments
# 5e3934b1 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

usr.bin: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# bdcbfde3 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

usr.bin: Remove ancient SCCS tags.

Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 7e53aaed 10-Jun-2018 Piotr Pawel Stefaniak <pstef@FreeBSD.org>

indent(1): group global option variables into an options structure

It's clearer now when a variable represents a toggable command line option.

Many options were stored in the parser's state structure, so fix also that.


# 9de29bfb 03-Jun-2018 Piotr Pawel Stefaniak <pstef@FreeBSD.org>

indent(1): improve CHECK_SIZE_ macros

Rewrite the macros so that they take a parameter. Consumers use it to signal
how much room in the buffer they need; this lets them do that once when
required space is known instead of doing the check once every loop step.

Also take the parameter value into consideration when resizing the buffer;
the requested space may be larger than the constant 400 bytes that the
previous version used - now it's the sum of those two values.

On the consumer side, don't copy strings byte by byte - use memcpy().

Deduplicate code that copied base 2, base 8 and base 16 literals.

Don't advance the e_token pointer once the token has been copied into
s_token. This allows easy calculation of the token's length.


# 1479f36d 03-Jun-2018 Piotr Pawel Stefaniak <pstef@FreeBSD.org>

indent(1): remove troff output support

The troff output in indent was invented at Sun and the online documentation
for some post-SunOS operating system includes this:
The usual way to get a troffed listing is with the command
indent -troff program.c | troff -mindent

The indent manual page in FreeBSD 1.0 already lacks that information and
troff -mindent complains about not being able to find the macro file.
It seems that the file did exist on SunOS and was supposed to be imported
into 4.3BSD together with the feature, but that has never happened.

Removal of troff output support simplifies a lot of indent's code.

vgrind(1) seems to be a promising replacement.


# 3c51c3cf 03-Jun-2018 Piotr Pawel Stefaniak <pstef@FreeBSD.org>

indent(1): improve handling of boxed comments indentation

The trick is to copy everything from the start of the line into the buffer
that stores newlines and comments until indent finds a brace or an else.
pr_comment() will use that information to calculate the original indentation
of the boxed comment.

This requires storing two pieces of information: the real start of the
buffer (sc_buf) and the start of the comment (save_com).


# df57947f 18-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

spdx: initial adoption of licensing ID tags.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.

Initially, only tag files that use BSD 4-Clause "Original" license.

RelNotes: yes
Differential Revision: https://reviews.freebsd.org/D13133


# fbdbd284 25-Jul-2017 Piotr Pawel Stefaniak <pstef@FreeBSD.org>

indent(1): add option -tsn for setting tab size.


# 3e2c1447 23-Jul-2017 Piotr Pawel Stefaniak <pstef@FreeBSD.org>

indent(1): better alignment of comments on code.

If aligning the beginning of a comment to -cn would mean no space between
code and the comment, align it to the next tab stop.


# f30beab3 23-Jul-2017 Piotr Pawel Stefaniak <pstef@FreeBSD.org>

indent(1): don't produce unnecessary blank lines.

Don't force a blank line between an opening brace and a block comment -- not
even if -bbb (blank lines before block comments) is on.


# 909f007f 30-Nov-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

indent(1): Don't unnecessarily add a blank before a comment ends.

pr_comment() did avoid adding surplus space character when a comment
contained it at the end. Now it's also paying attention to tabs.

Taken from: Piotr Stefaniak


# 458051a5 30-Nov-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

indent(1): Avoid out of bound access of array in_buffer

Work-around a somewhat complex interaction within the code. From
Piotr's commit [1]:

When pr_comment() calls dump_line() for the first line of a multiline
comment, it doesn't include any indentation - it starts with the "/*".
This is consistent for both boxed and not boxed comments. Where the logic
diverges is in how it treats the rest of the lines of the comment. For box
comments indent assumes that it must not change anything, so lines are
dumped as they were, including the indentation where it exists. For the
rest of comments, it will first remove the indentation to store plain text
of the comment and then add it again where indent thinks it's appropriate
-- this is part of comment re-indenting process.

For continuations of multi-line comments, the code that handles comments
in dump_line() will use pad_output() to create indentation from the
beginning of the line (what indent calls the first column) and then write
string pointed by s_com afterwards. But if it's a box comment, the string
will include original indentation, unless it's the first line of the
comment. This is why tab characters from s_com have to be considered when
calculating how much padding is needed and the "while (*com_st == '\t')
com_st++, target += 8;" does that.

In dump_line(), /target/ is initially set to ps.com_col, so it always
assumes that indentation needs to be produced in this function, regardless
of which line of a box comment it is. But for the first line of a box
comment it is not true, so pr_comment() signals it by setting
ps.n_comment_delta, the negative comment delta, to a negative number which
is then added to /target/ in dump_line() on all lines except the first
one, so that the function produces adequate indentation in this special
case.

The bug was in how that negative offset was calculated: pr_comment() used
count_spaces() on in_buffer, which pr_comment() expected to contain
non-null terminated sequence of characters, originating from whatever
originally was on the left side of the comment. Understanding that
count_spaces() requires a string, pr_comment() temporarily set buf_ptr[-2]
to 0 in hope that it would nul-terminate the right thing in in_buffer and
calling count_spaces() would be safe and do the expected thing. This was
false whenever buf_ptr would point into save_com, an entirely different
char array than in_buffer.

The short-term fix is to recognize whether buf_ptr points into in_buffer
or save_com.

Reference:
[1]
https://github.com/pstef/freebsd_indent/commit/ea486a2aa3b056b146bdfbb8e94843159750f200

Taken from: Piotr Stefaniak


# 6daffe6e 27-Nov-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

indent(1): fix regression introduced in r303596.

Multi-line comments are always block comments in KNF. Restore properly,
handling the case when a long one-liner gets wrapped and becomes a
multi-line comment.

Obtained from: Piotr Stefaniak


# 70a3049e 01-Aug-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

indent(1): Use a dash in the license headers.

Use of the canonical dash avoids indent(1) from reformatting the
license headers.


# 69e66b43 31-Jul-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

indent(1): Untangle the connection between pr_comment.c and io.c.

It's pr_comment.c that should decide whether to put a "star comment
continuation" or not. This duplicates code a bit, but it simplifies
pr_comment() at the same time since pr_comment() no longer has to "signal"
whether a star continuation is needed or not.

This change requires indent(1) to not wrap comment lines that lack a blank
character, but I think it's for the better if you look at cases when that
happens (mostly long URIs and file system paths, which arguably shouldn't
be wrapped).

It also fixes two bugs:

1. Cases where asterisk is a part of the comment's content (like in "*we*
are the champions") and happens to appear at the beginning of the line,
misleading dump_line() into thinking that this is part of the star comment
continuation, leading to misalignment.

2. Cases where blank starred lines had three too many characters on the
line when wrapped.

Reference:
https://github.com/pstef/freebsd_indent/commit/3b41ee78aafafc7c3e662b794835e3253218dbb3

Differential Revision: https://reviews.freebsd.org/D6966 (Partial)
Submitted by: Piotr Stefaniak


# 8ad92a65 31-Jul-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

indent(1): Fix wrapping of some lines in comments.

After a blank line was printed (to separate paragraphs in comments), the
next line was sometimes wrapped to the column at which the previous
non-empty line ended. The fix is to reset the last blank pointer (last_bl)
on newline.

References:
https://github.com/pstef/freebsd_indent/commit/345663c07af0758fd10433bde14722dfd900f85c

Differential Revision: https://reviews.freebsd.org/D6966 (Partial)
Submitted by: Piotr Stefaniak


# 54d57555 31-Jul-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

indent(1): Simplify pr_comment().

Modify count_spaces() to take a third parameter "end" that will make the
function return when the end is reached. This lets the caller pass a
pointer to non nul-terminated sequence of characters. Rename
count_spaces() to count_spaces_until() and reinstate count_spaces(), this
time based on count_spaces_until().

Use count_spaces_until() to recalculate current column when going through
a comment just before the fragment which decides if current line of the
comment should be wrapped. This move simplifies this code by eliminating
the need for keeping the column counter up to date every time e_com is
advanced and also reduces spread of code that has to know how many columns
a tab will produce.

Deduplicate code that decided if a comment needs a blank line at the top.

References:
https://github.com/pstef/freebsd_indent/commit/d9fa3b481532a448095f8ddd14fd0797ce59230c
https://github.com/pstef/freebsd_indent/commit/27185b4b336b0e2108a3d96aee6df80cced94192

Differential Revision: https://reviews.freebsd.org/D6966 (Partial)
Submitted by: Piotr Stefaniak


# 267c7470 31-Jul-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

indent(1): Remove dead code relating to unix-style comments.

The original indent(1) described unix-style comments as similar to box
comments, except the first non-blank character on each line is lined up
with the '*' of the "/*" which appears on a line by itself.

The code has been turned off for ages and -sc/-nsc make it even
less relevant.

Reference:
https://github.com/pstef/freebsd_indent/commit/89c5fe2c56742d96975bb3ea6b99f28baf9d82f6

Differential Revision: https://reviews.freebsd.org/D6966 (Partial)

Submitted by: Piotr Stefaniak


# c917a54b 29-Jul-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

indent(1): Use NULL instead of zero for pointers.


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# d0054952 15-Jun-2003 Philippe Charnier <charnier@FreeBSD.org>

err() on allocation failure. WARNS=9 compliant
use #if 0, #ifndef lint, #endif /* not lint */, #endif ordering
when a message is provided, use errx() instead of err().


# e026a48c 29-Jun-2002 David E. O'Brien <obrien@FreeBSD.org>

Consistently use FBSDID


# 90af6a72 24-Jun-2002 Juli Mallett <jmallett@FreeBSD.org>

Remove deprecated register qualifier.


# 7916863d 28-Oct-2001 Jens Schweikhardt <schweikh@FreeBSD.org>

Make this compile cleanly when warnings are enabled:
- ANSIfy function declarations
- braces around initializers structs within structs
- add parens in complicated expressions
- disambiguate dangling elses
- no more implicit int
- make functions static where possible
- use prototypes
- don't use varargs hack for diag()

Requested by: joerg
MFC after: 2 weeks


# 175f26d6 24-Dec-2000 David E. O'Brien <obrien@FreeBSD.org>

Don't abuse the SCCS `@(#)' for RCS.

Requested by: bde


# 9e50dd77 09-Dec-2000 David E. O'Brien <obrien@FreeBSD.org>

Add or fix FreeBSD IDs.


# a5e1cac0 09-Dec-2000 David E. O'Brien <obrien@FreeBSD.org>

"Implement -[n]fcb (formatting of block comments) and attempt to implement
no-space=after-sizeof (not optional) and no-space-after 'struct foo *'
(not optional). Without these, indent unKNFizes even more perfectly KNF code."

Submitted by: bde


# 9b50d902 26-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite Usr.bin Sources