Replace part of code of strschg_environ() using pure C++
This commit is contained in:
parent
bc54b3f3b3
commit
5bd7fc2a28
@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
// Adds the directory-delimiter character into end of string ('\\' in DOS-based, '/' in unix-based OS)
|
// Adds the directory-delimiter character into end of string ('\\' in DOS-based, '/' in unix-based OS)
|
||||||
|
// Replace wrong directory-delimiter character with good.
|
||||||
|
|
||||||
std::string& AddBackslash(std::string& p) {
|
std::string& AddBackslash(std::string& p) {
|
||||||
|
|
||||||
@ -74,6 +75,7 @@ void PathCopy(std::string& dst, const char* src) {
|
|||||||
|
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
// DOS-style enviroment variables substitution in string.
|
// DOS-style enviroment variables substitution in string.
|
||||||
|
// Unix-style tilde substitution in string.
|
||||||
|
|
||||||
int strschg_environ(std::string& s) {
|
int strschg_environ(std::string& s) {
|
||||||
|
|
||||||
@ -88,29 +90,25 @@ int strschg_environ(std::string& s) {
|
|||||||
s.replace(posn, posn1-posn+1, rep);
|
s.replace(posn, posn1-posn+1, rep);
|
||||||
replaced++;
|
replaced++;
|
||||||
}
|
}
|
||||||
|
fnd.clear();
|
||||||
|
|
||||||
#ifndef __HAVE_DRIVES__
|
#ifndef __HAVE_DRIVES__
|
||||||
if(not s.empty() and (s[0] == '~')) {
|
if( s[0] == '~' ) {
|
||||||
std::string name;
|
|
||||||
const char *p = s.c_str()+1;
|
|
||||||
struct passwd *pe=NULL;
|
struct passwd *pe=NULL;
|
||||||
|
size_t slash;
|
||||||
|
|
||||||
if((s.length() > 1) and not isslash(*p)) {
|
if( (s.length() > 2) and not isslash(s[1]) ) {
|
||||||
while(*p and not isslash(*p))
|
slash = s.find_first_of(GOLD_SLASH_STR GOLD_WRONG_SLASH_STR, 1);
|
||||||
name += *p++;
|
std::string name(s,1,slash-1);
|
||||||
pe = getpwnam(name.c_str());
|
pe = getpwnam(name.c_str());
|
||||||
}
|
}else {
|
||||||
else {
|
|
||||||
pe = getpwuid(getuid());
|
pe = getpwuid(getuid());
|
||||||
}
|
}
|
||||||
if(pe != NULL) {
|
if(pe != NULL) {
|
||||||
std::string dirname = pe->pw_dir;
|
std::string dirname = pe->pw_dir;
|
||||||
dirname += GOLD_SLASH_CHR;
|
if ( slash != std::string::npos )
|
||||||
if(isslash(*p))
|
dirname += s.substr(slash);
|
||||||
++p;
|
s=dirname;
|
||||||
dirname += p;
|
|
||||||
s = dirname.c_str();
|
|
||||||
replaced++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user