Loads more compiler checks and fixed some minor issues.

This commit is contained in:
Bruce Hill 2021-05-31 13:32:35 -07:00
parent 1e735dc71c
commit 07d03bf012
6 changed files with 69 additions and 20 deletions

View File

@ -1,9 +1,20 @@
PREFIX=
CC ?= gcc
O ?= -O2
CFLAGS=-std=c99 -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L
CWARN=-Wall -Wpedantic -Wextra -Wno-unknown-pragmas -Wno-missing-field-initializers\
-Wno-padded -Wsign-conversion -Wno-missing-noreturn -Wno-cast-qual -Wtype-limits
CFLAGS=-std=c99 -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L -Werror
CWARN=-Wall -Wpedantic -Wextra \
-Wsign-conversion -Wtype-limits -Wunused-result -Wnull-dereference \
-Waggregate-return -Walloc-zero -Walloca -Warith-conversion -Wcast-align -Wcast-align=strict \
-Wdangling-else -Wdate-time -Wdisabled-optimization -Wdouble-promotion -Wduplicated-branches \
-Wduplicated-cond -Wexpansion-to-defined -Wfloat-conversion -Wfloat-equal -Wformat-nonliteral \
-Wformat-security -Wformat-signedness -Wframe-address -Winline -Winvalid-pch -Wjump-misses-init \
-Wlogical-op -Wlong-long -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn \
-Wnull-dereference -Woverlength-strings -Wpacked -Wpacked-not-aligned -Wpointer-arith \
-Wredundant-decls -Wshadow -Wshadow=compatible-local -Wshadow=global -Wshadow=local \
-Wsign-conversion -Wstack-protector -Wsuggest-attribute=const -Wswitch-default -Wswitch-enum \
-Wsync-nand -Wtrampolines -Wundef -Wunused -Wunused-but-set-variable \
-Wunused-const-variable -Wunused-local-typedefs -Wvariadic-macros -Wvector-operation-performance \
-Wvla -Wwrite-strings
#CFLAGS += -fsanitize=address -fno-omit-frame-pointer
ifeq ($(shell uname -s),Darwin)
CFLAGS += -D_DARWIN_C_SOURCE

View File

@ -12,7 +12,7 @@ int main(void)
if (!bt) return 1;
int done = 0;
double t = 0;
double a = 1.13, b = 1.23, c = 1.37;
double a1 = 1.13, a2 = 1.23, a3 = 1.37;
double dt = 0.1;
char buf[1<<20];
setvbuf(bt->out, buf, _IOFBF, sizeof(buf));
@ -22,9 +22,9 @@ int main(void)
int y = bt->height-1;
btui_move_cursor(bt, 0, y);
for (int x = 0; x < bt->width; x++) {
int r = (int)(255.0 * (0.5 + 0.5*sin(t*a + (double)(x) / 50.0)));
int g = (int)(255.0 * (0.5 + 0.5*sin(0.8 + t*b + (double)(x) / 50.0)));
int b = (int)(255.0 * (0.5 + 0.5*sin(1.3 + t*c + (double)(x) / 50.0)));
int r = (int)(255.0 * (0.5 + 0.5*sin(t*a1 + (double)(x) / 50.0)));
int g = (int)(255.0 * (0.5 + 0.5*sin(0.8 + t*a2 + (double)(x) / 50.0)));
int b = (int)(255.0 * (0.5 + 0.5*sin(1.3 + t*a3 + (double)(x) / 50.0)));
btui_set_bg(bt,
(r < 0 ? 0 : (r > 255 ? 255 : r)),
(g < 0 ? 0 : (g > 255 ? 255 : g)),
@ -43,6 +43,7 @@ int main(void)
int key = btui_getkey(bt, 0, &mouse_x, &mouse_y);
switch (key) {
case 'q': case KEY_CTRL_C: done = 1; break;
default: break;
}
}
btui_disable(bt);

View File

@ -1,9 +1,20 @@
PREFIX=
CC ?= gcc
O ?= -O2
CFLAGS=-std=c99 -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L
CWARN=-Wall -Wpedantic -Wextra -Wno-unknown-pragmas -Wno-missing-field-initializers\
-Wno-padded -Wsign-conversion -Wno-missing-noreturn -Wno-cast-qual -Wtype-limits
CFLAGS=-std=c99 -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L -Werror
CWARN=-Wall -Wpedantic -Wextra \
-Wsign-conversion -Wtype-limits -Wunused-result -Wnull-dereference \
-Waggregate-return -Walloc-zero -Walloca -Warith-conversion -Wcast-align -Wcast-align=strict \
-Wdangling-else -Wdate-time -Wdisabled-optimization -Wdouble-promotion -Wduplicated-branches \
-Wduplicated-cond -Wexpansion-to-defined -Wfloat-conversion -Wfloat-equal -Wformat-nonliteral \
-Wformat-security -Wformat-signedness -Wframe-address -Winline -Winvalid-pch -Wjump-misses-init \
-Wlogical-op -Wlong-long -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn \
-Wnull-dereference -Woverlength-strings -Wpacked -Wpacked-not-aligned -Wpointer-arith \
-Wredundant-decls -Wshadow -Wshadow=compatible-local -Wshadow=global -Wshadow=local \
-Wsign-conversion -Wstack-protector -Wsuggest-attribute=const -Wswitch-default -Wswitch-enum \
-Wsync-nand -Wtrampolines -Wundef -Wunused -Wunused-but-set-variable \
-Wunused-const-variable -Wunused-local-typedefs -Wvariadic-macros -Wvector-operation-performance \
-Wvla -Wwrite-strings
#CFLAGS += -fsanitize=address -fno-omit-frame-pointer
ifeq ($(shell uname -s),Darwin)
CFLAGS += -D_DARWIN_C_SOURCE

View File

@ -1,9 +1,20 @@
PREFIX=
CC ?= gcc
O ?= -O2
CFLAGS=-std=c99 -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L
CWARN=-Wall -Wpedantic -Wextra -Wno-unknown-pragmas -Wno-missing-field-initializers\
-Wno-padded -Wsign-conversion -Wno-missing-noreturn -Wno-cast-qual -Wtype-limits
CFLAGS=-std=c99 -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L -Werror
CWARN=-Wall -Wpedantic -Wextra \
-Wsign-conversion -Wtype-limits -Wunused-result -Wnull-dereference \
-Waggregate-return -Walloc-zero -Walloca -Warith-conversion -Wcast-align -Wcast-align=strict \
-Wdangling-else -Wdate-time -Wdisabled-optimization -Wdouble-promotion -Wduplicated-branches \
-Wduplicated-cond -Wexpansion-to-defined -Wfloat-conversion -Wfloat-equal -Wformat-nonliteral \
-Wformat-security -Wformat-signedness -Wframe-address -Winline -Winvalid-pch -Wjump-misses-init \
-Wlogical-op -Wlong-long -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn \
-Wnull-dereference -Woverlength-strings -Wpacked -Wpacked-not-aligned -Wpointer-arith \
-Wredundant-decls -Wshadow -Wshadow=compatible-local -Wshadow=global -Wshadow=local \
-Wsign-conversion -Wstack-protector -Wsuggest-attribute=const -Wswitch-default -Wswitch-enum \
-Wsync-nand -Wtrampolines -Wundef -Wunused -Wunused-but-set-variable \
-Wunused-const-variable -Wunused-local-typedefs -Wvariadic-macros -Wvector-operation-performance \
-Wvla -Wwrite-strings
#CFLAGS += -fsanitize=address -fno-omit-frame-pointer
ifeq ($(shell uname -s),Darwin)
CFLAGS += -D_DARWIN_C_SOURCE

View File

@ -1,9 +1,20 @@
PREFIX=
CC ?= gcc
O ?= -O2
CFLAGS=-std=c99 -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L
CWARN=-Wall -Wpedantic -Wextra -Wno-unknown-pragmas -Wno-missing-field-initializers\
-Wno-padded -Wsign-conversion -Wno-missing-noreturn -Wno-cast-qual -Wtype-limits
CFLAGS=-std=c99 -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L -Werror
CWARN=-Wall -Wpedantic -Wextra \
-Wsign-conversion -Wtype-limits -Wunused-result -Wnull-dereference \
-Waggregate-return -Walloc-zero -Walloca -Warith-conversion -Wcast-align -Wcast-align=strict \
-Wdangling-else -Wdate-time -Wdisabled-optimization -Wdouble-promotion -Wduplicated-branches \
-Wduplicated-cond -Wexpansion-to-defined -Wfloat-conversion -Wfloat-equal -Wformat-nonliteral \
-Wformat-security -Wformat-signedness -Wframe-address -Winline -Winvalid-pch -Wjump-misses-init \
-Wlogical-op -Wlong-long -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn \
-Wnull-dereference -Woverlength-strings -Wpacked -Wpacked-not-aligned -Wpointer-arith \
-Wredundant-decls -Wshadow -Wshadow=compatible-local -Wshadow=global -Wshadow=local \
-Wsign-conversion -Wstack-protector -Wsuggest-attribute=const -Wswitch-default -Wswitch-enum \
-Wsync-nand -Wtrampolines -Wundef -Wunused -Wunused-but-set-variable \
-Wunused-const-variable -Wunused-local-typedefs -Wvariadic-macros -Wvector-operation-performance \
-Wvla -Wwrite-strings
#CFLAGS += -fsanitize=address -fno-omit-frame-pointer
ifeq ($(shell uname -s),Darwin)
CFLAGS += -D_DARWIN_C_SOURCE

12
btui.h
View File

@ -6,10 +6,11 @@
* This file defines some Text User Interface (TUI) functionality.
*/
#ifndef FILE__BTUI_H
#define FILE__BTUI_H
#ifndef __BTUI_H__
#define __BTUI_H__
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -114,7 +115,7 @@ const int BTUI_CLEAR_LEFT = _BTUI_CLEAR_LEFT;
const int BTUI_CLEAR_RIGHT = _BTUI_CLEAR_RIGHT;
// Text attributes:
typedef unsigned long long attr_t;
typedef uint64_t attr_t;
const attr_t BTUI_NORMAL = 1ul << 0;
const attr_t BTUI_BOLD = 1ul << 1;
const attr_t BTUI_FAINT = 1ul << 2;
@ -457,6 +458,7 @@ void btui_set_mode(btui_t *bt, btui_mode_t mode)
case BTUI_MODE_TUI:
fputs(T_OFF(T_SHOW_CURSOR ";" T_WRAP) T_ON(T_ALT_SCREEN ";" T_MOUSE_XY ";" T_MOUSE_CELL ";" T_MOUSE_SGR), bt->out);
break;
default: break;
}
fflush(bt->out);
bt->mode = mode;
@ -578,6 +580,7 @@ int btui_getkey(btui_t *bt, int timeout, int *mouse_x, int *mouse_y)
case 21: return modifiers | KEY_F10;
case 23: return modifiers | KEY_F11;
case 24: return modifiers | KEY_F12;
default: break;
}
return -1;
case '<': { // Mouse clicks
@ -619,6 +622,7 @@ int btui_getkey(btui_t *bt, int timeout, int *mouse_x, int *mouse_y)
case MOUSE_LEFT_RELEASE: key = MOUSE_LEFT_DOUBLE; break;
case MOUSE_RIGHT_RELEASE: key = MOUSE_RIGHT_DOUBLE; break;
case MOUSE_MIDDLE_RELEASE: key = MOUSE_MIDDLE_DOUBLE; break;
default: break;
}
}
}
@ -674,7 +678,7 @@ char *btui_keyname(int key, char *buf)
if (' ' < key && key <= '~')
return buf + sprintf(buf, "%c", key);
else
return buf + sprintf(buf, "\\x%02X", key);
return buf + sprintf(buf, "\\x%02X", (unsigned int)key);
}
/*