[GRASS-dev] Re: [bug #5218] (grass) wingrass: creating new
location from startup screen with projection values fails
Glynn Clements
glynn at gclements.plus.com
Wed Oct 25 02:21:47 EDT 2006
Hamish wrote:
> > 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.
>
> grass63$ grep -rI mkdir * | grep sprintf
>
> gem/reg_entries.c: sprintf ( str, "mkdir --verbose %s/etc/dm/gem-entries ; cp -vf ../entries-gisman %s/etc/dm/gem-entries/%s ; \
> gem/reg_entries.c: sprintf ( str, "mkdir %s/etc/dm/gem-entries &> %s ; cp -f ../entries-gisman %s/etc/dm/gem-entries/%s &> %s ; \
> gem/reg_entries.c: sprintf ( str, "mkdir --verbose -p %s/etc/gm/Xtns ; cp -fv ../entries-gisman2 %s/etc/gm/Xtns/%s.gem ; ",
> gem/reg_entries.c: sprintf ( str, "mkdir -p %s/etc/gm/Xtns ; cp -f ../entries-gisman2 %s/etc/gm/Xtns/%s.gem ; ",
GEM creates substantial scripts using sprintf(), then runs them using
"su -c ...". Ick. That isn't something which can easily be changed,
though.
> lib/init/mke_loc.c: sprintf (buf, "mkdir '%s'/'%s'", gisdbase, location_name);
> lib/init/mke_loc.c: sprintf (buf, "mkdir '%s'/'%s'/'%s'", gisdbase, location_name, mapset);
> lib/init/mke_mapset.c: sprintf(buffer,"mkdir '%s'/'%s'",location, mapset) ;
mke_mapset.c can be changed likewise. Ironically, it already uses
mkdir() to create the dbf directory.
> $ grep -rI mkdir * | grep system
>
> raster/r.le/r.le.setup/main.c: G_system("mkdir r.le.para");
> raster/r.le/r.le.patch/main.c: G_system("mkdir r.le.out");
> raster/r.le/r.le.pixel/main.c: G_system("mkdir r.le.out");
Well, r.le is r.le; nothing surprises me there.
We should probably add a G_mkdir(), to save having to handle the
Windows mkdir() (which only takes one argument) in lots of different
files.
In any case, system("mkdir ...") is just the tip of the iceberg. I
count:
function count
system 52
G_system 25
popen 28
G_popen 3
total 108
I wouldn't be surprised if the majority of those calls have some kind
of portability issue.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list