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

Add library support in TAF-Kit.

- taf-kit/tests/wrapper.in: Remove the fake commands.

- taf-kit/src/library_commands.hh: New.  Define `list-automata' and
`dump-automaton'.
- taf-kit/src/common_commands.hh: Include it.
- taf-kit/src/z_commands.cc,
- taf-kit/src/b_commands.cc: Add them.

- taf-kit/src/edit_automaton.hh,
- taf-kit/src/edit_automaton.hxx: Move to...
- taf-kit/src/edition_commands.hh,
- taf-kit/src/edition_commands.hxx: Here.  For name consistency.

- taf-kit/src/getters.hxx: Be more verbose, fix typo.

- taf-kit/src/commands_macros.hh,
- taf-kit/src/interface.cc: Handle commands with 0 argument.

- taf-kit/src/Makefile.am: Update.
parent 37f460a4
2006-07-21 Michal Cadilhac <michael.cadilhac@lrde.epita.fr>
Add library support in TAF-Kit.
* taf-kit/tests/wrapper.in: Remove the fake commands.
* taf-kit/src/library_commands.hh: New. Define `list-automata' and
`dump-automaton'.
* taf-kit/src/common_commands.hh: Include it.
* taf-kit/src/z_commands.cc,
* taf-kit/src/b_commands.cc: Add them.
* taf-kit/src/edit_automaton.hh,
* taf-kit/src/edit_automaton.hxx: Move to...
* taf-kit/src/edition_commands.hh,
* taf-kit/src/edition_commands.hxx: Here. For name consistency.
* taf-kit/src/getters.hxx: Be more verbose, fix typo.
* taf-kit/src/commands_macros.hh,
* taf-kit/src/interface.cc: Handle commands with 0 argument.
* taf-kit/src/Makefile.am: Update.
2006-07-21 Akim Demaille <akim@lrde.epita.fr>
Remove dead code and figure.
......
......@@ -29,8 +29,9 @@ COMMON_SOURCES = commands.hh \
commands_macros.hh \
common_commands.hh \
common.hh \
edit_automaton.hh \
edit_automaton.hxx \
edition_commands.hh \
edition_commands.hxx \
library_commands.hh \
getters.hh \
getters.hxx \
interface.cc \
......
......@@ -65,10 +65,12 @@ const command_t command_map[] =
COMMAND_ENTRY (display, Aut, "Display `aut'."),
COMMAND_ENTRY (dot_dump, Aut,
"Dump dot output of `aut'."),
COMMAND_ENTRY (dump_automaton, File, "Dump a predefined automaton."),
COMMAND_ENTRY (edit_automaton, File,
"Edit an existing automaton."),
COMMAND_ENTRY (identity, Aut, "Return `aut'."),
COMMAND_ENTRY (info, Aut, "Print useful infos about `aut'.")
COMMAND_ENTRY (info, Aut, "Print useful infos about `aut'."),
COMMAND_ENTRY (list_automata, Nil, "List predefined automata.")
),
......
......@@ -113,5 +113,6 @@
# define AutInt "aut n", 2
# define AutWord "aut word", 2
# define File "file", 1
# define Nil "", 0
#endif /* !COMMANDS_MACROS_HH */
......@@ -41,7 +41,8 @@ using vcsn::xml::XML;
# include <iostream>
# include "getters.hh"
# include "edit_automaton.hh"
# include "edition_commands.hh"
# include "library_commands.hh"
# include "commands.hh"
# include "commands_macros.hh"
......
// edit_automaton.hh: this file is part of the Vaucanson project.
// edition_commands.hh: this file is part of the Vaucanson project.
//
// Vaucanson, a generic library for finite state machines.
//
......@@ -19,10 +19,10 @@
# define EDIT_AUTOMATON_HH
/**
* @file edit_automaton.hh
* @file edition_commands.hh
* @author Michaël Cadilhac <michael.cadilhac@lrde.org>
*
* This file contains the declarations of @c edit_automaton_automaton
* This file contains the declarations of @c edit_automaton_command
* and @c define_automaton_command .
*/
......@@ -31,6 +31,6 @@
static int edit_automaton_command (const arguments_t& args);
static int define_automaton_command (const arguments_t& args);
# include "edit_automaton.hxx"
# include "edition_commands.hxx"
#endif /* !EDIT_AUTOMATON_HH */
// edit_automaton.hxx: this file is part of the Vaucanson project.
// edition_commands.hxx: this file is part of the Vaucanson project.
//
// Vaucanson, a generic library for finite state machines.
//
......@@ -18,10 +18,10 @@
# define EDIT_AUTOMATON_HXX
/**
* @file edit_automaton.hxx
* @file edition_commands.hxx
* @author Michaël Cadilhac <michael.cadilhac@lrde.org>
*
* This file contains the implementations of @c edit_automaton_automaton
* This file contains the implementations of @c edit_automaton_command
* and @c define_automaton_command .
* @note Should not be put in a .cc file, as CONTEXT_* macros
* could change from one compilation to another.
......@@ -57,7 +57,7 @@ extern void tputs (...);
# include <vaucanson/misc/static.hh>
# include "getters.hh"
# include "edit_automaton.hh"
# include "edition_commands.hh"
# define type_equal(T1, T2) (utility::static_eq < T1, T2 >::value)
# define discard_inputs() std::cin.ignore (LONG_MAX, '\n')
......@@ -67,7 +67,7 @@ extern void tputs (...);
| automaton |
`---------------------------------------------------------*/
namespace edit_automaton
namespace edition_commands
{
using namespace CONTEXT_NAMESPACE;
using namespace vcsn;
......@@ -383,7 +383,7 @@ static int edit_automaton_command (const arguments_t& args)
input >> automaton_loader (a, string_out (), XML ());
input.close ();
edit_automaton::main_loop (a);
edition_commands::main_loop (a);
std::ofstream output (args.args[1]);
output << automaton_saver (a, string_out (), XML ()) << std::endl;
......@@ -410,7 +410,7 @@ static int define_automaton_command (const arguments_t& args)
automaton_t a = make_automaton (get_alphabet (args.alphabet));
edit_automaton::main_loop (a);
edition_commands::main_loop (a);
output << automaton_saver (a, string_out (), XML ()) << std::endl;
output.close ();
......
......@@ -48,7 +48,7 @@ static alphabet_t get_alphabet (const char* alphabet)
if (not (alphabet and alphabet[0]))
{
warn ("Error: alphabet should be explicitly defined.");
warn ("Error: alphabet must be explicitly defined.");
exit (-2);
}
......@@ -84,7 +84,7 @@ static automaton_t get_aut (const std::string& s)
}
else
{
std::cerr << "Error: could not load automaton." << std::endl;
std::cerr << "Error: cannot open `" << s << "'." << std::endl;
exit (-3);
}
}
......
......@@ -48,7 +48,9 @@ void list_commands ()
{
echo_ (" - ");
write_with_dashs (command->name);
echo (" " << command->params << ": " << command->docstring);
if (command->n_params)
echo_ (" " << command->params);
echo (": " << command->docstring);
}
else
echo (" * " << command->docstring);
......
// library_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 AUTOMATON_LIBRARY_COMMANDS_HH
# define AUTOMATON_LIBRARY_COMMANDS_HH
/**
* @file library_commands.hh
* @author Michal Cadilhac <michael.cadilhac@lrde.org>
*
* Automaton library related commands.
*/
# include "common.hh"
# include CONTEXT_HEADER
# include <vaucanson/xml/XML.hh>
using namespace CONTEXT_NAMESPACE;
using namespace vcsn;
using namespace vcsn::io;
using vcsn::xml::XML;
# include <iostream>
# include <sys/types.h>
# include <dirent.h>
# include "getters.hh"
# include "commands.hh"
# include "commands_macros.hh"
/*--------------------------------------------.
| Command definitions for Automaton Library. |
`--------------------------------------------*/
static std::string get_automata_path (const arguments_t& args)
{
const char* base_path = getenv ("VCSN_DATA_PATH");
const char* lib_dir = "automata";
if (base_path == 0)
base_path = VCSN_DATA_PATH;
const std::string type = args.progname.substr (args.progname.rfind ('-') + 1);
std::string path = std::string (base_path) + "/" + lib_dir + "/" + type;
DIR* directory = opendir (path.c_str ());
if (not directory)
FAIL (std::string ("Error: Cannot open ") + path + ".\n"
"Please set VCSN_DATA_PATH to the Vaucanson data directory,\n"
"containing `" + lib_dir + "'.");
closedir (directory);
return path;
}
static int list_automata_command (const arguments_t& args)
{
DIR* directory = opendir (get_automata_path (args).c_str ());
dirent* file;
std::set<std::string> files;
while ((file = readdir (directory)))
{
std::string filename = file->d_name;
if (filename.rfind (".xml") == filename.size() - 4)
files.insert (filename);
}
closedir (directory);
echo ("The following automata are predefined:");
for_all (std::set<std::string>, ifile, files)
echo (" - " << ifile->substr (0, ifile->size () - 4));
return 0;
}
static int dump_automaton_command (const arguments_t& args)
{
std::string file = get_automata_path (args) + "/" + args.args[1] + ".xml";
std::ifstream in (file.c_str ());
if (in.fail ())
{
std::cerr << "Error: cannot open `" << file << "'." << std::endl;
exit (-3);
}
echo_ (in.rdbuf ());
return 0;
}
#endif /* !AUTOMATON_LIBRARY_COMMANDS_HH */
......@@ -40,9 +40,11 @@ const command_t command_map[] =
"Define an automaton from scratch."),
COMMAND_ENTRY (display, Aut, "Display `aut'."),
COMMAND_ENTRY (dot_dump, Aut, "Dump dot output of `aut'."),
COMMAND_ENTRY (dump_automaton, File, "Dump a predefined automaton."),
COMMAND_ENTRY (edit_automaton, File, "Edit an existing automaton."),
COMMAND_ENTRY (identity, Aut, "Return `aut'."),
COMMAND_ENTRY (info, Aut, "Print useful infos about `aut'.")
COMMAND_ENTRY (info, Aut, "Print useful infos about `aut'."),
COMMAND_ENTRY (list_automata, Nil, "List predefined automata.")
),
......
......@@ -7,16 +7,6 @@
VCSN_DATA_PATH='@abs_top_srcdir@/data'
export VCSN_DATA_PATH
# Until Mika has finished implemented dump-automaton and list-automata,
# we have to emulate them.
datadir=$VCSN_DATA_PATH/automata/$(basename "$0" | sed s/.*-//)
case $1 in
list-automata)
cd $datadir && exec ls -1 *.xml;;
dump-automaton)
exec cat $datadir/$2;;
esac
# PREVCSN can be set to tools such as Valgrind.
exec $PREVCSN '@abs_top_builddir@/taf-kit/src/'"$(basename "$0")" ${1+"$@"}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment