URI: 
       fixed CTL macro causing buggy input - iomenu - interactive terminal-based selection menu
  HTML git clone git://bitreich.org/iomenu git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/iomenu
   DIR Log
   DIR Files
   DIR Refs
   DIR Tags
   DIR README
   DIR LICENSE
       ---
   DIR commit 9747f2c9e90a2160e5578b80aa3b91101d338120
   DIR parent c1fc5b0c3cfd8ce193fd60d8a4586995b1af7758
  HTML Author: Josuah Demangeon <mail@josuah.net>
       Date:   Sat,  3 Mar 2018 00:05:42 +0100
       
       fixed CTL macro causing buggy input
       
       Diffstat:
         M Makefile                            |      11 +++++++----
         M iomenu.c                            |      57 +++++++++++--------------------
         A str.h                               |       1 +
         A strcasestr.c                        |      25 +++++++++++++++++++++++++
       
       4 files changed, 53 insertions(+), 41 deletions(-)
       ---
   DIR diff --git a/Makefile b/Makefile
       @@ -1,6 +1,6 @@
        CFLAGS = -std=c89 -pedantic -Wall -Wextra -g -D_POSIX_C_SOURCE=200809L
        
       -SRC = iomenu.c utf8.c
       +SRC = iomenu.c utf8.c strcasestr.c
        OBJ = ${SRC:.o=.c}
        
        all: iomenu
       @@ -8,16 +8,19 @@ all: iomenu
        .c.o:
                ${CC} -c -o $@ ${CFLAGS} $<
        
       -iomenu: ${OBJ}
       +iomenu: ${OBJ} utf8.h str.h
                ${CC} -o $@ ${LDFLAGS} ${OBJ}
       -${OBJ}: utf8.h
       +
       +utf8.c: utf8.h
       +
       +strcasestr.c: str.h
        
        test: test.c
                ${CC} -o $@ ${LDFLAGS} test.c utf8.c
                ./$@
        
        clean:
       -        rm -f *.o *.core iomenu
       +        rm -f *.o *.core iomenu test
        
        install: iomenu
                mkdir -p  ${PREFIX}/share/man/man1
   DIR diff --git a/iomenu.c b/iomenu.c
       @@ -12,13 +12,14 @@
        #include <unistd.h>
        
        #include "utf8.h"
       +#include "str.h"
        
        #ifndef SIGWINCH
        #define SIGWINCH        28
        #endif
        
        #define MIN(X, Y)        (((X) < (Y)) ? (X) : (Y))
       -#define CTL(char)        ((char) | 0x40)
       +#define CTL(char)        ((char) & ~0x40)
        #define ALT(char)        ((char) + 0x80)
        #define CSI(char)        ((char) + 0x80 + 0x80)
        
       @@ -26,32 +27,11 @@ static struct termios        termios;
        struct winsize                ws;
        static int                ttyfd;
        
       -int                        linec = 0, matchc = 0, cur = 0;
       -char                        **linev = NULL, **matchv = NULL;
       -char                        input[LINE_MAX], formatted[LINE_MAX * 8];
       +static int                linec = 0, matchc = 0, cur = 0;
       +static char                **linev = NULL, **matchv = NULL;
       +static char                input[LINE_MAX], formatted[LINE_MAX * 8];
        
       -int                        flag_hs = 0;
       -
       -static char *
       -io_strstr(const char *str1, const char *str2)
       -{
       -        const char        *s1;
       -        const char        *s2;
       -
       -        for (;;) {
       -                s1 = str1;
       -                s2 = str2;
       -                while (*s1 != '\0' && tolower(*s1) == tolower(*s2))
       -                        s1++, s2++;
       -                if (*s2 == '\0')
       -                        return (char *) str1;
       -                if (*s1 == '\0')
       -                        return NULL;
       -                str1++;
       -        }
       -
       -        return NULL;
       -}
       +static int                flag_hs = 0;
        
        /*
        ** Keep the line if it match every token (in no particular order, and allowed to
       @@ -63,7 +43,7 @@ match_line(char *line, char **tokv)
                if (flag_hs && line[0] == '#')
                        return 2;
                for (; *tokv != NULL; tokv++)
       -                if (io_strstr(line, *tokv) == NULL)
       +                if (strcasestr(line, *tokv) == NULL)
                                return 0;
                return 1;
        }
       @@ -267,6 +247,8 @@ key(int k)
                extern        int          linec;
        
        top:
       +        printf("{%d}", k);
       +        fflush(stdout);
                switch (k) {
                case CTL('C'):
                        return -1;
       @@ -382,7 +364,7 @@ set_terminal(void)
                        perror("tcgetattr");
                        exit(EXIT_FAILURE);
                }
       -        new.c_lflag &= ~(ICANON | ECHO | IGNBRK | IEXTEN | ISIG);
       +        new.c_lflag &= ~(ICANON | ECHO | IEXTEN | IGNBRK);
                tcsetattr(ttyfd, TCSANOW, &new);
        }
        
       @@ -396,18 +378,19 @@ reset_terminal(void)
                tcsetattr(ttyfd, TCSANOW, &termios);
        }
        
       -/*
       -** Redraw the whole screen on window resize.
       -*/
        static void
       -sigwinch()
       +sighandle(int sig)
        {
                extern struct winsize        ws;
        
       -        if (ioctl(ttyfd, TIOCGWINSZ, &ws) < 0)
       -                err("ioctl");
       -        print_screen();
       -        signal(SIGWINCH, sigwinch);
       +        switch (sig) {
       +        case SIGWINCH:
       +                if (ioctl(ttyfd, TIOCGWINSZ, &ws) < 0)
       +                        err("ioctl");
       +                print_screen();
       +                break;
       +        }
       +        signal(sig, sighandle);
        }
        
        static void
       @@ -453,7 +436,7 @@ init(void)
                        err("open /dev/tty");
        
                set_terminal();
       -        sigwinch();
       +        sighandle(SIGWINCH);
        }
        
        /*
   DIR diff --git a/str.h b/str.h
       @@ -0,0 +1 @@
       +char        *strcasestr(const char *, const char *);
   DIR diff --git a/strcasestr.c b/strcasestr.c
       @@ -0,0 +1,25 @@
       +#include <ctype.h>
       +#include <stddef.h>
       +
       +#include "str.h"
       +
       +char *
       +strcasesstr(const char *str1, const char *str2)
       +{
       +        const char        *s1;
       +        const char        *s2;
       +
       +        for (;;) {
       +                s1 = str1;
       +                s2 = str2;
       +                while (*s1 != '\0' && tolower(*s1) == tolower(*s2))
       +                        s1++, s2++;
       +                if (*s2 == '\0')
       +                        return (char *) str1;
       +                if (*s1 == '\0')
       +                        return NULL;
       +                str1++;
       +        }
       +
       +        return NULL;
       +}