[GRASS-dev] Re: [bug #5218] (grass) wingrass: creating new
location from startup screen with projection values fails
Glynn Clements
glynn at gclements.plus.com
Tue Oct 24 17:17:09 EDT 2006
Moritz Lennert wrote:
> So, IIUC, this should work with cmd.exe which allows pdcurses code, but
> it doesn't and fails with:
>
> > The procedure crashes after entering
> > the one-line description of the new location with an error
> > message: "the syntax of the command is not correct. LOCATION (test)
> > NOT created" (translated from French).
>
> So, if this is not a pdcurses issue, what could be the problem ?
make_location() uses system() with Unix commands:
sprintf (buf, "mkdir '%s'/'%s'", gisdbase, location_name);
if(system(buf)) return 0;
sprintf (buf, "mkdir '%s'/'%s'/'%s'", gisdbase, location_name, mapset);
if(system(buf)) return 0;
[snip]
sprintf (buf, "echo '%s' > '%s'/'%s'/'%s'/MYNAME", myname, gisdbase, location_name, mapset);
system(buf);
On a native Windows version, system() will use cmd.exe to execute
commands, not /bin/sh.
Windows has native versions of mkdir and echo. The native mkdir won't
like being passed Unix filenames, as it treats / as indicating
options:
C:\>mkdir /foo
The syntax of the command is incorrect.
Fortunately, this bug shoud be quite simple to fix: use the mkdir()
function rather than using system() to run the mkdir command. Could
someone try the attached patch?
Unfortunately, GRASS has a lot of this sort of stuff - using system()
to run commands rather than using functions; probably because the
author knew about the command but didn't know about the function. I've
even seen system("rm ...") used to delete files.
Finding (and fixing) all of the Unix-specific system() calls will be a
large part of getting a native Windows version of GRASS to work.
--
Glynn Clements <glynn at gclements.plus.com>
-------------- next part --------------
Index: lib/init/mke_loc.c
===================================================================
RCS file: /grassrepository/grass6/lib/init/mke_loc.c,v
retrieving revision 2.3
diff -u -r2.3 mke_loc.c
--- lib/init/mke_loc.c 9 Feb 2006 03:08:57 -0000 2.3
+++ lib/init/mke_loc.c 24 Oct 2006 21:05:08 -0000
@@ -3,6 +3,10 @@
#include <grass/gis.h>
#include "local_proto.h"
+#ifdef __MINGW32__
+# define mkdir(name, mode) ((mkdir) (name))
+#endif
+
int
make_location (char *gisdbase, char *location_name)
{
@@ -146,10 +150,10 @@
G__setenv ("MAPSET", mapset);
G__setenv ("LOCATION_NAME", location_name);
- sprintf (buf, "mkdir '%s'/'%s'", gisdbase, location_name);
- if(system(buf)) return 0;
- sprintf (buf, "mkdir '%s'/'%s'/'%s'", gisdbase, location_name, mapset);
- if(system(buf)) return 0;
+ sprintf (buf, "%s/%s", gisdbase, location_name);
+ if(mkdir(buf, 0777) < 0) return 0;
+ sprintf (buf, "%s/%s/%s", gisdbase, location_name, mapset);
+ if(mkdir(buf, 0777) < 0) return 0;
/* set the dummy window */
window.north =1.;
window.south = 0.;
More information about the grass-dev
mailing list