• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/H20-Nov-2021-6053

cmake/H20-Nov-2021-198163

documentation/H03-May-2022-6,2124,743

emscripten/H03-May-2022-877683

etc/H03-May-2022-15,51312,696

lnt/H03-May-2022-1717

man/H20-Nov-2021-182165

osx/H20-Nov-2021-121120

scripts/H20-Nov-2021-5,4744,035

src/H20-Nov-2021-68,22646,639

tests/H03-May-2022-112,66387,385

.editorconfigH A D20-Nov-202147 43

.gitattributesH A D20-Nov-2021296 138

.gitignoreH A D20-Nov-2021834 6549

.travis.ymlH A D20-Nov-20215.1 KiB189169

AUTHORSH A D20-Nov-20212.2 KiB167164

BUGSH A D20-Nov-20212.3 KiB6847

CODEOWNERSH A D20-Nov-2021222 128

CONTRIBUTING.mdH A D20-Nov-20213.9 KiB9176

COPYINGH A D20-Nov-202117.6 KiB341281

ChangeLogH A D20-Nov-202164.7 KiB1,5451,373

HELPH A D20-Nov-20211.8 KiB5937

NEWSH A D20-Nov-202123 31

README.mdH A D20-Nov-202114.5 KiB390300

TESTINGH A D20-Nov-20213.5 KiB10876

appveyor.ymlH A D20-Nov-20211.1 KiB3735

coverity.shH A D20-Nov-20211.4 KiB7150

coverity.travis.ymlH A D20-Nov-20211.6 KiB3024

extras.vpjH A D20-Nov-20214.4 KiB144143

forUncrustifySources.cfgH A D20-Nov-202118.6 KiB472456

package.jsonH A D20-Nov-2021573 2221

release-process.rstH A D20-Nov-202110.4 KiB326242

uncrustify.vpjH A D20-Nov-20214 KiB131130

uncrustify.vpwH A D20-Nov-2021385 1312

README.md

1[![AppVeyor](https://img.shields.io/appveyor/ci/uncrustify/uncrustify/master.svg?style=flat-square&label=Windows)](https://ci.appveyor.com/project/uncrustify/uncrustify)
2[![Coverage Status](https://coveralls.io/repos/github/uncrustify/uncrustify/badge.svg?branch=master)](https://coveralls.io/github/uncrustify/uncrustify?branch=master)
3<a href="#"><img src="https://img.shields.io/badge/C++-11-blue.svg?style=flat-square"></a>
4
5---------------------------
6
7# Uncrustify
8A source code beautifier for C, C++, C#, ObjectiveC, D, Java, Pawn and VALA
9
10## Features
11* Highly configurable - 787 configurable options as of version 0.74.0
12- <details><summary>add/remove spaces</summary>
13
14  - `sp_before_sparen`: _Add or remove space before '(' of 'if', 'for', 'switch', 'while', etc._
15  - `sp_compare`: _Add or remove space around compare operator '<', '>', '==', etc_
16</details>
17
18- <details><summary>add/remove newlines</summary>
19
20  - `nl_if_brace`: _Add or remove newline between 'if' and '{'_
21  - `nl_brace_while`: _Add or remove newline between '}' and 'while' of 'do' statement_
22</details>
23
24- <details><summary>add/remove blanklines</summary>
25
26  - `eat_blanks_before_close_brace`: _Whether to remove blank lines before '}'_
27  - `nl_max`: _The maximum consecutive newlines (3 = 2 blank lines)_
28</details>
29
30- <details><summary>indent code</summary>
31
32  - `indent_switch_case`: _indent_switch_case: Spaces to indent 'case' from 'switch'_
33  - `indent_class_colon`: _Whether to indent the stuff after a leading base class colon_
34</details>
35
36- <details><summary>align code</summary>
37
38  - `align_func_params`: _Align variable definitions in prototypes and functions_
39  - `align_struct_init_span`: _The span for aligning struct initializer values (0=don't align)_
40</details>
41
42- <details><summary>modify code</summary>
43
44  - `mod_full_brace_for`: _Add or remove braces on single-line 'for' statement_
45  - `mod_paren_on_return`: _Add or remove unnecessary paren on 'return' statement_
46</details>
47
48Here is an example [configuration file](https://raw.githubusercontent.com/uncrustify/uncrustify/master/documentation/htdocs/ben.cfg.txt),
49and here is a [before](https://raw.githubusercontent.com/uncrustify/uncrustify/master/documentation/htdocs/examples/c-1.in.c)
50and [after](https://raw.githubusercontent.com/uncrustify/uncrustify/master/documentation/htdocs/examples/c-1.out.c)
51C source example.
52That should give you a pretty good idea of what Uncrustify can do.
53
54
55
56
57
58---------------------------------------------------------------------------
59
60## Binaries
61Pre compiled binaries for Windows can be downloaded [here](https://sourceforge.net/projects/uncrustify/files/).
62
63## Build
64[Python](https://www.python.org/) is an "interpreted high-level programming language for general-purpose programming", for this project it is needed to extend the capabilities of CMake.
65
66[CMake](https://cmake.org/) is a tool that generates build systems
67(Makefiles, Visual Studio project files, Xcode project files and others).
68
69To generate a build system for Uncrustify using CMake, create a build
70folder and run CMake from it:
71
72```bash
73$ mkdir build
74$ cd build
75$ cmake ..
76```
77(Use `cmake -G Xcode ..` for Xcode)
78
79Then use the build tools of your build system (in many cases this will
80simply be `make`, but on Windows it could be MSBuild or Visual Studio).
81Or use CMake to invoke it:
82
83```bash
84$ cmake --build .
85```
86
87If testing is enabled, CMake generates a `test` target, which you can
88_build_ using your build system tools (usually `make test`). This can also
89be invoked using CTest:
90
91```bash
92$ ctest -V -C Debug
93```
94
95There is also an `install` target, which can be used to install the
96Uncrustify executable (typically `make install`).
97
98### A note on CMake configurations
99Some build systems are single-configuration, which means you specify the
100build type when running CMake (by setting the `CMAKE_BUILD_TYPE`
101variable), and the generated files then build that configuration.
102
103An example of a single-configuration build system are Makefiles. You can
104build the Release configuration of Uncrustify (from the build folder) with:
105
106```bash
107$ cmake -DCMAKE_BUILD_TYPE=Release ..
108$ make
109```
110
111Other build systems are multi-configuration, which means you specify the
112build type when building.
113
114An example of a multi-configuration build system are Visual Studios project
115files. When you open the project in Visual Studio, you can select which
116configuration to build. You can also do this while building from the
117command line with `cmake --build . --config Release`.
118
119
120## Bugs
121Post any bugs to the issue tracker found on the projects GitHub page:
122  https://github.com/uncrustify/uncrustify/issues
123
124Please include the following with your issue:
125 - a description of what is not working right
126 - input code sufficient to demonstrate the issue
127 - expected output code
128 - configuration options used to generate the output
129
130More about this is in the [ISSUE_TEMPLATE](https://github.com/uncrustify/uncrustify/blob/master/.github/ISSUE_TEMPLATE)
131
132
133### Known problems
134[Look at the Wiki](https://github.com/uncrustify/uncrustify/wiki/Known-Problems)
135
136
137## Which repositories have uncrustify?
138[Look here](https://repology.org/metapackage/uncrustify/versions)
139
140
141## Contribute
142If you want to add a feature, fix a bug, or implement missing
143functionality, feel free to do so! Patches are welcome!
144Here are some areas that need attention:
145
146- __Patches for Objective-C support__. We really need someone who knows
147  this language as it has more than plenty open issues. A good starting
148  point would be to integrate changes made in the
149  [Unity fork](https://github.com/Unity-Technologies/uncrustify/tree/fixes/c-oc-java)
150- Test Java support and provide feedback (or patches!)
151- Test Embedded SQL to see what works
152- A logo of some sort
153- Anything else that you want to do to make it better?
154
155### A note about pull requests
156Firstly take a look at the [CONTRIBUTING.md](https://github.com/uncrustify/uncrustify/blob/master/CONTRIBUTING.md)
157
158Currently we have two continuous integration systems that test your PRs,
159TravisCI and Appveyor.
160Tested are the test cases, the formatting of the code base and
161the output of the command line options.
162
163Test cases can be found in the `tests/` directory. Every file ending with
164`.test` is a test set. Inside each line with these components is a
165single test: `testNr[!] testConfigFileName testInputFileName [lang]`
166
167The configuration file `testConfigFileName` has to be located inside `tests/config`,
168the input file `testInputFileName` inside `tests/input/<testSetName>/`,
169and expected results file inside the `tests/expected/<testSetName>/`
170directory.
171Expected results have the following naming convention: `testNr-testInputFileName`.
172
173Optionally a `!` can follow the `testNr` to enable a custom rerun
174configuration.
175Rerun configurations need to be named like this:
176`testConfigFileName`(without extension)+`.rerun`+`.extension`
177
178Also, optionally a language for the input can be provided with `lang`.
179
180The codebase has to be formatted by the options set up in
181`forUncrustifySources.cfg`. Failing to format the sources correctly will
182cause TravisCI build failures.
183
184The Command line interface (CLI) output is tested by the
185`test_cli_options.sh` script. It is located inside of `tests/cli/` and operates
186on the subdirectories of that folder.
187
188If a PR is altering the CLI output, files inside those directories might
189need to be manually updated. This often happens when options are
190added, removed or altered. Keep in mind that the version string line
191(example: `# Uncrustify-0.69.0_f`) of outputs from commands like
192`--show-config` should be replaced with a blank line.
193
194### Debugging
195
196The first method is to use uncrustify itself to get debug informations.
197Using:
198```.txt
199   uncrustify -c myExample.cfg -f myExample.cpp -p myExample.p -L A 2>myExample.A
200```
201you get two files for the first informations.
202The p-file gives you details of the parsing process and indentation.
203```.txt
204# Line                Tag              Parent          Columns Br/Lvl/pp     Flag   Nl  Text
205#   1>              CLASS[               NONE][  1/  1/  6/  0][0/0/0][  10070000][0-0] class
206#   1>               TYPE[              CLASS][  7/  7/ 14/  1][0/0/0][  10000000][0-0]       Capteur
207#   1>         BRACE_OPEN[              CLASS][ 15/ 15/ 16/  1][0/0/0][ 100000400][0-0]               {
208```
209
210The A-file gives you many details about the run itself, where the process is running thru,
211which values have the most important variables.
212```.txt
213tokenize(2351): orig_line is 1, orig_col is 1, text() 'class', type is CLASS, orig_col_end is 6
214tokenize(2351): orig_line is 1, orig_col is 7, text() 'Capteur', type is WORD, orig_col_end is 14
215tokenize(2351): orig_line is 1, orig_col is 15, text() '{', type is BRACE_OPEN, orig_col_end is 16
216```
217
218You can also dump the parsing information of each formatting step using the 'dump steps' option.
219```.txt
220   uncrustify -c myExample.cfg -f myExample.cpp -ds dump
221```
222This will create a series of 'dump_nnn.log' files, each containing the parsing information at
223specific points of the formatting process ('dump_000.log' will list the formatting options in use).
224
225You can combine this option with -p and -L to get a lot of detailed debugging information.
226```.txt
227   uncrustify -c myExample.cfg -f myExample.cpp -p myExample.p -L A 2>myExample.A -ds dump
228```
229
230It might be useful to add some code lines to see where something is happening.
231Use the package `unc_tools`.
232Remove the comment at line:
233```.cpp
234#define DEVELOP_ONLY
235```
236Import the package:
237```.cpp
238#include "unc_tools.h"
239```
240Add at some places the line:
241```.cpp
242prot_the_line(__LINE__, 6, 0);
243```
244Compile again with DEBUG option.
245
246
247
248### How to add an option
249
250If you need a new option, there are a few steps to follow.
251Take as example the option `sp_trailing_ret_t`
252
253First define the option:
254- Insert the code below to the file src/options.h
255_NOTE:
256This file is processed by make_options.py, and must conform to a particular
257format. Option groups are marked by '//begin ' (in upper case; this example
258is lower case to prevent being considered a region marker for code folding)
259followed by the group description. Options consist of two lines of
260declaration preceded by one or more lines of C++ comments. The comments form
261the option description and are taken verbatim, aside from stripping the
262leading '// '. Only comments immediately preceding an option declaration,
263with no blank lines, are taken as part of the description, so a blank line
264may be used to separate notations from a description.
265An option declaration is 'extern TYPE\nNAME;', optionally followed by
266' // = VALUE' if the option has a default value that is different from the
267default-constructed value type of the option. The 'VALUE' must be valid C++
268code, and is taken verbatim as an argument when creating the option's
269instantiation. Note also that the line break, as shown, is required.
270_
271```.cpp
272// Add or remove space around trailing return operator '->'.
273extern Option<iarf_e>
274sp_trailing_ret_t;
275```
276- Insert the code below to the file src/space.cpp
277```.cpp
278   if (chunk_is_token(first, CT_TRAILING_RET_T))
279   {
280      // Add or remove space around trailing return operator '->'.
281      log_rule("sp_trailing_ret_t");
282      return(options::sp_trailing_ret_t());
283   }
284```
285
286
287### Portability
288
289We are pretty sure that nothing OS-specific is used in the code base.
290The software has been previously tested on the following operating systems:
291- Linux
292- QNX
293- OS X
294- FreeBSD, NetBSD, OpenBSD
295- Sun Solaris 9
296- Windows (binary available)
297
298
299---------------------------------------------------------------------------
300
301## Running the program
302
303__NOTE__ This application works reasonably well but it has bugs. Do __not__
304apply it on your whole codebase without checking the results!
305
306Here are ways to run it:
307```
308$ uncrustify -c mystyle.cfg -f somefile.c -o somefile.c.unc
309$ uncrustify -c mystyle.cfg -f somefile.c > somefile.c.unc
310$ uncrustify -c mystyle.cfg somefile.c
311$ uncrustify -c mystyle.cfg --no-backup somefile.c
312$ uncrustify -c mystyle.cfg *.c
313$ uncrustify -c mystyle.cfg --no-backup *.c
314```
315The `-c` flag selects the configuration file.
316The `-f` flag specifies the input file.
317The `-o` flag specifies the output file.
318If flag `-f` is used without flag `-o` the output will be send to `stdout`.
319
320Alternatively multiple or single files that should be processed can be
321specified at the command end without flags.
322If the flag `--no-backup` is missing, every file is saved with the initial
323name and an additional suffix (can be changed with --suffix).
324
325For more options descriptions call:
326```bash
327$ uncrustify -h
328```
329
330## Configuring the program
331Uncrustify usually reads configuration files that are passed via the `-c`
332flag. If the flag is not provided Uncrustify will try to find a
333configuration file via the `UNCRUSTIFY_CONFIG` environment variable or a
334file with the name `.uncrustify.cfg` or `uncrustify.cfg` in your home folder.
335
336To get a list of:
337- all available options use:
338  ```bash
339  uncrustify --show-config
340  ```
341
342- all available options in a usable configuration file format use:
343  ```bash
344  uncrustify --update-config
345  ```
346
347  or
348
349  ```bash
350  uncrustify --update-config-with-doc
351  ```
352
353  As the names suggest both options can produce output that adds newly
354  introduced options to your old configuration file. For this your old
355  configuration file has to be passed via the `-c` flag:
356  ```bash
357  uncrustify --update-config-with-doc -c path/to/your.cfg
358  ```
359
360Example configuration files that can be used as a starting point can be
361found in the `etc/` directory (such as [ben.cfg](./etc/ben.cfg)).
362
363Modify to your liking. Use a quality side-by-side diff tool to determine
364if the program did what you wanted. Repeat until your style is refined.
365
366To ease the process a bit, some 3rd party tools are available:
367- [Universal Indent GUI](http://universalindent.sourceforge.net/) - A
368  cross-platform graphical configuration file editor for many code
369  beautifiers, including Uncrustify.
370- [uncrustify_config](https://github.com/CDanU/uncrustify_config) - A web
371  configuration tool based on Uncrustify's emscripten interface.
372- [UncrustifyX](https://github.com/ryanmaxwell/UncrustifyX) - Uncrustify
373  utility and documentation browser for Mac OS X
374
375Under Windows:
376Uncrustify is a command-line tool, if you run it by double-clicking the
377executable, it will open a command prompt run the executable
378(which prints the help message), and then immediately close the window
379as uncrustify exits.
380
381You can open the command prompt (which is an interactive terminal
382window that allows you to run commands without it closing as soon as
383they exit) and run uncrustify.exe there.
384
385## Using uncrustify with vim
386Have a look [here]https://github.com/cofyc/vim-uncrustify
387
388## Using uncrustify with IntelliJ
389Have a look at https://plugins.jetbrains.com/plugin/17528-uncrustify
390