4634
|
1 /* |
|
2 |
|
3 Copyright (C) 2003 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
4634
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_ls_oct_ascii_h) |
|
25 #define octave_ls_oct_ascii_h 1 |
|
26 |
4687
|
27 #include <cfloat> |
|
28 |
5765
|
29 #include <sstream> |
5099
|
30 #include <string> |
|
31 |
|
32 #include "str-vec.h" |
|
33 |
4687
|
34 // Flag for cell elements |
|
35 #define CELL_ELT_TAG "<cell-element>" |
|
36 |
|
37 // Used when converting Inf to something that gnuplot can read. |
|
38 |
|
39 #ifndef OCT_RBV |
|
40 #define OCT_RBV DBL_MAX / 100.0 |
|
41 #endif |
|
42 |
6109
|
43 extern OCTINTERP_API std::string |
4687
|
44 extract_keyword (std::istream& is, const char *keyword, |
|
45 const bool next_only = false); |
|
46 |
6109
|
47 extern OCTINTERP_API std::string |
4634
|
48 read_ascii_data (std::istream& is, const std::string& filename, bool& global, |
5754
|
49 octave_value& tc, octave_idx_type count); |
4634
|
50 |
6109
|
51 extern OCTINTERP_API bool |
4634
|
52 save_ascii_data (std::ostream& os, const octave_value& val_arg, |
|
53 const std::string& name, bool& infnan_warned, |
5958
|
54 bool mark_as_global, int precision); |
4634
|
55 |
6109
|
56 extern OCTINTERP_API bool |
4634
|
57 save_ascii_data_for_plotting (std::ostream& os, const octave_value& t, |
|
58 const std::string& name); |
|
59 |
6109
|
60 extern OCTINTERP_API bool |
5958
|
61 save_three_d (std::ostream& os, const octave_value& t, |
|
62 bool parametric = false); |
|
63 |
5275
|
64 // Match KEYWORD on stream IS, placing the associated value in VALUE, |
|
65 // returning TRUE if successful and FALSE otherwise. |
|
66 // |
|
67 // Input should look something like: |
|
68 // |
|
69 // [%#][ \t]*keyword[ \t]*int-value.*\n |
|
70 |
|
71 template <class T> |
|
72 bool |
|
73 extract_keyword (std::istream& is, const char *keyword, T& value, |
|
74 const bool next_only = false) |
|
75 { |
|
76 bool status = false; |
|
77 value = 0; |
|
78 |
|
79 char c; |
|
80 while (is.get (c)) |
|
81 { |
|
82 if (c == '%' || c == '#') |
|
83 { |
5765
|
84 std::ostringstream buf; |
5275
|
85 |
|
86 while (is.get (c) && (c == ' ' || c == '\t' || c == '%' || c == '#')) |
|
87 ; // Skip whitespace and comment characters. |
|
88 |
|
89 if (isalpha (c)) |
|
90 buf << c; |
|
91 |
|
92 while (is.get (c) && isalpha (c)) |
|
93 buf << c; |
|
94 |
5765
|
95 std::string tmp = buf.str (); |
5679
|
96 bool match = (tmp.compare (0, strlen (keyword), keyword) == 0); |
5275
|
97 |
|
98 if (match) |
|
99 { |
|
100 while (is.get (c) && (c == ' ' || c == '\t' || c == ':')) |
|
101 ; // Skip whitespace and the colon. |
|
102 |
|
103 is.putback (c); |
|
104 if (c != '\n') |
|
105 is >> value; |
|
106 if (is) |
|
107 status = true; |
|
108 while (is.get (c) && c != '\n') |
|
109 ; // Skip to beginning of next line; |
|
110 break; |
|
111 } |
|
112 else if (next_only) |
|
113 break; |
|
114 } |
|
115 } |
|
116 return status; |
|
117 } |
|
118 |
|
119 // Match one of the elements in KEYWORDS on stream IS, placing the |
|
120 // matched keyword in KW and the associated value in VALUE, |
|
121 // returning TRUE if successful and FALSE otherwise. |
|
122 // |
|
123 // Input should look something like: |
|
124 // |
|
125 // [%#][ \t]*keyword[ \t]*int-value.*\n |
|
126 |
|
127 template <class T> |
|
128 bool |
|
129 extract_keyword (std::istream& is, const string_vector& keywords, |
|
130 std::string& kw, T& value, const bool next_only = false) |
|
131 { |
|
132 bool status = false; |
|
133 kw = ""; |
|
134 value = 0; |
|
135 |
|
136 char c; |
|
137 while (is.get (c)) |
|
138 { |
|
139 if (c == '%' || c == '#') |
|
140 { |
5765
|
141 std::ostringstream buf; |
5275
|
142 |
|
143 while (is.get (c) && (c == ' ' || c == '\t' || c == '%' || c == '#')) |
|
144 ; // Skip whitespace and comment characters. |
|
145 |
|
146 if (isalpha (c)) |
|
147 buf << c; |
|
148 |
|
149 while (is.get (c) && isalpha (c)) |
|
150 buf << c; |
|
151 |
5765
|
152 std::string tmp = buf.str (); |
5275
|
153 |
|
154 for (int i = 0; i < keywords.length (); i++) |
|
155 { |
|
156 int match = (tmp == keywords[i]); |
|
157 |
|
158 if (match) |
|
159 { |
|
160 kw = keywords[i]; |
|
161 |
|
162 while (is.get (c) && (c == ' ' || c == '\t' || c == ':')) |
|
163 ; // Skip whitespace and the colon. |
|
164 |
|
165 is.putback (c); |
|
166 if (c != '\n') |
|
167 is >> value; |
|
168 if (is) |
|
169 status = true; |
|
170 while (is.get (c) && c != '\n') |
|
171 ; // Skip to beginning of next line; |
|
172 return status; |
|
173 } |
|
174 } |
|
175 |
|
176 if (next_only) |
|
177 break; |
|
178 } |
|
179 } |
|
180 return status; |
|
181 } |
|
182 |
4634
|
183 #endif |
|
184 |
|
185 /* |
|
186 ;;; Local Variables: *** |
|
187 ;;; mode: C++ *** |
|
188 ;;; End: *** |
|
189 */ |
|
190 |