src: add debug logs for function entrance
This commit is contained in:
parent
220ba85011
commit
f0db572265
@ -15,6 +15,7 @@ static void __attribute__((constructor)) init_cdo(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main (int argc, char *argv[]) {
|
int main (int argc, char *argv[]) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
struct ArgList* args = parse_args(argc, argv);
|
struct ArgList* args = parse_args(argc, argv);
|
||||||
const char* relative_project_path = extract_value_from_arg(args, ARG_PROJECT);
|
const char* relative_project_path = extract_value_from_arg(args, ARG_PROJECT);
|
||||||
const char* full_path = convert_relative_to_full_path(relative_project_path);
|
const char* full_path = convert_relative_to_full_path(relative_project_path);
|
||||||
|
|||||||
12
src/cmd.c
12
src/cmd.c
@ -25,6 +25,7 @@ static const char* PREDEFINED_ARG_VALUES [] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void usage(void) {
|
void usage(void) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
Buffer * usage_lines = buffer_create(DEFAULT_USAGE_LINE_LEN);
|
Buffer * usage_lines = buffer_create(DEFAULT_USAGE_LINE_LEN);
|
||||||
buffer_append(usage_lines, "Usage: cdo [OPTION]...\n");
|
buffer_append(usage_lines, "Usage: cdo [OPTION]...\n");
|
||||||
buffer_append(usage_lines, "Parse TODO's of the PROJECT.\n\n");
|
buffer_append(usage_lines, "Parse TODO's of the PROJECT.\n\n");
|
||||||
@ -44,6 +45,7 @@ void usage(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct CommandLineArg* renderArgById(ArgNameId name) {
|
static struct CommandLineArg* renderArgById(ArgNameId name) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
struct CommandLineArg* e = cdo_malloc(sizeof(struct CommandLineArg));
|
struct CommandLineArg* e = cdo_malloc(sizeof(struct CommandLineArg));
|
||||||
e->name = NULL;
|
e->name = NULL;
|
||||||
e->description = NULL;
|
e->description = NULL;
|
||||||
@ -69,6 +71,7 @@ static struct CommandLineArg* renderArgByValues(
|
|||||||
const char* description,
|
const char* description,
|
||||||
const char* value,
|
const char* value,
|
||||||
ArgNameId id) {
|
ArgNameId id) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
struct CommandLineArg* e = cdo_malloc(sizeof(struct CommandLineArg));
|
struct CommandLineArg* e = cdo_malloc(sizeof(struct CommandLineArg));
|
||||||
e->name = NULL;
|
e->name = NULL;
|
||||||
e->description = NULL;
|
e->description = NULL;
|
||||||
@ -90,6 +93,7 @@ static struct CommandLineArg* renderArgByValues(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void init_cmd(void) {
|
void init_cmd(void) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
supported_args = create_arg_list(ARG_COUNT);
|
supported_args = create_arg_list(ARG_COUNT);
|
||||||
for (int i = 0; i < ARG_COUNT; i++) {
|
for (int i = 0; i < ARG_COUNT; i++) {
|
||||||
switch (i)
|
switch (i)
|
||||||
@ -106,10 +110,12 @@ void init_cmd(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void exit_cmd(void) {
|
void exit_cmd(void) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
free_arg_list(supported_args);
|
free_arg_list(supported_args);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ArgList* create_arg_list(size_t capacity) {
|
struct ArgList* create_arg_list(size_t capacity) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
struct ArgList* list = NULL;
|
struct ArgList* list = NULL;
|
||||||
list = (struct ArgList*) cdo_malloc(sizeof(struct ArgList));
|
list = (struct ArgList*) cdo_malloc(sizeof(struct ArgList));
|
||||||
list->args = (struct CommandLineArg*) cdo_malloc(capacity * sizeof(struct CommandLineArg));
|
list->args = (struct CommandLineArg*) cdo_malloc(capacity * sizeof(struct CommandLineArg));
|
||||||
@ -119,6 +125,7 @@ struct ArgList* create_arg_list(size_t capacity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void append_arg(struct ArgList* list, struct CommandLineArg* arg) {
|
void append_arg(struct ArgList* list, struct CommandLineArg* arg) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
if (list->size + 1 >= list->capacity) {
|
if (list->size + 1 >= list->capacity) {
|
||||||
list->capacity *= 2;
|
list->capacity *= 2;
|
||||||
list->args =
|
list->args =
|
||||||
@ -134,6 +141,7 @@ void append_arg(struct ArgList* list, struct CommandLineArg* arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char* extract_value_from_arg(struct ArgList* list, ArgNameId id) {
|
const char* extract_value_from_arg(struct ArgList* list, ArgNameId id) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
for (size_t i = 0; i < ARG_COUNT; i++) {
|
for (size_t i = 0; i < ARG_COUNT; i++) {
|
||||||
if (list->args[i].id == id) {
|
if (list->args[i].id == id) {
|
||||||
return list->args[i].value;
|
return list->args[i].value;
|
||||||
@ -143,6 +151,7 @@ const char* extract_value_from_arg(struct ArgList* list, ArgNameId id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void free_arg_list(struct ArgList* list) {
|
void free_arg_list(struct ArgList* list) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
for (size_t i = 0; i < list->size; i++) {
|
for (size_t i = 0; i < list->size; i++) {
|
||||||
cdo_free(list->args[i].name);
|
cdo_free(list->args[i].name);
|
||||||
cdo_free(list->args[i].description);
|
cdo_free(list->args[i].description);
|
||||||
@ -154,6 +163,7 @@ void free_arg_list(struct ArgList* list) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ArgNameId get_arg_name_id_from_str(const char* str) {
|
static ArgNameId get_arg_name_id_from_str(const char* str) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
for (int i = 0; i < ARG_COUNT; i++) {
|
for (int i = 0; i < ARG_COUNT; i++) {
|
||||||
if (strcmp(str, PREDEFINED_ARG_NAMES[i]) == 0)
|
if (strcmp(str, PREDEFINED_ARG_NAMES[i]) == 0)
|
||||||
return (ArgNameId)i;
|
return (ArgNameId)i;
|
||||||
@ -162,6 +172,7 @@ static ArgNameId get_arg_name_id_from_str(const char* str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool validate_arg_param(const char* str) {
|
static bool validate_arg_param(const char* str) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
for (int i = 0; i < ARG_COUNT; i++) {
|
for (int i = 0; i < ARG_COUNT; i++) {
|
||||||
if (strcmp(str, PREDEFINED_ARG_NAMES[i]) == 0)
|
if (strcmp(str, PREDEFINED_ARG_NAMES[i]) == 0)
|
||||||
return false;
|
return false;
|
||||||
@ -170,6 +181,7 @@ static bool validate_arg_param(const char* str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct ArgList* parse_args(const int argc, char* argv[]) {
|
struct ArgList* parse_args(const int argc, char* argv[]) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
int initial_capacity = 1;
|
int initial_capacity = 1;
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
initial_capacity = argc / 2;
|
initial_capacity = argc / 2;
|
||||||
|
|||||||
@ -15,6 +15,7 @@ const char* SUPPORTED_PLATFORM_NAMES [] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PlaformId identify_platfrom_from_project(const char* project_path) {
|
PlaformId identify_platfrom_from_project(const char* project_path) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
if (project_path == NULL) {
|
if (project_path == NULL) {
|
||||||
LOG_ERROR_EXIT("No path supplied for project.");
|
LOG_ERROR_EXIT("No path supplied for project.");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
const char* convert_relative_to_full_path(const char* relative_path) {
|
const char* convert_relative_to_full_path(const char* relative_path) {
|
||||||
//TODO: generate correct path when relative path is ../ or etc
|
//TODO: generate correct path when relative path is ../ or etc
|
||||||
LOG_DEBUG("Entering convert_relative_to_full_path function");
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
|
|
||||||
char* cwd;
|
char* cwd;
|
||||||
cwd = getcwd(NULL, 0);
|
cwd = getcwd(NULL, 0);
|
||||||
|
|||||||
@ -10,6 +10,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
Buffer* buffer_create(size_t capacity) {
|
Buffer* buffer_create(size_t capacity) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
Buffer* buffer = (Buffer*)cdo_malloc(sizeof(Buffer));
|
Buffer* buffer = (Buffer*)cdo_malloc(sizeof(Buffer));
|
||||||
buffer->data = (char*)cdo_malloc(capacity);
|
buffer->data = (char*)cdo_malloc(capacity);
|
||||||
buffer->size = 0;
|
buffer->size = 0;
|
||||||
@ -18,6 +19,7 @@ Buffer* buffer_create(size_t capacity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void buffer_append(Buffer* buffer, const char* str) {
|
void buffer_append(Buffer* buffer, const char* str) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
size_t len = strlen(str);
|
size_t len = strlen(str);
|
||||||
if (buffer->size + len >= buffer->capacity) {
|
if (buffer->size + len >= buffer->capacity) {
|
||||||
buffer->capacity *= 2;
|
buffer->capacity *= 2;
|
||||||
@ -28,6 +30,7 @@ void buffer_append(Buffer* buffer, const char* str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void buffer_append_c(Buffer* buffer, char c) {
|
void buffer_append_c(Buffer* buffer, char c) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
if (buffer->size + 1 >= buffer->capacity) {
|
if (buffer->size + 1 >= buffer->capacity) {
|
||||||
buffer->capacity *= 2;
|
buffer->capacity *= 2;
|
||||||
buffer->data = (char*)cdo_realloc(buffer->data, buffer->capacity);
|
buffer->data = (char*)cdo_realloc(buffer->data, buffer->capacity);
|
||||||
@ -37,11 +40,13 @@ void buffer_append_c(Buffer* buffer, char c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void buffer_flush(Buffer* buffer) {
|
void buffer_flush(Buffer* buffer) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
printf("%s", buffer->data);
|
printf("%s", buffer->data);
|
||||||
buffer_free(buffer);
|
buffer_free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void buffer_free(Buffer* buffer) {
|
void buffer_free(Buffer* buffer) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
cdo_free(buffer->data);
|
cdo_free(buffer->data);
|
||||||
buffer->data = NULL;
|
buffer->data = NULL;
|
||||||
cdo_free(buffer);
|
cdo_free(buffer);
|
||||||
@ -49,6 +54,7 @@ void buffer_free(Buffer* buffer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Lines* lines_create(size_t capacity) {
|
Lines* lines_create(size_t capacity) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
Lines* _lines = (Lines*)cdo_malloc(sizeof(Lines));
|
Lines* _lines = (Lines*)cdo_malloc(sizeof(Lines));
|
||||||
_lines->lines = (Buffer**)cdo_malloc(capacity * sizeof(Buffer*));
|
_lines->lines = (Buffer**)cdo_malloc(capacity * sizeof(Buffer*));
|
||||||
_lines->size = 0;
|
_lines->size = 0;
|
||||||
@ -57,6 +63,7 @@ Lines* lines_create(size_t capacity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Lines* read_file_lines(const char* file_path) {
|
Lines* read_file_lines(const char* file_path) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
FILE* _file_pointer = fopen(file_path, "r");
|
FILE* _file_pointer = fopen(file_path, "r");
|
||||||
if (_file_pointer == NULL) {
|
if (_file_pointer == NULL) {
|
||||||
LOG_ERROR_EXIT("Could not open file %s. ERRNO %d; %s",
|
LOG_ERROR_EXIT("Could not open file %s. ERRNO %d; %s",
|
||||||
@ -100,6 +107,7 @@ Lines* read_file_lines(const char* file_path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void lines_append(Lines* lines, Buffer* buffer) {
|
void lines_append(Lines* lines, Buffer* buffer) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
if (lines->size + 1 >= lines->capacity) {
|
if (lines->size + 1 >= lines->capacity) {
|
||||||
lines->capacity *= 2;
|
lines->capacity *= 2;
|
||||||
lines->lines = (Buffer**)cdo_realloc(lines->lines, lines->capacity * sizeof(Buffer*));
|
lines->lines = (Buffer**)cdo_realloc(lines->lines, lines->capacity * sizeof(Buffer*));
|
||||||
@ -112,6 +120,7 @@ void lines_append(Lines* lines, Buffer* buffer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void lines_flush(Lines* lines) {
|
void lines_flush(Lines* lines) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
for(size_t i = 0; i < lines->size; i++) {
|
for(size_t i = 0; i < lines->size; i++) {
|
||||||
printf("%s\n", lines->lines[i]->data);
|
printf("%s\n", lines->lines[i]->data);
|
||||||
buffer_free(lines->lines[i]);
|
buffer_free(lines->lines[i]);
|
||||||
@ -123,6 +132,7 @@ void lines_flush(Lines* lines) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void lines_free(Lines* lines) {
|
void lines_free(Lines* lines) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
for(size_t i = 0; i < lines->size; i++) {
|
for(size_t i = 0; i < lines->size; i++) {
|
||||||
buffer_free(lines->lines[i]);
|
buffer_free(lines->lines[i]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ char* cdo_log_enable_debug = NULL;
|
|||||||
char* cdo_log_enable_verbose = NULL;
|
char* cdo_log_enable_verbose = NULL;
|
||||||
|
|
||||||
void init_log(void) {
|
void init_log(void) {
|
||||||
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
cdo_log_enable_color = getenv(LOG_COLORED_OUTPUT_ENV);
|
cdo_log_enable_color = getenv(LOG_COLORED_OUTPUT_ENV);
|
||||||
cdo_log_enable_debug = getenv(LOG_DEBUG_MESSAGES_ENV);
|
cdo_log_enable_debug = getenv(LOG_DEBUG_MESSAGES_ENV);
|
||||||
cdo_log_enable_verbose = getenv(LOG_VERBOSITY_ENV);
|
cdo_log_enable_verbose = getenv(LOG_VERBOSITY_ENV);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user