mirror of
https://github.com/theoludwig/libcproject.git
synced 2025-05-21 23:21:15 +02:00
fix!: usage of stdint
instead of int
types for cross-platform compatibility
BREAKING CHANGE: Functions signatures changed. Fixes #9
This commit is contained in:
@ -21,6 +21,66 @@ string_t terminal_input() {
|
||||
return string;
|
||||
}
|
||||
|
||||
void terminal_print_int(void* value) {
|
||||
printf("%d", *(int*)value);
|
||||
}
|
||||
|
||||
void terminal_print_bool(void* value) {
|
||||
printf("%s", *(bool*)value ? "true" : "false");
|
||||
}
|
||||
|
||||
void terminal_print_long(void* value) {
|
||||
printf("%ld", *(long*)value);
|
||||
}
|
||||
|
||||
void terminal_print_unsigned_long(void* value) {
|
||||
printf("%lu", *(unsigned long*)value);
|
||||
}
|
||||
|
||||
void terminal_print_float(void* value) {
|
||||
printf("%f", *(float*)value);
|
||||
}
|
||||
|
||||
void terminal_print_double(void* value) {
|
||||
printf("%f", *(double*)value);
|
||||
}
|
||||
|
||||
void terminal_print_int8_t(void* value) {
|
||||
printf("%d", *(int8_t*)value);
|
||||
}
|
||||
|
||||
void terminal_print_int16_t(void* value) {
|
||||
printf("%d", *(int16_t*)value);
|
||||
}
|
||||
|
||||
void terminal_print_int32_t(void* value) {
|
||||
printf("%d", *(int32_t*)value);
|
||||
}
|
||||
|
||||
void terminal_print_int64_t(void* value) {
|
||||
printf("%ld", *(int64_t*)value);
|
||||
}
|
||||
|
||||
void terminal_print_uint8_t(void* value) {
|
||||
printf("%u", *(uint8_t*)value);
|
||||
}
|
||||
|
||||
void terminal_print_uint16_t(void* value) {
|
||||
printf("%u", *(uint16_t*)value);
|
||||
}
|
||||
|
||||
void terminal_print_uint32_t(void* value) {
|
||||
printf("%u", *(uint32_t*)value);
|
||||
}
|
||||
|
||||
void terminal_print_uint64_t(void* value) {
|
||||
printf("%lu", *(uint64_t*)value);
|
||||
}
|
||||
|
||||
void terminal_print_char(void* value) {
|
||||
printf("%c", *(string_t)value);
|
||||
}
|
||||
|
||||
void terminal_print_array(void* array, size_t array_size, size_t element_size, void (*print_element)(void*)) {
|
||||
printf("[");
|
||||
for (size_t index = 0; index < array_size; index++) {
|
||||
@ -34,22 +94,6 @@ void terminal_print_array(void* array, size_t array_size, size_t element_size, v
|
||||
printf("]\n");
|
||||
}
|
||||
|
||||
void terminal_print_int(void* value) {
|
||||
printf("%d", *(int*)value);
|
||||
}
|
||||
|
||||
void terminal_print_long(void* value) {
|
||||
printf("%ld", *(long*)value);
|
||||
}
|
||||
|
||||
void terminal_print_unsigned_long(void* value) {
|
||||
printf("%lu", *(unsigned long*)value);
|
||||
}
|
||||
|
||||
void terminal_print_char(void* value) {
|
||||
printf("%c", *(string_t)value);
|
||||
}
|
||||
|
||||
void terminal_print_string(void* value) {
|
||||
printf("%s", (string_t)value);
|
||||
}
|
||||
@ -64,7 +108,7 @@ void terminal_print_stack(struct stack* stack, void (*print_element)(void*)) {
|
||||
while (node_current != NULL) {
|
||||
printf("|\t");
|
||||
void* element = node_current->data;
|
||||
print_element(&element);
|
||||
print_element(element);
|
||||
node_current = node_current->next;
|
||||
printf("\t|\n");
|
||||
}
|
||||
@ -80,7 +124,7 @@ void terminal_print_queue(struct queue* queue, void (*print_element)(void*)) {
|
||||
while (node_current != NULL) {
|
||||
printf("|\t");
|
||||
void* element = node_current->data;
|
||||
print_element(&element);
|
||||
print_element(element);
|
||||
node_current = node_current->next;
|
||||
printf("\t|\n");
|
||||
}
|
||||
@ -96,7 +140,7 @@ void terminal_print_linked_list(struct linked_list* linked_list, void (*print_el
|
||||
while (node_current != NULL) {
|
||||
void* element = (string_t)node_current->data;
|
||||
node_current = node_current->next;
|
||||
print_element(&element);
|
||||
print_element(element);
|
||||
printf(" -> ");
|
||||
}
|
||||
printf("NULL\n");
|
||||
@ -116,12 +160,21 @@ void terminal_print_hash_map(struct hash_map* hash_map, void (*print_element)(vo
|
||||
printf("\t\"");
|
||||
terminal_print_string(key);
|
||||
printf("\" -> ");
|
||||
print_element(&value);
|
||||
print_element(value);
|
||||
printf("\n");
|
||||
}
|
||||
printf("}\n");
|
||||
free(keys);
|
||||
}
|
||||
|
||||
void terminal_print_array_list(struct array_list* list, void (*print_element)(void*)) {
|
||||
terminal_print_array(list->data, list->size, sizeof(void*), print_element);
|
||||
printf("[");
|
||||
for (size_t index = 0; index < list->size; index++) {
|
||||
void* element = list->data[index];
|
||||
print_element(element);
|
||||
if (index < list->size - 1) {
|
||||
printf(", ");
|
||||
}
|
||||
}
|
||||
printf("]\n");
|
||||
}
|
||||
|
Reference in New Issue
Block a user