Here's a patch to let ]usercmd accept restatement of an existing user
command definition so long as the associated function name and mode are
identical.

      ]usercmd ]foo foo 1
    User-defined command ]foo installed.
      ]usercmd ]foo foo 1
      ⍝ without the patch there'd be a BAD COMMAND response here
      ]usercmd ]foo foo
BAD COMMAND
      ⍝ correct: mode differs
      )more
conflict with existing user command definition in command ]USERCMD
      ]usercmd ]foo goo 1
BAD COMMAND
      ⍝ correct: function name differs
      )more
conflict with existing user command definition in command ]USERCMD
      ]help
Commands are:
      )CHECK 
[... snip ...]
      ]XTERM [ON or OFF]

User defined commands:
      ]foo → A foo B (mode 1)
      ⍝ initial definition is still present
      
Index: src/Command.cc
===================================================================
--- src/Command.cc	(revision 269)
+++ src/Command.cc	(working copy)
@@ -815,6 +815,33 @@
    return true;
 }
 //-----------------------------------------------------------------------------
+bool
+Command::check_redefinition(ostream & out, const UCS_string & cnew,
+                            const UCS_string fnew, const int mnew)
+{
+   loop(u, user_commands.size())
+     {
+       const UCS_string cold = user_commands[u].prefix;
+       const UCS_string fold = user_commands[u].apl_function;
+       const int mold = user_commands[u].mode;
+
+       if (cnew != cold)   continue;
+
+       // user command name matches; so must mode and function
+       if (mnew != mold || fnew != fold)
+         {
+           out << "BAD COMMAND" << endl;
+           Workspace::more_error() 
+             = UCS_string(
+                          "conflict with existing user command definition"
+                          " in command ]USERCMD");
+         }
+       return true;
+     }
+
+   return false;
+}
+//-----------------------------------------------------------------------------
 void
 Command::cmd_USERCMD(ostream & out, const UCS_string & cmd,
                      vector<UCS_string> & args)
@@ -900,8 +927,7 @@
 #define cmd_def(cmd_str, _cod, arg) \
    if (check_name_conflict(out, cmd_str, args[0]))   return;
 #include "Command.def"
-   loop(u, user_commands.size())
-       if (check_name_conflict(out, args[0], user_commands[u].prefix))   return;
+   if (check_redefinition(out, args[0], args[1], mode))   return;
 
    // check APL function name
    //
Index: src/Command.hh
===================================================================
--- src/Command.hh	(revision 269)
+++ src/Command.hh	(working copy)
@@ -121,6 +121,9 @@
    static bool check_name_conflict(ostream & out, const UCS_string & cnew,
                                    const UCS_string cold);
 
+   static bool check_redefinition(ostream & out, const UCS_string & cnew,
+                                  const UCS_string fnew, const int mnew);
+
    /// a helper struct for the )IN command
    struct transfer_context
       {

Reply via email to