payredu

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

csv_export.c (1685B)


      1 #include <stdio.h>
      2 #include <book.h>
      3 
      4 /* TEST_INPUT
      5 october-2023.txt
      6 TEST_INPUT */
      7 
      8 int main(int argc, char* argv[]) {
      9 	char* content = (char*)malloc(10000);
     10 	size_t content_len = 0;
     11 	//if (argc < 2) {
     12 	//	fprintf(stderr, "Usage: %s filename.txt\n", argv[0]);
     13 	//	return 1;
     14 	//}
     15 	//FILE* fp = fopen(argv[1], "r");
     16 	FILE* fp = fopen("october-2023.txt", "r");
     17 	if (fp == NULL) {
     18 		printf("Cannot open file\n");
     19 		goto export_csv_cleanup;
     20 	}
     21 	size_t content_read = 0;
     22 	char* content_ptr = content;
     23 	while ( (content_read = fread(content_ptr, 1, 1, fp)) != 0) {
     24 		content_ptr += content_read;
     25 	}
     26 	content_len = content_ptr - content;
     27 
     28 	printf("%s\n%ld", content, content_len);
     29 
     30 	ledger_parse_data(content, content_len);
     31 
     32 export_csv_cleanup:
     33 	if (fp != NULL) fclose(fp);
     34 	return 0;
     35 }
     36 
     37 /* TEST_OUTPUT
     38 "2015/10/12","","Exxon","Liabilities:MasterCard","$","-10","",""
     39 "2015/10/12","","Exxon","Expenses:Auto:Gas","$","10","",""
     40 "2015/10/12","","Donna's Cake World","Liabilities:Credit","$","-5","",""
     41 "2015/10/12","","Donna's Cake World","Expenses:Food:Dessert","$","5","",""
     42 "2024/10/25","","Zaitoon","Liabilities:Credit","$","-5","",""
     43 "2024/10/25","","Zaitoon","Expenses:Food:Dinner","$","5","",""
     44 "2024/10/24","","Donna's Cake World","Expenses:Food:Dessert","$","5","",""
     45 "2024/10/24","","Donna's Cake World","Expenses:Food:Dinner","$","19","",""
     46 "2024/10/24","","Donna's Cake World","Assets:Cash","$","-24","",""
     47 "2015/10/12","","Zoho","Income:Salary","$","-10000","",""
     48 "2015/10/12","","Zoho","Assets:Bank:Checking","$","10000","",""
     49 "2025/10/20","","Old loan from friend","Assets:Cash","$","200","",""
     50 "2025/10/20","","Old loan from friend","Friend:Cash","$","-200","",""
     51 TEST_OUTPUT */