1-pass bookmark parsing

This commit is contained in:
Arun Prakash Jana 2019-01-25 22:03:08 +05:30
parent d080ba997d
commit 575d8e0e66
No known key found for this signature in database
GPG key ID: A75979F35C080412

View file

@ -1648,38 +1648,35 @@ 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) {
if (bms == nextkey) {
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;
}
while (*bms && *bms != ';')
++bms;
if (*bms)
*bms = '\0';
else
break;
++bms;
if (*++bms != ':')
return FALSE;
if (*++bms == '\0')
return FALSE;
bookmark[i].loc = bms;
++i;
}
if (*bms == ';') {
*bms = '\0';
nextkey = bms + 1;
}
++bms;
}
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;
}