r2301 - alfs-POC/src

jhuntwork at linuxfromscratch.org jhuntwork at linuxfromscratch.org
Mon Mar 6 08:49:35 PST 2006


Author: jhuntwork
Date: 2006-03-06 09:49:35 -0700 (Mon, 06 Mar 2006)
New Revision: 2301

Modified:
   alfs-POC/src/Makefile
   alfs-POC/src/parser.cpp
Log:
Improved parsing of tag pairs

Modified: alfs-POC/src/Makefile
===================================================================
--- alfs-POC/src/Makefile	2006-03-03 20:58:07 UTC (rev 2300)
+++ alfs-POC/src/Makefile	2006-03-06 16:49:35 UTC (rev 2301)
@@ -2,7 +2,7 @@
 CXX = g++
 CFLAGS = -Wall -Werror -pedantic -O2 -pipe -std=gnu99 -D_GNU_SOURCE
 CXXFLAGS = -Wall -Werror -pedantic -pipe -D_GNU_SOURCE
-BINARIES = parser alfs alfsd cpp-parser
+BINARIES = parser alfs alfsd
 
 # List 'clean' as a dependency for now so that it will always clean
 # before it builds.
@@ -11,10 +11,7 @@
 alf%:
 	$(CC) $(CFLAGS) $@.c -o $@
 
-parser: parser.c
-	$(CC) $(CFLAGS) $@.c -o $@
-
-cpp-parser: parser.cpp
+parser: parser.cpp
 	$(CXX) $(CXXFLAGS) parser.cpp -o $@
 
 clean:

Modified: alfs-POC/src/parser.cpp
===================================================================
--- alfs-POC/src/parser.cpp	2006-03-03 20:58:07 UTC (rev 2300)
+++ alfs-POC/src/parser.cpp	2006-03-06 16:49:35 UTC (rev 2301)
@@ -25,7 +25,7 @@
 int parse_file(string filename){
 
   int loc, len, i, multi = 0;
-  string fn, parent, curline, path, buf;
+  string fn, parent, curline, path, buf, multibuf, parsebuf;
   const char *dir, *file;
   char wd[256];
   ifstream fp;
@@ -66,32 +66,45 @@
     if (curline.empty())
       continue;
 
-    for (buf = string(curline); buf.empty() != 1; i = 0) {
+    for (buf = string(curline); !buf.empty(); i = 0) {
 	if (multi != 1)
 	  i = buf.find_first_of("<");
 	else
 	  i = 0;
 
 	switch (i) {
+
 	  case -1 :
+	  // '<' not found in the string
 	    cout << buf << endl;
 	    buf.erase();
 	    break;
 
 	  case 0 :
+	  // '<' found as the first character of the string
+	    if (multi == 1) {
+		multibuf.append(buf);
+		buf = string(multibuf);
+	    }
 	    i = buf.find_first_of(">");
 	    if (i != -1) {
-	      cout << (string(buf, 0, i+1)) << endl;
+	      // Analyze tag
+	      parsebuf = string(buf, 0, i+1);
+	      parsebuf = string(parsebuf, parsebuf.find_first_not_of("<"), (parsebuf.find_last_not_of(">")-parsebuf.find_first_not_of("<"))+1);
+	      cout << "Parsed tag is: " << parsebuf << endl;
+	     // cout << (string(buf, 0, i+1)) << endl;
 	      buf = string(buf, i+1, buf.length()-i);
 	      multi = 0;
 	    } else {
-	      cout << buf << endl;
+	      // FIXME: append to previous line.
+	      multibuf = string(buf);
 	      multi = 1;
 	      buf.erase();
 	    }
 	    break;
 
 	  default :
+	  // '<' found, but not the first character in the string.
 	    cout << (string(buf, 0, i)) << endl;
 	    buf = string(buf, i, buf.length()-i);
 	    




More information about the alfs-log mailing list