Thread: SAC 101.2 compilation error with readline (patch provided)

Started: 2008-09-09 03:18:12
Last activity: 2008-09-09 03:18:12
Topics: SAC Developers
Hi all,

I just got the source code of SAC 101.2 today, and found that if it is
configured with readline (), the compile process would halt at the
step of compiling src/co/zgpmsg.c (and later src/co/zgtmsg.c). The
error message is:

$ ./configure --enable-readline
$ make
....
gcc -DHAVE_CONFIG_H -I. -I. -I../inc -I../inc -c -o
co/zgpmsg.o co/zgpmsg.c
In file included from /usr/include/readline/chardefs.h:26,
from /usr/include/readline/keymaps.h:36,
from /usr/include/readline/readline.h:39,
from co/zgpmsg.c:93:
/usr/include/ctype.h:116: error: expected identifier or '(' before 'int'
/usr/include/ctype.h:116: error: expected ')' before '?' token
/usr/include/ctype.h:119: error: expected identifier or '(' before 'int'
/usr/include/ctype.h:119: error: expected ')' before '?' token
make[1]: *** [co/zgpmsg.o] Error 1
make[1]: Leaving directory `/home/icrazy/tt/sac-101.2/src'
make: *** [all-recursive] Error 1

After spending some time with it, I found an easy way to illustrate
the problem to you. I'll create a test program, with the two culprit
lines of code extracted from co/zgpmsg.c .

$ cd ~/src/sac-101.2
$ cat src/co/tt.c
#include "stdu.h"
#include <readline/readline.h>

$ gcc -DHAVE_CONFIG_H -I. -Iinc -c -o src/co/tt src/co/tt.c
In file included from /usr/include/readline/chardefs.h:26,
from /usr/include/readline/keymaps.h:36,
from /usr/include/readline/readline.h:39,
from src/co/tt.c:5:
/usr/include/ctype.h:116: error: expected identifier or '(' before 'int'
/usr/include/ctype.h:116: error: expected ')' before '?' token
/usr/include/ctype.h:119: error: expected identifier or '(' before 'int'
/usr/include/ctype.h:119: error: expected ')' before '?' token

However, if I put a line ``#include <ctype.h>'' at the start of tt.c,
this problem disappears. That is how I figure out that there is
something in the header file src/co/stdu.h interfering with
/usr/include/ctype.h .

Below is a code snippet found at lines 116 and 119 (see above error
messages) in the file /usr/include/ctype.h, which comes with the
package libc6-dev 2.7-10ubuntu3 on my Ubuntu box.

/* Return the lowercase version of C. */
extern int tolower (int __c) __THROW;
/* Return the uppercase version of C. */
extern int toupper (int __c) __THROW;

If preprocessed correctly (verified using `gcc -E' on another simple
working C program that simply includes <ctype.h>), these lines would
become:

xtern int tolower (int __c) __attribute__ ((__nothrow__));
extern int toupper (int __c) __attribute__ ((__nothrow__));

And the above error messages result from these lines becoming

extern int _toupper (int) __attribute__ ((__nothrow__));
extern int _tolower (int) __attribute__ ((__nothrow__));

Fixing the problem is easy: getting rid of some duplicate definitions
of tolower() and toupper() in src/co/stdu.h would make this problem go
away. These functions (macros) are defined in C89, C99, 4.3BSD, so any
modern *nix system should have them already defined anyway.

$ git diff HEAD^ HEAD
diff --git a/src/co/stdu.h b/src/co/stdu.h
index f889826..f3bfa2d 100755
--- a/src/co/stdu.h
+++ b/src/co/stdu.h
@@ -23,13 +23,6 @@ extern int strappend();
extern int strcopy();
extern int strnumat();

-
-#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 */
-
#define TRUE 1
#define FALSE 0
#define SET 1


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/

00:03:49 v.b4412d20