Commit b33682c5 authored by Michaël Cadilhac's avatar Michaël Cadilhac
Browse files

Add TAF-Kit for Boolean automata.

TAF-Kit stands for Typed Automata Function Kit, that is to say,
programs that deal with fixed type automata, on the command line.

- src/taf-kit: New. TAF-Kit directory.

- src/taf-kit/b_commands.cc: New. Add commands specific to Boolean
automata.

The following files will be common to all TAF-Kit binaries:

- src/taf-kit/commands.hh: New.
- src/taf-kit/edit_automaton.hh,
- src/taf-kit/edit_automaton.hxx: New. `edit_automaton' and 
`create_automaton' functions.
- src/taf-kit/commands_macros.hh: New. Useful macros to define commands.
- src/taf-kit/getters.hh,
- src/taf-kit/getters.hxx: New. Getters for expressions, automata, ...
- src/taf-kit/common.hh: New.
- src/taf-kit/predefined_alphabets.hh: New.
- src/taf-kit/common_commands.hh: New.
- src/taf-kit/main.cc: New.

- src/taf-kit/Makefile.am: New.
- src/Makefile.am: Include TAF-Kit as a subdirectory if its build has
been requested.
- config/vcsn_taf_kit.m4: New. Check for Curses and enable the build
of TAF-Kit on demand.
- configure.ac: Update accordingly.
parent 45846753
2006-05-07 Michal Cadilhac <michael.cadilhac@lrde.epita.fr>
Add TAF-Kit for Boolean automata.
TAF-Kit stands for Typed Automata Function Kit, that is to say,
programs that deal with fixed type automata, on the command line.
* src/taf-kit: New. TAF-Kit directory.
* src/taf-kit/b_commands.cc: New. Add commands specific to Boolean
automata.
The following files will be common to all TAF-Kit binaries:
* src/taf-kit/commands.hh: New.
* src/taf-kit/edit_automaton.hh,
* src/taf-kit/edit_automaton.hxx: New. `edit_automaton' and
`create_automaton' functions.
* src/taf-kit/commands_macros.hh: New. Useful macros to define commands.
* src/taf-kit/getters.hh,
* src/taf-kit/getters.hxx: New. Getters for expressions, automata, ...
* src/taf-kit/common.hh: New.
* src/taf-kit/predefined_alphabets.hh: New.
* src/taf-kit/common_commands.hh: New.
* src/taf-kit/main.cc: New.
* src/taf-kit/Makefile.am: New.
* src/Makefile.am: Include TAF-Kit as a subdirectory if its build has
been requested.
* config/vcsn_taf_kit.m4: New. Check for Curses and enable the build
of TAF-Kit on demand.
* configure.ac: Update accordingly.
2006-05-07 Michal Cadilhac <michael.cadilhac@lrde.epita.fr>
Fix VCSN_NDEBUG use.
......
## Terminal library test, taken from GNU Texinfo configure.ac
AC_DEFUN([VCSN_CHECK_TERMLIB],
[dnl
AC_CHECK_HEADERS(ncurses/termcap.h termcap.h)
# Some GNU/Linux systems (e.g., SuSE 4.3, 1996) don't have curses, but
# rather ncurses. So we check for it.
TERMLIBS=
# Check for termlib before termcap because Solaris termcap needs libucb.
TERMLIB_VARIANTS="ncurses curses termlib termcap terminfo"
for termlib in ${TERMLIB_VARIANTS}; do
AC_CHECK_LIB(${termlib}, tgetent,
[TERMLIBS="${TERMLIBS} -l${termlib}"; break])
done
AC_SUBST([TERMLIBS])
])
## TAF Kit enabling
AC_DEFUN([VCSN_TAF_KIT],
[dnl
AC_ARG_ENABLE([taf-kit],
[AC_HELP_STRING([--disable-taf-kit],
[disable TAF-Kit (binary toolkit) compilation])],
[enable_taf_kit=$enableval],
[enable_taf_kit=yes])
if test x$enable_taf_kit = xyes; then
if test x$enable_vcsn_xml = xno; then
AC_MSG_WARN([XML support should be enabled for TAF-Kit to be compiled,
it will not be built])
enable_taf_kit=no
else
VCSN_CHECK_TERMLIB
if test -z "$TERMLIBS"; then
AC_MSG_WARN([need a terminal library (${TERMLIB_VARIANTS}), TAF-Kit
will not be built])
enable_taf_kit=no
fi
fi
else
enable_taf_kit=no
fi
AM_CONDITIONAL([VCSN_TAF_KIT], [test x$enable_taf_kit = xyes])
])
......@@ -92,6 +92,7 @@ AC_DEFINE_UNQUOTED([CXX], ["$CXX"], [The C++ compiler])
# AC_CHECK_HEADERS([stl_config.h])
VCSN_XML
VCSN_TAF_KIT
##
## Package header configuration.
......@@ -137,6 +138,7 @@ AC_CHECK_PROGS([TAR], [tar], [$am_aux_dir/missing tar])
AC_CONFIG_FILES([
Makefile
src/Makefile
src/taf-kit/Makefile
src/tests/Makefile
src/tests/check/Makefile
src/tests/check/defs
......
......@@ -7,5 +7,9 @@ SUBDIRS = tests \
benchs \
demos
if VCSN_TAF_KIT
SUBDIRS += taf-kit
endif
# The XSD file will be installed in a data directory.
dist_pkgdata_DATA = vaucanson.xsd
AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
AM_CXXFLAGS = $(CXXFLAGS_STRICT) $(CXXFLAGS_OPTIMIZE)
AM_LDFLAGS = $(TERMLIBS)
bin_PROGRAMS = vcsn-b
COMMON_SOURCES = commands.hh \
commands_macros.hh \
common_commands.hh \
common.hh \
edit_automaton.hh \
edit_automaton.hxx \
getters.hh \
getters.hxx \
main.cc \
predefined_alphabets.hh
vcsn_b_CPPFLAGS = $(AM_CPPFLAGS) \
-DCONTEXT_HEADER="<vaucanson/boolean_automaton.hh>" \
-DCONTEXT_NAMESPACE="vcsn::boolean_automaton"
vcsn_b_SOURCES = $(COMMON_SOURCES) \
b_commands.cc
// b_commands.cc: this file is part of the Vaucanson project.
//
// Vaucanson, a generic library for finite state machines.
//
// Copyright (C) 2006 The Vaucanson Group.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// The complete GNU General Public Licence Notice can be found as the
// `COPYING' file in the root directory.
//
// The Vaucanson Group consists of people listed in the `AUTHORS' file.
//
/**
* @file b_commands.c
* @author Michaël Cadilhac <michael.cadilhac@lrde.org>
*
* Commands declaration and definition for Boolean automata.
*/
#include "commands.hh"
#include "common_commands.hh"
/*-------------------.
| Command definition |
`-------------------*/
DEFINE_IS_PROPERTY_COMMAND (complete);
DEFINE_IS_PROPERTY_COMMAND (deterministic);
DEFINE_ONE_ARG_COMMAND (ARG_KIND (aut)
ALGO (complete));
DEFINE_ONE_ARG_COMMAND_TWO_ALGOS (NAME (determinize)
ARG_KIND (aut)
ALGOS (determinize, realtime));
DEFINE_ONE_ARG_COMMAND (ARG_KIND (aut)
ALGO (complement));
/*-----------------------------.
| Define the set of commands. |
`-----------------------------*/
static const command_t command_map[] =
{
COMMAND_GROUP (
"Input/output work with automata:",
COMMAND_ENTRY_CN (define-automaton, define_automaton, File,
"Define an automaton from scratch."),
COMMAND_ENTRY (display, Aut, "Display `aut'."),
COMMAND_ENTRY_CN (edit-automaton, edit_automaton, File,
"Edit an existing automaton."),
COMMAND_ENTRY (info, Aut, "Print useful infos about `aut'.")),
COMMAND_GROUP (
"Tests and evaluation on automata:",
COMMAND_ENTRY_CN (are-isomorphic, are_isomorphic, AutAut,
"Return whether `aut1' and `aut2' are isomorphic."),
COMMAND_ENTRY (eval, AutWord, "Evaluate `word' on `aut'."),
COMMAND_ENTRY_CN (is-complete, is_complete, Aut,
"Return whether `aut' is complete."),
COMMAND_ENTRY_CN (is-deterministic, is_deterministic, Aut,
"Return whether `aut' is deterministic."),
COMMAND_ENTRY_CN (is-empty, is_empty, Aut,
"Return whether trimed `aut' is empty."),
COMMAND_ENTRY_CN (is-normalized, is_normalized, Aut,
"Return whether `aut' is normalized."),
COMMAND_ENTRY_CN (is-realtime, is_realtime, Aut,
"Return whether `aut' is realtime."),
COMMAND_ENTRY_CN (is-standard, is_standard, Aut,
"Return whether `aut' is standard.")),
COMMAND_GROUP (
"Generic algorithms for automata:",
COMMAND_ENTRY (accessible, Aut,
"Give the maximal accessible subautomaton of `aut'."),
COMMAND_ENTRY (closure, Aut,
"Give `aut' closed over epsilon transitions."),
COMMAND_ENTRY_CN (co-accessible, coaccessible, Aut,
"Give the maximal coaccessible subautomaton of `aut'."),
COMMAND_ENTRY (complement, Aut, "Complement `aut1'."),
COMMAND_ENTRY (complete, Aut, "Give the complete version of `aut1'."),
COMMAND_ENTRY (concatenate, AutAut, "Concatenate `aut1' and `aut2'."),
COMMAND_ENTRY (determinize, Aut,
"Give the determinized automaton of `aut'."),
COMMAND_ENTRY_CN (minimize, minimization_hopcroft, Aut,
"Give the minimized of `aut' (Hopcroft algorithm)."),
COMMAND_ENTRY_CN (minimize-moore, minimization_moore, Aut,
"Give the minimized of `aut' (Moore algorithm)."),
COMMAND_ENTRY (normalize, Aut,
"Give the Thompson-normalized automaton of `aut'."),
COMMAND_ENTRY (power, AutInt, "Give the power of `aut' by `n'."),
COMMAND_ENTRY (product, AutAut, "Give the product of `aut1' by `aut2'." ),
COMMAND_ENTRY (quotient, Aut, "Give the quotient of `aut'."),
COMMAND_ENTRY (realtime, Aut, "Give the realtime version of `aut'."),
COMMAND_ENTRY (standardize, Aut, "Give the standard automaton of `aut'."),
COMMAND_ENTRY (sum, AutAut, "Give the sum of `aut1' and `aut2'."),
COMMAND_ENTRY (transpose, Aut, "Transpose the automaton `aut'."),
COMMAND_ENTRY (trim, Aut, "Trim the automaton `aut'.")),
COMMAND_GROUP (
"Conversion between automata and expressions:",
COMMAND_ENTRY_CN (aut-to-exp, aut_to_exp, Aut,
"Give the automaton associated to `aut'."),
COMMAND_ENTRY_CN (derived-term, derived_term_automaton, Exp,
"Use derivative to compute the automaton of `exp'."),
COMMAND_ENTRY_CN (exp-to-aut, standard_of, Exp,
"Alias of `stardard_of'."),
COMMAND_ENTRY (expand, Exp, "Expand `exp'."),
COMMAND_ENTRY_CN (standard, standard_of, Exp,
"Give the standard automaton of `exp'."),
COMMAND_ENTRY_CN (thompson, thompson_of, Exp,
"Give the Thompson automaton of `exp'.")),
{0, 0, 0, 0, 0}
};
/*----------.
| Interface |
`----------*/
/// List all the commands.
void list_commands ()
{
echo ("List of available commands:");
for (const command_t* command = command_map; command->docstring; ++command)
if (command->name)
echo (" - " << command->name << " " << command->params
<< ": " << command->docstring);
else
echo (" * " << command->docstring);
}
/**
* Execute an command according to the program's arguments.
*
* @param args Arguments.
*
* @return -1 on wrong number of args, -2 on inexistent algo,
* the result of the command otherwise.
*/
int execute_command (const arguments_t& args)
{
for (const command_t* command = command_map; command->docstring; ++command)
if (command->name && command->name == args.args[0])
{
if (command->n_params != args.n_args - 1)
{
warn (args.progname << ": wrong number of arguments for `"
<< command->name << " " << command->params << "' (should be "
<< command->n_params << ").");
warn ("Try `" << args.progname << " --list-commands'"
<< " for more information.");
return -1;
}
return command->command (args);
}
warn (args.progname << ": command `" << args.args[0] << "' doesn't exist.");
return -2;
}
// commands.hh: this file is part of Vaucanson.
//
// Vaucanson, a generic library for finite state machines.
//
// Copyright (C) 2006 The Vaucanson Group.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// The complete GNU General Public Licence Notice can be found as the
// `COPYING' file in the root directory.
//
// The Vaucanson Group consists of people listed in the `AUTHORS' file.
//
#ifndef COMMANDS_HH
# define COMMANDS_HH
/**
* @file commands.hh
* @author Michaël Cadilhac <michael.cadilhac@lrde.org>
*
* Command chooser interface.
*/
# include "common.hh"
int execute_command (const arguments_t&);
void list_commands ();
struct command_t
{
const char* name;
int (*command)(const arguments_t&);
const char* params;
int n_params;
const char* docstring;
};
#endif /* !COMMANDS_HH */
// commands_macros.hh: this file is part of Vaucanson.
//
// Vaucanson, a generic library for finite state machines.
//
// Copyright (C) 2006 The Vaucanson Group.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// The complete GNU General Public Licence Notice can be found as the
// `COPYING' file in the root directory.
//
// The Vaucanson Group consists of people listed in the `AUTHORS' file.
//
#ifndef COMMANDS_MACROS_HH
# define COMMANDS_MACROS_HH
/**
* @file commands_macros.hh
* @author Michal Cadilhac <michael.cadilhac@lrde.org>
*
* Commands declaration macros.
*/
/*----------------------------.
| Generic command definitions |
`----------------------------*/
// Syntactic sugar
# define NAME(Name) Name,
# define ARG_KIND(Type) get_ ## Type,
# define ALGO(Algo) Algo
# define ALGOS(Algo1, Algo2) Algo1, Algo2
# define CODE(Code) Code,
# define OUTPUT(Output) Output,
# define OUTPUT_ON_VERBOSE(Output) (args.verbose ? (Output) : ""),
# define RETURNVALUE(ReturnValue) (ReturnValue)
// Command without any special form.
# define DEFINE_COMMAND_(CodeName, Code, Output, ReturnValue) \
static int CodeName ## _command (const arguments_t& args) \
{ \
Code; \
echo_ (Output); \
return ReturnValue; \
}
# define DEFINE_COMMAND(BlockArgs) DEFINE_COMMAND_ (BlockArgs)
// Command associated to Algo named Algo_command that takes one argument.
# define DEFINE_ONE_ARG_COMMAND_(GetArg, Algo) \
DEFINE_COMMAND (NAME (Algo) \
CODE (/* Empty */) \
OUTPUT ( \
automaton_saver (Algo (GetArg (args.args[1])), \
string_out (), XML ())) \
RETURNVALUE (0))
# define DEFINE_ONE_ARG_COMMAND(BlockArgs) DEFINE_ONE_ARG_COMMAND_ (BlockArgs)
// Command named CodeName_command that takes one arg and uses two algos.
# define DEFINE_ONE_ARG_COMMAND_TWO_ALGOS_(CodeName, GetArg, Algo1, Algo2) \
DEFINE_COMMAND (NAME (CodeName) \
CODE (/* Empty */) \
OUTPUT ( \
automaton_saver (Algo1(Algo2(get_aut (args.args[1]))), \
string_out (), XML ())) \
RETURNVALUE (0))
# define DEFINE_ONE_ARG_COMMAND_TWO_ALGOS(BlockArgs) \
DEFINE_ONE_ARG_COMMAND_TWO_ALGOS_ (BlockArgs)
// Command named Algo_command that takes two args and uses @c Algo .
# define DEFINE_TWO_ARGS_COMMAND_(GetArg, Algo) \
DEFINE_COMMAND (NAME (Algo) \
CODE (/* Empty */) \
OUTPUT ( \
automaton_saver (Algo (GetArg (args.args[1]), \
GetArg (args.args[2])), \
string_out (), XML ())) \
RETURNVALUE (0))
# define DEFINE_TWO_ARGS_COMMAND(BlockArgs) \
DEFINE_TWO_ARGS_COMMAND_ (BlockArgs)
// Command just doing a is_@c Property .
# define DEFINE_IS_PROPERTY_COMMAND(Property) \
DEFINE_COMMAND (NAME (is_ ## Property) \
CODE ( \
bool b = is_ ## Property (get_aut (args.args[1]))) \
OUTPUT_ON_VERBOSE ( \
(b ? "Entry is " # Property "\n": \
"Entry is not " # Property "\n")) \
RETURNVALUE (b ? 0 : 1))
/*-----------------------------------------------.
| Command entries ; meant for arg parsing & co. |
`-----------------------------------------------*/
# define COMMAND_ENTRY_CN_(Name, CodeName, Params, NParams, Docstring) \
{ # Name, CodeName ## _command, Params, NParams, Docstring }
# define COMMAND_ENTRY_CN(Name, CodeName, BlockParams, Docstring) \
COMMAND_ENTRY_CN_ (Name, CodeName, BlockParams, Docstring)
# define COMMAND_ENTRY(Name, BlockParams, Docstring) \
COMMAND_ENTRY_CN_ (Name, Name, BlockParams, Docstring)
# define COMMAND_GROUP(Text, Group...) \
{ 0, 0, 0, 0, Text }, \
Group
# define Exp "exp", 1
# define Aut "aut", 1
# define AutAut "aut1 aut2", 2
# define AutInt "aut n", 2
# define AutWord "aut word", 2
# define File "file", 1
#endif /* !COMMANDS_MACROS_HH */
// common.hh: this file is part of the Vaucanson project.
//
// Vaucanson, a generic library for finite state machines.
//
// Copyright (C) 2006 The Vaucanson Group.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// The complete GNU General Public Licence Notice can be found as the
// `COPYING' file in the root directory.
//
// The Vaucanson Group consists of people listed in the `AUTHORS' file.
//
#ifndef COMMON_HH
# define COMMON_HH
/**
* @file common.hh
* @author Michal Cadilhac <michael.cadilhac@lrde.org>
*
* This file contains common declarations for all files.
*/
# ifdef HAVE_CONFIG_H
# include <config.h>
# endif
# include <iostream>
# define echo(S) std::cout << S << std::endl
# define echo_(S) std::cout << S
# define warn(S) std::cerr << S << std::endl
# define warn_(S) std::cerr << S
# if ! (defined (CONTEXT_HEADER) && defined (CONTEXT_NAMESPACE))
# error "CONTEXT_HEADER and CONTEXT_NAMESPACE has to be declared."
# endif /* defined (CONTEXT_HEADER) && defined (CONTEXT_NAMESPACE) */
# if 0 /* @bug Should use this with dynamic libraries. */
# define VCSN_USE_INTERFACE_ONLY 1
# endif /* 0 */
/* Turn VCSN traps into exception. */
# define EXCEPTION_TRAPS 1
# include <string>
struct arguments_t
{
std::string progname;
std::string args[3];
int n_args;
char* alphabet;
char epsilon;
# ifdef WITH_TWO_ALPHABETS
char* alphabet2;
char epsilon2;
# endif /* ! WITH_TWO_ALPHABETS */
bool verbose;
};
#endif /* !COMMON_HH */
// common_commands.hh: this file is part of Vaucanson.
//
// Vaucanson, a generic library for finite state machines.
//
// Copyright (C) 2006 The Vaucanson Group.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// The complete GNU General Public Licence Notice can be found as the
// `COPYING' file in the root directory.
//
// The Vaucanson Group consists of people listed in the `AUTHORS' file.
//
#ifndef COMMON_COMMANDS_HH
# define COMMON_COMMANDS_HH
/**
* @file common_commands.hh
* @author Michal Cadilhac <michael.cadilhac@lrde.org>
*
* Commands declaration and definition for all type of automata.
*/
# include "common.hh"
# include CONTEXT_HEADER
# include <vaucanson/xml/XML.hh>
# include <vaucanson/tools/dot_display.hh>
using namespace CONTEXT_NAMESPACE;
using namespace vcsn;
using namespace vcsn::io;
using vcsn::xml::XML;
# include <cstdlib>
# include "getters.hh"
# include "edit_automaton.hh"
# include "commands.hh"
# include "commands_macros.hh"
/*-------------------.
| Command definition |
`-------------------*/
DEFINE_IS_PROPERTY_COMMAND (normalized);
DEFINE_IS_PROPERTY_COMMAND (realtime);
DEFINE_IS_PROPERTY_COMMAND (standard);
DEFINE_ONE_ARG_COMMAND (ARG_KIND (exp)
ALGO (standard_of));
DEFINE_ONE_ARG_COMMAND (ARG_KIND (exp)
ALGO (thompson_of));
DEFINE_ONE_ARG_COMMAND (ARG_KIND (aut)
ALGO (trim));
DEFINE_ONE_ARG_COMMAND (ARG_KIND (aut)
ALGO (transpose));
DEFINE_ONE_ARG_COMMAND (ARG_KIND (aut)
ALGO (realtime));
DEFINE_ONE_ARG_COMMAND (ARG_KIND (aut)
ALGO (coaccessible));
DEFINE_ONE_ARG_COMMAND (ARG_KIND (aut)
ALGO (accessible));
DEFINE_ONE_ARG_COMMAND (ARG_KIND (aut)
ALGO (normalize));
DEFINE_ONE_ARG_COMMAND (ARG_KIND (aut)
ALGO (minimization_hopcroft));
DEFINE_ONE_ARG_COMMAND (ARG_KIND (aut)
ALGO (minimization_moore));
DEFINE_ONE_ARG_COMMAND_TWO_ALGOS (NAME (quotient)
ARG_KIND (aut)
ALGOS (quotient, realtime));
DEFINE_ONE_ARG_COMMAND_TWO_ALGOS (NAME (closure)
ARG_KIND (aut)
ALGOS (accessible, closure));