libcvd-members
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libcvd-members] gvars3 gvars3/GUI_non_readline.h src/GUI_non_re...


From: Georg Klein
Subject: [libcvd-members] gvars3 gvars3/GUI_non_readline.h src/GUI_non_re...
Date: Tue, 12 Feb 2008 19:38:17 +0000

CVSROOT:        /cvsroot/libcvd
Module name:    gvars3
Changes by:     Georg Klein <georgklein>        08/02/12 19:38:17

Added files:
        gvars3         : GUI_non_readline.h 
        src            : GUI_non_readline.cc 

Log message:
        Ooops, forgot to add these

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gvars3/gvars3/GUI_non_readline.h?cvsroot=libcvd&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gvars3/src/GUI_non_readline.cc?cvsroot=libcvd&rev=1.1

Patches:
Index: gvars3/GUI_non_readline.h
===================================================================
RCS file: gvars3/GUI_non_readline.h
diff -N gvars3/GUI_non_readline.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gvars3/GUI_non_readline.h   12 Feb 2008 19:38:17 -0000      1.1
@@ -0,0 +1,47 @@
+/*                       
+       This file is part of the GVars3 Library.
+
+       Copyright (C) 2005 The Authors
+
+       This library is free software; you can redistribute it and/or
+       modify it under the terms of the GNU Lesser General Public
+       License as published by the Free Software Foundation; either
+       version 2.1 of the License, or (at your option) any later version.
+
+       This library is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+       Lesser General Public License for more details.
+
+       You should have received a copy of the GNU Lesser General Public
+       License along with this library; if not, write to the Free Software
+       Foundation, Inc., 
+    51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#ifndef __GUI_NON_READLINE_H
+#define __GUI_NON_READLINE_H
+
+#include <string>
+
+namespace GVars3
+{
+
+       class spawn_non_readline_thread
+       {
+               public:
+                       spawn_non_readline_thread(const std::string&);
+                       ~spawn_non_readline_thread();
+
+               private:
+                       static bool running;
+                       static bool quit;
+                       static std::string quit_callback;
+                       pthread_t cmd;
+                       bool      none;
+                       static  void* proc(void*);
+       };
+
+
+};
+#endif

Index: src/GUI_non_readline.cc
===================================================================
RCS file: src/GUI_non_readline.cc
diff -N src/GUI_non_readline.cc
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/GUI_non_readline.cc     12 Feb 2008 19:38:17 -0000      1.1
@@ -0,0 +1,91 @@
+/*                       
+       This file is part of the GVars3 Library.
+
+       Copyright (C) 2005 The Authors
+
+       This library is free software; you can redistribute it and/or
+       modify it under the terms of the GNU Lesser General Public
+       License as published by the Free Software Foundation; either
+       version 2.1 of the License, or (at your option) any later version.
+
+       This library is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+       Lesser General Public License for more details.
+
+       You should have received a copy of the GNU Lesser General Public
+       License along with this library; if not, write to the Free Software
+       Foundation, Inc., 
+    51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include "gvars3/instances.h"
+#include "gvars3/GUI.h"
+#include "gvars3/GUI_non_readline.h"
+#include <iostream>
+#include <pthread.h>
+#include <poll.h>
+
+using namespace std;
+
+namespace GVars3
+{
+
+  bool spawn_non_readline_thread::running=0;
+  bool spawn_non_readline_thread::quit=0;
+  std::string spawn_non_readline_thread::quit_callback;
+  
+  spawn_non_readline_thread::spawn_non_readline_thread(const std::string& cb)
+  {
+    if(!running)
+      {
+       pthread_create(&cmd, 0, proc, 0);
+       running = 1;
+       quit=0;
+       none=0;
+       quit_callback = cb;
+      }
+    else
+      {
+       none =1;
+       std::cerr << "Error: non_readline thread already running.\n";
+      }
+  }
+
+
+  void* spawn_non_readline_thread::proc(void *)
+  {
+    char line[1000];
+    GUI.SetupReadlineCompletion();
+
+    while(1)
+      {
+       cout << "> ";  
+       cin.getline (line, 1000);
+       
+       if(quit || !line)
+         break;
+                 
+       if(*line)
+         GUI.ParseLine(line);
+      }
+    
+    GUI.ParseLine(quit_callback);
+    return 0;
+  }
+
+  spawn_non_readline_thread::~spawn_non_readline_thread()
+  {
+    //Terminate the readline and wait for it to finish
+    if(!none)
+      {
+       cout << endl << endl << endl << "Press enter to quit..." << endl ;
+       quit = 1;
+       pthread_join(cmd,NULL);
+       quit_callback = "";
+       quit = 0;
+       running = 0;
+      }
+  }
+       
+}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]