Merge in branch-1_29.

This commit is contained in:
Akim Demaille
2001-10-04 14:55:21 +00:00
parent 0150aabe35
commit 342b8b6e21
59 changed files with 2212 additions and 1586 deletions

View File

@@ -23,7 +23,6 @@
The entry point is generate_states. */
#include "system.h"
#include "xalloc.h"
#include "gram.h"
#include "state.h"
#include "complain.h"
@@ -33,39 +32,39 @@
int nstates;
int final_state;
core *first_state;
shifts *first_shift;
reductions *first_reduction;
core *first_state = NULL;
shifts *first_shift = NULL;
reductions *first_reduction = NULL;
static core *this_state;
static core *last_state;
static shifts *last_shift;
static reductions *last_reduction;
static core *this_state = NULL;
static core *last_state = NULL;
static shifts *last_shift = NULL;
static reductions *last_reduction = NULL;
static int nshifts;
static short *shift_symbol;
static short *shift_symbol = NULL;
static short *redset;
static short *shiftset;
static short *redset = NULL;
static short *shiftset = NULL;
static short **kernel_base;
static short **kernel_end;
static short *kernel_items;
static short **kernel_base = NULL;
static short **kernel_end = NULL;
static short *kernel_items = NULL;
/* hash table for states, to recognize equivalent ones. */
#define STATE_TABLE_SIZE 1009
static core **state_table;
static core **state_table = NULL;
static void
allocate_itemsets (void)
{
short *itemp;
short *itemp = NULL;
int symbol;
int i;
int count;
short *symbol_count;
short *symbol_count = NULL;
count = 0;
symbol_count = XCALLOC (short, nsyms);
@@ -89,7 +88,8 @@ allocate_itemsets (void)
We allocate that much space for each symbol. */
kernel_base = XCALLOC (short *, nsyms);
kernel_items = XCALLOC (short, count);
if (count)
kernel_items = XCALLOC (short, count);
count = 0;
for (i = 0; i < nsyms; i++)

View File

@@ -512,13 +512,13 @@ yyparse (YYPARSE_PARAM_ARG)
/*------------------------------------------------------------.
| yynewstate -- Push a new state, which is found in yystate. |
`------------------------------------------------------------*/
yynewstate:
yynewstate:
/* In all cases, when you get here, the value and location stacks
have just been pushed. so pushing a state here evens the stacks.
*/
yyssp++;
yysetstate:
yysetstate:
*yyssp = yystate;
if (yyssp >= yyss + yystacksize - 1)
@@ -995,4 +995,3 @@ yyabortlab:
#line %%input_line "%%filename"
%%epilogue

View File

@@ -19,7 +19,6 @@
02111-1307, USA. */
#include "system.h"
#include "xalloc.h"
#include "gram.h"
#include "closure.h"
#include "derives.h"

View File

@@ -19,14 +19,10 @@
/* Based on error.c and error.h,
written by David MacKenzie <djm@gnu.ai.mit.edu>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include "system.h"
#if HAVE_VPRINTF || HAVE_DOPRNT || _LIBC
# if __STDC__
# ifdef __STDC__
# include <stdarg.h>
# define VA_START(args, lastarg) va_start(args, lastarg)
# else
@@ -119,7 +115,7 @@ int error_one_per_line;
`--------------------------------*/
void
#if defined VA_START && __STDC__
#if defined VA_START && defined __STDC__
warn (const char *message, ...)
#else
warn (message, va_alist)
@@ -171,7 +167,7 @@ warn (message, va_alist)
`-----------------------------------------------------------*/
void
#if defined VA_START && __STDC__
#if defined VA_START && defined __STDC__
complain (const char *message, ...)
#else
complain (message, va_alist)
@@ -221,7 +217,7 @@ complain (message, va_alist)
`-------------------------------------------------*/
void
#if defined VA_START && __STDC__
#if defined VA_START && defined __STDC__
fatal (const char *message, ...)
#else
fatal (message, va_alist)
@@ -259,7 +255,7 @@ fatal (message, va_alist)
`------------------------------------------------------------------*/
void
#if defined VA_START && __STDC__
#if defined VA_START && defined __STDC__
error (int status, int errnum,
const char *message, ...)
#else

View File

@@ -23,7 +23,7 @@
extern "C" {
#endif
#if defined (__STDC__) && __STDC__
#ifdef __STDC__
/* Informative messages, but we proceed. */

View File

@@ -20,7 +20,6 @@
#include "system.h"
#include "getargs.h"
#include "xalloc.h"
#include "files.h"
#include "gram.h"
#include "state.h"
@@ -30,12 +29,12 @@
#include "LR0.h"
int any_conflicts = 0;
errs **err_table;
errs **err_table = NULL;
int expected_conflicts;
static char *conflicts;
static char *conflicts = NULL;
static unsigned *shiftset;
static unsigned *lookaheadset;
static unsigned *shiftset = NULL;
static unsigned *lookaheadset = NULL;
static int src_total;
static int rrc_total;
static int src_count;
@@ -264,7 +263,7 @@ set_conflicts (int state)
}
void
initialize_conflicts (void)
solve_conflicts (void)
{
int i;
@@ -458,7 +457,7 @@ conflict_report (int src_num, int rrc_num)
`---------------------------------------------*/
void
print_conflicts (void)
print_conflicts (FILE *out)
{
int i;
@@ -478,9 +477,8 @@ print_conflicts (void)
if (verbose_flag)
{
obstack_fgrow1 (&output_obstack, _("State %d contains"), i);
obstack_sgrow (&output_obstack,
conflict_report (src_count, rrc_count));
fprintf (out, _("State %d contains"), i);
fputs (conflict_report (src_count, rrc_count), out);
}
}
}
@@ -738,7 +736,7 @@ print_reductions (int state)
void
finalize_conflicts (void)
free_conflicts (void)
{
XFREE (conflicts);
XFREE (shiftset);

View File

@@ -22,10 +22,10 @@
# define CONFLICTS_H_
# include "state.h"
void initialize_conflicts PARAMS ((void));
void print_conflicts PARAMS ((void));
void solve_conflicts PARAMS ((void));
void print_conflicts PARAMS ((FILE *out));
void print_reductions PARAMS ((int));
void finalize_conflicts PARAMS ((void));
void free_conflicts PARAMS ((void));
/* Were there conflicts? */
extern int any_conflicts;

View File

@@ -25,7 +25,6 @@
*/
#include "system.h"
#include "xalloc.h"
#include "types.h"
#include "gram.h"
#include "derives.h"

View File

@@ -22,7 +22,6 @@
#include "system.h"
#include "getargs.h"
#include "files.h"
#include "xalloc.h"
#include "gram.h"
#include "complain.h"
@@ -34,11 +33,13 @@ struct obstack table_obstack;
struct obstack defines_obstack;
struct obstack guard_obstack;
struct obstack output_obstack;
struct obstack graph_obstack;
char *spec_outfile = NULL; /* for -o. */
char *spec_file_prefix = NULL; /* for -b. */
char *spec_name_prefix = NULL; /* for -p. */
char *spec_verbose_file = NULL; /* for --verbose. */
char *spec_graph_file = NULL; /* for -g. */
char *spec_defines_file = NULL; /* for --defines. */
char *infile = NULL;
char *attrsfile = NULL;
@@ -93,24 +94,26 @@ stringappend (const char *string1, const char *string2)
static char *
compute_header_macro (void)
{
int ite;
char *macro_name;
char *macro_name, *cp;
macro_name = XMALLOC (char,
strlen (base_name) +
strlen (header_extension) + 1);
if (spec_defines_file)
macro_name = xstrdup (spec_defines_file);
else
{
macro_name = XMALLOC (char,
strlen (base_name) +
strlen (header_extension) + 1);
stpcpy (macro_name, base_name);
strcat (macro_name, header_extension);
stpcpy (macro_name, base_name);
strcat (macro_name, header_extension);
}
for (cp = macro_name; *cp; ++cp)
if (islower (*cp))
*cp = toupper (*cp);
else if (!isalnum (*cp))
*cp = '_';
for (ite = 0; macro_name[ite]; ite++)
if (macro_name[ite] == '.')
macro_name[ite] = '_';
else
{
if (islower (macro_name[ite]))
macro_name[ite] -= ('a' - 'A');
}
return macro_name;
}
@@ -194,17 +197,42 @@ skeleton_find (const char *envvar, const char *skeleton_name)
{
const char *res = getenv (envvar);
#ifdef MSDOS
const char *cp;
/* File doesn't exist in current directory; try in INIT directory. */
if (!res && (cp = getenv ("INIT")))
#if defined (MSDOS) || defined (_WIN32)
if (!res)
{
res = XMALLOC (char, strlen (cp) + strlen (skeleton_name) + 2);
sprintf (res, "%s%c%s", cp, '/', skeleton_name);
}
#endif /* !MSDOS */
/* Skeleton file name without path */
const char *skel_name = strrchr(skeleton_name, '/');
if (!skel_name)
skel_name = strrchr(skeleton_name, '\\');
if (!skel_name)
skel_name = skeleton_name;
else
++skel_name;
/* File doesn't exist in current directory; try in INIT directory. */
const char *cp = getenv ("INIT");
if (cp)
{
res = XMALLOC (char, strlen (cp) + strlen (skel_name) + 2);
sprintf (res, "%s%c%s", cp, '\\', skel_name);
}
else if (access (skel_name, 4) == 0) /* Look in current dir. */
res = skel_name;
else
{
/* Look in program locations dir. */
extern char *program_name;
cp = strrchr(program_name, '\\');
if (!cp)
return skeleton_name;
else
++cp;
res = XMALLOC (char, cp - program_name + strlen (skel_name) + 1);
strncpy (res, program_name, cp - program_name);
strcpy (res + (cp - program_name), skel_name);
}
}
#endif /* defined (MSDOS) || defined (_WIN32) */
if (!res)
res = skeleton_name;
@@ -260,20 +288,10 @@ get_extension_index (const char *filename)
static void
compute_exts_from_gf (const char *ext)
{
/* Checks if SRC_EXTENSION is NULL. In the other case, %source_extension
was specified in the grammar file. */
if (src_extension == NULL)
{
src_extension = tr (ext, 'y', 'c');
src_extension = tr (src_extension, 'Y', 'C');
}
/* Checks if HEADER_EXTENSION is NULL. In the other case,
%header_extension was specified in the grammar file. */
if (header_extension == NULL)
{
header_extension = tr (ext, 'y', 'h');
header_extension = tr (header_extension, 'Y', 'H');
}
src_extension = tr (ext, 'y', 'c');
src_extension = tr (src_extension, 'Y', 'C');
header_extension = tr (ext, 'y', 'h');
header_extension = tr (header_extension, 'Y', 'H');
}
/* Computes extensions from the given c source file extension. */
@@ -395,6 +413,38 @@ compute_base_names (void)
}
}
/*-------------------------------------------------------.
| Close the open files, compute the output files names. |
`-------------------------------------------------------*/
void
compute_output_file_names (void)
{
compute_base_names ();
/* If not yet done. */
if (!src_extension)
src_extension = ".c";
if (!header_extension)
header_extension = ".h";
/* It the defines filename if not given, we create it. */
if (!spec_defines_file)
spec_defines_file = stringappend (base_name, header_extension);
/* It the graph filename if not given, we create it. */
if (!spec_graph_file)
spec_graph_file = stringappend (short_base_name, ".vcg");
spec_verbose_file = stringappend (short_base_name, EXT_OUTPUT);
attrsfile = stringappend (short_base_name, EXT_STYPE_H);
#ifndef MSDOS
attrsfile = stringappend (attrsfile, header_extension);
#endif /* MSDOS */
}
/*-----------------------------------------------------------------.
| Open the input file. Look for the skeletons. Find the names of |
| the output files. Prepare the obstacks. |
@@ -412,46 +462,47 @@ open_files (void)
obstack_init (&defines_obstack);
obstack_init (&guard_obstack);
obstack_init (&output_obstack);
obstack_init (&graph_obstack);
}
/*-----------------------------------------------------.
| Close the open files, produce all the output files. |
`-----------------------------------------------------*/
/*-----------------------.
| Close the open file.. |
`-----------------------*/
void
close_files (void)
{
xfclose (finput);
}
/*---------------------------.
| Produce the output files. |
`---------------------------*/
void
output_files (void)
{
xfclose (finput);
compute_base_names ();
/* Set default extensions */
if (!src_extension)
src_extension = ".c";
if (!header_extension)
header_extension = ".h";
attrsfile = stringappend (short_base_name, EXT_STYPE_H);
#ifndef MSDOS
stringappend (attrsfile, header_extension);
#endif /* MSDOS */
/* Output the main file. */
if (spec_outfile)
obstack_save (&table_obstack, spec_outfile);
else
obstack_save (&table_obstack, stringappend (base_name, src_extension));
obstack_free (&table_obstack, NULL);
/* Output the header file if wanted. */
if (defines_flag)
defines_obstack_save (stringappend (base_name, header_extension));
defines_obstack_save (spec_defines_file);
obstack_free (&defines_obstack, NULL);
#if 0
/* Seems to be invalid now --akim. */
/* If we output only the table, dump the actions in ACTFILE. */
if (no_parser_flag)
obstack_save (&action_obstack, stringappend (short_base_name, ".act"));
obstack_free (&action_obstack, NULL);
#endif
/* If we produced a semantic parser ATTRS_OBSTACK must be dumped
into its own file, ATTTRSFILE. */
@@ -460,19 +511,12 @@ output_files (void)
char *temp_name;
obstack_save (&attrs_obstack, attrsfile);
obstack_free (&attrs_obstack, NULL);
temp_name = stringappend (short_base_name, EXT_GUARD_C);
#ifndef MSDOS
temp_name = stringappend (temp_name, src_extension);
#endif /* MSDOS */
obstack_save (&guard_obstack, temp_name);
obstack_free (&guard_obstack, NULL);
}
if (verbose_flag)
/* We used to use just .out if spec_name_prefix (-p) was used, but
that conflicts with Posix. */
obstack_save (&output_obstack,
stringappend (short_base_name, EXT_OUTPUT));
if (graph_flag)
obstack_save (&graph_obstack, stringappend (short_base_name, ".vcg"));
}

View File

@@ -33,10 +33,19 @@ extern char *spec_name_prefix;
/* File name pfx specified with -b, or 0 if no -b. */
extern char *spec_file_prefix;
/* --verbose. */
extern char *spec_verbose_file;
/* File name specified for the output VCG graph. */
extern char *spec_graph_file;
/* File name specified with --defines. */
extern char *spec_defines_file;
/* Read grammar specifications. */
extern FILE *finput;
/* Output all the action code; precise form depends on which parser. */
extern struct obstack action_obstack;
@@ -56,17 +65,13 @@ extern struct obstack guard_obstack;
/* The verbose output. */
extern struct obstack output_obstack;
/* The VCG graph output. */
extern struct obstack graph_obstack;
extern char *infile;
extern char *attrsfile;
extern const char *src_extension;
extern const char *header_extension;
void open_files PARAMS((void));
void close_files PARAMS((void));
void compute_output_file_names PARAMS((void));
void output_files PARAMS((void));
FILE *xfopen PARAMS ((const char *name, const char *mode));

View File

@@ -89,7 +89,9 @@ Output:\n\
-d, --defines also produce a header file\n\
-v, --verbose also produce an explanation of the automaton\n\
-b, --file-prefix=PREFIX specify a PREFIX for output files\n\
-o, --output-file=FILE leave output to FILE\n"), stream);
-o, --output-file=FILE leave output to FILE\n\
-g, --graph also produce a VCG graph description of the \
automaton\n"), stream);
putc ('\n', stream);
fputs (_("\
@@ -153,7 +155,9 @@ getargs (int argc, char *argv[])
exit (0);
case 'g':
/* Here, the -g and --graph=FILE options are differentiated. */
graph_flag = 1;
spec_graph_file = optarg;
break;
case 'v':
@@ -165,7 +169,9 @@ getargs (int argc, char *argv[])
break;
case 'd':
/* Here, the -d and --defines options are differentiated. */
defines_flag = 1;
spec_defines_file = optarg;
break;
case 'l':

View File

@@ -31,21 +31,19 @@ int nsyms;
int ntokens;
int nvars;
short *ritem;
short *rlhs;
short *rrhs;
short *rprec;
short *rprecsym;
short *sprec;
short *rassoc;
short *sassoc;
short *token_translations;
short *rline;
short *ritem = NULL;
short *rlhs = NULL;
short *rrhs = NULL;
short *rprec = NULL;
short *rprecsym = NULL;
short *sprec = NULL;
short *rassoc = NULL;
short *sassoc = NULL;
short *token_translations = NULL;
short *rline = NULL;
int start_symbol;
int translations;
int max_user_token_number;
int semantic_parser;

View File

@@ -107,13 +107,9 @@ typedef enum
/* token translation table: indexed by a token number as returned by
the user's yylex routine, it yields the internal token number used
by the parser and throughout bison. If translations is zero, the
translation table is not used because the two kinds of token
numbers are the same. (It is noted in reader.c that "Nowadays
translations is always set to 1...") */
by the parser and throughout bison. */
extern short *token_translations;
extern int translations;
extern int max_user_token_number;
/* SEMANTIC_PARSER is nonzero if the input file says to use the hairy

View File

@@ -26,7 +26,6 @@
#include "system.h"
#include "types.h"
#include "LR0.h"
#include "xalloc.h"
#include "gram.h"
#include "complain.h"
#include "lalr.h"

View File

@@ -25,7 +25,6 @@
#include "symtab.h"
#include "options.h"
#include "lex.h"
#include "xalloc.h"
#include "complain.h"
#include "gram.h"
#include "quote.h"
@@ -37,15 +36,24 @@ const char *token_buffer = NULL;
bucket *symval;
int numval;
static int unlexed; /* these two describe a token to be reread */
static bucket *unlexed_symval; /* by the next call to lex */
/* these two describe a token to be reread */
static token_t unlexed = tok_undef;
/* by the next call to lex */
static bucket *unlexed_symval = NULL;
void
init_lex (void)
lex_init (void)
{
obstack_init (&token_obstack);
unlexed = -1;
unlexed = tok_undef;
}
void
lex_free (void)
{
obstack_free (&token_obstack, NULL);
}
@@ -314,7 +322,7 @@ literalchar (struct obstack *out, int *pcode, char term)
void
unlex (int token)
unlex (token_t token)
{
unlexed = token;
unlexed_symval = symval;
@@ -357,12 +365,12 @@ lex (void)
/* Just to make sure. */
token_buffer = NULL;
if (unlexed >= 0)
if (unlexed != tok_undef)
{
token_t res = unlexed;
symval = unlexed_symval;
c = unlexed;
unlexed = -1;
return c;
unlexed = tok_undef;
return res;
}
c = skip_white_space ();
@@ -418,7 +426,6 @@ lex (void)
case '\'':
/* parse the literal token and compute character code in code */
translations = -1;
{
int code, discode;
@@ -446,7 +453,6 @@ lex (void)
case '\"':
/* parse the literal string token and treat as an identifier */
translations = -1;
{
int code; /* ignored here */
@@ -464,32 +470,40 @@ lex (void)
}
case ',':
token_buffer = ",";
return tok_comma;
case ':':
token_buffer = ":";
return tok_colon;
case ';':
token_buffer = ";";
return tok_semicolon;
case '|':
token_buffer = "|";
return tok_bar;
case '{':
token_buffer = "{";
return tok_left_curly;
case '=':
obstack_1grow (&token_obstack, c);
do
{
c = getc (finput);
obstack_1grow (&token_obstack, c);
if (c == '\n')
lineno++;
}
while (c == ' ' || c == '\n' || c == '\t');
obstack_1grow (&token_obstack, '\0');
token_buffer = obstack_finish (&token_obstack);
if (c == '{')
{
token_buffer = "={";
return tok_left_curly;
}
else
@@ -506,6 +520,9 @@ lex (void)
return parse_percent_token ();
default:
obstack_1grow (&token_obstack, c);
obstack_1grow (&token_obstack, '\0');
token_buffer = obstack_finish (&token_obstack);
return tok_illegal;
}
}
@@ -516,28 +533,28 @@ lex (void)
static int
option_strcmp (const char *left, const char *right)
{
const unsigned char *l, *r;
int c;
const unsigned char *l, *r;
int c;
assert(left != NULL && right != NULL);
l = (const unsigned char *)left;
r = (const unsigned char *)right;
while (((c = *l - *r++) == 0 && *l != '\0')
|| ((*l == '-' || *l == '_') && (*r == '_' || *r == '-')))
l++;
return c;
assert (left);
assert (right);
l = (const unsigned char *)left;
r = (const unsigned char *)right;
while (((c = *l - *r++) == 0 && *l != '\0')
|| ((*l == '-' || *l == '_') && (*r == '_' || *r == '-')))
l++;
return c;
}
/* Parse a token which starts with %.
Assumes the % has already been read and discarded. */
int
token_t
parse_percent_token (void)
{
int c;
const struct option_table_struct *tx;
c = getc (finput);
int c = getc (finput);
switch (c)
{
@@ -601,6 +618,10 @@ parse_percent_token (void)
case tok_obsolete:
fatal (_("`%s' is no longer supported"), token_buffer);
break;
default:
/* Other cases do not apply here. */
break;
}
return tx->ret_val;

View File

@@ -24,6 +24,7 @@
/* Token-type codes. */
typedef enum token_e
{
tok_undef, /* Not defined. Used to initial token_t vars. */
tok_eof,
tok_identifier,
tok_comma,
@@ -47,8 +48,6 @@ typedef enum token_e
tok_number,
tok_expect,
tok_thong,
tok_hdrext,
tok_srcext,
tok_define,
tok_skel,
tok_noop,
@@ -61,9 +60,10 @@ extern const char *token_buffer;
extern bucket *symval;
extern int numval;
void init_lex PARAMS ((void));
void lex_init PARAMS ((void));
void lex_free PARAMS ((void));
int skip_white_space PARAMS ((void));
void unlex PARAMS ((int));
void unlex PARAMS ((token_t));
void read_type_name PARAMS ((FILE *fin));
/* Return one of the token-type codes. When an identifier is seen,
@@ -73,6 +73,6 @@ void read_type_name PARAMS ((FILE *fin));
token_t lex PARAMS ((void));
int parse_percent_token PARAMS ((void));
token_t parse_percent_token PARAMS ((void));
#endif /* !LEX_H_ */

View File

@@ -1,5 +1,5 @@
/* Top level entry point of bison,
Copyright 1984, 1986, 1989, 1992, 1995, 2000
Copyright 1984, 1986, 1989, 1992, 1995, 2000, 2001
Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
@@ -35,6 +35,8 @@
#include "conflicts.h"
#include "print_graph.h"
#include "muscle_tab.h"
#include "symtab.h"
#include "lex.h"
/* The name this program was run with, for messages. */
char *program_name;
@@ -81,7 +83,15 @@ main (int argc, char *argv[])
lookahead is not enough to disambiguate the parsing. In file
conflicts. Also resolve s/r conflicts based on precedence
declarations. */
initialize_conflicts ();
solve_conflicts ();
/* Output file names. */
compute_output_file_names ();
/* Stop if there were errors, to avoid trashing previous output
files. */
if (complain_message_count)
exit (1);
/* Print information about results, if requested. */
print_results ();
@@ -92,12 +102,19 @@ main (int argc, char *argv[])
/* Output the tables and the parser to ftable. In file output. */
output ();
finalize_conflicts ();
/* Free the symbol table data structure. */
free_symtab ();
lex_free ();
/* Close the input files. */
close_files ();
free_conflicts ();
free_nullable ();
free_derives ();
if (!complain_message_count)
output_files ();
output_files ();
exit (complain_message_count ? 1 : 0);
}

View File

@@ -26,7 +26,6 @@
#include "system.h"
#include "types.h"
#include "gram.h"
#include "xalloc.h"
#include "nullable.h"
char *nullable = NULL;

View File

@@ -45,7 +45,7 @@ const struct option_table_struct option_table[] =
/* Operation modes. */
{opt_cmd_line, "help", no_argument, 0, 0, 'h'},
{opt_cmd_line, "version", no_argument, 0, 0, 'V'},
/* Parser. */
/* was 'a'; apparently unused -wjh */
{opt_cmd_line, "name-prefix", required_argument, 0, 0, 'p'},
@@ -53,7 +53,7 @@ const struct option_table_struct option_table[] =
/* Output. */
{opt_cmd_line, "file-prefix", required_argument, 0, 0, 'b'},
{opt_cmd_line, "output-file", required_argument, 0, 0, 'o'},
{opt_cmd_line, "graph", no_argument, 0, 0, 'g'},
{opt_cmd_line, "graph", optional_argument, 0, 0, 'g'},
/* Hidden. */
{opt_cmd_line, "statistics", no_argument, &statistics_flag, 0, 1},
@@ -86,8 +86,6 @@ const struct option_table_struct option_table[] =
{opt_both, "file-prefix", required_argument,&spec_file_prefix,tok_setopt,'b'},
{opt_both, "name-prefix", required_argument,&spec_name_prefix,tok_setopt,'p'},
#endif
{opt_percent, "header-extension", 0, NULL, tok_hdrext, 0},
{opt_percent, "source-extension", 0, NULL, tok_srcext, 0},
{opt_percent, "define", 0, NULL, tok_define, 0},
{opt_percent, "semantic-parser", 0, &semantic_parser, tok_noop, 0},
{opt_percent, "pure-parser", 0, &pure_parser, tok_noop, 0},
@@ -97,11 +95,11 @@ const struct option_table_struct option_table[] =
*/
/* FIXME Usually option use `-' to separe words on command line
and `_' for percent option. But here the separator are always
and `_' for percent option. But here the separator are always
the same, the char `-'. */
/* Output. */
{opt_both, "defines", no_argument, &defines_flag, tok_noop, 'd'},
{opt_both, "defines", optional_argument, &defines_flag, tok_noop, 'd'},
{opt_both, "verbose", no_argument, &verbose_flag, tok_noop, 'v'},
/* Operation modes. */
@@ -109,7 +107,7 @@ const struct option_table_struct option_table[] =
{opt_both, "yacc", no_argument, &yacc_flag, tok_noop, 'y'},
/* Parser. */
{opt_both, "debug", no_argument, &debug_flag, tok_noop, 'd'},
{opt_both, "debug", no_argument, &debug_flag, tok_noop, 't'},
{opt_both, "locations", no_argument, &locations_flag, tok_noop, 1},
{opt_both, "no-lines", no_argument, &no_lines_flag, tok_noop, 'l'},
{opt_both, "no-parser", no_argument, &no_parser_flag, tok_noop, 'n'},

View File

@@ -94,7 +94,6 @@
#include "obstack.h"
#include "quotearg.h"
#include "getargs.h"
#include "xalloc.h"
#include "files.h"
#include "gram.h"
#include "LR0.h"
@@ -109,17 +108,17 @@ extern void berror PARAMS((const char *));
static int nvectors;
static int nentries;
static short **froms;
static short **tos;
static short *tally;
static short *width;
static short *actrow;
static short *state_count;
static short *order;
static short *base;
static short *pos;
static short *table;
static short *check;
static short **froms = NULL;
static short **tos = NULL;
static short *tally = NULL;
static short *width = NULL;
static short *actrow = NULL;
static short *state_count = NULL;
static short *order = NULL;
static short *base = NULL;
static short *pos = NULL;
static short *table = NULL;
static short *check = NULL;
static int lowzero;
static int high;
@@ -129,15 +128,15 @@ struct obstack output_obstack;
/* FIXME. */
static inline void
output_table_data (struct obstack *oout,
short *table_data,
short first,
short begin,
output_table_data (struct obstack *oout,
short *table_data,
short first,
short begin,
short end)
{
int i;
int j = 1;
obstack_fgrow1 (oout, "%6d", first);
for (i = begin; i < end; ++i)
{
@@ -158,19 +157,20 @@ output_table_data (struct obstack *oout,
static void
output_token_translations (void)
{
output_table_data (&output_obstack, token_translations,
output_table_data (&output_obstack, token_translations,
0, 1, max_user_token_number + 1);
muscle_insert ("translate", obstack_finish (&output_obstack));
XFREE (token_translations);
}
static void
output_gram (void)
{
output_table_data (&output_obstack, rrhs,
output_table_data (&output_obstack, rrhs,
0, 1, nrules + 1);
muscle_insert ("prhs", obstack_finish (&output_obstack));
{
size_t yyrhs_size = 1;
short *yyrhs, *sp;
@@ -183,7 +183,7 @@ output_gram (void)
for (sp = ritem + 1, i = 1; *sp; ++sp, ++i)
yyrhs[i] = *sp > 0 ? *sp : 0;
output_table_data (&output_obstack, yyrhs,
output_table_data (&output_obstack, yyrhs,
ritem[0], 1, yyrhs_size);
muscle_insert ("rhs", obstack_finish (&output_obstack));
@@ -200,7 +200,7 @@ output_gram (void)
static void
output_stos (void)
{
output_table_data (&output_obstack, accessing_symbol,
output_table_data (&output_obstack, accessing_symbol,
0, 1, nstates);
muscle_insert ("stos", obstack_finish (&output_obstack));
}
@@ -275,7 +275,7 @@ output_rule_data (void)
muscle_insert ("toknum", obstack_finish (&output_obstack));
/* Output YYR1. */
output_table_data (&output_obstack, rlhs,
output_table_data (&output_obstack, rlhs,
0, 1, nrules + 1);
muscle_insert ("r1", obstack_finish (&output_obstack));
XFREE (rlhs + 1);
@@ -285,7 +285,7 @@ output_rule_data (void)
for (i = 1; i < nrules; i++)
short_tab[i] = rrhs[i + 1] - rrhs[i] - 1;
short_tab[nrules] = nitems - rrhs[nrules] - 1;
output_table_data (&output_obstack, short_tab,
output_table_data (&output_obstack, short_tab,
0, 1, nrules + 1);
muscle_insert ("r2", obstack_finish (&output_obstack));
XFREE (short_tab);
@@ -534,10 +534,10 @@ token_actions (void)
save_row (i);
}
output_table_data (&output_obstack, yydefact,
output_table_data (&output_obstack, yydefact,
yydefact[0], 1, nstates);
muscle_insert ("defact", obstack_finish (&output_obstack));
XFREE (actrow);
XFREE (yydefact);
}
@@ -675,7 +675,7 @@ goto_actions (void)
yydefgoto[i - ntokens] = default_state;
}
output_table_data (&output_obstack, yydefgoto,
output_table_data (&output_obstack, yydefgoto,
yydefgoto[0], 1, nsyms - ntokens);
muscle_insert ("defgoto", obstack_finish (&output_obstack));
@@ -880,12 +880,12 @@ static void
output_base (void)
{
/* Output pact. */
output_table_data (&output_obstack, base,
output_table_data (&output_obstack, base,
base[0], 1, nstates);
muscle_insert ("pact", obstack_finish (&output_obstack));
/* Output pgoto. */
output_table_data (&output_obstack, base,
output_table_data (&output_obstack, base,
base[nstates], nstates + 1, nvectors);
muscle_insert ("pgoto", obstack_finish (&output_obstack));
@@ -896,7 +896,7 @@ output_base (void)
static void
output_table (void)
{
output_table_data (&output_obstack, table,
output_table_data (&output_obstack, table,
table[0], 1, high + 1);
muscle_insert ("table", obstack_finish (&output_obstack));
XFREE (table);
@@ -906,7 +906,7 @@ output_table (void)
static void
output_check (void)
{
output_table_data (&output_obstack, check,
output_table_data (&output_obstack, check,
check[0], 1, high + 1);
muscle_insert ("check", obstack_finish (&output_obstack));
XFREE (check);
@@ -1109,7 +1109,7 @@ output (void)
output_stos ();
output_rule_data ();
output_actions ();
#if 0
if (!no_parser_flag) */
#endif

View File

@@ -20,7 +20,6 @@
#include "system.h"
#include "xalloc.h"
#include "files.h"
#include "gram.h"
#include "LR0.h"
@@ -35,17 +34,17 @@
static void
print_token (int extnum, int token)
{
obstack_fgrow2 (&output_obstack, _(" type %d is %s\n"), extnum, tags[token]);
fprintf (out, _(" type %d is %s\n"), extnum, tags[token]);
}
#endif
/*================================\
/*--------------------------------.
| Report information on a state. |
\================================*/
`--------------------------------*/
static void
print_core (int state)
print_core (FILE *out, int state)
{
int i;
int k;
@@ -68,30 +67,30 @@ print_core (int state)
sp++;
rule = -(*sp);
obstack_fgrow1 (&output_obstack, " %s -> ", tags[rlhs[rule]]);
fprintf (out, " %s -> ", tags[rlhs[rule]]);
for (sp = ritem + rrhs[rule]; sp < sp1; sp++)
{
obstack_fgrow1 (&output_obstack, "%s ", tags[*sp]);
fprintf (out, "%s ", tags[*sp]);
}
obstack_1grow (&output_obstack, '.');
fputc ('.', out);
while (*sp > 0)
{
obstack_fgrow1 (&output_obstack, " %s", tags[*sp]);
fprintf (out, " %s", tags[*sp]);
sp++;
}
obstack_fgrow1 (&output_obstack, _(" (rule %d)"), rule);
obstack_1grow (&output_obstack, '\n');
fprintf (out, _(" (rule %d)"), rule);
fputc ('\n', out);
}
obstack_1grow (&output_obstack, '\n');
fputc ('\n', out);
}
static void
print_actions (int state)
print_actions (FILE *out, int state)
{
int i;
int k;
@@ -109,9 +108,9 @@ print_actions (int state)
if (!shiftp && !redp)
{
if (final_state == state)
obstack_sgrow (&output_obstack, _(" $default\taccept\n"));
fprintf (out, _(" $default\taccept\n"));
else
obstack_sgrow (&output_obstack, _(" NO ACTIONS\n"));
fprintf (out, _(" NO ACTIONS\n"));
return;
}
@@ -129,16 +128,16 @@ print_actions (int state)
if (ISVAR (symbol))
break;
if (symbol == 0) /* I.e. strcmp(tags[symbol],"$")==0 */
obstack_fgrow1 (&output_obstack,
_(" $ \tgo to state %d\n"), state1);
fprintf (out,
_(" $ \tgo to state %d\n"), state1);
else
obstack_fgrow2 (&output_obstack,
_(" %-4s\tshift, and go to state %d\n"),
tags[symbol], state1);
fprintf (out,
_(" %-4s\tshift, and go to state %d\n"),
tags[symbol], state1);
}
if (i > 0)
obstack_1grow (&output_obstack, '\n');
fputc ('\n', out);
}
else
{
@@ -157,21 +156,20 @@ print_actions (int state)
if (!errp->errs[j])
continue;
symbol = errp->errs[j];
obstack_fgrow1 (&output_obstack, _(" %-4s\terror (nonassociative)\n"),
fprintf (out, _(" %-4s\terror (nonassociative)\n"),
tags[symbol]);
}
if (j > 0)
obstack_1grow (&output_obstack, '\n');
fputc ('\n', out);
}
if (consistent[state] && redp)
{
rule = redp->rules[0];
symbol = rlhs[rule];
obstack_fgrow2 (&output_obstack,
_(" $default\treduce using rule %d (%s)\n\n"),
rule, tags[symbol]);
fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"),
rule, tags[symbol]);
}
else if (redp)
{
@@ -186,42 +184,41 @@ print_actions (int state)
continue;
state1 = shiftp->shifts[i];
symbol = accessing_symbol[state1];
obstack_fgrow2 (&output_obstack,
_(" %-4s\tgo to state %d\n"),
tags[symbol], state1);
fprintf (out, _(" %-4s\tgo to state %d\n"),
tags[symbol], state1);
}
obstack_1grow (&output_obstack, '\n');
fputc ('\n', out);
}
}
static void
print_state (int state)
print_state (FILE *out, int state)
{
obstack_sgrow (&output_obstack, "\n\n");
obstack_fgrow1 (&output_obstack, _("state %d"), state);
obstack_sgrow (&output_obstack, "\n\n");
print_core (state);
print_actions (state);
fputs ("\n\n", out);
fprintf (out, _("state %d"), state);
fputs ("\n\n", out);
print_core (out, state);
print_actions (out, state);
}
/*-----------------------------------------.
| Print information on the whole grammar. |
`-----------------------------------------*/
#define END_TEST(End) \
do { \
if (column + strlen(buffer) > (End)) \
{ \
obstack_fgrow1 (&output_obstack, "%s\n ", buffer); \
column = 3; \
buffer[0] = 0; \
} \
#define END_TEST(End) \
do { \
if (column + strlen(buffer) > (End)) \
{ \
fprintf (out, "%s\n ", buffer); \
column = 3; \
buffer[0] = 0; \
} \
} while (0)
static void
print_grammar (void)
print_grammar (FILE *out)
{
int i, j;
short *rule;
@@ -229,78 +226,46 @@ print_grammar (void)
int column = 0;
/* rule # : LHS -> RHS */
obstack_1grow (&output_obstack, '\n');
obstack_sgrow (&output_obstack, _("Grammar"));
obstack_1grow (&output_obstack, '\n');
fprintf (out, "\n%s\n", _("Grammar"));
for (i = 1; i <= nrules; i++)
/* Don't print rules disabled in reduce_grammar_tables. */
if (rlhs[i] >= 0)
{
obstack_fgrow2 (&output_obstack,
_("rule %-4d %s ->"), i, tags[rlhs[i]]);
fprintf (out, _("rule %-4d %s ->"), i, tags[rlhs[i]]);
rule = &ritem[rrhs[i]];
if (*rule > 0)
while (*rule > 0)
obstack_fgrow1 (&output_obstack, " %s", tags[*rule++]);
fprintf (out, " %s", tags[*rule++]);
else
obstack_sgrow (&output_obstack, _(" /* empty */"));
obstack_1grow (&output_obstack, '\n');
fprintf (out, " /* %s */\n", _("empty"));
}
/* TERMINAL (type #) : rule #s terminal is on RHS */
obstack_sgrow (&output_obstack, "\n");
obstack_sgrow (&output_obstack,
_("Terminals, with rules where they appear"));
obstack_sgrow (&output_obstack, "\n\n");
obstack_fgrow1 (&output_obstack, "%s (-1)\n", tags[0]);
if (translations)
{
for (i = 0; i <= max_user_token_number; i++)
if (token_translations[i] != 2)
{
buffer[0] = 0;
column = strlen (tags[token_translations[i]]);
obstack_sgrow (&output_obstack, tags[token_translations[i]]);
END_TEST (50);
sprintf (buffer, " (%d)", i);
fprintf (out, "\n%s\n\n", _("Terminals, with rules where they appear"));
fprintf (out, "%s (-1)\n", tags[0]);
for (j = 1; j <= nrules; j++)
for (rule = &ritem[rrhs[j]]; *rule > 0; rule++)
if (*rule == token_translations[i])
{
END_TEST (65);
sprintf (buffer + strlen (buffer), " %d", j);
break;
}
obstack_fgrow1 (&output_obstack, "%s\n", buffer);
}
}
else
{
for (i = 1; i < ntokens; i++)
{
buffer[0] = 0;
column = strlen (tags[i]);
obstack_sgrow (&output_obstack, tags[i]);
END_TEST (50);
sprintf (buffer, " (%d)", i);
for (i = 0; i <= max_user_token_number; i++)
if (token_translations[i] != 2)
{
buffer[0] = 0;
column = strlen (tags[token_translations[i]]);
fputs (tags[token_translations[i]], out);
END_TEST (50);
sprintf (buffer, " (%d)", i);
for (j = 1; j <= nrules; j++)
for (rule = &ritem[rrhs[j]]; *rule > 0; rule++)
if (*rule == i)
{
END_TEST (65);
sprintf (buffer + strlen (buffer), " %d", j);
break;
}
obstack_fgrow1 (&output_obstack, "%s\n", buffer);
}
}
for (j = 1; j <= nrules; j++)
for (rule = &ritem[rrhs[j]]; *rule > 0; rule++)
if (*rule == token_translations[i])
{
END_TEST (65);
sprintf (buffer + strlen (buffer), " %d", j);
break;
}
fprintf (out, "%s\n", buffer);
}
obstack_sgrow (&output_obstack, "\n");
obstack_sgrow (&output_obstack,
_("Nonterminals, with rules where they appear"));
obstack_sgrow (&output_obstack, "\n\n");
fprintf (out, "\n%s\n\n",
_("Nonterminals, with rules where they appear"));
for (i = ntokens; i <= nsyms - 1; i++)
{
int left_count = 0, right_count = 0;
@@ -318,7 +283,7 @@ print_grammar (void)
}
buffer[0] = 0;
obstack_sgrow (&output_obstack, tags[i]);
fputs (tags[i], out);
column = strlen (tags[i]);
sprintf (buffer, " (%d)", i);
END_TEST (0);
@@ -353,22 +318,33 @@ print_grammar (void)
}
}
}
obstack_fgrow1 (&output_obstack, "%s\n", buffer);
fprintf (out, "%s\n", buffer);
}
}
void
print_results (void)
{
int i;
if (any_conflicts)
print_conflicts ();
if (verbose_flag)
print_grammar ();
{
int i;
if (verbose_flag)
for (i = 0; i < nstates; i++)
print_state (i);
/* We used to use just .out if spec_name_prefix (-p) was used, but
that conflicts with Posix. */
FILE *out = xfopen (spec_verbose_file, "w");
size_t size = obstack_object_size (&output_obstack);
fwrite (obstack_finish (&output_obstack), 1, size, out);
if (any_conflicts)
print_conflicts (out);
print_grammar (out);
for (i = 0; i < nstates; i++)
print_state (out, i);
xfclose (out);
}
obstack_free (&output_obstack, NULL);
}

View File

@@ -19,7 +19,6 @@
Boston, MA 02111-1307, USA. */
#include "system.h"
#include "xalloc.h"
#include "files.h"
#include "gram.h"
#include "LR0.h"
@@ -35,8 +34,9 @@
#include "quotearg.h"
static graph_t graph;
static FILE *fgraph = NULL;
static unsigned node_output_size = 0;
static size_t node_output_size = 0;
/* Return an unambiguous printable representated, allocated in slot 0,
for NAME, suitable for C strings. */
@@ -136,7 +136,7 @@ print_actions (int state, const char *node_name, struct obstack *node_obstack)
if (state > state1)
edge.type = back_edge;
open_edge (&edge, &graph_obstack);
open_edge (&edge, fgraph);
/* The edge source is the current node. */
edge.sourcename = node_name;
sprintf (buff, "%d", state1);
@@ -145,8 +145,8 @@ print_actions (int state, const char *node_name, struct obstack *node_obstack)
/* FIXME: Be aware that quote uses static memory. The string
must be output immediately (which is the case here). */
edge.label = tags[symbol] ? quote (tags[symbol]) : NULL;
output_edge (&edge, &graph_obstack);
close_edge (&graph_obstack);
output_edge (&edge, fgraph);
close_edge (fgraph);
}
}
}
@@ -198,14 +198,14 @@ print_actions (int state, const char *node_name, struct obstack *node_obstack)
symbol = accessing_symbol[state1];
new_edge (&edge);
open_edge (&edge, &graph_obstack);
open_edge (&edge, fgraph);
edge.sourcename = node_name;
sprintf (buff, "%d", state1);
edge.targetname = buff;
edge.color = red;
edge.label = tags[symbol] ? quote (tags[symbol]) : NULL;
output_edge (&edge, &graph_obstack);
close_edge (&graph_obstack);
output_edge (&edge, fgraph);
close_edge (fgraph);
}
}
}
@@ -223,9 +223,6 @@ print_state (int state)
new_node (&node); /* Set node attributs default value. */
sprintf (name, "%d", state);
node.title = name; /* Give a name to the node. */
open_node (&node_obstack);
/* Output a VCG formatted attributs list. */
output_node (&node, &node_obstack);
{
/* Here we begin to compute the node label. */
@@ -241,15 +238,17 @@ print_state (int state)
print_actions (state, node.title, &node_obstack);
obstack_sgrow (&node_obstack, "\"\n"); /* Close Label. */
close_node (&node_obstack);
}
/* `obstack_cat' NODE_OBSTACK to GRAPH_OBSTACK. */
obstack_grow (&graph_obstack,
obstack_base (&node_obstack),
obstack_object_size (&node_obstack));
obstack_finish (&node_obstack);
}
open_node (fgraph);
/* Output a VCG formatted attributs list. */
output_node (&node, fgraph);
/* Save the node label. */
fwrite (obstack_base (&node_obstack),
obstack_object_size (&node_obstack), 1, fgraph);
close_node (fgraph);
obstack_free (&node_obstack, 0);
}
@@ -257,9 +256,13 @@ void
print_graph (void)
{
int i;
if (!graph_flag)
return;
/* Output file. */
fgraph = xfopen (spec_graph_file, "w");
new_graph (&graph);
#if 0
@@ -268,7 +271,7 @@ print_graph (void)
#endif
graph.display_edge_labels = yes;
graph.layoutalgorithm = 0;
graph.layoutalgorithm = normal;
graph.port_sharing = no;
graph.finetuning = yes;
@@ -279,13 +282,14 @@ print_graph (void)
graph.crossing_weight = median;
/* Output graph options. */
open_graph (&graph_obstack);
output_graph (&graph, &graph_obstack);
open_graph (fgraph);
output_graph (&graph, fgraph);
for (i = 0; i < nstates; i++)
/* Output nodes & edges. */
print_state (i);
/* Close graph. */
close_graph (&graph, &graph_obstack);
close_graph (&graph, fgraph);
xfclose (fgraph);
}

View File

@@ -26,7 +26,6 @@
#include "quote.h"
#include "getargs.h"
#include "files.h"
#include "xalloc.h"
#include "symtab.h"
#include "options.h"
#include "lex.h"
@@ -431,7 +430,7 @@ copy_definition (void)
if (!no_lines_flag)
{
obstack_fgrow2 (&attrs_obstack, muscle_find ("linef"),
lineno, quotearg_style (c_quoting_style,
lineno, quotearg_style (c_quoting_style,
muscle_find("filename")));
}
#endif
@@ -491,8 +490,8 @@ copy_definition (void)
static void
parse_token_decl (symbol_class what_is, symbol_class what_is_not)
{
token_t token = 0;
char *typename = 0;
token_t token = tok_undef;
char *typename = NULL;
/* The symbol being defined. */
struct bucket *symbol = NULL;
@@ -541,7 +540,6 @@ parse_token_decl (symbol_class what_is, symbol_class what_is_not)
/* symbol and symval combined are only one symbol */
nsyms--;
}
translations = 1;
symbol = NULL;
}
else if (token == tok_identifier)
@@ -566,7 +564,6 @@ parse_token_decl (symbol_class what_is, symbol_class what_is_not)
else if (symbol && token == tok_number)
{
symbol->user_token_number = numval;
translations = 1;
}
else
{
@@ -708,7 +705,6 @@ parse_assoc_decl (associativity assoc)
if (prev == tok_identifier)
{
symval->user_token_number = numval;
translations = 1;
}
else
{
@@ -754,7 +750,7 @@ parse_union_decl (void)
if (no_lines_flag)
obstack_1grow (&attrs_obstack, '\n');
obstack_init (&union_obstack);
obstack_sgrow (&union_obstack, "union");
if (defines_flag)
@@ -764,9 +760,13 @@ parse_union_decl (void)
while (c != EOF)
{
obstack_1grow (&union_obstack, c);
if (defines_flag)
obstack_1grow (&defines_obstack, c);
/* If C contains '/', it is output by copy_comment (). */
if (c != '/')
{
obstack_1grow (&attrs_obstack, c);
if (defines_flag)
obstack_1grow (&defines_obstack, c);
}
switch (c)
{
@@ -852,7 +852,6 @@ parse_thong_decl (void)
char *typename = 0;
int usrtoknum;
translations = 1;
token = lex (); /* fetch typename or first token */
if (token == tok_typename)
{
@@ -904,8 +903,6 @@ parse_thong_decl (void)
nsyms--;
}
/* FIXME. */
static void
parse_muscle_decl (void)
{
@@ -923,7 +920,7 @@ parse_muscle_decl (void)
copy_identifier (finput, &muscle_obstack);
obstack_1grow (&muscle_obstack, 0);
muscle_key = obstack_finish (&muscle_obstack);
/* Read value. */
ch = skip_white_space ();
if (ch != '"')
@@ -957,36 +954,6 @@ parse_skel_decl (void)
/* Complete with parse_dquoted_param () on the CVS branch 1.29. */
}
/*------------------------------------------.
| Parse what comes after %header_extension. |
`------------------------------------------*/
static void
parse_header_extension_decl (void)
{
char buff[32];
if (header_extension)
complain (_("multiple %%header_extension declarations"));
fscanf (finput, "%s", buff);
header_extension = xstrdup (buff);
}
/*------------------------------------------.
| Parse what comes after %source_extension. |
`------------------------------------------*/
static void
parse_source_extension_decl (void)
{
char buff[32];
if (src_extension)
complain (_("multiple %%source_extension declarations"));
fscanf (finput, "%s", buff);
src_extension = xstrdup (buff);
}
/*----------------------------------------------------------------.
| Read from finput until `%%' is seen. Discard the `%%'. Handle |
| any `%' declarations, and copy the contents of any `%{ ... %}' |
@@ -1056,18 +1023,10 @@ read_declarations (void)
parse_assoc_decl (non_assoc);
break;
case tok_hdrext:
parse_header_extension_decl ();
break;
case tok_srcext:
parse_source_extension_decl ();
break;
case tok_define:
parse_muscle_decl ();
break;
case tok_skel:
parse_skel_decl ();
break;
@@ -1115,7 +1074,7 @@ copy_action (symbol_list *rule, int stack_offset)
if (!no_lines_flag)
{
obstack_fgrow2 (&action_obstack, muscle_find ("linef"),
lineno, quotearg_style (c_quoting_style,
lineno, quotearg_style (c_quoting_style,
muscle_find ("filename")));
}
obstack_1grow (&action_obstack, '{');
@@ -1678,12 +1637,12 @@ read_additionnal_code (void)
{
char c;
struct obstack el_obstack;
obstack_init (&el_obstack);
while ((c = getc (finput)) != EOF)
obstack_1grow (&el_obstack, c);
obstack_1grow (&el_obstack, 0);
muscle_insert ("epilogue", obstack_finish (&el_obstack));
}
@@ -1729,9 +1688,10 @@ output_token_defines (struct obstack *oout)
continue;
obstack_fgrow2 (oout, "# define\t%s\t%d\n",
symbol,
(translations ? bp->user_token_number : bp->value));
symbol, bp->user_token_number);
if (semantic_parser)
/* FIXME: This is certainly dead wrong, and should be just as
above. --akim. */
obstack_fgrow2 (oout, "# define\tT%s\t%d\n", symbol, bp->value);
}
}
@@ -1746,9 +1706,9 @@ output_token_defines (struct obstack *oout)
static void
packsymbols (void)
{
bucket *bp;
bucket *bp = NULL;
int tokno = 1;
int i;
int i, j;
int last_user_token_number;
static char DOLLAR[] = "$";
@@ -1812,7 +1772,7 @@ packsymbols (void)
if (bp->class == token_sym)
{
if (translations && !(bp->user_token_number))
if (!bp->user_token_number)
bp->user_token_number = ++last_user_token_number;
if (bp->user_token_number > max_user_token_number)
max_user_token_number = bp->user_token_number;
@@ -1822,40 +1782,39 @@ packsymbols (void)
user_toknums[bp->value] = bp->user_token_number;
sprec[bp->value] = bp->prec;
sassoc[bp->value] = bp->assoc;
}
if (translations)
token_translations = XCALLOC (short, max_user_token_number + 1);
/* initialize all entries for literal tokens to 2, the internal
token number for $undefined., which represents all invalid
inputs. */
for (j = 0; j <= max_user_token_number; j++)
token_translations[j] = 2;
for (bp = firstsymbol; bp; bp = bp->next)
{
int j;
token_translations = XCALLOC (short, max_user_token_number + 1);
/* initialize all entries for literal tokens to 2, the internal
token number for $undefined., which represents all invalid
inputs. */
for (j = 0; j <= max_user_token_number; j++)
token_translations[j] = 2;
for (bp = firstsymbol; bp; bp = bp->next)
{
if (bp->value >= ntokens)
continue; /* non-terminal */
if (bp->user_token_number == SALIAS)
continue;
if (token_translations[bp->user_token_number] != 2)
complain (_("tokens %s and %s both assigned number %d"),
tags[token_translations[bp->user_token_number]],
bp->tag, bp->user_token_number);
token_translations[bp->user_token_number] = bp->value;
}
if (bp->value >= ntokens)
continue; /* non-terminal */
if (bp->user_token_number == SALIAS)
continue;
if (token_translations[bp->user_token_number] != 2)
complain (_("tokens %s and %s both assigned number %d"),
tags[token_translations[bp->user_token_number]],
bp->tag, bp->user_token_number);
token_translations[bp->user_token_number] = bp->value;
}
error_token_number = errtoken->value;
output_token_defines (&output_obstack);
obstack_1grow (&output_obstack, 0);
muscle_insert ("tokendef", obstack_finish (&output_obstack));
{
struct obstack tokendefs;
obstack_init (&tokendefs);
output_token_defines (&tokendefs);
obstack_1grow (&tokendefs, 0);
muscle_insert ("tokendef", xstrdup (obstack_finish (&tokendefs)));
obstack_free (&tokendefs, NULL);
}
#if 0
if (!no_parser_flag)
@@ -1980,15 +1939,6 @@ reader (void)
start_flag = 0;
startval = NULL; /* start symbol not specified yet. */
#if 0
/* initially assume token number translation not needed. */
translations = 0;
#endif
/* Nowadays translations is always set to 1, since we give `error' a
user-token-number to satisfy the Posix demand for YYERRCODE==256.
*/
translations = 1;
nsyms = 1;
nvars = 0;
nrules = 0;
@@ -2004,7 +1954,7 @@ reader (void)
grammar = NULL;
init_lex ();
lex_init ();
lineno = 1;
/* Initialize the muscle obstack. */
@@ -2043,7 +1993,4 @@ reader (void)
packsymbols ();
/* Convert the grammar into the format described in gram.h. */
packgram ();
/* Free the symbol table data structure since symbols are now all
referred to by symbol number. */
free_symtab ();
}

View File

@@ -29,7 +29,6 @@
#include "getargs.h"
#include "files.h"
#include "gram.h"
#include "xalloc.h"
#include "complain.h"
#include "reduce.h"
#include "reader.h"
@@ -117,7 +116,7 @@ static void
useless_nonterminals (void)
{
BSet Np, Ns;
int i, n;
int i;
/* N is set as built. Np is set being built this iteration. P is
set of all productions which have a RHS all in N. */
@@ -140,7 +139,6 @@ useless_nonterminals (void)
saved to be used when finding useful productions: only
productions in this set will appear in the final grammar. */
n = 0;
while (1)
{
for (i = WORDSIZE (nvars) - 1; i >= 0; i--)
@@ -171,7 +169,7 @@ static void
inaccessable_symbols (void)
{
BSet Vp, Vs, Pp;
int i, n;
int i;
short t;
rule r;
@@ -207,7 +205,6 @@ inaccessable_symbols (void)
SETBIT (V, start_symbol);
n = 0;
while (1)
{
for (i = WORDSIZE (nsyms) - 1; i >= 0; i--)

View File

@@ -20,7 +20,6 @@
#include "system.h"
#include "xalloc.h"
#include "symtab.h"
#include "gram.h"
@@ -143,6 +142,7 @@ free_symtab (void)
if (bp->type_name)
XFREE (bp->type_name);
#endif
XFREE (bp->tag);
XFREE (bp);
bp = bptmp;
}

View File

@@ -73,7 +73,7 @@ extern int errno;
# define PARAMS(p) ()
#endif
# include "xalloc.h"
/*---------------------.
| Missing prototypes. |
@@ -143,8 +143,6 @@ size_t strnlen PARAMS ((const char *s, size_t maxlen));
# define LOCALEDIR "/usr/local/share/locale"
#endif
#endif /* BISON_SYSTEM_H */
/*-----------.
| Booleans. |
@@ -161,9 +159,9 @@ typedef int bool;
| Obstacks. |
`-----------*/
#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
#include "obstack.h"
# define obstack_chunk_alloc xmalloc
# define obstack_chunk_free free
# include "obstack.h"
#define obstack_sgrow(Obs, Str) \
obstack_grow (Obs, Str, strlen (Str))
@@ -264,3 +262,15 @@ do { \
# define BISON_HAIRY "c:/usr/local/lib/bison.hairy"
# endif
#endif
/*---------------------------------.
| Debugging the memory allocator. |
`---------------------------------*/
# if WITH_DMALLOC
# define DMALLOC_FUNC_CHECK
# include <dmalloc.h>
# endif /* WITH_DMALLOC */
#endif /* BISON_SYSTEM_H */

449
src/vcg.c
View File

@@ -21,8 +21,6 @@
#include "system.h"
#include "vcg.h"
#include "vcg_defaults.h"
#include "xalloc.h"
#include "complain.h"
/* Initialize a graph with the default values. */
void
@@ -51,6 +49,9 @@ new_graph (graph_t *g)
g->textmode = G_TEXTMODE;
g->shape = G_SHAPE;
g->vertical_order = G_VERTICAL_ORDER;
g->horizontal_order = G_HORIZONTAL_ORDER;
g->xmax = G_XMAX; /* Not output. */
g->ymax = G_YMAX; /* Not output. */
@@ -231,8 +232,7 @@ get_color_str (enum color_e c)
case orchid: return "orchid";
case black: return "black";
default:
complain (_("vcg graph: no such color."));
return get_color_str(G_COLOR);
assert (!"Not a default color.");
}
return NULL;
}
@@ -246,8 +246,7 @@ get_textmode_str (enum textmode_e t)
case left_justify: return "left_justify";
case right_justify: return "right_justify";
default:
complain (_("vcg graph: no such text mode"));
return get_textmode_str(G_TEXTMODE);
assert (!"Not a text mode.");
}
return NULL;
}
@@ -262,8 +261,7 @@ get_shape_str (enum shape_e s)
case ellipse: return "ellipse";
case triangle: return "triangle";
default:
complain (_("vcg graph: no such shape"));
return get_shape_str(G_SHAPE);
assert (!"Not a shape.");
}
return NULL;
}
@@ -288,21 +286,20 @@ get_layoutalgorithm_str (enum layoutalgorithm_e l)
case dfs: return "dfs";
case tree: return "tree";
default:
return "normal";
assert (!"Not a layout algorithm.");
}
return NULL;
}
static const char *
get_decision_str (enum decision_e d, enum decision_e defaults)
get_decision_str (enum decision_e d)
{
switch (d)
{
case no: return "no";
case yes: return "yes";
default:
complain (_("vcg graph: no such decision"));
return get_decision_str(defaults, 0);
assert (!"Either yes nor no.");
}
return NULL;
}
@@ -317,8 +314,7 @@ get_orientation_str (enum orientation_e o)
case left_to_right: return "left_to_right";
case right_to_left: return "right_to_left";
default:
complain (_("vcg graph: no such an orientation"));
return get_orientation_str(G_ORIENTATION);
assert (!"Not an orientation.");
}
return NULL;
}
@@ -332,8 +328,7 @@ get_node_alignement_str (enum alignement_e a)
case top: return "top";
case bottom: return "bottom";
default:
complain (_("vcg graph: no such an alignement"));
return get_node_alignement_str(G_NODE_ALIGNEMENT);
assert (!"Not an alignement.");
}
return NULL;
}
@@ -346,8 +341,7 @@ get_arrow_mode_str (enum arrow_mode_e a)
case fixed: return "fixed";
case free_a: return "free";
default:
complain (_("vcg graph: no such an arrow mode"));
return get_arrow_mode_str(G_ARROW_MODE);
assert (!"Not an arrow mode.");
}
return NULL;
}
@@ -362,8 +356,7 @@ get_crossing_type_str (enum crossing_type_e c)
case barymedian: return "barymedian";
case medianbary: return "medianbary";
default:
complain (_("vcg graph: no such crossing_type"));
return get_crossing_type_str(G_CROSSING_WEIGHT);
assert (!"Not a crossing type.");
}
return NULL;
}
@@ -379,8 +372,7 @@ get_view_str (enum view_e v)
case fcfish: return "fcfish";
case fpfish: return "fpfish";
default:
complain (_("vcg graph: no such view"));
return get_view_str(G_VIEW);
assert (!"Not a view.");
}
return NULL;
}
@@ -395,8 +387,7 @@ get_linestyle_str (enum linestyle_e l)
case dotted: return "dotted";
case invisible: return "invisible";
default:
complain (_("vcg graph: no such linestyle"));
return get_linestyle_str(E_LINESTYLE);
assert (!"Not a line style.");
}
return NULL;
}
@@ -410,8 +401,7 @@ get_arrowstyle_str (enum arrowstyle_e a)
case line: return "line";
case none: return "none";
default:
complain (_("vcg graph: no such an arrowstyle"));
return get_arrowstyle_str(E_ARROWSTYLE);
assert (!"Not an arrow style.");
}
return NULL;
}
@@ -435,402 +425,461 @@ add_edge (graph_t *graph, edge_t *edge)
graph->edge_list = edge;
}
void
add_classname (graph_t *g, int val, const char *name)
{
struct classname_s *classname;
classname = XMALLOC (struct classname_s, 1);
classname->no = val;
classname->name = name;
classname->next = g->classname;
g->classname = classname;
}
void
add_infoname (graph_t *g, int integer, const char *string)
{
struct infoname_s *infoname;
infoname = XMALLOC (struct infoname_s, 1);
infoname->integer = integer;
infoname->string = string;
infoname->next = g->infoname;
g->infoname = infoname;
}
/* Build a colorentry struct and add it to the list. */
void
add_colorentry (graph_t *g, int color_idx, int red_cp,
int green_cp, int blue_cp)
{
struct colorentry_s *ce;
ce = XMALLOC (struct colorentry_s, 1);
ce->color_index = color_idx;
ce->red_cp = red_cp;
ce->green_cp = green_cp;
ce->blue_cp = blue_cp;
ce->next = g->colorentry;
g->colorentry = ce;
}
/*-------------------------------------.
| Open and close functions (formatted) |
`-------------------------------------*/
void
open_edge(edge_t *edge, struct obstack *os)
open_edge(edge_t *edge, FILE *fout)
{
switch (edge->type)
{
case normal_edge:
obstack_sgrow (os, "\tedge: {\n");
fputs ("\tedge: {\n", fout);
break;
case back_edge:
obstack_sgrow (os, "\tbackedge: {\n");
fputs ("\tbackedge: {\n", fout);
break;
case near_edge:
obstack_sgrow (os, "\tnearedge: {\n");
fputs ("\tnearedge: {\n", fout);
break;
case bent_near_edge:
obstack_sgrow (os, "\tbentnearedge: {\n");
fputs ("\tbentnearedge: {\n", fout);
break;
default:
obstack_sgrow (os, "\tedge: {\n");
fputs ("\tedge: {\n", fout);
}
}
void
close_edge(struct obstack *os)
close_edge(FILE *fout)
{
obstack_sgrow (os, "\t}\n");
fputs ("\t}\n", fout);
}
void
open_node(struct obstack *os)
open_node(FILE *fout)
{
obstack_sgrow (os, "\tnode: {\n");
fputs ("\tnode: {\n", fout);
}
void
close_node(struct obstack *os)
close_node(FILE *fout)
{
obstack_sgrow (os, "\t}\n");
fputs ("\t}\n", fout);
}
void
open_graph(struct obstack *os)
open_graph(FILE *fout)
{
obstack_sgrow (os, "graph: {\n");
fputs ("graph: {\n", fout);
}
void
close_graph(graph_t *graph, struct obstack *os)
close_graph(graph_t *graph, FILE *fout)
{
obstack_1grow (os, '\n');
fputc ('\n', fout);
/* FIXME: Unallocate nodes and edges if required. */
{
node_t *node;
for (node = graph->node_list; node; node = node->next)
{
open_node (os);
output_node (node, os);
close_node (os);
open_node (fout);
output_node (node, fout);
close_node (fout);
}
}
obstack_1grow (os, '\n');
fputc ('\n', fout);
{
edge_t *edge;
for (edge = graph->edge_list; edge; edge = edge->next)
{
open_edge (edge, os);
output_edge (edge, os);
close_edge (os);
open_edge (edge, fout);
output_edge (edge, fout);
close_edge (fout);
}
}
obstack_sgrow (os, "}\n");
fputs ("}\n", fout);
}
/*-------------------------------------------.
| Output functions (formatted) in obstack os |
| Output functions (formatted) in file FOUT |
`-------------------------------------------*/
void
output_node (node_t *node, struct obstack *os)
output_node (node_t *node, FILE *fout)
{
if (node->title != N_TITLE)
obstack_fgrow1 (os, "\t\ttitle:\t\"%s\"\n", node->title);
fprintf (fout, "\t\ttitle:\t\"%s\"\n", node->title);
if (node->label != N_LABEL)
obstack_fgrow1 (os, "\t\tlabel:\t\"%s\"\n", node->label);
fprintf (fout, "\t\tlabel:\t\"%s\"\n", node->label);
if ((node->locx != N_LOCX) && (node->locy != N_LOCY))
obstack_fgrow2 (os, "\t\tloc { x: %d y: %d }\t\n", node->locx, node->locy);
fprintf (fout, "\t\tloc { x: %d y: %d }\t\n", node->locx, node->locy);
if (node->vertical_order != N_VERTICAL_ORDER)
obstack_fgrow1 (os, "\t\tvertical_order:\t%d\n", node->vertical_order);
fprintf (fout, "\t\tvertical_order:\t%d\n", node->vertical_order);
if (node->horizontal_order != N_HORIZONTAL_ORDER)
obstack_fgrow1 (os, "\t\thorizontal_order:\t%d\n", node->horizontal_order);
fprintf (fout, "\t\thorizontal_order:\t%d\n", node->horizontal_order);
if (node->width != N_WIDTH)
obstack_fgrow1 (os, "\t\twidth:\t%d\n", node->width);
fprintf (fout, "\t\twidth:\t%d\n", node->width);
if (node->height != N_HEIGHT)
obstack_fgrow1 (os, "\t\theight:\t%d\n", node->height);
fprintf (fout, "\t\theight:\t%d\n", node->height);
if (node->shrink != N_SHRINK)
obstack_fgrow1 (os, "\t\tshrink:\t%d\n", node->shrink);
fprintf (fout, "\t\tshrink:\t%d\n", node->shrink);
if (node->stretch != N_STRETCH)
obstack_fgrow1 (os, "\t\tstretch:\t%d\n", node->stretch);
fprintf (fout, "\t\tstretch:\t%d\n", node->stretch);
if (node->folding != N_FOLDING)
obstack_fgrow1 (os, "\t\tfolding:\t%d\n", node->folding);
fprintf (fout, "\t\tfolding:\t%d\n", node->folding);
if (node->textmode != N_TEXTMODE)
obstack_fgrow1 (os, "\t\ttextmode:\t%s\n",
get_textmode_str (node->textmode));
fprintf (fout, "\t\ttextmode:\t%s\n",
get_textmode_str (node->textmode));
if (node->shape != N_SHAPE)
obstack_fgrow1 (os, "\t\tshape:\t%s\n", get_shape_str (node->shape));
fprintf (fout, "\t\tshape:\t%s\n", get_shape_str (node->shape));
if (node->borderwidth != N_BORDERWIDTH)
obstack_fgrow1 (os, "\t\tborderwidth:\t%d\n", node->borderwidth);
fprintf (fout, "\t\tborderwidth:\t%d\n", node->borderwidth);
if (node->color != N_COLOR)
obstack_fgrow1 (os, "\t\tcolor:\t%s\n", get_color_str (node->color));
fprintf (fout, "\t\tcolor:\t%s\n", get_color_str (node->color));
if (node->textcolor != N_TEXTCOLOR)
obstack_fgrow1 (os, "\t\ttextcolor:\t%s\n",
get_color_str (node->textcolor));
fprintf (fout, "\t\ttextcolor:\t%s\n",
get_color_str (node->textcolor));
if (node->bordercolor != N_BORDERCOLOR)
obstack_fgrow1 (os, "\t\tbordercolor:\t%s\n",
get_color_str (node->bordercolor));
fprintf (fout, "\t\tbordercolor:\t%s\n",
get_color_str (node->bordercolor));
if (node->infos[0])
obstack_fgrow1 (os, "\t\tinfo1:\t\"%s\"\n", node->infos[0]);
fprintf (fout, "\t\tinfo1:\t\"%s\"\n", node->infos[0]);
if (node->infos[1])
obstack_fgrow1 (os, "\t\tinfo2:\t\"%s\"\n", node->infos[1]);
fprintf (fout, "\t\tinfo2:\t\"%s\"\n", node->infos[1]);
if (node->infos[2])
obstack_fgrow1 (os, "\t\tinfo3:\t\"%s\"\n", node->infos[2]);
fprintf (fout, "\t\tinfo3:\t\"%s\"\n", node->infos[2]);
}
void
output_edge (edge_t *edge, struct obstack *os)
output_edge (edge_t *edge, FILE *fout)
{
/* FIXME: SOURCENAME and TARGETNAME are mandatory
so it has to be fatal not to give these informations. */
if (edge->sourcename != E_SOURCENAME)
obstack_fgrow1 (os, "\t\tsourcename:\t\"%s\"\n", edge->sourcename);
fprintf (fout, "\t\tsourcename:\t\"%s\"\n", edge->sourcename);
if (edge->targetname != E_TARGETNAME)
obstack_fgrow1 (os, "\t\ttargetname:\t\"%s\"\n", edge->targetname);
fprintf (fout, "\t\ttargetname:\t\"%s\"\n", edge->targetname);
if (edge->label != E_LABEL)
obstack_fgrow1 (os, "\t\tlabel:\t\"%s\"\n", edge->label);
fprintf (fout, "\t\tlabel:\t\"%s\"\n", edge->label);
if (edge->linestyle != E_LINESTYLE)
obstack_fgrow1 (os, "\t\tlinestyle:\t\"%s\"\n",
get_linestyle_str(edge->linestyle));
fprintf (fout, "\t\tlinestyle:\t\"%s\"\n",
get_linestyle_str(edge->linestyle));
if (edge->thickness != E_THICKNESS)
obstack_fgrow1 (os, "\t\tthickness:\t%d\n", edge->thickness);
fprintf (fout, "\t\tthickness:\t%d\n", edge->thickness);
if (edge->class != E_CLASS)
obstack_fgrow1 (os, "\t\tclass:\t%d\n", edge->class);
fprintf (fout, "\t\tclass:\t%d\n", edge->class);
if (edge->color != E_COLOR)
obstack_fgrow1 (os, "\t\tcolor:\t%s\n", get_color_str (edge->color));
fprintf (fout, "\t\tcolor:\t%s\n", get_color_str (edge->color));
if (edge->color != E_TEXTCOLOR)
obstack_fgrow1 (os, "\t\ttextcolor:\t%s\n",
get_color_str (edge->textcolor));
fprintf (fout, "\t\ttextcolor:\t%s\n",
get_color_str (edge->textcolor));
if (edge->arrowcolor != E_ARROWCOLOR)
obstack_fgrow1 (os, "\t\tarrowcolor:\t%s\n",
get_color_str (edge->arrowcolor));
fprintf (fout, "\t\tarrowcolor:\t%s\n",
get_color_str (edge->arrowcolor));
if (edge->backarrowcolor != E_BACKARROWCOLOR)
obstack_fgrow1 (os, "\t\tbackarrowcolor:\t%s\n",
get_color_str (edge->backarrowcolor));
fprintf (fout, "\t\tbackarrowcolor:\t%s\n",
get_color_str (edge->backarrowcolor));
if (edge->arrowsize != E_ARROWSIZE)
obstack_fgrow1 (os, "\t\tarrowsize:\t%d\n", edge->arrowsize);
fprintf (fout, "\t\tarrowsize:\t%d\n", edge->arrowsize);
if (edge->backarrowsize != E_BACKARROWSIZE)
obstack_fgrow1 (os, "\t\tbackarrowsize:\t%d\n", edge->backarrowsize);
fprintf (fout, "\t\tbackarrowsize:\t%d\n", edge->backarrowsize);
if (edge->arrowstyle != E_ARROWSTYLE)
obstack_fgrow1 (os, "\t\tarrowstyle:\t%s\n",
get_arrowstyle_str(edge->arrowstyle));
fprintf (fout, "\t\tarrowstyle:\t%s\n",
get_arrowstyle_str(edge->arrowstyle));
if (edge->backarrowstyle != E_BACKARROWSTYLE)
obstack_fgrow1 (os, "\t\tbackarrowstyle:\t%s\n",
get_arrowstyle_str(edge->backarrowstyle));
fprintf (fout, "\t\tbackarrowstyle:\t%s\n",
get_arrowstyle_str(edge->backarrowstyle));
if (edge->priority != E_PRIORITY)
obstack_fgrow1 (os, "\t\tpriority:\t%d\n", edge->priority);
fprintf (fout, "\t\tpriority:\t%d\n", edge->priority);
if (edge->anchor != E_ANCHOR)
obstack_fgrow1 (os, "\t\tanchor:\t%d\n", edge->anchor);
fprintf (fout, "\t\tanchor:\t%d\n", edge->anchor);
if (edge->horizontal_order != E_HORIZONTAL_ORDER)
obstack_fgrow1 (os, "\t\thorizontal_order:\t%d\n", edge->horizontal_order);
fprintf (fout, "\t\thorizontal_order:\t%d\n", edge->horizontal_order);
}
void
output_graph (graph_t *graph, struct obstack *os)
output_graph (graph_t *graph, FILE *fout)
{
if (graph->title)
obstack_fgrow1 (os, "\ttitle:\t\"%s\"\n", graph->title);
fprintf (fout, "\ttitle:\t\"%s\"\n", graph->title);
if (graph->label)
obstack_fgrow1 (os, "\tlabel:\t\"%s\"\n", graph->label);
fprintf (fout, "\tlabel:\t\"%s\"\n", graph->label);
if (graph->infos[0])
obstack_fgrow1 (os, "\tinfo1:\t\"%s\"\n", graph->infos[0]);
fprintf (fout, "\tinfo1:\t\"%s\"\n", graph->infos[0]);
if (graph->infos[1])
obstack_fgrow1 (os, "\tinfo2:\t\"%s\"\n", graph->infos[1]);
fprintf (fout, "\tinfo2:\t\"%s\"\n", graph->infos[1]);
if (graph->infos[2])
obstack_fgrow1 (os, "\tinfo3:\t\"%s\"\n", graph->infos[2]);
fprintf (fout, "\tinfo3:\t\"%s\"\n", graph->infos[2]);
if (graph->color != G_COLOR)
obstack_fgrow1 (os, "\tcolor:\t%s\n", get_color_str (graph->color));
fprintf (fout, "\tcolor:\t%s\n", get_color_str (graph->color));
if (graph->textcolor != G_TEXTCOLOR)
obstack_fgrow1 (os, "\ttextcolor:\t%s\n", get_color_str (graph->textcolor));
fprintf (fout, "\ttextcolor:\t%s\n", get_color_str (graph->textcolor));
if (graph->bordercolor != G_BORDERCOLOR)
obstack_fgrow1 (os, "\tbordercolor:\t%s\n",
get_color_str (graph->bordercolor));
fprintf (fout, "\tbordercolor:\t%s\n",
get_color_str (graph->bordercolor));
if (graph->width != G_WIDTH)
obstack_fgrow1 (os, "\twidth:\t%d\n", graph->width);
fprintf (fout, "\twidth:\t%d\n", graph->width);
if (graph->height != G_HEIGHT)
obstack_fgrow1 (os, "\theight:\t%d\n", graph->height);
fprintf (fout, "\theight:\t%d\n", graph->height);
if (graph->borderwidth != G_BORDERWIDTH)
obstack_fgrow1 (os, "\tborderwidth:\t%d\n", graph->borderwidth);
fprintf (fout, "\tborderwidth:\t%d\n", graph->borderwidth);
if (graph->x != G_X)
obstack_fgrow1 (os, "\tx:\t%d\n", graph->x);
fprintf (fout, "\tx:\t%d\n", graph->x);
if (graph->y != G_Y)
obstack_fgrow1 (os, "\ty:\t%d\n", graph->y);
fprintf (fout, "\ty:\t%d\n", graph->y);
if (graph->folding != G_FOLDING)
obstack_fgrow1 (os, "\tfolding:\t%d\n", graph->folding);
fprintf (fout, "\tfolding:\t%d\n", graph->folding);
if (graph->shrink != G_SHRINK)
obstack_fgrow1 (os, "\tshrink:\t%d\n", graph->shrink);
fprintf (fout, "\tshrink:\t%d\n", graph->shrink);
if (graph->stretch != G_STRETCH)
obstack_fgrow1 (os, "\tstretch:\t%d\n", graph->stretch);
fprintf (fout, "\tstretch:\t%d\n", graph->stretch);
if (graph->textmode != G_TEXTMODE)
obstack_fgrow1 (os, "\ttextmode:\t%s\n",
get_textmode_str (graph->textmode));
fprintf (fout, "\ttextmode:\t%s\n",
get_textmode_str (graph->textmode));
if (graph->shape != G_SHAPE)
obstack_fgrow1 (os, "\tshape:\t%s\n", get_shape_str (graph->shape));
fprintf (fout, "\tshape:\t%s\n", get_shape_str (graph->shape));
if (graph->vertical_order != G_VERTICAL_ORDER)
fprintf (fout, "\tvertical_order:\t%d\n", graph->vertical_order);
if (graph->horizontal_order != G_HORIZONTAL_ORDER)
fprintf (fout, "\thorizontal_order:\t%d\n", graph->horizontal_order);
if (graph->xmax != G_XMAX)
obstack_fgrow1 (os, "\txmax:\t%d\n", graph->xmax);
fprintf (fout, "\txmax:\t%d\n", graph->xmax);
if (graph->ymax != G_YMAX)
obstack_fgrow1 (os, "\tymax:\t%d\n", graph->ymax);
fprintf (fout, "\tymax:\t%d\n", graph->ymax);
if (graph->xbase != G_XBASE)
obstack_fgrow1 (os, "\txbase:\t%d\n", graph->xbase);
fprintf (fout, "\txbase:\t%d\n", graph->xbase);
if (graph->ybase != G_YBASE)
obstack_fgrow1 (os, "\tybase:\t%d\n", graph->ybase);
fprintf (fout, "\tybase:\t%d\n", graph->ybase);
if (graph->xspace != G_XSPACE)
obstack_fgrow1 (os, "\txspace:\t%d\n", graph->xspace);
fprintf (fout, "\txspace:\t%d\n", graph->xspace);
if (graph->yspace != G_YSPACE)
obstack_fgrow1 (os, "\tyspace:\t%d\n", graph->yspace);
fprintf (fout, "\tyspace:\t%d\n", graph->yspace);
if (graph->xlspace != G_XLSPACE)
obstack_fgrow1 (os, "\txlspace:\t%d\n", graph->xlspace);
fprintf (fout, "\txlspace:\t%d\n", graph->xlspace);
if (graph->xraster != G_XRASTER)
obstack_fgrow1 (os, "\txraster:\t%d\n", graph->xraster);
fprintf (fout, "\txraster:\t%d\n", graph->xraster);
if (graph->yraster != G_YRASTER)
obstack_fgrow1 (os, "\tyraster:\t%d\n", graph->yraster);
fprintf (fout, "\tyraster:\t%d\n", graph->yraster);
if (graph->xlraster != G_XLRASTER)
obstack_fgrow1 (os, "\txlraster:\t%d\n", graph->xlraster);
fprintf (fout, "\txlraster:\t%d\n", graph->xlraster);
if (graph->hidden != G_HIDDEN)
obstack_fgrow1 (os, "\thidden:\t%d\n", graph->hidden);
fprintf (fout, "\thidden:\t%d\n", graph->hidden);
/* FIXME: Unallocate struct list if required.
Maybe with a little function. */
if (graph->classname != G_CLASSNAME)
{
struct classname_s *ite;
for (ite = graph->classname; ite; ite = ite->next)
obstack_fgrow2 (os, "\tclassname %d :\t%s\n", ite->no, ite->name);
fprintf (fout, "\tclassname %d :\t%s\n", ite->no, ite->name);
}
if (graph->infoname != G_INFONAME)
{
struct infoname_s *ite;
for (ite = graph->infoname; ite; ite = ite->next)
fprintf (fout, "\tinfoname %d :\t%s\n", ite->integer, ite->string);
}
if (graph->colorentry != G_COLORENTRY)
{
struct colorentry_s *ite;
for (ite = graph->colorentry; ite; ite = ite->next)
{
fprintf (fout, "\tcolorentry %d :\t%d %d %d\n",
ite->color_index,
ite->red_cp,
ite->green_cp,
ite->blue_cp);
}
}
if (graph->layoutalgorithm != G_LAYOUTALGORITHM)
obstack_fgrow1 (os, "\tlayoutalgorithm:\t%s\n",
get_layoutalgorithm_str(graph->layoutalgorithm));
fprintf (fout, "\tlayoutalgorithm:\t%s\n",
get_layoutalgorithm_str(graph->layoutalgorithm));
if (graph->layout_downfactor != G_LAYOUT_DOWNFACTOR)
obstack_fgrow1 (os, "\tlayout_downfactor:\t%d\n", graph->layout_downfactor);
fprintf (fout, "\tlayout_downfactor:\t%d\n", graph->layout_downfactor);
if (graph->layout_upfactor != G_LAYOUT_UPFACTOR)
obstack_fgrow1 (os, "\tlayout_upfactor:\t%d\n", graph->layout_upfactor);
fprintf (fout, "\tlayout_upfactor:\t%d\n", graph->layout_upfactor);
if (graph->layout_nearfactor != G_LAYOUT_NEARFACTOR)
obstack_fgrow1 (os, "\tlayout_nearfactor:\t%d\n", graph->layout_nearfactor);
fprintf (fout, "\tlayout_nearfactor:\t%d\n", graph->layout_nearfactor);
if (graph->layout_splinefactor != G_LAYOUT_SPLINEFACTOR)
obstack_fgrow1 (os, "\tlayout_splinefactor:\t%d\n",
graph->layout_splinefactor);
fprintf (fout, "\tlayout_splinefactor:\t%d\n",
graph->layout_splinefactor);
if (graph->late_edge_labels != G_LATE_EDGE_LABELS)
obstack_fgrow1 (os, "\tlate_edge_labels:\t%s\n",
get_decision_str(graph->late_edge_labels,
G_LATE_EDGE_LABELS));
fprintf (fout, "\tlate_edge_labels:\t%s\n",
get_decision_str(graph->late_edge_labels));
if (graph->display_edge_labels != G_DISPLAY_EDGE_LABELS)
obstack_fgrow1 (os, "\tdisplay_edge_labels:\t%s\n",
get_decision_str(graph->display_edge_labels,
G_DISPLAY_EDGE_LABELS));
fprintf (fout, "\tdisplay_edge_labels:\t%s\n",
get_decision_str(graph->display_edge_labels));
if (graph->dirty_edge_labels != G_DIRTY_EDGE_LABELS)
obstack_fgrow1 (os, "\tdirty_edge_labels:\t%s\n",
get_decision_str(graph->dirty_edge_labels,
G_DIRTY_EDGE_LABELS));
fprintf (fout, "\tdirty_edge_labels:\t%s\n",
get_decision_str(graph->dirty_edge_labels));
if (graph->finetuning != G_FINETUNING)
obstack_fgrow1 (os, "\tfinetuning:\t%s\n",
get_decision_str(graph->finetuning, G_FINETUNING));
fprintf (fout, "\tfinetuning:\t%s\n",
get_decision_str(graph->finetuning));
if (graph->ignore_singles != G_IGNORE_SINGLES)
obstack_fgrow1 (os, "\tignore_singles:\t%s\n",
get_decision_str(graph->ignore_singles, G_IGNORE_SINGLES));
fprintf (fout, "\tignore_singles:\t%s\n",
get_decision_str(graph->ignore_singles));
if (graph->straight_phase != G_STRAIGHT_PHASE)
obstack_fgrow1 (os, "\tstraight_phase:\t%s\n",
get_decision_str(graph->straight_phase, G_STRAIGHT_PHASE));
fprintf (fout, "\tstraight_phase:\t%s\n",
get_decision_str(graph->straight_phase));
if (graph->priority_phase != G_PRIORITY_PHASE)
obstack_fgrow1 (os, "\tpriority_phase:\t%s\n",
get_decision_str(graph->priority_phase, G_PRIORITY_PHASE));
fprintf (fout, "\tpriority_phase:\t%s\n",
get_decision_str(graph->priority_phase));
if (graph->manhattan_edges != G_MANHATTAN_EDGES)
obstack_fgrow1 (os,
"\tmanhattan_edges:\t%s\n",
get_decision_str(graph->manhattan_edges,
G_MANHATTAN_EDGES));
fprintf (fout,
"\tmanhattan_edges:\t%s\n",
get_decision_str(graph->manhattan_edges));
if (graph->smanhattan_edges != G_SMANHATTAN_EDGES)
obstack_fgrow1 (os,
"\tsmanhattan_edges:\t%s\n",
get_decision_str(graph->smanhattan_edges,
G_SMANHATTAN_EDGES));
fprintf (fout,
"\tsmanhattan_edges:\t%s\n",
get_decision_str(graph->smanhattan_edges));
if (graph->near_edges != G_NEAR_EDGES)
obstack_fgrow1 (os, "\tnear_edges:\t%s\n",
get_decision_str(graph->near_edges, G_NEAR_EDGES));
fprintf (fout, "\tnear_edges:\t%s\n",
get_decision_str(graph->near_edges));
if (graph->orientation != G_ORIENTATION)
obstack_fgrow1 (os, "\torientation:\t%s\n",
get_decision_str(graph->orientation, G_ORIENTATION));
fprintf (fout, "\torientation:\t%s\n",
get_orientation_str(graph->orientation));
if (graph->node_alignement != G_NODE_ALIGNEMENT)
obstack_fgrow1 (os, "\tnode_alignement:\t%s\n",
get_decision_str(graph->node_alignement,
G_NODE_ALIGNEMENT));
fprintf (fout, "\tnode_alignement:\t%s\n",
get_node_alignement_str(graph->node_alignement));
if (graph->port_sharing != G_PORT_SHARING)
obstack_fgrow1 (os, "\tport_sharing:\t%s\n",
get_decision_str(graph->port_sharing, G_PORT_SHARING));
fprintf (fout, "\tport_sharing:\t%s\n",
get_decision_str(graph->port_sharing));
if (graph->arrow_mode != G_ARROW_MODE)
obstack_fgrow1 (os, "\tarrow_mode:\t%s\n",
get_arrow_mode_str(graph->arrow_mode));
fprintf (fout, "\tarrow_mode:\t%s\n",
get_arrow_mode_str(graph->arrow_mode));
if (graph->treefactor != G_TREEFACTOR)
obstack_fgrow1 (os, "\ttreefactor:\t%f\n", graph->treefactor);
fprintf (fout, "\ttreefactor:\t%f\n", graph->treefactor);
if (graph->spreadlevel != G_SPREADLEVEL)
obstack_fgrow1 (os, "\tspreadlevel:\t%d\n", graph->spreadlevel);
fprintf (fout, "\tspreadlevel:\t%d\n", graph->spreadlevel);
if (graph->crossing_weight != G_CROSSING_WEIGHT)
obstack_fgrow1 (os, "\tcrossing_weight:\t%s\n",
get_crossing_type_str(graph->crossing_weight));
fprintf (fout, "\tcrossing_weight:\t%s\n",
get_crossing_type_str(graph->crossing_weight));
if (graph->crossing_phase2 != G_CROSSING_PHASE2)
obstack_fgrow1 (os, "\tcrossing_phase2:\t%s\n",
get_decision_str(graph->crossing_phase2,
G_CROSSING_PHASE2));
fprintf (fout, "\tcrossing_phase2:\t%s\n",
get_decision_str(graph->crossing_phase2));
if (graph->crossing_optimization != G_CROSSING_OPTIMIZATION)
obstack_fgrow1 (os, "\tcrossing_optimization:\t%s\n",
get_decision_str(graph->crossing_optimization,
G_CROSSING_OPTIMIZATION));
fprintf (fout, "\tcrossing_optimization:\t%s\n",
get_decision_str(graph->crossing_optimization));
if (graph->view != G_VIEW)
obstack_fgrow1 (os, "\tview:\t%s\n", get_view_str(graph->view));
fprintf (fout, "\tview:\t%s\n", get_view_str(graph->view));
if (graph->edges != G_EDGES)
obstack_fgrow1 (os, "\tedges:\t%s\n", get_decision_str(graph->edges,
G_EDGES));
fprintf (fout, "\tedges:\t%s\n", get_decision_str(graph->edges));
if (graph->nodes != G_NODES)
obstack_fgrow1 (os,"\tnodes:\t%s\n",
get_decision_str(graph->nodes, G_NODES));
fprintf (fout,"\tnodes:\t%s\n", get_decision_str(graph->nodes));
if (graph->splines != G_SPLINES)
obstack_fgrow1 (os, "\tsplines:\t%s\n",
get_decision_str(graph->splines, G_SPLINES));
fprintf (fout, "\tsplines:\t%s\n", get_decision_str(graph->splines));
if (graph->bmax != G_BMAX)
obstack_fgrow1 (os, "\tbmax:\t%d\n", graph->bmax);
fprintf (fout, "\tbmax:\t%d\n", graph->bmax);
if (graph->cmin != G_CMIN)
obstack_fgrow1 (os, "\tcmin:\t%d\n", graph->cmin);
fprintf (fout, "\tcmin:\t%d\n", graph->cmin);
if (graph->cmax != G_CMAX)
obstack_fgrow1 (os, "\tcmax:\t%d\n", graph->cmax);
fprintf (fout, "\tcmax:\t%d\n", graph->cmax);
if (graph->pmin != G_PMIN)
obstack_fgrow1 (os, "\tpmin:\t%d\n", graph->pmin);
fprintf (fout, "\tpmin:\t%d\n", graph->pmin);
if (graph->pmax != G_PMAX)
obstack_fgrow1 (os, "\tpmax:\t%d\n", graph->pmax);
fprintf (fout, "\tpmax:\t%d\n", graph->pmax);
if (graph->rmin != G_RMIN)
obstack_fgrow1 (os, "\trmin:\t%d\n", graph->rmin);
fprintf (fout, "\trmin:\t%d\n", graph->rmin);
if (graph->rmax != G_RMAX)
obstack_fgrow1 (os, "\trmax:\t%d\n", graph->rmax);
fprintf (fout, "\trmax:\t%d\n", graph->rmax);
if (graph->smax != G_SMAX)
obstack_fgrow1 (os, "\tsmax:\t%d\n", graph->smax);
fprintf (fout, "\tsmax:\t%d\n", graph->smax);
}

View File

@@ -75,14 +75,32 @@ enum shape_e
triangle
};
/* Structure for colorentries. */
struct colorentry_s
{
int color_index;
int red_cp;
int green_cp;
int blue_cp;
struct colorentry_s *next;
};
/* Structure to construct lists of classnames. */
struct classname_s
{
int no; /* Class number */
char *name; /* Name associated to the class no. */
const char *name; /* Name associated to the class no. */
struct classname_s *next; /* next name class association. */
};
/* Structure is in infoname. */
struct infoname_s
{
int integer;
const char *string;
struct infoname_s *next;
};
/* Layout Algorithms which can be found in VCG.
Details about each algoithm can be found below. */
enum layoutalgorithm_e
@@ -161,13 +179,13 @@ struct node_s
{
/* Title the unique string identifying the node. This attribute is
mandatory. */
char *title;
const char *title;
/* Label the text displayed inside the node. If no label is specified
then the title of the node will be used. Note that this text may
contain control characters like NEWLINE that influences the size of
the node. */
char *label;
const char *label;
/* loc is the location as x, y position relatively to the system of
coordinates of the graph. Locations are specified in the form
@@ -277,7 +295,7 @@ struct node_s
/* info2, info3 can be selected from the menu. The corresponding text
labels can be shown by mouse clicks on nodes.
Default are null strings. */
char *infos[3];
const char *infos[3];
/* Node border color.
Default is textcolor. */
@@ -483,19 +501,19 @@ struct graph_s
index 2, green has index 3, etc.
Default is white for background and white or transparent for summary
nodes. */
unsigned char color;
enum color_e color;
/* Textcolor.
need explainations ???
defalut is black for summary nodes. */
unsigned char textcolor;
enum color_e textcolor;
/* Bordercolor is the color of the summary node's border. Default color
is the textcolor. width, height are width and height of the
displayed part of the window of the outermost graph in pixels, or
width and height of the summary node of inner subgraphs.
Default is the defalut of the textcolor. */
unsigned char bordercolor;
enum color_e bordercolor;
/* Width, height are width and height of the displayed part of the
window of the outermost graph in pixels, or width and height of the
@@ -559,7 +577,22 @@ struct graph_s
Defalut is box, other: rhomb, ellipse, triangle. */
enum shape_e shape;
/* FIXME {vertival,horizontal}_order */
/* Vertical order is the level position (rank) of the summary node of an
inner subgraph, if this subgraph is folded. We can also specify
level: int. The level is only recognized, if an automatical layout is
calculated. */
int vertical_order;
/* Horizontal order is the horizontal position of the summary node within
a level. The nodes which are specified with horizontal positions are
ordered according to these positions within the levels. The nodes which
do not have this attribute are inserted into this ordering by the
crossing reduction mechanism. Note that connected components are
handled separately, thus it is not possible to intermix such components
by specifying a horizontal order. If the algorithm for downward laid
out trees is used, the horizontal order influences only the order of
the child nodes at a node, but not the order of the whole level. */
int horizontal_order;
/* xmax, ymax specify the maximal size of the virtual window that is
used to display the graph. This is usually larger than the displayed
@@ -630,8 +663,19 @@ struct graph_s
By default, no class names. */
struct classname_s *classname;
/* FIXME : infoname. */
/* FIXME : colorentry. */
/* Infoname allows to introduce names for the additional text labels.
The names are used in the menus.
Infoname is given by an integer and a string.
The default value is NULL. */
struct infoname_s *infoname;
/* Colorentry allows to fill the color map. A color is a triplet of integer
values for the red/green/blue-part. Each integer is between 0 (off) and
255 (on), e.g., 0 0 0 is black and 255 255 255 is white. For instance
colorentry 75 : 70 130 180 sets the map entry 75 to steel blue. This
color can be used by specifying just the number 75.
Default id NULL. */
struct colorentry_s *colorentry;
/* layoutalgorithm chooses different graph layout algorithms
Possibilities are maxdepth, mindepth, maxdepthslow, mindepthslow,
@@ -955,16 +999,21 @@ void new_edge PARAMS ((edge_t *edge));
void add_node PARAMS ((graph_t *graph, node_t *node));
void add_edge PARAMS ((graph_t *graph, edge_t *edge));
void open_node PARAMS ((struct obstack *os));
void output_node PARAMS ((node_t *node, struct obstack *os));
void close_node PARAMS ((struct obstack *os));
void add_colorentry PARAMS ((graph_t *g, int color_idx, int red_cp,
int green_cp, int blue_cp));
void add_classname PARAMS ((graph_t *g, int val, const char *name));
void add_infoname PARAMS ((graph_t *g, int val, const char *name));
void open_edge PARAMS ((edge_t *edge, struct obstack *os));
void output_edge PARAMS ((edge_t *edge, struct obstack *os));
void close_edge PARAMS ((struct obstack *os));
void open_node PARAMS ((FILE *fout));
void output_node PARAMS ((node_t *node, FILE *fout));
void close_node PARAMS ((FILE *fout));
void open_graph PARAMS ((struct obstack *os));
void output_graph PARAMS ((graph_t *graph, struct obstack *os));
void close_graph PARAMS ((graph_t *graph, struct obstack *os));
void open_edge PARAMS ((edge_t *edge, FILE *fout));
void output_edge PARAMS ((edge_t *edge, FILE *fout));
void close_edge PARAMS ((FILE *fout));
void open_graph PARAMS ((FILE *fout));
void output_graph PARAMS ((graph_t *graph, FILE *fout));
void close_graph PARAMS ((graph_t *graph, FILE *fout));
#endif /* VCG_H_ */

View File

@@ -47,8 +47,11 @@
# define G_TEXTMODE centered
# define G_SHAPE box
# define G_XMAX 90 /* Not output */
# define G_YMAX 90 /* Not output */
# define G_VERTICAL_ORDER 0 /* Unspecified for subgraphs. */
# define G_HORIZONTAL_ORDER 0 /* Unspecified for subgraphs. */
# define G_XMAX 90 /* Not output */
# define G_YMAX 90 /* Not output */
# define G_XBASE 5
# define G_YBASE 5
@@ -61,9 +64,12 @@
# define G_YRASTER 1
# define G_XLRASTER 1
# define G_HIDDEN -1 /* No default value. */
# define G_HIDDEN -1 /* No default value. */
# define G_CLASSNAME NULL /* No class name association */
# define G_INFONAME NULL
# define G_COLORENTRY NULL
# define G_CLASSNAME NULL /* No class name association */
# define G_LAYOUTALGORITHM normal
# define G_LAYOUT_DOWNFACTOR 1
# define G_LAYOUT_UPFACTOR 1