tex: make ex_pathexpand() more compact - neatvi - [fork] simple vi-type editor with UTF-8 support
 (HTM) git clone git://src.adamsgaard.dk/neatvi
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) commit debb1a79efbabb95f0ce6383bc091c96b5bf1edc
 (DIR) parent 2413a868f0ce3e3d67a8732f7174de731c3f7a05
 (HTM) Author: Ali Gholami Rudi <ali@rudi.ir>
       Date:   Thu,  7 Oct 2021 13:04:29 +0330
       
       ex: make ex_pathexpand() more compact
       
       Diffstat:
         M ex.c                                |      26 +++++++++-----------------
       
       1 file changed, 9 insertions(+), 17 deletions(-)
       ---
 (DIR) diff --git a/ex.c b/ex.c
       t@@ -122,27 +122,19 @@ static char *ex_pathexpand(char *src, int spaceallowed)
                char *end = dst + sizeof(buf);
                while (dst + 1 < end && *src && *src != '\n' &&
                                (spaceallowed || (*src != ' ' && *src != '\t'))) {
       -                if (*src == '%') {
       -                        if (!bufs[0].path || !bufs[0].path[0]) {
       -                                ex_show("\"%\" is unset\n");
       +                if (*src == '%' || *src == '#') {
       +                        int idx = *src == '#';
       +                        if (!bufs[idx].path || !bufs[idx].path[0]) {
       +                                ex_show("pathname \"%\" or \"#\" is not set\n");
                                        return NULL;
                                }
       -                        dst += snprintf(dst, end - dst, "%s", bufs[0].path);
       +                        dst += snprintf(dst, end - dst, "%s", bufs[idx].path);
                                src++;
       -                        continue;
       -                }
       -                if (*src == '#') {
       -                        if (!bufs[1].path || !bufs[1].path[0]) {
       -                                ex_show("\"#\" is unset\n");
       -                                return NULL;
       -                        }
       -                        dst += snprintf(dst, end - dst, "%s", bufs[1].path);
       -                        src++;
       -                        continue;
       +                } else {
       +                        if (*src == '\\' && src[1])
       +                                src++;
       +                        *dst++ = *src++;
                        }
       -                if (*src == '\\' && src[1])
       -                        src++;
       -                *dst++ = *src++;
                }
                if (dst + 1 >= end)
                        dst = end - 1;