Skip to content

Commit 7517bbd

Browse files
committed
Start using clang-format for automatic source formatting.
2 parents c24d2b9 + fa5682a commit 7517bbd

File tree

141 files changed

+22414
-23936
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+22414
-23936
lines changed

.clang-format

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# clang-format configuration applied to all source files in this project.
2+
# Requires clang-format version 10.0.0 or newer.
3+
---
4+
Language: Cpp
5+
BasedOnStyle: Google
6+
AccessModifierOffset: -1
7+
AlignAfterOpenBracket: AlwaysBreak
8+
AlignConsecutiveAssignments: false
9+
AlignConsecutiveDeclarations: false
10+
AlignConsecutiveMacros: true
11+
AlignEscapedNewlines: Left
12+
AlignOperands: true
13+
AlignTrailingComments: true
14+
AllowAllArgumentsOnNextLine: true
15+
AllowAllConstructorInitializersOnNextLine: true
16+
AllowAllParametersOfDeclarationOnNextLine: false
17+
AllowShortBlocksOnASingleLine: false
18+
AllowShortCaseLabelsOnASingleLine: false
19+
AllowShortFunctionsOnASingleLine: Inline
20+
AllowShortLambdasOnASingleLine: All
21+
AllowShortIfStatementsOnASingleLine: Never
22+
AllowShortLoopsOnASingleLine: true
23+
AlwaysBreakAfterDefinitionReturnType: None
24+
AlwaysBreakAfterReturnType: None
25+
AlwaysBreakBeforeMultilineStrings: false
26+
AlwaysBreakTemplateDeclarations: Yes
27+
BinPackArguments: false
28+
BinPackParameters: false
29+
BraceWrapping:
30+
AfterCaseLabel: false
31+
AfterClass: false
32+
AfterControlStatement: true
33+
AfterEnum: false
34+
AfterFunction: true
35+
AfterNamespace: false
36+
AfterObjCDeclaration: false
37+
AfterStruct: true
38+
AfterUnion: false
39+
AfterExternBlock: false
40+
BeforeCatch: true
41+
BeforeElse: true
42+
IndentBraces: false
43+
SplitEmptyFunction: true
44+
SplitEmptyRecord: true
45+
SplitEmptyNamespace: true
46+
BreakBeforeBinaryOperators: None
47+
BreakBeforeBraces: Allman
48+
BreakBeforeInheritanceComma: false
49+
BreakInheritanceList: BeforeColon
50+
BreakBeforeTernaryOperators: true
51+
BreakConstructorInitializersBeforeComma: false
52+
BreakConstructorInitializers: BeforeColon
53+
BreakAfterJavaFieldAnnotations: false
54+
BreakStringLiterals: true
55+
ColumnLimit: 80
56+
CommentPragmas: '^ IWYU pragma:'
57+
CompactNamespaces: false
58+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
59+
ConstructorInitializerIndentWidth: 4
60+
ContinuationIndentWidth: 4
61+
Cpp11BracedListStyle: true
62+
DerivePointerAlignment: true
63+
DisableFormat: false
64+
ExperimentalAutoDetectBinPacking: false
65+
FixNamespaceComments: true
66+
IncludeBlocks: Preserve
67+
IncludeCategories:
68+
- Regex: '^<ext/.*\.h>'
69+
Priority: 2
70+
- Regex: '^<.*\.h>'
71+
Priority: 1
72+
- Regex: '^<.*'
73+
Priority: 2
74+
- Regex: '.*'
75+
Priority: 3
76+
IncludeIsMainRegex: '([-_](test|unittest))?$'
77+
IndentCaseLabels: false
78+
IndentPPDirectives: None
79+
IndentWidth: 2
80+
IndentWrappedFunctionNames: false
81+
JavaScriptQuotes: Leave
82+
JavaScriptWrapImports: true
83+
KeepEmptyLinesAtTheStartOfBlocks: false
84+
MacroBlockBegin: "^\
85+
begin_declarations|\
86+
begin_struct.*$"
87+
MacroBlockEnd: "^\
88+
end_declarations|\
89+
end_struct.*$"
90+
MaxEmptyLinesToKeep: 1
91+
NamespaceIndentation: None
92+
ObjCBinPackProtocolList: Never
93+
ObjCBlockIndentWidth: 2
94+
ObjCSpaceAfterProperty: false
95+
ObjCSpaceBeforeProtocolList: true
96+
PenaltyBreakAssignment: 100
97+
PenaltyBreakBeforeFirstCallParameter: 1
98+
PenaltyBreakComment: 300
99+
PenaltyBreakFirstLessLess: 120
100+
PenaltyBreakString: 1000
101+
PenaltyBreakTemplateDeclaration: 10
102+
PenaltyExcessCharacter: 1000000
103+
PenaltyReturnTypeOnItsOwnLine: 1000
104+
PointerAlignment: Left
105+
RawStringFormats:
106+
- Language: Cpp
107+
Delimiters:
108+
- cc
109+
- CC
110+
- cpp
111+
- Cpp
112+
- CPP
113+
- 'c++'
114+
- 'C++'
115+
CanonicalDelimiter: ''
116+
BasedOnStyle: google
117+
- Language: TextProto
118+
Delimiters:
119+
- pb
120+
- PB
121+
- proto
122+
- PROTO
123+
EnclosingFunctions:
124+
- EqualsProto
125+
- EquivToProto
126+
- PARSE_PARTIAL_TEXT_PROTO
127+
- PARSE_TEST_PROTO
128+
- PARSE_TEXT_PROTO
129+
- ParseTextOrDie
130+
- ParseTextProtoOrDie
131+
CanonicalDelimiter: ''
132+
BasedOnStyle: google
133+
ReflowComments: true
134+
SortIncludes: true
135+
SortUsingDeclarations: true
136+
SpaceAfterCStyleCast: true
137+
SpaceAfterLogicalNot: false
138+
SpaceAfterTemplateKeyword: true
139+
SpaceBeforeAssignmentOperators: true
140+
SpaceBeforeCpp11BracedList: false
141+
SpaceBeforeCtorInitializerColon: true
142+
SpaceBeforeInheritanceColon: true
143+
SpaceBeforeParens: ControlStatements
144+
SpaceBeforeRangeBasedForLoopColon: true
145+
SpaceInEmptyParentheses: false
146+
SpacesBeforeTrailingComments: 2
147+
SpacesInAngles: false
148+
SpacesInContainerLiterals: true
149+
SpacesInCStyleCastParentheses: false
150+
SpacesInParentheses: false
151+
SpacesInSquareBrackets: false
152+
Standard: Auto
153+
StatementMacros:
154+
- Q_UNUSED
155+
- QT_REQUIRE_VERSION
156+
TabWidth: 8
157+
UseTab: Never
158+
...

cli/args.c

+57-71
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,21 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2727
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
*/
2929

30+
#include "args.h"
31+
3032
#include <assert.h>
31-
#include <string.h>
3233
#include <stdlib.h>
33-
34+
#include <string.h>
3435
#include <yara.h>
3536

36-
#include "args.h"
37-
38-
#define args_is_long_arg(arg) \
39-
(arg[0] == '-' && arg[1] == '-' && arg[2] != '\0')
37+
#define args_is_long_arg(arg) (arg[0] == '-' && arg[1] == '-' && arg[2] != '\0')
4038

4139

42-
#define args_is_short_arg(arg) \
43-
(arg[0] == '-' && arg[1] != '-' && arg[1] != '\0')
40+
#define args_is_short_arg(arg) \
41+
(arg[0] == '-' && arg[1] != '-' && arg[1] != '\0')
4442

4543

46-
args_option_t* args_get_short_option(
47-
args_option_t *options,
48-
const char opt)
44+
args_option_t* args_get_short_option(args_option_t* options, const char opt)
4945
{
5046
while (options->type != ARGS_OPT_END)
5147
{
@@ -59,11 +55,9 @@ args_option_t* args_get_short_option(
5955
}
6056

6157

62-
args_option_t* args_get_long_option(
63-
args_option_t *options,
64-
const char* arg)
58+
args_option_t* args_get_long_option(args_option_t* options, const char* arg)
6559
{
66-
arg += 2; // skip starting --
60+
arg += 2; // skip starting --
6761

6862
while (options->type != ARGS_OPT_END)
6963
{
@@ -90,52 +84,52 @@ args_error_type_t args_parse_option(
9084
const char* opt_arg,
9185
int* opt_arg_was_used)
9286
{
93-
char *endptr = NULL;
87+
char* endptr = NULL;
9488

9589
if (opt_arg_was_used != NULL)
96-
*opt_arg_was_used = 0;
90+
*opt_arg_was_used = 0;
9791

9892
if (opt->count == opt->max_count)
9993
return ARGS_ERROR_TOO_MANY;
10094

10195
switch (opt->type)
10296
{
103-
case ARGS_OPT_BOOLEAN:
104-
*(bool*) opt->value = !(*(bool*) opt->value);
105-
break;
97+
case ARGS_OPT_BOOLEAN:
98+
*(bool*) opt->value = !(*(bool*) opt->value);
99+
break;
106100

107-
case ARGS_OPT_INTEGER:
101+
case ARGS_OPT_INTEGER:
108102

109-
if (opt_arg == NULL)
110-
return ARGS_ERROR_REQUIRED_INTEGER_ARG;
103+
if (opt_arg == NULL)
104+
return ARGS_ERROR_REQUIRED_INTEGER_ARG;
111105

112-
*(int*) opt->value = strtol(opt_arg, &endptr, 0);
106+
*(int*) opt->value = strtol(opt_arg, &endptr, 0);
113107

114-
if (*endptr != '\0')
115-
return ARGS_ERROR_REQUIRED_INTEGER_ARG;
108+
if (*endptr != '\0')
109+
return ARGS_ERROR_REQUIRED_INTEGER_ARG;
116110

117-
if (opt_arg_was_used != NULL)
118-
*opt_arg_was_used = 1;
111+
if (opt_arg_was_used != NULL)
112+
*opt_arg_was_used = 1;
119113

120-
break;
114+
break;
121115

122-
case ARGS_OPT_STRING:
116+
case ARGS_OPT_STRING:
123117

124-
if (opt_arg == NULL)
125-
return ARGS_ERROR_REQUIRED_STRING_ARG;
118+
if (opt_arg == NULL)
119+
return ARGS_ERROR_REQUIRED_STRING_ARG;
126120

127-
if (opt->max_count > 1)
128-
((const char**)opt->value)[opt->count] = opt_arg;
129-
else
130-
*(const char**) opt->value = opt_arg;
121+
if (opt->max_count > 1)
122+
((const char**) opt->value)[opt->count] = opt_arg;
123+
else
124+
*(const char**) opt->value = opt_arg;
131125

132-
if (opt_arg_was_used != NULL)
133-
*opt_arg_was_used = 1;
126+
if (opt_arg_was_used != NULL)
127+
*opt_arg_was_used = 1;
134128

135-
break;
129+
break;
136130

137-
default:
138-
assert(0);
131+
default:
132+
assert(0);
139133
}
140134

141135
opt->count++;
@@ -144,37 +138,32 @@ args_error_type_t args_parse_option(
144138
}
145139

146140

147-
void args_print_error(
148-
args_error_type_t error,
149-
const char* option)
141+
void args_print_error(args_error_type_t error, const char* option)
150142
{
151-
switch(error)
143+
switch (error)
152144
{
153-
case ARGS_ERROR_UNKNOWN_OPT:
154-
fprintf(stderr, "unknown option `%s`\n", option);
155-
break;
156-
case ARGS_ERROR_TOO_MANY:
157-
fprintf(stderr, "too many `%s` options\n", option);
158-
break;
159-
case ARGS_ERROR_REQUIRED_INTEGER_ARG:
160-
fprintf(stderr, "option `%s` requires an integer argument\n", option);
161-
break;
162-
case ARGS_ERROR_REQUIRED_STRING_ARG:
163-
fprintf(stderr, "option `%s` requires a string argument\n", option);
164-
break;
165-
case ARGS_ERROR_UNEXPECTED_ARG:
166-
fprintf(stderr, "option `%s` doesn't expect an argument\n", option);
167-
break;
168-
default:
169-
return;
145+
case ARGS_ERROR_UNKNOWN_OPT:
146+
fprintf(stderr, "unknown option `%s`\n", option);
147+
break;
148+
case ARGS_ERROR_TOO_MANY:
149+
fprintf(stderr, "too many `%s` options\n", option);
150+
break;
151+
case ARGS_ERROR_REQUIRED_INTEGER_ARG:
152+
fprintf(stderr, "option `%s` requires an integer argument\n", option);
153+
break;
154+
case ARGS_ERROR_REQUIRED_STRING_ARG:
155+
fprintf(stderr, "option `%s` requires a string argument\n", option);
156+
break;
157+
case ARGS_ERROR_UNEXPECTED_ARG:
158+
fprintf(stderr, "option `%s` doesn't expect an argument\n", option);
159+
break;
160+
default:
161+
return;
170162
}
171163
}
172164

173165

174-
int args_parse(
175-
args_option_t *options,
176-
int argc,
177-
const char **argv)
166+
int args_parse(args_option_t* options, int argc, const char** argv)
178167
{
179168
args_error_type_t error = ARGS_ERROR_OK;
180169

@@ -257,9 +246,7 @@ int args_parse(
257246
}
258247

259248

260-
void args_print_usage(
261-
args_option_t *options,
262-
int help_alignment)
249+
void args_print_usage(args_option_t* options, int help_alignment)
263250
{
264251
char buffer[128];
265252

@@ -278,8 +265,7 @@ void args_print_usage(
278265
if (options->long_name != NULL)
279266
len += sprintf(buffer + len, "--%s", options->long_name);
280267

281-
if (options->type == ARGS_OPT_STRING ||
282-
options->type == ARGS_OPT_INTEGER)
268+
if (options->type == ARGS_OPT_STRING || options->type == ARGS_OPT_INTEGER)
283269
{
284270
len += sprintf(
285271
buffer + len,

0 commit comments

Comments
 (0)