if (strmatch(token, "include")) {
/* the remaining text should be a regexp */
char *regexp = working;
+
+ if (!regexp) {
+ vty_out(vty, "%% Need a regexp to filter with\n");
+ goto fail;
+ }
+
bool succ = vty_set_include(vty, regexp);
if (!succ) {
- vty_out(vty, "%% Bad regexp '%s'", regexp);
+ vty_out(vty, "%% Bad regexp '%s'\n", regexp);
goto fail;
}
*cmd_out = XSTRDUP(MTYPE_TMP, cmd_in);
*(strstr(*cmd_out, "|")) = '\0';
} else {
- vty_out(vty, "%% Unknown action '%s'", token);
+ vty_out(vty, "%% Unknown action '%s'\n", token);
goto fail;
}
{
struct cmd_node *cmd_node;
+ hook_unregister(cmd_execute, handle_pipe_action);
+ hook_unregister(cmd_execute_done, handle_pipe_action_done);
+
if (cmdvec) {
for (unsigned int i = 0; i < vector_active(cmdvec); i++)
if ((cmd_node = vector_slot(cmdvec, i)) != NULL) {
char **result;
int argc;
+ if (!string)
+ return NULL;
+
frrstr_split(string, delimiter, &result, &argc);
vector v = array_to_vector((void **)result, argc);
memcpy(p, parts[i], arglen);
p += arglen;
- if (i + 1 != argc) {
+ if (i + 1 != argc && join) {
memcpy(p, join, joinlen);
p += joinlen;
}
bool ret = true;
char errbuf[256];
- if (!regexp) {
- memset(&vty->include, 0x00, sizeof(vty->include));
+ if (!regexp && vty->filter) {
+ regfree(&vty->include);
vty->filter = false;
return true;
}
vector lines = frrstr_split_vec(buf, "\n");
frrstr_filter_vec(lines, &vty->include);
- if (buf[strlen(buf) - 1] == '\n' && vector_active(lines) > 0)
+
+ /*
+ * Consider the string "foo\n". If the regex is an empty string
+ * and the line ended with a newline, then the vector will look
+ * like:
+ *
+ * [0]: 'foo'
+ * [1]: ''
+ *
+ * If the regex isn't empty, the vector will look like:
+ *
+ * [0]: 'foo'
+ *
+ * In this case we'd like to preserve the newline, so we add
+ * the empty string [1] as in the first example.
+ */
+ if (buf[strlen(buf) - 1] == '\n' && vector_active(lines) > 0
+ && strlen(vector_slot(lines, vector_active(lines) - 1)))
vector_set(lines, XSTRDUP(MTYPE_TMP, ""));
+
filtered = frrstr_join_vec(lines, "\n");
frrstr_strvec_free(lines);
} else {
if (vty->is_paged)
return vty->of;
+ if (!vtysh_pager_name)
+ return NULL;
+
vty->of_saved = vty->of;
vty->of = popen(vtysh_pager_name, "w");
if (vty->of == NULL) {