GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
octave-cmd.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2014-2017 Torsten
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 // Author: Torsten <ttl@justmail.de>
24 
25 #if defined (HAVE_CONFIG_H)
26 # include "config.h"
27 #endif
28 
29 #include "octave-cmd.h"
30 
31 #include "octave-qt-link.h"
32 #include "cmd-edit.h"
33 #include "builtin-defun-decls.h"
34 #include "utils.h"
35 
36 
37 // ---------------------------------------------------------------------
38 // class octave_cmd_exec: executing a command
39 
40 void
42 {
44 
49 }
50 
51 // ---------------------------------------------------------------------
52 // class octave_cmd_eval: running a file
53 
54 void
56 {
57  QString function_name = _info.fileName ();
58  function_name.chop (_info.suffix ().length () + 1);
59  std::string file_path = _info.absoluteFilePath ().toStdString ();
60 
62 
63  if (valid_identifier (function_name.toStdString ()))
64  {
65  // valid identifier: call as function with possibility to debug
66  std::string path = _info.absolutePath ().toStdString ();
67  if (octave_qt_link::file_in_path (file_path, path))
68  octave::command_editor::replace_line (function_name.toStdString ());
69  }
70  else
71  {
72  // no valid identifier: use Fsource (), no debug possible
73  Fsource (ovl (file_path));
75  }
76 
79 
81 }
82 
83 // ---------------------------------------------------------------------
84 // class octave_cmd_debug: executing a debugger command
85 
86 void
88 {
89  if (_cmd == "step")
90  {
92  Fdbstep ();
93  }
94  else if (_cmd == "cont")
95  {
97  Fdbcont ();
98  }
99  else if (_cmd == "quit")
100  Fdbquit ();
101  else
102  {
104  Fdbstep (ovl (_cmd.toStdString ()));
105  }
106 
108 }
109 
110 // ---------------------------------------------------------------------
111 // class octave_command_queue: queue of octave commands
112 
113 // add_cmd: add a command to the queue
114 void
116 {
117  _queue_mutex.lock ();
118  _queue.append (cmd);
119  _queue_mutex.unlock ();
120 
121  if (_processing.tryAcquire ()) // if callback not processing, post event
124 }
125 
126 // callback for executing the command by the worker thread
127 void
129 {
130  bool repost = false; // flag for reposting event for this callback
131 
132  if (! _queue.isEmpty ()) // list can not be empty here, just to make sure
133  {
134  _queue_mutex.lock (); // critical path
135 
136  octave_cmd *cmd = _queue.takeFirst ();
137 
138  if (_queue.isEmpty ())
139  _processing.release (); // cmd queue empty, processing will stop
140  else
141  repost = true; // not empty, repost at end
142  _queue_mutex.unlock ();
143 
144  cmd->execute ();
145 
146  delete cmd;
147  }
148 
149  if (repost) // queue not empty, so repost event for further processing
152 
153 }
void execute_command_callback(void)
Callback routine for executing the command by the worker thread.
Definition: octave-cmd.cc:128
OCTINTERP_API octave_value_list Fdbcont(const octave_value_list &=octave_value_list(), int=0)
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).is_integer_type())
virtual void execute()
Definition: octave-cmd.h:42
QFileInfo _info
Definition: octave-cmd.h:72
QSemaphore _processing
Definition: octave-cmd.h:128
OCTINTERP_API octave_value_list Fsource(const octave_value_list &=octave_value_list(), int=0)
OCTINTERP_API octave_value_list Fdbstep(const octave_value_list &=octave_value_list(), int=0)
bool valid_identifier(const char *s)
Definition: utils.cc:74
void add_cmd(octave_cmd *cmd)
Adds a new octave command to the command queue.
Definition: octave-cmd.cc:115
OCTINTERP_API octave_value_list Fdbquit(const octave_value_list &=octave_value_list(), int=0)
static void replace_line(const std::string &text, bool clear_undo=true)
Definition: cmd-edit.cc:1445
QString _cmd
Definition: octave-cmd.h:57
static bool interrupt(bool=true)
Definition: cmd-edit.cc:1620
OCTINTERP_API octave_value_list F__db_next_breakpoint_quiet__(const octave_value_list &=octave_value_list(), int=0)
static void redisplay(void)
Definition: cmd-edit.cc:1216
static void set_initial_input(const std::string &text)
Definition: cmd-edit.cc:1096
static void accept_line(void)
Definition: cmd-edit.cc:1473
static std::string get_current_line(void)
Definition: cmd-edit.cc:1431
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
QList< octave_cmd * > _queue
Definition: octave-cmd.h:127
bool _suppress_dbg_location
Definition: octave-cmd.h:92