GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
octave-cmd.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2014-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://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 namespace octave
37 {
39  {
41 
46  }
47 
49  {
50  QString function_name = m_info.fileName ();
51  function_name.chop (m_info.suffix ().length () + 1);
52  std::string file_path = m_info.absoluteFilePath ().toStdString ();
53 
55 
56  if (valid_identifier (function_name.toStdString ()))
57  {
58  // valid identifier: call as function with possibility to debug
59  std::string path = m_info.absolutePath ().toStdString ();
60  if (octave_qt_link::file_in_path (file_path, path))
61  octave::command_editor::replace_line (function_name.toStdString ());
62  }
63  else
64  {
65  // no valid identifier: use Fsource (), no debug possible
66  Fsource (ovl (file_path));
68  }
69 
72 
74  }
75 
77  {
78  if (m_cmd == "step")
79  {
80  F__db_next_breakpoint_quiet__ (ovl (m_suppress_dbg_location));
81  Fdbstep ();
82  }
83  else if (m_cmd == "cont")
84  {
85  F__db_next_breakpoint_quiet__ (ovl (m_suppress_dbg_location));
86  Fdbcont ();
87  }
88  else if (m_cmd == "quit")
89  Fdbquit ();
90  else
91  {
92  F__db_next_breakpoint_quiet__ (ovl (m_suppress_dbg_location));
93  Fdbstep (ovl (m_cmd.toStdString ()));
94  }
95 
97  }
98 
99  // add a command to the queue
100 
102  {
103  m_queue_mutex.lock ();
104  m_queue.append (cmd);
105  m_queue_mutex.unlock ();
106 
107  if (m_processing.tryAcquire ()) // if callback not processing, post event
109  }
110 
111  // callback for executing the command by the worker thread
112 
114  {
115  bool repost = false; // flag for reposting event for this callback
116 
117  if (! m_queue.isEmpty ()) // list can not be empty here, just to make sure
118  {
119  m_queue_mutex.lock (); // critical path
120 
121  octave_cmd *cmd = m_queue.takeFirst ();
122 
123  if (m_queue.isEmpty ())
124  m_processing.release (); // cmd queue empty, processing will stop
125  else
126  repost = true; // not empty, repost at end
127  m_queue_mutex.unlock ();
128 
129  cmd->execute ();
130 
131  delete cmd;
132  }
133 
134  if (repost) // queue not empty, so repost event for further processing
136  }
137 }
void add_cmd(octave_cmd *cmd)
Adds a new octave command to the command queue.
Definition: octave-cmd.cc:101
void execute_command_callback(void)
Callback routine for executing the command by the worker thread.
Definition: octave-cmd.cc:113
virtual void execute(void)
Definition: octave-cmd.h:45
bool valid_identifier(const char *s)
Definition: utils.cc:74
static void replace_line(const std::string &text, bool clear_undo=true)
Definition: cmd-edit.cc:1454
QList< octave_cmd * > m_queue
Definition: octave-cmd.h:115
static bool interrupt(bool=true)
Definition: cmd-edit.cc:1619
static void redisplay(void)
Definition: cmd-edit.cc:1225
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).isinteger())
static void set_initial_input(const std::string &text)
Definition: cmd-edit.cc:1108
static void accept_line(void)
Definition: cmd-edit.cc:1482
static std::string get_current_line(void)
Definition: cmd-edit.cc:1440
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:888