[GRASS-dev] using G_parser() --script in the wild

Hamish hamish_nospam at yahoo.com
Thu Mar 8 00:26:28 EST 2007


[wrapper script for d.path from the GUI with backdrop]

...
> > build up an options string. If $opt1 is "", then the exec command
> > just has an extra space in it.
> > 
> > for example:
> > 
> > optstring=""
> > if [ "$GIS_FLAG_G" -eq 1 ] ; then
> >   optstring="$optstring -g"
> > fi
> > if [ -n "$GIS_OPT_MAP" ] ; then
> >   optstring="$optstring map=\"$GIS_OPT_MAP\""
> > fi
> > exec d.path $optstring
> > 
> > 
> > or if you think optstring="$optstring ..." is evil,
> 
> It won't work with values which may contain spaces. If you wrap the
> value in single quotes, it won't work with values which may contain
> single quotes.
> 
> > if [ "$GIS_FLAG_G" -eq 1 ] ; then
> >     gflag="-g"
> > else
> >     gflag=""
> > fi
> > if [ -n "$GIS_OPT_AFCOL" ] ; then
> >     afcol="afcol=\"$GIS_OPT_AFCOL\""
> > else
> >     afcol=""
> > fi
> > [...]
> > exec d.path $gflag $afcol [...]
> 
> That works; it's just ugly. The fact that afcol, abcol and ncol need
> special treatment stands out, and lead me to consider whether there's
> a better solution.

why do the column name options need special treatment?

none of d.path's other options should contain spaces or special chars,
so I don't think the quoting is critical.


If I quote the column options on the exec line I get this error:

if [ -n "$GIS_OPT_AFCOL" ] ; then
    opt_afcol="afcol=$GIS_OPT_AFCOL"
else
    opt_afcol=""
fi

[...]

exec d.path $flag_g $flag_b \
	"$opt_map" "$opt_type" \
	"$opt_alayer" "$opt_nlayer" \
	"$opt_afcol" "$opt_abcol" "$opt_ncol" \
	"$opt_color" "$opt_hcolor" "$opt_bgcolor"


"Sorry <> is not a valid option",  followed by G_usage().

presumably because "" makes argc++, but the last few argv are empty, and
G_parser() loops through argc.


similar:
# invalid option error
d.erase grey \
""

# no error
d.erase grey\  
""


anyway, any problems with the attached script?
 will column names require quoting? (e.g. column="Jane's Data")
 or is that illegal SQL?


Hamish
-------------- next part --------------
A non-text attachment was scrubbed...
Name: d.path_wrapper.sh
Type: text/x-sh
Size: 4475 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/grass-dev/attachments/20070308/74101a53/d.path_wrapper.bin


More information about the grass-dev mailing list