Compare commits
2 Commits
f7f674f7a0
...
3b9533929b
Author | SHA1 | Date | |
---|---|---|---|
3b9533929b | |||
5ba4ca001a |
29
src/db.c
29
src/db.c
@ -13,12 +13,34 @@ Fonctions d'interaction avec la base de données
|
||||
#include "include/struct.h"
|
||||
|
||||
|
||||
char* get_db_path() {
|
||||
#ifndef DB_FILE
|
||||
//! We should check that $HOME/.config already exists even if it should be the case
|
||||
char* base_path = ".config/takl.sqlite3";
|
||||
|
||||
char* home_dir = getenv("HOME");
|
||||
assert(home_dir != NULL);
|
||||
|
||||
char* db_path = malloc(sizeof(char)*(strlen(base_path)+strlen(home_dir)+1));
|
||||
sprintf(db_path, "%s/%s", home_dir, base_path);
|
||||
|
||||
return db_path;
|
||||
#else
|
||||
char* db_path = malloc(sizeof(char)*(strlen(DB_FILE)+1));
|
||||
memcpy(db_path, DB_FILE, sizeof(char)*(strlen(DB_FILE)+1));
|
||||
|
||||
return db_path;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
sqlite3* get_db() {
|
||||
sqlite3* db;
|
||||
char* db_path = get_db_path();
|
||||
|
||||
if (access(DB_FILE, F_OK) != 0) {
|
||||
if (access(db_path, F_OK) != 0) {
|
||||
// Create DB
|
||||
sqlite3_open(DB_FILE, &db);
|
||||
sqlite3_open(db_path, &db);
|
||||
|
||||
char* zErrMsg = NULL;
|
||||
int ret = sqlite3_exec(
|
||||
@ -44,11 +66,12 @@ sqlite3* get_db() {
|
||||
printf(GREEN "OK" RESET " Base de données créée\n");
|
||||
}
|
||||
|
||||
int ret = sqlite3_open(DB_FILE, &db);
|
||||
int ret = sqlite3_open(db_path, &db);
|
||||
if (ret != SQLITE_OK) {
|
||||
fprintf(stderr, "(get_db) Unable to open db\n");
|
||||
}
|
||||
|
||||
free(db_path);
|
||||
return db;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,9 @@
|
||||
#define DEF_CONFIG_H
|
||||
|
||||
#define VERSION "0.0.0"
|
||||
#define DB_FILE "takl.sqlite3"
|
||||
|
||||
// By default, $HOME/.config/takl.sqlite3 is used. You can change this behaviour here
|
||||
//#define DB_FILE "takl.sqlite3"
|
||||
|
||||
#define MAX_TASK_ID 10000 // max is set to MAX_TASK_ID-1
|
||||
#define NEW_TASK_ID_MAX_RETRIES 10000 // number of retries before giving up
|
||||
|
@ -30,7 +30,13 @@ void print_task(task_t task) {
|
||||
if (task.done) {
|
||||
printf(GREEN "Complétée\n" RESET);
|
||||
} else {
|
||||
printf(BLUE "À faire\n" RESET);
|
||||
time_t now = time(0);
|
||||
if (difftime(now, task.due_to) <= 0 || task.due_to == 0) {
|
||||
printf(BLUE "À faire\n" RESET);
|
||||
} else {
|
||||
printf(RED "À faire\n" RESET);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (task.due_to != 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user