KNFMT(1) General Commands Manual KNFMT(1)

knfmtkernel normal form formatter

knfmt [-dis] [file ...]

knfmt [-Ddis]

The knfmt utility formats source code files to conform to the Kernel Normal Form (KNF) in a best effort fashion, see style(9).

The options are as follows:

Only format changed lines extracted from a unified diff read from standard input.
Produce a diff for each given file.
In place edit of file.
Simplify the source code.
file
One or many files to format. If omitted, defaults to reading from standard input.

In addition, knfmt is also interoperable with clang-format. A subset of the available style options found in a .clang-format file located in any directory along the current working directory is honored. Some style options are exclusive to knfmt and not supported by clang-format, annotated as extensions. The supported style options and corresponding values are as follows:

Horizontally align arguments enclosed in parenthesis.
Align arguments enclosed in parenthesis.
some_long_function(argument1,
		   argument2);
Do not align, instead indent arguments using ContinuationIndentWidth. (default)
some_long_function(argument1,
    argument2);
Not supported, interpreted as DontAlign.
Not supported, interpreted as DontAlign.
Align backslashes in preprocessor macro definitions spanning multiple lines.
Do not align backslashes.
#define A \
	int x; \
	int y
Not supported, interpreted as DontAlign.
Align backslashes to the right-most column with respect to ColumnLimit. (default)
#define A		\
	int x;		\
	int y
Horizontally align operands of binary and ternary expressions.
Do not align, instead indent arguments using ContinuationIndentWidth. (default)
int x = 11111111 +
    22222222;
Align operands of binary and ternary expressions.
int x = 11111111 +
        22222222;

When BreakBeforeBinaryOperators equals NonAssignment, the operator is aligned with the operand on the previous line.

int x = 11111111
        + 22222222;
Not supported, interpreted as DontAlign.
Break after the return type for function prototypes and definitions.
Never break after the function return type.
void prototype(void);

void definition(void)
{
}
Always break after the function return type.
void
prototype(void);

void definition(void)
{
}
Not supported, interpreted as All.
Always break after the return type for function definitions. (default)
void prototype(void);

int
definition(void)
{
}
Not supported, interpreted as AllDefinitions.
Insert spaces around bitfields.
Add spaces on each side of the colon.
unsigned int field : 1;
Do not insert spaces. (default)
unsigned int field:1;
Add space before the colon.
unsigned int field :1;
Add space after the colon.
unsigned int field: 1;
Break before or after braces in certain contexts. The supported nested options are as follows:
Break before braces in enum definitions.
enum e
{
}
enum e {
}
Break before braces in function definitions.
int
main(void)
{
}
int
main(void) {
}
Break before braces in struct definitions.
struct s
{
}
struct s {
}
Break before braces in union definitions.
union u
{
}
union u {
}
AfterExternBlock AfterFunction AfterNamespace AfterObjCDeclaration AfterStruct AfterUnion BeforeCatch BeforeElse BeforeLambdaBody BeforeWhile IndentBraces SplitEmptyFunction SplitEmptyNamespace SplitEmptyRecord
Not supported.
Break before or after binary operators.
Break after binary operators. (default)
int x = 11111111 +
    22222222;
Break before non assignment operators.
int x = 11111111
    + 22222222;
Break before all binary operators.
int x = 11111111
    + 22222222;
Brace break style.
Enables AfterFunction, see BraceWrapping. (default)
Breaks dictated by BraceWrapping.
Not supported, interpreted as Custom.
Break before or after ternary operators.
Break before ternary operators.
condition
    ? true
    : false;
Break after ternary operators. (default)
condition ?
    true :
    false;
Maximum number of allowed columns per line. (default 80)
Indentation width for line continuations. (default 4)
Treatment of blocks of includes.
Not supported.
Preserve blocks of includes. (default)
Regroup blocks of includes according to IncludeCategories.
Rules used to group includes into blocks.
(extension)
Number of path components used to construct header include guards.
Example using two path components.
$ cat libks/vector.h
#ifndef LIBKS_VECTOR_H
#define LIBKS_VECTOR_H
#endif /* !LIBKS_VECTOR_H */
Disable include guards. (default)
Indentation width. (default 8)
Sort blocks of preprocessor include directives.
Do not sort includes. (default)
Sort includes in a case sensitive manner.
Not supported, interpreted as Never.
Use tabs for indentation.
Do not use tabs for indentation.
Not supported, interpreted as Always.
Not supported, interpreted as Always.
Not supported, interpreted as Always.
Use tabs for indentation. (default)

The knfmt utility exits 0 on success, and >0 if an error occurs.

style(9)

Anton Lindqvist <anton@basename.se>

April 10, 2021 OpenBSD 7.6