diff --git a/utils/solvers/c++/Makefile b/utils/solvers/c++/Makefile index 2baa56df255fa83132dc324a4742ce9c8609d43a..5706f6bdcb4ed6f1fa243950bba171d3ffd49188 100644 --- a/utils/solvers/c++/Makefile +++ b/utils/solvers/c++/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.4 2005-01-16 20:41:42 geuzaine Exp $ +# $Id: Makefile,v 1.5 2006-02-24 01:57:09 geuzaine Exp $ # # Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle # @@ -21,9 +21,14 @@ include ../../../variables +all: solver.exe interactive.exe + solver.exe: solver.cpp ${CXX} ${FLAGS} ${OPTIM} -o solver.exe solver.cpp +interactive.exe: interactive.cpp + ${CXX} ${FLAGS} ${OPTIM} -o interactive.exe interactive.cpp -lreadline + clean: rm -f *.o *.exe *.pos diff --git a/utils/solvers/c++/interactive.cpp b/utils/solvers/c++/interactive.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fc571b7fcb669ef82aede79942839afe499c003b --- /dev/null +++ b/utils/solvers/c++/interactive.cpp @@ -0,0 +1,62 @@ +#include "GmshClient.h" +#include <readline/readline.h> +#include <readline/history.h> + +// compile with: g++ interact.cpp -lreadline + +class GmshInteractiveClient{ + private: + GmshClient _client; + public: + GmshInteractiveClient() + { + using_history(); + char *socket = "/Users/geuzaine/.gmshsock"; + if(_client.Connect(socket) < 0) { + printf("Unable to connect to Gmsh\n"); + exit(1); + } + _client.Start(); + } + ~GmshInteractiveClient() + { + _client.Stop(); + _client.Disconnect(); + } + void read(char *prompt) + { + while (1) { + // read input char until CR, LF, EOF, ^D + char *ptr = readline(prompt); + // exit interactive if EOF or ^D + if(!ptr) break; + // if there is something in the line + if(strlen(ptr)){ + // add the command in the stack + add_history(ptr); + if(!strcmp(ptr,"q") || !strcmp(ptr, "quit")){ + // exit interactive if q, quit, exit + free(ptr); + break; + } + else if(!strcmp(ptr, "dir") || !strcmp(ptr, "ls")){ + // direct system calls + system("ls -al"); + } + else{ + // pass any other command to gmsh + _client.ParseString(ptr); + } + } + free(ptr); + } + } +}; + +int main() +{ + GmshInteractiveClient c; + c.read("gmsh> "); + + return 0; +}