Compare commits
No commits in common. "dd0a0db94715aca10954dbc54887b165d9c435c2" and "22cd6a69daea825a7ff2791feb7fd2dec9594d40" have entirely different histories.
dd0a0db947
...
22cd6a69da
25
src/db.c
25
src/db.c
@ -156,8 +156,6 @@ void delete_task(int id) {
|
|||||||
|
|
||||||
|
|
||||||
void get_task(int id, task_t* t) {
|
void get_task(int id, task_t* t) {
|
||||||
t->id = -1;
|
|
||||||
|
|
||||||
sqlite3* db = get_db();
|
sqlite3* db = get_db();
|
||||||
sqlite3_stmt* stmt;
|
sqlite3_stmt* stmt;
|
||||||
|
|
||||||
@ -187,7 +185,7 @@ void get_task(int id, task_t* t) {
|
|||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
|
|
||||||
// t->id will be (-1) if not found
|
// t.id will be (-1) if not found
|
||||||
}
|
}
|
||||||
|
|
||||||
int list_tasks() {
|
int list_tasks() {
|
||||||
@ -226,24 +224,5 @@ int list_tasks() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int get_new_task_id() {
|
int get_new_task_id() {
|
||||||
task_t t;
|
return rand()%10000;
|
||||||
|
|
||||||
int new_id = rand() %MAX_TASK_ID;
|
|
||||||
t.id = new_id;
|
|
||||||
|
|
||||||
int i=0;
|
|
||||||
while (t.id != -1 && i < NEW_TASK_ID_MAX_RETRIES) { // If t.id==-1, task is not found so the id is sage to use
|
|
||||||
new_id = rand() %MAX_TASK_ID;
|
|
||||||
get_task(new_id, &t);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i == NEW_TASK_ID_MAX_RETRIES) {
|
|
||||||
printf(RED BOLD "Il semblerait que vous ayez un nombre de tâches se rapprochant de %d.\n" RESET, MAX_TASK_ID);
|
|
||||||
printf(YELLOW "Il peut être judicieux de supprimer les tâches effectuées pour libérer de la place (et des identifiants).\n");
|
|
||||||
printf("Vous pouvez également modifier la limite du nombre d'identifiants et recompiler le projet.\n" RESET);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new_id;
|
|
||||||
}
|
}
|
@ -4,7 +4,4 @@
|
|||||||
#define VERSION "0.0.0"
|
#define VERSION "0.0.0"
|
||||||
#define DB_FILE "takl.sqlite3"
|
#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
|
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -31,7 +31,6 @@ void delete_task(int id);
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Copie la tâche [id] dans *t si elle existe
|
Copie la tâche [id] dans *t si elle existe
|
||||||
t.id vaut -1 si non trouvé
|
|
||||||
*/
|
*/
|
||||||
void get_task(int id, task_t* t);
|
void get_task(int id, task_t* t);
|
||||||
|
|
||||||
|
29
src/main.c
29
src/main.c
@ -15,9 +15,9 @@ void help(char* name) {
|
|||||||
printf("\tFormat de la date:\n");
|
printf("\tFormat de la date:\n");
|
||||||
printf("\t\tRelatif: min+%%d, h+%%d, j+%%d\n");
|
printf("\t\tRelatif: min+%%d, h+%%d, j+%%d\n");
|
||||||
printf("\t\tAbsolu: dd/mm (pas de changement d'année pour l'instant\n");
|
printf("\t\tAbsolu: dd/mm (pas de changement d'année pour l'instant\n");
|
||||||
printf("\tinfo <id1> <id2> ...\n");
|
printf("\tinfo <id>\n");
|
||||||
printf("\tdone <id1> <id2> ...\n");
|
printf("\tdone <id>\n");
|
||||||
printf("\trm <id1> <id2> ...\n");
|
printf("\trm <id>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -84,9 +84,6 @@ int add(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
task_t t = create_task(argv[2], due_to);
|
task_t t = create_task(argv[2], due_to);
|
||||||
if (t.id == -1) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (add_task(t) != 0) {
|
if (add_task(t) != 0) {
|
||||||
printf("Erreur lors de l'ajout à la base de données\n");
|
printf("Erreur lors de l'ajout à la base de données\n");
|
||||||
@ -105,22 +102,20 @@ int info(int argc, char* argv[]) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i=2; i < argc; i++) {
|
int id = strtol(argv[2], NULL, 10);
|
||||||
int id = strtol(argv[i], NULL, 10);
|
|
||||||
|
|
||||||
task_t t;
|
task_t t;
|
||||||
t.id = -1;
|
t.id = -1;
|
||||||
get_task(id, &t);
|
get_task(id, &t);
|
||||||
|
|
||||||
if (t.id == -1) {
|
if (t.id == -1) {
|
||||||
printf(YELLOW "Tâche " BOLD "[%s]" RESET YELLOW " inexistante. Vérifiez que l'identifiant est bien correct\n" RESET, argv[i]);
|
printf(BOLD YELLOW "Tâche inexistante. Vérifiez que l'identifiant est bien correct\n" RESET);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
print_task(t);
|
print_task(t);
|
||||||
free(t.text);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
free(t.text);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,21 +126,19 @@ int mark_done(int argc, char* argv[]) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i=2; i < argc; i++) {
|
int id = strtol(argv[2], NULL, 10);
|
||||||
int id = strtol(argv[i], NULL, 10);
|
|
||||||
|
|
||||||
task_t t;
|
task_t t;
|
||||||
t.id = -1;
|
t.id = -1;
|
||||||
get_task(id, &t);
|
get_task(id, &t);
|
||||||
|
|
||||||
if (t.id == -1) {
|
if (t.id == -1) {
|
||||||
printf(YELLOW "Tâche " BOLD "[%s]" RESET YELLOW " inexistante. Vérifiez que l'identifiant est bien correct\n" RESET, argv[i]);
|
printf(BOLD YELLOW "Tâche inexistante. Vérifiez que l'identifiant est bien correct\n" RESET);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
t.done = true;
|
t.done = true;
|
||||||
update_task(t);
|
update_task(t);
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -158,20 +151,18 @@ int delete(int argc, char* argv[]) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i=2; i < argc; i++) {
|
int id = strtol(argv[2], NULL, 10);
|
||||||
int id = strtol(argv[i], NULL, 10);
|
|
||||||
|
|
||||||
task_t t;
|
task_t t;
|
||||||
t.id = -1;
|
t.id = -1;
|
||||||
get_task(id, &t);
|
get_task(id, &t);
|
||||||
|
|
||||||
if (t.id == -1) {
|
if (t.id == -1) {
|
||||||
printf(YELLOW "Tâche " BOLD "[%s]" RESET YELLOW " inexistante. Vérifiez que l'identifiant est bien correct\n" RESET, argv[i]);
|
printf(BOLD YELLOW "Tâche inexistante. Vérifiez que l'identifiant est bien correct\n" RESET);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete_task(t.id);
|
delete_task(t.id);
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user