along with GNU Emacs; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "getopt.h"
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
/* Conditionalize function prototypes. */
#ifdef PROTOTYPES /* From config.h. */
/* The character used as a separator in path lists (like $PATH). */
+#if defined(__MSDOS__)
+#define PATH_LIST_SEPARATOR ';'
+#define FILENAME_EQ(X,Y) (strcasecmp(X,Y) == 0)
+#else
+#if defined(WINDOWSNT)
+#define PATH_LIST_SEPARATOR ';'
+#define FILENAME_EQ(X,Y) (stricmp(X,Y) == 0)
+#else
#define PATH_LIST_SEPARATOR ':'
-
+#define FILENAME_EQ(X,Y) (streq(X,Y))
+#endif
+#endif
/* The default output file name. */
-#define DEFAULT_OUTFILE "EBROWSE"
+#define DEFAULT_OUTFILE "BROWSE"
/* A version string written to the output file. Change this whenever
the structure of the output file changes. */
void add_member_decl P_ ((struct sym *, char *, char *, int,
unsigned, int, int, int, int));
void dump_roots P_ ((FILE *));
-void *xmalloc P_ ((int));
+void *ymalloc P_ ((int));
void add_global_defn P_ ((char *, char *, int, unsigned, int, int, int));
void add_global_decl P_ ((char *, char *, int, unsigned, int, int, int));
void add_define P_ ((char *, char *, int));
void member P_ ((struct sym *, int));
void class_body P_ ((struct sym *, int));
void class_definition P_ ((struct sym *, int, int, int));
-void declaration P_ ((int, int));
+void declaration P_ ((int));
unsigned parm_list P_ ((int *));
char *operator_name P_ ((int *));
struct sym *parse_classname P_ ((void));
/* Like malloc but print an error and exit if not enough memory is
- available. */
+ available. This isn't called `xmalloc' because src/m/alpha.h,
+ and maybe others, contain an incompatible prototype for xmalloc
+ and xrealloc. */
void *
-xmalloc (nbytes)
+ymalloc (nbytes)
int nbytes;
{
void *p = malloc (nbytes);
- if (p)
- return p;
- yyerror ("out of memory");
- exit (1);
+ if (p == NULL)
+ {
+ yyerror ("out of memory");
+ exit (1);
+ }
+ return p;
}
/* Like realloc but print an error and exit if out of memory. */
void *
-xrealloc (p, sz)
+yrealloc (p, sz)
void *p;
int sz;
{
p = realloc (p, sz);
- if (p)
- return p;
- yyerror ("out of memory");
- exit (1);
+ if (p == NULL)
+ {
+ yyerror ("out of memory");
+ exit (1);
+ }
+ return p;
}
char *s;
{
if (s)
- s = strcpy (xmalloc (strlen (s) + 1), s);
+ s = strcpy (ymalloc (strlen (s) + 1), s);
return s;
}
puts (name);
}
- sym = (struct sym *) xmalloc (sizeof *sym + strlen (name));
+ sym = (struct sym *) ymalloc (sizeof *sym + strlen (name));
bzero (sym, sizeof *sym);
strcpy (sym->name, name);
sym->namesp = scope;
/* Avoid duplicates. */
if (p == NULL || p->sym != sub)
{
- lnk = (struct link *) xmalloc (sizeof *lnk);
- lnk2 = (struct link *) xmalloc (sizeof *lnk2);
+ lnk = (struct link *) ymalloc (sizeof *lnk);
+ lnk2 = (struct link *) ymalloc (sizeof *lnk2);
lnk->sym = sub;
lnk->next = p;
m = add_member (cls, name, var, sc, hash);
/* Have we seen a new filename? If so record that. */
- if (!cls->filename || !streq (cls->filename, filename))
+ if (!cls->filename || !FILENAME_EQ (cls->filename, filename))
m->filename = filename;
m->regexp = regexp;
if (!cls->sfilename)
cls->sfilename = filename;
- if (!streq (cls->sfilename, filename))
+ if (!FILENAME_EQ (cls->sfilename, filename))
m->def_filename = filename;
m->def_regexp = regexp;
if (!found)
{
if (!global_symbols->filename
- || !streq (global_symbols->filename, filename))
+ || !FILENAME_EQ (global_symbols->filename, filename))
m->filename = filename;
m->regexp = regexp;
int sc;
unsigned hash;
{
- struct member *m = (struct member *) xmalloc (sizeof *m + strlen (name));
+ struct member *m = (struct member *) ymalloc (sizeof *m + strlen (name));
struct member **list;
struct member *p;
struct member *prev;
make_namespace (name)
char *name;
{
- struct sym *s = (struct sym *) xmalloc (sizeof *s + strlen (name));
+ struct sym *s = (struct sym *) ymalloc (sizeof *s + strlen (name));
bzero (s, sizeof *s);
strcpy (s->name, name);
s->next = all_namespaces;
if (streq (new_name, p->name))
return;
- al = (struct alias *) xmalloc (sizeof *al + strlen (new_name));
+ al = (struct alias *) ymalloc (sizeof *al + strlen (new_name));
strcpy (al->name, new_name);
al->next = p->namesp_aliases;
p->namesp_aliases = al;
if (namespace_sp == namespace_stack_size)
{
int size = max (10, 2 * namespace_stack_size);
- namespace_stack = (struct sym **) xrealloc (namespace_stack, size);
+ namespace_stack = (struct sym **) yrealloc (namespace_stack, size);
namespace_stack_size = size;
}
if (scope_buffer_len + len >= scope_buffer_size)
{
int new_size = max (2 * scope_buffer_size, scope_buffer_len + len);
- scope_buffer = (char *) xrealloc (new_size);
+ scope_buffer = (char *) yrealloc (new_size);
scope_buffer_size = new_size;
}
}
if (!scope_buffer)
{
scope_buffer_size = 1024;
- scope_buffer = (char *) xmalloc (scope_buffer_size);
+ scope_buffer = (char *) ymalloc (scope_buffer_size);
}
*scope_buffer = '\0';
if (p == yytext_end - 1)
{
int size = yytext_end - yytext;
- yytext = (char *) xrealloc (yytext, 2 * size);
+ yytext = (char *) yrealloc (yytext, 2 * size);
yytext_end = yytext + 2 * size;
p = yytext + size - 1;
}
if (buffer == NULL)
{
- buffer = (char *) xmalloc (max_regexp);
+ buffer = (char *) ymalloc (max_regexp);
end_buf = &buffer[max_regexp] - 1;
}
if (yytext == NULL)
{
int size = 256;
- yytext = (char *) xmalloc (size * sizeof *yytext);
+ yytext = (char *) ymalloc (size * sizeof *yytext);
yytext_end = yytext + size;
}
}
{
char *s;
unsigned h = 0;
- struct kw *k = (struct kw *) xmalloc (sizeof *k);
+ struct kw *k = (struct kw *) ymalloc (sizeof *k);
for (s = name; *s; ++s)
h = (h << 1) ^ *s;
/* Allocate the input buffer */
inbuffer_size = READ_CHUNK_SIZE + 1;
- inbuffer = in = (char *) xmalloc (inbuffer_size);
+ inbuffer = in = (char *) ymalloc (inbuffer_size);
yyline = 1;
/* Set up character class vectors. */
if (len > id_size)
{
int new_size = max (len, 2 * id_size);
- id = (char *) xrealloc (id, new_size);
+ id = (char *) yrealloc (id, new_size);
id_size = new_size;
}
strcpy (id, s);
if (len > id_size)
{
int new_size = max (len, 2 * id_size);
- id = (char *) xrealloc (id, new_size);
+ id = (char *) yrealloc (id, new_size);
id_size = new_size;
}
strcpy (id, "operator");
if (len > id_size)
{
int new_size = max (len, 2 * id_size);
- id = (char *) xrealloc (id, new_size);
+ id = (char *) yrealloc (id, new_size);
id_size = new_size;
}
int len = strlen (yytext) + 1;
if (len > id_size)
{
- id = (char *) xrealloc (id, len);
+ id = (char *) yrealloc (id, len);
id_size = len;
}
strcpy (id, yytext);
int len = strlen (yytext) + 1;
if (len > id_size)
{
- id = (char *) xrealloc (id, len);
+ id = (char *) yrealloc (id, len);
id_size = len;
}
strcpy (id, yytext);
int flags;
int nested;
{
- register int token;
struct sym *current;
struct sym *base_class;
while (!done)
{
- switch (token = LA1)
+ switch (LA1)
{
case VIRTUAL: case PUBLIC: case PROTECTED: case PRIVATE:
MATCH ();
/* Parse a declaration. */
void
-declaration (is_extern, flags)
- int is_extern;
+declaration (flags)
int flags;
{
char *id = NULL;
return 0;
default:
- declaration (0, flags);
+ declaration (flags);
flags = start_flags;
break;
}
while (*path_list && *path_list != PATH_LIST_SEPARATOR)
++path_list;
- p = (struct search_path *) xmalloc (sizeof *p);
- p->path = (char *) xmalloc (path_list - start + 1);
+ p = (struct search_path *) ymalloc (sizeof *p);
+ p->path = (char *) ymalloc (path_list - start + 1);
memcpy (p->path, start, path_list - start);
p->path[path_list - start] = '\0';
p->next = NULL;
static char *buffer;
static int buffer_size;
struct search_path *path;
+ int flen = strlen (file) + 1; /* +1 for the slash */
filename = xstrdup (file);
for (path = search_path; path && fp == NULL; path = path->next)
{
- int len = strlen (path->path);
+ int len = strlen (path->path) + flen;
if (len + 1 >= buffer_size)
{
buffer_size = max (len + 1, 2 * buffer_size);
- buffer = (char *) xrealloc (buffer, buffer_size);
+ buffer = (char *) yrealloc (buffer, buffer_size);
}
strcpy (buffer, path->path);
if (nread + READ_CHUNK_SIZE >= inbuffer_size)
{
inbuffer_size = nread + READ_CHUNK_SIZE + 1;
- inbuffer = (char *) xrealloc (inbuffer, inbuffer_size);
+ inbuffer = (char *) yrealloc (inbuffer, inbuffer_size);
}
nbytes = fread (inbuffer + nread, 1, READ_CHUNK_SIZE, fp);
- nread += nbytes;
- if (nbytes < READ_CHUNK_SIZE)
+ if (nbytes <= 0)
break;
+ nread += nbytes;
}
+ if (nread < 0)
+ nread = 0;
inbuffer[nread] = '\0';
/* Reinitialize scanner and parser for the new input file. */
if (i >= buffer_size)
{
buffer_size = max (100, buffer_size * 2);
- buffer = (char *) xrealloc (buffer, buffer_size);
+ buffer = (char *) yrealloc (buffer, buffer_size);
}
buffer[i++] = c;
if (i == buffer_size)
{
buffer_size = max (100, buffer_size * 2);
- buffer = (char *) xrealloc (buffer, buffer_size);
+ buffer = (char *) yrealloc (buffer, buffer_size);
}
buffer[i] = '\0';
if (n_input_files == input_filenames_size)
{
input_filenames_size = max (10, 2 * input_filenames_size);
- input_filenames = (char **) xrealloc (input_filenames,
+ input_filenames = (char **) yrealloc (input_filenames,
input_filenames_size);
}
input_filenames[n_input_files++] = xstrdup (optarg);