From: Mikko Rasa Date: Wed, 27 Jul 2011 05:42:32 +0000 (+0300) Subject: Style update: spaces around assignments X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=fa77438b62207466c48620604c8cc34931080936;p=libs%2Fcore.git Style update: spaces around assignments --- diff --git a/source/dir.cpp b/source/dir.cpp index 111378f..ad2e013 100644 --- a/source/dir.cpp +++ b/source/dir.cpp @@ -42,20 +42,20 @@ const Path &get_bin_dir(const string &argv0) Path exe; if(argv0.find('/')==string::npos) { - const char *path=getenv("PATH"); - vector dirs=split(path, ':'); + const char *path = getenv("PATH"); + vector dirs = split(path, ':'); for(vector::const_iterator i=dirs.begin(); i!=dirs.end(); ++i) if(exists(Path(*i)/argv0)) { - exe=realpath(Path(*i)/argv0); + exe = realpath(Path(*i)/argv0); break; } } else - exe=realpath(argv0); + exe = realpath(argv0); - last_argv0=argv0; - bin_dir=dirname(exe); + last_argv0 = argv0; + bin_dir = dirname(exe); } return bin_dir; @@ -69,9 +69,9 @@ void mkdir(const Path &path, int mode) #ifdef WIN32 // The win32 version of this function doesn't take the mode argument. Go figure. (void)mode; - err=::mkdir(path.str().c_str()); + err = ::mkdir(path.str().c_str()); #else - err=::mkdir(path.str().c_str(), mode); + err = ::mkdir(path.str().c_str(), mode); #endif if(err==-1) @@ -83,13 +83,13 @@ void mkpath(const Path &path, int mode) Path p; for(Path::Iterator i=path.begin(); i!=path.end(); ++i) { - p/=*i; + p /= *i; #ifdef WIN32 if(p.size()==1 && p.is_absolute()) continue; #endif struct stat st; - int err=stat(p, st); + int err = stat(p, st); if(err==0) { if(!S_ISDIR(st.st_mode)) @@ -111,11 +111,11 @@ void rmdir(const Path &path) void rmdirs(const Path &path) { - list files=list_files(path); + list files = list_files(path); for(list::iterator i=files.begin(); i!=files.end(); ++i) { - Path p=path / *i; - struct stat st=stat(p.str().c_str()); + Path p = path / *i; + struct stat st = stat(p.str().c_str()); if(S_ISDIR(st.st_mode)) rmdirs(p); else @@ -135,12 +135,12 @@ list list_filtered(const Path &path, const string &filter) Regex r_filter(filter); list result; - DIR *dir=opendir(path.str().c_str()); + DIR *dir = opendir(path.str().c_str()); if(dir) { - while(dirent *de=readdir(dir)) + while(dirent *de = readdir(dir)) { - const char *fn=de->d_name; + const char *fn = de->d_name; if(fn[0]=='.' && (fn[1]==0 || (fn[1]=='.' && fn[2]==0))) continue; if(r_filter.match(fn)) @@ -165,7 +165,7 @@ Path get_home_dir() if(SHGetFolderPath(0, CSIDL_PERSONAL, 0, 0, home)==S_OK) return home; #else - const char *home=getenv("HOME"); + const char *home = getenv("HOME"); if(home) return home; #endif @@ -186,13 +186,13 @@ Path get_user_data_dir(const string &appname) Path get_sys_conf_dir(const string &argv0) { - Path dir=get_bin_dir(argv0); + Path dir = get_bin_dir(argv0); if(dir[-1]=="bin" || dir[-1]=="sbin") { - dir/=".."; + dir /= ".."; if(dir[-1]=="usr") - dir/=".."; + dir /= ".."; return dir/"etc"; } else @@ -201,7 +201,7 @@ Path get_sys_conf_dir(const string &argv0) Path get_sys_data_dir(const string &argv0, const string &appname) { - Path dir=get_bin_dir(argv0); + Path dir = get_bin_dir(argv0); if(dir[-1]=="bin" || dir[-1]=="sbin") return dir/".."/"share"/appname; @@ -211,7 +211,7 @@ Path get_sys_data_dir(const string &argv0, const string &appname) Path get_sys_lib_dir(const string &argv0, const string &appname) { - Path dir=get_bin_dir(argv0); + Path dir = get_bin_dir(argv0); if(dir[-1]=="bin" || dir[-1]=="sbin") return dir/".."/"lib"/appname; diff --git a/source/path.cpp b/source/path.cpp index d8a2c71..e514d36 100644 --- a/source/path.cpp +++ b/source/path.cpp @@ -42,7 +42,7 @@ unsigned Path::size() const if(path.size()==1 && path[0]==DIRSEP) return 1; - unsigned count=1; + unsigned count = 1; for(string::const_iterator i=path.begin(); i!=path.end(); ++i) if(*i==DIRSEP) ++count; return count; @@ -62,12 +62,12 @@ bool Path::is_absolute() const Path Path::subpath(unsigned start, unsigned count) const { Path result; - Iterator i=begin(); + Iterator i = begin(); for(unsigned j=0; (jstart) add_component(p.substr(start, slash-start)); if(slash==string::npos) break; - start=slash+1; + start = slash+1; } } @@ -167,21 +167,21 @@ void Path::add_component(const string &comp) { // Replace the path with the root directory #ifdef WIN32 - unsigned slash=path.find(DIRSEP); + unsigned slash = path.find(DIRSEP); if(is_windows_drive(path.substr(0, slash))) - path=path.substr(0, 2); + path = path.substr(0, 2); else #endif - path=comp; + path = comp; } #ifdef WIN32 else if(is_windows_drive(comp)) - path=comp; + path = comp; #endif else if(comp=="..") { if(path.empty() || path==".") - path=comp; + path = comp; // .. in root directory is a no-op else if(path.size()==1 && path[0]==DIRSEP) ; @@ -191,20 +191,20 @@ void Path::add_component(const string &comp) #endif else { - string::size_type slash=path.rfind(DIRSEP); - string::size_type start=(slash==string::npos ? 0 : slash+1); + string::size_type slash = path.rfind(DIRSEP); + string::size_type start = (slash==string::npos ? 0 : slash+1); if(!path.compare(start, string::npos, "..")) { // If the last component already is a .., add another - path+=DIRSEP; - path+=comp; + path += DIRSEP; + path += comp; } else if(slash==string::npos) - path="."; + path = "."; else { if(slash==0) - slash=1; + slash = 1; // Otherwise, erase the last component path.erase(slash, string::npos); } @@ -213,10 +213,10 @@ void Path::add_component(const string &comp) else if(comp!="." || path.empty()) { if(comp!="." && path.empty()) - path="."; + path = "."; if(path.size()>1 || (path.size()==1 && path[0]!=DIRSEP)) - path+=DIRSEP; - path+=comp; + path += DIRSEP; + path += comp; } } @@ -226,25 +226,25 @@ Path::Iterator::Iterator(const Path &p): start(0) { if(path.path.empty()) - start=end=string::npos; + start=end = string::npos; else if(path.path[0]==DIRSEP) - end=1; + end = 1; #ifdef WIN32 else if(path.path.size()>2 && path.path[2]==DIRSEP && is_windows_drive(path.path.substr(0, 2))) - end=2; + end = 2; #endif else - end=path.path.find(DIRSEP); + end = path.path.find(DIRSEP); } Path::Iterator &Path::Iterator::operator++() { - start=end; + start = end; if(start>=path.path.size()) return *this; if(path.path[start]==DIRSEP) ++start; - end=path.path.find(DIRSEP, start); + end = path.path.find(DIRSEP, start); return *this; } @@ -253,13 +253,13 @@ Path::Iterator &Path::Iterator::operator--() if(start==0) return *this; - end=start; + end = start; if(end>1 && end(-1)) const; + Path subpath(unsigned start, unsigned count = static_cast(-1)) const; /// Concatenates this path with another one, with usual filesystem semantics Path operator/(const Path &p) const; diff --git a/source/utils.cpp b/source/utils.cpp index 4036225..694a8f1 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -42,13 +42,13 @@ Path dirname(const Path &p) string basepart(const string &fn) { - unsigned dot=fn.rfind('.'); + unsigned dot = fn.rfind('.'); return fn.substr(0, dot); } string extpart(const string &fn) { - string::size_type dot=fn.rfind('.'); + string::size_type dot = fn.rfind('.'); if(dot==string::npos) return string(); return fn.substr(dot); @@ -56,30 +56,30 @@ string extpart(const string &fn) Path fix_case(const Path &path) { - bool found=true; + bool found = true; Path result; for(Path::Iterator i=path.begin(); i!=path.end(); ++i) { if(!found || *i=="/") - result/=*i; + result /= *i; else { list files; if(result.size()) - files=list_files(result); + files = list_files(result); else - files=list_files("."); + files = list_files("."); - found=false; + found = false; for(list::iterator j=files.begin(); (j!=files.end() && !found); ++j) if(!strcasecmp(*j,*i)) { - result/=*j; - found=true; + result /= *j; + found = true; } if(!found) - result/=*i; + result /= *i; } } @@ -93,7 +93,7 @@ Path readlink(const Path &link) throw Exception("No symbolic links on win32"); #else char buf[4096]; - int len=::readlink(link.str().c_str(), buf, sizeof(buf)); + int len = ::readlink(link.str().c_str(), buf, sizeof(buf)); if(len==-1) throw SystemError("readlink failed", errno); return string(buf, len); @@ -111,27 +111,27 @@ Path realpath(const Path &path) list queue(path.begin(), path.end()); if(!path.is_absolute()) { - Path cwd=getcwd(); + Path cwd = getcwd(); queue.insert(queue.begin(), cwd.begin(), cwd.end()); } Path real; - unsigned n_links=0; + unsigned n_links = 0; while(!queue.empty()) { - Path next=real/queue.front(); + Path next = real/queue.front(); queue.pop_front(); - struct stat st=lstat(next); + struct stat st = lstat(next); if(S_ISLNK(st.st_mode)) { if(++n_links>64) throw Exception("Ludicrous amount of symlinks detected in realpath, giving up"); - Path link=readlink(next); + Path link = readlink(next); queue.insert(queue.begin(), link.begin(), link.end()); } else - real=next; + real = next; } return real; @@ -152,23 +152,23 @@ void unlink(const Path &path) Path relative(const Path &path, const Path &base) { - Path::Iterator i=path.begin(); - Path::Iterator j=base.begin(); + Path::Iterator i = path.begin(); + Path::Iterator j = base.begin(); for(; (i!=path.end() && j!=base.end() && *i==*j); ++i, ++j) ; Path result; for(; j!=base.end(); ++j) - result/=".."; + result /= ".."; for(; i!=path.end(); ++i) - result/=*i; + result /= *i; return result; } int descendant_depth(const Path &path, const Path &parent) { - Path::Iterator i=path.begin(); - Path::Iterator j=parent.begin(); + Path::Iterator i = path.begin(); + Path::Iterator j = parent.begin(); for(; (i!=path.end() && j!=parent.end() && *i==*j); ++i, ++j) ; if(j!=parent.end())