Revision: 76427
          http://sourceforge.net/p/brlcad/code/76427
Author:   starseeker
Date:     2020-07-22 20:09:45 +0000 (Wed, 22 Jul 2020)
Log Message:
-----------
Print something informative if we get an unexpected argv0 value in one of the 
explicit ged_* function calls.  This won't catch a 
valid-command-but-not-matching-function-name situation, but it's a start.

Modified Paths:
--------------
    brlcad/branches/gedplugins/include/ged/defines.h
    brlcad/branches/gedplugins/src/libged/exec.cpp
    brlcad/branches/gedplugins/src/libged/exec_mapping.cpp
    brlcad/branches/gedplugins/src/libged/tests/plugins.c

Modified: brlcad/branches/gedplugins/include/ged/defines.h
===================================================================
--- brlcad/branches/gedplugins/include/ged/defines.h    2020-07-22 19:44:43 UTC 
(rev 76426)
+++ brlcad/branches/gedplugins/include/ged/defines.h    2020-07-22 20:09:45 UTC 
(rev 76427)
@@ -61,6 +61,7 @@
 #define GED_HELP  0x0002 /**< invalid specification, result contains usage */
 #define GED_MORE  0x0004 /**< incomplete specification, can specify again 
interactively */
 #define GED_QUIET 0x0008 /**< don't set or modify the result string */
+#define GED_UNKNOWN 0x0010 /**< argv[0] was not a known command */
 
 #define GED_VMIN -2048.0
 #define GED_VMAX 2047.0

Modified: brlcad/branches/gedplugins/src/libged/exec.cpp
===================================================================
--- brlcad/branches/gedplugins/src/libged/exec.cpp      2020-07-22 19:44:43 UTC 
(rev 76426)
+++ brlcad/branches/gedplugins/src/libged/exec.cpp      2020-07-22 20:09:45 UTC 
(rev 76427)
@@ -49,7 +49,7 @@
     std::map<std::string, const struct ged_cmd *>::iterator c_it = 
cmap->find(key);
     if (c_it == cmap->end()) {
        bu_vls_printf(gedp->ged_result_str, "unknown command: %s", argv[0]);
-       return GED_ERROR;
+       return (GED_ERROR | GED_UNKNOWN);
     }
 
     const struct ged_cmd *cmd = c_it->second;

Modified: brlcad/branches/gedplugins/src/libged/exec_mapping.cpp
===================================================================
--- brlcad/branches/gedplugins/src/libged/exec_mapping.cpp      2020-07-22 
19:44:43 UTC (rev 76426)
+++ brlcad/branches/gedplugins/src/libged/exec_mapping.cpp      2020-07-22 
20:09:45 UTC (rev 76427)
@@ -32,7 +32,11 @@
 #define GED_CMD(x) \
        int GED_CMD_HELPER1(ged_,x)(struct ged *gedp, int argc, const char 
*argv[]) \
        { \
-           return ged_exec(gedp, argc, argv); \
+           int ret = ged_exec(gedp, argc, argv); \
+           if (ret & GED_UNKNOWN) { \
+               bu_log("Error: LIBGED command \"ged_" #x "\" called with an 
unexpected argv[0] value: %s\n", argv[0]); \
+           }\
+           return ret; \
        } \
 
 GED_CMD(3ptarb)

Modified: brlcad/branches/gedplugins/src/libged/tests/plugins.c
===================================================================
--- brlcad/branches/gedplugins/src/libged/tests/plugins.c       2020-07-22 
19:44:43 UTC (rev 76426)
+++ brlcad/branches/gedplugins/src/libged/tests/plugins.c       2020-07-22 
20:09:45 UTC (rev 76427)
@@ -359,6 +359,15 @@
        ccmd = app_cmds[app_cmd_cnt];
     }
 
+    /* Deliberately call a ged function with wrong argv[0] */
+    const char *wav0 = "wrong_name";
+    int ret = ged_ls(gbp, 1, &wav0);
+    if (ret & GED_UNKNOWN) {
+       bu_log("\nged_ls called with command name \"%s\" reported expected 
error\n", wav0);
+    } else {
+       bu_log("\nged_ls called with command name \"%s\" did not report the 
expected error\n", wav0);
+    }
+
     ged_close(gbp);
     BU_PUT(gbp, struct ged);
     return 0;

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to