Commit 0809995e authored by Chris Müller's avatar Chris Müller

move header into its folder. Small refactorings in naming conventions

parent d6691d7d
...@@ -8,7 +8,7 @@ set(VERSION "0.1") ...@@ -8,7 +8,7 @@ set(VERSION "0.1")
include(${PROJECT_SOURCE_DIR}/macros/standard.cmake) include(${PROJECT_SOURCE_DIR}/macros/standard.cmake)
include_directories(src) include_directories(include)
add_subdirectory(src) add_subdirectory(src)
add_subdirectory(test) add_subdirectory(test)
......
...@@ -15,9 +15,7 @@ ...@@ -15,9 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#pragma once
#ifndef CRYSTAL_STRUCTURES_ARRAY_H
#define CRYSTAL_STRUCTURES_ARRAY_H
/** /**
* @file structures/array.h * @file structures/array.h
...@@ -52,10 +50,10 @@ size_t cry_array_ensure(struct CryArray* array, size_t min_capa ...@@ -52,10 +50,10 @@ size_t cry_array_ensure(struct CryArray* array, size_t min_capa
size_t cry_array_trim(struct CryArray* array); size_t cry_array_trim(struct CryArray* array);
void cry_array_append(struct CryArray* array, const_pointer data, size_t size); void cry_array_append(struct CryArray* array, const_pointer data, size_t size);
return_code cry_array_insert(struct CryArray* array, size_t index, const_pointer data, size_t size); int cry_array_insert(struct CryArray* array, size_t index, const_pointer data, size_t size);
return_code cry_array_remove(struct CryArray* array, size_t index, size_t size); int cry_array_remove(struct CryArray* array, size_t index, size_t size);
return_code cry_array_replace(struct CryArray* array, size_t index, const_pointer data, size_t size); int cry_array_replace(struct CryArray* array, size_t index, const_pointer data, size_t size);
void cry_array_clear(struct CryArray* array); void cry_array_clear(struct CryArray* array);
pointer cry_array_clone(struct CryArray* array); pointer cry_array_clone(struct CryArray* array);
pointer cry_array_get(struct CryArray* array, size_t index); pointer cry_array_get(struct CryArray* array, size_t index);
...@@ -73,14 +71,13 @@ size_t cry_ptr_array_trim(struct CryPtrArray* array); ...@@ -73,14 +71,13 @@ size_t cry_ptr_array_trim(struct CryPtrArray* array);
void cry_ptr_array_append(struct CryPtrArray* array, pointer ptr); void cry_ptr_array_append(struct CryPtrArray* array, pointer ptr);
return_code cry_ptr_array_insert(struct CryPtrArray* array, size_t index, pointer ptr); int cry_ptr_array_insert(struct CryPtrArray* array, size_t index, pointer ptr);
pointer cry_ptr_array_remove(struct CryPtrArray* array, size_t index); pointer cry_ptr_array_remove(struct CryPtrArray* array, size_t index);
pointer cry_ptr_array_replace(struct CryPtrArray* array, size_t index, pointer ptr); pointer cry_ptr_array_replace(struct CryPtrArray* array, size_t index, pointer ptr);
void cry_ptr_array_clear(struct CryPtrArray* array, cry_free_funptr fun); void cry_ptr_array_clear(struct CryPtrArray* array, cry_free_funptr fun);
pointer cry_ptr_array_get(struct CryPtrArray* array, size_t index); pointer cry_ptr_array_get(struct CryPtrArray* array, size_t index);
void cry_ptr_array_each(struct CryPtrArray* array, cry_foreach_funptr fun, pointer data); void cry_ptr_array_each(struct CryPtrArray* array, cry_foreach_funptr fun, pointer data);
#endif // CRYSTAL_STRUCTURES_ARRAY_H
...@@ -15,9 +15,7 @@ ...@@ -15,9 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#pragma once
#ifndef CRYSTAL_STRUCTURES_HEAP_H
#define CRYSTAL_STRUCTURES_HEAP_H
#include "structures.h" #include "structures.h"
...@@ -37,4 +35,3 @@ pointer cry_heap_pop(struct CryHeap* heap); ...@@ -37,4 +35,3 @@ pointer cry_heap_pop(struct CryHeap* heap);
#endif // CRYSTAL_STRUCTURES_HEAP_H
...@@ -15,9 +15,7 @@ ...@@ -15,9 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#pragma once
#ifndef CRYSTAL_STRUCTURES_LIST_H
#define CRYSTAL_STRUCTURES_LIST_H
#include "structures.h" #include "structures.h"
...@@ -28,8 +26,8 @@ struct CryList* cry_list_new(void); ...@@ -28,8 +26,8 @@ struct CryList* cry_list_new(void);
void cry_list_free(struct CryList* list, cry_free_funptr handler); void cry_list_free(struct CryList* list, cry_free_funptr handler);
size_t cry_list_size(struct CryList* list); size_t cry_list_size(struct CryList* list);
pointer cry_list_head(struct CryList* list); pointer cry_list_head(struct CryList* list);
pointer cry_list_tail(struct CryList* list); pointer cry_list_tail(struct CryList* list);
void cry_list_append(struct CryList* list, pointer data); void cry_list_append(struct CryList* list, pointer data);
void cry_list_prepend(struct CryList* list, pointer data); void cry_list_prepend(struct CryList* list, pointer data);
...@@ -49,4 +47,3 @@ pointer cry_list_remove(struct CryList* list, struct CryIndex* p ...@@ -49,4 +47,3 @@ pointer cry_list_remove(struct CryList* list, struct CryIndex* p
struct CryList* cry_list_concat(struct CryList* first, struct CryList* second); struct CryList* cry_list_concat(struct CryList* first, struct CryList* second);
#endif // CRYSTAL_STRUCTURES_LIST_H
...@@ -16,9 +16,7 @@ ...@@ -16,9 +16,7 @@
* *
*/ */
#ifndef CRYSTAL_STRUCTURES_MAP_H #pragma once
#define CRYSTAL_STRUCTURES_MAP_H
#include "structures.h" #include "structures.h"
...@@ -36,8 +34,6 @@ size_t cry_map_size(struct CryMap* map); ...@@ -36,8 +34,6 @@ size_t cry_map_size(struct CryMap* map);
pointer cry_map_lookup(struct CryMap* map, const_pointer key); pointer cry_map_lookup(struct CryMap* map, const_pointer key);
int cry_map_insert(struct CryMap* map, const_pointer key, const_pointer value); int cry_map_insert(struct CryMap* map, const_pointer key, const_pointer value);
struct CryMapPair cry_map_remove(struct CryMap* map, const_pointer key); struct CryMapPair cry_map_remove(struct CryMap* map, const_pointer key);
void cry_map_clear(struct CryMap* map, cry_free_funptr fun_key, cry_free_funptr fun_data); void cry_map_clear(struct CryMap* map, cry_free_funptr fun_key, cry_free_funptr fun_data);
#endif // CRYSTAL_STRUCTURES_MAP_H
...@@ -16,8 +16,7 @@ ...@@ -16,8 +16,7 @@
* *
*/ */
#ifndef CRYSTAL_STRUCTURES_QUEUE_H #pragma once
#define CRYSTAL_STRUCTURES_QUEUE_H
#include "structures.h" #include "structures.h"
...@@ -34,5 +33,3 @@ pointer cry_queue_nth(struct CryQueue* queue, size_t index); ...@@ -34,5 +33,3 @@ pointer cry_queue_nth(struct CryQueue* queue, size_t index);
pointer cry_queue_dequeue(struct CryQueue* queue); pointer cry_queue_dequeue(struct CryQueue* queue);
void cry_queue_enqueue(struct CryQueue* queue, pointer data); void cry_queue_enqueue(struct CryQueue* queue, pointer data);
#endif // CRYSTAL_STRUCTURES_QUEUE_H
...@@ -15,9 +15,7 @@ ...@@ -15,9 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#pragma once
#ifndef CRYSTAL_STRUCTURES_REDBLACKTREE_H
#define CRYSTAL_STRUCTURES_REDBLACKTREE_H
#include "structures.h" #include "structures.h"
...@@ -45,7 +43,7 @@ struct CryRbTree { ...@@ -45,7 +43,7 @@ struct CryRbTree {
struct CryRbTree* cry_rbtree_new(cry_ordering_funptr compare); struct CryRbTree* cry_rbtree_new(cry_ordering_funptr compare);
void cry_rbtree_clear(struct CryRbTree* tree, cry_free_funptr fun_entry, cry_free_funptr fun_data); void cry_rbtree_clear(struct CryRbTree* tree, cry_free_funptr fun_entry, cry_free_funptr fun_data);
struct CryRbNode* cry_rbtree_lookup(struct CryRbTree* tree, const_pointer entry); struct CryRbNode* cry_rbtree_lookup(struct CryRbTree* tree, const_pointer entry);
struct CryRbNode* cry_rbtree_insert(struct CryRbTree* tree, const_pointer entry, const_pointer data); struct CryRbNode* cry_rbtree_insert(struct CryRbTree* tree, const_pointer entry, const_pointer data);
...@@ -58,10 +56,5 @@ struct CryRbNode* cry_rbnode_next(struct CryRbNode* node); ...@@ -58,10 +56,5 @@ struct CryRbNode* cry_rbnode_next(struct CryRbNode* node);
struct CryRbNode* cry_rbnode_prev(struct CryRbNode* node); struct CryRbNode* cry_rbnode_prev(struct CryRbNode* node);
struct CryRbNode* cry_rbnode_new(enum CryRbNodeColor color, struct CryRbNode* parent, const_pointer entry, const_pointer data); struct CryRbNode* cry_rbnode_new(enum CryRbNodeColor color, struct CryRbNode* parent, const_pointer entry, const_pointer data);
void cry_rbnode_free(struct CryRbNode* node, cry_free_funptr fun_entry, cry_free_funptr fun_data); void cry_rbnode_free(struct CryRbNode* node, cry_free_funptr fun_entry, cry_free_funptr fun_data);
#endif // CRYSTAL_STRUCTURES_REDBLACKTREE_H
...@@ -15,9 +15,7 @@ ...@@ -15,9 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#pragma once
#ifndef CRYSTAL_STRUCTURES_STACK_H
#define CRYSTAL_STRUCTURES_STACK_H
#include "structures.h" #include "structures.h"
...@@ -33,4 +31,3 @@ pointer cry_stack_pop(struct CryStack* stack); ...@@ -33,4 +31,3 @@ pointer cry_stack_pop(struct CryStack* stack);
void cry_stack_push(struct CryStack* stack, pointer data); void cry_stack_push(struct CryStack* stack, pointer data);
#endif // CRYSTAL_STRUCTURES_STACK_H
...@@ -15,9 +15,7 @@ ...@@ -15,9 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#pragma once
#ifndef CRYSTAL_STANDARD_H
#define CRYSTAL_STANDARD_H
/** /**
* @file standard.h * @file standard.h
...@@ -27,46 +25,23 @@ ...@@ -27,46 +25,23 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
/**
* Convenient Macro for generating tuple types, returning error codes
* and data in a synchronous manner (without using return arguments via pointers)
* @param type Sets the type for the data field of this tuple
* @param T Sets the name for this tuple struct
*/
#define crydefine__tuple(type, T) \
struct T { \
return_code code; \
type data; \
}
/** General error code indicating all is fine */
#define CRY_OKAY 0
/** General error code indicating a failure occured */
#define CRY_FAIL -1
/** typedef to hide void* pointers for clearer interfaces */ /** typedef to hide void* pointers for clearer interfaces */
typedef void* pointer; typedef void* pointer;
/** typedef to hide void* const_pointers for clearer interfaces */ /** typedef to hide void* const_pointers for clearer interfaces */
typedef const void* const_pointer; typedef const void* const_pointer;
/** General typedef for setting an error code identifier */
typedef int return_code;
crydefine__tuple(pointer, tuple_pointer);
crydefine__tuple(const char*, tuple_string);
crydefine__tuple(int, tuple_int);
crydefine__tuple(short, tuple_short);
crydefine__tuple(long, tuple_long);
crydefine__tuple(double, tuple_double);
crydefine__tuple(float, tuple_float);
/** Smaller identifier for uint8_t */ /** Smaller identifier for uint8_t */
typedef uint8_t byte; typedef uint8_t byte_t;
/** Two bytes are a word */
typedef uint16_t word_t;
/** Unicode character type */ /** Unicode character type */
typedef uint32_t unicode; typedef uint32_t unicode_t;
#define FALSE 0
#define TRUE 1
/** /**
* Crystal's malloc macro for allocating memory based on a type * Crystal's malloc macro for allocating memory based on a type
...@@ -102,4 +77,3 @@ static void (*cry_free)(pointer data) = free; ...@@ -102,4 +77,3 @@ static void (*cry_free)(pointer data) = free;
*/ */
#define cry_cast(Type, Var) ((Type)Var) #define cry_cast(Type, Var) ((Type)Var)
#endif // CRYSTAL_STANDARD_H
...@@ -16,16 +16,11 @@ ...@@ -16,16 +16,11 @@
* *
*/ */
#ifndef CRYSTAL_STRUCTURES_H #pragma once
#define CRYSTAL_STRUCTURES_H
#include "../standard.h" #include "standard.h"
#define CRY_OUT_OF_INDEX_RANGE -1 typedef int (*cry_ordering_funptr)(const_pointer a, const_pointer b);
#define CRY_ENTRY_NOT_FOUND -2
#define CRY_ENTRY_FULL -3
typedef int (*cry_ordering_funptr)(const_pointer a, const_pointer b);
typedef void (*cry_foreach_funptr)(pointer element, pointer data); typedef void (*cry_foreach_funptr)(pointer element, pointer data);
typedef void (*cry_free_funptr)(pointer data); typedef void (*cry_free_funptr)(pointer data);
...@@ -33,4 +28,3 @@ int cry_int_compare(const_pointer a, const_pointer b); ...@@ -33,4 +28,3 @@ int cry_int_compare(const_pointer a, const_pointer b);
int cry_double_compare(const_pointer a, const_pointer b); int cry_double_compare(const_pointer a, const_pointer b);
#endif // CRYSTAL_STRUCTURES_H
...@@ -15,26 +15,35 @@ ...@@ -15,26 +15,35 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#ifndef CRYSTAL_UTF8_H
#define CRYSTAL_UTF8_H
#include "standard.h" #pragma once
int cry_utf8_validate(const byte* str);
int cry_utf8_compare(const byte* str1, const byte* str2);
byte* cry_utf8_chr(const byte* str, unicode character);
byte* cry_utf8_rchr(const byte* str, unicode character);
byte* cry_utf8_str(const byte* str1, const byte* str2);
size_t cry_utf8_size(const byte* str); #include "standard.h"
size_t cry_utf8_len(const byte* str);
unicode cry_utf8_get(const byte* str);
size_t cry_utf8_codepoints(const byte* str);
byte* cry_utf8_next(const byte* str);
byte* cry_utf8_prev(const byte* str);
#endif // CRYSTAL_UTF8_H
int cry_unicode_isblank(unicode_t ch);
int cry_unicode_isspace(unicode_t ch);
int cry_unicode_isalpha(unicode_t ch);
int cry_unicode_isalnum(unicode_t ch);
int cry_unicode_isdigit(unicode_t ch);
int cry_unicode_ishex(unicode_t ch);
int cry_unicode_isoct(unicode_t ch);
int cry_unicode_isprint(unicode_t ch);
int cry_unicode_isgraph(unicode_t ch);
int cry_unicode_ispunct(unicode_t ch);
int cry_unicode_iscntrl(unicode_t ch);
int cry_utf8_validate(const byte_t* str);
int cry_utf8_compare(const byte_t* str1, const byte_t* str2);
byte_t* cry_utf8_chr(const byte_t* str, unicode_t character);
byte_t* cry_utf8_rchr(const byte_t* str, unicode_t character);
byte_t* cry_utf8_str(const byte_t* str1, const byte_t* str2);
size_t cry_utf8_size(const byte_t* str);
size_t cry_utf8_len(const byte_t* str);
unicode_t cry_utf8_get(const byte_t* str);
size_t cry_utf8_codepoints(const byte_t* str);
byte_t* cry_utf8_next(const byte_t* str);
byte_t* cry_utf8_prev(const byte_t* str);
...@@ -15,9 +15,7 @@ ...@@ -15,9 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#pragma once
#ifndef CRYSTAL_UNITTEST_H
#define CRYSTAL_UNITTEST_H
#include "standard.h" #include "standard.h"
#include <assert.h> #include <assert.h>
...@@ -30,4 +28,3 @@ void cry_unittest_initialize(int argc, char** argv); ...@@ -30,4 +28,3 @@ void cry_unittest_initialize(int argc, char** argv);
void cry_unittest_finalize(void); void cry_unittest_finalize(void);
#endif // CRYSTAL_UNITTEST_H
...@@ -15,9 +15,7 @@ ...@@ -15,9 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#pragma once
#ifndef CRYSTAL_UNIXCOLORS_H
#define CRYSTAL_UNIXCOLORS_H
// Colors without bold attribute // Colors without bold attribute
#define CRY_NORMAL "\x1B[0m" #define CRY_NORMAL "\x1B[0m"
...@@ -60,4 +58,3 @@ ...@@ -60,4 +58,3 @@
#define CRY_BG_DARKCYAN "\x1B[1;46m" #define CRY_BG_DARKCYAN "\x1B[1;46m"
#define CRY_BG_WHITE "\x1B[1;47m" #define CRY_BG_WHITE "\x1B[1;47m"
#endif // CRYSTAL_UNIXCOLORS_H
set(SOURCES set(SOURCES
unittest.c unittest.c
utf8.c
unicode.c unicode.c
structures/single_linked_list.c structures/single_linked_list.c
structures/list.c structures/list.c
...@@ -15,7 +14,6 @@ set(HEADER ...@@ -15,7 +14,6 @@ set(HEADER
standard.h standard.h
unix_colors.h unix_colors.h
unittest.h unittest.h
utf8.h
unicode.h unicode.h
structures/structures.h structures/structures.h
structures/array.h structures/array.h
...@@ -30,6 +28,6 @@ set(HEADER ...@@ -30,6 +28,6 @@ set(HEADER
add_library(${TARGET_NAME} SHARED ${SOURCES}) add_library(${TARGET_NAME} SHARED ${SOURCES})
install(DIRECTORY . DESTINATION include/${TARGET_NAME} FILES_MATCHING PATTERN "*.h") install(DIRECTORY . DESTINATION include/${TARGET_NAME} FILES_MATCHING PATTERN "*.h")
#install(FILES ${HEADER} DESTINATION include/${TARGET_NAME}) install(FILES ${HEADER} DESTINATION include/${TARGET_NAME})
install(TARGETS ${TARGET_NAME} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib) install(TARGETS ${TARGET_NAME} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib)
This diff is collapsed.
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
*/ */
#include "array.h" #include "crystal/array.h"
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
...@@ -116,13 +116,13 @@ cry_array_append(struct CryArray* array, const_pointer data, size_t size) ...@@ -116,13 +116,13 @@ cry_array_append(struct CryArray* array, const_pointer data, size_t size)
} }
return_code int
cry_array_insert(struct CryArray* array, size_t index, const_pointer data, size_t size) cry_array_insert(struct CryArray* array, size_t index, const_pointer data, size_t size)
{ {
assert(array != 0); assert(array != 0);
if(index >= array->length) if(index >= array->length)
return CRY_OUT_OF_INDEX_RANGE; return FALSE;
cry_array_ensure(array, array->length + size); cry_array_ensure(array, array->length + size);
...@@ -131,36 +131,36 @@ cry_array_insert(struct CryArray* array, size_t index, const_pointer data, size_ ...@@ -131,36 +131,36 @@ cry_array_insert(struct CryArray* array, size_t index, const_pointer data, size_
array->length += size; array->length += size;
return CRY_OKAY; return TRUE;
} }
return_code int
cry_array_replace(struct CryArray* array, size_t index, const_pointer data, size_t size) cry_array_replace(struct CryArray* array, size_t index, const_pointer data, size_t size)
{ {
assert(array != 0); assert(array != 0);
if(index >= array->length && index + size > array->length) if(index >= array->length && index + size > array->length)
return CRY_OUT_OF_INDEX_RANGE; return FALSE;
cry_array_ensure(array, array->length + size); cry_array_ensure(array, array->length + size);
memcpy(array->data + index, data, size); memcpy(array->data + index, data, size);
} }
return_code int
cry_array_remove(struct CryArray* array, size_t index, size_t size) cry_array_remove(struct CryArray* array, size_t index, size_t size)
{ {
assert(array != 0); assert(array != 0);
if(index >= array->length) if(index >= array->length)
return CRY_OUT_OF_INDEX_RANGE; return FALSE;
memmove(array->data + index, array->data + index + size, array->length - index - size); memmove(array->data + index, array->data + index + size, array->length - index - size);
array->length -= size; array->length -= size;
return CRY_OKAY; return TRUE;
} }
...@@ -293,13 +293,13 @@ cry_ptr_array_append(struct CryPtrArray* array, pointer ptr) ...@@ -293,13 +293,13 @@ cry_ptr_array_append(struct CryPtrArray* array, pointer ptr)
} }
return_code int
cry_ptr_array_insert(struct CryPtrArray* array, size_t index, pointer ptr) cry_ptr_array_insert(struct CryPtrArray* array, size_t index, pointer ptr)
{ {
assert(array != 0); assert(array != 0);
if(index >= array->length) if(index >= array->length)
return CRY_OUT_OF_INDEX_RANGE; return FALSE;
cry_ptr_array_ensure(array, array->length + 1); cry_ptr_array_ensure(array, array->length + 1);
...@@ -309,7 +309,7 @@ cry_ptr_array_insert(struct CryPtrArray* array, size_t index, pointer ptr) ...@@ -309,7 +309,7 @@ cry_ptr_array_insert(struct CryPtrArray* array, size_t index, pointer ptr)
array->length += 1; array->length += 1;
return CRY_OKAY; return TRUE;
} }
...@@ -334,7 +334,7 @@ cry_ptr_array_remove(struct CryPtrArray* array, size_t index) ...@@ -334,7 +334,7 @@ cry_ptr_array_remove(struct CryPtrArray* array, size_t index)
assert(array != 0); assert(array != 0);
if(index >= array->length) if(index >= array->length)
return 0; return FALSE;
pointer data = *(array->data + index); pointer data = *(array->data + index);
......
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
*/ */
#include <assert.h> #include <assert.h>
#include "heap.h" #include "crystal/heap.h"
#include "array.h" #include "crystal/array.h"
struct CryHeap { struct CryHeap {
struct CryPtrArray* tree; struct CryPtrArray* tree;
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
* *
*/ */
#include "list.h" #include "crystal/list.h"