commit: bbff1e6aaf0d715b6db384fa80e94dcb559bc855
parent: 6e978c8c493faf4de6e9b7f5c80e148be2a43ccc
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sun, 1 Dec 2019 19:42:02 +0100
Add clang-format
Diffstat:
3 files changed, 44 insertions(+), 10 deletions(-)
diff --git a/.clang-format b/.clang-format
@@ -0,0 +1,21 @@
+AlignAfterOpenBracket: true
+AlignConsecutiveAssignments: true
+AlignOperands: true
+AlignTrailingComments: true
+AllowShortCaseLabelsOnASingleLine: true
+AllowShortFunctionsOnASingleLine: true
+AllowShortIfStatementsOnASingleLine: true
+AlwaysBreakAfterReturnType: AllDefinitions
+BinPackArguments: false
+BinPackParameters: false
+BreakBeforeBraces: Allman
+SpaceBeforeParens: Never
+IncludeBlocks: Regroup
+ReflowComments: false
+SortIncludes: true
+UseTab: ForIndentation
+IndentWidth: 2
+TabWidth: 2
+ColumnLimit: 100
+
+NamespaceIndentation: All
diff --git a/Makefile b/Makefile
@@ -1,7 +1,13 @@
+.POSIX:
+
EXE = day1
CFLAGS = -std=c99 -lm -Wall -Wextra -D_POSIX_C_SOURCE=200809L
all: $(EXE)
+.PHONY: clean
clean:
rm $(EXE)
+
+format: *.c
+ clang-format -style=file -assume-filename=.clang-format -i *.c
diff --git a/day1.c b/day1.c
@@ -1,19 +1,23 @@
-#include <math.h> /* lround() */
-#include <fenv.h> /* fesetround(), FE_DOWNWARD */
#include <assert.h> /* assert() */
-#include <stdio.h> /* printf(), getline() */
+#include <fenv.h> /* fesetround(), FE_DOWNWARD */
+#include <math.h> /* lround() */
+#include <stdio.h> /* printf(), getline() */
#include <stdlib.h> /* atol() */
-long int fuel_required(long int mass) {
+long int
+fuel_required(long int mass)
+{
long int result;
fesetround(FE_DOWNWARD);
- result = (lround(mass/3)-2);
+ result = (lround(mass / 3) - 2);
return result;
}
-long int fuel_fuel(long int input) {
+long int
+fuel_fuel(long int input)
+{
long int result;
result = fuel_required(input);
@@ -24,12 +28,15 @@ long int fuel_fuel(long int input) {
return result + fuel_fuel(result);
}
-int main(void) {
- char *line_mass = NULL;
- size_t len = 0;
+int
+main(void)
+{
+ char *line_mass = NULL;
+ size_t len = 0;
long int modules_total = 0, grand_total = 0, module_fuel;
- while(getline(&line_mass, &len, stdin) != -1) {
+ while(getline(&line_mass, &len, stdin) != -1)
+ {
module_fuel = fuel_required(atol(line_mass));
modules_total += module_fuel;
grand_total += module_fuel + fuel_fuel(module_fuel);