Mercurial > octave
changeset 27101:097774bed4ed
move some static functions inside octave namespace
In most files that define static functions and use the octave
namespace, define the static fucntions inside the namespace.
Files affected: octave-qscintilla.cc, main-window.cc,
variable-editor-model.cc, variable-editor.cc, welcome-wizard.cc,
call-stack.cc, environment.cc, help.cc, input.cc, load-path.cc,
sysdep.cc, text-renderer.cc, url-handle-manager.cc, __ode15__.cc,
ov-typeinfo.cc, aepbalance.cc, chol.cc, gsvd.cc, file-ops.cc,
lo-array-errwarn.cc, lo-regexp.cc, oct-glob.cc, and oct-sparse.cc.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 21 May 2019 19:50:59 +0000 |
parents | b453b586da16 |
children | 84ff9953faa1 |
files | libgui/src/m-editor/octave-qscintilla.cc libgui/src/main-window.cc libgui/src/variable-editor-model.cc libgui/src/variable-editor.cc libgui/src/welcome-wizard.cc libinterp/corefcn/call-stack.cc libinterp/corefcn/environment.cc libinterp/corefcn/help.cc libinterp/corefcn/input.cc libinterp/corefcn/load-path.cc libinterp/corefcn/sysdep.cc libinterp/corefcn/text-renderer.cc libinterp/corefcn/url-handle-manager.cc libinterp/dldfcn/__ode15__.cc libinterp/octave-value/ov-typeinfo.cc liboctave/numeric/aepbalance.cc liboctave/numeric/chol.cc liboctave/numeric/gsvd.cc liboctave/system/file-ops.cc liboctave/util/lo-array-errwarn.cc liboctave/util/lo-regexp.cc liboctave/util/oct-glob.cc liboctave/util/oct-sparse.cc |
diffstat | 23 files changed, 1405 insertions(+), 1387 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/octave-qscintilla.cc Tue May 21 17:39:13 2019 +0000 +++ b/libgui/src/m-editor/octave-qscintilla.cc Tue May 21 19:50:59 2019 +0000 @@ -65,45 +65,45 @@ // Used for testing the last word of an "if" etc. line, // or the first word of the following line. -static bool -is_end (const QString& candidate, const QString& opening) -{ - bool retval = false; - - if (opening == "do") // The only one that can't be ended by "end" - { - if (candidate == "until") - retval = true; - } - else - { - if (candidate == "end") - retval = true; - else - { - if (opening == "try") - { - if (candidate == "catch" || candidate == "end_try_catch") - retval = true; - } - else if (opening == "unwind_protect") - { - if (candidate == "unwind_protect_cleanup" - || candidate == "end_unwind_protect") - retval = true; - } - else if (candidate == "end" + opening) - retval = true; - else if (opening == "if" && candidate == "else") - retval = true; - } - } - - return retval; -} - namespace octave { + static bool + is_end (const QString& candidate, const QString& opening) + { + bool retval = false; + + if (opening == "do") // The only one that can't be ended by "end" + { + if (candidate == "until") + retval = true; + } + else + { + if (candidate == "end") + retval = true; + else + { + if (opening == "try") + { + if (candidate == "catch" || candidate == "end_try_catch") + retval = true; + } + else if (opening == "unwind_protect") + { + if (candidate == "unwind_protect_cleanup" + || candidate == "end_unwind_protect") + retval = true; + } + else if (candidate == "end" + opening) + retval = true; + else if (opening == "if" && candidate == "else") + retval = true; + } + } + + return retval; + } + octave_qscintilla::octave_qscintilla (QWidget *p) : QsciScintilla (p), m_word_at_cursor (), m_selection (), m_selection_replacement (), m_selection_line (-1),
--- a/libgui/src/main-window.cc Tue May 21 17:39:13 2019 +0000 +++ b/libgui/src/main-window.cc Tue May 21 19:50:59 2019 +0000 @@ -80,30 +80,30 @@ #include "utils.h" #include "version.h" -static octave::file_editor_interface * -create_default_editor (QWidget *p) -{ -#if defined (HAVE_QSCINTILLA) - return new octave::file_editor (p); -#else - octave_unused_parameter (p); - - return 0; -#endif -} - -// Disable all Qt messages by default. - -static void -#if defined (QTMESSAGEHANDLER_ACCEPTS_QMESSAGELOGCONTEXT) -message_handler (QtMsgType, const QMessageLogContext &, const QString &) -#else -message_handler (QtMsgType, const char *) -#endif -{ } - namespace octave { + static file_editor_interface * + create_default_editor (QWidget *p) + { +#if defined (HAVE_QSCINTILLA) + return new octave::file_editor (p); +#else + octave_unused_parameter (p); + + return 0; +#endif + } + + // Disable all Qt messages by default. + + static void +#if defined (QTMESSAGEHANDLER_ACCEPTS_QMESSAGELOGCONTEXT) + message_handler (QtMsgType, const QMessageLogContext &, const QString &) +#else + message_handler (QtMsgType, const char *) +#endif + { } + octave_interpreter::octave_interpreter (gui_application& app_context) : QObject (), m_app_context (app_context) { }
--- a/libgui/src/variable-editor-model.cc Tue May 21 17:39:13 2019 +0000 +++ b/libgui/src/variable-editor-model.cc Tue May 21 19:50:59 2019 +0000 @@ -46,48 +46,48 @@ #include "utils.h" #include "variables.h" -static bool -cell_is_editable (const octave_value& val) -{ - if ((val.isnumeric () || val.islogical ()) && val.numel () == 1) - return true; - - if (val.is_string () && (val.rows () == 1 || val.is_zero_by_zero ())) - return true; - - return false; -} - -static char -get_quote_char (const octave_value& val) -{ - if (val.is_sq_string ()) - return '\''; - - if (val.is_dq_string ()) - return '"'; - - return 0; -} - -static float_display_format -get_edit_display_format (const octave_value& val) -{ - // FIXME: make this limit configurable. - - return (val.numel () > 250000 - ? float_display_format () : val.get_edit_display_format ()); -} - -static bool -do_requires_sub_editor_sub (const octave_value& elt) -{ - return (! ((elt.numel () == 1 && (elt.isnumeric () || elt.islogical ())) - || (elt.is_string () && (elt.rows () == 1 || elt.isempty ())))); -} - namespace octave { + static bool + cell_is_editable (const octave_value& val) + { + if ((val.isnumeric () || val.islogical ()) && val.numel () == 1) + return true; + + if (val.is_string () && (val.rows () == 1 || val.is_zero_by_zero ())) + return true; + + return false; + } + + static char + get_quote_char (const octave_value& val) + { + if (val.is_sq_string ()) + return '\''; + + if (val.is_dq_string ()) + return '"'; + + return 0; + } + + static float_display_format + get_edit_display_format (const octave_value& val) + { + // FIXME: make this limit configurable. + + return (val.numel () > 250000 + ? float_display_format () : val.get_edit_display_format ()); + } + + static bool + do_requires_sub_editor_sub (const octave_value& elt) + { + return (! ((elt.numel () == 1 && (elt.isnumeric () || elt.islogical ())) + || (elt.is_string () && (elt.rows () == 1 || elt.isempty ())))); + } + base_ve_model::base_ve_model (const QString& expr, const octave_value& val) : m_name (expr.toStdString ()), m_value (val),
--- a/libgui/src/variable-editor.cc Tue May 21 17:39:13 2019 +0000 +++ b/libgui/src/variable-editor.cc Tue May 21 19:50:59 2019 +0000 @@ -54,36 +54,36 @@ #include "variable-editor-model.h" #include "gui-preferences.h" -// Code reuse functions - -static QString -idx_to_expr (int32_t from, int32_t to) -{ - return (from == to - ? QString ("%1").arg (from) - : QString ("%1:%2").arg (from).arg (to)); -} - -static QSignalMapper * -make_plot_mapper (QMenu *menu) -{ - QList<QString> list; - list << "plot" << "bar" << "stem" << "stairs" << "area" << "pie" << "hist"; - - QSignalMapper *plot_mapper = new QSignalMapper (menu); - - for (int i = 0; i < list.size(); ++i) - { - plot_mapper->setMapping - (menu->addAction (list.at (i), plot_mapper, SLOT (map ())), - "figure (); " + list.at (i) + " (%1); title (\"%1\");"); - } - - return plot_mapper; -} - namespace octave { + // Code reuse functions + + static QString + idx_to_expr (int32_t from, int32_t to) + { + return (from == to + ? QString ("%1").arg (from) + : QString ("%1:%2").arg (from).arg (to)); + } + + static QSignalMapper * + make_plot_mapper (QMenu *menu) + { + QList<QString> list; + list << "plot" << "bar" << "stem" << "stairs" << "area" << "pie" << "hist"; + + QSignalMapper *plot_mapper = new QSignalMapper (menu); + + for (int i = 0; i < list.size(); ++i) + { + plot_mapper->setMapping + (menu->addAction (list.at (i), plot_mapper, SLOT (map ())), + "figure (); " + list.at (i) + " (%1); title (\"%1\");"); + } + + return plot_mapper; + } + // Variable dock widget variable_dock_widget::variable_dock_widget (QWidget *p)
--- a/libgui/src/welcome-wizard.cc Tue May 21 17:39:13 2019 +0000 +++ b/libgui/src/welcome-wizard.cc Tue May 21 19:50:59 2019 +0000 @@ -39,17 +39,17 @@ #include "welcome-wizard.h" #include "resource-manager.h" -static QLabel * -make_octave_logo (QWidget *p = nullptr, int height = 100) -{ - QLabel *logo = new QLabel (p); - QPixmap logo_pixmap (":/actions/icons/logo.png"); - logo->setPixmap (logo_pixmap.scaledToHeight (height)); - return logo; -}; - namespace octave { + static QLabel * + make_octave_logo (QWidget *p = nullptr, int height = 100) + { + QLabel *logo = new QLabel (p); + QPixmap logo_pixmap (":/actions/icons/logo.png"); + logo->setPixmap (logo_pixmap.scaledToHeight (height)); + return logo; + }; + welcome_wizard::welcome_wizard (QWidget *p) : QDialog (p), m_page_ctor_list (), m_page_list_iterator (), m_current_page (initial_page::create (this)),
--- a/libinterp/corefcn/call-stack.cc Tue May 21 17:39:13 2019 +0000 +++ b/libinterp/corefcn/call-stack.cc Tue May 21 19:50:59 2019 +0000 @@ -48,14 +48,15 @@ #include "symscope.h" #include "variables.h" -// Use static fields for the best efficiency. -// NOTE: C++0x will allow these two to be merged into one. -static const char *bt_fieldnames[] = - { "file", "name", "line", "column", "scope", nullptr }; -static const octave_fields bt_fields (bt_fieldnames); - namespace octave { + // Use static fields for the best efficiency. + // NOTE: C++0x will allow these two to be merged into one. + static const char *bt_fieldnames[] = + { "file", "name", "line", "column", "scope", nullptr }; + + static const octave_fields bt_fields (bt_fieldnames); + call_stack::call_stack (tree_evaluator& evaluator) : m_evaluator (evaluator), m_cs (), m_curr_frame (0), m_max_stack_depth (1024), m_global_values ()
--- a/libinterp/corefcn/environment.cc Tue May 21 17:39:13 2019 +0000 +++ b/libinterp/corefcn/environment.cc Tue May 21 19:50:59 2019 +0000 @@ -38,35 +38,35 @@ #include "interpreter.h" #include "variables.h" -static void append_to_shell_path (const std::string& exec_path) -{ - // FIXME: should there be a way to remove a previous setting from - // PATH? - - if (exec_path.empty ()) - return; - - // FIXME: should we really be modifying PATH in the environment? - - std::string shell_path = octave::sys::env::getenv ("PATH"); - - if (shell_path.empty ()) - octave::sys::env::putenv ("PATH", exec_path); - else - { - // If PATH doesn't already have exec_path, append it. - // FIXME: should we search for the elements individually, and - // only append those that are missing? - - std::string path_sep = octave::directory_path::path_sep_str (); - - if (shell_path.find (exec_path) == std::string::npos) - octave::sys::env::putenv ("PATH", shell_path + path_sep + exec_path); - } -} - namespace octave { + static void append_to_shell_path (const std::string& exec_path) + { + // FIXME: should there be a way to remove a previous setting from + // PATH? + + if (exec_path.empty ()) + return; + + // FIXME: should we really be modifying PATH in the environment? + + std::string shell_path = octave::sys::env::getenv ("PATH"); + + if (shell_path.empty ()) + octave::sys::env::putenv ("PATH", exec_path); + else + { + // If PATH doesn't already have exec_path, append it. + // FIXME: should we search for the elements individually, and + // only append those that are missing? + + std::string path_sep = octave::directory_path::path_sep_str (); + + if (shell_path.find (exec_path) == std::string::npos) + octave::sys::env::putenv ("PATH", shell_path + path_sep + exec_path); + } + } + octave_value environment::editor (const octave_value_list& args, int nargout) {
--- a/libinterp/corefcn/help.cc Tue May 21 17:39:13 2019 +0000 +++ b/libinterp/corefcn/help.cc Tue May 21 19:50:59 2019 +0000 @@ -72,86 +72,86 @@ #include "default-defs.h" -const static char * const operators[] = -{ - "!", - "~", - "!=", - "~=", - R"(")", - "#", - "%", - "#{", - "%{", - "#}", - "%}", - "...", - "&", - "&&", - "'", - "(", - ")", - "*", - "**", - "^", - "+", - "++", - ",", - "-", - "--", - ".'", - ".*", - ".**", - ".^", - "./", - "/", - R"(.\)", - R"(\)", - ":", - ";", - "<", - "<=", - "=", - "==", - ">", - ">=", - "[", - "]", - "|", - "||", - nullptr -}; - -const static string_vector operator_names (operators); - -static bool -looks_like_html (const std::string& msg) -{ - const size_t p1 = msg.find ('\n'); - std::string t = msg.substr (0, p1); - // FIXME: this comparison should be case-insensitive - const size_t p2 = t.find ("<html"); - - return (p2 != std::string::npos); -} - -static bool -looks_like_texinfo (const std::string& msg, size_t& p1) -{ - p1 = msg.find ('\n'); - - std::string t = msg.substr (0, p1); - - if (p1 == std::string::npos) - p1 = 0; - - size_t p2 = t.find ("-*- texinfo -*-"); - - return (p2 != std::string::npos); -} - namespace octave { + const static char * const operators[] = + { + "!", + "~", + "!=", + "~=", + R"(")", + "#", + "%", + "#{", + "%{", + "#}", + "%}", + "...", + "&", + "&&", + "'", + "(", + ")", + "*", + "**", + "^", + "+", + "++", + ",", + "-", + "--", + ".'", + ".*", + ".**", + ".^", + "./", + "/", + R"(.\)", + R"(\)", + ":", + ";", + "<", + "<=", + "=", + "==", + ">", + ">=", + "[", + "]", + "|", + "||", + nullptr + }; + + const static string_vector operator_names (operators); + + static bool + looks_like_html (const std::string& msg) + { + const size_t p1 = msg.find ('\n'); + std::string t = msg.substr (0, p1); + // FIXME: this comparison should be case-insensitive + const size_t p2 = t.find ("<html"); + + return (p2 != std::string::npos); + } + + static bool + looks_like_texinfo (const std::string& msg, size_t& p1) + { + p1 = msg.find ('\n'); + + std::string t = msg.substr (0, p1); + + if (p1 == std::string::npos) + p1 = 0; + + size_t p2 = t.find ("-*- texinfo -*-"); + + return (p2 != std::string::npos); + } + octave_value help_system::built_in_docstrings_file (const octave_value_list& args, int nargout) @@ -766,7 +766,7 @@ Undocumented internal function. @end deftypefn */) { - return ovl (Cell (operator_names)); + return ovl (Cell (octave::operator_names)); } // Return a cell array of strings containing the names of all keywords.
--- a/libinterp/corefcn/input.cc Tue May 21 17:39:13 2019 +0000 +++ b/libinterp/corefcn/input.cc Tue May 21 19:50:59 2019 +0000 @@ -91,302 +91,302 @@ // the terminal. bool Vtrack_line_num = true; -static std::string -quoting_filename (const std::string& text, int, char quote) -{ - if (quote) - return text; - else - return ("'" + text); -} - -// Try to parse a partial command line in reverse, excluding trailing TEXT. -// If it appears a variable has been indexed by () or {}, -// return that expression, -// to allow autocomplete of field names of arrays of structures. -static std::string -find_indexed_expression (const std::string& text) -{ - std::string line = octave::command_editor::get_line_buffer (); - - int pos = line.length () - text.length (); - int curly_count = 0; - int paren_count = 0; - - int last = --pos; - - while (pos >= 0 && (line[pos] == ')' || line[pos] == '}')) - { - if (line[pos] == ')') - paren_count++; - else - curly_count++; - - while (curly_count + paren_count > 0 && --pos >= 0) - { - if (line[pos] == ')') - paren_count++; - else if (line[pos] == '(') - paren_count--; - else if (line[pos] == '}') - curly_count++; - else if (line[pos] == '{') - curly_count--; - } - - while (--pos >= 0 && line[pos] == ' ') - ; - } - - while (pos >= 0 && (isalnum (line[pos]) || line[pos] == '_')) - pos--; - - if (++pos >= 0) - return (line.substr (pos, last + 1 - pos)); - else - return std::string (); -} - -static string_vector -generate_struct_completions (const std::string& text, - std::string& prefix, std::string& hint) -{ - string_vector names; - - size_t pos = text.rfind ('.'); - bool array = false; - - if (pos != std::string::npos) - { - if (pos == text.length ()) - hint = ""; - else - hint = text.substr (pos+1); - - prefix = text.substr (0, pos); - - if (prefix == "") - { - array = true; - prefix = find_indexed_expression (text); - } - - std::string base_name = prefix; - - pos = base_name.find_first_of ("{(. "); - - if (pos != std::string::npos) - base_name = base_name.substr (0, pos); - - octave::interpreter& interp - = octave::__get_interpreter__ ("generate_struct_completions"); - - if (interp.is_variable (base_name)) - { - int parse_status; - - octave::unwind_protect frame; - - frame.protect_var (discard_error_messages); - frame.protect_var (discard_warning_messages); - - discard_error_messages = true; - discard_warning_messages = true; - - try - { - octave_value tmp - = interp.eval_string (prefix, true, parse_status); - - frame.run (); - - if (tmp.is_defined () - && (tmp.isstruct () || tmp.isjava () || tmp.is_classdef_object ())) - names = tmp.map_keys (); - } - catch (const octave::execution_exception&) - { - octave::interpreter::recover_from_exception (); - } - } - } - - // Undo look-back that found the array expression, - // but insert an extra "." to distinguish from the non-struct case. - if (array) - prefix = "."; - - return names; -} - -// FIXME: this will have to be much smarter to work "correctly". -static bool -looks_like_struct (const std::string& text, char prev_char) -{ - bool retval = (! text.empty () - && (text != "." || prev_char == ')' || prev_char == '}') - && text.find_first_of (octave::sys::file_ops::dir_sep_chars ()) == std::string::npos - && text.find ("..") == std::string::npos - && text.rfind ('.') != std::string::npos); - - return retval; -} - -// FIXME: make this generate filenames when appropriate. - -static string_vector -generate_possible_completions (const std::string& text, std::string& prefix, - std::string& hint, bool& deemed_struct) -{ - string_vector names; - - prefix = ""; - - char prev_char = octave::command_editor::get_prev_char (text.length ()); - deemed_struct = looks_like_struct (text, prev_char); - - if (deemed_struct) - names = generate_struct_completions (text, prefix, hint); - else - names = octave::make_name_list (); - - // Sort and remove duplicates. - - names.sort (true); - - return names; -} - -static bool -is_completing_dirfns (void) -{ - static std::string dirfns_commands[] = {"cd", "isfile", "isfolder", "ls"}; - static const size_t dirfns_commands_length = 4; - - bool retval = false; - - std::string line = octave::command_editor::get_line_buffer (); - - for (size_t i = 0; i < dirfns_commands_length; i++) - { - int index = line.find (dirfns_commands[i] + ' '); - - if (index == 0) - { - retval = true; - break; - } - } - - return retval; -} - -static std::string -generate_completion (const std::string& text, int state) -{ - std::string retval; - - static std::string prefix; - static std::string hint; - - static size_t hint_len = 0; - - static int list_index = 0; - static int name_list_len = 0; - static int name_list_total_len = 0; - static string_vector name_list; - static string_vector file_name_list; - - static int matches = 0; - - if (state == 0) - { - list_index = 0; - - prefix = ""; - - hint = text; - - // No reason to display symbols while completing a - // file/directory operation. - - bool deemed_struct = false; - - if (is_completing_dirfns ()) - name_list = string_vector (); - else - name_list = generate_possible_completions (text, prefix, hint, - deemed_struct); - - name_list_len = name_list.numel (); - - // If the line was something like "a{1}." then text = "." but - // we don't want to expand all the . files. - if (! deemed_struct) - { - - file_name_list = octave::command_editor::generate_filename_completions (text); - - name_list.append (file_name_list); - - } - - name_list_total_len = name_list.numel (); - - hint_len = hint.length (); - - matches = 0; - - for (int i = 0; i < name_list_len; i++) - if (hint == name_list[i].substr (0, hint_len)) - matches++; - } - - if (name_list_total_len > 0 && matches > 0) - { - while (list_index < name_list_total_len) - { - std::string name = name_list[list_index]; - - list_index++; - - if (hint == name.substr (0, hint_len)) - { - // Special case: array reference forces prefix="." - // in generate_struct_completions () - if (list_index <= name_list_len && ! prefix.empty ()) - retval = (prefix == "." ? "" : prefix) + '.' + name; - else - retval = name; - - char prev_char = octave::command_editor::get_prev_char - (text.length ()); - if (matches == 1 && looks_like_struct (retval, prev_char)) - { - // Don't append anything, since we don't know - // whether it should be '(' or '.'. - - octave::command_editor::set_completion_append_character ('\0'); - } - else - { - octave::input_system& input_sys - = octave::__get_input_system__ ("generate_completion"); - - octave::command_editor::set_completion_append_character - (input_sys.completion_append_char ()); - } - - break; - } - } - } - - return retval; -} - namespace octave { + static std::string + quoting_filename (const std::string& text, int, char quote) + { + if (quote) + return text; + else + return ("'" + text); + } + + // Try to parse a partial command line in reverse, excluding trailing TEXT. + // If it appears a variable has been indexed by () or {}, + // return that expression, + // to allow autocomplete of field names of arrays of structures. + static std::string + find_indexed_expression (const std::string& text) + { + std::string line = octave::command_editor::get_line_buffer (); + + int pos = line.length () - text.length (); + int curly_count = 0; + int paren_count = 0; + + int last = --pos; + + while (pos >= 0 && (line[pos] == ')' || line[pos] == '}')) + { + if (line[pos] == ')') + paren_count++; + else + curly_count++; + + while (curly_count + paren_count > 0 && --pos >= 0) + { + if (line[pos] == ')') + paren_count++; + else if (line[pos] == '(') + paren_count--; + else if (line[pos] == '}') + curly_count++; + else if (line[pos] == '{') + curly_count--; + } + + while (--pos >= 0 && line[pos] == ' ') + ; + } + + while (pos >= 0 && (isalnum (line[pos]) || line[pos] == '_')) + pos--; + + if (++pos >= 0) + return (line.substr (pos, last + 1 - pos)); + else + return std::string (); + } + + static string_vector + generate_struct_completions (const std::string& text, + std::string& prefix, std::string& hint) + { + string_vector names; + + size_t pos = text.rfind ('.'); + bool array = false; + + if (pos != std::string::npos) + { + if (pos == text.length ()) + hint = ""; + else + hint = text.substr (pos+1); + + prefix = text.substr (0, pos); + + if (prefix == "") + { + array = true; + prefix = find_indexed_expression (text); + } + + std::string base_name = prefix; + + pos = base_name.find_first_of ("{(. "); + + if (pos != std::string::npos) + base_name = base_name.substr (0, pos); + + octave::interpreter& interp + = octave::__get_interpreter__ ("generate_struct_completions"); + + if (interp.is_variable (base_name)) + { + int parse_status; + + octave::unwind_protect frame; + + frame.protect_var (discard_error_messages); + frame.protect_var (discard_warning_messages); + + discard_error_messages = true; + discard_warning_messages = true; + + try + { + octave_value tmp + = interp.eval_string (prefix, true, parse_status); + + frame.run (); + + if (tmp.is_defined () + && (tmp.isstruct () || tmp.isjava () || tmp.is_classdef_object ())) + names = tmp.map_keys (); + } + catch (const octave::execution_exception&) + { + octave::interpreter::recover_from_exception (); + } + } + } + + // Undo look-back that found the array expression, + // but insert an extra "." to distinguish from the non-struct case. + if (array) + prefix = "."; + + return names; + } + + // FIXME: this will have to be much smarter to work "correctly". + static bool + looks_like_struct (const std::string& text, char prev_char) + { + bool retval = (! text.empty () + && (text != "." || prev_char == ')' || prev_char == '}') + && text.find_first_of (octave::sys::file_ops::dir_sep_chars ()) == std::string::npos + && text.find ("..") == std::string::npos + && text.rfind ('.') != std::string::npos); + + return retval; + } + + // FIXME: make this generate filenames when appropriate. + + static string_vector + generate_possible_completions (const std::string& text, std::string& prefix, + std::string& hint, bool& deemed_struct) + { + string_vector names; + + prefix = ""; + + char prev_char = octave::command_editor::get_prev_char (text.length ()); + deemed_struct = looks_like_struct (text, prev_char); + + if (deemed_struct) + names = generate_struct_completions (text, prefix, hint); + else + names = octave::make_name_list (); + + // Sort and remove duplicates. + + names.sort (true); + + return names; + } + + static bool + is_completing_dirfns (void) + { + static std::string dirfns_commands[] = {"cd", "isfile", "isfolder", "ls"}; + static const size_t dirfns_commands_length = 4; + + bool retval = false; + + std::string line = octave::command_editor::get_line_buffer (); + + for (size_t i = 0; i < dirfns_commands_length; i++) + { + int index = line.find (dirfns_commands[i] + ' '); + + if (index == 0) + { + retval = true; + break; + } + } + + return retval; + } + + static std::string + generate_completion (const std::string& text, int state) + { + std::string retval; + + static std::string prefix; + static std::string hint; + + static size_t hint_len = 0; + + static int list_index = 0; + static int name_list_len = 0; + static int name_list_total_len = 0; + static string_vector name_list; + static string_vector file_name_list; + + static int matches = 0; + + if (state == 0) + { + list_index = 0; + + prefix = ""; + + hint = text; + + // No reason to display symbols while completing a + // file/directory operation. + + bool deemed_struct = false; + + if (is_completing_dirfns ()) + name_list = string_vector (); + else + name_list = generate_possible_completions (text, prefix, hint, + deemed_struct); + + name_list_len = name_list.numel (); + + // If the line was something like "a{1}." then text = "." but + // we don't want to expand all the . files. + if (! deemed_struct) + { + + file_name_list = octave::command_editor::generate_filename_completions (text); + + name_list.append (file_name_list); + + } + + name_list_total_len = name_list.numel (); + + hint_len = hint.length (); + + matches = 0; + + for (int i = 0; i < name_list_len; i++) + if (hint == name_list[i].substr (0, hint_len)) + matches++; + } + + if (name_list_total_len > 0 && matches > 0) + { + while (list_index < name_list_total_len) + { + std::string name = name_list[list_index]; + + list_index++; + + if (hint == name.substr (0, hint_len)) + { + // Special case: array reference forces prefix="." + // in generate_struct_completions () + if (list_index <= name_list_len && ! prefix.empty ()) + retval = (prefix == "." ? "" : prefix) + '.' + name; + else + retval = name; + + char prev_char = octave::command_editor::get_prev_char + (text.length ()); + if (matches == 1 && looks_like_struct (retval, prev_char)) + { + // Don't append anything, since we don't know + // whether it should be '(' or '.'. + + octave::command_editor::set_completion_append_character ('\0'); + } + else + { + octave::input_system& input_sys + = octave::__get_input_system__ ("generate_completion"); + + octave::command_editor::set_completion_append_character + (input_sys.completion_append_char ()); + } + + break; + } + } + } + + return retval; + } + // Use literal "octave" in default setting for PS1 instead of // "\\s" to avoid setting the prompt to "octave.exe" or // "octave-gui", etc. @@ -1097,7 +1097,7 @@ for (;;) { - std::string cmd = generate_completion (hint, k); + std::string cmd = octave::generate_completion (hint, k); if (! cmd.empty ()) { @@ -1203,18 +1203,20 @@ return ovl (); } -static int -internal_input_event_hook_fcn (void) +namespace octave { - octave::input_system& input_sys - = octave::__get_input_system__ ("internal_input_event_hook_fcn"); + static int internal_input_event_hook_fcn (void) + { + input_system& input_sys + = __get_input_system__ ("internal_input_event_hook_fcn"); - input_sys.run_input_event_hooks (); + input_sys.run_input_event_hooks (); - if (! input_sys.have_input_event_hooks ()) - octave::command_editor::remove_event_hook (internal_input_event_hook_fcn); + if (! input_sys.have_input_event_hooks ()) + command_editor::remove_event_hook (internal_input_event_hook_fcn); - return 0; + return 0; + } } DEFMETHOD (add_input_event_hook, interp, args, , @@ -1252,7 +1254,7 @@ hook_function hook_fcn (args(0), user_data); if (! input_sys.have_input_event_hooks ()) - octave::command_editor::add_event_hook (internal_input_event_hook_fcn); + octave::command_editor::add_event_hook (octave::internal_input_event_hook_fcn); input_sys.add_input_event_hook (hook_fcn); @@ -1285,7 +1287,7 @@ hook_fcn_id.c_str ()); if (! input_sys.have_input_event_hooks ()) - octave::command_editor::remove_event_hook (internal_input_event_hook_fcn); + octave::command_editor::remove_event_hook (octave::internal_input_event_hook_fcn); return ovl (); }
--- a/libinterp/corefcn/load-path.cc Tue May 21 17:39:13 2019 +0000 +++ b/libinterp/corefcn/load-path.cc Tue May 21 19:50:59 2019 +0000 @@ -46,146 +46,146 @@ #include "unwind-prot.h" #include "utils.h" -static void -maybe_add_path_elts (std::string& path, const std::string& dir) -{ - std::string tpath = octave::genpath (dir); - - if (! tpath.empty ()) - { - if (path.empty ()) - path = tpath; - else - path += octave::directory_path::path_sep_str () + tpath; - } -} - -static std::list<std::string> -split_path (const std::string& p) -{ - std::list<std::string> retval; - - size_t beg = 0; - size_t end = p.find (octave::directory_path::path_sep_char ()); - - size_t len = p.length (); - - while (end != std::string::npos) - { - std::string elt = p.substr (beg, end-beg); - - if (! elt.empty ()) - retval.push_back (elt); - - beg = end + 1; - - if (beg == len) - break; - - end = p.find (octave::directory_path::path_sep_char (), beg); - } - - std::string elt = p.substr (beg); - - if (! elt.empty ()) - retval.push_back (elt); - - return retval; -} - -// Strip trailing directory separators. - -static std::string -strip_trailing_separators (const std::string& dir_arg) -{ - std::string dir = dir_arg; - - size_t k = dir.length (); - - while (k > 1 && octave::sys::file_ops::is_dir_sep (dir[k-1])) - k--; - - if (k < dir.length ()) - dir.resize (k); - - return dir; -} - -// Should we cache all files in private directories, or is it OK to just -// look them up each time as needed? - -static std::string -find_private_file (const std::string& fname) -{ - std::string retval; - - // Look in private directory corresponding to current function (if - // any). - - octave::symbol_scope scope = octave::__get_current_scope__ ("find_private_file"); - - octave_user_function *curr_fcn = scope ? scope.function () : nullptr; - - if (curr_fcn) - { - // Even for private functions, dir_name doesn't contain the - // "private" directory component so we append it here in all - // cases. - - std::string dir_name = curr_fcn->dir_name (); - - if (! dir_name.empty ()) - { - std::string pfname = dir_name + octave::sys::file_ops::dir_sep_str () - + "private" + octave::sys::file_ops::dir_sep_str () + fname; - - octave::sys::file_stat fs (pfname); - - if (fs.exists () && fs.is_reg ()) - retval = pfname; - } - } - - return retval; -} - -// True if a path is contained in a path list separated by path_sep_char - -static bool -in_path_list (const std::string& path_list, const std::string& path) -{ - size_t ps = path.size (); - size_t pls = path_list.size (); - size_t pos = path_list.find (path); - char psc = octave::directory_path::path_sep_char (); - while (pos != std::string::npos) - { - if ((pos == 0 || path_list[pos-1] == psc) - && (pos + ps == pls || path_list[pos + ps] == psc)) - return true; - else - pos = path_list.find (path, pos + 1); - } - - return false; -} - -static void -rehash_internal (void) -{ - octave::load_path& lp = octave::__get_load_path__ ("rehash_internal"); - - lp.update (); - - // FIXME: maybe we should rename this variable since it is being - // used for more than keeping track of the prompt time. - - // This will force updated functions to be found. - Vlast_prompt_time.stamp (); -} - namespace octave { + static void + maybe_add_path_elts (std::string& path, const std::string& dir) + { + std::string tpath = octave::genpath (dir); + + if (! tpath.empty ()) + { + if (path.empty ()) + path = tpath; + else + path += octave::directory_path::path_sep_str () + tpath; + } + } + + static std::list<std::string> + split_path (const std::string& p) + { + std::list<std::string> retval; + + size_t beg = 0; + size_t end = p.find (octave::directory_path::path_sep_char ()); + + size_t len = p.length (); + + while (end != std::string::npos) + { + std::string elt = p.substr (beg, end-beg); + + if (! elt.empty ()) + retval.push_back (elt); + + beg = end + 1; + + if (beg == len) + break; + + end = p.find (octave::directory_path::path_sep_char (), beg); + } + + std::string elt = p.substr (beg); + + if (! elt.empty ()) + retval.push_back (elt); + + return retval; + } + + // Strip trailing directory separators. + + static std::string + strip_trailing_separators (const std::string& dir_arg) + { + std::string dir = dir_arg; + + size_t k = dir.length (); + + while (k > 1 && octave::sys::file_ops::is_dir_sep (dir[k-1])) + k--; + + if (k < dir.length ()) + dir.resize (k); + + return dir; + } + + // Should we cache all files in private directories, or is it OK to just + // look them up each time as needed? + + static std::string + find_private_file (const std::string& fname) + { + std::string retval; + + // Look in private directory corresponding to current function (if + // any). + + octave::symbol_scope scope = octave::__get_current_scope__ ("find_private_file"); + + octave_user_function *curr_fcn = scope ? scope.function () : nullptr; + + if (curr_fcn) + { + // Even for private functions, dir_name doesn't contain the + // "private" directory component so we append it here in all + // cases. + + std::string dir_name = curr_fcn->dir_name (); + + if (! dir_name.empty ()) + { + std::string pfname = dir_name + octave::sys::file_ops::dir_sep_str () + + "private" + octave::sys::file_ops::dir_sep_str () + fname; + + octave::sys::file_stat fs (pfname); + + if (fs.exists () && fs.is_reg ()) + retval = pfname; + } + } + + return retval; + } + + // True if a path is contained in a path list separated by path_sep_char + + static bool + in_path_list (const std::string& path_list, const std::string& path) + { + size_t ps = path.size (); + size_t pls = path_list.size (); + size_t pos = path_list.find (path); + char psc = octave::directory_path::path_sep_char (); + while (pos != std::string::npos) + { + if ((pos == 0 || path_list[pos-1] == psc) + && (pos + ps == pls || path_list[pos + ps] == psc)) + return true; + else + pos = path_list.find (path, pos + 1); + } + + return false; + } + + static void + rehash_internal (void) + { + octave::load_path& lp = octave::__get_load_path__ ("rehash_internal"); + + lp.update (); + + // FIXME: maybe we should rename this variable since it is being + // used for more than keeping track of the prompt time. + + // This will force updated functions to be found. + Vlast_prompt_time.stamp (); + } + std::string load_path::sys_path; load_path::abs_dir_cache_type load_path::abs_dir_cache; @@ -2246,7 +2246,7 @@ Reinitialize Octave's load path directory cache. @end deftypefn */) { - rehash_internal (); + octave::rehash_internal (); return ovl (); } @@ -2337,7 +2337,7 @@ lp.set (path, true); - rehash_internal (); + octave::rehash_internal (); } if (nargout > 0) @@ -2438,7 +2438,7 @@ { std::string arg = arglist(i).xstring_value ("addpath: all arguments must be strings"); - std::list<std::string> dir_elts = split_path (arg); + std::list<std::string> dir_elts = octave::split_path (arg); if (! append) std::reverse (dir_elts.begin (), dir_elts.end ()); @@ -2483,7 +2483,7 @@ } if (need_to_update) - rehash_internal (); + octave::rehash_internal (); return retval; } @@ -2527,7 +2527,7 @@ for (int i = 0; i < nargin; i++) { std::string arg = args(i).xstring_value ("rmpath: all arguments must be strings"); - std::list<std::string> dir_elts = split_path (arg); + std::list<std::string> dir_elts = octave::split_path (arg); for (const auto& dir : dir_elts) { @@ -2542,7 +2542,7 @@ } if (need_to_update) - rehash_internal (); + octave::rehash_internal (); return retval; }
--- a/libinterp/corefcn/sysdep.cc Tue May 21 17:39:13 2019 +0000 +++ b/libinterp/corefcn/sysdep.cc Tue May 21 19:50:59 2019 +0000 @@ -88,20 +88,6 @@ # define STDIN_FILENO 1 #endif -#if defined (__386BSD__) || defined (__FreeBSD__) || defined (__NetBSD__) -static void -BSD_init (void) -{ -# if defined (HAVE_FLOATINGPOINT_H) - // Disable trapping on common exceptions. -# if ! defined (FP_X_DNML) -# define FP_X_DNML 0 -# endif - fpsetmask (~(FP_X_OFL|FP_X_INV|FP_X_DZ|FP_X_DNML|FP_X_UFL|FP_X_IMP)); -# endif -} -#endif - #if defined (__MINGW32__) || defined (_MSC_VER) #define WIN32_LEAN_AND_MEAN @@ -109,65 +95,85 @@ #include <tlhelp32.h> #include <shellapi.h> -static void -w32_set_octave_home (void) -{ - std::string bin_dir; - - HANDLE h = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE -#if defined (TH32CS_SNAPMODULE32) - | TH32CS_SNAPMODULE32 -#endif - , 0); - - if (h != INVALID_HANDLE_VALUE) - { - MODULEENTRY32W mod_info; - - ZeroMemory (&mod_info, sizeof (mod_info)); - mod_info.dwSize = sizeof (mod_info); - - if (Module32FirstW (h, &mod_info)) - { - do - { - std::string mod_name (octave::sys::u8_from_wstring (mod_info.szModule)); - - if (mod_name.find ("octinterp") != std::string::npos) - { - bin_dir = octave::sys::u8_from_wstring (mod_info.szExePath); - if (! bin_dir.empty () && bin_dir.back () != '\\') - bin_dir.push_back ('\\'); - break; - } - } - while (Module32NextW (h, &mod_info)); - } - - CloseHandle (h); - } - - if (! bin_dir.empty ()) - { - size_t pos = bin_dir.rfind (R"(\bin\)"); - - if (pos != std::string::npos) - octave::sys::env::putenv ("OCTAVE_HOME", bin_dir.substr (0, pos)); - } -} - -static void -w32_init (void) -{ - w32_set_octave_home (); - - octave::command_editor::prefer_env_winsize (true); -} - #endif namespace octave { +#if defined (__386BSD__) || defined (__FreeBSD__) || defined (__NetBSD__) + + static void + BSD_init (void) + { +# if defined (HAVE_FLOATINGPOINT_H) + // Disable trapping on common exceptions. +# if ! defined (FP_X_DNML) +# define FP_X_DNML 0 +# endif + fpsetmask (~(FP_X_OFL|FP_X_INV|FP_X_DZ|FP_X_DNML|FP_X_UFL|FP_X_IMP)); +# endif + } + +#endif + +#if defined (__MINGW32__) || defined (_MSC_VER) + + static void + w32_set_octave_home (void) + { + std::string bin_dir; + + HANDLE h = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE +#if defined (TH32CS_SNAPMODULE32) + | TH32CS_SNAPMODULE32 +#endif + , 0); + + if (h != INVALID_HANDLE_VALUE) + { + MODULEENTRY32W mod_info; + + ZeroMemory (&mod_info, sizeof (mod_info)); + mod_info.dwSize = sizeof (mod_info); + + if (Module32FirstW (h, &mod_info)) + { + do + { + std::string mod_name (octave::sys::u8_from_wstring (mod_info.szModule)); + + if (mod_name.find ("octinterp") != std::string::npos) + { + bin_dir = octave::sys::u8_from_wstring (mod_info.szExePath); + if (! bin_dir.empty () && bin_dir.back () != '\\') + bin_dir.push_back ('\\'); + break; + } + } + while (Module32NextW (h, &mod_info)); + } + + CloseHandle (h); + } + + if (! bin_dir.empty ()) + { + size_t pos = bin_dir.rfind (R"(\bin\)"); + + if (pos != std::string::npos) + octave::sys::env::putenv ("OCTAVE_HOME", bin_dir.substr (0, pos)); + } + } + + static void + w32_init (void) + { + w32_set_octave_home (); + + octave::command_editor::prefer_env_winsize (true); + } + +#endif + // Set app id if we have the SetCurrentProcessExplicitAppUserModelID // available (>= Win7). FIXME: Could we check for existence of this // function in the configure script instead of dynamically loading @@ -236,24 +242,28 @@ return retval; } +namespace octave +{ #if defined (__MINGW32__) -static void -MINGW_init (void) -{ - w32_init (); -} + + static void + MINGW_init (void) + { + w32_init (); + } + #endif #if defined (_MSC_VER) -static void -MSVC_init (void) -{ - w32_init (); -} + + static void + MSVC_init (void) + { + w32_init (); + } + #endif -namespace octave -{ // Return TRUE if FILE1 and FILE2 refer to the same (physical) file. bool same_file_internal (const std::string& file1, const std::string& file2) @@ -780,91 +790,95 @@ #if defined (OCTAVE_USE_WINDOWS_API) -static void -reg_close_key_wrapper (HKEY key) +namespace octave { - RegCloseKey (key); + static void + reg_close_key_wrapper (HKEY key) + { + RegCloseKey (key); + } + + static LONG + get_regkey_value (HKEY h_rootkey, const std::string subkey, + const std::string name, octave_value& value) + { + LONG result; + HKEY h_subkey; + + result = RegOpenKeyExW (h_rootkey, + octave::sys::u8_to_wstring (subkey).c_str (), 0, + KEY_READ, &h_subkey); + if (result != ERROR_SUCCESS) + return result; + + octave::unwind_protect frame; + + frame.add_fcn (reg_close_key_wrapper, h_subkey); + + DWORD length = 0; + result = RegQueryValueExW (h_subkey, + octave::sys::u8_to_wstring (name).c_str (), + nullptr, nullptr, nullptr, &length); + if (result != ERROR_SUCCESS) + return result; + + DWORD type = 0; + OCTAVE_LOCAL_BUFFER (BYTE, data, length); + result = RegQueryValueExW (h_subkey, + octave::sys::u8_to_wstring (name).c_str (), + nullptr, &type, data, &length); + if (result != ERROR_SUCCESS) + return result; + + if (type == REG_DWORD) + value = octave_int32 (*data); + else if (type == REG_SZ || type == REG_EXPAND_SZ) + value = string_vector (octave::sys::u8_from_wstring ( + reinterpret_cast<wchar_t *> (data))); + + return result; + } + + static LONG + get_regkey_names (HKEY h_rootkey, const std::string subkey, + std::list<std::string> &fields) + { + LONG retval; + HKEY h_subkey; + + fields.clear (); + + retval = RegOpenKeyExW (h_rootkey, + octave::sys::u8_to_wstring (subkey).c_str (), 0, + KEY_READ, &h_subkey); + if (retval != ERROR_SUCCESS) + return retval; + + DWORD idx = 0; + const int MAX_VALUE_NAME_SIZE = 32766; + wchar_t value_name[MAX_VALUE_NAME_SIZE+1]; + DWORD value_name_size = MAX_VALUE_NAME_SIZE; + + while (true) + { + retval = RegEnumValueW (h_subkey, idx, value_name, &value_name_size, + nullptr, nullptr, nullptr, nullptr); + if (retval != ERROR_SUCCESS) + break; + fields.push_back (octave::sys::u8_from_wstring (value_name)); + value_name_size = MAX_VALUE_NAME_SIZE; + idx++; + } + + if (retval == ERROR_NO_MORE_ITEMS) + retval = ERROR_SUCCESS; + + RegCloseKey (h_subkey); + + return retval; + } } -LONG -get_regkey_value (HKEY h_rootkey, const std::string subkey, - const std::string name, octave_value& value) -{ - LONG result; - HKEY h_subkey; - - result = RegOpenKeyExW (h_rootkey, - octave::sys::u8_to_wstring (subkey).c_str (), 0, - KEY_READ, &h_subkey); - if (result != ERROR_SUCCESS) - return result; - - octave::unwind_protect frame; - - frame.add_fcn (reg_close_key_wrapper, h_subkey); - - DWORD length = 0; - result = RegQueryValueExW (h_subkey, - octave::sys::u8_to_wstring (name).c_str (), - nullptr, nullptr, nullptr, &length); - if (result != ERROR_SUCCESS) - return result; - - DWORD type = 0; - OCTAVE_LOCAL_BUFFER (BYTE, data, length); - result = RegQueryValueExW (h_subkey, - octave::sys::u8_to_wstring (name).c_str (), - nullptr, &type, data, &length); - if (result != ERROR_SUCCESS) - return result; - - if (type == REG_DWORD) - value = octave_int32 (*data); - else if (type == REG_SZ || type == REG_EXPAND_SZ) - value = string_vector (octave::sys::u8_from_wstring ( - reinterpret_cast<wchar_t *> (data))); - - return result; -} - -static LONG -get_regkey_names (HKEY h_rootkey, const std::string subkey, - std::list<std::string> &fields) -{ - LONG retval; - HKEY h_subkey; - - fields.clear (); - - retval = RegOpenKeyExW (h_rootkey, - octave::sys::u8_to_wstring (subkey).c_str (), 0, - KEY_READ, &h_subkey); - if (retval != ERROR_SUCCESS) - return retval; - - DWORD idx = 0; - const int MAX_VALUE_NAME_SIZE = 32766; - wchar_t value_name[MAX_VALUE_NAME_SIZE+1]; - DWORD value_name_size = MAX_VALUE_NAME_SIZE; - - while (true) - { - retval = RegEnumValueW (h_subkey, idx, value_name, &value_name_size, - nullptr, nullptr, nullptr, nullptr); - if (retval != ERROR_SUCCESS) - break; - fields.push_back (octave::sys::u8_from_wstring (value_name)); - value_name_size = MAX_VALUE_NAME_SIZE; - idx++; - } - - if (retval == ERROR_NO_MORE_ITEMS) - retval = ERROR_SUCCESS; - - RegCloseKey (h_subkey); - - return retval; -} #endif DEFUN (winqueryreg, args, , @@ -989,7 +1003,7 @@ { std::list<std::string> fields; - LONG retval = get_regkey_names (h_rootkey, subkey_name, fields); + LONG retval = octave::get_regkey_names (h_rootkey, subkey_name, fields); if (retval != ERROR_SUCCESS) error ("winqueryreg: error %ld reading names from registry", retval); @@ -1004,8 +1018,8 @@ else { octave_value key_val; - LONG retval = get_regkey_value (h_rootkey, subkey_name, value_name, - key_val); + LONG retval = octave::get_regkey_value (h_rootkey, subkey_name, + value_name, key_val); if (retval == ERROR_FILE_NOT_FOUND) error ("winqueryreg: no value found for '%s' at %s\\%s.", value_name.c_str (), rootkey_name.c_str (),
--- a/libinterp/corefcn/text-renderer.cc Tue May 21 17:39:13 2019 +0000 +++ b/libinterp/corefcn/text-renderer.cc Tue May 21 19:50:59 2019 +0000 @@ -30,17 +30,17 @@ #include "ft-text-renderer.h" #include "text-renderer.h" -static octave::base_text_renderer * -make_text_renderer (void) -{ - // Allow the possibility of choosing different text rendering - // implementations. - - return octave::make_ft_text_renderer (); -} - namespace octave { + static octave::base_text_renderer * + make_text_renderer (void) + { + // Allow the possibility of choosing different text rendering + // implementations. + + return octave::make_ft_text_renderer (); + } + text_renderer::text_renderer (void) : rep (make_text_renderer ()) { }
--- a/libinterp/corefcn/url-handle-manager.cc Tue May 21 17:39:13 2019 +0000 +++ b/libinterp/corefcn/url-handle-manager.cc Tue May 21 19:50:59 2019 +0000 @@ -30,16 +30,16 @@ #include "url-handle-manager.h" -static double -make_handle_fraction (void) -{ - static double maxrand = RAND_MAX + 2.0; - - return (rand () + 1.0) / maxrand; -} - namespace octave { + static double + make_handle_fraction (void) + { + static double maxrand = RAND_MAX + 2.0; + + return (rand () + 1.0) / maxrand; + } + url_handle url_handle_manager::get_handle (void) { url_handle retval;
--- a/libinterp/dldfcn/__ode15__.cc Tue May 21 17:39:13 2019 +0000 +++ b/libinterp/dldfcn/__ode15__.cc Tue May 21 19:50:59 2019 +0000 @@ -76,61 +76,61 @@ # include <sunlinsol/sunlinsol_klu.h> # endif +namespace octave +{ # if ! defined (HAVE_IDASETJACFN) && defined (HAVE_IDADLSSETJACFN) -static inline int -IDASetJacFn (void *ida_mem, IDADlsJacFn jac) -{ - return IDADlsSetJacFn (ida_mem, jac); -} + static inline int + IDASetJacFn (void *ida_mem, IDADlsJacFn jac) + { + return IDADlsSetJacFn (ida_mem, jac); + } # endif # if ! defined (HAVE_IDASETLINEARSOLVER) && defined (HAVE_IDADLSSETLINEARSOLVER) -static inline int -IDASetLinearSolver (void *ida_mem, SUNLinearSolver LS, SUNMatrix A) -{ - return IDADlsSetLinearSolver (ida_mem, LS, A); -} + static inline int + IDASetLinearSolver (void *ida_mem, SUNLinearSolver LS, SUNMatrix A) + { + return IDADlsSetLinearSolver (ida_mem, LS, A); + } # endif # if ! defined (HAVE_SUNLINSOL_DENSE) && defined (HAVE_SUNDENSELINEARSOLVER) -static inline SUNLinearSolver -SUNLinSol_Dense (N_Vector y, SUNMatrix A) -{ - return SUNDenseLinearSolver (y, A); -} + static inline SUNLinearSolver + SUNLinSol_Dense (N_Vector y, SUNMatrix A) + { + return SUNDenseLinearSolver (y, A); + } # endif # if defined (HAVE_SUNDIALS_SUNLINSOL_KLU) # if ! defined (HAVE_SUNLINSOL_KLU) && defined (HAVE_SUNKLU) -static inline SUNLinearSolver -SUNLinSol_KLU (N_Vector y, SUNMatrix A) -{ - return SUNKLU (y, A); -} + static inline SUNLinearSolver + SUNLinSol_KLU (N_Vector y, SUNMatrix A) + { + return SUNKLU (y, A); + } # endif # endif -static inline realtype * -nv_data_s (N_Vector& v) -{ + static inline realtype * + nv_data_s (N_Vector& v) + { #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC) - // Disable warning from GCC about old-style casts in Sundials - // macro expansions. Do this in a function so that this - // diagnostic may still be enabled for the rest of the file. + // Disable warning from GCC about old-style casts in Sundials + // macro expansions. Do this in a function so that this + // diagnostic may still be enabled for the rest of the file. # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wold-style-cast" #endif - return NV_DATA_S (v); + return NV_DATA_S (v); #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC) - // Restore prevailing warning state for remainder of the file. + // Restore prevailing warning state for remainder of the file. # pragma GCC diagnostic pop #endif -} + } -namespace octave -{ class IDA { public:
--- a/libinterp/octave-value/ov-typeinfo.cc Tue May 21 17:39:13 2019 +0000 +++ b/libinterp/octave-value/ov-typeinfo.cc Tue May 21 19:50:59 2019 +0000 @@ -36,33 +36,31 @@ #include "ov-typeinfo.h" #include "ov.h" -// FIXME: we should also store all class names and provide a -// way to list them (calling class with nargin == 0?). - -static NDArray -as_nd_array (const Array<int>& x) -{ - NDArray retval (x.dims ()); - - for (int i = 0; i < x.numel (); i++) - retval.xelem(i) = x(i); - - return retval; -} - -static boolNDArray -as_bool_nd_array (const Array<void *>& x) -{ - boolNDArray retval (x.dims ()); - - for (octave_idx_type i = 0; i < x.numel (); i++) - retval.xelem (i) = x(i); - - return retval; -} - namespace octave { + // FIXME: we should also store all class names and provide a + // way to list them (calling class with nargin == 0?). + + static NDArray as_nd_array (const Array<int>& x) + { + NDArray retval (x.dims ()); + + for (int i = 0; i < x.numel (); i++) + retval.xelem(i) = x(i); + + return retval; + } + + static boolNDArray as_bool_nd_array (const Array<void *>& x) + { + boolNDArray retval (x.dims ()); + + for (octave_idx_type i = 0; i < x.numel (); i++) + retval.xelem (i) = x(i); + + return retval; + } + type_info::type_info (int init_tab_sz) : num_types (0), types (dim_vector (init_tab_sz, 1), ""), vals (dim_vector (init_tab_sz, 1)),
--- a/liboctave/numeric/aepbalance.cc Tue May 21 17:39:13 2019 +0000 +++ b/liboctave/numeric/aepbalance.cc Tue May 21 19:50:59 2019 +0000 @@ -35,14 +35,14 @@ #include "lo-error.h" #include "lo-lapack-proto.h" -static inline char -get_job (bool noperm, bool noscal) -{ - return noperm ? (noscal ? 'N' : 'S') : (noscal ? 'P' : 'B'); -} - namespace octave { + static inline char + get_job (bool noperm, bool noscal) + { + return noperm ? (noscal ? 'N' : 'S') : (noscal ? 'P' : 'B'); + } + namespace math { template <>
--- a/liboctave/numeric/chol.cc Tue May 21 17:39:13 2019 +0000 +++ b/liboctave/numeric/chol.cc Tue May 21 19:50:59 2019 +0000 @@ -45,194 +45,194 @@ # include "qr.h" #endif -static Matrix -chol2inv_internal (const Matrix& r, bool is_upper = true) -{ - Matrix retval; - - octave_idx_type r_nr = r.rows (); - octave_idx_type r_nc = r.cols (); - - if (r_nr != r_nc) - (*current_liboctave_error_handler) ("chol2inv requires square matrix"); - - F77_INT n = octave::to_f77_int (r_nc); - F77_INT info; - - Matrix tmp = r; - double *v = tmp.fortran_vec (); - - if (is_upper) - F77_XFCN (dpotri, DPOTRI, (F77_CONST_CHAR_ARG2 ("U", 1), n, - v, n, info - F77_CHAR_ARG_LEN (1))); - else - F77_XFCN (dpotri, DPOTRI, (F77_CONST_CHAR_ARG2 ("L", 1), n, - v, n, info - F77_CHAR_ARG_LEN (1))); - - // FIXME: Should we check info exit value and possibly report an error? - - // If someone thinks of a more graceful way of doing this - // (or faster for that matter :-)), please let me know! - - if (n > 1) - { - if (is_upper) - for (octave_idx_type j = 0; j < r_nc; j++) - for (octave_idx_type i = j+1; i < r_nr; i++) - tmp.xelem (i, j) = tmp.xelem (j, i); - else - for (octave_idx_type j = 0; j < r_nc; j++) - for (octave_idx_type i = j+1; i < r_nr; i++) - tmp.xelem (j, i) = tmp.xelem (i, j); - } - - retval = tmp; - - return retval; -} - -static FloatMatrix -chol2inv_internal (const FloatMatrix& r, bool is_upper = true) -{ - FloatMatrix retval; - - octave_idx_type r_nr = r.rows (); - octave_idx_type r_nc = r.cols (); - - if (r_nr != r_nc) - (*current_liboctave_error_handler) ("chol2inv requires square matrix"); - - F77_INT n = octave::to_f77_int (r_nc); - F77_INT info; - - FloatMatrix tmp = r; - float *v = tmp.fortran_vec (); - - if (is_upper) - F77_XFCN (spotri, SPOTRI, (F77_CONST_CHAR_ARG2 ("U", 1), n, - v, n, info - F77_CHAR_ARG_LEN (1))); - else - F77_XFCN (spotri, SPOTRI, (F77_CONST_CHAR_ARG2 ("L", 1), n, - v, n, info - F77_CHAR_ARG_LEN (1))); - - // FIXME: Should we check info exit value and possibly report an error? - - // If someone thinks of a more graceful way of doing this (or - // faster for that matter :-)), please let me know! - - if (n > 1) - { - if (is_upper) - for (octave_idx_type j = 0; j < r_nc; j++) - for (octave_idx_type i = j+1; i < r_nr; i++) - tmp.xelem (i, j) = tmp.xelem (j, i); - else - for (octave_idx_type j = 0; j < r_nc; j++) - for (octave_idx_type i = j+1; i < r_nr; i++) - tmp.xelem (j, i) = tmp.xelem (i, j); - } - - retval = tmp; - - return retval; -} - -static ComplexMatrix -chol2inv_internal (const ComplexMatrix& r, bool is_upper = true) -{ - ComplexMatrix retval; - - octave_idx_type r_nr = r.rows (); - octave_idx_type r_nc = r.cols (); - - if (r_nr != r_nc) - (*current_liboctave_error_handler) ("chol2inv requires square matrix"); - - F77_INT n = octave::to_f77_int (r_nc); - F77_INT info; - - ComplexMatrix tmp = r; - - if (is_upper) - F77_XFCN (zpotri, ZPOTRI, (F77_CONST_CHAR_ARG2 ("U", 1), n, - F77_DBLE_CMPLX_ARG (tmp.fortran_vec ()), n, info - F77_CHAR_ARG_LEN (1))); - else - F77_XFCN (zpotri, ZPOTRI, (F77_CONST_CHAR_ARG2 ("L", 1), n, - F77_DBLE_CMPLX_ARG (tmp.fortran_vec ()), n, info - F77_CHAR_ARG_LEN (1))); - - // If someone thinks of a more graceful way of doing this (or - // faster for that matter :-)), please let me know! - - if (n > 1) - { - if (is_upper) - for (octave_idx_type j = 0; j < r_nc; j++) - for (octave_idx_type i = j+1; i < r_nr; i++) - tmp.xelem (i, j) = std::conj (tmp.xelem (j, i)); - else - for (octave_idx_type j = 0; j < r_nc; j++) - for (octave_idx_type i = j+1; i < r_nr; i++) - tmp.xelem (j, i) = std::conj (tmp.xelem (i, j)); - } - - retval = tmp; - - return retval; -} - -static FloatComplexMatrix -chol2inv_internal (const FloatComplexMatrix& r, bool is_upper = true) -{ - FloatComplexMatrix retval; - - octave_idx_type r_nr = r.rows (); - octave_idx_type r_nc = r.cols (); - - if (r_nr != r_nc) - (*current_liboctave_error_handler) ("chol2inv requires square matrix"); - - F77_INT n = octave::to_f77_int (r_nc); - F77_INT info; - - FloatComplexMatrix tmp = r; - - if (is_upper) - F77_XFCN (cpotri, CPOTRI, (F77_CONST_CHAR_ARG2 ("U", 1), n, - F77_CMPLX_ARG (tmp.fortran_vec ()), n, info - F77_CHAR_ARG_LEN (1))); - else - F77_XFCN (cpotri, CPOTRI, (F77_CONST_CHAR_ARG2 ("L", 1), n, - F77_CMPLX_ARG (tmp.fortran_vec ()), n, info - F77_CHAR_ARG_LEN (1))); - - // If someone thinks of a more graceful way of doing this (or - // faster for that matter :-)), please let me know! - - if (n > 1) - { - if (is_upper) - for (octave_idx_type j = 0; j < r_nc; j++) - for (octave_idx_type i = j+1; i < r_nr; i++) - tmp.xelem (i, j) = std::conj (tmp.xelem (j, i)); - else - for (octave_idx_type j = 0; j < r_nc; j++) - for (octave_idx_type i = j+1; i < r_nr; i++) - tmp.xelem (j, i) = std::conj (tmp.xelem (i, j)); - } - - retval = tmp; - - return retval; -} - namespace octave { + static Matrix + chol2inv_internal (const Matrix& r, bool is_upper = true) + { + Matrix retval; + + octave_idx_type r_nr = r.rows (); + octave_idx_type r_nc = r.cols (); + + if (r_nr != r_nc) + (*current_liboctave_error_handler) ("chol2inv requires square matrix"); + + F77_INT n = octave::to_f77_int (r_nc); + F77_INT info; + + Matrix tmp = r; + double *v = tmp.fortran_vec (); + + if (is_upper) + F77_XFCN (dpotri, DPOTRI, (F77_CONST_CHAR_ARG2 ("U", 1), n, + v, n, info + F77_CHAR_ARG_LEN (1))); + else + F77_XFCN (dpotri, DPOTRI, (F77_CONST_CHAR_ARG2 ("L", 1), n, + v, n, info + F77_CHAR_ARG_LEN (1))); + + // FIXME: Should we check info exit value and possibly report an error? + + // If someone thinks of a more graceful way of doing this + // (or faster for that matter :-)), please let me know! + + if (n > 1) + { + if (is_upper) + for (octave_idx_type j = 0; j < r_nc; j++) + for (octave_idx_type i = j+1; i < r_nr; i++) + tmp.xelem (i, j) = tmp.xelem (j, i); + else + for (octave_idx_type j = 0; j < r_nc; j++) + for (octave_idx_type i = j+1; i < r_nr; i++) + tmp.xelem (j, i) = tmp.xelem (i, j); + } + + retval = tmp; + + return retval; + } + + static FloatMatrix + chol2inv_internal (const FloatMatrix& r, bool is_upper = true) + { + FloatMatrix retval; + + octave_idx_type r_nr = r.rows (); + octave_idx_type r_nc = r.cols (); + + if (r_nr != r_nc) + (*current_liboctave_error_handler) ("chol2inv requires square matrix"); + + F77_INT n = octave::to_f77_int (r_nc); + F77_INT info; + + FloatMatrix tmp = r; + float *v = tmp.fortran_vec (); + + if (is_upper) + F77_XFCN (spotri, SPOTRI, (F77_CONST_CHAR_ARG2 ("U", 1), n, + v, n, info + F77_CHAR_ARG_LEN (1))); + else + F77_XFCN (spotri, SPOTRI, (F77_CONST_CHAR_ARG2 ("L", 1), n, + v, n, info + F77_CHAR_ARG_LEN (1))); + + // FIXME: Should we check info exit value and possibly report an error? + + // If someone thinks of a more graceful way of doing this (or + // faster for that matter :-)), please let me know! + + if (n > 1) + { + if (is_upper) + for (octave_idx_type j = 0; j < r_nc; j++) + for (octave_idx_type i = j+1; i < r_nr; i++) + tmp.xelem (i, j) = tmp.xelem (j, i); + else + for (octave_idx_type j = 0; j < r_nc; j++) + for (octave_idx_type i = j+1; i < r_nr; i++) + tmp.xelem (j, i) = tmp.xelem (i, j); + } + + retval = tmp; + + return retval; + } + + static ComplexMatrix + chol2inv_internal (const ComplexMatrix& r, bool is_upper = true) + { + ComplexMatrix retval; + + octave_idx_type r_nr = r.rows (); + octave_idx_type r_nc = r.cols (); + + if (r_nr != r_nc) + (*current_liboctave_error_handler) ("chol2inv requires square matrix"); + + F77_INT n = octave::to_f77_int (r_nc); + F77_INT info; + + ComplexMatrix tmp = r; + + if (is_upper) + F77_XFCN (zpotri, ZPOTRI, (F77_CONST_CHAR_ARG2 ("U", 1), n, + F77_DBLE_CMPLX_ARG (tmp.fortran_vec ()), n, info + F77_CHAR_ARG_LEN (1))); + else + F77_XFCN (zpotri, ZPOTRI, (F77_CONST_CHAR_ARG2 ("L", 1), n, + F77_DBLE_CMPLX_ARG (tmp.fortran_vec ()), n, info + F77_CHAR_ARG_LEN (1))); + + // If someone thinks of a more graceful way of doing this (or + // faster for that matter :-)), please let me know! + + if (n > 1) + { + if (is_upper) + for (octave_idx_type j = 0; j < r_nc; j++) + for (octave_idx_type i = j+1; i < r_nr; i++) + tmp.xelem (i, j) = std::conj (tmp.xelem (j, i)); + else + for (octave_idx_type j = 0; j < r_nc; j++) + for (octave_idx_type i = j+1; i < r_nr; i++) + tmp.xelem (j, i) = std::conj (tmp.xelem (i, j)); + } + + retval = tmp; + + return retval; + } + + static FloatComplexMatrix + chol2inv_internal (const FloatComplexMatrix& r, bool is_upper = true) + { + FloatComplexMatrix retval; + + octave_idx_type r_nr = r.rows (); + octave_idx_type r_nc = r.cols (); + + if (r_nr != r_nc) + (*current_liboctave_error_handler) ("chol2inv requires square matrix"); + + F77_INT n = octave::to_f77_int (r_nc); + F77_INT info; + + FloatComplexMatrix tmp = r; + + if (is_upper) + F77_XFCN (cpotri, CPOTRI, (F77_CONST_CHAR_ARG2 ("U", 1), n, + F77_CMPLX_ARG (tmp.fortran_vec ()), n, info + F77_CHAR_ARG_LEN (1))); + else + F77_XFCN (cpotri, CPOTRI, (F77_CONST_CHAR_ARG2 ("L", 1), n, + F77_CMPLX_ARG (tmp.fortran_vec ()), n, info + F77_CHAR_ARG_LEN (1))); + + // If someone thinks of a more graceful way of doing this (or + // faster for that matter :-)), please let me know! + + if (n > 1) + { + if (is_upper) + for (octave_idx_type j = 0; j < r_nc; j++) + for (octave_idx_type i = j+1; i < r_nr; i++) + tmp.xelem (i, j) = std::conj (tmp.xelem (j, i)); + else + for (octave_idx_type j = 0; j < r_nc; j++) + for (octave_idx_type i = j+1; i < r_nr; i++) + tmp.xelem (j, i) = std::conj (tmp.xelem (i, j)); + } + + retval = tmp; + + return retval; + } + namespace math { template <typename T>
--- a/liboctave/numeric/gsvd.cc Tue May 21 17:39:13 2019 +0000 +++ b/liboctave/numeric/gsvd.cc Tue May 21 19:50:59 2019 +0000 @@ -39,52 +39,54 @@ #include "lo-lapack-proto.h" #include "oct-shlib.h" -static std::map<std::string, void *> gsvd_fcn; +namespace octave +{ + static std::map<std::string, void *> gsvd_fcn; -static bool have_DGGSVD3 = false; -static bool gsvd_initialized = false; + static bool have_DGGSVD3 = false; + static bool gsvd_initialized = false; -/* Hack to stringize macro results. */ + /* Hack to stringize macro results. */ #define xSTRINGIZE(x) #x #define STRINGIZE(x) xSTRINGIZE(x) -void initialize_gsvd (void) -{ - if (gsvd_initialized) - return; + static void initialize_gsvd (void) + { + if (gsvd_initialized) + return; - octave::dynamic_library libs (""); - if (! libs) - { - // FIXME: Should we throw an error if we cannot check the libraries? - have_DGGSVD3 = false; - return; - } + octave::dynamic_library libs (""); + if (! libs) + { + // FIXME: Should we throw an error if we cannot check the libraries? + have_DGGSVD3 = false; + return; + } - have_DGGSVD3 = (libs.search (STRINGIZE (F77_FUNC (dggsvd3, DGGSVD3))) - != nullptr); + have_DGGSVD3 = (libs.search (STRINGIZE (F77_FUNC (dggsvd3, DGGSVD3))) + != nullptr); - if (have_DGGSVD3) - { - gsvd_fcn["dg"] = libs.search (STRINGIZE (F77_FUNC (dggsvd3, DGGSVD3))); - gsvd_fcn["sg"] = libs.search (STRINGIZE (F77_FUNC (sggsvd3, SGGSVD3))); - gsvd_fcn["zg"] = libs.search (STRINGIZE (F77_FUNC (zggsvd3, ZGGSVD3))); - gsvd_fcn["cg"] = libs.search (STRINGIZE (F77_FUNC (cggsvd3, CGGSVD3))); - } - else - { - gsvd_fcn["dg"] = libs.search (STRINGIZE (F77_FUNC (dggsvd, DGGSVD))); - gsvd_fcn["sg"] = libs.search (STRINGIZE (F77_FUNC (sggsvd, SGGSVD))); - gsvd_fcn["zg"] = libs.search (STRINGIZE (F77_FUNC (zggsvd, ZGGSVD))); - gsvd_fcn["cg"] = libs.search (STRINGIZE (F77_FUNC (cggsvd, CGGSVD))); - } - gsvd_initialized = true; -} + if (have_DGGSVD3) + { + gsvd_fcn["dg"] = libs.search (STRINGIZE (F77_FUNC (dggsvd3, DGGSVD3))); + gsvd_fcn["sg"] = libs.search (STRINGIZE (F77_FUNC (sggsvd3, SGGSVD3))); + gsvd_fcn["zg"] = libs.search (STRINGIZE (F77_FUNC (zggsvd3, ZGGSVD3))); + gsvd_fcn["cg"] = libs.search (STRINGIZE (F77_FUNC (cggsvd3, CGGSVD3))); + } + else + { + gsvd_fcn["dg"] = libs.search (STRINGIZE (F77_FUNC (dggsvd, DGGSVD))); + gsvd_fcn["sg"] = libs.search (STRINGIZE (F77_FUNC (sggsvd, SGGSVD))); + gsvd_fcn["zg"] = libs.search (STRINGIZE (F77_FUNC (zggsvd, ZGGSVD))); + gsvd_fcn["cg"] = libs.search (STRINGIZE (F77_FUNC (cggsvd, CGGSVD))); + } + gsvd_initialized = true; + } -template<class T1> -struct real_ggsvd_ptr -{ - typedef F77_RET_T (*type) + template<class T1> + struct real_ggsvd_ptr + { + typedef F77_RET_T (*type) (F77_CONST_CHAR_ARG_DECL, // JOBU F77_CONST_CHAR_ARG_DECL, // JOBV F77_CONST_CHAR_ARG_DECL, // JOBQ @@ -111,12 +113,12 @@ F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL); -}; + }; -template<class T1> -struct real_ggsvd3_ptr -{ - typedef F77_RET_T (*type) + template<class T1> + struct real_ggsvd3_ptr + { + typedef F77_RET_T (*type) (F77_CONST_CHAR_ARG_DECL, // JOBU F77_CONST_CHAR_ARG_DECL, // JOBV F77_CONST_CHAR_ARG_DECL, // JOBQ @@ -144,12 +146,12 @@ F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL); -}; + }; -template<class T1, class T2> -struct comp_ggsvd_ptr -{ - typedef F77_RET_T (*type) + template<class T1, class T2> + struct comp_ggsvd_ptr + { + typedef F77_RET_T (*type) (F77_CONST_CHAR_ARG_DECL, // JOBU F77_CONST_CHAR_ARG_DECL, // JOBV F77_CONST_CHAR_ARG_DECL, // JOBQ @@ -177,12 +179,12 @@ F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL); -}; + }; -template<class T1, class T2> -struct comp_ggsvd3_ptr -{ - typedef F77_RET_T (*type) + template<class T1, class T2> + struct comp_ggsvd3_ptr + { + typedef F77_RET_T (*type) (F77_CONST_CHAR_ARG_DECL, // JOBU F77_CONST_CHAR_ARG_DECL, // JOBV F77_CONST_CHAR_ARG_DECL, // JOBQ @@ -211,20 +213,18 @@ F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL); -}; + }; -// template specializations -typedef real_ggsvd3_ptr<F77_DBLE>::type dggsvd3_type; -typedef real_ggsvd_ptr<F77_DBLE>::type dggsvd_type; -typedef real_ggsvd3_ptr<F77_REAL>::type sggsvd3_type; -typedef real_ggsvd_ptr<F77_REAL>::type sggsvd_type; -typedef comp_ggsvd3_ptr<F77_DBLE_CMPLX, F77_DBLE>::type zggsvd3_type; -typedef comp_ggsvd_ptr<F77_DBLE_CMPLX, F77_DBLE>::type zggsvd_type; -typedef comp_ggsvd3_ptr<F77_CMPLX, F77_REAL>::type cggsvd3_type; -typedef comp_ggsvd_ptr<F77_CMPLX, F77_REAL>::type cggsvd_type; + // template specializations + typedef real_ggsvd3_ptr<F77_DBLE>::type dggsvd3_type; + typedef real_ggsvd_ptr<F77_DBLE>::type dggsvd_type; + typedef real_ggsvd3_ptr<F77_REAL>::type sggsvd3_type; + typedef real_ggsvd_ptr<F77_REAL>::type sggsvd_type; + typedef comp_ggsvd3_ptr<F77_DBLE_CMPLX, F77_DBLE>::type zggsvd3_type; + typedef comp_ggsvd_ptr<F77_DBLE_CMPLX, F77_DBLE>::type zggsvd_type; + typedef comp_ggsvd3_ptr<F77_CMPLX, F77_REAL>::type cggsvd3_type; + typedef comp_ggsvd_ptr<F77_CMPLX, F77_REAL>::type cggsvd_type; -namespace octave -{ namespace math { template <>
--- a/liboctave/system/file-ops.cc Tue May 21 17:39:13 2019 +0000 +++ b/liboctave/system/file-ops.cc Tue May 21 19:50:59 2019 +0000 @@ -50,164 +50,164 @@ #include "str-vec.h" #include "unistd-wrappers.h" -// The following tilde-expansion code was stolen and adapted from -// readline. - -// The default value of tilde_additional_prefixes. This is set to -// whitespace preceding a tilde so that simple programs which do not -// perform any word separation get desired behavior. -static const char *default_prefixes[] = { " ~", "\t~", ":~", nullptr }; - -// The default value of tilde_additional_suffixes. This is set to -// whitespace or newline so that simple programs which do not perform -// any word separation get desired behavior. -static const char *default_suffixes[] = { " ", "\n", ":", nullptr }; - -static size_t -tilde_find_prefix (const std::string& s, size_t& len) -{ - len = 0; - - size_t s_len = s.length (); - - if (s_len == 0 || s[0] == '~') - return 0; - - string_vector prefixes = octave::sys::file_ops::tilde_additional_prefixes; - - if (! prefixes.empty ()) - { - for (size_t i = 0; i < s_len; i++) - { - for (int j = 0; j < prefixes.numel (); j++) - { - size_t pfx_len = prefixes[j].length (); - - if (prefixes[j] == s.substr (i, pfx_len)) - { - len = pfx_len - 1; - return i + len; - } - } - } - } - - return s_len; -} - -// Find the end of a tilde expansion in S, and return the index -// of the character which ends the tilde definition. - -static size_t -tilde_find_suffix (const std::string& s) -{ - size_t s_len = s.length (); - - string_vector suffixes = octave::sys::file_ops::tilde_additional_suffixes; - - size_t i = 0; - - for ( ; i < s_len; i++) - { - if (octave::sys::file_ops::is_dir_sep (s[i])) - break; - - if (! suffixes.empty ()) - { - for (int j = 0; j < suffixes.numel (); j++) - { - size_t sfx_len = suffixes[j].length (); - - if (suffixes[j] == s.substr (i, sfx_len)) - return i; - } - } - } - - return i; -} - -// Take FNAME and return the tilde prefix we want expanded. - -static std::string -isolate_tilde_prefix (const std::string& fname) -{ - size_t f_len = fname.length (); - - size_t len = 1; - - while (len < f_len && ! octave::sys::file_ops::is_dir_sep (fname[len])) - len++; - - return fname.substr (1, len); -} - -// Do the work of tilde expansion on FILENAME. FILENAME starts with a -// tilde. - -static std::string -tilde_expand_word (const std::string& filename) -{ - size_t f_len = filename.length (); - - if (f_len == 0 || filename[0] != '~') - return std::string (filename); - - // A leading '~/' or a bare '~' is *always* translated to the value - // of $HOME or the home directory of the current user, regardless of - // any preexpansion hook. - - if (f_len == 1 || octave::sys::file_ops::is_dir_sep (filename[1])) - return octave::sys::env::get_home_directory () + filename.substr (1); - - std::string username = isolate_tilde_prefix (filename); - - size_t user_len = username.length (); - - std::string dirname; - - if (octave::sys::file_ops::tilde_expansion_preexpansion_hook) - { - std::string expansion - = octave::sys::file_ops::tilde_expansion_preexpansion_hook (username); - - if (! expansion.empty ()) - return expansion + filename.substr (user_len+1); - } - - // No preexpansion hook, or the preexpansion hook failed. Look in the - // password database. - - octave::sys::password pw = octave::sys::password::getpwnam (username); - - if (! pw) - { - // If the calling program has a special syntax for expanding tildes, - // and we couldn't find a standard expansion, then let them try. - - if (octave::sys::file_ops::tilde_expansion_failure_hook) - { - std::string expansion - = octave::sys::file_ops::tilde_expansion_failure_hook (username); - - if (! expansion.empty ()) - dirname = expansion + filename.substr (user_len+1); - } - - // If we don't have a failure hook, or if the failure hook did not - // expand the tilde, return a copy of what we were passed. - - if (dirname.empty ()) - dirname = filename; - } - else - dirname = pw.dir () + filename.substr (user_len+1); - - return dirname; -} - namespace octave { + // The following tilde-expansion code was stolen and adapted from + // readline. + + // The default value of tilde_additional_prefixes. This is set to + // whitespace preceding a tilde so that simple programs which do not + // perform any word separation get desired behavior. + static const char *default_prefixes[] = { " ~", "\t~", ":~", nullptr }; + + // The default value of tilde_additional_suffixes. This is set to + // whitespace or newline so that simple programs which do not perform + // any word separation get desired behavior. + static const char *default_suffixes[] = { " ", "\n", ":", nullptr }; + + static size_t + tilde_find_prefix (const std::string& s, size_t& len) + { + len = 0; + + size_t s_len = s.length (); + + if (s_len == 0 || s[0] == '~') + return 0; + + string_vector prefixes = octave::sys::file_ops::tilde_additional_prefixes; + + if (! prefixes.empty ()) + { + for (size_t i = 0; i < s_len; i++) + { + for (int j = 0; j < prefixes.numel (); j++) + { + size_t pfx_len = prefixes[j].length (); + + if (prefixes[j] == s.substr (i, pfx_len)) + { + len = pfx_len - 1; + return i + len; + } + } + } + } + + return s_len; + } + + // Find the end of a tilde expansion in S, and return the index + // of the character which ends the tilde definition. + + static size_t + tilde_find_suffix (const std::string& s) + { + size_t s_len = s.length (); + + string_vector suffixes = octave::sys::file_ops::tilde_additional_suffixes; + + size_t i = 0; + + for ( ; i < s_len; i++) + { + if (octave::sys::file_ops::is_dir_sep (s[i])) + break; + + if (! suffixes.empty ()) + { + for (int j = 0; j < suffixes.numel (); j++) + { + size_t sfx_len = suffixes[j].length (); + + if (suffixes[j] == s.substr (i, sfx_len)) + return i; + } + } + } + + return i; + } + + // Take FNAME and return the tilde prefix we want expanded. + + static std::string + isolate_tilde_prefix (const std::string& fname) + { + size_t f_len = fname.length (); + + size_t len = 1; + + while (len < f_len && ! octave::sys::file_ops::is_dir_sep (fname[len])) + len++; + + return fname.substr (1, len); + } + + // Do the work of tilde expansion on FILENAME. FILENAME starts with a + // tilde. + + static std::string + tilde_expand_word (const std::string& filename) + { + size_t f_len = filename.length (); + + if (f_len == 0 || filename[0] != '~') + return std::string (filename); + + // A leading '~/' or a bare '~' is *always* translated to the value + // of $HOME or the home directory of the current user, regardless of + // any preexpansion hook. + + if (f_len == 1 || octave::sys::file_ops::is_dir_sep (filename[1])) + return octave::sys::env::get_home_directory () + filename.substr (1); + + std::string username = isolate_tilde_prefix (filename); + + size_t user_len = username.length (); + + std::string dirname; + + if (octave::sys::file_ops::tilde_expansion_preexpansion_hook) + { + std::string expansion + = octave::sys::file_ops::tilde_expansion_preexpansion_hook (username); + + if (! expansion.empty ()) + return expansion + filename.substr (user_len+1); + } + + // No preexpansion hook, or the preexpansion hook failed. Look in the + // password database. + + octave::sys::password pw = octave::sys::password::getpwnam (username); + + if (! pw) + { + // If the calling program has a special syntax for expanding tildes, + // and we couldn't find a standard expansion, then let them try. + + if (octave::sys::file_ops::tilde_expansion_failure_hook) + { + std::string expansion + = octave::sys::file_ops::tilde_expansion_failure_hook (username); + + if (! expansion.empty ()) + dirname = expansion + filename.substr (user_len+1); + } + + // If we don't have a failure hook, or if the failure hook did not + // expand the tilde, return a copy of what we were passed. + + if (dirname.empty ()) + dirname = filename; + } + else + dirname = pw.dir () + filename.substr (user_len+1); + + return dirname; + } + namespace sys { namespace file_ops
--- a/liboctave/util/lo-array-errwarn.cc Tue May 21 17:39:13 2019 +0000 +++ b/liboctave/util/lo-array-errwarn.cc Tue May 21 19:50:59 2019 +0000 @@ -32,20 +32,23 @@ #include "lo-array-errwarn.h" #include "lo-error.h" -// Text constants used to shorten code below. -static const char *error_id_nonconformant_args = "Octave:nonconformant-args"; - -static const char *error_id_index_out_of_bounds = "Octave:index-out-of-bounds"; - -static const char *error_id_invalid_index = "Octave:invalid-index"; - -static const char *warning_id_nearly_singular_matrix = - "Octave:nearly-singular-matrix"; - -static const char *warning_id_singular_matrix = "Octave:singular-matrix"; - namespace octave { + // Text constants used to shorten code below. + + static const char *error_id_nonconformant_args + = "Octave:nonconformant-args"; + + static const char *error_id_index_out_of_bounds + = "Octave:index-out-of-bounds"; + + static const char *error_id_invalid_index = "Octave:invalid-index"; + + static const char *warning_id_nearly_singular_matrix + = "Octave:nearly-singular-matrix"; + + static const char *warning_id_singular_matrix = "Octave:singular-matrix"; + void err_nan_to_logical_conversion (void) {
--- a/liboctave/util/lo-regexp.cc Tue May 21 17:39:13 2019 +0000 +++ b/liboctave/util/lo-regexp.cc Tue May 21 19:50:59 2019 +0000 @@ -45,20 +45,20 @@ #include "lo-regexp.h" #include "str-vec.h" -// Define the maximum number of retries for a pattern -// that possibly results in an infinite recursion. +namespace octave +{ + // Define the maximum number of retries for a pattern + // that possibly results in an infinite recursion. #define PCRE_MATCHLIMIT_MAX 10 -// FIXME: should this be configurable? + // FIXME: should this be configurable? #define MAXLOOKBEHIND 10 -static bool lookbehind_warned = false; + static bool lookbehind_warned = false; -// FIXME: don't bother collecting and composing return values -// the user doesn't want. + // FIXME: don't bother collecting and composing return values + // the user doesn't want. -namespace octave -{ void regexp::free (void) {
--- a/liboctave/util/oct-glob.cc Tue May 21 17:39:13 2019 +0000 +++ b/liboctave/util/oct-glob.cc Tue May 21 19:50:59 2019 +0000 @@ -39,16 +39,16 @@ // transforms the glob_match::glob function to be glob_match::rpl_glob, // which is not what we want... -static bool -single_match_exists (const std::string& file) -{ - octave::sys::file_stat s (file); - - return s.exists (); -} - namespace octave { + static bool + single_match_exists (const std::string& file) + { + octave::sys::file_stat s (file); + + return s.exists (); + } + namespace sys { bool
--- a/liboctave/util/oct-sparse.cc Tue May 21 17:39:13 2019 +0000 +++ b/liboctave/util/oct-sparse.cc Tue May 21 19:50:59 2019 +0000 @@ -31,19 +31,19 @@ || defined (HAVE_CHOLMOD) || defined (HAVE_COLAMD) \ || defined (HAVE_CXSPARSE) || defined (HAVE_UMFPACK)) -static inline void -check_suitesparse_integer_size (void) -{ - // FIXME: maybe it would be better to make this a configure check and - // disable suitesparse if it fails? - - if (sizeof (octave::suitesparse_integer) != sizeof (octave_idx_type)) - (*current_liboctave_error_handler) - ("size of suitesparse integer does not match octave_idx_type!"); -} - namespace octave { + static inline void + check_suitesparse_integer_size (void) + { + // FIXME: maybe it would be better to make this a configure check and + // disable suitesparse if it fails? + + if (sizeof (octave::suitesparse_integer) != sizeof (octave_idx_type)) + (*current_liboctave_error_handler) + ("size of suitesparse integer does not match octave_idx_type!"); + } + suitesparse_integer * to_suitesparse_intptr (octave_idx_type *i) {