diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/array.h | 58 | ||||
-rw-r--r-- | include/ihex.h | 46 | ||||
-rw-r--r-- | include/util.h | 31 |
3 files changed, 135 insertions, 0 deletions
diff --git a/include/array.h b/include/array.h new file mode 100644 index 0000000..c382f1b --- /dev/null +++ b/include/array.h @@ -0,0 +1,58 @@ +/* + ihex + Copyright (C) 2025 Thomas Albers Raviola <thomas@thomaslabs.org> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef ARRAY_H +#define ARRAY_H + +#include <stddef.h> + +struct array { + size_t length; + size_t elem_size; + size_t capacity; + void *data; +}; + +void +init_array(struct array *arr, size_t elem_size); + +void +free_array(struct array *arr); + +void * +array_append(struct array *arr, const void *data); + +void +array_remove(struct array *arr, size_t n, void *dest); + +void +array_sort(struct array *arr, int (*compar)(const void *, const void *)); + +void * +array_search(struct array *arr, const void *key, + int (*compar)(const void *, const void *)); + +static inline void * +array_elt(struct array *arr, size_t n) +{ + return (void *)((char *)arr->data + n * arr->elem_size); +} + +#define ARRAY_ELT(ARRAY, TYPE, N) ((TYPE *)(ARRAY)->data)[N] + +#endif /* ARRAY_H */ diff --git a/include/ihex.h b/include/ihex.h new file mode 100644 index 0000000..a141120 --- /dev/null +++ b/include/ihex.h @@ -0,0 +1,46 @@ +/* + ihex + Copyright (C) 2025 Thomas Albers Raviola <thomas@thomaslabs.org> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef IHEX_H +#define IHEX_H + +#include <stdio.h> +#include <stddef.h> +#include <array.h> + +struct block { + /* Address in binary file */ + unsigned long address; + /* Block length */ + size_t length; + /* Offset in data buffer */ + size_t offset; + + const char *filename; +}; + +#define NO_BASE_ADDRESS -1 + +int +read_ihex_file(const char *pathname, struct array *blocks, struct array *data, + long base_address); + +int +write_hex(struct array *_blocks, struct array *_data, FILE *file); + +#endif /* IHEX_H */ diff --git a/include/util.h b/include/util.h new file mode 100644 index 0000000..31fcea7 --- /dev/null +++ b/include/util.h @@ -0,0 +1,31 @@ +/* + ihex + Copyright (C) 2025 Thomas Albers Raviola <thomas@thomaslabs.org> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef UTIL_H +#define UTIL_H + +void +die(const char *current_file, const char *fmt, ...); + +void * +ecalloc(size_t nmemb, size_t size); + +void * +erealloc(void *ptr, size_t size); + +#endif /* UTIL_H */ |