Mercurial > octave
comparison src/ls-oct-ascii.cc @ 5100:5a92c3177fc6 before-gnuplot-split
[project @ 2004-12-27 17:20:38 by jwe]
author | jwe |
---|---|
date | Mon, 27 Dec 2004 17:20:38 +0000 |
parents | f7e39f977fe8 |
children | e2ed74b9bfa0 |
comparison
equal
deleted
inserted
replaced
5099:f7e39f977fe8 | 5100:5a92c3177fc6 |
---|---|
297 } | 297 } |
298 } | 298 } |
299 return status; | 299 return status; |
300 } | 300 } |
301 | 301 |
302 // Match one of the elements in KEYWORDS on stream IS, placing the | |
303 // matched keyword in KW and the associated value in VALUE, | |
304 // returning TRUE if successful and FALSE otherwise. | |
305 // | |
306 // Input should look something like: | |
307 // | |
308 // [%#][ \t]*keyword[ \t]*int-value.*\n | |
309 | |
310 bool | |
311 extract_keyword (std::istream& is, const string_vector& keywords, | |
312 std::string& kw, int& value, const bool next_only) | |
313 { | |
314 bool status = false; | |
315 kw = ""; | |
316 value = 0; | |
317 | |
318 char c; | |
319 while (is.get (c)) | |
320 { | |
321 if (c == '%' || c == '#') | |
322 { | |
323 OSSTREAM buf; | |
324 | |
325 while (is.get (c) && (c == ' ' || c == '\t' || c == '%' || c == '#')) | |
326 ; // Skip whitespace and comment characters. | |
327 | |
328 if (isalpha (c)) | |
329 buf << c; | |
330 | |
331 while (is.get (c) && isalpha (c)) | |
332 buf << c; | |
333 | |
334 buf << OSSTREAM_ENDS; | |
335 std::string tmp = OSSTREAM_STR (buf); | |
336 OSSTREAM_FREEZE (buf); | |
337 | |
338 for (int i = 0; i < keywords.length (); i++) | |
339 { | |
340 int match = (tmp == keywords[i]); | |
341 | |
342 if (match) | |
343 { | |
344 kw = keywords[i]; | |
345 | |
346 while (is.get (c) && (c == ' ' || c == '\t' || c == ':')) | |
347 ; // Skip whitespace and the colon. | |
348 | |
349 is.putback (c); | |
350 if (c != '\n') | |
351 is >> value; | |
352 if (is) | |
353 status = true; | |
354 while (is.get (c) && c != '\n') | |
355 ; // Skip to beginning of next line; | |
356 return status; | |
357 } | |
358 } | |
359 | |
360 if (next_only) | |
361 break; | |
362 } | |
363 } | |
364 return status; | |
365 } | |
366 | |
302 // Extract one value (scalar, matrix, string, etc.) from stream IS and | 367 // Extract one value (scalar, matrix, string, etc.) from stream IS and |
303 // place it in TC, returning the name of the variable. If the value | 368 // place it in TC, returning the name of the variable. If the value |
304 // is tagged as global in the file, return TRUE in GLOBAL. | 369 // is tagged as global in the file, return TRUE in GLOBAL. |
305 // | 370 // |
306 // Each type supplies its own function to load the data, and so this | 371 // Each type supplies its own function to load the data, and so this |