* 1994 Line-by-line regexp tags by Tom Tromey.
* 2001 Nested classes by Francesco Potortì (concept by Mykola Dzyuba).
* 2002 #line directives by Francesco Potortì.
- *
- * Francesco Potortì <pot@gnu.org> has maintained and improved it since 1993.
+ * Francesco Potortì maintained and improved it for many years
+ starting in 1993.
*/
/*
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
-#include <stdio.h>
+#include <sysstdio.h>
#include <ctype.h>
#include <errno.h>
#include <sys/types.h>
* SYNOPSIS: Type *xnew (int n, Type);
* void xrnew (OldPointer, int n, Type);
*/
-#if DEBUG
-# include "chkmalloc.h"
-# define xnew(n,Type) ((Type *) trace_malloc (__FILE__, __LINE__, \
- (n) * sizeof (Type)))
-# define xrnew(op,n,Type) ((op) = (Type *) trace_realloc (__FILE__, __LINE__, \
- (char *) (op), (n) * sizeof (Type)))
-#else
-# define xnew(n,Type) ((Type *) xmalloc ((n) * sizeof (Type)))
-# define xrnew(op,n,Type) ((op) = (Type *) xrealloc ( \
- (char *) (op), (n) * sizeof (Type)))
-#endif
+#define xnew(n, Type) ((Type *) xmalloc ((n) * sizeof (Type)))
+#define xrnew(op, n, Type) ((op) = (Type *) xrealloc (op, (n) * sizeof (Type)))
typedef void Lang_function (FILE *);
static void linebuffer_init (linebuffer *);
static void linebuffer_setlen (linebuffer *, int);
static void *xmalloc (size_t);
-static void *xrealloc (char *, size_t);
+static void *xrealloc (void *, size_t);
\f
static char searchar = '/'; /* use /.../ searches */
if (real_name == compressed_name)
{
char *cmd = concat (compr->command, " ", real_name);
- inf = popen (cmd, "rb");
+ inf = popen (cmd, "r" FOPEN_BINARY);
free (cmd);
}
else
- inf = fopen (real_name, "rb");
+ inf = fopen (real_name, "r" FOPEN_BINARY);
if (inf == NULL)
{
perror (real_name);
case st_none:
if (constantypedefs
&& structdef == snone
- && structtype == st_C_enum && bracelev > structbracelev)
+ && structtype == st_C_enum && bracelev > structbracelev
+ /* Don't tag tokens in expressions that assign values to enum
+ constants. */
+ && fvdef != vignore)
return true; /* enum constant */
switch (fvdef)
{
cpptoken = false;
}
if (cpptoken)
- definedef = dsharpseen;
+ {
+ definedef = dsharpseen;
+ /* This is needed for tagging enum values: when there are
+ preprocessor conditionals inside the enum, we need to
+ reset the value of fvdef so that the next enum value is
+ tagged even though the one before it did not end in a
+ comma. */
+ if (fvdef == vignore && instruct && parlev == 0)
+ {
+ if (strneq (cp, "#if", 3) || strneq (cp, "#el", 3))
+ fvdef = fvnone;
+ }
+ }
} /* if (definedef == dnone) */
continue;
case '[':
case fstartlist:
case finlist:
case fignore:
+ break;
case vignore:
+ if (instruct && parlev == 0)
+ fvdef = fvnone;
break;
case fdefunname:
fvdef = fignore;
char *regexfile = regex_arg + 1;
/* regexfile is a file containing regexps, one per line. */
- regexfp = fopen (regexfile, "rb");
+ regexfp = fopen (regexfile, "r" FOPEN_BINARY);
if (regexfp == NULL)
pfatal (regexfile);
linebuffer_init (®exbuf);
canonicalize_filename (register char *fn)
{
register char* cp;
- char sep = '/';
#ifdef DOS_NT
/* Canonicalize drive letter case. */
if (fn[0] != '\0' && fn[1] == ':' && ISUPPER (fn[0]))
fn[0] = lowcase (fn[0]);
- sep = '\\';
-#endif
+ /* Collapse multiple forward- and back-slashes into a single forward
+ slash. */
+ for (cp = fn; *cp != '\0'; cp++, fn++)
+ if (*cp == '/' || *cp == '\\')
+ {
+ *fn = '/';
+ while (cp[1] == '/' || cp[1] == '\\')
+ cp++;
+ }
+ else
+ *fn = *cp;
+
+#else /* !DOS_NT */
- /* Collapse multiple separators into a single slash. */
+ /* Collapse multiple slashes into a single slash. */
for (cp = fn; *cp != '\0'; cp++, fn++)
- if (*cp == sep)
+ if (*cp == '/')
{
*fn = '/';
- while (cp[1] == sep)
+ while (cp[1] == '/')
cp++;
}
else
*fn = *cp;
+
+#endif /* !DOS_NT */
+
*fn = '\0';
}
}
static void *
-xrealloc (char *ptr, size_t size)
+xrealloc (void *ptr, size_t size)
{
void *result = realloc (ptr, size);
if (result == NULL)