[GRASS-dev] Re: g.list: extra whitespace issue

Ivan Shmakov ivan at theory.asu.ru
Sun Mar 2 14:05:05 EST 2008


>>>>> Paul Kelly <paul-grass at stjohnspoint.co.uk> writes:

 >>>> As for the padding problem, I believe that a more generic
 >>>> should be implemented.

 >>> Such as the following (rather obscure, though actually obvious)
 >>> one.

[...]

 >> I've now committed the change:

 > Thanks Ivan. The orginal code was mine (a "DIY" solution), and I was
 > aware of the problem with the ugly linebreaks on Windows, but hadn't
 > yet investigated it further. FWIW I thought no space after the last
 > item on a line, rather than no no space when there is only one item
 > on a line, was the obvious course of action to pursue,

	The committed change eliminates extra whitespace for whatever
	number of items on a line.  The change I've suggested formely
	was, OTOH, much simpler:

     /* Field width to accomodate longest filename */
-    field_width = screen_width / perline;
+    /* NB: don't pad the names with spaces when printing one name per
+     *     line */
+    field_width = (perline > 1) ? (screen_width / perline) : 0;

	(Please note that `%0s' is identical to `%s' as far as printf ()
	is concerned.)

 > but I'm sure the code from GNU ls achieves the same even better than
 > hacking my code would.

	I didn't borrow the code from GNU ls as of yet (the piece was
	just too big for me to comprehend at once), and thus I'm solely
	responsible for the hack I've committed.

	Using the GNU ls code would be preferred, since it allows for
	variable length columns, like:

$ g.list ... 
...
Bar      Baz          Foo                                                Qux
a--name  a-long-name  an-even-longer-name-making-this-column-the-widest
$ 

	But actually, I think that a much needed change is to add both a
	``single column'' and a ``no decoration'' mode for `g.list'.
	This would somewhat simplify `g.mlist', and would allow for
	iterating over the `g.list' result directly from the Shell:

$ g.list --no-decoration -1 ... \
      | (while read i ; do ... ; done) 



More information about the grass-dev mailing list