clang-format src/*

This commit is contained in:
2023-08-18 17:18:23 +02:00
parent 2712a1bf3e
commit 17a439b415
18 changed files with 149 additions and 244 deletions

View File

@@ -2,109 +2,12 @@
# modified .clang-format from # modified .clang-format from
# https://github.com/torvalds/linux/blob/master/.clang-format # https://github.com/torvalds/linux/blob/master/.clang-format
AccessModifierOffset: -4 BasedOnStyle: WebKit
AlignAfterOpenBracket: Align AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false AlignConsecutiveDeclarations: true
AlignEscapedNewlines: Left AlignEscapedNewlines: Left
AlignOperands: true AlignOperands: true
AlignTrailingComments: false AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: true
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: false
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentGotoLabels: false
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
# Taken from git's rules
PenaltyBreakAssignment: 10
PenaltyBreakBeforeFirstCallParameter: 30
PenaltyBreakComment: 10
PenaltyBreakFirstLessLess: 0
PenaltyBreakString: 10
PenaltyExcessCharacter: 100
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right PointerAlignment: Right
ReflowComments: false
SortIncludes: false
SortUsingDeclarations: false
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatementsExceptForEachMacros
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 4

View File

@@ -1,6 +1,6 @@
#include "cell.h" #include "cell.h"
#include <stdlib.h>
#include <err.h> #include <err.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
void cell_parse_function(struct cell *cell); void cell_parse_function(struct cell *cell);

View File

@@ -1,17 +1,15 @@
#ifndef CELL_H #ifndef CELL_H
#define CELL_H #define CELL_H
#include "common.h"
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <time.h> #include <time.h>
#include "common.h"
enum cell_type { enum cell_type { Text,
Text,
Integer, Integer,
Floating, Floating,
Date Date };
};
struct cell_list { struct cell_list {
struct cell *cell; struct cell *cell;

View File

@@ -1,10 +1,11 @@
#include "celltree.h" #include "celltree.h"
#include <stdlib.h>
#include <errno.h>
#include <err.h> #include <err.h>
#include <errno.h>
#include <stdlib.h>
/* returns true if (ax,ay) `greater than` (bx,by) */ /* returns true if (ax,ay) `greater than` (bx,by) */
static bool greater_than(int x_a, int y_a, int x_b, int y_b) static bool
greater_than(int x_a, int y_a, int x_b, int y_b)
{ {
if (x_a == x_b) if (x_a == x_b)
return y_a > y_b; return y_a > y_b;
@@ -25,7 +26,8 @@ void celltree_delete(struct celltree *root)
free(root); free(root);
} }
struct cell* celltree_search(struct celltree *root, size_t x, size_t y) struct cell *
celltree_search(struct celltree *root, size_t x, size_t y)
{ {
if (root == NULL) { if (root == NULL) {
return NULL; return NULL;

View File

@@ -1,8 +1,8 @@
#ifndef CELLTREE_H #ifndef CELLTREE_H
#define CELLTREE_H #define CELLTREE_H
#include <stdbool.h>
#include "cell.h" #include "cell.h"
#include <stdbool.h>
/* TODO: implement red-black tree */ /* TODO: implement red-black tree */
struct celltree { struct celltree {

View File

@@ -2,6 +2,8 @@
#ifndef COMMON_H #ifndef COMMON_H
#define COMMON_H #define COMMON_H
enum modes {Edit, Command, G}; enum modes { Edit,
Command,
G };
#endif #endif

View File

@@ -9,7 +9,6 @@
#define DEFAULT_WIDTH 80 #define DEFAULT_WIDTH 80
#define MAX_STR 64 #define MAX_STR 64
// dimensions // dimensions
#define CELL_SIZE 12 #define CELL_SIZE 12
#define TAB_SIZE 24 #define TAB_SIZE 24
@@ -17,7 +16,6 @@
#define N_CELLS_WIDTH 5 #define N_CELLS_WIDTH 5
#define N_CELLS_HEIGHT 5 #define N_CELLS_HEIGHT 5
// colors // colors
#define COLOR_TITLE 20 #define COLOR_TITLE 20
#define COLOR_BACKGROUND 21 #define COLOR_BACKGROUND 21

View File

@@ -11,7 +11,8 @@
#define _STR(x) #x #define _STR(x) #x
#define STR(x) _STR(x) #define STR(x) _STR(x)
static void cleanup() static void
cleanup()
{ {
clear(); clear();
echo(); echo();
@@ -20,17 +21,20 @@ static void cleanup()
endwin(); endwin();
} }
static int x_pos(int x) static int
x_pos(int x)
{ {
return x * CELL_SIZE + Y_AXIS_WIDTH; return x * CELL_SIZE + Y_AXIS_WIDTH;
} }
static int y_pos(int y) static int
y_pos(int y)
{ {
return y + 2; return y + 2;
} }
static int get_cell_color(int const row, int const col) static int
get_cell_color(int const row, int const col)
{ {
return (row + col) % 2 ? COLOR_LIGHTER_GRAY : COLOR_LIGHT_GRAY; return (row + col) % 2 ? COLOR_LIGHTER_GRAY : COLOR_LIGHT_GRAY;
} }
@@ -103,7 +107,8 @@ void draw_cell(struct cell const * const cell)
attroff(COLOR_PAIR(color)); attroff(COLOR_PAIR(color));
} }
static void draw_celltree(struct celltree const *const root) static void
draw_celltree(struct celltree const *const root)
{ {
if (root == NULL) { if (root == NULL) {
return; return;
@@ -114,14 +119,16 @@ static void draw_celltree(struct celltree const *const root)
draw_celltree(root->left); draw_celltree(root->left);
} }
static void draw_row_num(int n) static void
draw_row_num(int n)
{ {
attron(COLOR_PAIR(COLOR_GRAY)); attron(COLOR_PAIR(COLOR_GRAY));
printw("%" STR(Y_AXIS_WIDTH) "d", n); printw("%" STR(Y_AXIS_WIDTH) "d", n);
attroff(COLOR_PAIR(COLOR_GRAY)); attroff(COLOR_PAIR(COLOR_GRAY));
} }
static void draw_row_header(int row) static void
draw_row_header(int row)
{ {
// TODO: make it dynamic // TODO: make it dynamic
char buf[4] = " "; char buf[4] = " ";
@@ -139,7 +146,8 @@ static void draw_row_header(int row)
attroff(COLOR_PAIR(COLOR_GRAY)); attroff(COLOR_PAIR(COLOR_GRAY));
} }
static void draw_sheet(struct sheet *s) static void
draw_sheet(struct sheet *s)
{ {
addch('\n'); addch('\n');
@@ -164,9 +172,7 @@ static void draw_sheet(struct sheet *s)
attron(COLOR_PAIR(color)); attron(COLOR_PAIR(color));
mvprintw(y_pos(row), mvprintw(y_pos(row), x_pos(col), "%" STR(CELL_SIZE) "s", " ");
x_pos(col),
"%" STR(CELL_SIZE) "s", " ");
} }
attroff(COLOR_PAIR(color)); attroff(COLOR_PAIR(color));
} }
@@ -175,7 +181,8 @@ static void draw_sheet(struct sheet *s)
draw_celltree(s->root_cell); draw_celltree(s->root_cell);
} }
static void draw_input_bar() static void
draw_input_bar()
{ {
int width, height; int width, height;
@@ -215,8 +222,7 @@ void draw_highlight(int const x, int const y)
static int prev_y; static int prev_y;
int color; int color;
mvchgat(y_pos(y), x_pos(x), CELL_SIZE, 0, COLOR_HIGHLIGHTED, mvchgat(y_pos(y), x_pos(x), CELL_SIZE, 0, COLOR_HIGHLIGHTED, NULL);
NULL);
color = get_cell_color(prev_y, prev_x); color = get_cell_color(prev_y, prev_x);
@@ -244,4 +250,3 @@ void draw_right_status(char const *const s)
mvprintw(y - 1, x - 1 - strlen(s), "%s", s); mvprintw(y - 1, x - 1 - strlen(s), "%s", s);
attron(COLOR_PAIR(COLOR_TITLE)); attron(COLOR_PAIR(COLOR_TITLE));
} }

View File

@@ -3,8 +3,8 @@
#define DRAW_H #define DRAW_H
#include "book.h" #include "book.h"
#include <stddef.h>
#include "cell.h" #include "cell.h"
#include <stddef.h>
void draw_highlight(int const x, int const y); void draw_highlight(int const x, int const y);

View File

@@ -1,10 +1,10 @@
#include <ctype.h> #include <ctype.h>
#include <errno.h>
#include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdbool.h>
#include <errno.h>
static char *operators[] = { static char *operators[] = {
"+", "+",
@@ -45,7 +45,8 @@ struct token_list {
// returns length of string in haystack matching needle, or 0 if it // returns length of string in haystack matching needle, or 0 if it
// doesn't exist // doesn't exist
static int contains(char * const *haystack, char* needle) static int
contains(char *const *haystack, char *needle)
{ {
for (char *s = *haystack; s; s++) { for (char *s = *haystack; s; s++) {
if (strcmp(s, needle) == 0) { if (strcmp(s, needle) == 0) {
@@ -56,7 +57,8 @@ static int contains(char * const *haystack, char* needle)
return false; return false;
} }
static struct token eat(char **str, int (*f)(int), enum type type) static struct token
eat(char **str, int (*f)(int), enum type type)
{ {
struct token tok; struct token tok;
tok.type = type; tok.type = type;
@@ -71,18 +73,21 @@ static struct token eat(char **str, int (*f)(int), enum type type)
return tok; return tok;
} }
static struct token tokenize_identifier(char** str) static struct token
tokenize_identifier(char **str)
{ {
return eat(str, isalnum, identifier); return eat(str, isalnum, identifier);
} }
static struct token tokenize_number(char **str) static struct token
tokenize_number(char **str)
{ {
return eat(str, isdigit, identifier); return eat(str, isdigit, identifier);
} }
// Returns a token array from function // Returns a token array from function
static struct token_list tokenize(char *str) static struct token_list
tokenize(char *str)
{ {
struct token_list *tok_list = malloc(sizeof *tok_list); struct token_list *tok_list = malloc(sizeof *tok_list);
@@ -104,21 +109,17 @@ static struct token_list tokenize(char *str)
if (isalpha(*str)) { if (isalpha(*str)) {
t = tokenize_identifier(&str); t = tokenize_identifier(&str);
} } else if (!isalnum(*str)) {
else if (!isalnum(*str) ) {
t = tokenize_number(&str); t = tokenize_number(&str);
} } else if ((n = contains(operators, str))) {
else if ((n = contains(operators, str))) {
t.type = operator; t.type = operator;
t.value = str; t.value = str;
t.value_len = n; t.value_len = n;
} } else if ((n = contains(separators, str))) {
else if ((n = contains(separators, str))) {
t.type = separator; t.type = separator;
t.value = str; t.value = str;
t.value_len = n; t.value_len = n;
} } else {
else {
t.type = error; t.type = error;
t.value = str; t.value = str;
t.value_len = strlen(str); t.value_len = strlen(str);
@@ -133,7 +134,8 @@ static struct token_list tokenize(char *str)
// credits: Daniel J. Bernstein // credits: Daniel J. Bernstein
// https://web.archive.org/web/20220328102559/http://www.cse.yorku.ca/~oz/hash.html // https://web.archive.org/web/20220328102559/http://www.cse.yorku.ca/~oz/hash.html
static unsigned long hash(unsigned char *str) static unsigned long
hash(unsigned char *str)
{ {
unsigned long hash = 5381; unsigned long hash = 5381;
int c = 0; int c = 0;
@@ -143,5 +145,3 @@ static unsigned long hash(unsigned char *str)
return hash; return hash;
} }

View File

@@ -2,6 +2,4 @@
#ifndef FUNCTION_PARSE_H #ifndef FUNCTION_PARSE_H
#define FUNCTION_PARSE_H #define FUNCTION_PARSE_H
#endif #endif

View File

@@ -1,11 +1,11 @@
#include "interface.h" #include "interface.h"
#include "cell.h" #include "cell.h"
#include "celltree.h"
#include "draw.h"
#include "keymap.h"
#include <curses.h> #include <curses.h>
#include <stdlib.h> #include <stdlib.h>
#include "celltree.h"
#include "keymap.h"
#include "draw.h"
int g_display_sel_x = 0; int g_display_sel_x = 0;
int g_display_sel_y = 0; int g_display_sel_y = 0;
@@ -104,7 +104,8 @@ void interface_editor_append(const char c)
refresh(); refresh();
} }
static void start_edit_cell() static void
start_edit_cell()
{ {
// struct cell* cur // struct cell* cur
g_cur = celltree_search(g_book->sheets[g_tab]->root_cell, g_display_sel_x, g_cur = celltree_search(g_book->sheets[g_tab]->root_cell, g_display_sel_x,

View File

@@ -50,7 +50,6 @@ void interface_editor_append(const char c);
/* Remove last char */ /* Remove last char */
void interface_editor_backspace(); void interface_editor_backspace();
/* /*
* Mode switching * Mode switching
* -------------- * --------------
@@ -65,5 +64,4 @@ void interface_mode_edit();
/* switch to normal mode */ /* switch to normal mode */
void interface_mode_normal(); void interface_mode_normal();
#endif #endif

View File

@@ -35,7 +35,8 @@ static void * const keymap_g[1024] = {
['T'] = interface_prev_tab, ['T'] = interface_prev_tab,
}; };
static void undefined() static void
undefined()
{ {
int height = getmaxy(stdscr); int height = getmaxy(stdscr);
move(height - 1, 0); move(height - 1, 0);

View File

@@ -1,13 +1,12 @@
#include "book.h" #include "book.h"
#include "draw.h"
#include "config.h" #include "config.h"
#include "draw.h"
#include "interface.h" #include "interface.h"
#include "sheet.h" #include "sheet.h"
#include <curses.h> #include <curses.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
(void)argv; (void)argv;

View File

@@ -1,11 +1,11 @@
#ifndef SHEET_H #ifndef SHEET_H
#define SHEET_H #define SHEET_H
#include <stddef.h>
#include <string.h>
#include <stdlib.h>
#include <err.h>
#include "config.h" #include "config.h"
#include <err.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
struct sheet { struct sheet {
struct celltree *root_cell; struct celltree *root_cell;