[GRASS-SVN] r40788 -
grass/branches/releasebranch_6_4/visualization/nviz/src
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Feb 3 03:12:36 EST 2010
Author: neteler
Date: 2010-02-03 03:12:34 -0500 (Wed, 03 Feb 2010)
New Revision: 40788
Modified:
grass/branches/releasebranch_6_4/visualization/nviz/src/interface.h
grass/branches/releasebranch_6_4/visualization/nviz/src/nviz_init.c
Log:
glynn: Fix handling of command line (backport from trunk, r40784)
Modified: grass/branches/releasebranch_6_4/visualization/nviz/src/interface.h
===================================================================
--- grass/branches/releasebranch_6_4/visualization/nviz/src/interface.h 2010-02-03 06:13:30 UTC (rev 40787)
+++ grass/branches/releasebranch_6_4/visualization/nviz/src/interface.h 2010-02-03 08:12:34 UTC (rev 40788)
@@ -243,7 +243,6 @@
/* nviz_init.c */
int Ninit(Tcl_Interp *, Tk_Window);
int Ninitdata(Tcl_Interp *, Nv_data *);
-int Ngetargs(Tcl_Interp *, const char ***);
/* position.c */
int Ninit_view_cmd(Nv_data *, Tcl_Interp *, int, char **);
Modified: grass/branches/releasebranch_6_4/visualization/nviz/src/nviz_init.c
===================================================================
--- grass/branches/releasebranch_6_4/visualization/nviz/src/nviz_init.c 2010-02-03 06:13:30 UTC (rev 40787)
+++ grass/branches/releasebranch_6_4/visualization/nviz/src/nviz_init.c 2010-02-03 08:12:34 UTC (rev 40788)
@@ -21,7 +21,7 @@
int script_mode = 0;
static int parse_command(Nv_data * data, Tcl_Interp * interp, /* Current interpreter. */
- int argc, const char **argv)
+ int argc, const char *argv0, const char **argv)
{
struct Option *elev, *colr, *vct, *pnt, *vol;
struct Option *panel_path, *script, *state;
@@ -29,7 +29,7 @@
struct GModule *module;
char *arglist[3], *autoload;
int i, aload = 1;
- char *argv2[argc - 1];
+ char **argv2;
int argc2, ii, jj;
/*
@@ -136,15 +136,13 @@
* Routine to strip out script name passed to through argv
* If left in it treats it as a elev arg and tries to open
*/
- for (ii = 0; ii < argc; ii++) {
- if (ii == 1)
- continue;
- argv2[jj] = (char *)argv[ii];
- jj++;
- }
- argc2 = argc - 1;
+ argv2 = G_malloc((argc + 2) * sizeof(char *));
+ argv2[0] = (char *)argv0;
+ for (ii = 0; ii < argc; ii++)
+ argv2[ii + 1] = (char *)argv[ii];
+ argv2[argc + 1] = NULL;
+ argc2 = argc + 1;
-
/* BUG?: warning: passing arg 2 of `G_parser' from incompatible pointer type */
if (G_parser(argc2, argv2))
exit(EXIT_FAILURE);
@@ -378,55 +376,44 @@
* so that G_parser can deal with them without getting sick.
*/
-int Ngetargs(Tcl_Interp * interp, /* Current interpreter. */
- const char ***args)
+static int Ngetargs(Tcl_Interp * interp, /* Current interpreter. */
+ const char **p_argv0,
+ const char ***p_argv)
{
- const char *argv0, *tmp;
- char *tmp2;
- const char *cmd;
+ const char *argv0, *argv, *cmd;
+ char *tmp;
int argc;
G_debug(2, "nviz_init:Ngetargs()");
argv0 = Tcl_GetVar(interp, "argv0", TCL_LEAVE_ERR_MSG);
- tmp = Tcl_GetVar(interp, "argv", TCL_LEAVE_ERR_MSG);
+ argv = Tcl_GetVar(interp, "argv", TCL_LEAVE_ERR_MSG);
cmd = Tcl_GetNameOfExecutable();
-#ifdef __MINGW32__
- /* argv0: C:\path\to\nviz.exe
- * cmd: C:/path/to/nviz.exe
- *
- * modify argv0 to compare with cmd.
- */
- for (tmp2 = argv0; *tmp2; tmp2++)
- if (*tmp2 == '\\')
- *tmp2 = '/';
-#endif
+ G_debug(2, "nviz_init:argv0=%s", argv0);
+ G_debug(2, "nviz_init:argv=%s", argv);
+ G_debug(2, "nviz_init:cmd=%s", cmd);
+
+ tmp = G_store(argv0);
+ G_convert_dirseps_from_host(tmp);
+ argv0 = tmp;
+
+ *p_argv0 = argv0;
+
if (strstr(argv0, "script_tools") != NULL ||
strstr(argv0, "script_play") != NULL ||
strstr(argv0, "script_get_line") != NULL ||
strstr(argv0, "script_file_tools") != NULL) {
G_message(_("Entering script mode ..."));
- tmp2 = (char *)G_malloc((strlen(cmd) + 2) * (sizeof(char)));
- sprintf(tmp2, "%s", cmd);
script_mode = 1;
+ argv = "";
}
- else if (strstr(cmd, argv0) == NULL) {
- tmp2 =
- (char *)G_malloc((strlen(cmd) + strlen(argv0) + strlen(tmp) + 4) *
- (sizeof(char)));
- sprintf(tmp2, "%s %s %s", cmd, argv0, tmp);
- }
- else {
- tmp2 =
- (char *)G_malloc((strlen(argv0) + strlen(tmp) + 2) *
- (sizeof(char)));
- sprintf(tmp2, "%s %s", argv0, tmp);
- }
- if (TCL_ERROR == Tcl_SplitList(interp, tmp2, &argc, args))
+ if (TCL_ERROR == Tcl_SplitList(interp, argv, &argc, p_argv))
exit(EXIT_FAILURE);
+ G_debug(2, "nviz_init:argc=%d", argc);
+
return (argc);
}
@@ -552,12 +539,13 @@
int Ninitdata(Tcl_Interp *interp, /* Current interpreter. */
Nv_data *data)
{
+ const char *argv0;
const char **argv;
int argc;
- argc = Ngetargs(interp, &argv);
+ argc = Ngetargs(interp, &argv0, &argv);
- G_gisinit(argv[0]);
+ G_gisinit(argv0);
GS_libinit();
@@ -567,7 +555,7 @@
data->NumCplanes = 0;
data->CurCplane = 0;
if (!script_mode)
- parse_command(data, interp, argc, argv);
+ parse_command(data, interp, argc, argv0, argv);
return (TCL_OK);
}
More information about the grass-commit
mailing list