libcvd-members
[Top][All Lists]
Advanced

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

[libcvd-members] gvars3/src GUI.cc inst.cc


From: Georg Klein
Subject: [libcvd-members] gvars3/src GUI.cc inst.cc
Date: Tue, 12 Feb 2008 17:56:55 +0000

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

Modified files:
        src            : GUI.cc inst.cc 

Log message:
        Moved some GUI code from inst.cc to GUI.cc

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gvars3/src/GUI.cc?cvsroot=libcvd&r1=1.18&r2=1.19
http://cvs.savannah.gnu.org/viewcvs/gvars3/src/inst.cc?cvsroot=libcvd&r1=1.13&r2=1.14

Patches:
Index: GUI.cc
===================================================================
RCS file: /cvsroot/libcvd/gvars3/src/GUI.cc,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- GUI.cc      22 Oct 2007 22:20:44 -0000      1.18
+++ GUI.cc      12 Feb 2008 17:56:54 -0000      1.19
@@ -38,8 +38,8 @@
 {
        //GUI GUI;
 
-bool setvar(string s)
-{
+  bool setvar(string s)
+  {
        //Execution failed. Maybe its an assignment.
         string::size_type n;
        n=s.find("=");
@@ -71,34 +71,34 @@
        }
 
        return false;
-}
+  }
 
 
 
-GUI *GUI::mpReadlineCompleterGUI=NULL;
+  GUI *GUI::mpReadlineCompleterGUI=NULL;
 
 
-void GUI::UnRegisterCommand(string sCommandName)
-{
+  void GUI::UnRegisterCommand(string sCommandName)
+  {
        mmCallBackMap.erase(sCommandName);
-};
+  };
 
-void GUI::UnRegisterAllCommands(void* thisptr)
-{
+  void GUI::UnRegisterAllCommands(void* thisptr)
+  {
   for(map<string, CallbackVector>::iterator i=mmCallBackMap.begin(); 
i!=mmCallBackMap.end(); i++)
     UnRegisterCommand(i->first, thisptr);
-};
+  };
 
-void GUI::UnRegisterCommand(string sCommandName, void* thisptr)
-{
+  void GUI::UnRegisterCommand(string sCommandName, void* thisptr)
+  {
        CallbackVector &cbv = mmCallBackMap[sCommandName];
        for(int i = cbv.size() - 1; i>=0; i--)
              if(cbv[i].thisptr == thisptr)
                    cbv.erase(cbv.begin() + i);
-};
+  };
 
-void GUI::RegisterCommand(string sCommandName, GUICallbackProc callback, void* 
thisptr)
-{
+  void GUI::RegisterCommand(string sCommandName, GUICallbackProc callback, 
void* thisptr)
+  {
        if(builtins.count(sCommandName))
        {
                cerr << "!!GUI::RegisterCommand: Tried to register reserved 
keyword " << sCommandName << "." << endl;
@@ -119,13 +119,13 @@
 
        if(!bAlreadyThere)
                        cbv->push_back(s);
-};
+  };
 
 
-// Returns true if something was called;
-// otherwise returns false
-bool GUI::CallCallbacks(string sCommand, string sParams)
-{
+  // Returns true if something was called;
+  // otherwise returns false
+  bool GUI::CallCallbacks(string sCommand, string sParams)
+  {
        if(mmCallBackMap.count(sCommand)==0)
                return false;
 
@@ -138,18 +138,18 @@
                i->cbp(i->thisptr, sCommand, sParams);
 
        return true;
-};
+  };
 
 
-void GUI::ParseStream(istream& is)
-{
+  void GUI::ParseStream(istream& is)
+  {
        string buffer;
        while(getline(is, buffer))
                ParseLine(buffer);
-}
+  }
 
-void GUI::LoadFile(string sFileName)
-{
+  void GUI::LoadFile(string sFileName)
+  {
        ifstream ifs;
 
        vector<string> v = ChopAndUnquoteString(sFileName);
@@ -167,14 +167,14 @@
 
        ParseStream(ifs);
        ifs.close();
-}
+  }
 
 
 
 
 
-string::size_type FindCloseBrace(const string& s, string::size_type start, 
char op, char cl)
-{
+  string::size_type FindCloseBrace(const string& s, string::size_type start, 
char op, char cl)
+  {
         string::size_type open=1;
        string::size_type i;
 
@@ -192,11 +192,11 @@
        if(i == s.size())
                i = s.npos;
        return i;
-}
+  }
 
 
-void GUI::ParseLine(string s, bool bSilentFailure )
-{
+  void GUI::ParseLine(string s, bool bSilentFailure )
+  {
        s = UncommentString(s); 
        if(s == "")
                return;
@@ -285,18 +285,18 @@
                //int nCloseBracePos = s.rfind(")");
                string::size_type nCloseBracePos = FindCloseBrace(s, 
nOpenBracePos, '(', ')');
 
-//             cerr << "((( " << nOpenBracePos << "  " << nCloseBracePos << 
endl;
+      //               cerr << "((( " << nOpenBracePos << "  " << 
nCloseBracePos << endl;
                
 
                if((nOpenBracePos  !=s.npos) && (nCloseBracePos !=s.npos) && 
(nCloseBracePos > nOpenBracePos))
                {   // Brace Pair found!!
-//cerr << "Found (\n";
+         //cerr << "Found (\n";
                        //cout << "Found brace pair. " << endl;
                        string sBegin = s.substr(0,nOpenBracePos);
                        string sVarName = 
s.substr(nOpenBracePos+1,nCloseBracePos-nOpenBracePos-1);
                        string sEnd = s.substr(nCloseBracePos+1);
 
-//cerr << "varname = --" << sVarName << "--\n";
+         //cerr << "varname = --" << sVarName << "--\n";
 
                        string::size_type nLength = sVarName.size();   // Check 
if it's a double brace: {{foo}} in which case remove one pair, but don't expand.
                        bool bIsDoubleQuoted = false;
@@ -310,8 +310,8 @@
 
                        if(!bIsDoubleQuoted)
                        {
-//cerr << "varname = --" << sVarName << "--\n";
-//cerr << "***************" << GV3::get_var(sVarName) << endl;
+             //cerr << "varname = --" << sVarName << "--\n";
+             //cerr << "***************" << GV3::get_var(sVarName) << endl;
                                //string sExpanded = 
mpGV2->StringValue(sVarName, true);
                                string sExpanded = GV3::get_var(sVarName);
                                s = sBegin + sExpanded + sEnd;
@@ -348,16 +348,16 @@
 
        if(!bSilentFailure) 
                cerr << "? GUI::ParseLine: Unknown command \"" << sCommand << 
"\" or invalid assignment." << endl;
-}
+  }
 
 
 
-////////////////////////////////////////////////////////////////////////////////
-//
-// Builtin commands
+  
////////////////////////////////////////////////////////////////////////////////
+  //
+  // Builtin commands
 
-void builtin_shell(void* ptr, string sCommand, string sParams)
-{
+  void builtin_shell(void* ptr, string sCommand, string sParams)
+  {
        vector<string> v = ChopAndUnquoteString(sParams);
 
        if(v.size()==0) 
@@ -367,44 +367,44 @@
        }
 
        system(sParams.c_str());
-}
+  }
 
-void builtin_ls(void* ptr, string sCommand, string sParams)
-{
+  void builtin_ls(void* ptr, string sCommand, string sParams)
+  {
        GUI* p = (GUI*)ptr;
        p->ParseLine("shell ls " + sParams);    
-}
+  }
 
-void builtin_ll(void* ptr, string sCommand, string sParams)
-{
+  void builtin_ll(void* ptr, string sCommand, string sParams)
+  {
        GUI* p = (GUI*)ptr;
        p->ParseLine("shell ls -l " + sParams); 
-}
+  }
 
-void builtin_try(void* ptr, string sCommand, string sParams)
-{
+  void builtin_try(void* ptr, string sCommand, string sParams)
+  {
        GUI* p = (GUI*)ptr;
        p->ParseLine(sParams, true);
-}
+  }
 
-void builtin_exec(void* ptr, string sCommand, string sParams)
-{
+  void builtin_exec(void* ptr, string sCommand, string sParams)
+  {
        GUI* p = (GUI*)ptr;
        p->LoadFile(sParams);
-}
+  }
 
-void builtin_echo(void* ptr, string sCommand, string sParams)
-{
+  void builtin_echo(void* ptr, string sCommand, string sParams)
+  {
        cout << sParams << endl;
-}
+  }
 
-void builtin_qmark(void* ptr, string sCommand, string sParams)
-{
+  void builtin_qmark(void* ptr, string sCommand, string sParams)
+  {
        cout << "  Perhaps you'd like to type \"commandlist\" or \"gvarlist\"." 
<< endl;
-}
+  }
 
-void builtin_if(void* ptr, string sCommand, string sParams)
-{
+  void builtin_if(void* ptr, string sCommand, string sParams)
+  {
   GUI* p = (GUI*)ptr;
   vector<string> v = ChopAndUnquoteString(sParams);
   if(v.size()<2)
@@ -431,10 +431,10 @@
        p->ParseLine(s);
     }
   return;
-}
+  }
 
-void builtin_ifnot(void* ptr, string sCommand, string sParams)
-{
+  void builtin_ifnot(void* ptr, string sCommand, string sParams)
+  {
   GUI* p = (GUI*)ptr;
   vector<string> v = ChopAndUnquoteString(sParams);
   if(v.size()<2)
@@ -461,10 +461,10 @@
        p->ParseLine(s);
     }
   return;
-}
+  }
 
-void builtin_ifeq(void* ptr, string sCommand, string sParams)
-{
+  void builtin_ifeq(void* ptr, string sCommand, string sParams)
+  {
   GUI* p = (GUI*)ptr;
   vector<string> v = ChopAndUnquoteString(sParams);
   if(v.size()<3)
@@ -492,10 +492,10 @@
        p->ParseLine(s);
     }
   return;
-}
+  }
 
-void builtin_toggle(void* ptr, string sCommand, string sParams)
-{
+  void builtin_toggle(void* ptr, string sCommand, string sParams)
+  {
   GUI* p = (GUI*)ptr;
   vector<string> v = ChopAndUnquoteString(sParams);
   if(v.size()!=1) 
@@ -510,16 +510,16 @@
     GV3::set_var(v[0],"1");
   return;
   
-};
+  };
 
-void builtin_set(void* ptr, string sCommand, string sParams)
-{
+  void builtin_set(void* ptr, string sCommand, string sParams)
+  {
        setvar(sParams);
-}
+  }
 
 
-void builtin_gvarlist(void* ptr, string sCommand, string sParams)
-{
+  void builtin_gvarlist(void* ptr, string sCommand, string sParams)
+  {
   bool error = false;
   bool print_all = false;
   string pattern = "";
@@ -551,17 +551,17 @@
     cout << "? GUI internal " << sCommand << ": syntax is " << sCommand << " 
[-a] [pattern] " << endl;
   else
     GV3::print_var_list(cout, pattern, print_all);
-}
+  }
 
 
-void builtin_printvar(void* ptr, string sCommand, string sParams)
-{
+  void builtin_printvar(void* ptr, string sCommand, string sParams)
+  {
        cout << sParams << "=" << GV3::get_var(sParams) << endl;;
-}
+  }
 
 
-void builtin_commandlist(void* ptr, string sCommand, string sParams)
-{
+  void builtin_commandlist(void* ptr, string sCommand, string sParams)
+  {
        GUI* p = (GUI*)ptr;
 
        cout << "  Builtin commands:" << endl;
@@ -575,10 +575,10 @@
        for(map<string,CallbackVector>::iterator i=p->mmCallBackMap.begin(); 
i!=p->mmCallBackMap.end(); i++)
                if(p->builtins.count(i->first) == 0)
                          cout << "    " << i->first << endl;
-}
+  }
 
-void builtin_queue(void* ptr, string sCommand, string sParams)
-{
+  void builtin_queue(void* ptr, string sCommand, string sParams)
+  {
        vector<string> vs = ChopAndUnquoteString(sParams);
        if(vs.size() < 2)
          {
@@ -590,10 +590,10 @@
        
        GUI* pGUI = (GUI*)ptr;
        pGUI->mmQueues[sQueueName].push_back(sParams);
-}
+  }
 
-void builtin_runqueue(void* ptr, string sCommand, string sParams)
-{
+  void builtin_runqueue(void* ptr, string sCommand, string sParams)
+  {
        GUI* pGUI = (GUI*)ptr;
        vector<string> vs = ChopAndUnquoteString(sParams);
        if(vs.size() != 1)
@@ -619,16 +619,16 @@
          pGUI->ParseLine(vQueue[i]);
        if(sCommand=="runqueue")
          vQueue.clear();   // do not clear the queue if the command was 
runqueue_noclear!
-}
+  }
 
-///////////////////////////////////////
-///////////////////////////////////////
-////////     Readline stuff:
-///////////////////////////////////////
-///////////////////////////////////////
+  ///////////////////////////////////////
+  ///////////////////////////////////////
+  ////////     Readline stuff:
+  ///////////////////////////////////////
+  ///////////////////////////////////////
 
 
-int GUI::parseArguments( const int argc, char * argv[], int start, const 
string prefix, const string execKeyword ){
+  int GUI::parseArguments( const int argc, char * argv[], int start, const 
string prefix, const string execKeyword ){
        while(start < argc){
                string opt = argv[start];
                if(opt.size() > prefix.size() && opt.find(prefix) == 0){
@@ -647,33 +647,33 @@
                else break;
        }
        return start;
-}
+  }
 
-void GUI::RegisterBuiltin(string sCommandName, GUICallbackProc callback)
-{
+  void GUI::RegisterBuiltin(string sCommandName, GUICallbackProc callback)
+  {
        RegisterCommand(sCommandName, callback, this);
        builtins.insert(sCommandName);
-}
+  }
 
-GUI::GUI()
-{
+  GUI::GUI()
+  {
        do_builtins();
-}
+  }
 
-GUI::GUI(GVars2*)
-{
+  GUI::GUI(GVars2*)
+  {
        do_builtins();
-}
+  }
 
-void print_history(ostream &ost);
-void builtin_history(void* ptr, string sCommand, string sParams)
-{
+  void print_history(ostream &ost);
+  void builtin_history(void* ptr, string sCommand, string sParams)
+  {
   cout << "History: " << endl;
   print_history(cout);
-};
+  };
 
-void builtin_save_history(void* ptr, string sCommand, string sParams)
-{
+  void builtin_save_history(void* ptr, string sCommand, string sParams)
+  {
   vector<string> v = ChopAndUnquoteString(sParams);
   if(v.size()!=1) 
     cout << "? GUI internal savehistory command: need one param (filename)." 
<< endl;
@@ -690,11 +690,11 @@
          cout << "  Saved to " << v[0] << endl;
        }
     };
-};
+  };
 
 
-void GUI::do_builtins()
-{
+  void GUI::do_builtins()
+  {
        RegisterBuiltin("shell", builtin_shell);
        RegisterBuiltin("ls", builtin_ls);
        RegisterBuiltin("ll", builtin_ll);
@@ -715,7 +715,59 @@
        RegisterBuiltin("queue",  builtin_queue);
        RegisterBuiltin("runqueue", builtin_runqueue);
        RegisterBuiltin("runqueue_noclear", builtin_runqueue);
-};
+  };
+  
+  
+#ifdef GUI_HAVE_READLINE
+#include <readline/readline.h>
+#include <readline/history.h>
+  
+  void GUI::SetupReadlineCompletion()
+  {
+    mpReadlineCompleterGUI = this;
+    rl_attempted_completion_function = ReadlineCompletionFunction;
+    rl_basic_word_break_characters = " \t\n\"\\'address@hidden><;|&{("; 
+  }
+  
+  char ** GUI::ReadlineCompletionFunction (const char *text, int start, int 
end)
+  {
+    rl_completion_append_character=0;
+    char **matches;
+    matches = (char **)NULL;
+    matches = rl_completion_matches (text,   ReadlineCommandGeneratorCB);
+    return (matches);
+  }
+  
+  void print_history(ostream &ost)
+  {
+    HIST_ENTRY **apHistEntries = history_list();
+    if(apHistEntries)
+      while((*apHistEntries)!=NULL)
+       {
+         ost << (*apHistEntries)->line << endl;
+         apHistEntries++;
+       }
+  };
+#else
+  void GUI::SetupReadlineCompletion()
+  {
+  }
+
+  char ** GUI::ReadlineCompletionFunction (const char *text, int start, int 
end)
+  {
+    return NULL;
+  }
+
+
+  void print_history(ostream &ost)
+  {
+  }
+#endif
+
+
+
 
 }
 
+
+

Index: inst.cc
===================================================================
RCS file: /cvsroot/libcvd/gvars3/src/inst.cc,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- inst.cc     1 Feb 2008 14:57:36 -0000       1.13
+++ inst.cc     12 Feb 2008 17:56:54 -0000      1.14
@@ -33,12 +33,6 @@
        #include <gvars3/GUI_Motif.h>
 #endif
 
-
-#ifdef GUI_HAVE_READLINE
-       #include <readline/readline.h>
-       #include <readline/history.h>
-#endif
-
 #include "gvars3/GUI.h"
 #include "gvars3/GStringUtil.h"
 
@@ -59,52 +53,4 @@
        #ifdef GUI_HAVE_MOTIF
                class GUI_Motif GUI_Motif(&GUI, &GV2);
        #endif
-
-       #ifdef GUI_HAVE_READLINE
-               void GUI::SetupReadlineCompletion()
-               {
-                 mpReadlineCompleterGUI = this;
-                 rl_attempted_completion_function = ReadlineCompletionFunction;
-                 rl_basic_word_break_characters = " 
\t\n\"\\'address@hidden><;|&{("; 
-               }
-
-               char ** GUI::ReadlineCompletionFunction (const char *text, int 
start, int end)
-               {
-                 rl_completion_append_character=0;
-                 char **matches;
-                 matches = (char **)NULL;
-                 matches = rl_completion_matches (text,   
ReadlineCommandGeneratorCB);
-                 return (matches);
-               }
-
-               void print_history(ostream &ost)
-               {
-                 HIST_ENTRY **apHistEntries = history_list();
-                 if(apHistEntries)
-                       while((*apHistEntries)!=NULL)
-                         {
-                       ost << (*apHistEntries)->line << endl;
-                       apHistEntries++;
-                         }
-               };
-       #else
-
-               void GUI::SetupReadlineCompletion()
-               {
-               }
-
-               char ** GUI::ReadlineCompletionFunction (const char *text, int 
start, int end)
-               {
-                 return NULL;
-               }
-
-
-               void print_history(ostream &ost)
-               {
-               }
-
-
-       #endif
-
-
 }




reply via email to

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