Not for 21.4.
Yes, there are UNUSED in DEFUNs. Dunno why; GNU or backward
compatibility, I guess. This results in a badly broken docstring: the
"UNUSED" itself is interpreted as a formal argument, and the following
close paren ends the argument list.
This patch works for me so far, but the whole thing seems quite
delicate: any mistakes in the parser here will cost you the docstrings
of everything defined in C....
Tests and comments welcome. Eventually I'll commit if nobody
complains.
Index: lib-src/ChangeLog
===================================================================
RCS file:
/Users/steve/Software/Repositories/cvs.xemacs.org/XEmacs/xemacs/lib-src/ChangeLog,v
retrieving revision 1.178.2.1
diff -u -r1.178.2.1 ChangeLog
--- ChangeLog 2004/12/11 05:12:52 1.178.2.1
+++ ChangeLog 2005/01/22 04:53:31
@@ -0,0 +1,5 @@
+2004-12-19 Stephen J. Turnbull <stephen(a)xemacs.org>
+
+ * make-docfile.c (write_c_args): Handle UNUSED, USED_IF macros.
+ (scan_c_file): Handle nested parens in DEFUN argument lists.
+
Index: lib-src/make-docfile.c
===================================================================
RCS file:
/Users/steve/Software/Repositories/cvs.xemacs.org/XEmacs/xemacs/lib-src/make-docfile.c,v
retrieving revision 1.15.2.1
diff -u -r1.15.2.1 make-docfile.c
--- make-docfile.c 2004/12/11 05:12:54 1.15.2.1
+++ make-docfile.c 2005/01/23 11:07:27
@@ -525,9 +525,16 @@
char c = *p;
int ident_start = 0;
- /* XEmacs addition: add support for ANSI prototypes. Hop over
- "Lisp_Object" string (the only C type allowed in DEFUNs) */
+ /* XEmacs addition: add support for ANSI prototypes and the UNUSED
+ macros. Hop over them. "Lisp_Object" is the only C type allowed
+ in DEFUNs. For the UNUSED macros we need to eat parens, too. */
+ static char uu [] = "UNUSED";
+ static char ui [] = "USED_IF_";
static char lo[] = "Lisp_Object";
+
+ /* aren't these all vulnerable to buffer overrun? I guess that
+ means that the .c is busted, so we may as well just die ... */
+ /* skip over "Lisp_Object" */
if ((C_IDENTIFIER_CHAR_P (c) != in_ident) && !in_ident &&
(strncmp (p, lo, sizeof (lo) - 1) == 0) &&
isspace ((unsigned char) p[sizeof (lo) - 1]))
@@ -538,6 +545,45 @@
c = *p;
}
+ /* skip over "UNUSED" invocation */
+ if ((C_IDENTIFIER_CHAR_P (c) != in_ident) && !in_ident &&
+ (strncmp (p, uu, sizeof (uu) - 1) == 0))
+ {
+ char *here = p;
+ p += (sizeof (uu) - 1);
+ while (isspace ((unsigned char) (*p)))
+ p++;
+ if (*p == '(')
+ {
+ while (isspace ((unsigned char) (*++p)))
+ ;
+ c = *p;
+ }
+ else
+ p = here;
+ }
+
+ /* skip over "USED_IF_*" invocation (only if USED failed) */
+ else if ((C_IDENTIFIER_CHAR_P (c) != in_ident) && !in_ident &&
+ (strncmp (p, ui, sizeof (ui) - 1) == 0))
+ {
+ char *here = p;
+ p += (sizeof (ui) - 1);
+ /* There should be a law against parsing in C:
+ this allows a broken USED_IF call, skipping to next macro's
+ parens. *You* can fix that, I don't see how offhand. ;-) */
+ while (*p && *p++ != '(')
+ ;
+ if (*p)
+ {
+ while (isspace ((unsigned char) (*p)))
+ p++;
+ c = *p;
+ }
+ else
+ p = here;
+ }
+
/* Notice when we start printing a new identifier. */
if (C_IDENTIFIER_CHAR_P (c) != in_ident)
{
@@ -836,6 +882,7 @@
if (defunflag && maxargs != -1)
{
char argbuf[1024], *p = argbuf;
+ int paren_level = 1;
#if 0 /* For old DEFUN's only */
while (c != ')')
{
@@ -858,8 +905,13 @@
*p++ = c = getc (infile);
if (c < 0)
goto eof;
+ /* XEmacs change: handle macros with args (eg, UNUSED) */
+ if (c == ')')
+ paren_level--;
+ if (c == '(')
+ paren_level++;
}
- while (c != ')');
+ while (paren_level > 0);
*p = '\0';
/* Output them. */
if (ellcc)
--
Graduate School of Systems and Information Engineering University of Tsukuba
http://turnbull.sk.tsukuba.ac.jp/ Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
Economics of Information Communication and Computation Systems
Experimental Economics, Microeconomic Theory, Game Theory