Thread: NetBSD falling foul of SAC's toupper/tolower macros

Started: 2008-09-30 21:15:19
Last activity: 2008-09-30 22:43:17
Topics: SAC Help
Kevin.Buckley@mcs.vuw.ac.nz
2008-09-30 21:15:19
Hi there,

I am sure this is a known issue but my searches turned up zilch
so, just in case ...

I came to build sac-101.2 on a NetBSD 4.99.58 platform with
gcc (GCC) 4.1.3 20080202 prerelease (NetBSD nb1 20070620), the
sac build being configured thus:

./configure --prefix=/local/scratch/kevin/sac-101.2

resulting in:

Compliation Options for sac (Seismic Analysis Code 101.2)

CFLAGS =
LDFLAGS =
LIBS = -lm -lcurses
Debug =
Optimization =
Database = off
Matlab = off
X11-buffer = on
X11-depth = on
X_LIBS = -L/usr/pkg/lib
X_CFLAGS = -I/usr/pkg/include
Readline = off
Editline = on
Install Base = /local/scratch/kevin/sac-101.2
System = (i386-unknown-netbsdelf4.99.58)


and saw this error:

gcc -DHAVE_CONFIG_H -I. -I. -I../inc -I/usr/pkg/include -I../inc
-I../libedit/include -c -o co/zgpmsg.o co/zgpmsg.c
In file included from /usr/pkg/include/readline/chardefs.h:26,
from /usr/pkg/include/readline/keymaps.h:36,
from /usr/pkg/include/readline/readline.h:38,
from co/zgpmsg.c:93:
/usr/include/ctype.h:71: error: expected identifier or '(' before 'int'
/usr/include/ctype.h:71: error: expected ')' before '?' token
/usr/include/ctype.h:72: error: expected identifier or '(' before 'int'
/usr/include/ctype.h:72: error: expected ')' before '?' token

this occurs because the toupper/tolower declarations in this system's
ctype.h

int tolower(int);
int toupper(int);

get mangled by the macro declaration in sac's

src/co/stdu.h

#ifndef CYGWIN
/* macro expansions */
#define tolower(c) ((c>='A' && c<='Z') ? (c+('a'-'A')) : c)
#define toupper(c) ((c>='a' && c<='z') ? (c-('a'-'A')) : c)
#endif /* CYGWIN */

as they are only protected by the CYGWIN define and so appear as:

int ((int>='A' && int<='Z') ? (int+('a'-'A')) : int);
int ((int>='a' && int<='z') ? (int-('a'-'A')) : int);


After removing the macro definitions, the code compiles OK.


--

Kevin M. Buckley Room: CO327
School of Mathematics, Statistics Phone: +64 4 463 5971
and Computer Science
Victoria University of Wellington
New Zealand


  • Hi Keven,

    I've reported the same problem a couple of weeks ago, and provided a patch.

    http://www.iris.washington.edu/pipermail/sac-dev/2008-September/000088.html

    This should be fixed in the next version.


    Best regards,

    --
    Kuang He
    Department of Physics
    University of Connecticut
    Storrs, CT 06269-3046

    Tel: +1.860.486.4919
    Web: http://www.phys.uconn.edu/~he/

    On Mon, Sep 29, 2008 at 9:15 PM, <Kevin.Buckley<at>mcs.vuw.ac.nz> wrote:
    Hi there,

    I am sure this is a known issue but my searches turned up zilch
    so, just in case ...

    I came to build sac-101.2 on a NetBSD 4.99.58 platform with
    gcc (GCC) 4.1.3 20080202 prerelease (NetBSD nb1 20070620), the
    sac build being configured thus:

    ./configure --prefix=/local/scratch/kevin/sac-101.2

    resulting in:

    Compliation Options for sac (Seismic Analysis Code 101.2)

    CFLAGS =
    LDFLAGS =
    LIBS = -lm -lcurses
    Debug =
    Optimization =
    Database = off
    Matlab = off
    X11-buffer = on
    X11-depth = on
    X_LIBS = -L/usr/pkg/lib
    X_CFLAGS = -I/usr/pkg/include
    Readline = off
    Editline = on
    Install Base = /local/scratch/kevin/sac-101.2
    System = (i386-unknown-netbsdelf4.99.58)


    and saw this error:

    gcc -DHAVE_CONFIG_H -I. -I. -I../inc -I/usr/pkg/include -I../inc
    -I../libedit/include -c -o co/zgpmsg.o co/zgpmsg.c
    In file included from /usr/pkg/include/readline/chardefs.h:26,
    from /usr/pkg/include/readline/keymaps.h:36,
    from /usr/pkg/include/readline/readline.h:38,
    from co/zgpmsg.c:93:
    /usr/include/ctype.h:71: error: expected identifier or '(' before 'int'
    /usr/include/ctype.h:71: error: expected ')' before '?' token
    /usr/include/ctype.h:72: error: expected identifier or '(' before 'int'
    /usr/include/ctype.h:72: error: expected ')' before '?' token

    this occurs because the toupper/tolower declarations in this system's
    ctype.h

    int tolower(int);
    int toupper(int);

    get mangled by the macro declaration in sac's

    src/co/stdu.h

    #ifndef CYGWIN
    /* macro expansions */
    #define tolower(c) ((c>='A' && c<='Z') ? (c+('a'-'A')) : c)
    #define toupper(c) ((c>='a' && c<='z') ? (c-('a'-'A')) : c)
    #endif /* CYGWIN */

    as they are only protected by the CYGWIN define and so appear as:

    int ((int>='A' && int<='Z') ? (int+('a'-'A')) : int);
    int ((int>='a' && int<='z') ? (int-('a'-'A')) : int);


    After removing the macro definitions, the code compiles OK.


    --

    Kevin M. Buckley Room: CO327
    School of Mathematics, Statistics Phone: +64 4 463 5971
    and Computer Science
    Victoria University of Wellington
    New Zealand

    _______________________________________________
    sac-help mailing list
    sac-help<at>iris.washington.edu
    http://www.iris.washington.edu/mailman/listinfo/sac-help


    • Kevin.Buckley@mcs.vuw.ac.nz
      2008-09-30 22:43:17
      Hello Kuang He

      I've reported the same problem a couple of weeks ago, and provided a
      patch.

      http://www.iris.washington.edu/pipermail/sac-dev/2008-September/000088.html

      I knew I wouldn't be the first to have seen this but didn't think it
      would be so recent.

      I wonder why my search did not throw your post up. I think I must have
      assumed it must be NetBSD specific (only recently started using that
      platform) so searched with the term NetBSD rather than just BSD.

      I don't think I had found sac-dev either ?


      This should be fixed in the next version.


      Sounds like the inclusion of <ctype.h> is the way to go, rather than
      removing the macros for those few systems that don't have the system
      calls.

      Thanks for the feedback,
      Kevin


15:17:12 v.22510d55