Skip to content
This repository was archived by the owner on Dec 2, 2019. It is now read-only.

Commit 2f8edb6

Browse files
committed
Build all demos as C89
1 parent 181cfd8 commit 2f8edb6

File tree

13 files changed

+53
-38
lines changed

13 files changed

+53
-38
lines changed

demo/allegro5/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
BIN = demo
33

44
# Flags
5-
CFLAGS += -std=c99 -pedantic -O2
5+
CFLAGS += -std=c89 -pedantic -O2
66

77
SRC = main.c
88
OBJ = $(SRC:.c=.o)

demo/allegro5/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ int main(void)
5656
/* Platform */
5757
ALLEGRO_DISPLAY *display = NULL;
5858
ALLEGRO_EVENT_QUEUE *event_queue = NULL;
59+
NkAllegro5Font *font;
60+
struct nk_context *ctx;
5961

6062
if (!al_init()) {
6163
fprintf(stdout, "failed to initialize allegro5!\n");
@@ -86,9 +88,7 @@ int main(void)
8688
al_register_event_source(event_queue, al_get_mouse_event_source());
8789
al_register_event_source(event_queue, al_get_keyboard_event_source());
8890

89-
NkAllegro5Font *font;
9091
font = nk_allegro5_font_create_from_file("../../../extra_font/Roboto-Regular.ttf", 12, 0);
91-
struct nk_context *ctx;
9292

9393
ctx = nk_allegro5_init(font, display, WINDOW_WIDTH, WINDOW_HEIGHT);
9494

demo/allegro5/nuklear_allegro5.h

+28-15
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ static struct nk_allegro5 {
6868
NK_API NkAllegro5Font*
6969
nk_allegro5_font_create_from_file(const char *file_name, int font_size, int flags)
7070
{
71+
NkAllegro5Font *font;
7172
if (!al_init_image_addon()) {
7273
fprintf(stdout, "Unable to initialize required allegro5 image addon\n");
7374
exit(1);
@@ -80,7 +81,7 @@ nk_allegro5_font_create_from_file(const char *file_name, int font_size, int flag
8081
fprintf(stdout, "Unable to initialize required allegro5 TTF font addon\n");
8182
exit(1);
8283
}
83-
NkAllegro5Font *font = (NkAllegro5Font*)calloc(1, sizeof(NkAllegro5Font));
84+
font = (NkAllegro5Font*)calloc(1, sizeof(NkAllegro5Font));
8485

8586
font->font = al_load_font(file_name, font_size, flags);
8687
if (font->font == NULL) {
@@ -94,6 +95,8 @@ nk_allegro5_font_create_from_file(const char *file_name, int font_size, int flag
9495
static float
9596
nk_allegro5_font_get_text_width(nk_handle handle, float height, const char *text, int len)
9697
{
98+
float width;
99+
char *strcpy;
97100
NkAllegro5Font *font = (NkAllegro5Font*)handle.ptr;
98101
if (!font || !text) {
99102
return 0;
@@ -102,10 +105,12 @@ nk_allegro5_font_get_text_width(nk_handle handle, float height, const char *text
102105
as nuklear uses variable size buffers and al_get_text_width doesn't
103106
accept a length, it infers length from null-termination
104107
(which is unsafe API design by allegro devs!) */
105-
char strcpy[len+1];
106-
strncpy((char*)&strcpy, text, len);
108+
strcpy = malloc(len + 1);
109+
strncpy(strcpy, text, len);
107110
strcpy[len] = '\0';
108-
return al_get_text_width(font->font, strcpy);
111+
width = al_get_text_width(font->font, strcpy);
112+
free(strcpy);
113+
return width;
109114
}
110115

111116
NK_API void
@@ -170,18 +175,18 @@ nk_allegro5_render()
170175
(float)r->rounding, color);
171176
} break;
172177
case NK_COMMAND_CIRCLE: {
178+
float xr, yr;
173179
const struct nk_command_circle *c = (const struct nk_command_circle *)cmd;
174180
color = nk_color_to_allegro_color(c->color);
175-
float xr, yr;
176181
xr = (float)c->w/2;
177182
yr = (float)c->h/2;
178183
al_draw_ellipse(((float)(c->x)) + xr, ((float)c->y) + yr,
179184
xr, yr, color, (float)c->line_thickness);
180185
} break;
181186
case NK_COMMAND_CIRCLE_FILLED: {
187+
float xr, yr;
182188
const struct nk_command_circle_filled *c = (const struct nk_command_circle_filled *)cmd;
183189
color = nk_color_to_allegro_color(c->color);
184-
float xr, yr;
185190
xr = (float)c->w/2;
186191
yr = (float)c->h/2;
187192
al_draw_filled_ellipse(((float)(c->x)) + xr, ((float)c->y) + yr,
@@ -200,54 +205,61 @@ nk_allegro5_render()
200205
(float)t->b.y, (float)t->c.x, (float)t->c.y, color);
201206
} break;
202207
case NK_COMMAND_POLYGON: {
208+
int i;
209+
float *vertices;
203210
const struct nk_command_polygon *p = (const struct nk_command_polygon*)cmd;
211+
vertices = calloc(p->point_count * 2, sizeof(float));
204212
color = nk_color_to_allegro_color(p->color);
205-
int i;
206-
float vertices[p->point_count * 2];
207213
for (i = 0; i < p->point_count; i++) {
208214
vertices[i*2] = p->points[i].x;
209215
vertices[(i*2) + 1] = p->points[i].y;
210216
}
211217
al_draw_polyline((const float*)&vertices, (2 * sizeof(float)),
212218
(int)p->point_count, ALLEGRO_LINE_JOIN_ROUND, ALLEGRO_LINE_CAP_CLOSED,
213219
color, (float)p->line_thickness, 0.0);
220+
free(vertices);
214221
} break;
215222
case NK_COMMAND_POLYGON_FILLED: {
223+
int i;
224+
float *vertices;
216225
const struct nk_command_polygon_filled *p = (const struct nk_command_polygon_filled *)cmd;
226+
vertices = calloc(p->point_count * 2, sizeof(float));
217227
color = nk_color_to_allegro_color(p->color);
218-
int i;
219-
float vertices[p->point_count * 2];
220228
for (i = 0; i < p->point_count; i++) {
221229
vertices[i*2] = p->points[i].x;
222230
vertices[(i*2) + 1] = p->points[i].y;
223231
}
224232
al_draw_filled_polygon((const float*)&vertices, (int)p->point_count, color);
233+
free(vertices);
225234
} break;
226235
case NK_COMMAND_POLYLINE: {
236+
int i;
237+
float *vertices;
227238
const struct nk_command_polyline *p = (const struct nk_command_polyline *)cmd;
239+
vertices = calloc(p->point_count * 2, sizeof(float));
228240
color = nk_color_to_allegro_color(p->color);
229-
int i;
230-
float vertices[p->point_count * 2];
231241
for (i = 0; i < p->point_count; i++) {
232242
vertices[i*2] = p->points[i].x;
233243
vertices[(i*2) + 1] = p->points[i].y;
234244
}
235245
al_draw_polyline((const float*)&vertices, (2 * sizeof(float)),
236246
(int)p->point_count, ALLEGRO_LINE_JOIN_ROUND, ALLEGRO_LINE_CAP_ROUND,
237247
color, (float)p->line_thickness, 0.0);
248+
free(vertices);
238249
} break;
239250
case NK_COMMAND_TEXT: {
251+
NkAllegro5Font *font;
240252
const struct nk_command_text *t = (const struct nk_command_text*)cmd;
241253
color = nk_color_to_allegro_color(t->foreground);
242-
NkAllegro5Font *font = (NkAllegro5Font*)t->font->userdata.ptr;
254+
font = (NkAllegro5Font*)t->font->userdata.ptr;
243255
al_draw_text(font->font,
244256
color, (float)t->x, (float)t->y, 0,
245257
(const char*)t->string);
246258
} break;
247259
case NK_COMMAND_CURVE: {
260+
float points[8];
248261
const struct nk_command_curve *q = (const struct nk_command_curve *)cmd;
249262
color = nk_color_to_allegro_color(q->color);
250-
float points[8];
251263
points[0] = (float)q->begin.x;
252264
points[1] = (float)q->begin.y;
253265
points[2] = (float)q->ctrl[0].x;
@@ -425,12 +437,13 @@ NK_API struct nk_context*
425437
nk_allegro5_init(NkAllegro5Font *allegro5font, ALLEGRO_DISPLAY *dsp,
426438
unsigned int width, unsigned int height)
427439
{
440+
struct nk_user_font *font;
428441
if (!al_init_primitives_addon()) {
429442
fprintf(stdout, "Unable to initialize required allegro5 primitives addon\n");
430443
exit(1);
431444
}
432445

433-
struct nk_user_font *font = &allegro5font->nk;
446+
font = &allegro5font->nk;
434447
font->userdata = nk_handle_ptr(allegro5font);
435448
font->height = (float)allegro5font->height;
436449
font->width = nk_allegro5_font_get_text_width;

demo/glfw_opengl2/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
BIN = demo
33

44
# Flags
5-
CFLAGS += -std=c99 -pedantic -O2
5+
CFLAGS += -std=c89 -pedantic -O2
66

77
SRC = main.c
88
OBJ = $(SRC:.c=.o)

demo/glfw_opengl3/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
BIN = demo
33

44
# Flags
5-
CFLAGS += -std=c99 -pedantic -O2
5+
CFLAGS += -std=c89 -pedantic -O2
66

77
SRC = main.c
88
OBJ = $(SRC:.c=.o)

demo/glfw_opengl4/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
BIN = demo
33

44
# Flags
5-
CFLAGS += -std=c99 -pedantic -O2
5+
CFLAGS += -std=c89 -pedantic -O2
66

77
SRC = main.c
88
OBJ = $(SRC:.c=.o)

demo/glfw_opengl4/nuklear_glfw_gl4.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ NK_API void
116116
nk_glfw3_device_create()
117117
{
118118
GLint status;
119+
GLint len = 0;
119120
static const GLchar *vertex_shader =
120121
NK_SHADER_VERSION
121122
NK_SHADER_BINDLESS
@@ -156,7 +157,6 @@ nk_glfw3_device_create()
156157
glCompileShader(dev->frag_shdr);
157158
glGetShaderiv(dev->vert_shdr, GL_COMPILE_STATUS, &status);
158159

159-
GLint len = 0;
160160
glGetShaderiv(dev->vert_shdr, GL_INFO_LOG_LENGTH, &len);
161161
if (len > 1) {
162162
char *log = calloc((size_t)len, sizeof(char));

demo/sdl_opengl2/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
BIN = demo
33

44
# Flags
5-
CFLAGS += -std=c99 -pedantic -O2
5+
CFLAGS += -std=c89 -pedantic -O2
66

77
SRC = main.c
88
OBJ = $(SRC:.c=.o)

demo/sdl_opengl3/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
BIN = demo
33

44
# Flags
5-
CFLAGS += -std=c99 -pedantic -O2
5+
CFLAGS += -std=c89 -pedantic -O2
66

77
SRC = main.c
88
OBJ = $(SRC:.c=.o)

demo/sdl_opengles2/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
BIN = demo
33

44
# Flags
5-
CFLAGS += -std=c99 -pedantic -O2
5+
CFLAGS += -std=c89 -pedantic -O2
66

77
SRC = main.c
88
OBJ = $(SRC:.c=.o)

demo/sdl_opengles2/main.c

+13-11
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,19 @@ MainLoop(void* loopArg){
9696
nk_layout_row_end(ctx);
9797
nk_menubar_end(ctx);
9898

99-
enum {EASY, HARD};
100-
static int op = EASY;
101-
static int property = 20;
102-
nk_layout_row_static(ctx, 30, 80, 1);
103-
if (nk_button_label(ctx, "button"))
104-
fprintf(stdout, "button pressed\n");
105-
nk_layout_row_dynamic(ctx, 30, 2);
106-
if (nk_option_label(ctx, "easy", op == EASY)) op = EASY;
107-
if (nk_option_label(ctx, "hard", op == HARD)) op = HARD;
108-
nk_layout_row_dynamic(ctx, 25, 1);
109-
nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
99+
{
100+
enum {EASY, HARD};
101+
static int op = EASY;
102+
static int property = 20;
103+
nk_layout_row_static(ctx, 30, 80, 1);
104+
if (nk_button_label(ctx, "button"))
105+
fprintf(stdout, "button pressed\n");
106+
nk_layout_row_dynamic(ctx, 30, 2);
107+
if (nk_option_label(ctx, "easy", op == EASY)) op = EASY;
108+
if (nk_option_label(ctx, "hard", op == HARD)) op = HARD;
109+
nk_layout_row_dynamic(ctx, 25, 1);
110+
nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
111+
}
110112
}
111113
nk_end(ctx);
112114

demo/x11_opengl2/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ CC = clang
66
DCC = gcc
77

88
# Flags
9-
CFLAGS += -std=c99 -pedantic -O2
9+
CFLAGS += -std=c89 -pedantic -O2
1010

1111
SRC = main.c
1212
OBJ = $(SRC:.c=.o)

demo/x11_opengl3/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ CC = clang
66
DCC = gcc
77

88
# Flags
9-
CFLAGS += -std=c99 -pedantic -O2
9+
CFLAGS += -std=c89 -pedantic -O2
1010

1111
SRC = main.c
1212
OBJ = $(SRC:.c=.o)

0 commit comments

Comments
 (0)