Compare commits
No commits in common. "10c326c040b3487492e57f0e7bf6af1bed4af390" and "965473c87b3dc538de9a68d357be45dc7e080b51" have entirely different histories.
10c326c040
...
965473c87b
7
Makefile
7
Makefile
@ -8,9 +8,11 @@ $(shell mkdir -p out)
|
||||
out/%.o: src/%.c
|
||||
$(CC) -c $(FLAGS) $^ -o $@
|
||||
|
||||
takl: out/main.o out/db.o out/tasks.o
|
||||
$(CC) $(FLAGS) $(LD_FLAGS) $^ -o $@
|
||||
out/%.o: src/%.cpp
|
||||
$(CXX) -c $(FLAGS) $^ -o $@
|
||||
|
||||
takl: out/main.o out/db.o out/tasks.o
|
||||
$(CXX) $(FLAGS) $(LD_FLAGS) $^ -o $@
|
||||
|
||||
install: takl
|
||||
sudo cp takl /usr/bin/takl
|
||||
@ -18,7 +20,6 @@ install: takl
|
||||
uninstall: takl
|
||||
sudo rm /usr/bin/takl
|
||||
|
||||
|
||||
clean:
|
||||
rm out -r
|
||||
rm ./takl
|
31
src/db.c
31
src/db.c
@ -213,7 +213,7 @@ void get_task(int id, task_t* t) {
|
||||
// t->id will be (-1) if not found
|
||||
}
|
||||
|
||||
task_list_t* get_task_list(bool include_completed) {
|
||||
int list_tasks(bool show_completed) {
|
||||
sqlite3* db = get_db();
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
@ -221,33 +221,38 @@ task_list_t* get_task_list(bool include_completed) {
|
||||
|
||||
if (ret != SQLITE_OK) {
|
||||
printf("(get_task) failure fetching data\n");
|
||||
return NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
task_list_t* list = NULL;
|
||||
time_t now = time(0);
|
||||
while (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
task_t t;
|
||||
|
||||
t.id = strtol((char*)sqlite3_column_text(stmt, 0), NULL, 10);
|
||||
t.text = (char*)sqlite3_column_text(stmt, 1);
|
||||
t.done = strtol((char*)sqlite3_column_text(stmt, 2), NULL, 10);
|
||||
t.due_to = strtol((char*)sqlite3_column_text(stmt, 3), NULL, 10);
|
||||
|
||||
if (!t.done || include_completed) { // We don't want to allocate memory for things that will not be used
|
||||
char* text = (char*)sqlite3_column_text(stmt, 1);
|
||||
t.text = malloc(sizeof(char)*(strlen(text)+1));
|
||||
strcpy(t.text, text);
|
||||
//* Warning: t just lives here (particularly t.text)
|
||||
|
||||
task_list_t* cur = malloc(sizeof(task_list_t)); // Add the parsed task to the beginning of the list
|
||||
cur->task = t;
|
||||
cur->next = list;
|
||||
list = cur;
|
||||
if (t.done) {
|
||||
if (show_completed) {
|
||||
printf(BOLD GREEN); // Task completed
|
||||
}
|
||||
} else if (difftime(now, t.due_to) <= 0 || t.due_to == 0) {
|
||||
printf(BOLD YELLOW); // Task not completed but that is fine
|
||||
} else {
|
||||
printf(BOLD RED); // Task not completed but should be !
|
||||
}
|
||||
|
||||
if (!t.done || show_completed) {
|
||||
printf("[%d]" RESET " %s\n", t.id, t.text);
|
||||
}
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
sqlite3_close(db);
|
||||
|
||||
return list;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_new_task_id() {
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef DEF_CONFIG_H
|
||||
#define DEF_CONFIG_H
|
||||
|
||||
#define VERSION "1.0.1"
|
||||
#define VERSION "1.0.0"
|
||||
|
||||
// By default, $HOME/.config/takl.sqlite3 is used. You can change this behaviour here
|
||||
//#define DB_FILE "takl.sqlite3"
|
||||
|
@ -3,6 +3,9 @@
|
||||
#ifndef DEF_DB_H
|
||||
#define DEF_DB_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
Création de la base de données
|
||||
Arrête le programme en cas d'échec
|
||||
@ -33,9 +36,9 @@ t.id vaut -1 si non trouvé
|
||||
void get_task(int id, task_t* t);
|
||||
|
||||
/*
|
||||
Renvoie la liste des tâches de la base de données
|
||||
Liste les tâches dans un format prédéfini
|
||||
*/
|
||||
task_list_t* get_task_list(bool include_completed);
|
||||
int list_tasks(bool show_completed);
|
||||
|
||||
/*
|
||||
Renvoie un identifiant de tâche encore non utilisé
|
||||
@ -43,4 +46,7 @@ Renvoie un identifiant de tâche encore non utilisé
|
||||
int get_new_task_id();
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
@ -12,10 +12,4 @@ struct task {
|
||||
};
|
||||
typedef struct task task_t;
|
||||
|
||||
struct task_list {
|
||||
task_t task;
|
||||
struct task_list* next;
|
||||
};
|
||||
typedef struct task_list task_list_t;
|
||||
|
||||
#endif
|
@ -3,24 +3,8 @@
|
||||
#ifndef DEF_TASKS_H
|
||||
#define DEF_TASKS_H
|
||||
|
||||
/*
|
||||
Renvoie une tâche avec un identifiant aléatoire valide
|
||||
*/
|
||||
task_t create_task(char* text, time_t due_to);
|
||||
|
||||
/*
|
||||
Affiche une tâche, avec toutes ses informations
|
||||
*/
|
||||
void print_task(task_t task);
|
||||
|
||||
/*
|
||||
Affiche une liste de tâches de manière compacte (et par catégorie: urgent, à faire, [complétée])
|
||||
*/
|
||||
void print_task_list(task_list_t* list, bool show_completed);
|
||||
|
||||
/*
|
||||
Libère la mémoire allouée à une liste de tâches
|
||||
*/
|
||||
void free_task_list(task_list_t* list);
|
||||
|
||||
#endif
|
@ -98,14 +98,6 @@ int add(int argc, char* argv[]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int list_tasks(bool show_completed) {
|
||||
task_list_t* tasks = get_task_list(show_completed);
|
||||
print_task_list(tasks, show_completed); // show_completed: true would work as all the tasks are not loaded if false
|
||||
free_task_list(tasks);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int info(int argc, char* argv[]) {
|
||||
if (argc < 3) {
|
||||
|
95
src/tasks.c
95
src/tasks.c
@ -1,95 +0,0 @@
|
||||
/*
|
||||
Fonctions utilitaires concernant les tâches
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "include/db.h"
|
||||
#include "include/struct.h"
|
||||
#include "include/colors.h"
|
||||
|
||||
|
||||
task_t create_task(char* text, time_t due_to) {
|
||||
task_t task;
|
||||
|
||||
task.id = get_new_task_id();
|
||||
task.text = text;
|
||||
task.done = false;
|
||||
task.due_to = due_to;
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
|
||||
void print_task(task_t task) {
|
||||
printf(YELLOW "=== Tâche " BOLD "[%d]" RESET YELLOW " ===\n" RESET, task.id);
|
||||
printf(BOLD "%s\n" RESET, task.text);
|
||||
|
||||
printf("Statut: ");
|
||||
if (task.done) {
|
||||
printf(GREEN "Complétée\n" RESET);
|
||||
} else {
|
||||
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) {
|
||||
struct tm * timeinfo;
|
||||
char buffer[80];
|
||||
|
||||
timeinfo = localtime(&task.due_to);
|
||||
|
||||
strftime(buffer,sizeof(buffer),"%d-%m-%Y %H:%M:%S",timeinfo);
|
||||
|
||||
printf("Dûe le %s\n", buffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void print_task_list(task_list_t* list, bool show_completed) {
|
||||
task_list_t* cur = list;
|
||||
time_t now = time(0);
|
||||
while (cur) { // Show not completed red tasks first
|
||||
task_t t = cur->task;
|
||||
if (!t.done && difftime(now, t.due_to) >= 0 && t.due_to != 0) {
|
||||
printf(BOLD RED "[%d]" RESET " %s\n", t.id, t.text); // Task not completed but should be !
|
||||
}
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
cur = list;
|
||||
while (cur) { // Show not completed but not due_to then
|
||||
task_t t = cur->task;
|
||||
if (!t.done && (difftime(now, t.due_to) <= 0 || t.due_to == 0)) {
|
||||
printf(BOLD YELLOW "[%d]" RESET " %s\n", t.id, t.text); // Task not completed but should be !
|
||||
}
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
if (show_completed) {
|
||||
cur = list;
|
||||
while (cur) { // Show not completed but not due_to then
|
||||
task_t t = cur->task;
|
||||
if (t.done) {
|
||||
printf(BOLD GREEN "[%d]" RESET " %s\n", t.id, t.text); // Task not completed but should be !
|
||||
}
|
||||
cur = cur->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void free_task_list(task_list_t* list) {
|
||||
while (list) {
|
||||
task_list_t* next = list->next;
|
||||
free(list->task.text);
|
||||
free(list);
|
||||
list = next;
|
||||
}
|
||||
}
|
52
src/tasks.cpp
Normal file
52
src/tasks.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
Fonctions de création/ modification d'objet tâches
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctime>
|
||||
|
||||
#include "include/db.h"
|
||||
#include "include/struct.h"
|
||||
#include "include/colors.h"
|
||||
|
||||
extern "C"
|
||||
task_t create_task(char* text, time_t due_to) {
|
||||
task_t task;
|
||||
|
||||
task.id = get_new_task_id();
|
||||
task.text = text;
|
||||
task.done = false;
|
||||
task.due_to = due_to;
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
void print_task(task_t task) {
|
||||
printf(YELLOW "=== Tâche " BOLD "[%d]" RESET YELLOW " ===\n" RESET, task.id);
|
||||
printf(BOLD "%s\n" RESET, task.text);
|
||||
|
||||
printf("Statut: ");
|
||||
if (task.done) {
|
||||
printf(GREEN "Complétée\n" RESET);
|
||||
} else {
|
||||
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) {
|
||||
struct tm * timeinfo;
|
||||
char buffer[80];
|
||||
|
||||
timeinfo = localtime(&task.due_to);
|
||||
|
||||
strftime(buffer,sizeof(buffer),"%d-%m-%Y %H:%M:%S",timeinfo);
|
||||
|
||||
printf("Dûe le %s\n", buffer);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user