payredu

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

commit cef3db4146df8098f4ded73302c4bb789d3cd419
parent 2301cc52f4caf6eabbf297fbd967c39903dc222b
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date:   Wed, 25 Oct 2023 03:45:34 +0530

Rename the project to 'peredu'

Add basic parsing in book.c

Diffstat:
MMakefile | 7+++----
MREADME | 15++++++++++-----
Mbalance.c | 2+-
Mbook.c | 81++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Ahot.sh | 3+++
Ahotbook | 0
Mhotbook.c | 28+++++++++++++++++++++-------
7 files changed, 116 insertions(+), 20 deletions(-)

diff --git a/Makefile b/Makefile @@ -19,13 +19,12 @@ balance: balance.c ledger.h hot: hot.c libbalance.so +libbook.so: book.c book.h + hotbook: hotbook.c libbook.so refresh: - git ls-files | entr make libbook.so - -autorefresh: - ls libbook.so | entr kill -3 $$(pgrep hot) + git ls-files | entr sh hot.sh clean: -rm $$(cat .gitignore) diff --git a/README b/README @@ -1,15 +1,20 @@ -balance -======= +peredu +====== +பேரேடு +====== -balance is a cross-platform frontend to ledger(pta) with emphasis on simplicity. It is written in c99 and works on top of nuklear making it lightweigt and fast. +peredu is a cross-platform frontend to ledger(pta) with emphasis on simplicity. perudu means ledger in Tamil. It is written in c99 and works on top of nuklear making it lightweigt and fast. NOTE: The quality of the software is beta in the least, it's still in development. -It is configu +For now the following commands work, + + ledger balance -f file.txt [-b 2023/01/01] [-e 2023/01/31] -S [date|amount] [register query ...] + Build ----- make -will generate the 'hot' which you can use to +will generate 'hotbook' which you can use to start the motor diff --git a/balance.c b/balance.c @@ -18,7 +18,7 @@ #include <nuklear.h> #include <nuklear_glfw_gl2.h> -#include "ledger.h" +#include "book.h" float your_text_width_calculation(nk_handle handle, float height, const char *text, int len) { return 10.0f; diff --git a/book.c b/book.c @@ -1,7 +1,7 @@ #include <stdio.h> #include <stddef.h> #include <stdlib.h> -#include <time.h> +#include <inttypes.h> #include "common.h" #include <GLFW/glfw3.h> @@ -18,14 +18,89 @@ #include <nuklear.h> #include <nuklear_glfw_gl2.h> +#define _XOPEN_SOURCE +#include <time.h> + #include "book.h" float your_text_width_calculation(nk_handle handle, float height, const char *text, int len) { return 10.0f; } +char* tags[100]; + +/* +char* tags = { + "Expenses:Auto:Gas", + "Liabilities:MasterCard", + "Assets:Credit" + }; +*/ + +/** + * +read the file | parse for newlines +2023/10/24 - 5, fptr + 0, fptr + 6, fptr + 9 +Entry* entry = get_entry("2023/10/24"); + +skip \n +read until date, and read until from + +**/ + +// commodity max size 256 +// commodity name max size 4 +char commodity_list[256][4]; + +typedef struct { + time_t date; // the date associated with the entry + char* from; + size_t from_len; + short from_denom; + long from_amount; + char* to; + size_t to_len; + short to_denom; + long to_amount; +} LedgerEntry; + + +time_t ledger_timestamp_from_ledger_date(const char* date_str) { + // coneverts string 'YYYY-MM-DD' to unix timestamp + // date_str should be exactly 10 characters + assert(strlen(date_str) == 10); + struct tm tm; + tm.tm_year = 2023;//strtoi(date_str, date_str + 10, 0, 0, 3); + printf("%d", tm.tm_year); + return 0; +} + +void ledger_parse_data(const char* text, size_t text_len) { + time_t t = time(NULL); + for(int c = 0; c < text_len; c++) { + switch(text[c]) { + case ';': + printf("#"); + break; + case ' ': + printf(" "); + break; + case ' ': + printf(" "); + break; + case '\n': + printf(",\n"); + break; + default: + printf("*"); + break; + } + } + return; +} +void* module_main(const char* data, size_t data_len) { + printf("%s\n", data); -void* module_main(struct nk_context* ctx, int width, int height) { - printf("this is us\n"); + ledger_parse_data(data, data_len); } diff --git a/hot.sh b/hot.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +make libbook.so hotbook.c && kill -3 $(pgrep hot) diff --git a/hotbook b/hotbook Binary files differ. diff --git a/hotbook.c b/hotbook.c @@ -3,14 +3,16 @@ #include <stdlib.h> #include <dlfcn.h> #include <signal.h> +#include <unistd.h> #include "common.h" #define MAX_MEMORY 4064 #define WINDOW_WIDTH 512 #define WINDOW_HEIGHT 512 +#define BUFFER_SIZE 256 -int should_exit = 1; +int should_exit = 0; void sig_handle() { printf("Reloaded\n"); @@ -18,21 +20,33 @@ void sig_handle() { should_exit = 1; } -typedef void* (*module_main_func)(void*, int, int); +typedef void* (*module_main_func)(const char*, size_t); int main(int argc, char* argv[]) { - signal(SIGQUIT, sig_handle); - while(1) { - void* module = dlopen("./libbalance.so", RTLD_NOW); + signal(SIGQUIT, sig_handle); while(1) { + void* module = dlopen("./libbook.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 = dlopen("./libbook.so", RTLD_NOW); } module_main_func module_main = dlsym(module, "module_main"); - dlclose(module); + FILE* in = fopen("october-2023.txt", "r"); + char* data = (char*)malloc(2048 * sizeof(char)); + size_t data_size = 0; + size_t c_read = 0; + while((c_read = fread(data, 1, BUFFER_SIZE, in)) != 0) { + data_size += c_read; + } + if (ferror(in)) fprintf(stderr, "Error reading file\n"); + module_main(data, data_size); + while(should_exit == 0) { + sleep(1); + } should_exit = 0; + dlclose(module); + fprintf(stderr, "Continue?\n"); } return 0;