1
1
mirror of https://github.com/theoludwig/libcproject.git synced 2025-05-21 23:21:15 +02:00

refactor: include only in header files

This commit is contained in:
Divlo
2023-01-07 19:38:01 +01:00
parent 886038a0ac
commit bd85171e2d
41 changed files with 101 additions and 131 deletions

View File

@ -4,8 +4,6 @@
#include <stdbool.h>
#include <stdlib.h>
#include "linked_list.h"
#define ARRAY_LIST_INITIAL_CAPACITY 10
struct array_list {

View File

@ -1,10 +1,5 @@
#include "character.h"
#include <stdbool.h>
#include <stdlib.h>
#include "string.h"
void character_append(char* string, const char character) {
size_t length = string_get_length(string);
character_append_at(string, character, length);

View File

@ -4,6 +4,8 @@
#include <stdbool.h>
#include <stdlib.h>
#include "string.h"
/**
* @brief Append a character to a string, assuming string points to an array
* with enough space.

View File

@ -1,13 +1,5 @@
#include "convert.h"
#include <stdio.h>
#include <stdlib.h>
#include "character.h"
#include "mathematics.h"
#include "stdbool.h"
#include "string.h"
char* convert_character_to_string(const char character) {
char* string = malloc(sizeof(char*) * 2);
if (string == NULL) {

View File

@ -1,6 +1,14 @@
#ifndef __CONVERT__
#define __CONVERT__
#include <stdio.h>
#include <stdlib.h>
#include "character.h"
#include "mathematics.h"
#include "stdbool.h"
#include "string.h"
char* convert_character_to_string(const char character);
char convert_character_to_digit(const char character);

View File

@ -1,9 +1,5 @@
#include "dictionary.h"
#include <stdlib.h>
#include "string.h"
struct dictionary *dictionary_initialization() {
struct dictionary *dictionary = malloc(sizeof(struct dictionary));
dictionary->items = malloc(sizeof(struct dictionary_item *) * DICTIONARY_INITIAL_CAPACITY);

View File

@ -4,7 +4,7 @@
#include <stdbool.h>
#include <stdlib.h>
#include "linked_list.h"
#include "string.h"
#define DICTIONARY_INITIAL_CAPACITY 10

View File

@ -1,16 +1,5 @@
#include "filesystem.h"
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <pwd.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "string.h"
int filesystem_read(char *path, char **file_content, off_t *file_size) {
int file_descriptor = open(path, O_RDONLY);
if (file_descriptor == -1) {

View File

@ -1,7 +1,16 @@
#ifndef __FILESYSTEM__
#define __FILESYSTEM__
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <pwd.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "string.h"
/**
* @brief Read the content of a file.

View File

@ -1,10 +1,5 @@
#include "linked_list.h"
#include <stdbool.h>
#include <stdlib.h>
#include "stack.h"
struct linked_list *linked_list_initialization() {
struct linked_list *list = malloc(sizeof(*list));
if (list == NULL) {

View File

@ -1,10 +1,12 @@
#ifndef __LINKED_LIST__
#define __LINKED_LIST__
#include <stdbool.h>
#include <stdlib.h>
#include "stack.h"
struct linked_list {
// first node of the list
struct linked_list_node *head;
size_t length;

View File

@ -1,7 +1,5 @@
#include "mathematics.h"
#include <stdbool.h>
bool mathematics_equals(const float number1, const float number2) {
return (number1 - number2) < MATHEMATICS_FLOAT_PRECISION;
}

View File

@ -1,8 +1,5 @@
#include "queue.h"
#include <stdio.h>
#include <stdlib.h>
struct queue *queue_initialization() {
struct queue *queue = malloc(sizeof(*queue));
if (queue == NULL) {

View File

@ -1,6 +1,7 @@
#ifndef __QUEUE__
#define __QUEUE__
#include <stdio.h>
#include <stdlib.h>
// FIFO = First In First Out

View File

@ -1,8 +1,5 @@
#include "stack.h"
#include <stdio.h>
#include <stdlib.h>
struct stack *stack_initialization() {
struct stack *stack = malloc(sizeof(*stack));
if (stack == NULL) {

View File

@ -1,6 +1,7 @@
#ifndef __STACK__
#define __STACK__
#include <stdio.h>
#include <stdlib.h>
// LIFO = Last In First Out

View File

@ -1,13 +1,5 @@
#include "string.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "character.h"
#include "convert.h"
#include "dictionary.h"
size_t string_get_length(const char* string) {
size_t length = 0;
while (string[length] != '\0') {

View File

@ -2,8 +2,13 @@
#define __STRING__
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "character.h"
#include "convert.h"
#include "dictionary.h"
/**
* @brief Return the length of a string (excluding '\0').
*
@ -100,7 +105,7 @@ char* string_reverse(const char* string);
*
* @param string1
* @param string2
* @return true if the strings are equals, false otherwise
* @return true if the strings are equals, false otherwise.
*/
bool string_equals(const char* string1, const char* string2);
@ -108,7 +113,7 @@ bool string_equals(const char* string1, const char* string2);
* @brief Check if the string is a integer.
*
* @param string
* @return true if the string is a integer, false otherwise
* @return true if the string is a integer, false otherwise.
*/
bool string_get_is_integer(const char* string);
@ -143,7 +148,7 @@ char* string_concatenate(char* string1, char* string2);
* @brief Check if a string contains only unique characters.
*
* @param string
* @return true if string contains only unique characters, false otherwise
* @return true if string contains only unique characters, false otherwise.
*/
bool string_get_has_unique_characters(const char* string);
@ -162,7 +167,7 @@ char* string_substring(const char* string, size_t index_start, size_t index_end)
*
* @param string
* @param substring
* @return true if the string contains the substring, false otherwise
* @return true if the string contains the substring, false otherwise.
*/
bool string_get_is_substring(const char* string, const char* substring);
@ -188,7 +193,7 @@ char* string_get_last_occurence_of_character(const char* string, char character)
*
* @param string
* @param prefix
* @return true if the string starts with the substring, false otherwise
* @return true if the string starts with the substring, false otherwise.
*/
bool string_starts_with(const char* string, const char* prefix);
@ -197,7 +202,7 @@ bool string_starts_with(const char* string, const char* prefix);
*
* @param string
* @param prefix
* @return true if the string ends with the substring, false otherwise
* @return true if the string ends with the substring, false otherwise.
*/
bool string_ends_with(const char* string, const char* prefix);

View File

@ -1,16 +1,5 @@
#include "terminal.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "character.h"
#include "dictionary.h"
#include "linked_list.h"
#include "queue.h"
#include "stack.h"
char* terminal_input() {
char character;
size_t length = 1;

View File

@ -1,8 +1,12 @@
#ifndef __TERMINAL__
#define __TERMINAL__
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "character.h"
#include "dictionary.h"
#include "linked_list.h"
#include "queue.h"