$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r64264 - in sandbox/tools/auto_index: . src
From: john_at_[hidden]
Date: 2010-07-22 12:11:25
Author: johnmaddock
Date: 2010-07-22 12:11:24 EDT (Thu, 22 Jul 2010)
New Revision: 64264
URL: http://svn.boost.org/trac/boost/changeset/64264
Log:
Fix up source to reduce the warnings emitted, have better error handling, and better tolerance to scripts with whitespace on the ends of lines.
Change intermediate files to have ".auto_index" extension.
Text files modified: 
   sandbox/tools/auto_index/auto-index.jam        |     3                                         
   sandbox/tools/auto_index/src/auto_index.cpp    |     5 +                                       
   sandbox/tools/auto_index/src/file_scanning.cpp |   179 +++++++++++++++++++++++++++------------ 
   3 files changed, 132 insertions(+), 55 deletions(-)
Modified: sandbox/tools/auto_index/auto-index.jam
==============================================================================
--- sandbox/tools/auto_index/auto-index.jam	(original)
+++ sandbox/tools/auto_index/auto-index.jam	2010-07-22 12:11:24 EDT (Thu, 22 Jul 2010)
@@ -192,7 +192,7 @@
 toolset.flags auto-index.auto-index AI-COMMAND      <auto-index-binary> ;
 toolset.flags auto-index.auto-index AI-DEPENDENCIES <auto-index-binary-dependencies> ;
 
-generators.register [ class.new auto-index-generator auto-index.auto-index : DOCBOOK : DOCBOOK(%.modified) ] ;
+generators.register [ class.new auto-index-generator auto-index.auto-index : DOCBOOK : DOCBOOK(%.auto_index) ] ;
 generators.override auto-index.auto-index : boostbook.boostbook-to-docbook ;
 
 rule auto-index ( target : source : properties * )
@@ -210,3 +210,4 @@
 }
 
 
+
Modified: sandbox/tools/auto_index/src/auto_index.cpp
==============================================================================
--- sandbox/tools/auto_index/src/auto_index.cpp	(original)
+++ sandbox/tools/auto_index/src/auto_index.cpp	2010-07-22 12:11:24 EDT (Thu, 22 Jul 2010)
@@ -8,6 +8,7 @@
 #include <set>
 #include <cstring>
 #include <boost/array.hpp>
+#include <boost/exception/all.hpp>
 #include "auto_index.hpp"
 
 std::string infile, outfile, prefix, last_primary, last_secondary;
@@ -586,6 +587,10 @@
    boost::tiny_xml::write(*xml, os);
 
    }
+   catch(boost::exception& e)
+   {
+      std::cerr << diagnostic_information(e);
+   }
    catch(const std::exception& e)
    {
       std::cerr << e.what() << std::endl;
Modified: sandbox/tools/auto_index/src/file_scanning.cpp
==============================================================================
--- sandbox/tools/auto_index/src/file_scanning.cpp	(original)
+++ sandbox/tools/auto_index/src/file_scanning.cpp	2010-07-22 12:11:24 EDT (Thu, 22 Jul 2010)
@@ -82,15 +82,29 @@
       boost::sregex_token_iterator i(text.begin(), text.end(), class_e, 5), j;
       while(i != j)
       {
-         index_info info;
-         info.term = i->str();
-         info.search_text = class_prefix_regex + i->str() + class_suffix_regex;
-         info.category = "class_name";
-         if(index_terms.count(info) == 0)
+         try
          {
-            if(verbose)
-               std::cout << "Indexing class " << info.term << std::endl;
-            index_terms.insert(info);
+            index_info info;
+            info.term = i->str();
+            info.search_text = class_prefix_regex + i->str() + class_suffix_regex;
+            info.category = "class_name";
+            if(index_terms.count(info) == 0)
+            {
+               if(verbose)
+                  std::cout << "Indexing class " << info.term << std::endl;
+               index_terms.insert(info);
+            }
+         }
+         catch(const boost::regex_error&)
+         {
+            std::cerr << "Unable to create regular expression from class name:\""
+               << i->str() << "\" In file " << file << std::endl;
+         }
+         catch(const std::exception&)
+         {
+            std::cerr << "Unable to create class entry:\""
+               << i->str() << "\" In file " << file << std::endl;
+            throw;
          }
          ++i;
       }
@@ -107,15 +121,29 @@
       boost::sregex_token_iterator i(text.begin(), text.end(), typedef_exp, 1), j;
       while(i != j)
       {
-         index_info info;
-         info.term = i->str();
-         info.search_text = typedef_prefix_regex + i->str() + typedef_suffix_regex;
-         info.category = "typedef_name";
-         if(index_terms.count(info) == 0)
+         try
          {
-            if(verbose)
-               std::cout << "Indexing typedef " << info.term << std::endl;
-            index_terms.insert(info);
+            index_info info;
+            info.term = i->str();
+            info.search_text = typedef_prefix_regex + i->str() + typedef_suffix_regex;
+            info.category = "typedef_name";
+            if(index_terms.count(info) == 0)
+            {
+               if(verbose)
+                  std::cout << "Indexing typedef " << info.term << std::endl;
+               index_terms.insert(info);
+            }
+         }
+         catch(const boost::regex_error&)
+         {
+            std::cerr << "Unable to create regular expression from typedef name:\""
+               << i->str() << "\" In file " << file << std::endl;
+         }
+         catch(const std::exception&)
+         {
+            std::cerr << "Unable to create typedef entry:\""
+               << i->str() << "\" In file " << file << std::endl;
+            throw;
          }
          ++i;
       }
@@ -133,15 +161,29 @@
       boost::sregex_token_iterator i(text.begin(), text.end(), e, 1), j;
       while(i != j)
       {
-         index_info info;
-         info.term = i->str();
-         info.search_text = "\\<" + i->str() + "\\>";
-         info.category = "macro_name";
-         if(index_terms.count(info) == 0)
+         try
          {
-            if(verbose)
-               std::cout << "Indexing macro " << info.term << std::endl;
-            index_terms.insert(info);
+            index_info info;
+            info.term = i->str();
+            info.search_text = "\\<" + i->str() + "\\>";
+            info.category = "macro_name";
+            if(index_terms.count(info) == 0)
+            {
+               if(verbose)
+                  std::cout << "Indexing macro " << info.term << std::endl;
+               index_terms.insert(info);
+            }
+         }
+         catch(const boost::regex_error&)
+         {
+            std::cerr << "Unable to create regular expression from macro name:\""
+               << i->str() << "\" In file " << file << std::endl;
+         }
+         catch(const std::exception&)
+         {
+            std::cerr << "Unable to create macro entry:\""
+               << i->str() << "\" In file " << file << std::endl;
+            throw;
          }
          ++i;
       }
@@ -158,15 +200,29 @@
       boost::sregex_token_iterator i(text.begin(), text.end(), e, 1), j;
       while(i != j)
       {
-         index_info info;
-         info.term = i->str();
-         info.search_text = function_prefix_regex + i->str() + function_suffix_regex;
-         info.category = "function_name";
-         if(index_terms.count(info) == 0)
+         try
          {
-            if(verbose)
-               std::cout << "Indexing function " << info.term << std::endl;
-            index_terms.insert(info);
+            index_info info;
+            info.term = i->str();
+            info.search_text = function_prefix_regex + i->str() + function_suffix_regex;
+            info.category = "function_name";
+            if(index_terms.count(info) == 0)
+            {
+               if(verbose)
+                  std::cout << "Indexing function " << info.term << std::endl;
+               index_terms.insert(info);
+            }
+         }
+         catch(const boost::regex_error&)
+         {
+            std::cerr << "Unable to create regular expression from function name:\""
+               << i->str() << "\" In file " << file << std::endl;
+         }
+         catch(const std::exception&)
+         {
+            std::cerr << "Unable to create function entry:\""
+               << i->str() << "\" In file " << file << std::endl;
+            throw;
          }
          ++i;
       }
@@ -217,7 +273,7 @@
       );
    static const boost::regex scan_parser(
       "!scan[[:space:]]+"
-      "([^\"[:space:]]+|\"(?:[^\"\\\\]|\\\\.)+\")"
+      "([^\"[:space:]]+|\"(?:[^\"\\\\]|\\\\.)+\")\\s*"
       );
    static const boost::regex scan_dir_parser(
       "!scan-path[[:space:]]+"
@@ -227,7 +283,7 @@
       "(?:"
          "[[:space:]]+"
          "([^\"[:space:]]+|\"(?:[^\"\\\\]|\\\\.)+\")"
-      ")?"
+      ")?\\s*"
       );
    static const boost::regex entry_parser( 
       "([^\"[:space:]]+|\"(?:[^\"\\\\]|\\\\.)+\")"
@@ -247,12 +303,12 @@
    static const boost::regex rewrite_parser(
       "!(rewrite-name|rewrite-id)\\s+"
       "([^\"[:space:]]+|\"(?:[^\"\\\\]|\\\\.)+\")\\s+"
-      "([^\"[:space:]]+|\"(?:[^\"\\\\]|\\\\.)+\")"
+      "([^\"[:space:]]+|\"(?:[^\"\\\\]|\\\\.)+\")\\s*"
       );
    static const boost::regex set_regex_parser(
       "!set-regex\\s+(?:(class)|(function)|(typedef)|(macro))\\s+"
       "(?<prefix>[^\"[:space:]]+|\"(?:[^\"\\\\]|\\\\.)+\")\\s+"
-      "(?<suffix>[^\"[:space:]]+|\"(?:[^\"\\\\]|\\\\.)+\")"
+      "(?<suffix>[^\"[:space:]]+|\"(?:[^\"\\\\]|\\\\.)+\")\\s*"
       );
 
    if(verbose)
@@ -374,6 +430,7 @@
          else if(what[4].matched)
          {
             std::cout << "WARNING: Changing the regexes used for macro name scanning is not supported yet." << std::endl;
+			return;
          }
          else
          {
@@ -394,25 +451,39 @@
       }
       else if(regex_match(line, what, entry_parser))
       {
-         // what[1] is the Index entry
-         // what[2] is the regex to search for (optional)
-         // what[3] is a section id that must be matched 
-         // in order for the term to be indexed (optional)
-         // what[4] is the index category to place the term in (optional).
-         index_info info;
-         info.term = unquote(what.str(1));
-         std::string s = unquote(what.str(2));
-         if(s.size())
-            info.search_text = boost::regex(s, boost::regex::icase|boost::regex::perl);
-         else
-            info.search_text = boost::regex("\\<" + what.str(1) + "\\>", boost::regex::icase|boost::regex::perl);
+         try{
+            // what[1] is the Index entry
+            // what[2] is the regex to search for (optional)
+            // what[3] is a section id that must be matched 
+            // in order for the term to be indexed (optional)
+            // what[4] is the index category to place the term in (optional).
+            index_info info;
+            info.term = unquote(what.str(1));
+            std::string s = unquote(what.str(2));
+            if(s.size())
+               info.search_text = boost::regex(s, boost::regex::icase|boost::regex::perl);
+            else
+               info.search_text = boost::regex("\\<" + what.str(1) + "\\>", boost::regex::icase|boost::regex::perl);
 
-         s = unquote(what.str(3));
-         if(s.size())
-            info.search_id = s;
-         if(what[4].matched)
-            info.category = unquote(what.str(4));
-         index_terms.insert(info);
+            s = unquote(what.str(3));
+            if(s.size())
+               info.search_id = s;
+            if(what[4].matched)
+               info.category = unquote(what.str(4));
+            index_terms.insert(info);
+         }
+         catch(const boost::regex_error&)
+         {
+            std::cerr << "Unable to process regular expression in script line:\n  \""
+               << line << "\"" << std::endl;
+            throw;
+         }
+         catch(const std::exception&)
+         {
+            std::cerr << "Unable to process script line:\n  \""
+               << line << "\"" << std::endl;
+            throw;
+         }
       }
    }
 }