Allow to have commands with bang.
authorDaniel Carl <danielcarl@gmx.de>
Sun, 13 Oct 2013 18:52:02 +0000 (20:52 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Sun, 13 Oct 2013 19:05:44 +0000 (21:05 +0200)
src/ex.c

index 4ea5859..90efb9f 100644 (file)
--- a/src/ex.c
+++ b/src/ex.c
@@ -93,6 +93,7 @@ static void input_activate(void);
 static gboolean parse(const char **input, ExArg *arg);
 static gboolean parse_count(const char **input, ExArg *arg);
 static gboolean parse_command_name(const char **input, ExArg *arg);
+static gboolean parse_bang(const char **input, ExArg *arg);
 static gboolean parse_lhs(const char **input, ExArg *arg);
 static gboolean parse_rhs(const char **input, ExArg *arg);
 static void skip_whitespace(const char **input);
@@ -438,6 +439,11 @@ static gboolean parse(const char **input, ExArg *arg)
     /* get the command and it's flags to decide what to parse */
     cmd = &(commands[arg->idx]);
 
+    /* parse the bang if this is allowed */
+    if (cmd->flags & EX_FLAG_BANG) {
+        parse_bang(input, arg);
+    }
+
     /* parse the lhs if this is available */
     skip_whitespace(input);
     if (cmd->flags & EX_FLAG_LHS) {
@@ -502,7 +508,7 @@ static gboolean parse_command_name(const char **input, ExArg *arg)
             }
         }
         (*input)++;
-    } while (matches > 0 && **input && **input != ' ');
+    } while (matches > 0 && **input && **input != ' ' && **input != '!');
 
     if (!matches) {
         /* TODO show readable error message */
@@ -516,6 +522,18 @@ static gboolean parse_command_name(const char **input, ExArg *arg)
     return true;
 }
 
+/**
+ * Parse a single bang ! after the command.
+ */
+static gboolean parse_bang(const char **input, ExArg *arg)
+{
+    if (*input && **input == '!') {
+        arg->bang = true;
+        (*input)++;
+    }
+    return true;
+}
+
 /**
  * Parse a single word left hand side of a command arg.
  */