فهرست منبع

parser: provide wxGUI forms.py with a full path if available (https://trac.osgeo.org/grass/ticket/2133)

The GUI form/dialog now opens for a script
which is not on path and from command line
and main GUI the dialog will actually execute
the module because the full path is available.
(Needs also r67993.)


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@67994 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras 9 سال پیش
والد
کامیت
f820d866f5
2فایلهای تغییر یافته به همراه61 افزوده شده و 3 حذف شده
  1. 40 3
      lib/gis/parser.c
  2. 21 0
      lib/gis/progrm_nme.c

+ 40 - 3
lib/gis/parser.c

@@ -619,9 +619,11 @@ int G_parser(int argc, char **argv)
  * Creates a command-line that runs the current command completely
  * non-interactive.
  *
+ * \param original_path TRUE if original path should be used, FALSE for
+ *  stripped and clean name of the module
  * \return pointer to a char string
  */
-char *G_recreate_command(void)
+char *recreate_command(int original_path)
 {
     char *buff;
     char flg[4];
@@ -638,7 +640,10 @@ char *G_recreate_command(void)
 
     buff = G_calloc(1024, sizeof(char));
     nalloced += 1024;
-    tmp = G_program_name();
+    if (original_path)
+        tmp = G_original_program_name();
+    else
+        tmp = G_program_name();
     len = strlen(tmp);
     if (len >= nalloced) {
 	nalloced += (1024 > len) ? 1024 : len + 1;
@@ -750,6 +755,37 @@ char *G_recreate_command(void)
 }
 
 /*!
+ * \brief Creates command to run non-interactive.
+ *
+ * Creates a command-line that runs the current command completely
+ * non-interactive.
+ *
+ * \return pointer to a char string
+ */
+char *G_recreate_command(void)
+{
+    recreate_command(FALSE);
+}
+
+/* TODO: update to docs of these 3 functions to whatever general purpose
+ * they have now. */
+/*!
+ * \brief Creates command to run non-interactive.
+ *
+ * Creates a command-line that runs the current command completely
+ * non-interactive.
+ *
+ * This gives the same as G_recreate_command() but the original path
+ * from the command line is used instead of the module name only.
+ *
+ * \return pointer to a char string
+ */
+char *G_recreate_command_original_path(void)
+{
+    recreate_command(TRUE);
+}
+
+/*!
   \brief Add keyword to the list
 
   \param keyword keyword string
@@ -863,6 +899,7 @@ int module_gui_wx(void)
 {
     char script[GPATH_MAX];
 
+    /* TODO: the 4 following lines seems useless */
     if (!st->pgm_path)
 	st->pgm_path = G_program_name();
     if (!st->pgm_path)
@@ -872,7 +909,7 @@ int module_gui_wx(void)
             getenv("GISBASE"));
     if (access(script, F_OK) != -1)
         G_spawn(getenv("GRASS_PYTHON"), getenv("GRASS_PYTHON"),
-                script, G_recreate_command(), NULL);
+                script, G_recreate_command_original_path(), NULL);
     else
         return -1;
 

+ 21 - 0
lib/gis/progrm_nme.c

@@ -15,6 +15,7 @@
 #include <grass/gis.h>
 
 static const char *name = "?";
+static const char *original_name = "?";
 
 /*!
  * \brief Return module name
@@ -30,6 +31,24 @@ const char *G_program_name(void)
 }
 
 /*!
+ * \brief Return original path of the executed program
+ *
+ * This function returns the name of the program as set by the call to
+ * G_gisinit().
+ *
+ * Unlike G_program_name() which returns name of the module
+ * this function return original path which was used to execute
+ * the program. For standard GRASS modules, it will be the same as
+ * the result from G_program_name() function.
+ *
+ * \return pointer to string with program name or full path
+ */
+const char *G_original_program_name(void)
+{
+    return original_name;
+}
+
+/*!
   \brief Set program name
 
   Program name set to name (name will be returned by
@@ -44,6 +63,8 @@ void G_set_program_name(const char *s)
     int i;
     char *temp;
 
+    original_name = G_store(s);
+
     i = strlen(s);
     while (--i >= 0) {
 	if (G_is_dirsep(s[i])) {