[GRASS5] snprintf and other compile errors on IRIX

Hello
I am running GRASS on two slightly out-of-date IRIX installations (6.2 and
6.4---nothing I can do about this!) and everytime I update our GRASS
installation it seems even more modules are failing due to the snprintf
function being used in them. I don't know that much about libraries but it
is not in the standard ones that come with IRIX. I have got round the
problem by downloading a 3rd party libsnprintf library, compiled and
installed that and then I have to manually change the Gmakefile for all
the failed modules, adding in the exact path to libsnprintf.a at the end
of the compiler line in the makefile; it is nearly always after
$(XDRLIB) or $(MATHLIB).

This works fine but it is very tedious. I was wondering could the
makefiles be changed for those modules that include snprintf in their code
(list is below) to perhaps have another variable specifically referring to
a 3rd party snprintf library at the end of the line after ($XDRLIB). [The
snprintf library could even be included with GRASS to make it transparent
to the end user], or else it could be specifed as an option to the
configure script (probably a better idea if it only applies to very few
platforms). Has anybody else had this problem and would it be as easy to
fix as what I have suggested?

Below is a list of the modules with the snprintf problem.

src/libes/dbmi/clients
src/display/d.db
src/display/d.profile
src/display/d.site.labels
src/display/d.vect.labels
src/display/d.what.db
src/display/d.what.vect
src/imagery/i.tape.tm.fast
src/mapdev/v.db.reclass
src/mapdev/v.in.mif
src/mapdev/v.in.shape
src/mapdev/v.mkgrid
src/mapdev/v.out.shape
src/mapdev/v.to.db
src/mapdev/v.transform
src/raster/r.in.shape
src/sites/s.in.dbf
src/sites/s.qcount
src/sites/s.to.rast
src/sites/s.to.vect
src.contrib/GMSL/NVIZ2.2

I found the following errors in addition to use of snprintf:

Compilation error in module: src/paint/p.vrml1.1 (ignored)
fixed by adding prototype void vrml_putline(int, FILE *, char *); at start
of vrml.c

Compilation error in module: src/sites/s.hull (ignored)
has some // c++ style comments which my compiler rejects; just needed to
change these to /* */

Compilation error in module: src.contrib/GMSL/NVIZ2.2 (ignored)
as well as the snprintf problem needed to remove newline between lines 232
and 233 in NVIZ2.2/src/nviz_int.c

And the following modules had errors I couldn't fix

Compilation error in module: src/mapdev/v.in.mif (ignored)

cc -I/indigo-disk2/grass/grass/src/include -g
-I/indigo-disk2/grass/doom.ee.qub.ac.uk/include -c lex.yy.c -o
OBJ.mips-sgi-irix6.2/lex.yy.o
cfe: Error: mif.l, line 572: Syntax Error
        {blank} |
        ------^
make: *** [OBJ.mips-sgi-irix6.2/lex.yy.o] Error 1

Compilation error in module: src/raster/r.fill.dir (ignored)

cc -I/indigo-disk2/grass/grass/src/include -g
-I/indigo-disk2/grass/doom.ee.qub.ac.uk/include -c wtrshed.c -o
OBJ.mips-sgi-irix6.2/wtrshed.o
cfe: Error: wtrshed.c, line 67: missing size for array 'dir'
    struct whereandwhat dir[mxbuf];
-----------------------^
cfe: Error: wtrshed.c, line 67: storage size for 'dir' isn't known
    struct whereandwhat dir[mxbuf];
-----------------------^
cfe: Error: wtrshed.c, line 67: Invalid constant expression.
    struct whereandwhat dir[mxbuf];
---------------------------^
cfe: Error: wtrshed.c, line 68: missing size for array 'bas'
    struct whereandwhat bas[mxbuf];
-----------------------^
cfe: Error: wtrshed.c, line 68: storage size for 'bas' isn't known
    struct whereandwhat bas[mxbuf];
-----------------------^
make: *** [OBJ.mips-sgi-irix6.2/wtrshed.o] Error 1

Compilation error in module: src/raster/r.in.gdal (ignored)

cc -L/indigo-disk2/grass/grass/src/libes/LIB.mips-sgi-irix6.2
-L/indigo-disk2/grass/doom.ee.qub.ac.uk/lib -o
/indigo-disk2/grass/grass/dist.mips-sgi-irix6.2/etc/bin/cmd/r.in.gdal
OBJ.mips-sgi-irix6.2/main.o OBJ.mips-sgi-irix6.2/gbgetsymbol.o
OBJ.mips-sgi-irix6.2/gdalbridge.o OBJ.mips-sgi-irix6.2/make_loc.o \
         -lgis -lI -lproj -lm -lz
ld: ERROR 33: Unresolved text symbol "GBGetSymbol" -- 1st referenced by
OBJ.mips-sgi-irix6.2/gdalbridge.o.
ld: INFO 152: Output file removed because of error.
make: ***
[/indigo-disk2/grass/grass/dist.mips-sgi-irix6.2/etc/bin/cmd/r.in.gdal]
Error 1

I hope this information may be of some use to somebody

Paul

Paul Kelly wrote:

Below is a list of the modules with the snprintf problem.

Paul, etc,

I would suggest that instead of Paul's suggestion, that we conditionally
compile in a GRASS version of snprintf() if the system does not provide one
and put it in libgis.a. The configure script should check for the
availability.

I don't have an IRIX system so I can't easily do the change, but if someone
else is willing to check it after I have done the work, I would be willing
to incorporate the required changes.

Best regards,

--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam@pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | Geospatial Programmer for Rent

Hello Frank
That sounds like a good idea. I've seen mentioned in lots of other places
the existence of GRASS versions of functions to replace those which were
non-existent or buggy on various systems. I would certainly be able and
willing to test it. For your information the snprintf I am using, I got
from http://www.ijs.si/software/snprintf/

Thank you

Paul

On Tue, 23 Apr 2002, Frank Warmerdam wrote:

Paul, etc,

I would suggest that instead of Paul's suggestion, that we conditionally
compile in a GRASS version of snprintf() if the system does not provide one
and put it in libgis.a. The configure script should check for the
availability.

I don't have an IRIX system so I can't easily do the change, but if someone
else is willing to check it after I have done the work, I would be willing
to incorporate the required changes.

Paul Kelly wrote:

Hello
I am running GRASS on two slightly out-of-date IRIX installations (6.2 and
6.4---nothing I can do about this!) and everytime I update our GRASS
installation it seems even more modules are failing due to the snprintf
function being used in them. I don't know that much about libraries but it
is not in the standard ones that come with IRIX.

snprintf() isn't part of the original C89 specification. AFAICT, it
originated in BSD 4.4; it is part of the Single Unix Specification,
and C9X, but neither of those are sufficiently widespread to impose as
a requirement.

This works fine but it is very tedious. I was wondering could the
makefiles be changed for those modules that include snprintf in their code
(list is below) to perhaps have another variable specifically referring to
a 3rd party snprintf library at the end of the line after ($XDRLIB). [The
snprintf library could even be included with GRASS to make it transparent
to the end user], or else it could be specifed as an option to the
configure script (probably a better idea if it only applies to very few
platforms). Has anybody else had this problem and would it be as easy to
fix as what I have suggested?

It's debatable whether we should actually be using snprintf() in any
case. Even on platforms which do implement it, there are differences
in the return value when the string is truncated.

And unless the code actually checks the return value, using snprintf()
instead of sprintf() may cause the program to behave incorrectly, but
without indicating an error. In that regard, using a third-party
snprintf() library may not provide a significant benefit over using a
stub which simply discards the size argument before calling
vsprintf().

Many of the cases where sprintf() is used should be probably replaced
with multiple calls to strcat(), using a dynamically allocated buffer
whose size is actually computed to ensure that no overflow occurs.

In any case, GRASS is absolutely littered with code which uses
fixed-size buffers without any bounds checking, so using snprintf() in
a few specific cases is a drop in the ocean.

I found the following errors in addition to use of snprintf:

Compilation error in module: src/paint/p.vrml1.1 (ignored)
fixed by adding prototype void vrml_putline(int, FILE *, char *); at start
of vrml.c

There are a number of problems with p.vrml1.1; I'll do a general
clean-up if it's going to stay.

Compilation error in module: src/sites/s.hull (ignored)
has some // c++ style comments which my compiler rejects; just needed to
change these to /* */

I'll fix that.

Compilation error in module: src.contrib/GMSL/NVIZ2.2 (ignored)
as well as the snprintf problem needed to remove newline between lines 232
and 233 in NVIZ2.2/src/nviz_int.c

That's the broken string literal:

  fprintf(stderr, "ERROR: Number of elevation files does
  not match number of colors files\n");

right? I'll fix that.

And the following modules had errors I couldn't fix

Compilation error in module: src/mapdev/v.in.mif (ignored)

cc -I/indigo-disk2/grass/grass/src/include -g
-I/indigo-disk2/grass/doom.ee.qub.ac.uk/include -c lex.yy.c -o
OBJ.mips-sgi-irix6.2/lex.yy.o
cfe: Error: mif.l, line 572: Syntax Error
        {blank} |
        ------^
make: *** [OBJ.mips-sgi-irix6.2/lex.yy.o] Error 1

I'm not sure what it's complaining about here; if you can find out
exactly what the error is, I'll commit the fix.

Compilation error in module: src/raster/r.fill.dir (ignored)

cc -I/indigo-disk2/grass/grass/src/include -g
-I/indigo-disk2/grass/doom.ee.qub.ac.uk/include -c wtrshed.c -o
OBJ.mips-sgi-irix6.2/wtrshed.o
cfe: Error: wtrshed.c, line 67: missing size for array 'dir'
    struct whereandwhat dir[mxbuf];
-----------------------^
cfe: Error: wtrshed.c, line 67: storage size for 'dir' isn't known
    struct whereandwhat dir[mxbuf];
-----------------------^
cfe: Error: wtrshed.c, line 67: Invalid constant expression.
    struct whereandwhat dir[mxbuf];
---------------------------^
cfe: Error: wtrshed.c, line 68: missing size for array 'bas'
    struct whereandwhat bas[mxbuf];
-----------------------^
cfe: Error: wtrshed.c, line 68: storage size for 'bas' isn't known
    struct whereandwhat bas[mxbuf];
-----------------------^
make: *** [OBJ.mips-sgi-irix6.2/wtrshed.o] Error 1

I don't understand the "storage size" errors; "struct whereandwhat" is
defined at the top of that file. But the use of "mxbuf" is a gcc-ism,
which I'll fix (by using malloc()).

Compilation error in module: src/raster/r.in.gdal (ignored)

cc -L/indigo-disk2/grass/grass/src/libes/LIB.mips-sgi-irix6.2
-L/indigo-disk2/grass/doom.ee.qub.ac.uk/lib -o
/indigo-disk2/grass/grass/dist.mips-sgi-irix6.2/etc/bin/cmd/r.in.gdal
OBJ.mips-sgi-irix6.2/main.o OBJ.mips-sgi-irix6.2/gbgetsymbol.o
OBJ.mips-sgi-irix6.2/gdalbridge.o OBJ.mips-sgi-irix6.2/make_loc.o \
         -lgis -lI -lproj -lm -lz
ld: ERROR 33: Unresolved text symbol "GBGetSymbol" -- 1st referenced by
OBJ.mips-sgi-irix6.2/gdalbridge.o.
ld: INFO 152: Output file removed because of error.

This suggests that neither

  #if defined(__unix__)
nor
  #ifdef _WIN32

are true. Can you provide a suitable symbol which could be tested?

--
Glynn Clements <glynn.clements@virgin.net>

I'm probably the guilty party for most of those snprintf calls. Sorry.
If I had to guess, I'd say better than 50% of the time, the call
probably is supliferous (where sprintf would really be fine) and
probably near 100% of the time the return value is not checked (so the
benefit is lost). I'll try to go through the sources and replace all
occurrence tonight (-800).

It'd be nice to have a function that was a combination of sprintf and
strdup: char * G_strdupf(const char *fmt, ...); ??
String handling in C is such a PITA...

--
Eric G. Miller <egm2@jps.net>

I think I've fixed all the occurrences of snprintf that I had a hand in
introducing. Still remaining (at least):

* src/display/d.db main.c
* src/display/d.what.db attr.c main.c
* src/display/d.what.vect attr.c
* src/imagery/i.tape.tm.fast inter/ask_title.c
* src/libes/dbmi/drivers/odbc cursor.c db.c describe.c error.c execute.c
select.c table.c
* src/libes/dbmi/lib dbmscap.c reclass.c
* src/libes/gis user_config.c (this is mine, but should be unused...)
* src/mapdev/v.in.mif main.c write_lines.c
* src/mapdev/v.in.shape lines.c vmap_import.c test/arctest1.c
* src/mapdev/v.mkgrid grid_atts.c
* src/mapdev/v.to.db update.c
* src/mapdev/v.transform main.c
* src/raster/r.in.shape main.c
* src/sites/s.in.dbf dump.c

I didn't grep any of the other "src" directories...

I'll try and look at some of these tomorrow, probably starting with
v.mkgrid, v.transform, d.what.vect, and i.tape.tm.fast. If someone
wants to look at some of the others, be my guest.

BTW: Are v.in.mif, v.in.shape, r.in.shape and s.in.dbf working
acceptably? I know they've been problematic in the past.

--
Eric G. Miller <egm2@jps.net>

On Wed, Apr 24, 2002 at 12:37:58AM -0700, Eric G. Miller wrote:

I think I've fixed all the occurrences of snprintf that I had a hand in
introducing.

If you improved the code while doing so, it is fine.
I believe that we need to have configure handle to add a replacement
function, if snprintf is not available for the system.

This seems reasonable as snprintf is standard for quite some time.

Even when its just a drop, I think that reducing the chance for
buffer overflows is always a good thing.

For everybody else: Becareful about grass checkins,
as Glynn will create the release branch soon.

On Apr 23, Eric G. Miller wrote:
> It'd be nice to have a function that was a combination of sprintf and
> strdup: char * G_strdupf(const char *fmt, ...); ??

Absolutely.

Some systems have an asprintf which is printf with allocation. It's
even harder to find than snprintf though. :frowning:

Instead, if you do have snprintf, (one that is capable of returning
indication of whether N was large enough)., then it's pretty easy to
make a function just like what you want. In other projects, I've been
happily using such a function that I snitched from the printf(3) page
on a Linux system. I rarely think about string lengths anymore.

I'll include the function I'm using for reference, (but it doesn't
seem like GRASS could use anything like this yet).

> String handling in C is such a PITA...

Tell me about it.

-Carl

PS. Here's the code I use regularly, (I actually pass in the address
of the char * of interest rather than returning it as you propose).

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>

int sprintf_alloc(char **str, const char *fmt, ...)
{
    int ret;
    va_list ap;

    va_start(ap, fmt);
    ret = va_sprintf_alloc(str, fmt, ap);
    va_end(ap);

    return ret;
}

/* ripped more or less straight out of PRINTF(3) */
int va_sprintf_alloc(char **str, const char *fmt, va_list ap)
{
    char *new_str;
    /* Guess we need no more than 100 bytes. */
    int n, size = 100;

    if ((*str = malloc (size)) == NULL)
        return -1;
    while (1) {
        /* Try to print in the allocated space. */
        n = vsnprintf (*str, size, fmt, ap);
        /* If that worked, return the size. */
        if (n > -1 && n < size)
            return n;
        /* Else try again with more space. */
        if (n > -1) /* glibc 2.1 */
            size = n+1; /* precisely what is needed */
        else /* glibc 2.0 */
            size *= 2; /* twice the old size */
        new_str = realloc(*str, size);
        if (new_str == NULL) {
            free(*str);
            *str = NULL;
            return -1;
        }
        *str = new_str;
    }
}

--
Carl Worth
USC Information Sciences Institute cworth@east.isi.edu
3811 N. Fairfax Dr. #200, Arlington VA 22203 703-812-3725

On Wed, Apr 24, 2002 at 03:03:14PM +0200, Bernhard Reiter wrote:

On Wed, Apr 24, 2002 at 12:37:58AM -0700, Eric G. Miller wrote:
> I think I've fixed all the occurrences of snprintf that I had a hand in
> introducing.

If you improved the code while doing so, it is fine.
I believe that we need to have configure handle to add a replacement
function, if snprintf is not available for the system.

I think most are better for it. In most cases, if it wasn't already the
case, I looked at ensuring buffers are sized correclty (i.e. use
dynamic allocation).

This seems reasonable as snprintf is standard for quite some time.

Yes, but I see the merit of trying to keep the code based on C89/90.
At least for a couple more years.

Even when its just a drop, I think that reducing the chance for
buffer overflows is always a good thing.

Yea, buffer overflows are never desirable :wink:

For everybody else: Becareful about grass checkins,
as Glynn will create the release branch soon.

--
Eric G. Miller <egm2@jps.net>

I've now had a chance to go over this again:

Glynn Clements wrote:

---snip--- various obvious bugs fixed, thank you

> And the following modules had errors I couldn't fix
>
> Compilation error in module: src/mapdev/v.in.mif (ignored)
>
> cc -I/indigo-disk2/grass/grass/src/include -g
> -I/indigo-disk2/grass/doom.ee.qub.ac.uk/include -c lex.yy.c -o
> OBJ.mips-sgi-irix6.2/lex.yy.o
> cfe: Error: mif.l, line 572: Syntax Error
> {blank} |
> ------^
> make: *** [OBJ.mips-sgi-irix6.2/lex.yy.o] Error 1

I'm not sure what it's complaining about here; if you can find out
exactly what the error is, I'll commit the fix.

Still don't have a clue about this, sorry

> Compilation error in module: src/raster/r.fill.dir (ignored)
>
> cc -I/indigo-disk2/grass/grass/src/include -g
> -I/indigo-disk2/grass/doom.ee.qub.ac.uk/include -c wtrshed.c -o
> OBJ.mips-sgi-irix6.2/wtrshed.o
> cfe: Error: wtrshed.c, line 67: missing size for array 'dir'
> struct whereandwhat dir[mxbuf];
> -----------------------^
> cfe: Error: wtrshed.c, line 67: storage size for 'dir' isn't known
> struct whereandwhat dir[mxbuf];
> -----------------------^
> cfe: Error: wtrshed.c, line 67: Invalid constant expression.
> struct whereandwhat dir[mxbuf];
> ---------------------------^
> cfe: Error: wtrshed.c, line 68: missing size for array 'bas'
> struct whereandwhat bas[mxbuf];
> -----------------------^
> cfe: Error: wtrshed.c, line 68: storage size for 'bas' isn't known
> struct whereandwhat bas[mxbuf];
> -----------------------^
> make: *** [OBJ.mips-sgi-irix6.2/wtrshed.o] Error 1

I don't understand the "storage size" errors; "struct whereandwhat" is
defined at the top of that file. But the use of "mxbuf" is a gcc-ism,
which I'll fix (by using malloc()).

Yes, that fixed it. After wtrshed.c compiled all right I found a
similar problem in ppupdate.c in the same directory, which I fixed
as follows using the same syntax as you:

39c39,41
< struct links list[nbasins];
---

   struct links *list;

   list = G_malloc(nbasins * sizeof(struct links));

After that r.fill.dir compiled in its entirety.

> Compilation error in module: src/raster/r.in.gdal (ignored)
>
> cc -L/indigo-disk2/grass/grass/src/libes/LIB.mips-sgi-irix6.2
> -L/indigo-disk2/grass/doom.ee.qub.ac.uk/lib -o
> /indigo-disk2/grass/grass/dist.mips-sgi-irix6.2/etc/bin/cmd/r.in.gdal
> OBJ.mips-sgi-irix6.2/main.o OBJ.mips-sgi-irix6.2/gbgetsymbol.o
> OBJ.mips-sgi-irix6.2/gdalbridge.o OBJ.mips-sgi-irix6.2/make_loc.o \
> -lgis -lI -lproj -lm -lz
> ld: ERROR 33: Unresolved text symbol "GBGetSymbol" -- 1st referenced by
> OBJ.mips-sgi-irix6.2/gdalbridge.o.
> ld: INFO 152: Output file removed because of error.

This suggests that neither

        #if defined(__unix__)
nor
        #ifdef _WIN32

are true. Can you provide a suitable symbol which could be tested?

I made the following change to gbgetsymbol.c to get it to work

53c53
< #if defined(__unix__)
---

#if defined(__unix)

Extract from IRIX cc man page:

COMMAND LINE OPTIONS (all three ABIs).
These options are specific to cc and valid in all three ABIs.

-ansi
     (ANSI/ISO C only) Pure ANSI/ISO C. The symbols _MIPS_FPSET,
     _MIPS_ISA, _MIPS_SIM, _MIPS_SZINT, _MIPS_SZLONG, _MIPS_SZPTR,
     _LANGUAGE_C, __sgi, __unix, __host_mips, _MODERN_C, __DSO__,
     _SYSTYPE_SVR4, __mips, _MIPSEB, __STDC__, and _CFE are defined to
     the preprocessor. The symbol __ANSI_CPP__ is defined, and ANSI/ISO
     trigraphs are processed, by default. NOTE: when compiling in pure
     ANSI/ISO mode ( -ansi) several standard UNIX symbols (e.g. environ,
     end) may only be referenced by their ANSI/ISO-compliant counterparts
     (e.g., _environ, _end). The type 'long long' is allowed, but
     results in a warning, in -ansi mode. To take advantage of this type
     in libraries that refer to __int64_t and __uint64_t the user must
     define the macro __LONGLONG on the command line; otherwise,
     __int64_t and __uint64_t will be defined as structs. See the ANSI C
     Transition Guide for more information.

-cckr
     The traditional K&R/Version7 C with SGI (and some ANSI/ISO-C-like)
     extensions, including function prototypes, void, void*. The symbols
     _MIPS_FPSET, _MIPS_ISA, _MIPS_SIM, _MIPS_SZINT, _MIPS_SZLONG,
     _MIPS_SZPTR, __EXTENSIONS__, LANGUAGE_C, _LANGUAGE_C,
     __INLINE_INTRINSICS, sgi, __sgi, unix, mips, host_mips, __unix,
     __host_mips, _SVR4_SOURCE, _MODERN_C, _SGI_SOURCE, __DSO__,
     SYSTYPE_SVR4, _SYSTYPE_SVR4, _LONGLONG, __mips, _MIPSEB, MIPSEB, and
     _CFE are defined to the preprocessor.

Hopefully this is enough information for you to get something versatile
working on all systems.

There was also a compile error in src/raster/r.le, which I forgot to
mention in my earlier e-mail. It involved strings broken over multiple
lines again, which I fixed by putting backslashes at the end of the
broken lines. The two files affected were src/raster/r.le/r.le.patch/input.c
and src/raster/r.le/r.le.pixel/input.c and the diff files for the changes
are as follows

src/raster/r.le/r.le.patch/input.c
101c101
< sampling_method->description = "Sampling method (choose only 1 method):
---

   sampling_method->description = "Sampling method (choose only 1 method):\

116,118c116,118
< att->description = "a1 = mn. pixel att. \t\ta2 = s.d. pixel att.
< \ta3 = mn. patch att. \t\ta4 = s.d. patch att.
< \ta5 = cover by gp \t\ta6 = density by gp
---

   att->description = "a1 = mn. pixel att. \t\ta2 = s.d. pixel att.\
   \ta3 = mn. patch att. \t\ta4 = s.d. patch att.\
   \ta5 = cover by gp \t\ta6 = density by gp\

127,129c127,129
< size->description = "s1 = mn. patch size\t\ts2 = s.d. patch size
< \ts3 = mn. patch size by gp\ts4 = s.d. patch size by gp
< \ts5 = no. by size class\t\ts6 = no. by size class by gp
---

   size->description = "s1 = mn. patch size\t\ts2 = s.d. patch size\
   \ts3 = mn. patch size by gp\ts4 = s.d. patch size by gp \
   \ts5 = no. by size class\t\ts6 = no. by size class by gp\

144,148c144,148
< core->description = "Core size measures (required if co1 was specified):
< \tc1 = mn. core size\t\tc2 = s.d. core size
< \tc3 = mn. edge size\t\tc4 = s.d. edge size
< \tc5 = mn. core size by gp\tc6 = s.d. core size by gp
< \tc7 = mn. edge size by gp\tc8 = s.d. edge size by gp
---

   core->description = "Core size measures (required if co1 was specified):\
   \tc1 = mn. core size\t\tc2 = s.d. core size\
   \tc3 = mn. edge size\t\tc4 = s.d. edge size\
   \tc5 = mn. core size by gp\tc6 = s.d. core size by gp\
   \tc7 = mn. edge size by gp\tc8 = s.d. edge size by gp\

157c157
< shape->description = "Shape index (choose only 1 index):
---

   shape->description = "Shape index (choose only 1 index):\

165,167c165,167
< shape_m->description = "Shape measures (required if sh1 was specified):
< \th1 = mn. patch shape\t\th2 = s.d. patch shape
< \th3 = mn. patch shape by gp\th4 = s.d. patch shape by gp
---

   shape_m->description = "Shape measures (required if sh1 was specified):\
   \th1 = mn. patch shape\t\th2 = s.d. patch shape\
   \th3 = mn. patch shape by gp\th4 = s.d. patch shape by gp\

176c176
< boundary->description = "n1 = mn. twist number n2 = s.d. twist number
---

   boundary->description = "n1 = mn. twist number n2 = s.d. twist number\

185,186c185,186
< perimeter->description = "p1 = sum of perims.\t\tp4 = sum of perims. by gp
< \tp2 = mn. per.\t\t\tp5 = mn. per. by gp
---

   perimeter->description = "p1 = sum of perims.\t\tp4 = sum of perims. by gp\
   \tp2 = mn. per.\t\t\tp5 = mn. per. by gp\

195c195
< out->description = "Name of output file for individual patch measures, when sam=w,u,r;
---

   out->description = "Name of output file for individual patch measures, when sam=w,u,r;\

src/raster/r.le/r.le.pixel/input.c
82c82
< sampling_method->description = "Sampling method (choose only 1 method):
---

   sampling_method->description = "Sampling method (choose only 1 method):\

97c97
< att->description = "b1 = mn. pixel att. b2 = s.d. pixel att.
---

   att->description = "b1 = mn. pixel att. b2 = s.d. pixel att.\

114,115c114,115
< method_code->description = "Texture method (choose only 1 method):
< \tm1 = 2N-H m2 = 2N-45 m3 = 2N-V m4 = 2N-135
---

   method_code->description = "Texture method (choose only 1 method):\
   \tm1 = 2N-H m2 = 2N-45 m3 = 2N-V m4 = 2N-135\

124,125c124,125
< measure_code->description = "Texture measures (required if te1 was specified):
< \tt1 = contagion t2 = ang. sec. mom. t3 = inv. diff. mom.
---

   measure_code->description = "Texture measures (required if te1 was specified):\
   \tt1 = contagion t2 = ang. sec. mom. t3 = inv. diff. mom.\

134c134
< juxtaposition->description = "Juxtaposition measures (weight file in r.le.para needed):
---

   juxtaposition->description = "Juxtaposition measures (weight file in r.le.para needed):\

So if all the snprintf() calls have been removed, v.in.mif
is now the only module not compiling on IRIX 6.2 (out
of those enabled in src/CMD/lists/GRASS of course). My
next big challenge is to get SG3d working with GRASS 5 (I
currently only have the non-floating point version working
with GRASS 4.3).

Paul Kelly

Paul Kelly wrote:

> > And the following modules had errors I couldn't fix
> >
> > Compilation error in module: src/mapdev/v.in.mif (ignored)
> >
> > cc -I/indigo-disk2/grass/grass/src/include -g
> > -I/indigo-disk2/grass/doom.ee.qub.ac.uk/include -c lex.yy.c -o
> > OBJ.mips-sgi-irix6.2/lex.yy.o
> > cfe: Error: mif.l, line 572: Syntax Error
> > {blank} |
> > ------^
> > make: *** [OBJ.mips-sgi-irix6.2/lex.yy.o] Error 1
>
> I'm not sure what it's complaining about here; if you can find out
> exactly what the error is, I'll commit the fix.

Still don't have a clue about this, sorry

Try changing the lines:

<*>{whitespace} |
  {blank} |
    {end} ;

to:

<*>{whitespace} |
<*>{blank} |
<*>{end} ;

> > Compilation error in module: src/raster/r.fill.dir (ignored)
> >
> > cc -I/indigo-disk2/grass/grass/src/include -g
> > -I/indigo-disk2/grass/doom.ee.qub.ac.uk/include -c wtrshed.c -o
> > OBJ.mips-sgi-irix6.2/wtrshed.o
> > cfe: Error: wtrshed.c, line 67: missing size for array 'dir'
> > struct whereandwhat dir[mxbuf];
> > -----------------------^
> > cfe: Error: wtrshed.c, line 67: storage size for 'dir' isn't known
> > struct whereandwhat dir[mxbuf];
> > -----------------------^
> > cfe: Error: wtrshed.c, line 67: Invalid constant expression.
> > struct whereandwhat dir[mxbuf];
> > ---------------------------^
> > cfe: Error: wtrshed.c, line 68: missing size for array 'bas'
> > struct whereandwhat bas[mxbuf];
> > -----------------------^
> > cfe: Error: wtrshed.c, line 68: storage size for 'bas' isn't known
> > struct whereandwhat bas[mxbuf];
> > -----------------------^
> > make: *** [OBJ.mips-sgi-irix6.2/wtrshed.o] Error 1
>
> I don't understand the "storage size" errors; "struct whereandwhat" is
> defined at the top of that file. But the use of "mxbuf" is a gcc-ism,
> which I'll fix (by using malloc()).
>

Yes, that fixed it. After wtrshed.c compiled all right I found a
similar problem in ppupdate.c in the same directory, which I fixed
as follows using the same syntax as you:

OK; I've fixed that.

> > Compilation error in module: src/raster/r.in.gdal (ignored)
> >
> > cc -L/indigo-disk2/grass/grass/src/libes/LIB.mips-sgi-irix6.2
> > -L/indigo-disk2/grass/doom.ee.qub.ac.uk/lib -o
> > /indigo-disk2/grass/grass/dist.mips-sgi-irix6.2/etc/bin/cmd/r.in.gdal
> > OBJ.mips-sgi-irix6.2/main.o OBJ.mips-sgi-irix6.2/gbgetsymbol.o
> > OBJ.mips-sgi-irix6.2/gdalbridge.o OBJ.mips-sgi-irix6.2/make_loc.o \
> > -lgis -lI -lproj -lm -lz
> > ld: ERROR 33: Unresolved text symbol "GBGetSymbol" -- 1st referenced by
> > OBJ.mips-sgi-irix6.2/gdalbridge.o.
> > ld: INFO 152: Output file removed because of error.
>
> This suggests that neither
>
> #if defined(__unix__)
> nor
> #ifdef _WIN32
>
> are true. Can you provide a suitable symbol which could be tested?

I made the following change to gbgetsymbol.c to get it to work

53c53
< #if defined(__unix__)
---
> #if defined(__unix)

OK; gcc defines both __unix__ and __unix, so I'll use the latter.

There was also a compile error in src/raster/r.le, which I forgot to
mention in my earlier e-mail. It involved strings broken over multiple
lines again, which I fixed by putting backslashes at the end of the
broken lines.

That will allow the file to compile, but it will mess up the output of
e.g. "r.le.patch help". Instead, I've used e.g.:

   sampling_method->description = "Sampling method (choose only 1 method): \n"
   "\tw = whole map u = units m = moving window r = regions";

The two files affected were src/raster/r.le/r.le.patch/input.c
and src/raster/r.le/r.le.pixel/input.c and the diff files for the changes
are as follows

I've fixed those two files.

--
Glynn Clements <glynn.clements@virgin.net>

On Fri, Apr 26, 2002 at 03:26:19PM +0100, Paul Kelly wrote:

> > Compilation error in module: src/raster/r.in.gdal (ignored)
> >
> > cc -L/indigo-disk2/grass/grass/src/libes/LIB.mips-sgi-irix6.2
> > -L/indigo-disk2/grass/doom.ee.qub.ac.uk/lib -o
> > /indigo-disk2/grass/grass/dist.mips-sgi-irix6.2/etc/bin/cmd/r.in.gdal
> > OBJ.mips-sgi-irix6.2/main.o OBJ.mips-sgi-irix6.2/gbgetsymbol.o
> > OBJ.mips-sgi-irix6.2/gdalbridge.o OBJ.mips-sgi-irix6.2/make_loc.o \
> > -lgis -lI -lproj -lm -lz
> > ld: ERROR 33: Unresolved text symbol "GBGetSymbol" -- 1st referenced by
> > OBJ.mips-sgi-irix6.2/gdalbridge.o.
> > ld: INFO 152: Output file removed because of error.
>
> This suggests that neither
>
> #if defined(__unix__)
> nor
> #ifdef _WIN32
>
> are true. Can you provide a suitable symbol which could be tested?

I made the following change to gbgetsymbol.c to get it to work

53c53
< #if defined(__unix__)
---
> #if defined(__unix)

Extract from IRIX cc man page:

Problem is, these symbols are compiler specific. It is definitely
__unix__ for gcc, but all __<foo> symbols are reserved for the
implementation (i.e. platform specific).

There was also a compile error in src/raster/r.le, which I forgot to
mention in my earlier e-mail. It involved strings broken over multiple
lines again, which I fixed by putting backslashes at the end of the
broken lines. The two files affected were src/raster/r.le/r.le.patch/input.c
and src/raster/r.le/r.le.pixel/input.c and the diff files for the changes
are as follows

[snip]

Hmm. Those still seem wrong. I'm guessing what is wanted is:

foo = "Some line of text.\n"\
"\tAnother line of text with a leading tab character.\n";

Quotes should not be broken across lines. It is not the right way to
embed newlines (this isn't Perl or sh ...) since the compiler will
probably strip those newlines when parsing the code.

So if all the snprintf() calls have been removed, v.in.mif
is now the only module not compiling on IRIX 6.2 (out
of those enabled in src/CMD/lists/GRASS of course). My
next big challenge is to get SG3d working with GRASS 5 (I
currently only have the non-floating point version working
with GRASS 4.3).

There're still some instances of snprintf()...

--
Eric G. Miller <egm2@jps.net>

Eric G. Miller wrote:

> I made the following change to gbgetsymbol.c to get it to work
>
> 53c53
> < #if defined(__unix__)
> ---
> > #if defined(__unix)
>
> Extract from IRIX cc man page:

Problem is, these symbols are compiler specific. It is definitely
__unix__ for gcc, but all __<foo> symbols are reserved for the
implementation (i.e. platform specific).

AFAIK, gcc defines both. To be on the safe side, I've changed the
check to:

  #if defined(__unix) || defined(__unix__)

> There was also a compile error in src/raster/r.le, which I forgot to
> mention in my earlier e-mail. It involved strings broken over multiple
> lines again, which I fixed by putting backslashes at the end of the
> broken lines. The two files affected were src/raster/r.le/r.le.patch/input.c
> and src/raster/r.le/r.le.pixel/input.c and the diff files for the changes
> are as follows

[snip]

Hmm. Those still seem wrong. I'm guessing what is wanted is:

foo = "Some line of text.\n"\
"\tAnother line of text with a leading tab character.\n";

Yep, although you don't need the backslash.

Quotes should not be broken across lines. It is not the right way to
embed newlines (this isn't Perl or sh ...) since the compiler will
probably strip those newlines when parsing the code.

Yep.

> So if all the snprintf() calls have been removed, v.in.mif
> is now the only module not compiling on IRIX 6.2 (out
> of those enabled in src/CMD/lists/GRASS of course). My
> next big challenge is to get SG3d working with GRASS 5 (I
> currently only have the non-floating point version working
> with GRASS 4.3).

There're still some instances of snprintf()...

Should I add a stub implementation to libgis?

In any case, I'll add a configure check.

--
Glynn Clements <glynn.clements@virgin.net>

I've got a sort of cheat for asprintf. We can't use vsnprintf for the
same reason we can't use snprintf :wink: Comments welcome (I'm not too
sure tmpfile() is safe. It's apparently an anonymous file on my
machine, as nothing shows up in /tmp or the current directory...)

---------------------- <snip> ----------------------------------
/* BEGIN HEADER */
#ifndef G_ASPRINTF_H
#define G_ASPRINTF_H

#if !defined _GNU_SOURCE
int
G_asprintf (char ** /* out */, const char * /* fmt */, ...);
#else
#if defined __STDC__VERSION__ + 0 >= 199900L
#define G_asprintf(pp,fmt,...) asprintf(pp, fmt, __VA_ARGS__)
#else
#define G_asprintf(pp,fmt,args...) asprintf(pp, fmt, args)
#endif /* __STDC_VERSION__ of variadic macro */
#endif /* older GNU version of variadic macro */

#endif
/* END HEADER */

/* BEGIN SOURCE */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <assert.h>
#include "g_asprintf.h"

/* Make sure the macro doesn't impact our function, if it is defined */
#undef G_asprintf

/* We cheat by printing to a tempfile via vfprintf and then reading it
* back in. Not the most efficient way, probably and tmpfile() is
* not safe?
*/
int
G_asprintf (char **out, const char *fmt, ...)
{
    va_list ap;
    int ret_status = EOF;
    int count = 0;
    FILE *fp = NULL;
    char *work = NULL;
    
    assert (out != NULL && fmt != NULL);
    
    va_start (ap, fmt);
    if ((fp = tmpfile()))
    {
        count = vfprintf (fp, fmt, ap);
        if (count >= 0)
        {
            work = calloc (count + 1, 1);
            if (work != NULL)
            {
                rewind (fp);
                ret_status = fread (work, 1, count, fp);
                if (ret_status != count)
                {
                    ret_status = EOF;
                    free (work);
                    work = NULL;
                }
            }
        }
        fclose (fp);
    }
    va_end (ap);
    *out = work;
    return ret_status;
}
/* END SOURCE */
----------------------------- <snip> ------------------------------
--
Eric G. Miller <egm2@jps.net>

Eric G. Miller writes:
> I've got a sort of cheat for asprintf. We can't use vsnprintf for the
> same reason we can't use snprintf :wink:

Why not include gnprintf out of the gtk glib package? There are two
reasonable ways to achieve portability in my experience: include your
own version of the software you need (which is what qmail does) or
rely on a library which is portable (which is what the gimp does).
Trying to rely on vendor C libraries is fraught with peril.

--
-russ nelson http://russnelson.com | Okay, enough is enough!
Crynwr sells support for free software | PGPok | Can we PLEASE all stop
521 Pleasant Valley Rd. | +1 315 268 1925 voice | using insecure Microsoft
Potsdam, NY 13676-3213 | +1 315 268 9201 FAX | email products???

On May 2, Eric G. Miller wrote:
> Comments welcome (I'm not too
> sure tmpfile() is safe. It's apparently an anonymous file on my
> machine, as nothing shows up in /tmp or the current directory...)

tmpfile may be implemented by opening the file, then immediately
unlinking it. The process that retains the open file handle can
continue to use it until that file handle is closed, (at which point
the file is then actually removed). This could explain why you never
actually see any file created.

This is a great way to ensure that the file always gets removed
without the programmer having to do anything extra to say that the
file is no longer needed. Even if the program crashes, all open file
handles will be closed so the cleanup always occurs.

Incidentally, there was some recent discussion about getting GRASS
temporary files cleaned up more consistently. Moving to tmpfile where
possible might be just the thing to do.

-Carl

--
Carl Worth
USC Information Sciences Institute cworth@east.isi.edu
3811 N. Fairfax Dr. #200, Arlington VA 22203 703-812-3725