indent – Format C source files

The indent command is a Linux utility used to format C source code files. It can be used to adjust the indentation, spacing, and formatting of code to make it more readable and easier to understand. The indent command can also be used to standardize the formatting of code across multiple files or projects.

Overview

The indent command can be used to format C source code files in a variety of ways. By default, indent will adjust the indentation of code to match the current settings of the terminal. However, there are a number of options that can be used to customize the formatting of code, including:

  • -br: Break braces before the code they enclose.
  • -ce: Put a space after control statements (if, while, for, etc.).
  • -ci: Put a space after commas in declarations.
  • -cli: Put a space after commas in function calls.
  • -cs: Put a space after the semicolon at the end of a statement.
  • -di: Indent preprocessor directives.
  • -npro: Do not format function prototypes.
  • -npsl: Do not put a space before the opening parenthesis of a function call.
  • -nut: Use tabs for indentation.
  • -ts n: Set the tab size to n spaces.

For example, to format a C source file called example.c with tabs for indentation and a tab size of 4 spaces, you could use the following command:

indent -nut -ts4 example.c

Options

The following table lists the available options for the indent command:

Option Description
-br Break braces before the code they enclose.
-ce Put a space after control statements (if, while, for, etc.).
-ci Put a space after commas in declarations.
-cli Put a space after commas in function calls.
-cs Put a space after the semicolon at the end of a statement.
-di Indent preprocessor directives.
-npro Do not format function prototypes.
-npsl Do not put a space before the opening parenthesis of a function call.
-nut Use tabs for indentation.
-ts n Set the tab size to n spaces.

Troubleshooting tips

If you encounter issues when using the indent command, there are a few things you can try:

  • Check the syntax of your command to make sure you have not made any typos or errors.
  • Make sure you are using the correct options for your specific use case.
  • If you are having trouble with the formatting of your code, try adjusting the options to see if that resolves the issue.
  • If you are still having issues, consult the indent manual page for more information.

Notes

  • The indent command can be used to format code in a variety of ways, but it is important to use it judiciously. Overuse of the indent command can make code difficult to read and understand.
  • The indent command can be used in conjunction with other Linux utilities, such as find and xargs, to format multiple files at once.