[WIP] Refactor project

There are many problems with the way the current version is provided
and maintained. This commit or series of commits will fix this.
This commit is contained in:
Piotr Krygier committed 2025-06-20 13:44:33 +02:00
1 parent f5ab5f3f27
commit 173a82b9d1
63 files changed
+2663 -2239

No files matched your search

+6 -6
View File
@@ -1,16 +1,16 @@
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
add_library(rse_utilities SHARED)
add_library(utilities SHARED)
target_include_directories(rse_utilities PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
target_include_directories(utilities PRIVATE
${PROJECT_SOURCE_DIR}
)
target_sources(rse_utilities PRIVATE
target_sources(utilities PRIVATE
src/file_utils.c
src/logger.c
src/rse_task_linux.c
src/task_linux.c
)
target_link_libraries(rse_utilities PRIVATE
target_link_libraries(utilities PRIVATE
pthread)
@@ -1,5 +1,5 @@
/**
* @file rse_commons.h
* @file commons.h
* @author Piotr Krygier (everyonecancode@gmail.com)
* @brief Common functionality for all modules
* @version 0.1
@@ -9,11 +9,13 @@
*
*/
#ifndef RSE_COMMONS_H
#define RSE_COMMONS_H
#ifndef COMMONS_H
#define COMMONS_H
#include "utilities/logger.h"
#include "utilities/locale_common.h"
#include <stdint.h>
#include <stdlib.h>
/**
* @brief Macro for allocating memory and checking it on the same line
@@ -23,17 +25,19 @@
#define rse_malloc(ptr, size) \
ptr = malloc(size); \
if (ptr == NULL) { \
LOGF(common_messages[COMMON_ERROR_MEMORY_ALLOCATION_FAILED]); \
LOGF(_("Memory allocation failed\n")); \
exit(1); \
}
#define rse_free(ptr) free(ptr);
#define rse_memcpy(dst, src, size) memcpy(dst, src, size);
#define rse_memset(ptr, value, size) memset(ptr, value, size);
#else
#define rse_malloc(ptr, size) ptr = NULL;
#define rse_free(ptr)
#define rse_memcpy(dst, src, size)
#define rse_memset
#endif
/**
@@ -42,4 +46,4 @@ if (ptr == NULL) { \
*/
typedef uint32_t rse_err_t;
#endif /* RSE_COMMONS_H */
#endif /* COMMONS_H */
@@ -1,5 +1,5 @@
/**
* @file rse_errors_common.h
* @file errors_common.h
* @author Piotr Krygier (everyonecancode@gmail.com)
* @brief Common error messages, that can appear in any module
* @version 0.1
@@ -9,7 +9,7 @@
*
*/
#ifndef RSE_ERRORS_COMMON_H
#ifndef ERRORS_COMMON_H
/* Macro for checking status of function execution in initVulkan. Created to avoid writing boilerplate code */
#define STATUS_CHECK(FUNC) \
@@ -20,11 +20,12 @@
#define RSE_COMMON_MODULE_ID 0x0100U
enum rse_common_error_t
enum common_error_t
{
RSE_ERROR_NO_ERROR = RSE_COMMON_MODULE_ID,
RSE_ERROR_ALREADY_INITIALIZED,
RSE_COMMON_ERROR_MALLLOC_FAILED,
};
#define RSE_ERRORS_COMMON_H
#endif /* RSE_ERRORS_COMMON_H */
#define ERRORS_COMMON_H
#endif /* ERRORS_COMMON_H */
+5 -5
View File
@@ -1,5 +1,5 @@
#ifndef RSE_FILE_UTILS_H
#define RSE_FILE_UTILS_H
#ifndef FILE_UTILS_H
#define FILE_UTILS_H
#include <stddef.h>
@@ -11,9 +11,9 @@
* @param bytes_count Returned bytes count
* @param buffer Returned filled buffer
*/
void rse_read_file(const char* file_path, long* bytes_count, char* buffer);
void read_file(const char* file_path, size_t* bytes_count, char* buffer);
void rse_write_to_file(const char* file_name, long bytes_count, char* buffer);
void write_to_file(const char* file_name, size_t bytes_count, char* buffer);
#endif /* RSE_FILE_UTILS_H */
#endif /* FILE_UTILS_H */
+128
View File
@@ -0,0 +1,128 @@
/**
* @file linked_list.h
* @author Piotr Krygier (everyonecancode@gmail.com)
* @brief
* @version 0.1
* @date 2024-05-01
*
* @copyright Copyright (c) 2024
*
*/
#ifndef LINKED_LIST_H
#define LINKED_LIST_H
#include "utilities/commons.h"
/**
* @brief Define a linked list structure
*
* @param name Name of the linked list structure
* @param type Type of the data stored in the linked list
* @return struct name { type data; struct name *next; }
* @note This macro defines a linked list structure with a given name and data type
*/
#define RSE_LINKED_LIST_DEFINE(name, type) \
struct name { \
type data; \
struct name *next; \
}
#define RSE_LINKED_LIST_PUSH_FRONT(list, value) \
typeof(list) new_node = NULL; \
rse_malloc(new_node, sizeof(*(list))); \
new_node->data = value; \
new_node->next = list; \
list = new_node
#define RSE_LINKED_LIST_PUSH_BACK(list, value) \
typeof(list) new_node = NULL; \
rse_malloc(new_node, sizeof(*(list))); \
new_node->data = value; \
new_node->next = NULL; \
if (list == NULL) { \
list = new_node; \
} else { \
typeof(list) current = list; \
while (current->next != NULL) { \
current = current->next; \
} \
current->next = new_node; \
}
#define RSE_LINKED_LIST_POP_FRONT(list) \
if (list != NULL) { \
typeof(list) temp = list; \
list = list->next; \
rse_free(temp); \
}
#define RSE_LINKED_LIST_POP_BACK(list) \
if (list != NULL) { \
if (list->next == NULL) { \
rse_free(list); \
list = NULL; \
} else { \
typeof(list) *current = list; \
while (current->next->next != NULL) { \
current = current->next; \
} \
rse_free(current->next); \
current->next = NULL; \
} \
}
#define RSE_LINKED_LIST_FRONT(list) \
list->data
#define RSE_LINKED_LIST_BACK(list) \
if (list != NULL) { \
typeof(list) *current = list; \
while (current->next != NULL) { \
current = current->next; \
} \
current->data; \
}
#define RSE_LINKED_LIST_IS_EMPTY(list) \
list == NULL
#define RSE_LINKED_LIST_SIZE(list) \
({ \
int size = 0; \
typeof(list) current = list; \
while (current != NULL) { \
size++; \
current = current->next; \
} \
size; \
})
#define RSE_LINKED_LIST_CLEAR(list) \
while (list != NULL) { \
typeof(list) temp = list; \
list = list->next; \
rse_free(temp); \
}
#define RSE_LINKED_LIST_FOREACH(list, i) \
for (typeof(list) i = list; i != NULL; i = i->next)
#define RSE_LINKED_LIST_FOREACH_REVERSE(list, i) \
for (typeof(list) i = list; i != NULL; i = i->next)
#define RSE_LINKED_LIST_TO_ARRAY(list, array) \
({ \
int size = RSE_LINKED_LIST_SIZE(list); \
rse_malloc(array, size * sizeof(*(list))); \
int i = 0; \
RSE_LINKED_LIST_FOREACH(list, current) { \
array[i++] = current->data; \
} \
size; \
})
#endif // LINKED_LIST_H
+3 -3
View File
@@ -9,8 +9,8 @@
*
*/
#ifndef RSE_LOCALE_COMMON_H
#define RSE_LOCALE_COMMON_H
#ifndef LOCALE_COMMON_H
#define LOCALE_COMMON_H
#include "localization.h"
@@ -28,4 +28,4 @@ static const char common_messages_nolocale[LAST_LANGUAGE][COMMON_ERROR_LAST_MESS
}
};
#endif /* RSE_LOCALE_COMMON_H */
#endif /* LOCALE_COMMON_H */
+7 -15
View File
@@ -1,7 +1,7 @@
/**
* @file localization.h
* @author Piotr Krygier (everyonencancode@gmail.com)
* @brief Simple localization header
* @brief Simple localization header. Gettext is used for localization
* @version 0.1
* @date 2022-02-15
*
@@ -9,20 +9,12 @@
*
*/
#ifndef RSE_LOCALIZATION_H
#define RSE_LOCALIZATION_H
#ifndef LOCALIZATION_H
#define LOCALIZATION_H
#define SELECTED_LANGUAGE EN_US
#define MAX_MESSAGE_LENGHT 128
#include <libintl.h>
/**
* @brief Available languages
*
*/
enum languages_t
{
EN_US = 0,
LAST_LANGUAGE
};
/* Enable localization */
#define _(STRING) gettext(STRING)
#endif /* RSE_LOCALIZATION_H */
#endif /* LOCALIZATION_H */
+4 -4
View File
@@ -1,5 +1,5 @@
/**
* @file log.h
* @file logger.h
* @author Piotr Krygier (everyonencancode@gmail.com)
* @brief Logging interfaces
* @version 0.1
@@ -9,8 +9,8 @@
*
*/
#ifndef RSE_LOGGER_H
#define RSE_LOGGER_H
#ifndef LOGGER_H
#define LOGGER_H
#include <stdio.h>
#include <string.h>
@@ -42,4 +42,4 @@ enum log_level_t
void _log_log(unsigned int level, const char* file, int line, const char* fmt, ...);
#endif /* RSE_LOGGER_H */
#endif /* LOGGER_H */
-28
View File
@@ -1,28 +0,0 @@
/**
* @file rse_task.h
* @author Piotr Krygier (everyonecancode@gmail.com)
* @brief Threads wrapper
* @version 0.1
* @date 2023-08-14
*
* @copyright Copyright (c) 2023
*
*/
#ifndef RSE_THREADS_H
#define RSE_THREADS_H
#include <stdint.h>
#ifdef __linux__
#include <pthread.h>
typedef pthread_t rse_thread_t;
#endif
typedef void*(*thread_worker_t)(void*);
uint8_t rse_create_task(rse_thread_t* thread_id, thread_worker_t callback, void* args);
uint8_t rse_task_join(rse_thread_t* thread_id);
void rse_task_exit(void);
#endif /* RSE_THREADS_H */
+2 -2
View File
@@ -3,7 +3,7 @@
#include <stdio.h>
#include <stdlib.h>
void rse_read_file(const char* file_name, long* bytes_count, char* buffer)
void read_file(const char* file_name, size_t* bytes_count, char* buffer)
{
FILE* file;
@@ -24,7 +24,7 @@ void rse_read_file(const char* file_name, long* bytes_count, char* buffer)
fclose(file);
}
void rse_write_to_file(const char* file_name, long bytes_count, char* buffer)
void write_to_file(const char* file_name, size_t bytes_count, char* buffer)
{
FILE* file;
@@ -1,6 +1,6 @@
#include "rse_task.h"
#include "task.h"
uint8_t rse_create_task(rse_thread_t* thread_id, thread_worker_t callback, void* args)
uint8_t create_task(thread_t* thread_id, thread_worker_t callback, void* args)
{
uint8_t result = 0;
@@ -9,7 +9,7 @@ uint8_t rse_create_task(rse_thread_t* thread_id, thread_worker_t callback, void*
return result; //TODO: Do error handling
}
uint8_t rse_task_join(rse_thread_t* thread_id)
uint8_t task_join(thread_t* thread_id)
{
uint8_t result = 0;
@@ -18,7 +18,7 @@ uint8_t rse_task_join(rse_thread_t* thread_id)
return result; //TODO: Do error handling
}
void rse_task_exit()
void task_exit()
{
pthread_exit(NULL);
}
+45
View File
@@ -0,0 +1,45 @@
/**
* @file stack.h
* @author Piotr Krygier (everyonecancode@gmail.com)
* @brief
* @version 0.1
* @date 2024-05-01
*
* @copyright Copyright (c) 2024
*
*/
#ifndef STACK_H
#define STACK_H
#define RSE_STACK_DEFINE(name, type, size) \
struct name { \
type data[size]; \
int top; \
}
#define RSE_STACK_PUSH(stack, value) \
stack.data[++stack.top] = value
#define RSE_STACK_POP(stack) \
stack.data[stack.top--]
#define RSE_STACK_TOP(stack) \
stack.data[stack.top]
#define RSE_STACK_IS_EMPTY(stack) \
stack.top == -1
#define RSE_STACK_IS_FULL(stack, size) \
stack.top == size - 1
#define RSE_STACK_INIT(stack) \
stack.top = -1
#define RSE_STACK_SIZE(stack) \
stack.top + 1
#define RSE_STACK_CLEAR(stack) \
stack.top = -1
#endif // STACK_H
+28
View File
@@ -0,0 +1,28 @@
/**
* @file task.h
* @author Piotr Krygier (everyonecancode@gmail.com)
* @brief Threads wrapper
* @version 0.1
* @date 2023-08-14
*
* @copyright Copyright (c) 2023
*
*/
#ifndef THREADS_H
#define THREADS_H
#include <stdint.h>
#ifdef __linux__
#include <pthread.h>
typedef pthread_t thread_t;
#endif
typedef void*(*thread_worker_t)(void*);
uint8_t create_task(thread_t* thread_id, thread_worker_t callback, void* args);
uint8_t task_join(thread_t* thread_id);
void task_exit(void);
#endif /* THREADS_H */