History log of /freebsd-current/usr.bin/indent/io.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/


# 02bde5cf 06-Apr-2020 Kyle Evans <kevans@FreeBSD.org>

indent: fix the -fno-common build

Spread the globals far and wide, hopefully to the files that make the most
sense.

-fno-common will become the default in GCC10/LLVM11.

MFC after: 3 days


# 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.


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

indent(1): new option -lpl

With -lpl, code surrounded by parentheses in continuation lines is lined up
even if it would extend past the right margin.

With -nlpl (the default), such a line that would extend past the right
margin is moved left to keep it within the margin, if that does not require
placing it to the left of the prevailing indentation level.

These switches have no effect if -nlp is selected.

Submitted by: Tom Lane


# 50a29760 03-Jun-2018 Piotr Pawel Stefaniak <pstef@FreeBSD.org>

indent(1): revert introduction of -lpl

That was committed with the wrong message. Will be re-added.


# 971e1c47 03-Jun-2018 Piotr Pawel Stefaniak <pstef@FreeBSD.org>

indent(1): new option -lpl (always line up to parenthesis)

With -lp, if a line has an opening paren which is not closed on that line,
then continuation lines will be lined up to start at the character position
just after the opening paren.

Submitted by: Tom Lane


# 9963ad6f 03-Jun-2018 Piotr Pawel Stefaniak <pstef@FreeBSD.org>

indent(1): ignore null characters from input


# 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.


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

indent(1): limit character classification functions' input to unsigned char


# 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.


# 0bae80a3 02-Dec-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

indent(1): Avoid out-of-bound accesses of arrays.

ps.paren_indents:
When ps.paren_level was 0, this was accessing paren_indents[-1].

in_buffer:
This fragment checks if "*/" was read, but there's no guarantee that there
is more than one byte in the array (actually, this happens frequently for
the "{" in things like "int main(void) {").

Submitted by: 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


# bf140447 23-Aug-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

indent(1): have the memset invocation somewhat more canonical.

While correct, the previous invocation was somewhat more error prone.

Pointed out by: delphij, bde


# 38359266 23-Aug-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

indent(1): remove dead assignments.

Taken from: Piotr Sephaniak


# 16c2e360 22-Aug-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

indent(1): add some comments to quiet down Coverity.

Hopefully adding comments should help explain the code to both static
checkers and humans.

CID: 976543, 976544, 976545
Obtained from: Piotr Stephaniak


# 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.


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

indent(1): replace function call to bzero with memset.

Reference:
https://github.com/pstef/freebsd_indent/commit/7422f42f80099c69d34833d7106035dc09230235

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


# 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


# 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


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

indent(1): Yet more style issues.

strchr(3) returns a pointer not a boolean.
Attempt to make the style somewhat more ocnsistent with what indent
had before recent changes.

Pointed out by: bde


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

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


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

indent(1): Removed whitespace shouldn't be considered in column calculations.

This piece of code removed tabs and space characters from after colons
that follow labels by decrementing the e_lab (end of label) "pointer"
which is later used to calculate the width of the string that fprintf()
puts into "output". But pad_output() gets the length from the actual
string, so it miscalculated what the current column is.

Fixed by putting a string terminator at the e_lab "pointer".

Differential Revision: https://reviews.freebsd.org/D6966
(Partial)
Obtained from: Piotr Stefaniak


# 487ac9ac 30-Dec-2011 Ulrich Spörlein <uqs@FreeBSD.org>

Spelling fixes for usr.bin/


# f7c0d4c7 17-Dec-2011 Dimitry Andric <dim@FreeBSD.org>

In usr.bin/indent/io.c, fix a few warnings about format strings not being literals.

MFC after: 1 week


# 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.


# 84032c0a 13-Nov-2005 David Malone <dwmalone@FreeBSD.org>

Declare find_err in indent_globs.h where the other shared variables
live rather than listing it as an extern in indent.c.


# e3625e9c 27-Jun-2004 Jens Schweikhardt <schweikh@FreeBSD.org>

Fix problems with non-8 space tabs. New options for function
declarations with the opening brace on the same line as the declaration
of arguments all spaces and no tabs (a feature which exists in GNU's
indent). Man page update to follow RSN.

PR: bin/67983
Submitted by: Chip Norkus <wd@teleri.net>
Style guidance and bug for bug compatibility by: bde
MFC after: 2 weeks


# a55a608e 12-Feb-2004 Bruce Evans <bde@FreeBSD.org>

Only indent once for continuation lines when not lining up with
parentheses if the continuation indent is exactly half of the main
indent. Indenting one contination indent for every level of
parentheses gives bad results in most cases and is not what is done
in about 90% of properly hand-formatted KNF code (sys/kern/*.c,
nvi/common/*.c). The main advantage of the non-default KNF options
-nlp -ci4 is that continuation lines don't accidentally line up with
the next main indentation level or march to the right, and increasing
their indentation defeats this.

This behaviour change is limited to when the continuation indent is
exactly half of the main indent to avoid adding yet another option.


# 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.


# 8c7e7698 30-Mar-2002 David Malone <dwmalone@FreeBSD.org>

1) Const enough things to avoid warnings.
2) Cast ifdef_level to a size_t before comparing it to a ratio of size_ts.
Ifdef_level should always be positive.
3) Complete prototype for chfont.
4) Cast some ptrdiff_ts to ints before using as a field width.
5) Avoid shadowing a local variable p with another local variable p.


# 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.


# c3aac50f 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 9ef5c48b 04-Jul-1999 Bill Fumerola <billf@FreeBSD.org>

Clean up some ambiguous nested if/elses.


# 958d7c9f 15-Jul-1997 Philippe Charnier <charnier@FreeBSD.org>

Use err(3) instead of local redefinition. Add usage().


# 7799f52a 30-May-1995 Rodney W. Grimes <rgrimes@FreeBSD.org>

Remove trailing whitespace.


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

BSD 4.4 Lite Usr.bin Sources