aboutsummaryrefslogtreecommitdiff
path: root/ttt.jai
diff options
context:
space:
mode:
Diffstat (limited to 'ttt.jai')
-rw-r--r--ttt.jai259
1 files changed, 101 insertions, 158 deletions
diff --git a/ttt.jai b/ttt.jai
index 4911cc1..c77f2a3 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -1,4 +1,4 @@
-// Copyright 2022 Daniel Martins
+// Copyright 2023 Daniel Martins
// License GPL-3.0-or-later
//
// This program is free software: you can redistribute it and/or modify it under
@@ -14,6 +14,12 @@
// this program. If not, see <https://www.gnu.org/licenses/>.
+#import "Basic";
+#import "System";
+#import "Math";
+#import "curses";
+// #import "File_Utilities";
+
VERSION :: "2.0"; // Use only 3 chars (to fit layouts).
TASK_NAME_LENGTH :: 57;
TASK_NAME_BYTES :: #run TASK_NAME_LENGTH+1; // TODO Get rid of this!
@@ -159,13 +165,14 @@ bool is_file_accessible(const char *path) {
}
return is_file_accessible;
}
+*/
// Returns true if string to_compare is equal to any of the other passed strings, false otherwise.
-bool is_equal_to_any(const char *to_compare, const char *test_a, const char *test_b) {
- return strncmp(to_compare, test_a, strlen(test_a)+1) == 0
- || strncmp(to_compare, test_b, strlen(test_b)+1) == 0;
+is_equal_to_any :: (to_compare :string, test_a :string, test_b :string) -> bool {
+ return to_compare == test_a || to_compare == test_b;
}
+/*
// Given an UTF8 encoded string, truncate it to length bytes without breaking any UTF8 character.
// The string should have capacity for at least length + 1.
// The terminating null byte ('\0') is not included in length.
@@ -1117,7 +1124,9 @@ void *mem_alloc(size_t mem_size, const char *error_tag) {
return mem_pointer;
}
-void free_memory() {
+*/
+free_memory :: () {
+ /* TODO
reset_database(&database);
reset_database(&archive);
@@ -1125,8 +1134,10 @@ void free_memory() {
free(app_folder); app_folder = NULL;
free(db_file_path); db_file_path = NULL;
free(ar_file_path); ar_file_path = NULL;
+ */
}
+/*
bool initialize_app_folder() {
size_t temp_size;
@@ -1223,9 +1234,11 @@ bool read_enter_confirmation(int row, int style, const char *message) {
return getch() == '\n';
}
+*/
-int main(int argc, char *argv[]) {
-
+
+main :: () {
+ /*
if (initialize_app_folder() == false) {
print_error("Failed to initialize app folder.");
free_memory();
@@ -1251,72 +1264,84 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}
}
+ */
- if (argc > 1) {
- bool is_exit_requested = false;
- for (unsigned idx = 1; idx < argc; idx++) {
- if (is_equal_to_any(argv[idx], "--help", "-h")) {
- fprintf(stdout,
- "Usage: ttt [OPTION]... [FILE]...\n"
- " -i, --import-csv [FILE] Import CSV file to database (discard first row).\n"
- " -e, --export-csv [FILE] Export database to CSV file.\n"
- " -n, --no-autosave Disable autosave feature (only save on exit).\n"
- " -h, --help Display this help and exit.\n"
- " -v, --version Output version information and exit.\n"
- "\n"
- "In app commands\n"
- " a, A Archive selected task (except if active).\n"
- " r, R Restore selected task from archive.\n"
- " t, T Select currently active task (if any).\n"
- " d, D Duplicate selected task.\n"
- " n, N Create new task.\n"
- " m, M Move selected task to position.\n"
- " g, G Select task by position.\n"
- " q, Q Save changes and exit.\n"
- " F2 Rename selected task.\n"
- " F5 Recalculate total times.\n"
- " TAB Toggle archive view.\n"
- " BACKSPACE Reset times for selected task.\n"
- " DELETE Delete selected task (except if active).\n"
- " SPACE, ENTER Toggle selected task as active/inactive.\n"
- " 1, 2, 3, 4, 5, 6, 7 Edit selected task time for the Nth day of week:\n"
- " =# sets # seconds;\n"
- " -# subtracts # seconds;\n"
- " # adds # seconds;\n"
- " #m specifies # as minutes;\n"
- " #h specifies # as hours;\n"
- " #d specifies # as days;\n"
- " #y specifies # as years.\n"
- " UP Select task above.\n"
- " DOWN Select task below.\n"
- " PAGE-UP Select task 1 page above.\n"
- " PAGE-DOWN Select task 1 page below.\n"
- " HOME Select first/top task.\n"
- " END Select last/bottom task.\n"
- "\n"
- "Notes\n"
- "- All data files are stored in '$" HOME_PATH_ENV "/.task_time_tracker'.\n"
- " If $" HOME_PATH_ENV " is undefined, './.task_time_tracker' will be used.\n"
- " The database entries are stored in binary format on the 'database.bin' file.\n"
- " The archived entries are stored in CSV format on the 'archive.csv' file.\n"
- "- During intensive tasks such as saving to file or recalculating totals times,\n"
- " a diamond symbol is shown on the top left corner.\n"
- );
+ args := get_command_line_arguments();
+ defer array_reset(*args);
+
+
+
+ for args {
+ if it_index == 0 continue;
+
+
+ }
+
+ if args.count > 1 {
+
+ is_exit_requested := false;
+ for 1..args.count-1 {
+ if is_equal_to_any(args[it], "--help", "-h") {
+ print("Usage: ttt [OPTION]... [FILE]...\n");
+ print(" -i, --import-csv [FILE] Import CSV file to database (discard first row).\n");
+ print(" -e, --export-csv [FILE] Export database to CSV file.\n");
+ print(" -n, --no-autosave Disable autosave feature (only save on exit).\n");
+ print(" -h, --help Display this help and exit.\n");
+ print(" -v, --version Output version information and exit.\n");
+ print("\n");
+ print("In app commands\n");
+ print(" a, A Archive selected task (except if active).\n");
+ print(" r, R Restore selected task from archive.\n");
+ print(" t, T Select currently active task (if any).\n");
+ print(" d, D Duplicate selected task.\n");
+ print(" n, N Create new task.\n");
+ print(" m, M Move selected task to position.\n");
+ print(" g, G Select task by position.\n");
+ print(" q, Q Save changes and exit.\n");
+ print(" F2 Rename selected task.\n");
+ print(" F5 Recalculate total times.\n");
+ print(" TAB Toggle archive view.\n");
+ print(" BACKSPACE Reset times for selected task.\n");
+ print(" DELETE Delete selected task (except if active).\n");
+ print(" SPACE, ENTER Toggle selected task as active/inactive.\n");
+ print(" 1, 2, 3, 4, 5, 6, 7 Edit selected task time for the Nth day of week:\n");
+ print(" =# sets # seconds;\n");
+ print(" -# subtracts # seconds;\n");
+ print(" # adds # seconds;\n");
+ print(" #m specifies # as minutes;\n");
+ print(" #h specifies # as hours;\n");
+ print(" #d specifies # as days;\n");
+ print(" #y specifies # as years.\n");
+ print(" UP Select task above.\n");
+ print(" DOWN Select task below.\n");
+ print(" PAGE-UP Select task 1 page above.\n");
+ print(" PAGE-DOWN Select task 1 page below.\n");
+ print(" HOME Select first/top task.\n");
+ print(" END Select last/bottom task.\n");
+ print("\n");
+ print("Notes\n");
+ print("- All data files are stored '%/.task_time_tracker'.\n", get_home_directory());
+ print(" If the home directory is undefined, './.task_time_tracker' will be used.\n");
+ print(" The database entries are stored in binary format on the 'database.bin' file.\n");
+ print(" The archived entries are stored in CSV format on the 'archive.csv' file.\n");
+ print("- During intensive tasks such as saving to file or recalculating totals times,\n");
+ print(" a diamond symbol is shown on the top left corner.\n");
free_memory();
- return EXIT_SUCCESS;
+ return;
}
- if (is_equal_to_any(argv[idx], "--version", "-v")) {
- fprintf(stdout,
- "Task Time Tracker version " VERSION "\n"
- "Copyright 2022 Daniel Martins\n"
+ }}// TODO To be removed once we continue our journey...
+ /*
+ if is_equal_to_any(args[it], "--version", "-v") {
+ print("Task Time Tracker version % \n"
+ "Copyright 2023 Daniel Martins\n"
"License GPL-3.0-or-later\n"
);
free_memory();
return EXIT_SUCCESS;
}
- if (is_equal_to_any(argv[idx], "--import-csv", "-i")) {
+ if (is_equal_to_any(args[it], "--import-csv", "-i")) {
idx++;
if (idx >= argc) {
print_error("Missing CSV file path to import.");
@@ -1328,7 +1353,7 @@ int main(int argc, char *argv[]) {
free_memory();
return EXIT_FAILURE;
}
- if (import_from_csv(&database, argv[idx]) == false) {
+ if (import_from_csv(&database, args[it]) == false) {
print_error("Failed to import CSV file.");
free_memory();
return EXIT_FAILURE;
@@ -1343,7 +1368,7 @@ int main(int argc, char *argv[]) {
continue;
}
- if (is_equal_to_any(argv[idx], "--export-csv", "-e")) {
+ if (is_equal_to_any(args[it], "--export-csv", "-e")) {
idx++;
if (idx >= argc) {
print_error("Missing CSV file path to export.");
@@ -1355,7 +1380,7 @@ int main(int argc, char *argv[]) {
free_memory();
return EXIT_FAILURE;
}
- if (export_to_csv(&database, argv[idx]) == false) {
+ if (export_to_csv(&database, args[it]) == false) {
print_error("Failed to export CSV file.");
free_memory();
return EXIT_FAILURE;
@@ -1365,12 +1390,12 @@ int main(int argc, char *argv[]) {
continue;
}
- if (is_equal_to_any(argv[idx], "--no-autosave", "-n")) {
+ if (is_equal_to_any(args[it], "--no-autosave", "-n")) {
is_autosave_enabled = false;
continue;
}
- print_error("%s: invalid option '%s'.\nTry '%s --help' for more information.", argv[0], argv[idx], argv[0]);
+ print_error("%s: invalid option '%s'.\nTry '%s --help' for more information.", argv[0], args[it], argv[0]);
free_memory();
return EXIT_FAILURE;
}
@@ -1802,16 +1827,11 @@ int main(int argc, char *argv[]) {
endwin();
free_memory();
return error_saving ? EXIT_FAILURE : EXIT_SUCCESS;
+ */
}
-*/
-
-#import "Basic";
-#import "System";
-#import "Math";
-// #import "File_Utilities";
-homie : string;
+/*
main :: () {
print("TNL %\n", TASK_NAME_LENGTH);
@@ -1825,90 +1845,12 @@ main :: () {
print("License GPL-3.0-or-later\n");
// TODO More binding examples here https://github.com/vrcamillo/jai-tracy
-/*
- short : s16
- int : s32
- long : s64 (int)
- single : float32 (float)
- double : float64
-*/
-
-ldat :: struct {
- text :*void; /* text of the line */
- firstchar :s16; /* first changed character in the line */
- lastchar :s16; /* last changed character in the line */
- oldindex :s16; /* index of the line at last update */
-};
-
-
-WINDOW :: struct {
- _cury, _curx : s16; /* current cursor position */
-
- /* window location and size */
- _maxy, _maxx : s16; /* maximums of x and y, NOT window size */
- _begy, _begx : s16; /* screen coords of upper-left-hand corner */
-
- _flags :s16; /* window state flags */
-
- /* attribute tracking */
- _attrs :u8; /* current attribute for non-space character */
- _bkgd :u8; /* current background char/attribute pair */
-
- /* option values set by user */
- _notimeout :bool; /* no time out on function-key entry? */
- _clear :bool; /* consider all data in the window invalid? */
- _leaveok :bool; /* OK to not reset cursor on exit? */
- _scroll :bool; /* OK to scroll this window? */
- _idlok :bool; /* OK to use insert/delete line? */
- _idcok :bool; /* OK to use insert/delete char? */
- _immed :bool; /* window in immed mode? (not yet used) */
- _sync :bool; /* window in sync mode? */
- _use_keypad :bool; /* process function keys into KEY_ symbols? */
- _delay :s32; /* 0 = nodelay, <0 = blocking, >0 = delay */
-
- _line :*ldat; /* the actual line data */
-
- /* global screen state */
- _regtop :s16; /* top line of scrolling region */
- _regbottom :s16; /* bottom line of scrolling region */
-
- /* these are used only if this is a sub-window */
- _parx :s32; /* x coordinate of this window in parent */
- _pary :s32; /* y coordinate of this window in parent */
- _parent :*WINDOW; /* pointer to parent if a sub-window */
-
- /* these are used only if this is a pad */
- pdat :: struct
- {
- _pad_y, _pad_x :s16 ;
- _pad_top, _pad_left :s16;
- _pad_bottom, _pad_right :s16;
- };
- _pad :pdat;
-
- _yoffset :s16; /* real begy is _begy + _yoffset */
+// short : s16
+// int : s32
+// long : s64 (int)
+// single : float32 (float)
+// double : float64
-/*
-#if NCURSES_WIDECHAR
- cchar_t _bkgrnd;
-#if 1
- int _color;
-#endif
-#endif
-*/
-};
-
- tinfo :: #system_library "libtinfo"; // Required by some of ncurses functions.
- ncurses :: #library "libncurses";
- initscr :: () -> *WINDOW #foreign ncurses;
- getch :: () -> s8 #foreign ncurses;
- endwin :: () -> void #foreign ncurses;
-
- curs_set :: (visibility: s32) -> s32 #foreign ncurses;
- mvaddstr :: (y: s32, x: s32, str: *u8) -> s32 #foreign ncurses;
- noecho :: () -> s32 #foreign ncurses;
- box :: (win :*WINDOW, verch :u8, horch :u8) -> s32 #foreign ncurses;
-
stdscr := initscr();
curs_set(0);
noecho();
@@ -1921,3 +1863,4 @@ WINDOW :: struct {
endwin();
}
+*/