Author: ruschein
Date: 2011-09-22 16:57:37 -0700 (Thu, 22 Sep 2011)
New Revision: 26942

Modified:
   csplugins/trunk/ucsd/ruschein/GSFS/progs/Makefile
   csplugins/trunk/ucsd/ruschein/GSFS/progs/ParseDirectory.cc
Log:
Work in progress.

Modified: csplugins/trunk/ucsd/ruschein/GSFS/progs/Makefile
===================================================================
--- csplugins/trunk/ucsd/ruschein/GSFS/progs/Makefile   2011-09-22 23:43:58 UTC 
(rev 26941)
+++ csplugins/trunk/ucsd/ruschein/GSFS/progs/Makefile   2011-09-22 23:57:37 UTC 
(rev 26942)
@@ -30,7 +30,7 @@
 ParseDirectory.o: ParseDirectory.cc
        $(CXX) $(CXXFLAGS) -I. -c $<
 
-ParseDirectory: ParseDirectory.o
+ParseDirectory: ParseDirectory.o JSONScanner.o
        $(CXX) -o $@ $^ $(LIBS)
 
 JSONScanner.o: JSONScanner.cc JSONScanner.h

Modified: csplugins/trunk/ucsd/ruschein/GSFS/progs/ParseDirectory.cc
===================================================================
--- csplugins/trunk/ucsd/ruschein/GSFS/progs/ParseDirectory.cc  2011-09-22 
23:43:58 UTC (rev 26941)
+++ csplugins/trunk/ucsd/ruschein/GSFS/progs/ParseDirectory.cc  2011-09-22 
23:57:37 UTC (rev 26942)
@@ -2,6 +2,7 @@
 #include <vector>
 #include <cstdlib>
 #include <FileUtil.h>
+#include "JSONScanner.h"
 
 
 void Usage() {
@@ -14,73 +15,78 @@
 };
 
 
-bool Expect(std::string::const_iterator &ch, const std::string::const_iterator 
&end, const char * const expected_string) {
-       const char *next_expected_char = expected_string;
-       while (*next_expected_char != '\0') {
-               if (ch == end)
+static bool SkipBraceBlock(JSONScanner * const scanner) {
+       JSONScanner::TokenType token = scanner->getToken();
+       if (token != JSONScanner::OPEN_BRACE)
+               return false;
+
+       unsigned open_brace_count(1);
+       while (open_brace_count != 0) {
+               token = scanner->getToken();
+               if (token == JSONScanner::END_OF_INPUT)
                        return false;
-               if (*ch != *next_expected_char)
-                       return false;
-               ++ch, ++next_expected_char;
+               else if (token == JSONScanner::OPEN_BRACE)
+                       ++open_brace_count;
+               else if (token == JSONScanner::CLOSE_BRACE)
+                       --open_brace_count;
        }
 
        return true;
 }
 
 
-bool ParseBoolean(std::string::const_iterator &ch, const 
std::string::const_iterator &end, bool * const value) {
-       if (*ch != 't' && *ch != 'f')
+static bool SkipBracketBlock(JSONScanner * const scanner) {
+       JSONScanner::TokenType token = scanner->getToken();
+       if (token != JSONScanner::OPEN_BRACKET)
                return false;
 
-       if (*ch == 't') {
-               if (!Expect(ch, end, "true"))
+       unsigned open_bracket_count(1);
+       while (open_bracket_count != 0) {
+               token = scanner->getToken();
+               if (token == JSONScanner::END_OF_INPUT)
                        return false;
-               *value = true;
-       } else {
-               if (!Expect(ch, end, "false"))
-                       return false;
-               *value = false;
+               else if (token == JSONScanner::OPEN_BRACKET)
+                       ++open_bracket_count;
+               else if (token == JSONScanner::CLOSE_BRACKET)
+                       --open_bracket_count;
        }
 
        return true;
 }
 
 
-// Assumes that "ch" points to the first character of the string.
-bool ParseString(std::string::const_iterator &ch, const 
std::string::const_iterator &end, std::string * const value) {
-       value->clear();
+bool ParseListing(const std::string &listing, std::vector<DirEntry> * const 
entries) {
+       entries->clear();
 
-       for (;;) {
-               if (ch == end)
-                       return false;
+       JSONScanner scanner(listing);
 
-               if (*ch == '"') {
-                       ++ch;
-                       return true;
-               }
-                       
-               if (*ch == '\\') { // escaped character (we're ignoring unicode 
values for now
-                       ++ch;
-                       if (*ch == 'u') {
-                               std::cerr << "*** unicode char support not 
implemented!\n";
-                               return false;
-                       }
-                       *value += *ch;
-                       ++ch;
-               } else {
-                       *value += *ch;
-                       ++ch;
-               }
-       }
-}
+       // top-level opening brace
+       if (scanner.getToken() != JSONScanner::OPEN_BRACE)
+               return false;
 
+       if (scanner.getToken() != JSONScanner::STRING_CONSTANT)
+               return false;
+       if (scanner.getLastString() != "directory")
+               return false;
 
-bool ParseListing(const std::string &listing, std::vector<DirEntry> * const 
entries) {
-       entries->clear();
+       if (!SkipBraceBlock(&scanner))
+               return false;
 
-       for (std::string::const_iterator ch = listing.begin(); ch != 
listing.end(); ++ch) {
-       }
+       if (scanner.getToken() != JSONScanner::STRING_CONSTANT)
+               return false;
+       if (scanner.getLastString() != "contents")
+               return false;
 
+       if (!SkipBracketBlock(&scanner))
+               return false;
+
+       if (scanner.getToken() != JSONScanner::COMMA)
+                return false;
+
+       // top-level closing brace
+       if (scanner.getToken() != JSONScanner::CLOSE_BRACE)
+               return false;
+
        return true;
 }
 
@@ -95,5 +101,6 @@
                std::exit(EXIT_FAILURE);
        }
 
-       std::cout << json_directory_listing << '\n';
+       std::vector<DirEntry> dir_entries;
+       std::cout << "ParseListing() returned " << 
ParseListing(json_directory_listing, &dir_entries) << '\n';
 }

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to