[GRASS-dev] Re: testing native winGRASS

Glynn Clements glynn at gclements.plus.com
Fri Mar 16 19:48:48 EDT 2007


Moritz Lennert wrote:

> >> > but at the minute my mind has gone blank as to the portable way to
> >> > replace that. I general audit of calls to system() would have caught
> >> > that if we're able to get round to doing it I suppose.
> >>
> >> This might be priority to my testing via the GDF GRASS Tutorial, so I'll
> >> try to do that first.
> >>
> >> Should all system calls be replaced by G_system ? Should any system /
> >> G_sytem calls be avoided ? Or should we check which system() calls use
> >> functions which might not exist in Windows ?
> >
> > Avoid system() and G_system() equally. G_system() is almost identical
> > to system(), except that it appears to work around a signal handling
> > bug in some ancient system() implementations. Ditto for G_popen().
> 
> I've done a first "audit" of system() and G_system() calls. The result is
> attached.
> 
> One line for the call, the next for the line(s) defining the command that
> is being called.
> 
> I left out most calls to GRASS modules, except for those where I felt that
> there might be pathname issue. At this stage, I also left out all the
> display/ and the image rectification modules which have been replaced by
> georectify.
> 
> I don't have enough knowledge to decide what to do about each of them, but
> I'm willing to work on this provided someone can guide me.

> general/g.mapset/main.c:135:    ret = system ( buf ) ;
> G_asprintf ( &buf, "%s %s/.gislock %s", lock_prog, mapset_new_path, gis_lock );

	sprintf(path, "%s/.gislock", mapset_new_path);
	G_spawn(lock_prog, lock_prog, path, gis_lock, NULL);

> general/g.mapset/main.c:165:    system( buf );
> G_asprintf ( &buf, "/bin/sh -c \"%s/etc/clean_temp > /dev/null\"", G_gisbase() );

	sprintf(path, "%s/etc/clean_temp", G_gisbase());
	G_spawn(path, "clean_temp", NULL);
or:
	G_spawn_ex(path, "clean_temp", SF_REDIRECT_FILE, 1, O_WRONLY, "/dev/null", NULL);

> general/g.mapsets/main_cmd.c:91&126:		system (command);
> sprintf (command, "ls -C %s/%s 1>&2", G_gisdbase(), G_location());

	G_ls(G_location_path(), stderr);

> general/g.mapsets/set_path.c:65:    if (system (command) == 0)
> strcpy (command, "g.mapsets -p mapset=") & other strcat calls

	sprintf(mapset_arg, "mapset=%s", mapset)
	G_spawn("g.mapsets", "g.mapsets", "-p", mapset_arg, <other args>, NULL);

> general/g.setproj/get_stp.c:198&315:			G_system(buff);
> sprintf(buff,"%s \"%s\" 1>&2", pager, G_convert_dirseps_to_host(Tmp_file1));

	G_spawn(pager, pager, G_convert_dirseps_to_host(Tmp_file1), NULL);
or:
	G_spawn_ex(pager, pager, G_convert_dirseps_to_host(Tmp_file1), SF_REDIRECT_DESCRIPTOR, 1, 2, NULL);

> lib/g3d/g3dwindowio.c:226:    if (access (path, 0) != 0) system (command);
> strcpy (path = command, "mkdir ");

This is commented out, but in general use G_mkdir().

> lib/gis/get_datum_name.c:83:                G_system(buff);
> sprintf(buff,"%s \"%s\" 1>&2",pager, G_convert_dirseps_to_host(Tmp_file));
> 
> lib/gis/get_ell_name.c:60:            G_system(buff);
> sprintf(buff,"%s \"%s\" 1>&2", pager, G_convert_dirseps_to_host(Tmp_file));
> 
> lib/gis/get_projname.c:74:            G_system(buff);
> sprintf(buff,"%s \"%s\" 1>&2", pager, G_convert_dirseps_to_host(Tmp_file));

All as for g.setproj above.

> lib/gis/gisbase.c:34:  system (command);
> sprintf (command, "%s/etc/sroff", G_gisbase( ) );

	G_spawn(command, "sroff", NULL);

> lib/gis/gishelp.c:55:	system(buffer) ;
> sprintf(buffer, "%%GRASS_PAGER%% %s", file) ; /*ifdef __MINGW32__*/
> sprintf(buffer, "$GRASS_PAGER %s", file) ;/*else*/

	G_spawn(getenv("GRASS_PAGER"), getenv("GRASS_PAGER"), file, NULL);

> lib/imagery/ls_groups.c:70&129:    G_system(buf);
> sprintf (buf, "$GRASS_PAGER %s", tempfile);

	G_spawn(getenv("GRASS_PAGER"), getenv("GRASS_PAGER"), tempfile, NULL);

> lib/init/mke_loc.c:179:    system(buf);
> sprintf (buf, "echo %s >  \"%s/%s/%s/MYNAME\"", myname, gisdbase, location_name, mapset);  &  G_convert_dirseps_to_host(buf);

	sprintf(path, "%s/%s/%s/MYNAME", gisdbase, location_name, mapset);
	fp = fopen(path, "w");
	fputs(myname, fp);
	fclose(fp);

> lib/proj/datum.c:300:                G_system(buff);
> sprintf(buff,"%s \"%s\" 1>&2", pager, G_convert_dirseps_to_host(Tmp_file));

As for other pager uses above.

> lib/vask/V_clear.c:63:	system("clear");

Commented out.

> raster/r.average/main.c:94:    if ((stat = system(command)))
> sprintf (command, "%s -anC input=%s,%s fs=space > \"%s\"", STATS, basemap->answer, covermap->answer, tempfile1); & #define STATS "r.stats"

	sprintf(input_arg, "input=%s,%s", basemap->answer, covermap->answer);
	G_spawn_ex(STATS, STATS, "-anC", input_arg, "fs=space", SF_REDIRECT_FILE, 1, O_WRONLY|O_CREAT, tempfile, NULL);

> raster/r.average/main.c:154:    stat = system(command);
> sprintf (command, "%s input=%s output=%s < \"%s\"", RECODE, basemap->answer, outputmap->answer, tempfile2); & #define RECODE "r.recode"

	sprintf(input_arg, "input=%s", basemap->answer);
	sprintf(output_arg, "output=%s", outputmap->answer);
	G_spawn_ex(RECODE, RECODE, input_arg, output_arg, SF_REDIRECT_FILE, 0, O_RDONLY, tempfile2, NULL);

> raster/r.coin/inter.c:32:    G_system("clear");
> 
> raster/r.coin/inter.c:51:	G_system("clear");

	G_spawn("clear", "clear", NULL);

> raster/r.coin/inter.c:87:	G_system(command);
> sprintf(command,"$GRASS_PAGER %s",dumpname);

As for other pager uses above.

> raster/r.coin/inter.c:108:	    G_system(command);
> sprintf(command,"cp %s %s/%s",dumpname,G_home(),outname); 

We could really do with a G_copy(), but for now:

	sprintf(path, "%s/%s", G_home(), outname);
	G_spawn("cp", "cp", dumpname, path, NULL);

Except: the Unix version of G_home() is nonsense; the correct way to
determine the user's home directory is getenv("HOME").

> raster/r.coin/inter.c:130:	    G_system(command);
> sprintf(command,"lpr %s",dumpname);

	G_spawn("lpr", "lpr", dumpname, NULL);

> raster/r.kappa/stats.c:47:  if (system(buf)) {
> strcpy (buf, "r.stats -cin"); & many strcat() calles

	G_spawn("r.stats", "r.stats", "-cin", <other arguments>, NULL);

> lots in r.le/*, but all seem to be calls to GRASS modules, plus a series of G_system("clear") calls

Hopefully r.le won't be around much longer.

> raster/r.out.mpeg/main.c:82:    if (256 == G_system("ppmtompeg 2> /dev/null"))

	G_spawn("ppmtompeg", "ppmtompeg", NULL);
or:
	G_spawn_ex("ppmtompeg", "ppmtompeg", SF_REDIRECT_FILE, 2, O_WRONLY, "/dev/null", NULL);

> raster/r.out.mpeg/main.c:84:    else if (256 == G_system("mpeg_encode 2> /dev/null"))

	G_spawn("mpeg_encode", "ppmtompeg", NULL);
or:
	G_spawn_ex("mpeg_encode", "ppmtompeg", SF_REDIRECT_FILE, 2, O_WRONLY, "/dev/null", NULL);

> raster/r.out.mpeg/main.c:319:    if (0 != G_system(cmd))
> sprintf(cmd, "%s %s", encoder, mpfilename);

	G_spawn(encoder, encoder, mpfilename, NULL);

> raster/r.out.mpeg/main.c:351:	    G_system(cmd);
> sprintf(cmd, "cd %s; \\ls %s >> %s 2> /dev/null", path, wildarg, tfile);

Ick; leave this alone for now.

> raster/r.out.mpeg/main.c:377:    G_system(cmd);
> sprintf(cmd, "\\rm %s", tfile);

	remove(tfile);

> raster/r.out.mpeg/write.c:351&356:    G_system(cmd);
> sprintf(cmd, "\\rm %s", file);

	remove(file);
> raster/r.report/stats.c:48:	if(system(buf))
> strcpy (buf, "r.stats -acr"); & more calls to strcat

See above.

> raster/r.statistics/o_average.c:30:    if (stat = system(command))
> sprintf (command, "%s -an input='%s,%s' fs=space > %s", STATS, basemap, covermap, tempfile1); & #define STATS "r.stats"

	sprintf(input_arg, "input=%s,%s", basemap, covermap);
	G_spawn_ex(STATS, STATS, "-an", input_arg, "fs=space", SF_REDIRECT_FILE, 1, O_WRONLY|O_CREAT, tempfile1, NULL);

> raster/r.statistics/o_average.c:70:    stat = system(command);
> sprintf (command, "%s input='%s' output='%s' < %s", RECLASS, basemap, outputmap, tempfile2); & #define RECLASS "r.reclass"

	sprintf(input_arg, "input=%s", basemap);
	sprintf(output_arg, "output=%s", outputmap);
	G_spawn_ex(RECLASS, RECLASS, input_arg, output_arg, SF_REDIRECT_FILE, 0, O_RDONLY, tempfile2, NULL);

> raster/r.statistics/o_sum.c:31:    if (stat = system(command))
> sprintf (command, "%s -cn input='%s,%s' fs=space > %s", STATS, basemap, covermap, tempfile1); & #define STATS "r.stats"

	sprintf(input_arg, "input=%s,%s", basemap, covermap);
	G_spawn_ex(STATS, STATS, "-cn", input_arg, "fs=space", SF_REDIRECT_FILE, 1, O_WRONLY|O_CREAT, tempfile1, NULL);

> raster/r.statistics/o_sum.c:72:    stat = system(command);
> sprintf (command, "%s input='%s' output='%s' < %s", RECLASS, basemap, outputmap, tempfile2); & #define RECLASS "r.reclass"

	sprintf(input_arg, "input=%s", basemap);
	sprintf(output_arg, "output=%s", outputmap);
	G_spawn_ex(RECLASS, RECLASS, input_arg, output_arg, SF_REDIRECT_FILE, 0, O_RDONLY, tempfile2, NULL);

> raster/r.support/front/run.c:19:    if ((stat = G_system(buf)))
> G_snprintf(buf, sizeof(buf), "%s/etc/support/%s '%s'", G_gisbase(), pgm, rast); 

	sprintf(path, "%s/etc/support/%s", G_gisbase(), pgm);
	G_spawn(path, pgm, rast, NULL);

> raster/r.support/front/run.c:37:    if ((stat = G_system(buf)))
> G_snprintf(buf, sizeof(buf), "%s", pgm);

	G_spawn(pgm, pgm, NULL);

[Exactly why this doesn't just use G_system(pgm), I have no idea.]

> raster/r.support/modhead/check_un.c:63:    G_system(command);
> G_snprintf(command, sizeof(command), "$GRASS_PAGER %s", tempfile);

	G_spawn(getenv("GRASS_PAGER"), getenv("GRASS_PAGER"), tempfile, NULL);

> raster/r.topmodel/misc.c:10:	if(G_system(cmd)){
> where command can be one of a series of GRASS modules

	G_spawn(...)

> raster/r.transect/main.c:135:    exit (system(command));
> sprintf (command, "r.profile %s input='%s' output='-' null='%s' profile=", coord_str, parms.map->answer, parms.null_str->answer); & more strcat() calls

	sprintf(input_arg, "input=%s", parms.map->answer);
	sprintf(null_arg, "null=%s", parms.null_str->answer);
	G_spawn_ex(r.profile, r.profile, coord_str, input_arg, null_arg, <other args>, NULL);

> raster/r.watershed/front/main.c:318:	ret = system(command);
> sprintf (command, "%s/etc/water/", G_gisbase()) ; & (strcat(command,"r.watershed.seg") ||  strcat(command,"r.watershed.ram") & more strcat() calls

	sprintf(command, "%s/etc/water/%s", G_gisbase(), prog);
	G_spawn(command, prog, NULL);

> raster/r.watershed/shed/main.c:36:	    if (G_system (input.com_line_ram)) {
> 
> raster/r.watershed/shed/main.c:40:    		if (G_system (input.com_line_seg)) {
> 
> raster/r.watershed/shed/main.c:47:	  } else if (G_system (input.com_line_seg)) {

These might actually need to use G_system(); it depends upon where
input.com_line_* come from.

> vector/v.transform/creat_trans.c:66:	G_system("clear") ;

	G_spawn("clear", "clear", NULL);

> visualization/nviz/src/do_zoom.c:169:	if (system(cmd) != 0) {
> strcpy(cmd, "pnmcat -lr "); & more strcat() calls
> 
> visualization/nviz/src/do_zoom.c:184:    if (system(cmd2) != 0) {
> strcpy(cmd2, "pnmcat -tb "); & more strcat() calls

Ick. I need to either extend G_spawn[_ex] or add a G_vspawn
(G_spawnv?) function to allow for an array of arguments.

> visualization/xganim/main.c:512:	    system(cmd);
> sprintf(cmd, "cd %s; \\ls %s >> %s 2> /dev/null", path, wildarg, tfile);_______________________________________________

Same as r.out.mpeg; leave for now.

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




More information about the grass-dev mailing list