added meson build file, fixed sign-compare warnings

AuthorKonata <konata@posteo.jp>
Date
Commit9109b44c4b7ddf8aafdce6bf92a244dbc661ea02
Parent0994cd0
6 files changed, 57 insertions(+), 11 deletions(-)
MCMakeLists.txt
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0)
22
33 project(orcsmasher LANGUAGES C)
44
5-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic -Wno-sign-compare")
5+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic")
66
77 if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
88 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Og -g -fsanitize=address")
Minclude/game.h
@@ -102,15 +102,20 @@ static inline struct field *game_at(const struct game *g, struct point p)
102102
103103 static inline struct game create_game(size_t y, size_t x)
104104 {
105+ size_t res = y * x;
106+ if (y != 0 && res / y != x) {
107+ assert(false);
108+ }
105109 struct game ret;
106110 ret.map = xmalloc(x * y * sizeof(*ret.map));
111+ ret.xs = x;
112+ ret.ys = y;
113+
107114 for(size_t i = 0; i < x*y; i++)
108115 {
109116 ret.map[i].u = xmalloc(sizeof(*ret.map[i].u));
110117 ret.map[i].has_monster = false;
111118 }
112- ret.xs = x;
113- ret.ys = y;
114119
115120 return ret;
116121 }
@@ -161,7 +166,7 @@ static inline struct point relative(struct point p, enum direction d)
161166
162167 static inline bool in_bounds(struct game *g, struct point p)
163168 {
164- if(p.y >= 0 && p.y < g->ys && p.x >= 0 && p.x < g->xs)
169+ if(p.y >= 0 && (size_t)p.y < g->ys && p.x >= 0 && (size_t)p.x < g->xs)
165170 return true;
166171 else
167172 return false;
Minclude/tui.h
@@ -12,7 +12,7 @@ void charclear(); //clears the character screen
1212 void charprint(const char *format, ...); //echoes printf string to the charwindow
1313 void log_scroll(enum direction d); //scrolls the log up or down
1414 void draw_map(const struct game *g, struct point p); //draws the map around the player
15-bool messagebox(const char *str, int y, int x); //shows a centered messagebox of at least the given size
15+bool messagebox(const char *str, size_t y, size_t x); //shows a centered messagebox of at least the given size
1616
1717 typedef bool(itemselectfn)(struct monster *m, size_t i); //returns true if cursor should be reset
1818 void itemselect(struct monster *m, itemselectfn f); //provides an inventory screen, calls f when the space is pressed on an item
Ameson.build
@@ -0,0 +1,42 @@
1+project('orcsmasher', 'c',
2+ version : '0.1',
3+ default_options : ['warning_level=3', 'c_std=c99'])
4+
5+inc = include_directories('include')
6+
7+cc = meson.get_compiler('c')
8+
9+CFLAGS = []
10+LDFLAGS = []
11+
12+if get_option('buildtype') == 'debug'
13+ CFLAGS += ['-Og', '-g', '-fsanitize=address']
14+ LDFLAGS += ['-lasan']
15+endif
16+
17+if get_option('buildtype') == 'release'
18+ CFLAGS += ['-O3', '-march=native', '-g']
19+endif
20+
21+static_build = get_option('default_library') == 'static'
22+
23+if static_build
24+ LDFLAGS += ['-l:libgpm.a']
25+endif
26+
27+srcprefix = 'src/'
28+srcraw = [
29+ 'algorithm.c',
30+ 'loop.c',
31+ 'main.c',
32+ 'tui.c',
33+ ]
34+src = []
35+foreach s : srcraw
36+ src += srcprefix + s
37+endforeach
38+
39+curses_dep = dependency('ncursesw', static: static_build)
40+panel_dep = dependency('panelw', static: static_build)
41+executable('orcsmasher', src, include_directories: inc, dependencies: [curses_dep, panel_dep], c_args: CFLAGS, link_args: LDFLAGS)
42+
Msrc/algorithm.c
@@ -25,16 +25,15 @@ static char *maze_at(char *m, size_t xs, struct point p)
2525
2626 static bool maze_in_bounds(size_t ys, size_t xs, struct point p)
2727 {
28- return p.y > 0 && p.y < ys-1 &&
29- p.x > 0 && p.x < xs-1;
28+ return p.y > 0 && (size_t)p.y < ys-1 && p.x > 0 && (size_t)p.x < xs-1;
3029 }
3130
3231 struct game make_maze(size_t y, size_t x)
3332 {
34- assert(y >= 5);
35- assert(y >= 5);
3633 y += (y%2 == 0); //it must be an uneven number to look fine
3734 x += (x%2 == 0);
35+ assert(y >= 5);
36+ assert(x >= 5);
3837 struct game g = create_game(y, x);
3938
4039 char *maze = xmalloc(y * x + 1);
Msrc/tui.c
@@ -184,7 +184,7 @@ void logstr(const char *format, ...)
184184 vsprintf(logs[loglength-1]+10, format, ap2);
185185 va_end(ap2);
186186
187- if(loglength - logindex == getmaxy(logwin))
187+ if(loglength - logindex == (size_t)getmaxy(logwin)) //cast is fine, getmaxy only returns ERR if WINDOW is NULL
188188 logindex++;
189189
190190 printlog();
@@ -250,7 +250,7 @@ void draw_map(const struct game *g, struct point p)
250250 wrefresh(mapwin);
251251 }
252252
253-bool messagebox(const char *str, int y, int x)
253+bool messagebox(const char *str, size_t y, size_t x)
254254 {
255255 int yorig = y, xorig = x;
256256 struct winsize w;