payredu

Cross-platform ledger GUI written in c99
git clone git@getsh.org:payredu.git
Log | Files | Refs | README

commit 2301cc52f4caf6eabbf297fbd967c39903dc222b
parent 9ec4db1998f2d106227c4e57746cc3cf587d9e47
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date:   Sun, 22 Oct 2023 19:09:20 +0530

Add book.c for ledger operations

Diffstat:
MMakefile | 8+++++---
Abook.c | 31+++++++++++++++++++++++++++++++
Abook.h | 33+++++++++++++++++++++++++++++++++
Ahotbook.c | 39+++++++++++++++++++++++++++++++++++++++
Dledger.h | 33---------------------------------
5 files changed, 108 insertions(+), 36 deletions(-)

diff --git a/Makefile b/Makefile @@ -2,7 +2,7 @@ GENERAL_FLAGS=-fPIC LDFLAGS=$(GENERAL_FLAGS) -lglfw -lGL -lm CFLAGS=$(GENERAL_FLAGS) -O0 -I. -g -Werror #-Wpedantic -.DEFAULT_GOAL=hot +.DEFAULT_GOAL=hotbook CC=tcc @@ -19,11 +19,13 @@ balance: balance.c ledger.h hot: hot.c libbalance.so +hotbook: hotbook.c libbook.so + refresh: - git ls-files | entr make libbalance.so + git ls-files | entr make libbook.so autorefresh: - ls libbalance.so | entr kill -3 $$(pgrep hot) + ls libbook.so | entr kill -3 $$(pgrep hot) clean: -rm $$(cat .gitignore) diff --git a/book.c b/book.c @@ -0,0 +1,31 @@ +#include <stdio.h> +#include <stddef.h> +#include <stdlib.h> +#include <time.h> +#include "common.h" + +#include <GLFW/glfw3.h> +#define NK_INCLUDE_FIXED_TYPES +#define NK_INCLUDE_STANDARD_IO +#define NK_INCLUDE_STANDARD_VARARGS +#define NK_INCLUDE_DEFAULT_ALLOCATOR +#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT +#define NK_INCLUDE_FONT_BAKING +#define NK_INCLUDE_DEFAULT_FONT +#define NK_IMPLEMENTATION +#define NK_GLFW_GL2_IMPLEMENTATION +#define NK_KEYSTATE_BASED_INPUT +#include <nuklear.h> +#include <nuklear_glfw_gl2.h> + +#include "book.h" + +float your_text_width_calculation(nk_handle handle, float height, const char *text, int len) { + return 10.0f; +} + + + +void* module_main(struct nk_context* ctx, int width, int height) { + printf("this is us\n"); +} diff --git a/book.h b/book.h @@ -0,0 +1,33 @@ +#include <string.h> +#include <stdlib.h> + +typedef struct { + char* name; +} Entity; + +typedef struct { + Entity* from; + Entity* to; + long long amt; +} Entry; + +Entity me = {"Account:Income"}; + +Entry** ledger_read_file(const char* filename, time_t date_start, time_t date_end) { + // list population, read from + FILE* file = fopen(filename, "r"); + if (file == NULL) { + printf("Failed to open file %s\n", filename); + } + Entry** new_list = (Entry**)malloc(sizeof(Entry*) * 12); + for(int i = 0; i < 12; i++) { + Entry* entry = (Entry*)malloc(sizeof(Entry)); + new_list[i] = entry; + entry->from = &me; + entry->to = (Entity*)malloc(sizeof(Entity)); + entry->to->name = (char*)malloc(sizeof(char*) * 20); + strcpy(entry->to->name, "Man"); + } + return new_list; +} + diff --git a/hotbook.c b/hotbook.c @@ -0,0 +1,39 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <dlfcn.h> +#include <signal.h> + +#include "common.h" + +#define MAX_MEMORY 4064 +#define WINDOW_WIDTH 512 +#define WINDOW_HEIGHT 512 + +int should_exit = 1; + +void sig_handle() { + printf("Reloaded\n"); + system("date"); + should_exit = 1; +} + +typedef void* (*module_main_func)(void*, int, int); + +int main(int argc, char* argv[]) { + signal(SIGQUIT, sig_handle); + while(1) { + void* module = dlopen("./libbalance.so", RTLD_NOW); + while(module == NULL){ + fprintf(stderr, "Failed to load module. (%s)\n", dlerror()); + fprintf(stderr, "Press return to try again.\n"); + getchar(); + module = dlopen("./libbalance.so", RTLD_NOW); + } + module_main_func module_main = dlsym(module, "module_main"); + dlclose(module); + should_exit = 0; + } + + return 0; +} diff --git a/ledger.h b/ledger.h @@ -1,33 +0,0 @@ -#include <string.h> -#include <stdlib.h> - -typedef struct { - char* name; -} Entity; - -typedef struct { - Entity* from; - Entity* to; - long long amt; -} Entry; - -Entity me = {"Account:Income"}; - -Entry** ledger_read_file(const char* filename, time_t date_start, time_t date_end) { - // list population, read from - FILE* file = fopen(filename, "r"); - if (file == NULL) { - printf("Failed to open file %s\n", filename); - } - Entry** new_list = (Entry**)malloc(sizeof(Entry*) * 12); - for(int i = 0; i < 12; i++) { - Entry* entry = (Entry*)malloc(sizeof(Entry)); - new_list[i] = entry; - entry->from = &me; - entry->to = (Entity*)malloc(sizeof(Entity)); - entry->to->name = (char*)malloc(sizeof(char*) * 20); - strcpy(entry->to->name, "Woman"); - } - return new_list; -} -