From edca8806cfb205b204b4f79899ff9e6f9d939e78 Mon Sep 17 00:00:00 2001 From: Emil Kosz Date: Tue, 9 Sep 2025 10:05:07 +0200 Subject: [PATCH] Add make format rule --- .gitignore | 3 ++- Makefile | 7 ++++++- shell.nix | 1 + src/client/client.c | 6 +++--- src/client/gfx_context.c | 6 ++++-- src/client/gfx_context.h | 8 ++++---- src/common/game_state.h | 5 ++--- src/common/world.c | 1 - src/common/world.h | 20 ++++++++++---------- src/server/server.c | 5 +++-- 10 files changed, 35 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index f5ebaef..fbd06ee 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ /librefront /librefront-headless /perf.data* -/massif.out* \ No newline at end of file +/massif.out* +/*~ \ No newline at end of file diff --git a/Makefile b/Makefile index 68f3235..e0bee7e 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ SERVER_LDFLAGS := $(COMMON_LDFLAGS) CLIENT := librefront SERVER := librefront-headless -.PHONY: all clean +.PHONY: all clean format all: $(CLIENT) $(SERVER) @@ -66,6 +66,11 @@ build/server/%.o: $(SRC_DIR)/server/%.c clean: $(RM) -r build/ $(CLIENT) $(SERVER) perf.data* massif.out* +format: + find $(SRC_DIR) -type f \( -name '*.c' -o -name '*.h' \) \ + -exec sh -c 'tmp=$$(mktemp) || tmp=/tmp/indent.$$$$; \ + indent -gnu "$$1" -o "$$tmp" && mv "$$tmp" "$$1"' _ {} \; + -include $(COMMON_DEP) -include $(CLIENT_DEP) -include $(SERVER_DEP) diff --git a/shell.nix b/shell.nix index d0eb7cb..024f2e5 100644 --- a/shell.nix +++ b/shell.nix @@ -9,6 +9,7 @@ pkgs.mkShellNoCC { glib gcc + indent pkg-config cloc valgrind diff --git a/src/client/client.c b/src/client/client.c index c387654..2e7d20e 100644 --- a/src/client/client.c +++ b/src/client/client.c @@ -48,7 +48,7 @@ SDL_AppInit (void **appstate, int argc, char **argv) #endif SDL_SetAppMetadata (GAME_NAME, GAME_VERSION, GAME_URL); - + if (!SDL_Init (SDL_INIT_VIDEO)) { g_error ("Couldn't initialize SDL: %s", SDL_GetError ()); @@ -63,7 +63,7 @@ SDL_AppResult SDL_AppEvent (void *appstate, SDL_Event *event) { UNUSED (appstate); - + if (event->type == SDL_EVENT_QUIT) { return SDL_APP_SUCCESS; @@ -79,7 +79,7 @@ SDL_AppIterate (void *appstate) GfxContext_prerender (gfx_ctx); GfxContext_postrender (gfx_ctx); - + return SDL_APP_CONTINUE; } diff --git a/src/client/gfx_context.c b/src/client/gfx_context.c index f2e8b73..b42934a 100644 --- a/src/client/gfx_context.c +++ b/src/client/gfx_context.c @@ -30,14 +30,16 @@ GfxContext_new () if (!self->window) { - g_critical ("Couldn't create window for context %p: %s", self, SDL_GetError ()); + g_critical ("Couldn't create window for context %p: %s", self, + SDL_GetError ()); } self->renderer = SDL_CreateRenderer (self->window, NULL); if (!self->window) { - g_critical ("Couldn't create renderer for context %p: %s", self, SDL_GetError ()); + g_critical ("Couldn't create renderer for context %p: %s", self, + SDL_GetError ()); } return self; diff --git a/src/client/gfx_context.h b/src/client/gfx_context.h index fe4ef94..056d7d8 100644 --- a/src/client/gfx_context.h +++ b/src/client/gfx_context.h @@ -34,8 +34,8 @@ typedef struct GfxContext } GfxContext; GfxContext *GfxContext_new (); -void GfxContext_prerender (GfxContext *self); -void GfxContext_postrender (GfxContext *self); -void GfxContext_free (GfxContext *self); +void GfxContext_prerender (GfxContext * self); +void GfxContext_postrender (GfxContext * self); +void GfxContext_free (GfxContext * self); -void GfxContext_renderWorld (GfxContext *self, World *world); +void GfxContext_renderWorld (GfxContext * self, World * world); diff --git a/src/common/game_state.h b/src/common/game_state.h index e9e534f..6c7f900 100644 --- a/src/common/game_state.h +++ b/src/common/game_state.h @@ -13,11 +13,11 @@ typedef struct Player unsigned int id; const char *name; SDL_Color color; /* 4 bytes */ - + unsigned int power; unsigned int population, max_population; - gboolean is_alive : 1, is_human : 1; + gboolean is_alive:1, is_human:1; } Player; typedef struct GameState @@ -26,4 +26,3 @@ typedef struct GameState GArray *players; Player *me; } GameState; - diff --git a/src/common/world.c b/src/common/world.c index fae69fe..ea50eca 100644 --- a/src/common/world.c +++ b/src/common/world.c @@ -1,2 +1 @@ #include "world.h" - diff --git a/src/common/world.h b/src/common/world.h index 5f11062..6c3f91a 100644 --- a/src/common/world.h +++ b/src/common/world.h @@ -3,12 +3,12 @@ #include typedef enum TerrainType - { - TERRAIN_WATER, - TERRAIN_FLAT, - TERRAIN_HILL, - TERRAIN_MOUNTAIN - } TerrainType; +{ + TERRAIN_WATER, + TERRAIN_FLAT, + TERRAIN_HILL, + TERRAIN_MOUNTAIN +} TerrainType; typedef struct MapTile { @@ -16,7 +16,7 @@ typedef struct MapTile unsigned int owner_id; TerrainType terrain_type; - gboolean is_defended : 1, is_radiated : 1; + gboolean is_defended:1, is_radiated:1; } MapTile; typedef struct World @@ -27,14 +27,14 @@ typedef struct World } World; -typedef struct Building Building; // Typedef is needed to avoid circular dependency +typedef struct Building Building; // Typedef is needed to avoid circular dependency struct Building { MapTile *parent_tile; unsigned int level; - unsigned int (*at_what_cost) (Building *self, World *world); + unsigned int (*at_what_cost) (Building * self, World * world); }; World *World_new (unsigned int width, unsigned int height); -void World_tick (World *self); +void World_tick (World * self); diff --git a/src/server/server.c b/src/server/server.c index 604ee00..0ad9bb3 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -1,7 +1,8 @@ #include -int main () +int +main () { - fprintf(stderr, "Server not implemented!\n"); + fprintf (stderr, "Server not implemented!\n"); return -1; }