(hopefully help suggestions - take them in this spirit
The programmers' manual, chapter 7, page 42, footnote 4,
says that blank spaces can be used a field separators sites
lists. This has not worked when I've tried to use G_get_site.
I checked s.menu on the same file (in the format
1 16 11.170000
1 15 9.920000
1 14 10.210000
) and it didn't work either (though after some poking
it doesn't seem like s.menu doesn't uses the library function).
See the appended program.
I would recommend that
1. the note be deleted on page 42 of the manual
(making the pipe separated format the only valid one)
2. G_get_site:the "point|east|north|desc" format be removed
(what uses it?)
3. G_get_site:change "return -1" to "return EOF"
(I know this is picky
4. G_get_site:return another negative error code when
bad site is found (now, more than just '^#'
can be used to indicate a comment).
The only programs in src/sites that I found that
used G_get_site made sure that it returned
a positive value (thus, they wouldn't be broken
by such a change). Other programs may wish
to issue a warning when something negative
(other than EOF) happens.
5. the manual page for sites.format be changed
to indicate that more than integers can be read.
It can read doubles now (what about lat/long
in deg:min:sec|deg:min:sec|desc format?)
6. s.menu be changed to use the library function
(src/sites/s.menu/Lib/read_sites.c)
--Darrell
#include<stdio.h>
#include<string.h>
main ()
{
char temp[400];
char ebuf[128], nbuf[128];
char buf[2000];
fprintf (stderr, "\n-------------------\n");
strcpy (buf, "1 16 11.170000");
/*
* At least one character must match for this conversion to be con-
* sidered successful. This is why the following format used by
* G_get_site does not work.
*/
if (sscanf (buf, "point|%[^|]|%[^|]|%[^\n]", ebuf, nbuf, temp) >= 2
|| sscanf (buf, "%[^|]|%[^|]|%[^\n]", ebuf, nbuf, temp) >= 2)
fprintf (stderr, "0:|%s|\n1:|%s|%s|%s|", buf, ebuf, nbuf, temp);
else
fprintf (stderr, "ERROR READING site");
fprintf (stderr, "\n-------------------\n");
/*
* It should be changed to something like this. Note the order (I'm
* under the impression that the "point" prefix is archaic)
*/
if (sscanf (buf, "%[^|]|%[^|]|%[^\n]", ebuf, nbuf, temp) >= 2
|| sscanf (buf, "%s %s %[^\n]", ebuf, nbuf, temp) >= 2
|| sscanf (buf, "point|%[^|]|%[^|]|%[^\n]", ebuf, nbuf, temp) >= 2)
fprintf (stderr, "0:|%s|\n1:|%s|%s|%s|", buf, ebuf, nbuf, temp);
else
fprintf (stderr, "ERROR READING site");
fprintf (stderr, "\n-------------------\n");
}