KNFMT(1)

NAME
knfmt - kernel normal form formatter

SYNOPSIS
knfmt [-dis] [file ...]
knfmt [-Ddis]

DESCRIPTION
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:

-D  Only format changed lines extracted from a unified diff read from standard input.

-d  Produce a diff for each given file.

-i  In place edit of file.

-s  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:

AlignAfterOpenBracket
    Horizontally align arguments enclosed in parenthesis.

    Align
        Align arguments enclosed in parenthesis.

            some_long_function(argument1,
            		   argument2);

    DontAlign
        Do not align, instead indent arguments using ContinuationIndentWidth. (default)

            some_long_function(argument1,
                argument2);

    AlwaysBreak
        Not supported, interpreted as DontAlign.

    BlockIndent
        Not supported, interpreted as DontAlign.

AlignEscapedNewlines
    Align backslashes in preprocessor macro definitions spanning multiple lines.

    DontAlign
        Do not align backslashes.

            #define A \
            	int x; \
            	int y

    Left
        Not supported, interpreted as DontAlign.

    Right
        Align backslashes to the right-most column with respect to ColumnLimit. (default)

            #define A		\
            	int x;		\
            	int y

AlignOperands
    Horizontally align operands of binary and ternary expressions.

    DontAlign
        Do not align, instead indent arguments using ContinuationIndentWidth. (default)

            int x = 11111111 +
                22222222;

    Align
        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;

    AlignAfterOperator
        Not supported, interpreted as DontAlign.

AlwaysBreakAfterReturnType
    Break after the return type for function prototypes and definitions.

    None
        Never break after the function return type.

            void prototype(void);
            void definition(void)
            {
            }

    All Always break after the function return type.

            void
            prototype(void);
            void definition(void)
            {
            }

    TopLevel
        Not supported, interpreted as All.

    AllDefinitions
        Always break after the return type for function definitions. (default)

            void prototype(void);
            int
            definition(void)
            {
            }

    TopLevelDefinitions
        Not supported, interpreted as AllDefinitions.

BitFieldColonSpacing
    Insert spaces around bitfields.

    Both
        Add spaces on each side of the colon.

            unsigned int field : 1;

    None
        Do not insert spaces. (default)

            unsigned int field:1;

    Before
        Add space before the colon.

            unsigned int field :1;

    After
        Add space after the colon.

            unsigned int field: 1;

BraceWrapping
    Break before or after braces in certain contexts. The supported nested options are as follows:

    AfterEnum
        Break before braces in enum definitions.

        true
                enum e
                {
                }

        false
                enum e {
                }

    AfterFunction
        Break before braces in function definitions.

        true
                int
                main(void)
                {
                }

        false
                int
                main(void) {
                }

    AfterStruct
        Break before braces in struct definitions.

        true
                struct s
                {
                }

        false
                struct s {
                }

    AfterUnion
        Break before braces in union definitions.

        true
                union u
                {
                }

        false
                union u {
                }

        AfterCaseLabel AfterClass AfterControlStatement AfterEnum AfterExternBlock AfterFunction AfterNamespace AfterObjCDeclaration AfterStruct AfterUnion BeforeCatch BeforeElse BeforeLambdaBody BeforeWhile IndentBraces SplitEmptyFunction SplitEmptyNamespace SplitEmptyRecord Not supported.

BreakBeforeBinaryOperators
    Break before or after binary operators.

    None
        Break after binary operators. (default)

            int x = 11111111 +
                22222222;

    NonAssignment
        Break before non assignment operators.

            int x = 11111111
                + 22222222;

    All Break before all binary operators.

            int x = 11111111
                + 22222222;

BreakBeforeBraces
    Brace break style.

    Linux
        Enables AfterFunction, see BraceWrapping. (default)

    Custom
        Breaks dictated by BraceWrapping.

    Allman Attach GNU Mozilla Stroustrup WebKit Whitesmiths
        Not supported, interpreted as Custom.

BreakBeforeTernaryOperators
    Break before or after ternary operators.

    true
        Break before ternary operators.

            condition
                ? true
                : false;

    false
        Break after ternary operators. (default)

            condition ?
                true :
                false;

ColumnLimit
    Maximum number of allowed columns per line. (default 80)

ContinuationIndentWidth
    Indentation width for line continuations. (default 4)

IncludeBlocks
    Treatment of blocks of includes.

    Merge
        Regroup blocks of includes according to IncludeCategories but do not emit a blank line between the block of includes.

    Preserve
        Preserve blocks of includes. (default)

    Regroup
        Regroup blocks of includes according to IncludeCategories.

IncludeCategories
    Rules used to group includes into blocks.

IncludeGuards (extension)
    List of headers in which include guards must be present. The supported nested options are as follows:

    Regex
        Extended regular expression used to determine if file denotes a header, see regex(3).

    PathComponents
        Number of path components used to construct header include guards.

        >0
                $ cat libks/vector.h
                #ifndef LIBKS_VECTOR_H
                #define LIBKS_VECTOR_H
                #endif /* !LIBKS_VECTOR_H */

        1   (default)
                $ cat libks/vector.h
                #ifndef VECTOR_H
                #define VECTOR_H
                #endif /* !VECTOR_H */

IndentWidth
    Indentation width. (default 8)

SortIncludes
    Sort blocks of preprocessor include directives.

    Never
        Do not sort includes. (default)

    CaseSensitive
        Sort includes in a case sensitive manner.

    CaseInsensitive
        Not supported, interpreted as Never.

UseTab
    Use tabs for indentation.

    Never
        Do not use tabs for indentation.

    ForIndentation
        Not supported, interpreted as Always.

    ForContinuationAndIndentation
        Not supported, interpreted as Always.

    AlignWithSpaces
        Not supported, interpreted as Always.

    Always
        Use tabs for indentation. (default)

DIAGNOSTICS

SEE ALSO
style(9)

AUTHORS
Anton Lindqvist <anton@basename.se>