[GRASS-dev] r.colors: rules file list unsorted

Paul Kelly paul-grass at stjohnspoint.co.uk
Sun Jan 28 21:06:22 EST 2007


Hello Daniel

On Sun, 28 Jan 2007, Daniel Calvelo wrote:

> On 1/28/07, Glynn Clements <glynn at gclements.plus.com> wrote:
>> 
>> A library function should probably return the entries as an array of
>> strings (char **) rather than write them to a stream. The caller can
>> deal with writing them, if that's desired.
>
> That's how it's done in the patched r.colors. If it must be turned
> into a library function, where would it go? What would its name be?
> I'm willing to do it (and also change any system("ls")'s remaining).

I've just finished it - see attached - planning on committing it as 
lib/gis/ls.c tomorrow after some more polishing if no objections.

The way I've done it there are 3 functions:

G__ls() reads the directory and stores the entries in an array.
G_ls() prints the listing to a specified stream, one entry per line.
G_ls_columns() prints the listing to a specified stream in column format.

>> > and perhaps a flag to do a column-wise listing
>> > (a la "ls -C"). I think this would be the hardest part to do; not sure 
>> how
>> > ls does it - unless there is something easy we could do with format
>> > conversion strings?
>> 
>> Read all of the names, find the longest name to determine the column
>> widths, divide the width of the terminal[1] by the column width to
>> determine the number of columns, write out all of the strings padded
>> to a fixed width.
>
> The parser uses column break with a hardcoded value. We certainly
> could use a global function for determining column width.

I used the ioctl method. Works for me on Linux but not on Windows - have 
disabled the functionality there and it just uses hard-coded 80 characters 
for now. But it does work nicely on Linux as far as I can see. The 
GetConsoleScreenBufferInfo() function might be worth looking at on 
Windows.

Paul
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ls.c
Type: text/x-csrc
Size: 3747 bytes
Desc: 
Url : http://lists.osgeo.org/pipermail/grass-dev/attachments/20070129/ddc52086/ls.bin


More information about the grass-dev mailing list