[sword-svn] r2108 - in trunk: . include src/mgr tests utilities

scribe at www.crosswire.org scribe at www.crosswire.org
Sat Oct 13 13:35:03 MST 2007


Author: scribe
Date: 2007-10-13 13:35:02 -0700 (Sat, 13 Oct 2007)
New Revision: 2108

Modified:
   trunk/ChangeLog
   trunk/include/defs.h
   trunk/include/filemgr.h
   trunk/include/swmgr.h
   trunk/src/mgr/filemgr.cpp
   trunk/tests/complzss.cpp
   trunk/tests/compnone.cpp
   trunk/tests/compzip.cpp
   trunk/utilities/cipherraw.cpp
   trunk/utilities/gbfidx.cpp
   trunk/utilities/step2vpl.cpp
   trunk/utilities/stepdump.cpp
   trunk/utilities/vpl2mod.cpp
   trunk/utilities/vpl2zmod2.cpp
Log:
	Added new FileMgr::openFileReadOnly to help centralize
		all file io details.



Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-10-12 05:54:54 UTC (rev 2107)
+++ trunk/ChangeLog	2007-10-13 20:35:02 UTC (rev 2108)
@@ -1,6 +1,10 @@
 API ChangeLog 
 
 11-Oct-2007	Troy A. Griffitts <scribe at crosswire.org>
+	Added new FileMgr::openFileReadOnly to help centralize
+		all file io details.
+
+11-Oct-2007	Troy A. Griffitts <scribe at crosswire.org>
 	Added new RawText4 and RawCom4 drivers which allow
 		for a 4 byte record size.  Patch submitted by
 		Doug Rintoul <doug_rintoul at sil dot org>

Modified: trunk/include/defs.h
===================================================================
--- trunk/include/defs.h	2007-10-12 05:54:54 UTC (rev 2107)
+++ trunk/include/defs.h	2007-10-13 20:35:02 UTC (rev 2108)
@@ -101,18 +101,6 @@
 #  define SWDLLIMPORT
 #endif
 
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
-#ifndef S_IRGRP
-#define S_IRGRP 0
-#endif
-
-#ifndef S_IROTH
-#define S_IROTH 0
-#endif
-
 enum {DIRECTION_LTR = 0, DIRECTION_RTL, DIRECTION_BIDI};
 enum {FMT_UNKNOWN = 0, FMT_PLAIN, FMT_THML, FMT_GBF, FMT_HTML, FMT_HTMLHREF, FMT_RTF, FMT_OSIS, FMT_WEBIF, FMT_TEI};
 enum {ENC_UNKNOWN = 0, ENC_LATIN1, ENC_UTF8, ENC_SCSU, ENC_UTF16, ENC_RTF, ENC_HTML};

Modified: trunk/include/filemgr.h
===================================================================
--- trunk/include/filemgr.h	2007-10-12 05:54:54 UTC (rev 2107)
+++ trunk/include/filemgr.h	2007-10-13 20:35:02 UTC (rev 2108)
@@ -171,6 +171,12 @@
 	static char isDirectory(const char *path);
 	static int createParent(const char *pName);
 	static int createPathAndFile(const char *fName);
+
+	/** attempts to open a file readonly
+	 * @param fName filename to open
+	 * @return fd; < 0 = error
+	 */
+	static int openFileReadOnly(const char *fName);
 	static int copyFile(const char *srcFile, const char *destFile);
 	static int copyDir(const char *srcDir, const char *destDir);
 	static int removeDir(const char *targetDir);

Modified: trunk/include/swmgr.h
===================================================================
--- trunk/include/swmgr.h	2007-10-12 05:54:54 UTC (rev 2107)
+++ trunk/include/swmgr.h	2007-10-13 20:35:02 UTC (rev 2108)
@@ -21,7 +21,7 @@
  */
 
 /** @mainpage The SWORD Project - API documentation
- * This is the API documentation for the SWORD Project.
+ * This is the API documentation for The SWORD Project.
  * It describes the structure of the SWORD library and documents the functions of the classes.
  * From time to time this documentation gives programming examples, too.
  *
@@ -30,9 +30,9 @@
  *
  * Some main classes:
  *
- * SWMgr makes an installed library of modules (works) available.
- * SWModule represents an individual work
- * SWKey represents a location into a work (e.g. "John 3:16")
+ * SWMgr gives access to an installed library of modules (books).
+ * SWModule represents an individual module
+ * SWKey represents a location into a module (e.g. "John 3:16")
  *
  * An API Primer can be found at:
  *

Modified: trunk/src/mgr/filemgr.cpp
===================================================================
--- trunk/src/mgr/filemgr.cpp	2007-10-12 05:54:54 UTC (rev 2107)
+++ trunk/src/mgr/filemgr.cpp	2007-10-13 20:35:02 UTC (rev 2108)
@@ -37,6 +37,19 @@
 #include <unistd.h>
 #endif
 
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
+#ifndef S_IRGRP
+#define S_IRGRP 0
+#endif
+
+#ifndef S_IROTH
+#define S_IROTH 0
+#endif
+
 // Fix for VC6
 #ifndef S_IREAD
 #ifdef _S_IREAD
@@ -364,6 +377,12 @@
 }
 	
 
+int FileMgr::openFileReadOnly(const char *fName) {
+	int fd = ::open(fName, O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
+	return fd;
+}
+
+
 int FileMgr::createPathAndFile(const char *fName) {
 	int fd;
 	

Modified: trunk/tests/complzss.cpp
===================================================================
--- trunk/tests/complzss.cpp	2007-10-12 05:54:54 UTC (rev 2107)
+++ trunk/tests/complzss.cpp	2007-10-13 20:35:02 UTC (rev 2108)
@@ -13,7 +13,9 @@
 #include <unistd.h>
 #endif
 
+#include <filemgr.h>
 #include <lzsscomprs.h>
+
 #ifndef NO_SWORD_NAMESPACE
 using namespace sword;
 #endif
@@ -37,14 +39,10 @@
 {
 	char buf[256];
 
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
+	ufd  = FileMgr::createPathAndFile(fname);
 
-	ufd  = open(fname, O_RDWR|O_CREAT|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
-
 	sprintf(buf, "%s.lzs", fname);
-	zfd = open(buf, O_RDWR|O_CREAT|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
+	zfd = FileMgr::createPathAndFile(buf);
 }
 
 	

Modified: trunk/tests/compnone.cpp
===================================================================
--- trunk/tests/compnone.cpp	2007-10-12 05:54:54 UTC (rev 2107)
+++ trunk/tests/compnone.cpp	2007-10-13 20:35:02 UTC (rev 2108)
@@ -13,7 +13,9 @@
 #include <unistd.h>
 #endif
 
+#include <filemgr.h>
 #include <swcomprs.h>
+
 #ifndef NO_SWORD_NAMESPACE
 using namespace sword;
 #endif
@@ -37,14 +39,10 @@
 {
 	char buf[256];
 
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
+	ufd  = FileMgr::createPathAndFile(fname);
 
-	ufd  = open(fname, O_RDWR|O_CREAT|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
-
 	sprintf(buf, "%s.zzz", fname);
-	zfd = open(buf, O_RDWR|O_CREAT|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
+	zfd = FileMgr::createPathAndFile(buf);
 }
 
 	

Modified: trunk/tests/compzip.cpp
===================================================================
--- trunk/tests/compzip.cpp	2007-10-12 05:54:54 UTC (rev 2107)
+++ trunk/tests/compzip.cpp	2007-10-13 20:35:02 UTC (rev 2108)
@@ -11,7 +11,9 @@
 #include <unistd.h>
 #endif
 
+#include <filemgr.h>
 #include <zipcomprs.h>
+
 #ifndef NO_SWORD_NAMESPACE
 using namespace sword;
 #endif
@@ -35,14 +37,10 @@
 {
 	char buf[256];
 
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
+	ufd  = FileMgr::createPathAndFile(fname);
 
-	ufd  = open(fname, O_RDWR|O_CREAT|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
-
 	sprintf(buf, "%s.zip", fname);
-	zfd = open(buf, O_RDWR|O_CREAT|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
+	zfd = FileMgr::createPathAndFile(buf);
 }
 
 	

Modified: trunk/utilities/cipherraw.cpp
===================================================================
--- trunk/utilities/cipherraw.cpp	2007-10-12 05:54:54 UTC (rev 2107)
+++ trunk/utilities/cipherraw.cpp	2007-10-13 20:35:02 UTC (rev 2108)
@@ -12,6 +12,7 @@
 #include <unistd.h>
 #endif
 
+#include <filemgr.h>
 #include <swcipher.h>
 #include <versekey.h>
 #include <rawverse.h>
@@ -39,19 +40,15 @@
 	rawdrv = new RawVerse(argv[1]);
 	zobj = new SWCipher((unsigned char *)argv[2]);
 
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
 	tmpbuf = new char [ strlen(argv[1]) + 11 ];
 	sprintf(tmpbuf, "%sot.zzz", argv[1]);
-	ofd[0] = open(tmpbuf, O_WRONLY|O_BINARY|O_CREAT, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
+	ofd[0] = FileMgr::createPathAndFile(tmpbuf);
 	sprintf(tmpbuf, "%sot.zzz.vss", argv[1]);
-	oxfd[0] = open(tmpbuf, O_WRONLY|O_BINARY|O_CREAT, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
+	oxfd[0] = FileMgr::createPathAndFile(tmpbuf);
 	sprintf(tmpbuf, "%snt.zzz", argv[1]);
-	ofd[1] = open(tmpbuf, O_WRONLY|O_BINARY|O_CREAT, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
+	ofd[1] = FileMgr::createPathAndFile(tmpbuf);
 	sprintf(tmpbuf, "%snt.zzz.vss", argv[1]);
-	oxfd[1] = open(tmpbuf, O_WRONLY|O_BINARY|O_CREAT, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
+	oxfd[1] = FileMgr::createPathAndFile(tmpbuf);
 
 	delete [] tmpbuf;
 

Modified: trunk/utilities/gbfidx.cpp
===================================================================
--- trunk/utilities/gbfidx.cpp	2007-10-12 05:54:54 UTC (rev 2107)
+++ trunk/utilities/gbfidx.cpp	2007-10-13 20:35:02 UTC (rev 2108)
@@ -16,6 +16,7 @@
 
 #include <fcntl.h>
 #include <versekey.h>
+#include <filemgr.h>
 
 using namespace sword;
 
@@ -248,30 +249,27 @@
 
 void openfiles(char *fname)
 {
-#ifndef O_BINARY		// O_BINARY is needed in Borland C++ 4.53
-#define O_BINARY 0		// If it hasn't been defined than we probably
-#endif				// don't need it.
-	char buf[255];
+	SWBuf buf;
 
-	if ((fp = open(fname, O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH)) == -1) {
+	if ((fp = FileMgr::openFileReadOnly(fname)) < 0) {
 		fprintf(stderr, "Couldn't open file: %s\n", fname);
 		exit(1);
 	}
 
-	sprintf(buf, "%s.vss", fname);
-	if ((vfp = open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH)) == -1) {
+	buf.setFormatted("%s.vss", fname);
+	if ((vfp = FileMgr::createPathAndFile(buf)) < 0) {
 		fprintf(stderr, "Couldn't open file: %s\n", buf);
 		exit(1);
 	}
 
-	sprintf(buf, "%s.cps", fname);
-	if ((cfp = open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH)) == -1) {
+	buf.setFormatted("%s.cps", fname);
+	if ((cfp = FileMgr::createPathAndFile(buf)) < 0) {
 		fprintf(stderr, "Couldn't open file: %s\n", buf);
 		exit(1);
 	}
 
-	sprintf(buf, "%s.bks", fname);
-	if ((bfp = open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH)) == -1) {
+	buf.setFormatted("%s.bks", fname);
+	if ((bfp = FileMgr::createPathAndFile(buf)) < 0) {
 		fprintf(stderr, "Couldn't open file: %s\n", buf);
 		exit(1);
 	}

Modified: trunk/utilities/step2vpl.cpp
===================================================================
--- trunk/utilities/step2vpl.cpp	2007-10-12 05:54:54 UTC (rev 2107)
+++ trunk/utilities/step2vpl.cpp	2007-10-13 20:35:02 UTC (rev 2108)
@@ -11,6 +11,7 @@
 #include <unistd.h>
 #endif
 
+#include <filemgr.h>
 #include <lzsscomprs.h>
 
 using namespace std;
@@ -135,7 +136,7 @@
 		bookpath += "/";
 
 	fileName = bookpath + "Book.dat";
-	int fdbook = open(fileName.c_str(), O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
+	int fdbook = FileMgr::openFileReadOnly(fileName.c_str());
 
 	if (fdbook < 1) {
 		cerr << "error, couldn't open file: " << fileName << "\n";
@@ -148,7 +149,7 @@
 
 
 	fileName = bookpath + "Viewable.idx";
-	int fdviewable = open(fileName.c_str(), O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
+	int fdviewable = FileMgr::openFileReadOnly(fileName.c_str());
 
 	if (fdviewable < 1) {
 		cerr << "error, couldn't open file: " << fileName << "\n";
@@ -163,7 +164,7 @@
 
 
 	fileName = bookpath + "Vsync.idx";
-	int fdvsync = open(fileName.c_str(), O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
+	int fdvsync = FileMgr::openFileReadOnly(fileName.c_str());
 
 	if (fdvsync < 1) {
 		cerr << "error, couldn't open file: " << fileName << "\n";
@@ -171,7 +172,7 @@
 	}
 
 	fileName = bookpath + "Sections.idx";
-	int fdsections = open(fileName.c_str(), O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
+	int fdsections = FileMgr::openFileReadOnly(fileName.c_str());
 
 	if (fdsections < 1) {
 		cerr << "error, couldn't open file: " << fileName << "\n";

Modified: trunk/utilities/stepdump.cpp
===================================================================
--- trunk/utilities/stepdump.cpp	2007-10-12 05:54:54 UTC (rev 2107)
+++ trunk/utilities/stepdump.cpp	2007-10-13 20:35:02 UTC (rev 2108)
@@ -9,6 +9,7 @@
 #include <unistd.h>
 #endif
 
+#include <filemgr.h>
 #include <lzsscomprs.h>
 
 using namespace std;
@@ -74,7 +75,7 @@
 		bookpath += "/";
 
 	fileName = bookpath + "Book.dat";
-	int fd = open(fileName.c_str(), O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
+	int fd = FileMgr::openFileReadOnly(fileName.c_str());
 
 	if (fd < 1) {
 		cerr << "error, couldn't open file: " << fileName << "\n";
@@ -87,7 +88,7 @@
 
 
 	fileName = bookpath + "Viewable.idx";
-	int fdv = open(fileName.c_str(), O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
+	int fdv = FileMgr::openFileReadOnly(fileName.c_str());
 
 	if (fdv < 1) {
 		cerr << "error, couldn't open file: " << fileName << "\n";

Modified: trunk/utilities/vpl2mod.cpp
===================================================================
--- trunk/utilities/vpl2mod.cpp	2007-10-12 05:54:54 UTC (rev 2107)
+++ trunk/utilities/vpl2mod.cpp	2007-10-13 20:35:02 UTC (rev 2108)
@@ -11,6 +11,7 @@
 #include <unistd.h>
 #endif
 
+#include <filemgr.h>
 #include <swmgr.h>
 #include <rawtext.h>
 #include <iostream>
@@ -18,6 +19,7 @@
 #include <versekey.h>
 
 #ifndef NO_SWORD_NAMESPACE
+using sword::FileMgr;
 using sword::SWMgr;
 using sword::RawText;
 using sword::VerseKey;
@@ -150,7 +152,7 @@
 		fprintf(stderr, "\t\tCHAPTER 1 HEADER\n");
 		fprintf(stderr, "\t\tIn the beginning...\n\n");
 		fprintf(stderr, "\t... implying there must also be a CHAPTER2 HEADER,\n");
-        fprintf(stderr, "\tEXODUS HEADER, NEW TESTAMENT HEADER, etc.  If there is no text for\n");
+		fprintf(stderr, "\tEXODUS HEADER, NEW TESTAMENT HEADER, etc.  If there is no text for\n");
 		fprintf(stderr, "\tthe header, a blank line must, at least, hold place.\n\n");
 		fprintf(stderr, "\tWith verse refs, source file must simply contain any number of lines,\n");
 		fprintf(stderr, "\tthat begin with the verse reference for which it is an entry.  e.g.:\n\n");
@@ -160,7 +162,7 @@
 	}
 
 	// Let's see if we can open our input file
-	int fd = open(argv[1], O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
+	int fd = FileMgr::openFileReadOnly(argv[1]);
 	if (fd < 0) {
 		fprintf(stderr, "error: %s: couldn't open input file: %s \n", argv[0], argv[1]);
 		exit(-2);

Modified: trunk/utilities/vpl2zmod2.cpp
===================================================================
--- trunk/utilities/vpl2zmod2.cpp	2007-10-12 05:54:54 UTC (rev 2107)
+++ trunk/utilities/vpl2zmod2.cpp	2007-10-13 20:35:02 UTC (rev 2108)
@@ -173,7 +173,7 @@
 	}
 
 	// Let's see if we can open our input file
-	int fd = open(argv[1], O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
+	int fd = FileMgr::openFileReadOnly(argv[1]);
 	if (fd < 0) {
 		fprintf(stderr, "error: %s: couldn't open input file: %s \n", argv[0], argv[1]);
 		exit(-2);




More information about the sword-cvs mailing list