# HG changeset patch # User jwe # Date 1104168038 0 # Node ID 5a92c3177fc6c038bc93745f6ebc6a055e602b96 # Parent f7e39f977fe864d5508977a0020921da5d9f98cd [project @ 2004-12-27 17:20:38 by jwe] diff -r f7e39f977fe8 -r 5a92c3177fc6 src/ls-oct-ascii.cc --- a/src/ls-oct-ascii.cc Fri Dec 24 19:06:01 2004 +0000 +++ b/src/ls-oct-ascii.cc Mon Dec 27 17:20:38 2004 +0000 @@ -299,6 +299,71 @@ return status; } +// Match one of the elements in KEYWORDS on stream IS, placing the +// matched keyword in KW and the associated value in VALUE, +// returning TRUE if successful and FALSE otherwise. +// +// Input should look something like: +// +// [%#][ \t]*keyword[ \t]*int-value.*\n + +bool +extract_keyword (std::istream& is, const string_vector& keywords, + std::string& kw, int& value, const bool next_only) +{ + bool status = false; + kw = ""; + value = 0; + + char c; + while (is.get (c)) + { + if (c == '%' || c == '#') + { + OSSTREAM buf; + + while (is.get (c) && (c == ' ' || c == '\t' || c == '%' || c == '#')) + ; // Skip whitespace and comment characters. + + if (isalpha (c)) + buf << c; + + while (is.get (c) && isalpha (c)) + buf << c; + + buf << OSSTREAM_ENDS; + std::string tmp = OSSTREAM_STR (buf); + OSSTREAM_FREEZE (buf); + + for (int i = 0; i < keywords.length (); i++) + { + int match = (tmp == keywords[i]); + + if (match) + { + kw = keywords[i]; + + while (is.get (c) && (c == ' ' || c == '\t' || c == ':')) + ; // Skip whitespace and the colon. + + is.putback (c); + if (c != '\n') + is >> value; + if (is) + status = true; + while (is.get (c) && c != '\n') + ; // Skip to beginning of next line; + return status; + } + } + + if (next_only) + break; + } + } + return status; +} + // Extract one value (scalar, matrix, string, etc.) from stream IS and // place it in TC, returning the name of the variable. If the value // is tagged as global in the file, return TRUE in GLOBAL.