aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzsugabubus <zsugabubus@users.noreply.github.com>2020-01-12 15:51:12 +0100
committerzsugabubus <zsugabubus@users.noreply.github.com>2020-01-12 15:52:01 +0100
commita7bb2aac13719d3fed71e3829f736074ec231537 (patch)
tree08379f59b6f1c31f865a696880654885e29d73a3
parente136e348cbd0ea4bf2dd8de6f98da1ca1924bc96 (diff)
downloadvis-a7bb2aac13719d3fed71e3829f736074ec231537.tar.gz
vis-a7bb2aac13719d3fed71e3829f736074ec231537.tar.xz
vis-menu: fix sign-compare compiler warnings
-rw-r--r--vis-menu.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/vis-menu.c b/vis-menu.c
index 1682ed2..3a2d487 100644
--- a/vis-menu.c
+++ b/vis-menu.c
@@ -41,6 +41,7 @@
#include <sys/types.h>
#include <termios.h>
#include <unistd.h>
+#include <errno.h>
#define CONTROL(ch) (ch ^ 0x40)
#define MIN(a,b) ((a) < (b) ? (a) : (b))
@@ -59,9 +60,9 @@ struct Item {
static char text[BUFSIZ] = "";
static int barpos = 0;
-static int mw, mh;
-static int lines = 0;
-static int inputw, promptw;
+static size_t mw, mh;
+static size_t lines = 0;
+static size_t inputw, promptw;
static size_t cursor;
static char *prompt = NULL;
static Item *items = NULL;
@@ -96,7 +97,7 @@ textw(const char *s) {
static void
calcoffsets(void) {
- int i, n;
+ size_t i, n;
if (lines > 0)
n = lines;
@@ -128,7 +129,7 @@ die(const char *s) {
static void
drawtext(const char *t, size_t w, Color col) {
const char *prestr, *poststr;
- int i, tw;
+ size_t i, tw;
char *buf;
if (w<5) return; /* This is the minimum size needed to write a label: 1 char + 4 padding spaces */
@@ -156,14 +157,14 @@ drawtext(const char *t, size_t w, Color col) {
static void
resetline(void) {
- if (barpos != 0) fprintf(stderr, "\033[%iH", barpos > 0 ? 0 : (mh-lines));
- else fprintf(stderr, "\033[%iF", lines);
+ if (barpos != 0) fprintf(stderr, "\033[%ldH", (long)(barpos > 0 ? 0 : (mh-lines)));
+ else fprintf(stderr, "\033[%zuF", lines);
}
static void
drawmenu(void) {
Item *item;
- int rw;
+ size_t rw;
/* use default colors */
fprintf(stderr, "\033[0m");
@@ -195,12 +196,12 @@ drawmenu(void) {
if ((rw -= textw(item->text)) <= 0) break;
}
if (next) {
- fprintf(stderr, "\033[%iG", mw-5);
+ fprintf(stderr, "\033[%zuG", mw-5);
drawtext(">", 5 /*textw(">")*/, C_Normal);
}
}
- fprintf(stderr, "\033[%iG", (int)(promptw+textwn(text, cursor)-1));
+ fprintf(stderr, "\033[%ldG", (long)(promptw+textwn(text, cursor)-1));
fflush(stderr);
}
@@ -591,7 +592,10 @@ main(int argc, char **argv) {
if (prompt && !prompt[0])
prompt = NULL;
} else if (!strcmp(argv[i], "-l")) {
- lines = atoi(argv[++i]);
+ errno = 0;
+ lines = strtoul(argv[++i], NULL, 10);
+ if (errno)
+ usage();
} else {
usage();
}