vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 97340fe319242cb01e7166d6246982db5390ae82 parent 6dff861cc1d5f3b06d0bb3b1025367b7915f2c6e Author: zsugabubus <zsugabubus@users.noreply.github.com> Date: Sun, 12 Jan 2020 15:51:12 +0100 vis-menu: fix sign-compare compiler warnings Diffstat:
| M | vis-menu.c | | | 26 | +++++++++++++++----------- |
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git 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(); }