GNU Octave  4.0.0
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 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 <[email protected]>
24 
25 #ifdef 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 {
43  std::string pending_input = command_editor::get_current_line ();
44 
45  command_editor::set_initial_input (pending_input);
46  command_editor::replace_line (_cmd.toStdString ());
49 }
50 
51 
52 // ---------------------------------------------------------------------
53 // class octave_cmd_eval: running a file
54 
55 void
57 {
58  QString function_name = _info.fileName ();
59  function_name.chop (_info.suffix ().length () + 1);
60  std::string file_path = _info.absoluteFilePath ().toStdString ();
61 
62  std::string pending_input = command_editor::get_current_line ();
63 
64  if (valid_identifier (function_name.toStdString ()))
65  {
66  // valid identifier: call as function with possibility to debug
67  std::string path = _info.absolutePath ().toStdString ();
68  if (octave_qt_link::file_in_path (file_path, path))
69  command_editor::replace_line (function_name.toStdString ());
70  }
71  else
72  {
73  // no valid identifier: use Fsource (), no debug possible
74  Fsource (ovl (file_path));
76  }
77 
78  command_editor::set_initial_input (pending_input);
80 
82 }
QFileInfo _info
Definition: octave-cmd.h:70
OCTINTERP_API octave_value_list Fsource(const octave_value_list &=octave_value_list(), int=0)
Definition: oct-parse.cc:8588
static void accept_line(void)
Definition: cmd-edit.cc:1368
bool valid_identifier(const char *s)
Definition: utils.cc:77
static std::string get_current_line(void)
Definition: cmd-edit.cc:1334
static bool interrupt(bool=true)
Definition: cmd-edit.cc:1515
QString _cmd
Definition: octave-cmd.h:54
octave_value_list ovl(const octave_value &a0)
Definition: oct-obj.h:178
static void redisplay(void)
Definition: cmd-edit.cc:1119
static void replace_line(const std::string &text, bool clear_undo=true)
Definition: cmd-edit.cc:1340
static void set_initial_input(const std::string &text)
Definition: cmd-edit.cc:996