diff options
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 119 |
1 files changed, 12 insertions, 107 deletions
@@ -49,11 +49,10 @@ 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; -database_t database; -database_t archive; -database_t *db; - -char *string_buffer; +database_t database = { .tasks = NULL }; +database_t archive = { .tasks = NULL }; +database_t *db = NULL; +char *string_buffer = NULL; int size_x, size_y, pos_x, pos_y; // Checks if file is exists and is accessible. @@ -600,80 +599,6 @@ void update_total_timers(database_t *db) { } } -typedef enum { - T_NONE = 0x00, - T_TIME = 0x01, - T_SOT = 0x02, - T_TPF = 0x04, - T_ALL = 0xFF, -} test_et; - -void prototype(test_et level) { - - const char *done = "# -- done -- -- -- /\n"; - - /////////////////////////////////////////////////////////////////////////// - // Get current time and day of week (UTC). - if (level & T_TIME) { - fprintf(stderr, "# UTC time and day of week -------------------- \\\n"); - time_t now_utc = time(NULL); // Get current UTC time. - uint8_t week_day = localtime(&now_utc)->tm_wday; // Get current day of the week. - fprintf(stderr, "day of week: %d\ntime: %s", week_day, ctime(&now_utc)); - fprintf(stderr, done); - } - - /////////////////////////////////////////////////////////////////////////// - // Check size of types - if (level & T_SOT) { - size_t size; - char *name; - fprintf(stderr, "# check size of types ------------------------- \\\n"); - - fprintf(stderr, "sizeof(byte) = %u bits\n", CHAR_BIT); - - name = "database_t"; - size = sizeof(database_t); - fprintf(stderr, "sizeof(%s) = %zu bytes (%zu bits : %6.3f W64b)\n", name, size, size*8, ((double)size)*8.0/64.0); - - name = "task_t"; - size = sizeof(task_t); - fprintf(stderr, "sizeof(%s) = %zu bytes (%zu bits : %6.3f W64b)\n", name, size, size*8, ((double)size)*8.0/64.0); - - name = "time_t"; - size = sizeof(time_t); - fprintf(stderr, "sizeof(%s) = %zu bytes (%zu bits : %6.3f W64b)\n", name, size, size*8, ((double)size)*8.0/64.0); - - name = "size_t"; - size = sizeof(size_t); - fprintf(stderr, "sizeof(%s) = %zu bytes (%zu bits : %6.3f W64b)\n", name, size, size*8, ((double)size)*8.0/64.0); - - name = "ptrdiff_t"; - size = sizeof(ptrdiff_t); - fprintf(stderr, "sizeof(%s) = %zu bytes (%zu bits : %6.3f W64b)\n", name, size, size*8, ((double)size)*8.0/64.0); - - name = "int"; - size = sizeof(int); - fprintf(stderr, "sizeof(%s) = %zu bytes (%zu bits : %6.3f W64b)\n", name, size, size*8, ((double)size)*8.0/64.0); - - - name = "DB_FILE_SIGN_LENGTH"; - size = DB_FILE_SIGN_LENGTH; - fprintf(stderr, "sizeof(%s) = %zu bytes (%zu bits : %6.3f W64b)\n", name, size, size*8, ((double)size)*8.0/64.0); - - fprintf(stderr, done); - } - - /////////////////////////////////////////////////////////////////////////// - // Check time print format - if (level & T_TPF) { - double times[7] = { 0.12345, 1.12345, 10.12345, 100.12345, 1000.12345, 10000.12345, 10000000000000.12345 }; - for (int idx = 0; idx < 7; idx++) { - fprintf(stderr, "%.2e\n", times[idx]); - } - } -} - - #define NUM_OF_COLUMNS 9 @@ -997,38 +922,18 @@ int main(int argc, char *argv[]) { bool do_action = false; for (int idx = 1; idx < argc; idx++) { - action = "--version"; - do_action = strncmp(argv[idx], action, strlen(action)+1) == 0; - if (do_action) { - fprintf(stdout, "Task Time Tracker " VERSION "\n"); - return EXIT_SUCCESS; - } - - action = "--t_time"; + action = "--help"; do_action = strncmp(argv[idx], action, strlen(action)+1) == 0; if (do_action) { - prototype(T_TIME); + fprintf(stdout, "TO BE IMPLEMENTED\n"); // TODO return EXIT_SUCCESS; } - action = "--t_sot"; - do_action = strncmp(argv[idx], action, strlen(action)+1) == 0; - if (do_action) { - prototype(T_SOT); - return EXIT_SUCCESS; - } - - action = "--t_tpf"; - do_action = strncmp(argv[idx], action, strlen(action)+1) == 0; - if (do_action) { - prototype(T_TPF); - return EXIT_SUCCESS; - } - - action = "--test"; + action = "--version"; do_action = strncmp(argv[idx], action, strlen(action)+1) == 0; if (do_action) { - prototype(T_ALL); + fprintf(stdout, "Task Time Tracker " VERSION "\n"); + free_memory(); return EXIT_SUCCESS; } @@ -1041,7 +946,7 @@ int main(int argc, char *argv[]) { load_database(&database, DB_BIN_PATH_NAME); import_from_csv(&database, argv[idx+1]); store_database(&database, DB_BIN_PATH_NAME); - reset_database(&database); + free_memory(); return EXIT_SUCCESS; } @@ -1053,7 +958,7 @@ int main(int argc, char *argv[]) { } load_database(&database, DB_BIN_PATH_NAME); export_to_csv(&database, argv[idx+1]); - reset_database(&database); + free_memory(); return EXIT_SUCCESS; } } @@ -1171,7 +1076,7 @@ int main(int argc, char *argv[]) { case KEY_BACKSPACE: if (db == &database) { - reset_database(&archive); + reset_database(&archive); // TODO Not needed because we never leave things hanging. import_from_csv(&archive, AR_CSV_PATH_NAME); db = &archive; } |
