[Pinfo-devel] r48 - pinfo/branches/cxx/src
Nathanael Nerode
neroden-guest at costa.debian.org
Fri Aug 26 10:53:56 UTC 2005
Author: neroden-guest
Date: 2005-08-26 10:53:45 +0000 (Fri, 26 Aug 2005)
New Revision: 48
Modified:
pinfo/branches/cxx/src/filehandling_functions.cxx
Log:
More low-hanging fruit for std::string conversion.
Modified: pinfo/branches/cxx/src/filehandling_functions.cxx
===================================================================
--- pinfo/branches/cxx/src/filehandling_functions.cxx 2005-08-26 10:21:29 UTC (rev 47)
+++ pinfo/branches/cxx/src/filehandling_functions.cxx 2005-08-26 10:53:45 UTC (rev 48)
@@ -32,9 +32,32 @@
}
Suffixes;
-char * basename(char *filename);
+void
+basename_and_dirname(string filename, string& basename, string& dirname)
+{
+ /* Dirname should end with a slash, or be empty. */
+ string::size_type index = filename.rfind('/');
+ if (index == string::npos) {
+ basename = filename;
+ dirname = "";
+ } else {
+ basename = filename.substr(index + 1);
+ dirname = filename.substr(0, index);
+ }
+}
+void
+basename(string filename, string& basename_str)
+{
+ string::size_type index = filename.rfind('/');
+ if (index == string::npos) {
+ basename_str = filename;
+ } else {
+ basename_str = filename.substr(index + 1);
+ }
+}
+
/******************************************************************************
* This piece of declarations says what to do with info files stored with *
* different formats/compression methods, before putting them into a temporary *
@@ -70,13 +93,18 @@
{
#define Buf (*buf)
DIR *dir;
- char *bname=basename(name);
+ string name_string = name;
+ string basename_string;
+ string dirname_string;
+ basename_and_dirname(name_string, basename_string, dirname_string);
+
+ const char *bname = basename_string.c_str();
struct dirent *dp;
int namelen = strlen(bname);
int matched = 0;
if (Buf[strlen(Buf)-1]!='/')
strcat(Buf,"/");
- strncat(Buf,name,bname-name);
+ strcat(Buf,dirname_string.c_str());
dir = opendir(Buf); /* here we always have '/' at end */
if (dir == NULL)
return 1;
@@ -643,20 +671,6 @@
return NULL;
}
-char *
-basename(char *filename)
-{
- int len = strlen(filename);
- char *a = filename + len;
- while (a > filename)
- {
- a--;
- if (*a == '/')
- return a + 1;
- }
- return filename; /* when it was a basename */
-}
-
/*
* Note: openinfo is a function for reading info files, and putting
* uncompressed content into a temporary filename. For a flexibility, there
@@ -717,7 +731,10 @@
{
strcpy(buf, filenameprefix); /* build a filename */
strcat(buf, "/");
- strcat(buf, basename(filename));
+ string filename_string = filename;
+ string basename_string;
+ basename(filename_string, basename_string);
+ strcat(buf, basename_string.c_str());
}
}
else
@@ -772,7 +789,7 @@
return 0;
}
- void
+void
addrawpath(char *filename)
{
int len = strlen(filename);
@@ -805,7 +822,7 @@
filename[pos] = tmp;
}
- int
+int
isininfopath(char *name)
{
int i;
More information about the Pinfo-devel
mailing list