changeset 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 9b1af8135ecd
files src/ls-oct-ascii.cc
diffstat 1 files changed, 65 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/ls-oct-ascii.cc
+++ b/src/ls-oct-ascii.cc
@@ -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.