]> git.tdb.fi Git - libs/core.git/commitdiff
Style update: spaces around assignments
authorMikko Rasa <tdb@tdb.fi>
Wed, 27 Jul 2011 05:42:32 +0000 (08:42 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 27 Jul 2011 05:42:32 +0000 (08:42 +0300)
source/dir.cpp
source/path.cpp
source/path.h
source/utils.cpp

index 111378fa0e0e0a7dcc9f808aba659b3036e8eca9..ad2e013085024fbbcfaf54d3cf154f0a256711a2 100644 (file)
@@ -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<string> dirs=split(path, ':');
+                       const char *path = getenv("PATH");
+                       vector<string> dirs = split(path, ':');
                        for(vector<string>::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<string> files=list_files(path);
+       list<string> files = list_files(path);
        for(list<string>::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<string> list_filtered(const Path &path, const string &filter)
        Regex r_filter(filter);
 
        list<string> 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;
index d8a2c71e830f08052d9b45573546ba241a4c4df9..e514d36bfe490f5a4349f9a46946847221caa5f5 100644 (file)
@@ -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; (j<start && i!=end()); ++j)
                ++i;
        for(unsigned j=0; (j<count && i!=end()); ++j)
        {
-               result/=*i;
+               result /= *i;
                ++i;
        }
        return result;
@@ -75,8 +75,8 @@ Path Path::subpath(unsigned start, unsigned count) const
 
 Path Path::operator/(const Path &p) const
 {
-       Path a=*this;
-       a/=p;
+       Path a = *this;
+       a /= p;
        return a;
 }
 
@@ -88,7 +88,7 @@ are ignored.
 Path &Path::operator/=(const Path &p)
 {
        if(p.is_absolute())
-               path=p.path;
+               path = p.path;
        else
        {
                for(Iterator i=p.begin(); i!=p.end(); ++i)
@@ -135,23 +135,23 @@ Path::Iterator Path::begin() const
 Path::Iterator Path::end() const
 {
        Iterator i(*this);
-       i.start=i.end=std::string::npos;
+       i.start=i.end = std::string::npos;
        return i;
 }
 
 void Path::init(const string &p)
 {
-       string::size_type start=0;
+       string::size_type start = 0;
        if(p[0]=='/' || p[0]=='\\')
                add_component(string(1, DIRSEP));
        while(1)
        {
-               string::size_type slash=p.find_first_of("/\\", start);
+               string::size_type slash = p.find_first_of("/\\", start);
                if(slash>start)
                        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<path.path.size() && path.path[end]!=DIRSEP)
                --end;
 
-       start=path.path.rfind(DIRSEP, end-1);
+       start = path.path.rfind(DIRSEP, end-1);
        if(start==string::npos)
-               start=0;
+               start = 0;
        else if(start<end-1)
                ++start;
 
index 0b946fdcdb18bb00ab79ffe189249946fc5bc8be..e560d3f96c4b3e1ae5b718f5d4a724e4fc8a57c2 100644 (file)
@@ -17,9 +17,9 @@ namespace FS {
 enum
 {
 #ifdef WIN32
-       DIRSEP='\\'
+       DIRSEP = '\\'
 #else
-       DIRSEP='/'
+       DIRSEP = '/'
 #endif
 };
 
@@ -67,7 +67,7 @@ public:
        bool is_absolute() const;
 
        /// Extracts a range of components from the path.
-       Path subpath(unsigned start, unsigned count=static_cast<unsigned>(-1)) const;
+       Path subpath(unsigned start, unsigned count = static_cast<unsigned>(-1)) const;
 
        /// Concatenates this path with another one, with usual filesystem semantics
        Path operator/(const Path &p) const;
index 4036225a0f2af593584931d1205fe64aeab82199..694a8f12a6c6c67b4f77dd89e0e9a8168d1fcf1e 100644 (file)
@@ -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<string> 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<string>::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<string> 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())