src = load(vb.files[FILES_BOOKMARK]);
src = g_list_reverse(src);
- if (!input || *input == '\0') {
+ if (!input || !*input) {
/* without any tags return all bookmarked items */
for (GList *l = src; l; l = l->next) {
bm = (Bookmark*)l->data;
}
/* generate the completion with the found tags */
- if (!input || *input == '\0') {
+ if (!input || !*input) {
for (l = tags; l; l = l->next) {
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, COMPLETION_STORE_FIRST, l->data, -1);
while (g_ascii_isspace(*line)) {
line++;
}
- if (*line == '\0') {
+ if (!*line) {
return NULL;
}
if (**input) {
(*input)++;
}
-#if 0
- PRINT_DEBUG("CMD idx=%d, x=%d [%s][%s][%s]", arg->idx, arg->count, arg->name, arg->lhs->str, arg->rhs->str);
-#endif
+
return true;
}
}
}
(*input)++;
- } while (matches > 0 && **input != '\0' && **input != ' ');
+ } while (matches > 0 && **input && **input != ' ');
if (!matches) {
/* TODO show readable error message */
*/
static gboolean parse_lhs(const char **input, ExArg *arg)
{
+ char quote = '\\';
+
if (!*input || !**input) {
return false;
}
+
/* get the char until the next none escaped whitespace and save it into
* the lhs */
while (**input && **input != ' ') {
/* if we find a backslash this escapes the next whitespace */
- if (**input == '\\') {
+ if (**input == quote) {
/* move pointer to the next char */
(*input)++;
if (!*input) {
/* if input ends here - use only the backslash */
- g_string_append_c(arg->lhs, '\\');
+ g_string_append_c(arg->lhs, quote);
} else if (**input == ' ') {
/* escaped whitespace becomes only whitespace */
g_string_append_c(arg->lhs, **input);
} else {
/* put escape char and next char into the result string */
- g_string_append_c(arg->lhs, '\\');
+ g_string_append_c(arg->lhs, quote);
g_string_append_c(arg->lhs, **input);
}
} else {
*/
static gboolean parse_rhs(const char **input, ExArg *arg)
{
+ char quote = '\\';
+
if (!*input || !**input) {
return false;
}
+
/* get char until the end of command */
while (**input && **input != '\n' && **input != '|') {
/* if we find a backslash this escapes the next whitespace */
- if (**input == '\\') {
+ if (**input == quote) {
/* move pointer to the next char */
(*input)++;
if (!*input) {
/* if input ends here - use only the backslash */
- g_string_append_c(arg->rhs, '\\');
+ g_string_append_c(arg->rhs, quote);
} else if (**input == ' ') {
/* escaped whitespace becomes only whitespace */
g_string_append_c(arg->rhs, **input);
} else {
/* put escape char and next char into the result string */
- g_string_append_c(arg->rhs, '\\');
+ g_string_append_c(arg->rhs, quote);
g_string_append_c(arg->rhs, **input);
}
} else {
gboolean success;
char *value = NULL;
- if (!*arg->rhs->str) {
+ if (!arg->rhs->len) {
return false;
}
static gboolean ex_map(const ExArg *arg)
{
- /* TODO implement parsing of chars */
- char *lhs = arg->lhs->str;
- char *rhs = arg->rhs->str;
+ char *lhs, *rhs;
- if (!*lhs || !*rhs) {
+ if (!arg->lhs->len || !arg->rhs->len) {
return false;
}
+ lhs = arg->lhs->str;
+ rhs = arg->rhs->str;
+
if (arg->code == EX_NMAP) {
map_insert(lhs, rhs, 'n');
} else if (arg->code == EX_CMAP) {
static gboolean ex_unmap(const ExArg *arg)
{
- /* TODO implement parsing of chars */
- char *lhs = arg->lhs->str;
-
- if (!*lhs) {
+ char *lhs;
+ if (!arg->lhs->len) {
return false;
}
+ lhs = arg->lhs->str;
+
if (arg->code == EX_NUNMAP) {
map_delete(lhs, 'n');
} else if (arg->code == EX_CUNMAP) {
gboolean success;
char *param = NULL;
- if (!*arg->rhs->str) {
+ if (!arg->rhs->len) {
return false;
}
* shortcut[name]=http://donain.tld/?q=$0' */
switch (arg->code) {
case EX_SCA:
- if (*arg->rhs->str && (p = strchr(arg->rhs->str, '='))) {
+ if (arg->rhs->len && (p = strchr(arg->rhs->str, '='))) {
*p++ = '\0';
return shortcut_add(arg->rhs->str, p);
}