annotate libinterp/corefcn/ls-oct-text.h @ 33624:e0c037a01fde default tip

redirect stdout and stderr into experimental terminal widget * command-widget.cc (command_widget): open temp files for redirecting stdout and stderr, setup a file system watcher for signals on changes to these files; (~command_widget): close and remove the temp. files; (insert_interpreter_output): use the style as second argument (print_stream): add new contents of temp. files for stdout and stderr to the end of the terminal contents; (notice_settings): set the terminal preferences to the new lexer of the console; (console): create and set new lexer; (new_command_line): use prompt style for the prompt; (execute_command): use second command line argument for the style; (append_string): use style as second argument and style the added text accordingly; * command-widget.h (console) append_string with second argument for style, (command_widget): now with destructor, new method print_stream, insert_interpreter_output with second argument for style, new class variables for temp. file descriptors and file system watcher * console-lexer.cc/h: new lexer derived from QScintillas default lexer for styling the terminal output, styles used so far: Default, Error, and Prompt * gui-preferences-cs.h: new constants for error and prompt colors * libgui/src/module.mk: new files console_lexer.cc/h * qt-interpreter-events.cc (display_exception): interpreter_output_signal with second argument for the style, here Error style * qt-interpreter-events.h: interpreter_output_signal with second argument for the style * terminal-dock-widget.h: interpreter_output_signal with second argument for the style
author Torsten Lilge <ttl-octave@mailbox.org>
date Sat, 25 May 2024 14:36:01 +0200
parents 2e484f9f1f18
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
32632
2e484f9f1f18 maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
3 // Copyright (C) 2003-2024 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
25
20791
f7084eae3318 maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents: 20447
diff changeset
26 #if ! defined (octave_ls_oct_text_h)
20447
c6224b4e7774 maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents: 20232
diff changeset
27 #define octave_ls_oct_text_h 1
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
28
21244
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
29 #include "octave-config.h"
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
30
23455
73ff72d3d603 maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents: 23442
diff changeset
31 #include <limits>
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5754
diff changeset
32 #include <sstream>
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4687
diff changeset
33 #include <string>
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4687
diff changeset
34
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4687
diff changeset
35 #include "str-vec.h"
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4687
diff changeset
36
8946
e7e928088e90 fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 8920
diff changeset
37 #include "ls-ascii-helper.h"
e7e928088e90 fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 8920
diff changeset
38
23442
53f5f8231c37 allow most header files to be compiled separately
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
39 class octave_value;
53f5f8231c37 allow most header files to be compiled separately
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
40
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4634
diff changeset
41 // Flag for cell elements
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4634
diff changeset
42 #define CELL_ELT_TAG "<cell-element>"
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4634
diff changeset
43
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4634
diff changeset
44 // Used when converting Inf to something that gnuplot can read.
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4634
diff changeset
45
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
46 #if ! defined (OCT_RBV)
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21139
diff changeset
47 # define OCT_RBV (std::numeric_limits<double>::max () / 100.0)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4634
diff changeset
48 #endif
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4634
diff changeset
49
6109
c68896f193e3 [project @ 2006-10-27 02:16:18 by jwe]
jwe
parents: 5958
diff changeset
50 extern OCTINTERP_API std::string
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
51 extract_keyword (std::istream& is, const char *keyword,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
52 const bool next_only = false);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4634
diff changeset
53
6109
c68896f193e3 [project @ 2006-10-27 02:16:18 by jwe]
jwe
parents: 5958
diff changeset
54 extern OCTINTERP_API std::string
20447
c6224b4e7774 maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents: 20232
diff changeset
55 read_text_data (std::istream& is, const std::string& filename, bool& global,
28161
ef349f5c320b Load structures with arbitrary string fieldnames (bug #50831, bug #46645).
Olaf Till <i7tiol@t-online.de>
parents: 27923
diff changeset
56 octave_value& tc, octave_idx_type count,
ef349f5c320b Load structures with arbitrary string fieldnames (bug #50831, bug #46645).
Olaf Till <i7tiol@t-online.de>
parents: 27923
diff changeset
57 const bool do_name_validation = true);
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
58
6109
c68896f193e3 [project @ 2006-10-27 02:16:18 by jwe]
jwe
parents: 5958
diff changeset
59 extern OCTINTERP_API bool
20447
c6224b4e7774 maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents: 20232
diff changeset
60 save_text_data (std::ostream& os, const octave_value& val_arg,
23470
a41fdb801db6 use mark_global and mark_persistent consistently
John W. Eaton <jwe@octave.org>
parents: 23455
diff changeset
61 const std::string& name, bool mark_global, int precision);
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
62
6109
c68896f193e3 [project @ 2006-10-27 02:16:18 by jwe]
jwe
parents: 5958
diff changeset
63 extern OCTINTERP_API bool
20447
c6224b4e7774 maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents: 20232
diff changeset
64 save_text_data_for_plotting (std::ostream& os, const octave_value& t,
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
65 const std::string& name);
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
66
6109
c68896f193e3 [project @ 2006-10-27 02:16:18 by jwe]
jwe
parents: 5958
diff changeset
67 extern OCTINTERP_API bool
5958
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5956
diff changeset
68 save_three_d (std::ostream& os, const octave_value& t,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
69 bool parametric = false);
5958
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5956
diff changeset
70
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
71 // Match KEYWORD on stream IS, placing the associated value in VALUE,
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
72 // returning TRUE if successful and FALSE otherwise.
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
73 //
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
74 // Input should look something like:
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
75 //
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
76 // [%#][ \t]*keyword[ \t]*int-value.*\n
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
77
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21021
diff changeset
78 template <typename T>
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
79 bool
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
80 extract_keyword (std::istream& is, const char *keyword, T& value,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
81 const bool next_only = false)
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
82 {
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
83 bool status = false;
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
84 value = T ();
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
85
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
86 char c;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
87 while (is.get (c))
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
88 {
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
89 if (c == '%' || c == '#')
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
90 {
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
91 std::ostringstream buf;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
92
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
93 while (is.get (c) && (c == ' ' || c == '\t' || c == '%' || c == '#'))
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
94 ; // Skip whitespace and comment characters.
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
95
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
96 if (isalpha (c))
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
97 buf << c;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
98
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
99 while (is.get (c) && isalpha (c))
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
100 buf << c;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
101
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
102 std::string tmp = buf.str ();
21021
a5b99b09f8fd maint: Use comparison operators rather than compare() for strings.
Rik <rik@octave.org>
parents: 20791
diff changeset
103 bool match = (tmp.substr (0, strlen (keyword)) == keyword);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
104
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
105 if (match)
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
106 {
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
107 while (is.get (c) && (c == ' ' || c == '\t' || c == ':'))
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
108 ; // Skip whitespace and the colon.
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
109
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
110 is.putback (c);
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
111 if (c != '\n' && c != '\r')
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
112 is >> value;
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
113 if (is)
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
114 status = true;
30006
75dff8f2de2e move some load-save utilities to octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
115 octave::skip_until_newline (is, false);
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
116 break;
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
117 }
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
118 else if (next_only)
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
119 break;
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
120 }
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
121 }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
122 return status;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
123 }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
124
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21021
diff changeset
125 template <typename T>
9852
aabf7a8c2e57 implement sparse logical conversion
Jaroslav Hajek <highegg@gmail.com>
parents: 8946
diff changeset
126 bool
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
127 extract_keyword (std::istream& is, const std::string& kw, T& value,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
128 const bool next_only = false)
9852
aabf7a8c2e57 implement sparse logical conversion
Jaroslav Hajek <highegg@gmail.com>
parents: 8946
diff changeset
129 {
aabf7a8c2e57 implement sparse logical conversion
Jaroslav Hajek <highegg@gmail.com>
parents: 8946
diff changeset
130 return extract_keyword (is, kw.c_str (), value, next_only);
aabf7a8c2e57 implement sparse logical conversion
Jaroslav Hajek <highegg@gmail.com>
parents: 8946
diff changeset
131 }
aabf7a8c2e57 implement sparse logical conversion
Jaroslav Hajek <highegg@gmail.com>
parents: 8946
diff changeset
132
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
133 // Match one of the elements in KEYWORDS on stream IS, placing the
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
134 // matched keyword in KW and the associated value in VALUE,
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
135 // returning TRUE if successful and FALSE otherwise.
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
136 //
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
137 // Input should look something like:
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
138 //
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
139 // [%#][ \t]*keyword[ \t]*int-value.*\n
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
140
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21021
diff changeset
141 template <typename T>
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
142 bool
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
143 extract_keyword (std::istream& is, const string_vector& keywords,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
144 std::string& kw, T& value, const bool next_only = false)
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
145 {
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
146 bool status = false;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
147 kw = "";
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
148 value = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
149
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
150 char c;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
151 while (is.get (c))
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
152 {
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
153 if (c == '%' || c == '#')
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
154 {
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
155 std::ostringstream buf;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
156
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
157 while (is.get (c) && (c == ' ' || c == '\t' || c == '%' || c == '#'))
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
158 ; // Skip whitespace and comment characters.
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
159
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
160 if (isalpha (c))
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
161 buf << c;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
162
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
163 while (is.get (c) && isalpha (c))
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
164 buf << c;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
165
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
166 std::string tmp = buf.str ();
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
167
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
168 for (int i = 0; i < keywords.numel (); i++)
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
169 {
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
170 int match = (tmp == keywords[i]);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
171
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
172 if (match)
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
173 {
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
174 kw = keywords[i];
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
175
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
176 while (is.get (c) && (c == ' ' || c == '\t' || c == ':'))
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
177 ; // Skip whitespace and the colon.
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
178
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
179 is.putback (c);
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
180 if (c != '\n' && c != '\r')
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
181 is >> value;
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
182 if (is)
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
183 status = true;
30006
75dff8f2de2e move some load-save utilities to octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
184 octave::skip_until_newline (is, false);
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
185 return status;
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
186 }
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
187 }
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
188
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
189 if (next_only)
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
190 break;
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
191 }
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
192 }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
193 return status;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
194 }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5099
diff changeset
195
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
196 #endif