From bb62e6e9f46f2009a9b09d8b3f106a7470ffb0f2 Mon Sep 17 00:00:00 2001 From: dam Date: Wed, 25 Jan 2023 00:01:15 +0000 Subject: Initial tests in jai. --- ttt.jai | 116 +++++++++++++++++++++++----------------------------------------- 1 file changed, 42 insertions(+), 74 deletions(-) (limited to 'ttt.jai') diff --git a/ttt.jai b/ttt.jai index a2a4e8f..fd39bb3 100644 --- a/ttt.jai +++ b/ttt.jai @@ -14,90 +14,47 @@ // this program. If not, see . -// Compilation commands: -// - debug : jai ttt.jai -exe ttt -// - release : jai ttt.jai -exe ttt -x64 -release -// -// Compiler flags: -// -l : libraries to link -// -o : output file name -// -Wall : enables all compiler's warning messages -// -Werror : make all warnings into errors -// -pedantic : issue all the warnings demanded by strict ISO C -// -O : code optimization level (commonly accepted as best: 2) -// -g : debug information level (max: 3) -// -m64 : 64b architecture -// -D : defines for preprocessor -// -static-pie : link statically producing an position-independent executable -// -DNDEBUG : remove assertions from code (not used) - -/* -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -*/ - -// #define VERSION "2.0" // Use only 3 chars (to fit layouts). -VERSION :: "2.0"; -// #define TASK_NAME_LENGTH 57 // Task name length. +VERSION :: "2.0"; // Use only 3 chars (to fit layouts). TASK_NAME_LENGTH :: 57; -// #define TASK_NAME_BYTES (TASK_NAME_LENGTH+1) -TASK_NAME_BYTES :: #run TASK_NAME_LENGTH+1; -// #define FIRST_DAY_OF_WEEK 1 // (0-6, Sunday = 0). -FIRST_DAY_OF_WEEK :: 1; -// #define NUM_WEEK_DAYS 7 // Just to be more clear about what we're looping about. -NUM_WEEK_DAYS :: 7; +TASK_NAME_BYTES :: #run TASK_NAME_LENGTH+1; // TODO Get rid of this! +FIRST_DAY_OF_WEEK :: 1; // (0-6, Sunday = 0). +NUM_WEEK_DAYS :: 7; // Just to be more clear about what we're looping about. + +APP_FOLDER_NAME :: ".task_time_tracker"; +DB_FILE_NAME :: "database.bin"; +AR_FILE_NAME :: "archive.csv"; + +DB_FILE_SIGN_STR :: "TTT:B:02"; +SECONDS_IN_MINUTE :: cast(s64)60; +SECONDS_IN_HOUR :: cast(s64)60*SECONDS_IN_MINUTE; +SECONDS_IN_DAY :: cast(s64)24*SECONDS_IN_HOUR; +SECONDS_IN_YEAR :: cast(s64)365*SECONDS_IN_DAY; +MAX_DATABASE_TASKS :: S64_MAX; + +Task :: struct { + times : [NUM_WEEK_DAYS] s64; + name : [TASK_NAME_BYTES] u8; // TODO Start using strings. +} -/* -#if defined(_WIN64) -#define HOME_PATH_ENV "USERPROFILE" -#else -#define HOME_PATH_ENV "HOME" -#endif -#define APP_FOLDER_NAME ".task_time_tracker" -#define DB_FILE_NAME "database.bin" -#define AR_FILE_NAME "archive.csv" +Database :: struct { + active_task : *~s64 Task = null; + selected_task : *~s64 Task = null; + tasks : [..] Task; + modified_on : s64; + total_times : [NUM_WEEK_DAYS] s64; +// size_t count; // Will always be equal or less than capacity. TODO Will this be necessary? +} -typedef struct { - int64_t times[NUM_WEEK_DAYS]; - char name[TASK_NAME_BYTES]; -} task_st; -typedef struct { - task_st *tasks; - size_t count; // Will always be equal or less than capacity. - size_t capacity; // Will always be equal or less than PTRDIFF_MAX (see MAX_DATABASE_TASKS). - ptrdiff_t active_task; // Will always be less than capacity/count. - ptrdiff_t selected_task; // Will always be less than capacity/count. - int64_t modified_on; - int64_t total_times[NUM_WEEK_DAYS]; -} database_st; - -#define DB_FILE_SIGN_STR "TTT:B:01" + +/* const char DB_FILE_SIGN[] = DB_FILE_SIGN_STR; const size_t DB_FILE_SIGN_LENGTH = sizeof(DB_FILE_SIGN_STR)-1; const size_t SIZEOF_TASK_ST = sizeof(task_st); const size_t SIZEOF_DATABASE_ST = sizeof(database_st); const size_t SIZEOF_CHAR = sizeof(char); const size_t SIZEOF_INT64 = sizeof(int64_t); -const int64_t SECONDS_IN_MINUTE = (int64_t)60; -const int64_t SECONDS_IN_HOUR = (int64_t)60*SECONDS_IN_MINUTE; -const int64_t SECONDS_IN_DAY = (int64_t)24*SECONDS_IN_HOUR; -const int64_t SECONDS_IN_YEAR = (int64_t)365*SECONDS_IN_DAY; -const size_t MAX_DATABASE_TASKS = (PTRDIFF_MAX < (SIZE_MAX / SIZEOF_TASK_ST)) ? PTRDIFF_MAX : (SIZE_MAX / SIZEOF_TASK_ST); + database_st database = { .tasks = NULL }; @@ -1865,8 +1822,19 @@ int main(int argc, char *argv[]) { */ #import "Basic"; +#import "System"; +#import "File_Utilities"; + +homie : string; main :: () { + + print("TNL %\n", TASK_NAME_LENGTH); + print("TNB %\n", TASK_NAME_BYTES); + + home, success := get_home_directory(); + print("home '%' | success '%'\n", home, success); + print("Task Time Tracker version %\n", VERSION); print("Copyright 2022 Daniel Martins\n"); print("License GPL-3.0-or-later\n"); -- cgit v1.2.3