more standard const qualifiers

This commit is contained in:
snit 2024-09-29 02:33:16 -05:00
parent 764a5a09fc
commit 51a7412af3
8 changed files with 15 additions and 15 deletions

View File

@ -9,13 +9,13 @@
enum error_t entity_registrant_init( enum error_t entity_registrant_init(
struct entity_registrant_t *self, struct entity_registrant_t *self,
const char *name, char tile char const *name, char tile
) { ) {
assert(self != NULL); assert(self != NULL);
if (name == NULL || strlen(name) > MAX_NAME_LENGTH) return ERR_INPUT; if (name == NULL || strlen(name) > MAX_NAME_LENGTH) return ERR_INPUT;
const char *dup = strndup(name, MAX_NAME_LENGTH); char const *dup = strndup(name, MAX_NAME_LENGTH);
if (dup == NULL) return ERR_ALLOC; if (dup == NULL) return ERR_ALLOC;
self->name = dup; self->name = dup;
@ -57,7 +57,7 @@ void entity_registry_free(struct entity_registry_t *self) {
enum error_t entity_registry_append( enum error_t entity_registry_append(
struct entity_registry_t *self, struct entity_registry_t *self,
struct entity_registrant_t *registrant struct entity_registrant_t const *registrant
) { ) {
assert(self != NULL && registrant != NULL); assert(self != NULL && registrant != NULL);

View File

@ -6,13 +6,13 @@
#include "../error.h" #include "../error.h"
struct entity_registrant_t { struct entity_registrant_t {
const char *name; char const *name;
char tile; char tile;
}; };
enum error_t entity_registrant_init( enum error_t entity_registrant_init(
struct entity_registrant_t *, struct entity_registrant_t *,
const char *, char char const *, char
); );
void entity_registrant_free(struct entity_registrant_t *); void entity_registrant_free(struct entity_registrant_t *);
@ -28,7 +28,7 @@ void entity_registry_free(struct entity_registry_t *);
enum error_t entity_registry_append( enum error_t entity_registry_append(
struct entity_registry_t *, struct entity_registry_t *,
struct entity_registrant_t * struct entity_registrant_t const *
); );
#endif #endif

View File

@ -2,7 +2,7 @@
#include "error.h" #include "error.h"
const char *const ERROR_STRS[] = { char const *const ERROR_STRS[] = {
"SUCCESS", "SUCCESS",
"BAD INPUT", "BAD INPUT",
"ALLOCATION", "ALLOCATION",

View File

@ -9,6 +9,6 @@ enum error_t {
__ERR_COUNT, __ERR_COUNT,
}; };
extern const char *const ERROR_STRS[]; extern char const *const ERROR_STRS[];
#endif #endif

View File

@ -4,10 +4,10 @@
#include "render.h" #include "render.h"
void render_world(struct world_t *world) { void render_world(struct world_t const *world) {
for (size_t i = 0; i < MAX_ENTITIES; i++) { for (size_t i = 0; i < MAX_ENTITIES; i++) {
struct entity_t *entity = &world->entities[i]; struct entity_t const *const entity = &world->entities[i];
struct entity_registrant_t *registrant = struct entity_registrant_t const *const registrant =
&world->registered_entities.entities[entity->id]; &world->registered_entities.entities[entity->id];
if (entity->id == 0) continue; if (entity->id == 0) continue;

View File

@ -3,6 +3,6 @@
#include "../world.h" #include "../world.h"
void render_world(struct world_t *); void render_world(struct world_t const *);
#endif #endif

View File

@ -38,7 +38,7 @@ void world_free(struct world_t *self) {
enum error_t world_register_entity( enum error_t world_register_entity(
struct world_t *self, struct world_t *self,
const char *name, char tile char const *name, char tile
) { ) {
enum error_t err; enum error_t err;
struct entity_registry_t *registry = &self->registered_entities; struct entity_registry_t *registry = &self->registered_entities;
@ -53,7 +53,7 @@ enum error_t world_register_entity(
return ERR_OK; return ERR_OK;
} }
static size_t world_find_empty_entity(struct world_t *self) { static size_t world_find_empty_entity(struct world_t const *self) {
for (size_t i = 0; i < MAX_ENTITIES; i++) for (size_t i = 0; i < MAX_ENTITIES; i++)
if (self->entities[i].id == 0) return i; if (self->entities[i].id == 0) return i;

View File

@ -20,7 +20,7 @@ struct world_t {
enum error_t world_init(struct world_t *, size_t, size_t); enum error_t world_init(struct world_t *, size_t, size_t);
void world_free(struct world_t *); void world_free(struct world_t *);
enum error_t world_register_entity(struct world_t *, const char *, char); enum error_t world_register_entity(struct world_t *, char const *, char);
enum error_t world_place_entity(struct world_t *, size_t, size_t, size_t); enum error_t world_place_entity(struct world_t *, size_t, size_t, size_t);
#endif #endif