clang-format src/*
This commit is contained in:
105
.clang-format
105
.clang-format
@@ -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
|
|
||||||
@@ -39,7 +39,7 @@ bool book_add_sheet(struct book *b)
|
|||||||
|
|
||||||
b->n_sheets++;
|
b->n_sheets++;
|
||||||
|
|
||||||
void* tmp = realloc(b->sheets, sizeof(struct sheet*) * (b->n_sheets + 1));
|
void *tmp = realloc(b->sheets, sizeof(struct sheet *) * (b->n_sheets + 1));
|
||||||
if (tmp == NULL)
|
if (tmp == NULL)
|
||||||
return false;
|
return false;
|
||||||
b->sheets = tmp;
|
b->sheets = tmp;
|
||||||
@@ -49,7 +49,7 @@ bool book_add_sheet(struct book *b)
|
|||||||
s = malloc(sizeof(struct sheet));
|
s = malloc(sizeof(struct sheet));
|
||||||
sheet_init(s, DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_SHEET_TITLE);
|
sheet_init(s, DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_SHEET_TITLE);
|
||||||
|
|
||||||
b->sheets[b->n_sheets-1] = s;
|
b->sheets[b->n_sheets - 1] = s;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
@@ -11,7 +11,7 @@ void cell_init(struct cell *c, size_t x, size_t y, enum cell_type type)
|
|||||||
c->x_pos = x;
|
c->x_pos = x;
|
||||||
c->y_pos = y;
|
c->y_pos = y;
|
||||||
c->type = type;
|
c->type = type;
|
||||||
c->text = calloc(1,1);
|
c->text = calloc(1, 1);
|
||||||
c->value.integer = 0;
|
c->value.integer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ void cell_delete(struct cell *c)
|
|||||||
void cell_set_type(struct cell *cell)
|
void cell_set_type(struct cell *cell)
|
||||||
{
|
{
|
||||||
if (cell->text[0] == '=') {
|
if (cell->text[0] == '=') {
|
||||||
//cell_parse_function(cell);
|
// cell_parse_function(cell);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -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
|
||||||
|
|||||||
39
src/draw.c
39
src/draw.c
@@ -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;
|
||||||
}
|
}
|
||||||
@@ -77,7 +81,7 @@ void draw_init(struct book *book)
|
|||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_cell(struct cell const * const cell)
|
void draw_cell(struct cell const *const cell)
|
||||||
{
|
{
|
||||||
int x = x_pos(cell->x_pos);
|
int x = x_pos(cell->x_pos);
|
||||||
int y = y_pos(cell->y_pos);
|
int y = y_pos(cell->y_pos);
|
||||||
@@ -88,7 +92,7 @@ void draw_cell(struct cell const * const cell)
|
|||||||
|
|
||||||
attron(COLOR_PAIR(color));
|
attron(COLOR_PAIR(color));
|
||||||
|
|
||||||
switch(cell->type){
|
switch (cell->type) {
|
||||||
case Integer:
|
case Integer:
|
||||||
printw("%" STR(CELL_SIZE) "li", cell->value.integer);
|
printw("%" STR(CELL_SIZE) "li", cell->value.integer);
|
||||||
break;
|
break;
|
||||||
@@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ void draw_init(struct book *book);
|
|||||||
|
|
||||||
void draw_book(struct book *b, size_t tab);
|
void draw_book(struct book *b, size_t tab);
|
||||||
|
|
||||||
void draw_cell(struct cell const * const cell);
|
void draw_cell(struct cell const *const cell);
|
||||||
|
|
||||||
void draw_left_status(const char *const s);
|
void draw_left_status(const char *const s);
|
||||||
|
|
||||||
|
|||||||
@@ -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[] = {
|
||||||
"+",
|
"+",
|
||||||
@@ -32,7 +32,7 @@ enum type {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct token {
|
struct token {
|
||||||
char const * value;
|
char const *value;
|
||||||
size_t value_len;
|
size_t value_len;
|
||||||
enum type type;
|
enum type type;
|
||||||
};
|
};
|
||||||
@@ -45,9 +45,10 @@ 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) {
|
||||||
return strlen(s);
|
return strlen(s);
|
||||||
}
|
}
|
||||||
@@ -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,15 +134,14 @@ 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;
|
||||||
|
|
||||||
for(size_t i=0; str[i] != '\0'; i++)
|
for (size_t i = 0; str[i] != '\0'; i++)
|
||||||
hash = hash * 33 + c;
|
hash = hash * 33 + c;
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,4 @@
|
|||||||
#ifndef FUNCTION_PARSE_H
|
#ifndef FUNCTION_PARSE_H
|
||||||
#define FUNCTION_PARSE_H
|
#define FUNCTION_PARSE_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
|
|
||||||
#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;
|
||||||
int g_tab = 0;
|
int g_tab = 0;
|
||||||
//int g_right_scrolled = 0;
|
// int g_right_scrolled = 0;
|
||||||
//int g_down_scrolled = 0;
|
// int g_down_scrolled = 0;
|
||||||
|
|
||||||
struct book *g_book = NULL;
|
struct book *g_book = NULL;
|
||||||
struct cell *g_cur = NULL;
|
struct cell *g_cur = NULL;
|
||||||
@@ -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,
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
15
src/keymap.c
15
src/keymap.c
@@ -6,12 +6,12 @@
|
|||||||
|
|
||||||
#define KEY_ESC 27
|
#define KEY_ESC 27
|
||||||
|
|
||||||
static void * const keymap_always[1024] = {
|
static void *const keymap_always[1024] = {
|
||||||
[KEY_RESIZE] = interface_handle_resize,
|
[KEY_RESIZE] = interface_handle_resize,
|
||||||
[27] /*ESC*/ = interface_mode_normal,
|
[27] /*ESC*/ = interface_mode_normal,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void * const keymap_normal[1024] = {
|
static void *const keymap_normal[1024] = {
|
||||||
['i'] = interface_mode_edit,
|
['i'] = interface_mode_edit,
|
||||||
['a'] = interface_mode_edit,
|
['a'] = interface_mode_edit,
|
||||||
['g'] = interface_mode_g,
|
['g'] = interface_mode_g,
|
||||||
@@ -25,17 +25,18 @@ static void * const keymap_normal[1024] = {
|
|||||||
['l'] = interface_move_right,
|
['l'] = interface_move_right,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void * const keymap_edit[1024] = {
|
static void *const keymap_edit[1024] = {
|
||||||
[KEY_ESC] = interface_mode_normal,
|
[KEY_ESC] = interface_mode_normal,
|
||||||
[KEY_BACKSPACE] = interface_editor_backspace,
|
[KEY_BACKSPACE] = interface_editor_backspace,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void * const keymap_g[1024] = {
|
static void *const keymap_g[1024] = {
|
||||||
['t'] = interface_next_tab,
|
['t'] = interface_next_tab,
|
||||||
['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);
|
||||||
@@ -55,7 +56,7 @@ void keymap_parse_key(size_t c, enum modes mode)
|
|||||||
break;
|
break;
|
||||||
case Edit:
|
case Edit:
|
||||||
cmd = keymap_edit[c];
|
cmd = keymap_edit[c];
|
||||||
if (cmd == NULL){
|
if (cmd == NULL) {
|
||||||
interface_editor_append(c);
|
interface_editor_append(c);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -65,7 +66,7 @@ void keymap_parse_key(size_t c, enum modes mode)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mode != Edit) {
|
if (mode != Edit) {
|
||||||
mode = Command;
|
mode = Command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
12
src/sheet.h
12
src/sheet.h
@@ -1,20 +1,20 @@
|
|||||||
#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;
|
||||||
size_t width;
|
size_t width;
|
||||||
size_t height;
|
size_t height;
|
||||||
char* title;
|
char *title;
|
||||||
};
|
};
|
||||||
|
|
||||||
void sheet_init(struct sheet *s, size_t width, size_t height, char* title);
|
void sheet_init(struct sheet *s, size_t width, size_t height, char *title);
|
||||||
void sheet_delete(struct sheet *s);
|
void sheet_delete(struct sheet *s);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user