Skip to content
Snippets Groups Projects
Commit a1802176 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

added example of interactive command line driver for Gmsh
parent a0caaee8
No related branches found
No related tags found
No related merge requests found
# $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
......
#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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment