aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDacav <dacav@fastmail.com>2020-08-29 08:01:46 +0200
committerDacav <dacav@fastmail.com>2020-08-29 08:01:46 +0200
commita24081196ec68979eab49c1e35ce89066eb86d2f (patch)
tree92d4c74acbc6c21034a2f0397ee42b4eeb9b2366
parentb71bf6f6a95f49b1d2b53a2f673d5d93836b4fc1 (diff)
downloadforg-a24081196ec68979eab49c1e35ce89066eb86d2f.tar.gz
clang-format
-rw-r--r--.clang-format127
-rw-r--r--filehash.c62
-rw-r--r--filehash.h6
-rw-r--r--forg-import.c262
4 files changed, 295 insertions, 162 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..74a79ab
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,127 @@
+---
+Language: Cpp
+# BasedOnStyle: Mozilla
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveMacros: false
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Right
+AlignOperands: true
+AlignTrailingComments: true
+AllowAllArgumentsOnNextLine: true
+AllowAllConstructorInitializersOnNextLine: true
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: Inline
+AllowShortLambdasOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: Never
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: TopLevel
+AlwaysBreakAfterReturnType: TopLevel
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: Yes
+BinPackArguments: false
+BinPackParameters: false
+BraceWrapping:
+ AfterCaseLabel: false
+ AfterClass: true
+ AfterControlStatement: false
+ AfterEnum: true
+ AfterFunction: true
+ AfterNamespace: false
+ AfterObjCDeclaration: false
+ AfterStruct: true
+ AfterUnion: true
+ AfterExternBlock: true
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: false
+ SplitEmptyFunction: true
+ SplitEmptyRecord: false
+ SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Mozilla
+BreakBeforeInheritanceComma: false
+BreakInheritanceList: BeforeComma
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeComma
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: true
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 2
+ContinuationIndentWidth: 2
+Cpp11BracedListStyle: false
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: false
+ForEachMacros:
+ - foreach
+ - Q_FOREACH
+ - BOOST_FOREACH
+IncludeBlocks: Preserve
+IncludeCategories:
+ - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
+ Priority: 2
+ - Regex: '^(<|"(gtest|gmock|isl|json)/)'
+ Priority: 3
+ - Regex: '.*'
+ Priority: 1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: true
+IndentPPDirectives: None
+IndentWidth: 2
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: false
+PenaltyBreakAssignment: 2
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyBreakTemplateDeclaration: 10
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 200
+PointerAlignment: Right
+ReflowComments: true
+SortIncludes: true
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceAfterLogicalNot: false
+SpaceAfterTemplateKeyword: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCpp11BracedList: false
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatements
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp11
+StatementMacros:
+ - Q_UNUSED
+ - QT_REQUIRE_VERSION
+TabWidth: 8
+UseTab: Never
+...
+
diff --git a/filehash.c b/filehash.c
index 5616226..ace1992 100644
--- a/filehash.c
+++ b/filehash.c
@@ -1,53 +1,51 @@
#include "filehash.h"
-#include <string.h>
#include <stdlib.h>
+#include <string.h>
struct filehash_t
{
- const char *hash_program;
- const char **argv;
- unsigned max_per_invocation;
+ const char *hash_program;
+ const char **argv;
+ unsigned max_per_invocation;
};
-filehash_t *filehash_new(const char *hash_program, unsigned max_per_invocation)
+filehash_t *
+filehash_new(const char *hash_program, unsigned max_per_invocation)
{
- filehash_t *fh;
+ filehash_t *fh;
- fh = malloc(sizeof(filehash_t));
- if (!fh)
- return NULL;
+ fh = malloc(sizeof(filehash_t));
+ if (!fh)
+ return NULL;
- *fh = (filehash_t){
- .hash_program = strdup(hash_program),
- .max_per_invocation = max_per_invocation,
- .argv = reallocarray(
- NULL,
- 1 + max_per_invocation,
- sizeof(const char *)
- ),
- };
+ *fh = (filehash_t){
+ .hash_program = strdup(hash_program),
+ .max_per_invocation = max_per_invocation,
+ .argv = reallocarray(NULL, 1 + max_per_invocation, sizeof(const char *)),
+ };
- if (!fh->hash_program)
- goto fail;
- if (!fh->argv)
- goto fail;
+ if (!fh->hash_program)
+ goto fail;
+ if (!fh->argv)
+ goto fail;
- fh->argv[max_per_invocation] = NULL;
+ fh->argv[max_per_invocation] = NULL;
- return fh;
+ return fh;
fail:
- filehash_free(fh);
- return NULL;
+ filehash_free(fh);
+ return NULL;
}
-void filehash_free(filehash_t *fh)
+void
+filehash_free(filehash_t *fh)
{
- if (!fh)
- return;
+ if (!fh)
+ return;
- free(fh->argv);
- free((void *)fh->hash_program);
- free(fh);
+ free(fh->argv);
+ free((void *)fh->hash_program);
+ free(fh);
}
diff --git a/filehash.h b/filehash.h
index 4f99b0e..c52f983 100644
--- a/filehash.h
+++ b/filehash.h
@@ -2,6 +2,8 @@
typedef struct filehash_t filehash_t;
-filehash_t *filehash_new(const char *hash_program, unsigned max_per_invocation);
+filehash_t *
+filehash_new(const char *hash_program, unsigned max_per_invocation);
-void filehash_free(filehash_t *);
+void
+filehash_free(filehash_t *);
diff --git a/forg-import.c b/forg-import.c
index 241e3f3..9f6cdb4 100644
--- a/forg-import.c
+++ b/forg-import.c
@@ -9,173 +9,179 @@
#define optstr "0h:L:r:"
-typedef struct {
- const char *hash;
- const char *repository;
- unsigned hash_max_lines;
- char **files;
- unsigned n_files;
- char input_sep;
+typedef struct
+{
+ const char *hash;
+ const char *repository;
+ unsigned hash_max_lines;
+ char **files;
+ unsigned n_files;
+ char input_sep;
} options_t;
-static void usage(const char *prgname)
+static void
+usage(const char *prgname)
{
- errx(EX_USAGE, "usage %s ...", prgname);
+ errx(EX_USAGE, "usage %s ...", prgname);
}
-static int str_to_uint(const char *str, unsigned *out)
+static int
+str_to_uint(const char *str, unsigned *out)
{
- unsigned long result;
- char *end;
+ unsigned long result;
+ char *end;
- errno = 0;
- result = strtoul(str, &end, 10);
+ errno = 0;
+ result = strtoul(str, &end, 10);
- if (errno)
- goto fail;
+ if (errno)
+ goto fail;
- if (*end != '\0') {
- errno = EINVAL;
- goto fail;
- }
+ if (*end != '\0') {
+ errno = EINVAL;
+ goto fail;
+ }
- if (result > UINT_MAX) {
- errno = ERANGE;
- goto fail;
- }
+ if (result > UINT_MAX) {
+ errno = ERANGE;
+ goto fail;
+ }
- *out = result;
- return 0;
+ *out = result;
+ return 0;
fail:
- warn("str_to_uint \"%s\"", str);
- return -1;
+ warn("str_to_uint \"%s\"", str);
+ return -1;
}
-static options_t read_opts(int argc, char **argv)
+static options_t
+read_opts(int argc, char **argv)
{
- int o;
- const char *prgname;
- options_t options = {
- .hash = "md5sum",
- .repository = ".",
- .hash_max_lines = 4096,
- .input_sep = '\n',
- };
-
- prgname = argc < 1 ? "keep" : argv[0];
-
- while (o = getopt(argc, argv, optstr), o != -1) {
- switch (o) {
- case '0':
- options.input_sep = '\0';
- break;
- case 'h':
- options.hash = optarg;
- break;
- case 'L':
- if (str_to_uint(optarg, &options.hash_max_lines))
- goto fail;
- break;
- case 'r':
- options.repository = optarg;
- break;
- case '?':
- default:
- usage(prgname);
- }
+ int o;
+ const char *prgname;
+ options_t options = {
+ .hash = "md5sum",
+ .repository = ".",
+ .hash_max_lines = 4096,
+ .input_sep = '\n',
+ };
+
+ prgname = argc < 1 ? "keep" : argv[0];
+
+ while (o = getopt(argc, argv, optstr), o != -1) {
+ switch (o) {
+ case '0':
+ options.input_sep = '\0';
+ break;
+ case 'h':
+ options.hash = optarg;
+ break;
+ case 'L':
+ if (str_to_uint(optarg, &options.hash_max_lines))
+ goto fail;
+ break;
+ case 'r':
+ options.repository = optarg;
+ break;
+ case '?':
+ default:
+ usage(prgname);
}
+ }
- options.files = argv + optind;
- options.n_files = argc - optind;
+ options.files = argv + optind;
+ options.n_files = argc - optind;
- return options;
+ return options;
fail:
- err(EX_CONFIG, "bad options");
+ err(EX_CONFIG, "bad options");
}
-static const char *iter_files(const options_t *opts, void **aux)
+static const char *
+iter_files(const options_t *opts, void **aux)
{
- struct ctx {
- enum {
- from_files_list,
- from_stdin,
- } from;
-
- union {
- struct {
- int next;
- } files_list;
- struct {
- char *line;
- size_t len;
- } stdin;
- };
+ struct ctx
+ {
+ enum
+ {
+ from_files_list,
+ from_stdin,
+ } from;
+
+ union
+ {
+ struct
+ {
+ int next;
+ } files_list;
+ struct
+ {
+ char *line;
+ size_t len;
+ } stdin;
};
+ };
- struct ctx *ctx = *aux;
- ssize_t nread;
+ struct ctx *ctx = *aux;
+ ssize_t nread;
- if (!ctx) { /* initialization */
+ if (!ctx) { /* initialization */
- *aux = ctx = malloc(sizeof(struct ctx));
- if (!ctx)
- err(EX_OSERR, "malloc");
+ *aux = ctx = malloc(sizeof(struct ctx));
+ if (!ctx)
+ err(EX_OSERR, "malloc");
- *ctx = (struct ctx){
- opts->n_files ? from_files_list : from_stdin
- };
- }
+ *ctx = (struct ctx){ opts->n_files ? from_files_list : from_stdin };
+ }
- switch (ctx->from) {
- case from_stdin:
- errno = 0;
- nread = getdelim(
- &ctx->stdin.line,
- &ctx->stdin.len,
- opts->input_sep,
- stdin
- );
- if (nread == -1) {
- if (!errno) {
- free(ctx->stdin.line);
- goto done;
- }
- err(EX_OSERR, "getdelim(..., stdin)");
- }
- if (opts->input_sep && ctx->stdin.line[nread - 1] == opts->input_sep)
- ctx->stdin.line[nread - 1] = '\0';
- return ctx->stdin.line;
-
- case from_files_list:
- if (ctx->files_list.next >= opts->n_files)
- goto done;
- return opts->files[ctx->files_list.next++];
- }
- err(EX_SOFTWARE, __FILE__":%d - buggy", __LINE__);
+ switch (ctx->from) {
+ case from_stdin:
+ errno = 0;
+ nread =
+ getdelim(&ctx->stdin.line, &ctx->stdin.len, opts->input_sep, stdin);
+ if (nread == -1) {
+ if (!errno) {
+ free(ctx->stdin.line);
+ goto done;
+ }
+ err(EX_OSERR, "getdelim(..., stdin)");
+ }
+ if (opts->input_sep && ctx->stdin.line[nread - 1] == opts->input_sep)
+ ctx->stdin.line[nread - 1] = '\0';
+ return ctx->stdin.line;
+
+ case from_files_list:
+ if (ctx->files_list.next >= opts->n_files)
+ goto done;
+ return opts->files[ctx->files_list.next++];
+ }
+ err(EX_SOFTWARE, __FILE__ ":%d - buggy", __LINE__);
done:
- free(*aux);
- *aux = NULL;
- return NULL;
+ free(*aux);
+ *aux = NULL;
+ return NULL;
}
-static int run(const options_t *opts)
+static int
+run(const options_t *opts)
{
- void *aux = NULL;
- const char *file;
+ void *aux = NULL;
+ const char *file;
- while (file = iter_files(opts, &aux), file)
- warnx("[%s]", file);
+ while (file = iter_files(opts, &aux), file)
+ warnx("[%s]", file);
- return 0;
+ return 0;
}
-int main(int argc, char **argv)
+int
+main(int argc, char **argv)
{
- options_t opts;
+ options_t opts;
- opts = read_opts(argc, argv);
- return run(&opts);
+ opts = read_opts(argc, argv);
+ return run(&opts);
}