diff options
| author | dam <dam@gudinoff> | 2023-01-27 17:41:08 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2023-01-27 17:41:08 +0000 |
| commit | e952ef4d14589d8dbaf2f6e8cf0399030b725bff (patch) | |
| tree | b43b37da87f226b766cd619d684e004de3a1d4ba | |
| parent | 43d2bf3d44ebdd50c535649f609b458d1b487abc (diff) | |
| download | task-time-tracker-e952ef4d14589d8dbaf2f6e8cf0399030b725bff.tar.zst task-time-tracker-e952ef4d14589d8dbaf2f6e8cf0399030b725bff.zip | |
Initial attempt to process input arguments. Added fossil settings.
| -rw-r--r-- | .fossil-settings/binary-glob | 15 | ||||
| -rw-r--r-- | .fossil-settings/crlf-glob | 1 | ||||
| -rw-r--r-- | .fossil-settings/ignore-glob | 261 | ||||
| -rw-r--r-- | curses.jai | 89 | ||||
| -rw-r--r-- | libncurses.so | bin | 0 -> 165808 bytes | |||
| -rw-r--r-- | ttt.jai | 259 |
6 files changed, 467 insertions, 158 deletions
diff --git a/.fossil-settings/binary-glob b/.fossil-settings/binary-glob new file mode 100644 index 0000000..21f2881 --- /dev/null +++ b/.fossil-settings/binary-glob @@ -0,0 +1,15 @@ +*.ico +*.keystore +*.mp3 +*.mp4 +*.mkv +*.otf +*.png +*.so +*.tar.gz +*.tar.zst +*.tgz +*.ttf +*.wav +*.xcf +*.zip diff --git a/.fossil-settings/crlf-glob b/.fossil-settings/crlf-glob new file mode 100644 index 0000000..92bc64d --- /dev/null +++ b/.fossil-settings/crlf-glob @@ -0,0 +1 @@ +CR+LF diff --git a/.fossil-settings/ignore-glob b/.fossil-settings/ignore-glob new file mode 100644 index 0000000..3c4efe2 --- /dev/null +++ b/.fossil-settings/ignore-glob @@ -0,0 +1,261 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +#*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc
\ No newline at end of file diff --git a/curses.jai b/curses.jai new file mode 100644 index 0000000..bec9db5 --- /dev/null +++ b/curses.jai @@ -0,0 +1,89 @@ + +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 */ +}; + +// TODO This also works... +WINDOW :: struct { + data : [88] u8; +} + +WINDOWx :: 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 */ + +/* +#if NCURSES_WIDECHAR + cchar_t _bkgrnd; +#if 1 + int _color; +#endif +#endif +*/ +}; + + +tinfo :: #system_library "libtinfo"; // Required by some of ncurses functions. +// NOTE +// Must use local lib while having package libncurses-dev installed because it introduces +// an override file: +// > cat /lib/x86_64-linux-gnu/libncurses.so +// INPUT(libncursesw.so.6 -ltinfo) +// I suspect this is an attempt to help the compilers to include libtinfo automatically. +// ncurses :: #system_library "libncurses"; +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; + diff --git a/libncurses.so b/libncurses.so Binary files differnew file mode 100644 index 0000000..1e7352e --- /dev/null +++ b/libncurses.so @@ -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(); } +*/ |
