Some worked done toward adding a storage support.
This commit is contained in:
90
base_core.h
90
base_core.h
@@ -868,31 +868,31 @@ struct FileProperties
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Safe Casts
|
//~ rjf: Safe Casts
|
||||||
|
|
||||||
internal U16 safe_cast_u16(U32 x);
|
/* internal U16 safe_cast_u16(U32 x); */
|
||||||
internal U32 safe_cast_u32(U64 x);
|
/* internal U32 safe_cast_u32(U64 x); */
|
||||||
internal S32 safe_cast_s32(S64 x);
|
/* internal S32 safe_cast_s32(S64 x); */
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Large Base Type Functions
|
//~ rjf: Large Base Type Functions
|
||||||
|
|
||||||
internal U128 u128_zero(void);
|
/* internal U128 u128_zero(void); */
|
||||||
internal U128 u128_make(U64 v0, U64 v1);
|
/* internal U128 u128_make(U64 v0, U64 v1); */
|
||||||
internal B32 u128_match(U128 a, U128 b);
|
/* internal B32 u128_match(U128 a, U128 b); */
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Bit Patterns
|
//~ rjf: Bit Patterns
|
||||||
|
|
||||||
internal U32 u32_from_u64_saturate(U64 x);
|
/* internal U32 u32_from_u64_saturate(U64 x); */
|
||||||
internal U64 u64_up_to_pow2(U64 x);
|
/* internal U64 u64_up_to_pow2(U64 x); */
|
||||||
internal S32 extend_sign32(U32 x, U32 size);
|
/* internal S32 extend_sign32(U32 x, U32 size); */
|
||||||
internal S64 extend_sign64(U64 x, U64 size);
|
/* internal S64 extend_sign64(U64 x, U64 size); */
|
||||||
|
|
||||||
internal F32 inf32(void);
|
/* internal F32 inf32(void); */
|
||||||
internal F32 neg_inf32(void);
|
/* internal F32 neg_inf32(void); */
|
||||||
|
|
||||||
internal U16 bswap_u16(U16 x);
|
/* internal U16 bswap_u16(U16 x); */
|
||||||
internal U32 bswap_u32(U32 x);
|
/* internal U32 bswap_u32(U32 x); */
|
||||||
internal U64 bswap_u64(U64 x);
|
/* internal U64 bswap_u64(U64 x); */
|
||||||
|
|
||||||
#if ARCH_LITTLE_ENDIAN
|
#if ARCH_LITTLE_ENDIAN
|
||||||
# define from_be_u16(x) bswap_u16(x)
|
# define from_be_u16(x) bswap_u16(x)
|
||||||
@@ -904,13 +904,13 @@ internal U64 bswap_u64(U64 x);
|
|||||||
# define from_be_u64(x) (x)
|
# define from_be_u64(x) (x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
internal U64 count_bits_set32(U32 val);
|
/* internal U64 count_bits_set32(U32 val); */
|
||||||
internal U64 count_bits_set64(U64 val);
|
/* internal U64 count_bits_set64(U64 val); */
|
||||||
|
|
||||||
internal U64 ctz32(U32 val);
|
/* internal U64 ctz32(U32 val); */
|
||||||
internal U64 ctz64(U64 val);
|
/* internal U64 ctz64(U64 val); */
|
||||||
internal U64 clz32(U32 val);
|
/* internal U64 clz32(U32 val); */
|
||||||
internal U64 clz64(U64 val);
|
/* internal U64 clz64(U64 val); */
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Enum -> Sign
|
//~ rjf: Enum -> Sign
|
||||||
@@ -921,43 +921,43 @@ internal U64 clz64(U64 val);
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Memory Functions
|
//~ rjf: Memory Functions
|
||||||
|
|
||||||
internal B32 memory_is_zero(void *ptr, U64 size);
|
/* internal B32 memory_is_zero(void *ptr, U64 size); */
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Text 2D Coordinate/Range Functions
|
//~ rjf: Text 2D Coordinate/Range Functions
|
||||||
|
|
||||||
internal TxtPt txt_pt(S64 line, S64 column);
|
/* internal TxtPt txt_pt(S64 line, S64 column); */
|
||||||
internal B32 txt_pt_match(TxtPt a, TxtPt b);
|
/* internal B32 txt_pt_match(TxtPt a, TxtPt b); */
|
||||||
internal B32 txt_pt_less_than(TxtPt a, TxtPt b);
|
/* internal B32 txt_pt_less_than(TxtPt a, TxtPt b); */
|
||||||
internal TxtPt txt_pt_min(TxtPt a, TxtPt b);
|
/* internal TxtPt txt_pt_min(TxtPt a, TxtPt b); */
|
||||||
internal TxtPt txt_pt_max(TxtPt a, TxtPt b);
|
/* internal TxtPt txt_pt_max(TxtPt a, TxtPt b); */
|
||||||
internal TxtRng txt_rng(TxtPt min, TxtPt max);
|
/* internal TxtRng txt_rng(TxtPt min, TxtPt max); */
|
||||||
internal TxtRng txt_rng_intersect(TxtRng a, TxtRng b);
|
/* internal TxtRng txt_rng_intersect(TxtRng a, TxtRng b); */
|
||||||
internal TxtRng txt_rng_union(TxtRng a, TxtRng b);
|
/* internal TxtRng txt_rng_union(TxtRng a, TxtRng b); */
|
||||||
internal B32 txt_rng_contains(TxtRng r, TxtPt pt);
|
/* internal B32 txt_rng_contains(TxtRng r, TxtPt pt); */
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Toolchain/Environment Enum Functions
|
//~ rjf: Toolchain/Environment Enum Functions
|
||||||
|
|
||||||
internal U64 bit_size_from_arch(Arch arch);
|
/* internal U64 bit_size_from_arch(Arch arch); */
|
||||||
internal U64 byte_size_from_arch(Arch arch);
|
/* internal U64 byte_size_from_arch(Arch arch); */
|
||||||
internal U64 max_instruction_size_from_arch(Arch arch);
|
/* internal U64 max_instruction_size_from_arch(Arch arch); */
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Time Functions
|
//~ rjf: Time Functions
|
||||||
|
|
||||||
internal DenseTime dense_time_from_date_time(DateTime date_time);
|
/* internal DenseTime dense_time_from_date_time(DateTime date_time); */
|
||||||
internal DateTime date_time_from_dense_time(DenseTime time);
|
/* internal DateTime date_time_from_dense_time(DenseTime time); */
|
||||||
internal DateTime date_time_from_micro_seconds(U64 time);
|
/* internal DateTime date_time_from_micro_seconds(U64 time); */
|
||||||
internal DateTime date_time_from_unix_time(U64 unix_time);
|
/* internal DateTime date_time_from_unix_time(U64 unix_time); */
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Non-Fancy Ring Buffer Reads/Writes
|
//~ rjf: Non-Fancy Ring Buffer Reads/Writes
|
||||||
|
|
||||||
internal U64 ring_write(U8 *ring_base, U64 ring_size, U64 ring_pos, void *src_data, U64 src_data_size);
|
/* internal U64 ring_write(U8 *ring_base, U64 ring_size, U64 ring_pos, void *src_data, U64 src_data_size); */
|
||||||
internal U64 ring_read(U8 *ring_base, U64 ring_size, U64 ring_pos, void *dst_data, U64 read_size);
|
/* internal U64 ring_read(U8 *ring_base, U64 ring_size, U64 ring_pos, void *dst_data, U64 read_size); */
|
||||||
#define ring_write_struct(ring_base, ring_size, ring_pos, ptr) ring_write((ring_base), (ring_size), (ring_pos), (ptr), sizeof(*(ptr)))
|
/* #define ring_write_struct(ring_base, ring_size, ring_pos, ptr) ring_write((ring_base), (ring_size), (ring_pos), (ptr), sizeof(*(ptr))) */
|
||||||
#define ring_read_struct(ring_base, ring_size, ring_pos, ptr) ring_read((ring_base), (ring_size), (ring_pos), (ptr), sizeof(*(ptr)))
|
/* #define ring_read_struct(ring_base, ring_size, ring_pos, ptr) ring_read((ring_base), (ring_size), (ring_pos), (ptr), sizeof(*(ptr))) */
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Sorts
|
//~ rjf: Sorts
|
||||||
@@ -966,11 +966,11 @@ internal U64 ring_read(U8 *ring_base, U64 ring_size, U64 ring_pos, void *dst_dat
|
|||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
internal U64 u64_array_bsearch(U64 *arr, U64 count, U64 value);
|
/* internal U64 u64_array_bsearch(U64 *arr, U64 count, U64 value); */
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
internal U64 index_of_zero_u32(U32 *ptr, U64 count);
|
/* internal U64 index_of_zero_u32(U32 *ptr, U64 count); */
|
||||||
internal U64 index_of_zero_u64(U64 *ptr, U64 count);
|
/* internal U64 index_of_zero_u64(U64 *ptr, U64 count); */
|
||||||
|
|
||||||
#endif // BASE_CORE_H
|
#endif // BASE_CORE_H
|
||||||
|
|||||||
107
main.c
107
main.c
@@ -1,6 +1,11 @@
|
|||||||
#include "base_context_cracking.h"
|
#include "base_context_cracking.h"
|
||||||
#include "base_core.h"
|
#include "base_core.h"
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <pwd.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
@@ -27,6 +32,37 @@ global_state state;
|
|||||||
// return ms;
|
// return ms;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
B32 path_exists(const char *path)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
return stat(path, &st) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
B32 is_directory(const char *path)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
return (stat(path, &st) == 0) && S_ISDIR(st.st_mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *get_home_dir()
|
||||||
|
{
|
||||||
|
const char *home = getenv("HOME");
|
||||||
|
if(home && home[0] != '\0') return home;
|
||||||
|
|
||||||
|
struct passwd *pw = getpwuid(getuid());
|
||||||
|
if(pw && pw->pw_dir && pw->pw_dir[0] != '\0') return pw->pw_dir;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
U64 file_size(FILE *f)
|
||||||
|
{
|
||||||
|
fseek(f, 0, SEEK_END);
|
||||||
|
U64 size = ftell(f);
|
||||||
|
fseek(f, 0, SEEK_SET); // TODO: NOTE: Save the current position, instead?
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
U64 now()
|
U64 now()
|
||||||
{
|
{
|
||||||
return (U64)time(NULL);
|
return (U64)time(NULL);
|
||||||
@@ -131,6 +167,9 @@ Hours break_time(U64 seconds)
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
(void)argc;
|
||||||
|
(void)argv;
|
||||||
|
|
||||||
U64 secs = now();
|
U64 secs = now();
|
||||||
struct tm *t = localtime((time_t *)(&secs));
|
struct tm *t = localtime((time_t *)(&secs));
|
||||||
t->tm_hour = 0;
|
t->tm_hour = 0;
|
||||||
@@ -143,6 +182,62 @@ int main(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if 2025-02-10 available
|
||||||
|
// build array
|
||||||
|
// then, save the file periodically (every ~5 seconds)
|
||||||
|
// TODO: Make global constant or in config file
|
||||||
|
char date_buffer[16];
|
||||||
|
char dir_buffer[128];
|
||||||
|
char file_buffer[256];
|
||||||
|
|
||||||
|
strftime(date_buffer, sizeof(date_buffer), "%Y_%m_%d", t);
|
||||||
|
snprintf(dir_buffer, sizeof(dir_buffer), "%s/.timetracker", get_home_dir());
|
||||||
|
snprintf(file_buffer, sizeof(file_buffer), "%s/%s", dir_buffer, date_buffer);
|
||||||
|
|
||||||
|
if(!is_directory(dir_buffer)) {
|
||||||
|
mkdir(dir_buffer, 0700); // WARNING: Might fail, what then?
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Fix error handling.
|
||||||
|
FILE *f;
|
||||||
|
if(path_exists(file_buffer)) {
|
||||||
|
f = fopen(file_buffer, "r+");
|
||||||
|
if(!f) {
|
||||||
|
fprintf(stderr, "fopen(%s) failed: %s\n", file_buffer, strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
f = fopen(file_buffer, "w+");
|
||||||
|
}
|
||||||
|
|
||||||
|
char line[4096];
|
||||||
|
if(file_size(f) < 1) {
|
||||||
|
printf("EMPTY\n");
|
||||||
|
} else {
|
||||||
|
while(fgets(line, sizeof line, f)) {
|
||||||
|
size_t n = strcspn(line, "\r\n");
|
||||||
|
line[n] = '\0';
|
||||||
|
|
||||||
|
printf("%s\n", line);
|
||||||
|
|
||||||
|
/* if(current_activity >= 0) */
|
||||||
|
/* current_activity++; */
|
||||||
|
|
||||||
|
char test[64];
|
||||||
|
U64 var1;
|
||||||
|
U64 var2;
|
||||||
|
int l = sscanf(line, "%s %llu %llu", test, &var1, &var2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ferror(f)) {
|
||||||
|
fprintf(stderr, "read error: %s\n", strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
U64 lower_bound_s = (U64)ts;
|
U64 lower_bound_s = (U64)ts;
|
||||||
U64 upper_bound_s = lower_bound_s + 86400;
|
U64 upper_bound_s = lower_bound_s + 86400;
|
||||||
// U64 upper_bound_s = lower_bound_s + 3600;
|
// U64 upper_bound_s = lower_bound_s + 3600;
|
||||||
@@ -203,7 +298,7 @@ int main(int argc, char *argv[])
|
|||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
|
|
||||||
F32 padding_x = 10.0f;
|
F32 padding_x = 10.0f;
|
||||||
F32 padding_y = 10.0f;
|
// F32 padding_y = 10.0f;
|
||||||
|
|
||||||
DrawRectangle(0, 0, window_w, 40, GRAY);
|
DrawRectangle(0, 0, window_w, 40, GRAY);
|
||||||
|
|
||||||
@@ -224,7 +319,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
Hours time = break_time(activities_stats[other].total_seconds);
|
Hours time = break_time(activities_stats[other].total_seconds);
|
||||||
snprintf(activities_stats[other].seconds_str, sizeof(activities_stats[other].seconds_str), "%02lu:%02lu:%02lu", time.hours, time.minutes, time.seconds);
|
snprintf(activities_stats[other].seconds_str, sizeof(activities_stats[other].seconds_str), "%02llu:%02llu:%02llu", time.hours, time.minutes, time.seconds);
|
||||||
if(activity_button(padding_x, 60, width, (window_h-70), "Other", activities_stats[other].seconds_str, font_size, RED)) {
|
if(activity_button(padding_x, 60, width, (window_h-70), "Other", activities_stats[other].seconds_str, font_size, RED)) {
|
||||||
if(activities[current_activity].activity != other) {
|
if(activities[current_activity].activity != other) {
|
||||||
current_activity++;
|
current_activity++;
|
||||||
@@ -237,7 +332,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
time = break_time(activities_stats[work].total_seconds);
|
time = break_time(activities_stats[work].total_seconds);
|
||||||
snprintf(activities_stats[work].seconds_str, sizeof(activities_stats[work].seconds_str), "%02lu:%02lu:%02lu", time.hours, time.minutes, time.seconds);
|
snprintf(activities_stats[work].seconds_str, sizeof(activities_stats[work].seconds_str), "%02llu:%02llu:%02llu", time.hours, time.minutes, time.seconds);
|
||||||
if(activity_button((padding_x*2)+(width*1), 60, width, (window_h-70), "Work", activities_stats[work].seconds_str, font_size, BLUE)) {
|
if(activity_button((padding_x*2)+(width*1), 60, width, (window_h-70), "Work", activities_stats[work].seconds_str, font_size, BLUE)) {
|
||||||
if(activities[current_activity].activity != work) {
|
if(activities[current_activity].activity != work) {
|
||||||
current_activity++;
|
current_activity++;
|
||||||
@@ -250,7 +345,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
time = break_time(activities_stats[projects].total_seconds);
|
time = break_time(activities_stats[projects].total_seconds);
|
||||||
snprintf(activities_stats[projects].seconds_str, sizeof(activities_stats[projects].seconds_str), "%02lu:%02lu:%02lu", time.hours, time.minutes, time.seconds);
|
snprintf(activities_stats[projects].seconds_str, sizeof(activities_stats[projects].seconds_str), "%02llu:%02llu:%02llu", time.hours, time.minutes, time.seconds);
|
||||||
if(activity_button((padding_x*3)+(width*2), 60, width, (window_h-70), "Projects", activities_stats[projects].seconds_str, font_size, YELLOW)) {
|
if(activity_button((padding_x*3)+(width*2), 60, width, (window_h-70), "Projects", activities_stats[projects].seconds_str, font_size, YELLOW)) {
|
||||||
if(activities[current_activity].activity != projects) {
|
if(activities[current_activity].activity != projects) {
|
||||||
printf("Activity PROJECTS\n");
|
printf("Activity PROJECTS\n");
|
||||||
@@ -265,7 +360,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
time = break_time(activities_stats[gaming].total_seconds);
|
time = break_time(activities_stats[gaming].total_seconds);
|
||||||
snprintf(activities_stats[gaming].seconds_str, sizeof(activities_stats[gaming].seconds_str), "%02lu:%02lu:%02lu", time.hours, time.minutes, time.seconds);
|
snprintf(activities_stats[gaming].seconds_str, sizeof(activities_stats[gaming].seconds_str), "%02llu:%02llu:%02llu", time.hours, time.minutes, time.seconds);
|
||||||
if(activity_button((padding_x*4)+(width*3), 60, width, (window_h-70), "Gaming", activities_stats[gaming].seconds_str, font_size, GREEN)) {
|
if(activity_button((padding_x*4)+(width*3), 60, width, (window_h-70), "Gaming", activities_stats[gaming].seconds_str, font_size, GREEN)) {
|
||||||
if(activities[current_activity].activity != gaming) {
|
if(activities[current_activity].activity != gaming) {
|
||||||
printf("Activity GAMING\n");
|
printf("Activity GAMING\n");
|
||||||
@@ -280,7 +375,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
time = break_time(activities_stats[exercise].total_seconds);
|
time = break_time(activities_stats[exercise].total_seconds);
|
||||||
snprintf(activities_stats[exercise].seconds_str, sizeof(activities_stats[exercise].seconds_str), "%02lu:%02lu:%02lu", time.hours, time.minutes, time.seconds);
|
snprintf(activities_stats[exercise].seconds_str, sizeof(activities_stats[exercise].seconds_str), "%02llu:%02llu:%02llu", time.hours, time.minutes, time.seconds);
|
||||||
if(activity_button((padding_x*5)+(width*4), 60, width, (window_h-70), "Exercise", activities_stats[exercise].seconds_str, font_size, PURPLE)) {
|
if(activity_button((padding_x*5)+(width*4), 60, width, (window_h-70), "Exercise", activities_stats[exercise].seconds_str, font_size, PURPLE)) {
|
||||||
if(activities[current_activity].activity != exercise) {
|
if(activities[current_activity].activity != exercise) {
|
||||||
printf("Activity EXERCISE\n");
|
printf("Activity EXERCISE\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user