[GRASS-dev] new v.support metadata module

Markus Neteler neteler at itc.it
Thu Mar 15 09:53:02 EDT 2007


Hello Paul,

On Thu, Mar 15, 2007 at 11:49:13AM +0000, Paul Kelly wrote:
> Hello Markus
> 
> On Thu, 15 Mar 2007, Markus Neteler wrote:
> 
> >Known bug: long comments are crashing it, I don't know why (C string 
> >programming
> >and me are somewhat orthogonal to each other) - please someone take a look.
> 
> G_strcat() does not enlarge the memory allocated for the string you are 
> appending to - it just adds the new string on to the end but the memory 
> bytes after the end were probably reserved for something else, so that is 
> a problem. You could enlarge the space allocated for Map.head.line_3 using 
> perhaps G_realloc() before appending the new comment to it, but IMHO that 
> would be a bad idea too as it is bad to modify the internal parameters of 
> the struct Map_info without using vector library functions to do it.

ah, I see!

> I think it would be better to use a temporary string for the new comment. 
> Something like:
> 
> char *temp;
> 
> G_asprintf(&temp, "%s%s", Map.head.line_3, comment->answer);
> 
> Vect_set_comment(&Map, temp);
> 
> Then you are never messing directly with the internals of the Map_info 
> struct and G_asprintf() will ensure enough memory is allocated to hold the 
> two strings concatenated together.

Very nice. Implemented like that.

> But I wonder too should there not be a newline character in there 
> somewhere as the documentation says the comment text is added to the next 
> line?

Right, the documentation was wrong - updated.

> Also don't understand the second example where a space " " is 
> appended to the comment?

>From the API I have the impression that a comment may only have
one line - which is a severe limitation! So I used space to attach
one to the next (for now). Better ideas welcome.

We now need to to some string magic to make 'v.info' print comments
longer than 80 or so chars, currently they are cut.
r.info does some line wrapping magic for this (again, C string business...).

> Also it might be useful to have a flag that would totally over-write the 
> comment rather than appending, with a big warning in the description of 
> course.

Good point: -r "replace" flag added for comments.

Markus




More information about the grass-dev mailing list