[GRASS-dev] g.mapsets use of sleep()

Glynn Clements glynn at gclements.plus.com
Wed Dec 6 01:53:36 EST 2006


Hamish wrote:

> > A lot of the [G_]system and [G_]popen calls in GRASS (I count 105)
> > will be similarly problematic. Some will be calling GRASS programs,
> > but a lot use Unix commands.
> 
> 105 really isn't that many.
> 
> for the ones that are unix commands, the vast majority are just ls, cp,
> mv, rm?

I'm not saying it's difficult, just a lot of donkey-work.

Although, there are a few non-trivial cases; e.g. replacing "rm -rf"
isn't simple, and getting it wrong can be quite disastrous. But we
already have a replacement in lib/init/clean_temp.c.

rename() is ANSI C, although (on Unix, at least) it only works if the
source and destination paths are on the same filesystem (partition),
otherwise you have to copy the file then delete the original.

Windows has CopyFile(); Unix doesn't have any equivalent (the notion
of copying is ambiguous when the destination exists).

> step 1: define portable tcl and C replacements (e.g. glob, unlink())
> for the common ones. (eg with Paul's new G_convert_dirseps_to_host())

remove() (ANSI C) is preferable to unlink() (POSIX) for files,
although Windows requires using rmdir() (POSIX) for directories.

MinGW provides an opendir/readdir/closedir implementation, or you can
use FindFirstFile/FindNextFile/FindClose.

> these two are really bad:
> 
> lib/fonts/for_grass/try.c:   system ("cd fonts; ls *.hmp | sed 's/.hmp//' | fmt");
> lib/fonts/for_grass/fontmap.c:  system ("cd ../fonts; ls *.hmp | sed 's/.hmp//' | fmt");

"try" is just a debugging utility. It doesn't get built as part of the
normal build process. Also, that section of fontmap.c appears to be
for debugging; it only gets called if you specify "ls" as an argument
to splitfont.

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list