aboutsummaryrefslogtreecommitdiffstats
path: root/src/nnn.c
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-01-25 22:03:08 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-01-25 22:03:08 +0530
commit575d8e0e6689120821d26d0fecfa0537a6a6a44c (patch)
treeddf5d831184b05848eb860c7f98dcc1304d6d39a /src/nnn.c
parentd080ba997ddfbb486a3a629c6fb799d5771031b3 (diff)
downloadnnn-575d8e0e6689120821d26d0fecfa0537a6a6a44c.tar.gz
1-pass bookmark parsing
Diffstat (limited to 'src/nnn.c')
-rw-r--r--src/nnn.c43
1 files changed, 20 insertions, 23 deletions
diff --git a/src/nnn.c b/src/nnn.c
index 3187a40..7e4c103 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -1648,36 +1648,33 @@ static bool parsebmstr()
{
int i = 0;
char *bms = getenv(env_cfg[NNN_BMS]);
- if (!bms)
+ char *nextkey = bms;
+ if (!bms | !*bms)
return TRUE;
while (*bms && i < BM_MAX) {
- bookmark[i].key = *bms;
-
- if (!*++bms) {
- bookmark[i].key = '\0';
- break;
- }
-
- if (*bms != ':')
- return FALSE; /* We support single char keys only */
-
- bookmark[i].loc = ++bms;
- if (bookmark[i].loc[0] == '\0' || bookmark[i].loc[0] == ';') {
- bookmark[i].key = '\0';
- break;
+ if (bms == nextkey) {
+ bookmark[i].key = *bms;
+ if (*++bms != ':')
+ return FALSE;
+ if (*++bms == '\0')
+ return FALSE;
+ bookmark[i].loc = bms;
+ ++i;
}
- while (*bms && *bms != ';')
- ++bms;
-
- if (*bms)
+ if (*bms == ';') {
*bms = '\0';
- else
- break;
+ nextkey = bms + 1;
+ }
++bms;
- ++i;
+ }
+
+ if (i < BM_MAX) {
+ if (*bookmark[i - 1].loc == '\0')
+ return FALSE;
+ bookmark[i].key = '\0';
}
return TRUE;
@@ -3903,7 +3900,7 @@ int main(int argc, char *argv[])
/* Parse bookmarks string */
if (!parsebmstr()) {
- fprintf(stderr, "%s: 1 char per key\n", env_cfg[NNN_BMS]);
+ fprintf(stderr, "%s: malformed\n", env_cfg[NNN_BMS]);
return 1;
}