Skip to content

Commit

Permalink
Start using clang-format for formatting the code automatically.
Browse files Browse the repository at this point in the history
  • Loading branch information
plusvic committed Oct 7, 2020
1 parent d13bc34 commit 0bce4bd
Show file tree
Hide file tree
Showing 142 changed files with 24,426 additions and 25,013 deletions.
156 changes: 156 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
---
Language: Cpp
BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: true
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: true
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: false
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Allman
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: "^\
begin_declarations|\
begin_struct.*$"
MacroBlockEnd: "^\
end_declarations|\
end_struct.*$"
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 100
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 1000
PointerAlignment: Left
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
CanonicalDelimiter: ''
BasedOnStyle: google
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseTab: Never
...
128 changes: 57 additions & 71 deletions cli/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,21 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "args.h"

#include <assert.h>
#include <string.h>
#include <stdlib.h>

#include <string.h>
#include <yara.h>

#include "args.h"

#define args_is_long_arg(arg) \
(arg[0] == '-' && arg[1] == '-' && arg[2] != '\0')
#define args_is_long_arg(arg) (arg[0] == '-' && arg[1] == '-' && arg[2] != '\0')


#define args_is_short_arg(arg) \
(arg[0] == '-' && arg[1] != '-' && arg[1] != '\0')
#define args_is_short_arg(arg) \
(arg[0] == '-' && arg[1] != '-' && arg[1] != '\0')


args_option_t* args_get_short_option(
args_option_t *options,
const char opt)
args_option_t* args_get_short_option(args_option_t* options, const char opt)
{
while (options->type != ARGS_OPT_END)
{
Expand All @@ -59,11 +55,9 @@ args_option_t* args_get_short_option(
}


args_option_t* args_get_long_option(
args_option_t *options,
const char* arg)
args_option_t* args_get_long_option(args_option_t* options, const char* arg)
{
arg += 2; // skip starting --
arg += 2; // skip starting --

while (options->type != ARGS_OPT_END)
{
Expand All @@ -90,52 +84,52 @@ args_error_type_t args_parse_option(
const char* opt_arg,
int* opt_arg_was_used)
{
char *endptr = NULL;
char* endptr = NULL;

if (opt_arg_was_used != NULL)
*opt_arg_was_used = 0;
*opt_arg_was_used = 0;

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

switch (opt->type)
{
case ARGS_OPT_BOOLEAN:
*(bool*) opt->value = !(*(bool*) opt->value);
break;
case ARGS_OPT_BOOLEAN:
*(bool*) opt->value = !(*(bool*) opt->value);
break;

case ARGS_OPT_INTEGER:
case ARGS_OPT_INTEGER:

if (opt_arg == NULL)
return ARGS_ERROR_REQUIRED_INTEGER_ARG;
if (opt_arg == NULL)
return ARGS_ERROR_REQUIRED_INTEGER_ARG;

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

if (*endptr != '\0')
return ARGS_ERROR_REQUIRED_INTEGER_ARG;
if (*endptr != '\0')
return ARGS_ERROR_REQUIRED_INTEGER_ARG;

if (opt_arg_was_used != NULL)
*opt_arg_was_used = 1;
if (opt_arg_was_used != NULL)
*opt_arg_was_used = 1;

break;
break;

case ARGS_OPT_STRING:
case ARGS_OPT_STRING:

if (opt_arg == NULL)
return ARGS_ERROR_REQUIRED_STRING_ARG;
if (opt_arg == NULL)
return ARGS_ERROR_REQUIRED_STRING_ARG;

if (opt->max_count > 1)
((const char**)opt->value)[opt->count] = opt_arg;
else
*(const char**) opt->value = opt_arg;
if (opt->max_count > 1)
((const char**) opt->value)[opt->count] = opt_arg;
else
*(const char**) opt->value = opt_arg;

if (opt_arg_was_used != NULL)
*opt_arg_was_used = 1;
if (opt_arg_was_used != NULL)
*opt_arg_was_used = 1;

break;
break;

default:
assert(0);
default:
assert(0);
}

opt->count++;
Expand All @@ -144,37 +138,32 @@ args_error_type_t args_parse_option(
}


void args_print_error(
args_error_type_t error,
const char* option)
void args_print_error(args_error_type_t error, const char* option)
{
switch(error)
switch (error)
{
case ARGS_ERROR_UNKNOWN_OPT:
fprintf(stderr, "unknown option `%s`\n", option);
break;
case ARGS_ERROR_TOO_MANY:
fprintf(stderr, "too many `%s` options\n", option);
break;
case ARGS_ERROR_REQUIRED_INTEGER_ARG:
fprintf(stderr, "option `%s` requires an integer argument\n", option);
break;
case ARGS_ERROR_REQUIRED_STRING_ARG:
fprintf(stderr, "option `%s` requires a string argument\n", option);
break;
case ARGS_ERROR_UNEXPECTED_ARG:
fprintf(stderr, "option `%s` doesn't expect an argument\n", option);
break;
default:
return;
case ARGS_ERROR_UNKNOWN_OPT:
fprintf(stderr, "unknown option `%s`\n", option);
break;
case ARGS_ERROR_TOO_MANY:
fprintf(stderr, "too many `%s` options\n", option);
break;
case ARGS_ERROR_REQUIRED_INTEGER_ARG:
fprintf(stderr, "option `%s` requires an integer argument\n", option);
break;
case ARGS_ERROR_REQUIRED_STRING_ARG:
fprintf(stderr, "option `%s` requires a string argument\n", option);
break;
case ARGS_ERROR_UNEXPECTED_ARG:
fprintf(stderr, "option `%s` doesn't expect an argument\n", option);
break;
default:
return;
}
}


int args_parse(
args_option_t *options,
int argc,
const char **argv)
int args_parse(args_option_t* options, int argc, const char** argv)
{
args_error_type_t error = ARGS_ERROR_OK;

Expand Down Expand Up @@ -257,9 +246,7 @@ int args_parse(
}


void args_print_usage(
args_option_t *options,
int help_alignment)
void args_print_usage(args_option_t* options, int help_alignment)
{
char buffer[128];

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

if (options->type == ARGS_OPT_STRING ||
options->type == ARGS_OPT_INTEGER)
if (options->type == ARGS_OPT_STRING || options->type == ARGS_OPT_INTEGER)
{
len += sprintf(
buffer + len,
Expand Down
Loading

0 comments on commit 0bce4bd

Please sign in to comment.