[sword-svn] r1839 - trunk/utilities

dglassey at crosswire.org dglassey at crosswire.org
Wed Jun 29 15:23:12 MST 2005


Author: dglassey
Date: 2005-06-29 15:23:12 -0700 (Wed, 29 Jun 2005)
New Revision: 1839

Modified:
   trunk/utilities/imp2vs.cpp
Log:
fix a crash on the final blank line
it's a utility so exceptions should be ok, can revert them if not



Modified: trunk/utilities/imp2vs.cpp
===================================================================
--- trunk/utilities/imp2vs.cpp	2005-06-29 15:13:31 UTC (rev 1838)
+++ trunk/utilities/imp2vs.cpp	2005-06-29 22:23:12 UTC (rev 1839)
@@ -23,10 +23,10 @@
   const string helptext ="imp2vs 1.0 Bible/Commentary module creation tool for the SWORD Project\n  usage:\n   %s <filename> [output dir] \n";
   
   signed long i = 0;
-  string keybuffer;
-  string entbuffer;
-  string linebuffer;
-  string modname;
+  string keybuffer = "";
+  string entbuffer = "";
+  string linebuffer = "";
+  string modname = "";
   
   if (argc > 2) {
     modname = argv[2];
@@ -39,6 +39,8 @@
     exit(-1);
   }
   
+  try {
+  
   ifstream infile(argv[1]);
 
   SWText* mod;
@@ -57,7 +59,7 @@
   final = (!infile.eof()) + 1;
 
   while (final) {
-    if (linebuffer.substr(0,3) == "$$$" || final == 1) {
+    if (final == 1 || (linebuffer.size() > 3 && linebuffer.substr(0,3) == "$$$")) {
       if (keybuffer.size() && entbuffer.size()) {
 	std::cout << "from file: " << keybuffer << std::endl;
 	*vkey = keybuffer.c_str();
@@ -78,7 +80,7 @@
 		  vkey->Verse(0);
        }
 
-	  std::cout << "adding entry: " << *vkey << std::endl;
+	  std::cout << "adding entry: " << *vkey << " length " << entbuffer.size() << "/" << (unsigned short)entbuffer.size() << std::endl;
 	  mod->setEntry(entbuffer.c_str(), entbuffer.size());
 	}
 	else {
@@ -99,7 +101,7 @@
 		havefirst = true;
 		firstverse = *vkey;
 
-	     std::cout << "adding entry: " << *vkey << std::endl;
+		std::cout << "adding entry: " << *vkey << " length " << entbuffer.size() << "/" << (unsigned short)entbuffer.size() << std::endl;
 		mod->setEntry(entbuffer.c_str(), entbuffer.size());
 		(*vkey)++;
 	      }
@@ -120,14 +122,15 @@
 		havefirst = true;
 		firstverse = *vkey;
 
-	     std::cout << "adding entry: " << *vkey << std::endl;
+		std::cout << "adding entry: " << *vkey << " length " << entbuffer.size() << "/" << (unsigned short)entbuffer.size() << std::endl;
 		mod->setEntry(entbuffer.c_str(), entbuffer.size());
 	      }
 	    }
 	  }
 	}
       }
-      keybuffer = linebuffer.substr(3,linebuffer.size()) ;
+      if (linebuffer.size() > 3)
+	      keybuffer = linebuffer.substr(3,linebuffer.size()) ;
       entbuffer.resize(0);
     }
     else {
@@ -139,6 +142,18 @@
       final = (!infile.eof()) + 1;
     }
   }
+  }
+  catch (const std::exception& e) {
+         std::cerr << "Exception: imp2vs failed: " << e.what() << std::endl;
+	 std::cerr << "Line: " << linebuffer.size() << " " << linebuffer << std::endl;
+	 std::cerr << "Key: "  << keybuffer.size() << " " << keybuffer << std::endl;
+	 std::cerr << "Ent: "  << entbuffer.size() << " " << entbuffer << std::endl;
+         return -2;
+  }
+  catch (...) {
+         std::cerr << "Exception: imp2vs failed" << std::endl;
+         return -3;
+  }
 
   return 0;
 }



More information about the sword-cvs mailing list