more config and clang-tidy stuff
This commit is contained in:
parent
5a8e3a073a
commit
d05b7735b2
9 changed files with 94 additions and 75 deletions
|
@ -15,7 +15,7 @@ char *klist_config_key_to_string(KLIST_CONFIG_KEY key) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
KLIST_CONFIG_KEY klist_config_string_to_key(char *key) {
|
KLIST_CONFIG_KEY klist_config_string_to_key(const char *key) {
|
||||||
if (!strcmp(key, klist_config_key_to_string(CONFIG_DATABASE_NAME)))
|
if (!strcmp(key, klist_config_key_to_string(CONFIG_DATABASE_NAME)))
|
||||||
return CONFIG_DATABASE_NAME;
|
return CONFIG_DATABASE_NAME;
|
||||||
return _CONFIG_KEY_COUNT;
|
return _CONFIG_KEY_COUNT;
|
||||||
|
@ -62,17 +62,17 @@ void klist_config_parse(klist_config *ctx, FILE *config) {
|
||||||
while ((c = fgetc(config)) != EOF) {
|
while ((c = fgetc(config)) != EOF) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '\n':
|
case '\n':
|
||||||
ignore_line = true;
|
ignore_line = false;
|
||||||
if (!key)
|
if (!key)
|
||||||
continue;
|
continue;
|
||||||
if (!val) {
|
if (!val) {
|
||||||
fprintf(stderr, "ignoring key '%s'", key);
|
fprintf(stderr, "ignoring key '%s'", key);
|
||||||
}
|
}
|
||||||
if (!strcmp(key, "database")) {
|
if (!strcmp(key, klist_config_key_to_string(CONFIG_DATABASE_NAME))) {
|
||||||
ctx->db_file = malloc(strlen(val));
|
*ctx[CONFIG_DATABASE_NAME] = malloc((strlen(val) + 1) * sizeof(char));
|
||||||
strcpy(ctx->db_file, val);
|
strcpy(*ctx[CONFIG_DATABASE_NAME], val);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "ignoring unknown key '%s'", key);
|
fprintf(stderr, "[init] ignoring unknown key '%s'", key);
|
||||||
}
|
}
|
||||||
free(key);
|
free(key);
|
||||||
free(val);
|
free(val);
|
||||||
|
@ -80,6 +80,8 @@ void klist_config_parse(klist_config *ctx, FILE *config) {
|
||||||
key = NULL, val = NULL;
|
key = NULL, val = NULL;
|
||||||
break;
|
break;
|
||||||
case '=':
|
case '=':
|
||||||
|
if (ignore_line)
|
||||||
|
continue;
|
||||||
if (!found_key)
|
if (!found_key)
|
||||||
found_key = true;
|
found_key = true;
|
||||||
else {
|
else {
|
||||||
|
@ -94,9 +96,11 @@ void klist_config_parse(klist_config *ctx, FILE *config) {
|
||||||
if (ignore_line)
|
if (ignore_line)
|
||||||
continue;
|
continue;
|
||||||
if (found_key) {
|
if (found_key) {
|
||||||
if (val)
|
if (val) {
|
||||||
val = realloc(val, ++val_len * sizeof(char));
|
char *_val = realloc(val, ++val_len * sizeof(char));
|
||||||
else {
|
if (_val)
|
||||||
|
val = _val;
|
||||||
|
} else {
|
||||||
val_len = 2;
|
val_len = 2;
|
||||||
val = malloc(val_len * sizeof(char));
|
val = malloc(val_len * sizeof(char));
|
||||||
}
|
}
|
||||||
|
@ -104,18 +108,23 @@ void klist_config_parse(klist_config *ctx, FILE *config) {
|
||||||
val[val_len - 1] = '\0';
|
val[val_len - 1] = '\0';
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (key)
|
if (key) {
|
||||||
key = realloc(key, ++key_len * sizeof(char));
|
char *_key = realloc(key, ++key_len * sizeof(char));
|
||||||
else {
|
if (_key)
|
||||||
|
key = _key;
|
||||||
|
} else {
|
||||||
key_len = 2;
|
key_len = 2;
|
||||||
key = malloc(key_len * sizeof(char));
|
key = malloc(key_len * sizeof(char));
|
||||||
}
|
}
|
||||||
key[key_len - 2] = (char)c;
|
key[key_len - 2] = (char)c;
|
||||||
key[key_len - 1] = '\0';
|
key[key_len - 1] = '\0';
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (key)
|
||||||
|
free(key);
|
||||||
|
if (val)
|
||||||
|
free(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void klist_config_setup(char *name, FILE *config) {
|
void klist_config_setup(char *name, FILE *config) {
|
||||||
|
@ -142,6 +151,14 @@ void klist_config_setup(char *name, FILE *config) {
|
||||||
free(data_home);
|
free(data_home);
|
||||||
|
|
||||||
// fseek(config, 0, SEEK_END);
|
// fseek(config, 0, SEEK_END);
|
||||||
|
fprintf(config, "# -- klist config file --\n"
|
||||||
|
"# please note that keys and values are case and space "
|
||||||
|
"sensitive, only key=value is parsable\n"
|
||||||
|
"# valid keys: ");
|
||||||
|
int i = 0;
|
||||||
|
for (; i < _CONFIG_KEY_COUNT; i++)
|
||||||
|
fprintf(config, "%s,", klist_config_key_to_string(i));
|
||||||
|
fprintf(config, "\n\n");
|
||||||
fprintf(config, "%s=%s/tasks.db\n",
|
fprintf(config, "%s=%s/tasks.db\n",
|
||||||
klist_config_key_to_string(CONFIG_DATABASE_NAME), db_file);
|
klist_config_key_to_string(CONFIG_DATABASE_NAME), db_file);
|
||||||
fclose(config);
|
fclose(config);
|
||||||
|
|
|
@ -4,10 +4,10 @@
|
||||||
enum KLIST_CONFIG_KEY { CONFIG_DATABASE_NAME, _CONFIG_KEY_COUNT };
|
enum KLIST_CONFIG_KEY { CONFIG_DATABASE_NAME, _CONFIG_KEY_COUNT };
|
||||||
typedef enum KLIST_CONFIG_KEY KLIST_CONFIG_KEY;
|
typedef enum KLIST_CONFIG_KEY KLIST_CONFIG_KEY;
|
||||||
|
|
||||||
struct klist_config {
|
typedef char *klist_config[_CONFIG_KEY_COUNT];
|
||||||
char *db_file;
|
|
||||||
};
|
char *klist_config_key_to_string(KLIST_CONFIG_KEY key);
|
||||||
typedef struct klist_config klist_config;
|
KLIST_CONFIG_KEY klist_config_string_to_key(const char *key);
|
||||||
|
|
||||||
char *klist_config_name(char *);
|
char *klist_config_name(char *);
|
||||||
void klist_config_parse(klist_config *, FILE *);
|
void klist_config_parse(klist_config *, FILE *);
|
||||||
|
|
|
@ -2,16 +2,16 @@
|
||||||
|
|
||||||
#include "klist.h"
|
#include "klist.h"
|
||||||
|
|
||||||
int klist_app_user_get(klist *);
|
int klist_app_user_get(const klist *);
|
||||||
int klist_app_user_create(klist *);
|
int klist_app_user_create(const klist *);
|
||||||
int klist_app_user_delete(klist *);
|
int klist_app_user_delete(const klist *);
|
||||||
|
|
||||||
int klist_app_list_add(klist *);
|
int klist_app_list_add(const klist *);
|
||||||
int klist_app_list_edit(klist *);
|
int klist_app_list_edit(const klist *);
|
||||||
int klist_app_list_get(klist *);
|
int klist_app_list_get(const klist *);
|
||||||
int klist_app_list_delete(klist *);
|
int klist_app_list_delete(const klist *);
|
||||||
|
|
||||||
int klist_app_task_add(klist *);
|
int klist_app_task_add(const klist *);
|
||||||
int klist_app_task_edit(klist *);
|
int klist_app_task_edit(const klist *);
|
||||||
int klist_app_task_get(klist *);
|
int klist_app_task_get(const klist *);
|
||||||
int klist_app_task_delete(klist *);
|
int klist_app_task_delete(const klist *);
|
|
@ -12,7 +12,7 @@ void setup(klist *ctx, int argc, char **argv);
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
char *name = "klist";
|
char *name = "klist";
|
||||||
klist_config *config = malloc(sizeof(klist_config));
|
klist_config config;
|
||||||
|
|
||||||
char *config_file_name = klist_config_name(name);
|
char *config_file_name = klist_config_name(name);
|
||||||
|
|
||||||
|
@ -23,11 +23,12 @@ int main(int argc, char **argv) {
|
||||||
} else
|
} else
|
||||||
config_file = fopen(config_file_name, "a+");
|
config_file = fopen(config_file_name, "a+");
|
||||||
|
|
||||||
klist_config_parse(config, config_file);
|
klist_config_parse(&config, config_file);
|
||||||
|
|
||||||
klist *ctx = klist_init(config->db_file);
|
klist *ctx = klist_init(config[CONFIG_DATABASE_NAME]);
|
||||||
|
|
||||||
free(config);
|
free(config_file_name);
|
||||||
|
free(config[CONFIG_DATABASE_NAME]);
|
||||||
|
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
print_help(ctx, argv);
|
print_help(ctx, argv);
|
||||||
|
@ -77,7 +78,7 @@ int main(int argc, char **argv) {
|
||||||
klist_task_context *task_ctx = ctx->cmd_ctx;
|
klist_task_context *task_ctx = ctx->cmd_ctx;
|
||||||
switch (((klist_task_context *)ctx->cmd_ctx)->cmd) {
|
switch (((klist_task_context *)ctx->cmd_ctx)->cmd) {
|
||||||
case TASK_ADD: // basically the same things happen and edit can create if
|
case TASK_ADD: // basically the same things happen and edit can create if
|
||||||
// nescessary
|
// necessary
|
||||||
case TASK_EDIT:
|
case TASK_EDIT:
|
||||||
klist_app_task_edit(ctx);
|
klist_app_task_edit(ctx);
|
||||||
break;
|
break;
|
||||||
|
@ -161,10 +162,13 @@ void setup(klist *ctx, int argc, char **argv) {
|
||||||
case 's':
|
case 's':
|
||||||
char *stage = NULL;
|
char *stage = NULL;
|
||||||
while ((stage = strsep(&optarg, ","))) {
|
while ((stage = strsep(&optarg, ","))) {
|
||||||
list_ctx->stages = realloc(list_ctx->stages,
|
char **stages = realloc(list_ctx->stages,
|
||||||
(++list_ctx->stages_len) * sizeof(char *));
|
(++list_ctx->stages_len) * sizeof(char *));
|
||||||
|
if (stages) {
|
||||||
|
list_ctx->stages = stages;
|
||||||
list_ctx->stages[list_ctx->stages_len - 1] = strdup(stage);
|
list_ctx->stages[list_ctx->stages_len - 1] = strdup(stage);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
print_help(ctx, argv);
|
print_help(ctx, argv);
|
||||||
|
@ -219,7 +223,8 @@ void setup(klist *ctx, int argc, char **argv) {
|
||||||
"-d\tdelete a task"
|
"-d\tdelete a task"
|
||||||
"Not providing a parameter prints all tasks of a list.");
|
"Not providing a parameter prints all tasks of a list.");
|
||||||
}
|
}
|
||||||
if (!task_ctx->cmd) task_ctx->cmd = TASK_ADD;
|
if (!task_ctx->cmd)
|
||||||
|
task_ctx->cmd = TASK_ADD;
|
||||||
ctx->cmd_ctx = task_ctx;
|
ctx->cmd_ctx = task_ctx;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int klist_app_user_get(klist *ctx) {
|
int klist_app_user_get(const klist *ctx) {
|
||||||
klist_user *user = klist_user_get_by_local(ctx, getuid());
|
klist_user *user = klist_user_get_by_local(ctx, getuid());
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
|
@ -20,7 +20,7 @@ int klist_app_user_get(klist *ctx) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int klist_app_user_create(klist *ctx) {
|
int klist_app_user_create(const klist *ctx) {
|
||||||
klist_print(ctx, KLIST_LOG_INFO,
|
klist_print(ctx, KLIST_LOG_INFO,
|
||||||
(klist_assure_user(ctx, getuid(), getlogin()))
|
(klist_assure_user(ctx, getuid(), getlogin()))
|
||||||
? "User created.\n"
|
? "User created.\n"
|
||||||
|
@ -28,7 +28,7 @@ int klist_app_user_create(klist *ctx) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int klist_app_user_delete(klist *ctx) {
|
int klist_app_user_delete(const klist *ctx) {
|
||||||
klist_user *user = klist_user_get_by_local(ctx, getuid());
|
klist_user *user = klist_user_get_by_local(ctx, getuid());
|
||||||
if (user) {
|
if (user) {
|
||||||
klist_user_delete(ctx, user);
|
klist_user_delete(ctx, user);
|
||||||
|
@ -38,7 +38,7 @@ int klist_app_user_delete(klist *ctx) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int klist_app_list_add(klist *ctx) {
|
int klist_app_list_add(const klist *ctx) {
|
||||||
klist_list_context *list_ctx = ctx->cmd_ctx;
|
klist_list_context *list_ctx = ctx->cmd_ctx;
|
||||||
if (!list_ctx->stages_len) {
|
if (!list_ctx->stages_len) {
|
||||||
klist_print(ctx, KLIST_LOG_ERROR, "Missing stages.\n");
|
klist_print(ctx, KLIST_LOG_ERROR, "Missing stages.\n");
|
||||||
|
@ -67,12 +67,12 @@ int klist_app_list_add(klist *ctx) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int klist_app_list_edit(klist *ctx) {
|
int klist_app_list_edit(const klist *ctx) {
|
||||||
klist_print(ctx, KLIST_LOG_ERROR, "Not implemented\n");
|
klist_print(ctx, KLIST_LOG_ERROR, "Not implemented\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int klist_app_list_get(klist *ctx) {
|
int klist_app_list_get(const klist *ctx) {
|
||||||
klist_list_context *list_ctx = ctx->cmd_ctx;
|
klist_list_context *list_ctx = ctx->cmd_ctx;
|
||||||
klist_user *user = klist_user_get_by_local(ctx, getuid());
|
klist_user *user = klist_user_get_by_local(ctx, getuid());
|
||||||
|
|
||||||
|
@ -99,9 +99,9 @@ int klist_app_list_get(klist *ctx) {
|
||||||
printf("Name: %s\n", (char *)list->name);
|
printf("Name: %s\n", (char *)list->name);
|
||||||
printf("Description: %s\n", list->desc ? (char *)list->desc : "N/A");
|
printf("Description: %s\n", list->desc ? (char *)list->desc : "N/A");
|
||||||
printf("Tasks: %ld\n", tasks_len);
|
printf("Tasks: %ld\n", tasks_len);
|
||||||
i = 0;
|
int j = 0;
|
||||||
for (; i < tasks_len; i++)
|
for (; j < tasks_len; j++)
|
||||||
klist_task_deinit(tasks[i]);
|
klist_task_deinit(tasks[j]);
|
||||||
free(tasks);
|
free(tasks);
|
||||||
klist_list_deinit(list);
|
klist_list_deinit(list);
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ int klist_app_list_get(klist *ctx) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int klist_app_list_delete(klist *ctx) {
|
int klist_app_list_delete(const klist *ctx) {
|
||||||
klist_list_context *list_ctx = ctx->cmd_ctx;
|
klist_list_context *list_ctx = ctx->cmd_ctx;
|
||||||
klist_assure_user(ctx, getuid(), getlogin());
|
klist_assure_user(ctx, getuid(), getlogin());
|
||||||
klist_user *user = klist_user_get_by_local(ctx, getuid());
|
klist_user *user = klist_user_get_by_local(ctx, getuid());
|
||||||
|
@ -124,8 +124,6 @@ int klist_app_list_delete(klist *ctx) {
|
||||||
|
|
||||||
klist_list *list =
|
klist_list *list =
|
||||||
klist_list_get_by_user_and_name(ctx, user->id, list_ctx->name);
|
klist_list_get_by_user_and_name(ctx, user->id, list_ctx->name);
|
||||||
|
|
||||||
list = klist_list_get_by_user_and_name(ctx, user->id, list_ctx->name);
|
|
||||||
if (list) {
|
if (list) {
|
||||||
size_t tasks_len = 0;
|
size_t tasks_len = 0;
|
||||||
klist_task **tasks = klist_task_get_for_list(ctx, list->id, &tasks_len);
|
klist_task **tasks = klist_task_get_for_list(ctx, list->id, &tasks_len);
|
||||||
|
@ -139,9 +137,9 @@ int klist_app_list_delete(klist *ctx) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int klist_app_task_add(klist *ctx) { return klist_app_task_edit(ctx); }
|
int klist_app_task_add(const klist *ctx) { return klist_app_task_edit(ctx); }
|
||||||
|
|
||||||
int klist_app_task_edit(klist *ctx) {
|
int klist_app_task_edit(const klist *ctx) {
|
||||||
klist_task_context *task_ctx = ctx->cmd_ctx;
|
klist_task_context *task_ctx = ctx->cmd_ctx;
|
||||||
klist_assure_user(ctx, getuid(), getlogin());
|
klist_assure_user(ctx, getuid(), getlogin());
|
||||||
klist_user *user = klist_user_get_by_local(ctx, getuid());
|
klist_user *user = klist_user_get_by_local(ctx, getuid());
|
||||||
|
@ -155,32 +153,29 @@ int klist_app_task_edit(klist *ctx) {
|
||||||
list = klist_list_get_by_user_and_name(ctx, user->id, task_ctx->list);
|
list = klist_list_get_by_user_and_name(ctx, user->id, task_ctx->list);
|
||||||
if (list) {
|
if (list) {
|
||||||
size_t stages_len = 0;
|
size_t stages_len = 0;
|
||||||
|
int i = 0;
|
||||||
klist_stage **stages =
|
klist_stage **stages =
|
||||||
klist_stage_get_all_for_list(ctx, list->id, &stages_len);
|
klist_stage_get_all_for_list(ctx, list->id, &stages_len);
|
||||||
if (!task_ctx->stage) {
|
if (!task_ctx->stage) {
|
||||||
klist_print(ctx, KLIST_LOG_ERROR,
|
klist_print(ctx, KLIST_LOG_ERROR,
|
||||||
"Stage missing/wrong, please pass one of: ");
|
"Stage missing/wrong, please pass one of: ");
|
||||||
int i = 0;
|
for (i = 0; i < stages_len; i++)
|
||||||
for (; i < stages_len; i++)
|
|
||||||
fprintf(ctx->log_target, "%s ", (char *)stages[i]->name);
|
fprintf(ctx->log_target, "%s ", (char *)stages[i]->name);
|
||||||
fprintf(ctx->log_target, "\n");
|
fprintf(ctx->log_target, "\n");
|
||||||
}
|
}
|
||||||
int i = 0;
|
long stage_id = -1;
|
||||||
ssize_t stage_id = -1;
|
for (i = 0; i < stages_len; i++)
|
||||||
for (; i < stages_len; i++)
|
|
||||||
if (strcmp((char *)stages[i]->name, task_ctx->stage) == 0)
|
if (strcmp((char *)stages[i]->name, task_ctx->stage) == 0)
|
||||||
stage_id = stages[i]->id;
|
stage_id = stages[i]->id;
|
||||||
|
|
||||||
if (stage_id == -1) {
|
if (stage_id == -1) {
|
||||||
klist_print(ctx, KLIST_LOG_ERROR,
|
klist_print(ctx, KLIST_LOG_ERROR,
|
||||||
"Stage %s not found. Use one of: ", task_ctx->stage);
|
"Stage %s not found. Use one of: ", task_ctx->stage);
|
||||||
i = 0;
|
for (i = 0; i < stages_len; i++)
|
||||||
for (; i < stages_len; i++)
|
|
||||||
fprintf(ctx->log_target, "%s ", (char *)stages[i]->name);
|
fprintf(ctx->log_target, "%s ", (char *)stages[i]->name);
|
||||||
fprintf(ctx->log_target, "\n");
|
fprintf(ctx->log_target, "\n");
|
||||||
}
|
}
|
||||||
i = 0;
|
for (i = 0; i < stages_len; i++)
|
||||||
for (; i < stages_len; i++)
|
|
||||||
klist_stage_deinit(stages[i]);
|
klist_stage_deinit(stages[i]);
|
||||||
free(stages);
|
free(stages);
|
||||||
|
|
||||||
|
@ -206,7 +201,7 @@ int klist_app_task_edit(klist *ctx) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int klist_app_task_get(klist *ctx) {
|
int klist_app_task_get(const klist *ctx) {
|
||||||
klist_task_context *task_ctx = ctx->cmd_ctx;
|
klist_task_context *task_ctx = ctx->cmd_ctx;
|
||||||
klist_assure_user(ctx, getuid(), getlogin());
|
klist_assure_user(ctx, getuid(), getlogin());
|
||||||
klist_user *user = klist_user_get_by_local(ctx, getuid());
|
klist_user *user = klist_user_get_by_local(ctx, getuid());
|
||||||
|
@ -247,7 +242,7 @@ int klist_app_task_get(klist *ctx) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int klist_app_task_delete(klist *ctx) {
|
int klist_app_task_delete(const klist *ctx) {
|
||||||
klist_task_context *task_ctx = ctx->cmd_ctx;
|
klist_task_context *task_ctx = ctx->cmd_ctx;
|
||||||
klist_assure_user(ctx, getuid(), getlogin());
|
klist_assure_user(ctx, getuid(), getlogin());
|
||||||
klist_user *user = klist_user_get_by_local(ctx, getuid());
|
klist_user *user = klist_user_get_by_local(ctx, getuid());
|
||||||
|
@ -258,7 +253,7 @@ int klist_app_task_delete(klist *ctx) {
|
||||||
klist_list *list =
|
klist_list *list =
|
||||||
klist_list_get_by_user_and_name(ctx, user->id, task_ctx->list);
|
klist_list_get_by_user_and_name(ctx, user->id, task_ctx->list);
|
||||||
if (list) {
|
if (list) {
|
||||||
if (task_ctx) {
|
if (task_ctx->name) {
|
||||||
klist_task *task =
|
klist_task *task =
|
||||||
klist_task_get_for_list_by_name(ctx, list->id, task_ctx->name);
|
klist_task_get_for_list_by_name(ctx, list->id, task_ctx->name);
|
||||||
if (task) {
|
if (task) {
|
||||||
|
|
|
@ -74,5 +74,5 @@ void klist_task_delete(const klist *, const klist_task *);
|
||||||
void klist_task_deinit(klist_task *);
|
void klist_task_deinit(klist_task *);
|
||||||
|
|
||||||
void klist_print_user(klist *, const klist_user *);
|
void klist_print_user(klist *, const klist_user *);
|
||||||
void klist_print_list(klist *, klist_list *, klist_task **, size_t);
|
void klist_print_list(const klist *, const klist_list *, klist_task **, size_t);
|
||||||
void klist_print_task(klist *, klist_task **, size_t);
|
void klist_print_task(klist *, klist_task **, size_t);
|
|
@ -93,7 +93,7 @@ void klist_sql_prepare(klist *, char *);
|
||||||
* assuring things
|
* assuring things
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool klist_assure_user(klist *, __uid_t, char *);
|
bool klist_assure_user(const klist *, __uid_t, const char *);
|
||||||
void klist_assure_list(klist *, char *);
|
void klist_assure_list(klist *, char *);
|
||||||
void klist_assure_task(klist *, char *);
|
void klist_assure_task(klist *, char *);
|
||||||
|
|
||||||
|
|
|
@ -383,7 +383,7 @@ void klist_print_user(klist *ctx, const klist_user *user) {
|
||||||
void print_table_line(char *left, size_t cols, char *filler, size_t col_width,
|
void print_table_line(char *left, size_t cols, char *filler, size_t col_width,
|
||||||
char *col_delim, char *right) {
|
char *col_delim, char *right) {
|
||||||
printf("%s", left);
|
printf("%s", left);
|
||||||
int i = 0;
|
int i;
|
||||||
for (i = 0; i < cols; i++) {
|
for (i = 0; i < cols; i++) {
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for (; j < col_width; j++)
|
for (; j < col_width; j++)
|
||||||
|
@ -394,8 +394,8 @@ void print_table_line(char *left, size_t cols, char *filler, size_t col_width,
|
||||||
printf("%s\n", right);
|
printf("%s\n", right);
|
||||||
}
|
}
|
||||||
|
|
||||||
void klist_print_list(klist *ctx, klist_list *list, klist_task **tasks,
|
void klist_print_list(const klist *ctx, const klist_list *list,
|
||||||
size_t tasks_len) {
|
klist_task **tasks, size_t tasks_len) {
|
||||||
struct winsize w;
|
struct winsize w;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
||||||
|
@ -421,8 +421,10 @@ void klist_print_list(klist *ctx, klist_list *list, klist_task **tasks,
|
||||||
if (task_length > max_task_length)
|
if (task_length > max_task_length)
|
||||||
max_task_length = task_length;
|
max_task_length = task_length;
|
||||||
}
|
}
|
||||||
u_int content_width = (int)((double)max_task_length * 1.6 * (double)stages_len);
|
u_int content_width =
|
||||||
if (content_width) width = content_width;
|
(int)((double)max_task_length * 1.6 * (double)stages_len);
|
||||||
|
if (content_width)
|
||||||
|
width = content_width;
|
||||||
size_t stage_col_width = (width - 3 - (stages_len - 1)) / stages_len;
|
size_t stage_col_width = (width - 3 - (stages_len - 1)) / stages_len;
|
||||||
|
|
||||||
int tasks_max = 0;
|
int tasks_max = 0;
|
||||||
|
@ -436,7 +438,9 @@ void klist_print_list(klist *ctx, klist_list *list, klist_task **tasks,
|
||||||
// list name
|
// list name
|
||||||
printf("│");
|
printf("│");
|
||||||
printf(" %s", (char *)list->name);
|
printf(" %s", (char *)list->name);
|
||||||
for (i = 0; i < (stages_len * stage_col_width) - (strlen((char *)list->name + 1)); i++)
|
for (i = 0;
|
||||||
|
i < (stages_len * stage_col_width) - (strlen((char *)list->name + 1));
|
||||||
|
i++)
|
||||||
printf(" ");
|
printf(" ");
|
||||||
printf("│\n");
|
printf("│\n");
|
||||||
|
|
||||||
|
|
|
@ -129,7 +129,7 @@ void klist_sql_seed(klist *ctx) {}
|
||||||
* assuring things
|
* assuring things
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool klist_assure_user(klist *ctx, __uid_t id, char *name) {
|
bool klist_assure_user(const klist *ctx, const __uid_t id, const char *name) {
|
||||||
klist_user *user = klist_user_get_by_local(ctx, id);
|
klist_user *user = klist_user_get_by_local(ctx, id);
|
||||||
bool created = false;
|
bool created = false;
|
||||||
if (!user) {
|
if (!user) {
|
||||||
|
@ -143,8 +143,6 @@ bool klist_assure_user(klist *ctx, __uid_t id, char *name) {
|
||||||
klist_user_deinit(user);
|
klist_user_deinit(user);
|
||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
void klist_assure_list(klist *, char *);
|
|
||||||
void klist_assure_task(klist *, char *);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* printing methods
|
* printing methods
|
||||||
|
|
Loading…
Add table
Reference in a new issue