diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2020-01-16 16:43:07 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2020-01-16 16:43:07 +0100 |
| commit | 6945a8dcde5e04bf08afbd9d6be63b470ee4643b (patch) | |
| tree | 024932f1161c80cea614e2839604f792af56c58b | |
| parent | 1b0382160acda0a9efd5c07045619bc20292192a (diff) | |
| parent | a7bb2aac13719d3fed71e3829f736074ec231537 (diff) | |
| download | vis-6945a8dcde5e04bf08afbd9d6be63b470ee4643b.tar.gz vis-6945a8dcde5e04bf08afbd9d6be63b470ee4643b.tar.xz | |
Merge branch 'fix-menu-warns' of https://github.com/zsugabubus/vis
| -rw-r--r-- | vis-menu.c | 26 |
1 files changed, 15 insertions, 11 deletions
@@ -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(); } |
