Commit feb028d7 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

Add a gui command that starts vgi.

* taf-kit/src/cmd_io.cc (gui_command): New command.
* taf-kit/src/getters.cc, taf-kit/src/getters.hh (write_aut): New
function.
parent 0780f4b0
2012-06-06 Alexandre Duret-Lutz <adl@lrde.epita.fr>
Add a gui command that starts vgi.
* taf-kit/src/cmd_io.cc (gui_command): New command.
* taf-kit/src/getters.cc, taf-kit/src/getters.hh (write_aut): New
function.
2012-05-22 Alexandre Duret-Lutz <adl@lrde.epita.fr>
 
* data/vaucanson.xsd: Allow any unknown elements in
......
## Vaucanson, a generic library for finite state machines.
## Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2008,
## 2009, 2010, 2011 The Vaucanson Group.
## 2009, 2010, 2011, 2012 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
......
......@@ -2,7 +2,7 @@
//
// Vaucanson, a generic library for finite state machines.
//
// Copyright (C) 2010, 2011 The Vaucanson Group.
// Copyright (C) 2010, 2011, 2012 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
......@@ -17,6 +17,10 @@
#include "commands.hh"
#include "edition_commands.hh"
# include <sys/types.h>
# include <sys/wait.h>
# include <unistd.h>
# include <cstdlib>
static int
data_command(const arguments_t& args)
......@@ -43,6 +47,76 @@ display_command(const arguments_t& args)
return display_aut(get_aut(args, 1), args, 1);
}
static int
gui_command(const arguments_t& args)
{
automaton_t a = get_aut(args, 1);
int filedes[2];
if (pipe(filedes))
{
g_res.stream << "Cannot create pipe." << std::endl;
return 1;
}
pid_t child_pid = fork();
if (child_pid)
{
close(filedes[0]);
if (child_pid == -1)
{
g_res.stream << "Cannot fork." << std::endl;
close(filedes[1]);
return 1;
}
else
{
std::cout.flush();
int old = dup(STDOUT_FILENO);
if (old != -1)
dup2(filedes[1], STDOUT_FILENO);
close(filedes[1]);
write_aut(a, std::cout);
if (old != -1)
{
dup2(old, STDOUT_FILENO);
close(old);
}
return 0;
}
}
else
{
close(filedes[1]);
dup2(filedes[0], STDIN_FILENO);
close(filedes[0]);
// execvp will treat its second argument as if it was
// "const char* const*". See the following page for an
// explanation of why it is only declared as "char* const*".
// http://www.opengroup.org/onlinepubs/000095399/functions/exec.html
const char* vgijar = getenv("VGIJAR");
if (vgijar)
{
const char* const argv[] = {"java", "-jar", vgijar, "-", 0};
execvp(argv[0], const_cast<char *const *>(argv));
}
// If running java failed, or ig VGIJAR is not defined, try to
// run a command called vgi.
const char* const argv[] = {"vgi", "-", 0};
execvp(argv[0], const_cast<char *const *>(argv));
std::cerr << "Failed to execute `" << argv[0] << "'.\n"
<< "You should either define an environment variable VGIJAR "
<< "that points to the\nlocation of `vgi.jar', or have on your "
<< "PATH a script `vgi' that starts VGI." << std::endl;
exit(1);
}
}
BEGIN_COMMAND_GROUP(io_commands,
"0. Input/Output functions:");
......@@ -50,4 +124,6 @@ COMMAND_ENTRY(data, Aut, Text, "Print useful infos about `aut'.");
COMMAND_ENTRY(cat, Aut, Aut, "Return `aut'.");
COMMAND_ENTRY(display, Aut, None, "Display `aut'.");
COMMAND_ENTRY(edit, Aut, None, "Create or edit an automaton interactively.");
COMMAND_ENTRY(gui, Aut, None,
"launch VGI to create or edit an automaton interactively.");
END_COMMAND_GROUP
......@@ -2,7 +2,7 @@
//
// Vaucanson, a generic library for finite state machines.
//
// Copyright (C) 2006, 2008, 2009, 2010, 2011 The Vaucanson Group.
// Copyright (C) 2006, 2008, 2009, 2010, 2011, 2012 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
......@@ -373,6 +373,12 @@ automaton_t get_aut (const arguments_t& args, int n)
}
}
int
write_aut(const automaton_t& aut, std::ostream& out)
{
out << automaton_saver(aut, string_out(), XML());
return 0;
}
int
write_aut(const automaton_t& aut, const arguments_t& args, int n)
......
......@@ -2,7 +2,7 @@
//
// Vaucanson, a generic library for finite state machines.
//
// Copyright (C) 2006, 2008, 2009, 2010, 2011 The Vaucanson Group.
// Copyright (C) 2006, 2008, 2009, 2010, 2011, 2012 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
......@@ -72,6 +72,7 @@ IOAUT_CONTEXT::automaton_t
get_single_band_aut(const arguments_t& args, int n);
#endif
int write_aut(const automaton_t& aut, std::ostream& out);
int write_aut(const automaton_t& aut, const arguments_t& args, int n);
int display_aut(const automaton_t& aut, const arguments_t& args, int n);
......
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