[GRASS-dev] Re: [GRASS-windows] Problems with Mapcanvas

Hamish hamish_nospam at yahoo.com
Thu Nov 22 07:27:12 EST 2007


> > Glynn:
> > > That doesn't tell me the one thing I really need to know: whether
> > > there are CR characters in the file.
> > > 
> > > Try "od -t x1z PROJ_INFO"; look for any occurrences of "0d" in the
> > > output.
> > 
Hamish:
> > perhaps this patch helps:
> > 
> > Index: lib/gis/key_value2.c
> > ===================================================================
> > RCS file: /home/grass/grassrepository/grass6/lib/gis/key_value2.c,v
> > retrieving revision 2.3
> > diff -u -r2.3 key_value2.c
> > --- lib/gis/key_value2.c        14 Apr 2007 23:01:59 -0000      2.3
> > +++ lib/gis/key_value2.c        21 Nov 2007 01:11:54 -0000
> > @@ -32,7 +32,7 @@
> >      kv = G_create_key_value();
> >      if (kv == NULL)
> >         return NULL;
> > -    while (G_getl(buf, sizeof buf, fd) != 0)
> > +    while (G_getl2(buf, sizeof buf, fd) != 0)
> >      {
> >         key = value = buf;
> >         while (*value && *value != ':')
>
> Probably.

applied in 6.3 HEAD & the 6.3.0 r.b.

> Although we should also change the code which is putting the
> CRs there in the first place (assuming that's what's happening).

lib/gis/key_value2.c has G_fwrite_key_value(), but that does this:
  fprintf (fd, "%s: %s\n",

r.in.gdal uses that through G_make_location()
The other way to make a new location is through g.proj -c (GUI startup screen
uses this) but that uses G_write_key_value_file() too, as does g.setproj.

?


> For 7.x, we should probably just rename G_getl2 -> G_getl. There can't
> be many cases where we actually want to read native line ends.

fine with me.
 
> > also, should that be using "(buf, sizeof(buf)-1, fd" ?
> 
> Yes and no. The current behaviour of G_getl2() requires it, but it's
> G_getl2() which should be changed to match G_getl(), fgets() etc.

fine with me.


Towards a goal of read sloppy & write strict, these places in lib/gis still use
G_getl() and fgets(), and should be reviewed for a possible change to
G_getl2():

lib/gis$ grep 'G_getl\|fgets' *.c | grep -v 'G_getl2\|getl.c:'       
cats.c:    if (G_getl(buff,sizeof buff,fd) == 0)
cats.c:    if (G_getl(buff,sizeof buff,fd) == 0)
cats.c: if (G_getl(fmt,sizeof fmt,fd) == 0)
cats.c: if (G_getl(buff,sizeof buff,fd) == 0)
cats.c: if (G_getl(buff, sizeof buff, fd) == 0)
cell_title.c:   if (!fgets(title, sizeof title, fd))   /* skip number of cats
*/
cell_title.c:   else if (!G_getl(title, sizeof title, fd))      /* read title
*/
color_read.c:    if (fgets(buf,sizeof buf,fd) == NULL) 
color_read.c:    if (fgets(buf,sizeof buf,fd) == NULL) 
color_read.c:    while (fgets(buf, sizeof buf, fd))
color_read.c:    if (fgets(buf,sizeof buf,fd) == NULL) 
color_read.c:    while (fgets (buf, sizeof buf, fd))
color_rules.c:  if (!fgets(buf, sizeof(buf), fp))
dig_title.c:    if (!fgets(title, sizeof title, fd))   /* skip number of cats
*/
dig_title.c:    else if (!G_getl(title, sizeof title, fd))      /* read title
*/
error.c:        if (fgets(cwd, sizeof(cwd), pwd))
gets.c:      eof = fgets(p,100,stdin);
histogram.c:    while (fgets (buf, sizeof buf, fd))
history.c:    if (!G_getl(hist->mapid, sizeof(hist->mapid), fd))
history.c:    if (!G_getl(hist->title, sizeof(hist->title), fd))
history.c:    if (!G_getl(hist->mapset, sizeof(hist->mapset), fd))
history.c:    if (!G_getl(hist->creator, sizeof(hist->creator), fd))
history.c:    if (!G_getl(hist->maptype, sizeof(hist->maptype), fd))
history.c:    if (!G_getl(hist->datsrc_1, sizeof(hist->datsrc_1), fd))
history.c:    if (!G_getl(hist->datsrc_2, sizeof(hist->datsrc_2), fd))
history.c:    if (!G_getl(hist->keywrd, sizeof(hist->keywrd), fd))
history.c:      (G_getl( hist->edhist[hist->edlinecnt], sizeof
(hist->edhist[0]), fd)))
myname.c:       ok = G_getl(name, sizeof name, fd);
parser.c:               if(fgets(buff,1024,stdin) == 0) exit(EXIT_SUCCESS); ;
put_title.c:    for (line = 0; G_getl (buf, sizeof buf, in); line++)
put_title.c:    while (fgets(buf, sizeof buf, in))
quant_io.c:  while (fgets (buf, sizeof (buf), fd)) 
range.c:        if (!fgets (buf, sizeof buf, fd))
rd_cellhd.c:    while ( G_getl (buf, sizeof (buf), fd) ) count++;
rd_cellhd.c:    while ( G_getl (buf, sizeof (buf), fd) )
reclass.c:    for (i=0; !feof(fd) && fgets(buf2, 255, fd); )
reclass.c:    if (fgets(buf,sizeof(buf),fd) == NULL)
reclass.c:      if (fgets(buf,sizeof buf,fd) == NULL)
reclass.c:    for (i=0; !feof(fd) && fgets(buf3, 255, fd); )
reclass.c:    while (fgets (buf, sizeof buf, fd))
squeeze.c: *     Also squeezes out newlines -- easier to use with fgets()
timestamp.c:    while (fgets(buf, sizeof(buf), fd))
view.c: if(NULL != fgets(buffer, 80, fp)){
view.c: while(NULL != fgets(buffer, 75, fp)){
view.c: if(1 == sscanf(fgets(buffer, 80, fp),"%f",&(v->from_to[1][0])) )
view.c: if(1 == sscanf(fgets(buffer, 80, fp),"%f",&(v->from_to[1][1])) )
view.c: if(1 == sscanf(fgets(buffer, 80, fp),"%f",&(v->from_to[1][2])) )
view.c: if(1 == sscanf(fgets(buffer, 80, fp),"%f",&(v->from_to[0][0])) )
view.c: if(1 == sscanf(fgets(buffer, 80, fp),"%f",&(v->from_to[0][1])) )
view.c: if(1 == sscanf(fgets(buffer, 80, fp),"%f",&(v->from_to[0][2])) )
view.c: if(1 == sscanf(fgets(buffer, 80, fp),"%f",&(v->exag)) )
view.c: sscanf(fgets(buffer, 80, fp),"%d",&(v->mesh_freq)) ;
view.c: if(1 == sscanf(fgets(buffer, 80, fp),"%f",&(v->fov)) )
view.c: if(1 == sscanf(fgets(buffer, 80, fp),"%lf",&td) ){  /* resolution */
view.c: sscanf(fgets(buffer, 80, fp),"%s",boo) ; /* linesonly */
view.c: sscanf(fgets(buffer, 80, fp),"%s",boo) ;
view.c: sscanf(fgets(buffer, 80, fp),"%s",v->grid_col) ;
view.c: sscanf(fgets(buffer, 80, fp),"%s",v->other_col) ;
view.c: sscanf(fgets(buffer, 80, fp),"%s",v->bg_col) ;
view.c: sscanf(fgets(buffer, 80, fp),"%s",boo) ;



Hamish



      ____________________________________________________________________________________
Get easy, one-click access to your favorites. 
Make Yahoo! your homepage.
http://www.yahoo.com/r/hs 


More information about the grass-dev mailing list