Revision: 76408
          http://sourceforge.net/p/brlcad/code/76408
Author:   starseeker
Date:     2020-07-22 12:13:17 +0000 (Wed, 22 Jul 2020)
Log Message:
-----------
Make a stab at a function to return a list of ged commands

Modified Paths:
--------------
    brlcad/branches/gedplugins/include/ged/defines.h
    brlcad/branches/gedplugins/src/libged/ged_init.cpp

Modified: brlcad/branches/gedplugins/include/ged/defines.h
===================================================================
--- brlcad/branches/gedplugins/include/ged/defines.h    2020-07-22 11:43:56 UTC 
(rev 76407)
+++ brlcad/branches/gedplugins/include/ged/defines.h    2020-07-22 12:13:17 UTC 
(rev 76408)
@@ -290,6 +290,12 @@
 
 GED_EXPORT const char * ged_init_msgs();
 
+/* LIBGED maintains this list - callers should regard it as read only.  This
+ * list will change (size and pointers to individual command strings if
+ * commands are added or removed - caller is responsible for performing a new
+ * call to get an updated list and size if commands are altered.  */
+GED_EXPORT size_t ged_cmd_list(const char * const **cmd_list);
+
 __END_DECLS
 
 #endif /* GED_DEFINES_H */

Modified: brlcad/branches/gedplugins/src/libged/ged_init.cpp
===================================================================
--- brlcad/branches/gedplugins/src/libged/ged_init.cpp  2020-07-22 11:43:56 UTC 
(rev 76407)
+++ brlcad/branches/gedplugins/src/libged/ged_init.cpp  2020-07-22 12:13:17 UTC 
(rev 76408)
@@ -37,6 +37,7 @@
 #include "bu/app.h"
 #include "bu/dylib.h"
 #include "bu/file.h"
+#include "bu/str.h"
 #include "bu/vls.h"
 #include "ged.h"
 
@@ -43,6 +44,8 @@
 #include "./include/plugin.h"
 
 static std::map<std::string, const struct ged_cmd *> ged_cmd_map;
+static size_t cmd_list_len = 0;
+static char **cmd_list = NULL;
 void *ged_cmds;
 
 static std::set<void *> ged_handles;
@@ -54,6 +57,23 @@
     return bu_vls_cstr(ged_init_msg_str);
 }
 
+size_t
+ged_cmd_list(const char * const **cl)
+{
+    if (!cmd_list) {
+       bu_argv_free(cmd_list_len, (char **)cmd_list);
+       cmd_list_len = 0;
+    }
+    cmd_list = (char **)bu_calloc(ged_cmd_map.size(), sizeof(char *), "ged cmd 
argv");
+    std::map<std::string, const struct ged_cmd *>::iterator m_it;
+    for (m_it = ged_cmd_map.begin(); m_it != ged_cmd_map.end(); m_it++) {
+       const char *str = m_it->first.c_str();
+       cmd_list[cmd_list_len] = bu_strdup(str);
+       cmd_list_len++;
+    }
+    (*cl) = (const char * const *)cmd_list;
+    return cmd_list_len;
+}
 
 static void
 libged_init(void)

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