Commit a0e7f8f2 authored by Jerome Galtier's avatar Jerome Galtier
Browse files

TAF-Kit: Fix the epsilon of predefined alphabets in --help.

	* taf-kit/src/Makefile.am: Add new file to the distribution.
	* taf-kit/src/main.cc: Only include the `predefined_alphabets.hh'
	  header if relevant. Remove any reference to the `DEFAULT_EPSILON'
	  macro. New variable `predefined_string', to hold the dynamically
	  calculated string displayed when using --help.
	  (main) [!NO_PREDEF_ALPHABETS]: Call the new
	  `build_predefined_string' to populate `predefined_string'.
	* taf-kit/src/predefined_alphabets.hh: Include the
	  `parser_options.hh' header file. Remove the definition of
	  `DEFAULT_EPSILON'. Declare new function `build_predefined_string'.
	* taf-kit/src/predefined_alphabets.hxx: New: Add the implementation
	  of the `build_predefined_string'.
	* taf-kit/tests/vcsn-char-b.test,
	* taf-kit/tests/vcsn-char-fmp-b.test,
	* taf-kit/tests/vcsn-char-fmp-z.test,
	* taf-kit/tests/vcsn-char-z.test: Add the regression test.
parent 1bf1ad24
2009-01-21 Jerome Galtier <jerome.galtier@lrde.epita.fr>
TAF-Kit: Fix the epsilon of predefined alphabets in --help.
* taf-kit/src/Makefile.am: Add new file to the distribution.
* taf-kit/src/main.cc: Only include the `predefined_alphabets.hh'
header if relevant. Remove any reference to the `DEFAULT_EPSILON'
macro. New variable `predefined_string', to hold the dynamically
calculated string displayed when using --help.
(main) [!NO_PREDEF_ALPHABETS]: Call the new
`build_predefined_string' to populate `predefined_string'.
* taf-kit/src/predefined_alphabets.hh: Include the
`parser_options.hh' header file. Remove the definition of
`DEFAULT_EPSILON'. Declare new function `build_predefined_string'.
* taf-kit/src/predefined_alphabets.hxx: New: Add the implementation
of the `build_predefined_string'.
* taf-kit/tests/vcsn-char-b.test,
* taf-kit/tests/vcsn-char-fmp-b.test,
* taf-kit/tests/vcsn-char-fmp-z.test,
* taf-kit/tests/vcsn-char-z.test: Add the regression test.
2009-01-21 Jerome Galtier <jerome.galtier@lrde.epita.fr>
 
TAF-Kit: Disable predefined alphabets for pair contexts.
......
......@@ -36,6 +36,7 @@ COMMON_SOURCES = commands.hh \
interface.hh \
main.cc \
predefined_alphabets.hh \
predefined_alphabets.hxx \
pipe.hh \
pipe.hxx \
pipe_command_sequence.hh \
......
......@@ -2,7 +2,7 @@
//
// Vaucanson, a generic library for finite state machines.
//
// Copyright (C) 2006, 2007, 2008 The Vaucanson Group.
// Copyright (C) 2006, 2007, 2008, 2009 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
......@@ -38,7 +38,10 @@
#include "argp.h"
#include "progname.h"
#include "predefined_alphabets.hh"
#ifndef NO_PREDEF_ALPHABETS
# include "predefined_alphabets.hh"
#endif
#include "commands.hh"
#include "interface.hh"
#include "parser_options.hh"
......@@ -78,6 +81,9 @@ namespace
{
const char doc[] = "VCSN TAF-Kit -- a toolkit for working with automata";
const char args_doc[] = "<command> <args...>";
#ifndef NO_PREDEF_ALPHABETS
char predefined_string[1024];
#endif
const argp_option options[] = {
{"list-commands", 'l', 0, 0,
"List the commands handled by the program", 0 },
......@@ -116,11 +122,7 @@ namespace
"Set the parsing options for rational expressions", 0 },
#ifndef NO_PREDEF_ALPHABETS
{ 0, 0, 0, 0, "The following alphabets are predefined:\n"
" `letters': Use [a-z] as the alphabet, " DEFAULT_EPSILON " as epsilon\n"
" `alpha': Use [a-zA-Z] as the alphabet, " DEFAULT_EPSILON " as epsilon\n"
" `digits': Use [0-9] as the alphabet, " DEFAULT_EPSILON " as epsilon\n"
" `ascii': Use ascii characters as the alphabet, " DEFAULT_EPSILON " as epsilon\n", 0},
{ 0, 0, 0, 0, predefined_string, 0},
#endif
{ 0, 0, 0, 0, 0, 0 }
......@@ -131,12 +133,11 @@ namespace
{
const char* name;
const char* alphabet;
const char* epsilon;
} predefined_alphabets[] = { { "letters", ALPHABET_AZ, DEFAULT_EPSILON },
{ "alpha", ALPHABET_AZAZ, DEFAULT_EPSILON },
{ "digits", ALPHABET_DIGITS, DEFAULT_EPSILON },
{ "ascii", ALPHABET_ASCII, DEFAULT_EPSILON },
{ 0, 0, 0 } };
} predefined_alphabets[] = { { "letters", ALPHABET_AZ },
{ "alpha", ALPHABET_AZAZ },
{ "digits", ALPHABET_DIGITS },
{ "ascii", ALPHABET_ASCII },
{ 0, 0 } };
#endif
error_t parse_opt (int key, char* arg, argp_state* state)
......@@ -154,21 +155,12 @@ namespace
if (std::string (alpha->name) == arg)
{
if (key == 'a')
{
#ifdef WITH_TWO_ALPHABETS
args.add_parser1_option("ALPHABET", alpha->alphabet);
args.add_parser1_option("ONE", alpha->epsilon);
#else
args.add_parser_option("ALPHABET", alpha->alphabet);
args.add_parser_option("ONE", alpha->epsilon);
#endif /* ! WITH_TWO_ALPHABETS */
}
#ifdef WITH_TWO_ALPHABETS
else
{
args.add_parser2_option("ALPHABET", alpha->alphabet);
args.add_parser2_option("ONE", alpha->epsilon);
}
#else
args.add_parser_option("ALPHABET", alpha->alphabet);
#endif /* ! WITH_TWO_ALPHABETS */
found = true;
break;
......@@ -319,6 +311,9 @@ int main (int argc, char* argv[])
for (std::list<pipe_command>::iterator li = command_list.begin ();
li != command_list.end (); ++li)
{
#ifndef NO_PREDEF_ALPHABETS
build_predefined_string(predefined_string);
#endif
argp_parse (&argp_setup, li->length, li->arg, 0, 0, &(li->args));
try
......
......@@ -2,7 +2,7 @@
//
// Vaucanson, a generic library for finite state machines.
//
// Copyright (C) 2006, 2008 The Vaucanson Group.
// Copyright (C) 2006, 2008, 2009 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
......@@ -26,6 +26,8 @@
* Predefined alphabets as macros.
*/
# include "parser_options.hh"
// FIXME: " and \0 (\\0)
# define ALPHABET_ASCII \
"\\ \"!#$%&'\\(\\)*+\\,-./0123456789\\:;<\\=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
......@@ -35,6 +37,8 @@
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
# define ALPHABET_DIGITS "0123456789"
# define DEFAULT_EPSILON "1"
void build_predefined_string(char* buffer);
# include "predefined_alphabets.hxx"
#endif /* !PREDEFINED_ALPHABETS_HH */
// predefined_alphabets.hxx: this file is part of the Vaucanson project.
//
// Vaucanson, a generic library for finite state machines.
//
// Copyright (C) 2008, 2009 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 PREDEFINED_ALPHABETS_HXX
# define PREDEFINED_ALPHABETS_HXX
# include <string>
# include <vector>
# include "predefined_alphabets.hh"
std::string build_default_eps(std::string alphabet)
{
// Type helpers.
typedef std::vector<std::string> ab_vect_t;
parser_options<monoid_rep_t, series_rep_t> p_opts("ALPHABET=" + alphabet);
ab_vect_t letters = p_opts.get_letters();
# ifdef WITH_TWO_ALPHABETS
first_alphabet_t al;
# else
alphabet_t al;
# endif
for (ab_vect_t::const_iterator it = letters.begin();
it != letters.end();
++it)
al.insert(*it);
# ifdef WITH_TWO_ALPHABETS
first_monoid_t M(al);
# else
monoid_t M(al);
# endif
return M.representation()->empty;
}
void build_predefined_string(char* buffer)
{
std::string output;
// Build the string with dynamic values for epsilon representations.
output += "The following alphabets are predefined:\n"
" `letters': Use [a-z] as the alphabet, "
+ build_default_eps(ALPHABET_AZ)
+ " as epsilon\n"
+ " `alpha': Use [a-zA-Z] as the alphabet, "
+ build_default_eps(ALPHABET_AZAZ)
+ " as epsilon\n"
+ " `digits': Use [0-9] as the alphabet, "
+ build_default_eps(ALPHABET_DIGITS)
+ " as epsilon\n"
+ " `ascii': Use ascii characters as the alphabet, "
+ build_default_eps(ALPHABET_ASCII)
+ " as epsilon\n";
// Reset buffer because this function is called for each command,
// and we may overflow the buffer.
buffer[0] = 0;
// Concatenate output with buffer.
std::strcat(buffer, output.c_str());
}
#endif /* !PREDEFINED_ALPHABETS_HXX */
......@@ -492,6 +492,14 @@ diff stderr stderr.ref
# Check predefined alphabets in help.
$VCSN --help |grep predefined
eps=`$VCSN --help |sed -e "/letters'/s/.*, \([^ ]*\) as epsilon/\1/p;d"`
test x"$eps" = x"1"
eps=`$VCSN --help |sed -e "/alpha'/s/.*, \([^ ]*\) as epsilon/\1/p;d"`
test x"$eps" = x"1"
eps=`$VCSN --help |sed -e "/digits'/s/.*, \([^ ]*\) as epsilon/\1/p;d"`
test x"$eps" = x"e"
eps=`$VCSN --help |sed -e "/ascii'/s/.*, \([^ ]*\) as epsilon/\1/p;d"`
test x"$eps" = x"_e"
## ------------------- ##
## Test div3base2.xml. ##
......
......@@ -410,3 +410,11 @@ diff wd-new.xml wd-ref.xml
# Check predefined alphabets in help.
$VCSN --help |grep predefined
eps=`$VCSN --help |sed -e "/letters'/s/.*, \([^ ]*\) as epsilon/\1/p;d"`
test x"$eps" = x"1"
eps=`$VCSN --help |sed -e "/alpha'/s/.*, \([^ ]*\) as epsilon/\1/p;d"`
test x"$eps" = x"1"
eps=`$VCSN --help |sed -e "/digits'/s/.*, \([^ ]*\) as epsilon/\1/p;d"`
test x"$eps" = x"e"
eps=`$VCSN --help |sed -e "/ascii'/s/.*, \([^ ]*\) as epsilon/\1/p;d"`
test x"$eps" = x"_e"
......@@ -162,3 +162,11 @@ diff wd-new.xml wd-ref.xml
# Check predefined alphabets in help.
$VCSN --help |grep predefined
eps=`$VCSN --help |sed -e "/letters'/s/.*, \([^ ]*\) as epsilon/\1/p;d"`
test x"$eps" = x"1"
eps=`$VCSN --help |sed -e "/alpha'/s/.*, \([^ ]*\) as epsilon/\1/p;d"`
test x"$eps" = x"1"
eps=`$VCSN --help |sed -e "/digits'/s/.*, \([^ ]*\) as epsilon/\1/p;d"`
test x"$eps" = x"e"
eps=`$VCSN --help |sed -e "/ascii'/s/.*, \([^ ]*\) as epsilon/\1/p;d"`
test x"$eps" = x"_e"
......@@ -234,5 +234,13 @@ diff wd-new.xml wd-ref.xml
# Check predefined alphabets in help.
$VCSN --help |grep predefined
eps=`$VCSN --help |sed -e "/letters'/s/.*, \([^ ]*\) as epsilon/\1/p;d"`
test x"$eps" = x"1"
eps=`$VCSN --help |sed -e "/alpha'/s/.*, \([^ ]*\) as epsilon/\1/p;d"`
test x"$eps" = x"1"
eps=`$VCSN --help |sed -e "/digits'/s/.*, \([^ ]*\) as epsilon/\1/p;d"`
test x"$eps" = x"e"
eps=`$VCSN --help |sed -e "/ascii'/s/.*, \([^ ]*\) as epsilon/\1/p;d"`
test x"$eps" = x"_e"
exit 0
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