Fresco/Prague/src/Sys DLL.cc,1.11,1.12 DataTypeManager.cc,1.9,1.10 Directory.cc,1.6,1.7 Env.cc,1.10,1.11 File.cc,1.6,1.7 Fork.cc,1.7,1.8 GetOpt.cc,1.11,1.12 MMap.cc,1.11,1.12 Path.cc,1.8,1.9 Profiler.cc,1.10,1.11 SHM.cc,1.4,1.5 Signal.cc,1.10,1.11 Stopwatch.cc,1.8,1.9 Thread.cc,1.14,1.15 Time.cc,1.4,1.5 Timer.cc,1.11,1.12 Tracer.cc,1.4,1.5 User.cc,1.5,1.6 logbuf.cc,1.4,1.5 regex.cc,1.5,1.6
Tobias Hunger <[email protected]> Fri, 31 Oct 2003 22:33:18 +0000
| Newsgroups | gmane.comp.video.fresco.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvs/fresco/Fresco/Prague/src/Sys In directory purcel:/tmp/cvs-serv28781/Prague/src/Sys Modified Files: DLL.cc DataTypeManager.cc Directory.cc Env.cc File.cc Fork.cc GetOpt.cc MMap.cc Path.cc Profiler.cc SHM.cc Signal.cc Stopwatch.cc Thread.cc Time.cc Timer.cc Tracer.cc User.cc logbuf.cc regex.cc Log Message: Fix up indention according to the coding style guide. Index: DLL.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/Sys/DLL.cc,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- DLL.cc 8 May 2003 04:11:33 -0000 1.11 +++ DLL.cc 31 Oct 2003 22:33:13 -0000 1.12 @@ -1,7 +1,7 @@ /*$Id$ * * This source file is a part of the Fresco Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * Copyright (C) 1999 Stefan Seefeld <[email protected]> * http://www.fresco.org * * This library is free software; you can redistribute it and/or @@ -30,62 +30,63 @@ using namespace Prague; -DLL::DLL(const std::string &name, bool now) throw(std::runtime_error, std::logic_error) - : my_name(name) +DLL::DLL(const std::string &name, bool now) throw(std::runtime_error, std::logic_error) : my_name(name) { - if (!my_name.empty()) + if (!my_name.empty()) { #if defined(HAVE_DLOPEN) - int flags = now ? RTLD_NOW : RTLD_LAZY; - flags |= RTLD_GLOBAL; - my_handle = dlopen(my_name.c_str(), flags); - if (!my_handle) - { - std::string message = "Failed to load " + my_name + ": " + dlerror(); - throw std::runtime_error(message); - } + int flags = now ? RTLD_NOW : RTLD_LAZY; + flags |= RTLD_GLOBAL; + my_handle = dlopen(my_name.c_str(), flags); + if (!my_handle) + { + std::string message = "Failed to load " + my_name + ": " + dlerror(); + throw std::runtime_error(message); + } #elif defined(HAVE_SHL_LOAD) - shl_t shl_handle = shl_load(my_name.c_str(), (now ? BIND_DEFERRED : BIND_IMMEDIATE) | BIND_NONFATAL | BIND_VERBOSE, 0); - if (!shl_handle) - { - std::string message = "Failed to load " + my_name + ": " + strerror(errno); - throw std::runtime_error(message); - } - else my_handle = shl_handle; + shl_t shl_handle = shl_load(my_name.c_str(), + (now ? BIND_DEFERRED : BIND_IMMEDIATE) | BIND_NONFATAL | BIND_VERBOSE, 0); + if (!shl_handle) + { + std::string message = "Failed to load " + my_name + ": " + strerror(errno); + throw std::runtime_error(message); + } + else my_handle = shl_handle; #endif } - else throw std::logic_error("empty filename"); + else throw std::logic_error("empty filename"); } DLL::~DLL() throw() { #if defined(HAVE_DLCLOSE) - dlclose(my_handle); + dlclose(my_handle); #elif defined(HAVE_SHL_UNLOAD) - shl_unload (reinterpret_cast<shl_t>(my_handle)); + shl_unload (reinterpret_cast<shl_t>(my_handle)); #endif } void *DLL::resolve(const std::string &symbol) throw(std::runtime_error) { #if defined(HAVE_DLSYM) - void *tmp = dlsym(my_handle, symbol.c_str()); - if (!tmp) - { - std::string message = "Failed to resolve \"" + symbol + - "\" in loaded file \"" + my_name + - "\": " + dlerror(); - throw std::runtime_error(message); - } + void *tmp = dlsym(my_handle, symbol.c_str()); + if (!tmp) + { + std::string message = "Failed to resolve \"" + symbol + + "\" in loaded file \"" + my_name + + "\": " + dlerror(); + throw std::runtime_error(message); + } #elif defined(HAVE_SHL_FINDSYM) - void *tmp; - if (shl_findsym(reinterpret_cast<shl_t *>(&my_handle), symbol.c_str(), TYPE_UNDEFINED, &tmp) != 0 || my_handle == 0 || tmp == 0) - { - std:string message = "Failed to resolve \"" + symbol + - "\" in loaded file \"" + my_name + - "\": " + strerror(errno); - throw std::runtime_error(message); - } + void *tmp; + if (shl_findsym(reinterpret_cast<shl_t *>(&my_handle), symbol.c_str(), TYPE_UNDEFINED, &tmp) != 0 || + my_handle == 0 || tmp == 0) + { + std:string message = "Failed to resolve \"" + symbol + + "\" in loaded file \"" + my_name + + "\": " + strerror(errno); + throw std::runtime_error(message); + } #endif - return tmp; + return tmp; }; Index: DataTypeManager.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/Sys/DataTypeManager.cc,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- DataTypeManager.cc 2 Jun 2002 23:42:24 -0000 1.9 +++ DataTypeManager.cc 31 Oct 2003 22:33:13 -0000 1.10 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -32,268 +32,260 @@ void stripcomment(std::string &line) { - bool quote = false; - for (std::string::iterator i = line.begin(); i != line.end(); i++) + bool quote = false; + for (std::string::iterator i = line.begin(); i != line.end(); i++) { - if (*i == '\'') quote = !quote; - else if (!quote && *i == '#') - { - line.erase(i, line.end()); - return; - } + if (*i == '\'') quote = !quote; + else if (!quote && *i == '#') + { + line.erase(i, line.end()); + return; + } } } std::vector<unsigned char> getbytes(std::istream &is, unsigned short n) { - std::vector<unsigned char> bytes; - unsigned short i = 0; - do + std::vector<unsigned char> bytes; + unsigned short i = 0; + do { - std::string token; - while (isspace(is.peek())) is.ignore(); - /* - * if it's a string, read all what is between the quote marks - */ - if (is.peek() == '\'') - { - is.ignore(); - getline(is, token, '\''); - bytes.insert(bytes.end(), token.begin(), token.end()); - i += token.length(); - } - /* - * else if it's a byte, read all till the next white space - */ - else - { - int value; - is >> token; - sscanf(token.c_str(), "%i", &value); - bytes.push_back(value); - i++; - } + std::string token; + while (isspace(is.peek())) is.ignore(); + // if it's a string, read all what is between the quote marks + if (is.peek() == '\'') + { + is.ignore(); + getline(is, token, '\''); + bytes.insert(bytes.end(), token.begin(), token.end()); + i += token.length(); + } + // else if it's a byte, read all till the next white space + else + { + int value; + is >> token; + sscanf(token.c_str(), "%i", &value); + bytes.push_back(value); + i++; + } } - while (i < n); - return bytes.size() == n ? bytes : std::vector<unsigned char>(); + while (i < n); + return bytes.size() == n ? bytes : std::vector<unsigned char>(); } std::string::const_iterator DataTypeManager::Type::Name::parse(std::string::const_iterator begin, std::string::const_iterator end) { - std::istringstream iss(std::string(begin, end)); - iss >> score; - iss.ignore(end - begin, '\''); - std::string tmp; - getline(iss, tmp, '\''); - name = tmp; - return iss && tmp.length() ? end : begin; + std::istringstream iss(std::string(begin, end)); + iss >> score; + iss.ignore(end - begin, '\''); + std::string tmp; + getline(iss, tmp, '\''); + name = tmp; + return iss && tmp.length() ? end : begin; } std::string::const_iterator DataTypeManager::Type::Magic::Part::parse(std::string::const_iterator begin, std::string::const_iterator end) { - std::istringstream iss(std::string(begin, end)); - iss >> offset; - iss.ignore(end - begin, '['); - iss >> length; - iss.ignore(end - begin, ']'); - if (!iss || length > 4096) return begin; - data.resize(length); - mask.resize(length, 0xff); - std::string token; - iss >> token; - if (token == "&") + std::istringstream iss(std::string(begin, end)); + iss >> offset; + iss.ignore(end - begin, '['); + iss >> length; + iss.ignore(end - begin, ']'); + if (!iss || length > 4096) return begin; + data.resize(length); + mask.resize(length, 0xff); + std::string token; + iss >> token; + if (token == "&") { - mask = getbytes(iss, length); - iss >> token; + mask = getbytes(iss, length); + iss >> token; } - bool approx = false; - if (token == "~=") approx = true; - if (!approx && token != "==") return begin; - data = getbytes(iss, length); - return iss ? end : begin; + bool approx = false; + if (token == "~=") approx = true; + if (!approx && token != "==") return begin; + data = getbytes(iss, length); + return iss ? end : begin; } std::string::const_iterator DataTypeManager::Type::Magic::parse(std::string::const_iterator begin, std::string::const_iterator end) { - std::string::const_iterator i = begin; - while (isspace(*i)) i++; - std::istringstream iss(std::string(i, end)); - iss >> score; - while (!isspace(*i)) i++; - while (1) + std::string::const_iterator i = begin; + while (isspace(*i)) ++i; + std::istringstream iss(std::string(i, end)); + iss >> score; + while (!isspace(*i)) ++i; + while (1) { - Part part; - std::string::const_iterator j = part.parse(i, end); - if (i == j) return begin; - begin = i = j; - parts.push_back(part); + Part part; + std::string::const_iterator j = part.parse(i, end); + if (i == j) return begin; + begin = i = j; + parts.push_back(part); } - return begin; + return begin; } bool DataTypeManager::Type::parse(const std::string &line) { - if (line.substr(0, 5) == "type:") + if (line.substr(0, 5) == "type:") { - std::istringstream iss(line.substr(6)); - iss >> type; + std::istringstream iss(line.substr(6)); + iss >> type; } - else if (line.substr(0, 5) == "mime:") + else if (line.substr(0, 5) == "mime:") { - std::istringstream iss(line.substr(6)); - iss >> mime; + std::istringstream iss(line.substr(6)); + iss >> mime; } - else if (line.substr(0, 5) == "name:") + else if (line.substr(0, 5) == "name:") { - Name name; - if (name.parse(line.begin() + 5, line.end()) != line.begin() + 5) - names.push_back(name); - else return false; + Name name; + if (name.parse(line.begin() + 5, line.end()) != line.begin() + 5) + names.push_back(name); + else return false; } - else if (line.substr(0, 6) == "magic:") + else if (line.substr(0, 6) == "magic:") { - Magic magic; - if (magic.parse(line.begin() + 6, line.end()) != line.begin() + 6) - magics.push_back(magic); - else return false; + Magic magic; + if (magic.parse(line.begin() + 6, line.end()) != line.begin() + 6) + magics.push_back(magic); + else return false; } - else return false; - return true; + else return false; + return true; } void DataTypeManager::merge(const std::string &file) { - std::ifstream ifs(file.c_str()); - unsigned int lineno = 0; - Type *type = 0; - while (ifs && ++lineno) + std::ifstream ifs(file.c_str()); + unsigned int lineno = 0; + Type *type = 0; + while (ifs && ++lineno) { - std::string line; - std::getline(ifs, line); - stripcomment(line); - if (line.empty()) continue; - if (line.substr(0, 5) == "type:") - { - if (type) { _types.push_back(*type); delete type;} - type = new Type; - } - if (!type || !type->parse(line)) - std::cerr << "DataTypeManager::merge: error in line " << lineno << " of file " << file << std::endl; + std::string line; + std::getline(ifs, line); + stripcomment(line); + if (line.empty()) continue; + if (line.substr(0, 5) == "type:") + { + if (type) { _types.push_back(*type); delete type;} + type = new Type; + } + if (!type || !type->parse(line)) + std::cerr << "DataTypeManager::merge: error in line " << lineno << " of file " << file << std::endl; } - if (type) { _types.push_back(*type); delete type;} + if (type) { _types.push_back(*type); delete type;} } short DataTypeManager::compare(unsigned short name1, unsigned short magic1, unsigned short name2, unsigned short magic2) { /* - * Returns: - * 1 if type1 > type2, + * Returns: + * 1 if type1 > type2, * -1 if type1 < type2, - * 0 if type1 = type2. (conflict) + * 0 if type1 = type2. (conflict) */ - if ((magic1 > magic2 && name1 >= name2) || (name1 > name2 && magic1 >= magic2)) return 1; - if ((magic2 > magic1 && name2 >= name1) || (name2 > name1 && magic2 >= magic1)) return -1; - - if (std::max(name1, magic1) > std::max(name2, magic2)) return 1; - if (std::max(name2, magic2) > std::max(name1, magic1)) return -1; - - if (std::min(name1, magic1) > std::min(name2, magic2)) return 1; - if (std::min(name2, magic2) > std::min(name1, magic1)) return -1; - - if (magic1 > magic2) return 1; - if (magic2 > magic1) return -1; - - return 0; + if ((magic1 > magic2 && name1 >= name2) || (name1 > name2 && magic1 >= magic2)) return 1; + if ((magic2 > magic1 && name2 >= name1) || (name2 > name1 && magic2 >= magic1)) return -1; + + if (std::max(name1, magic1) > std::max(name2, magic2)) return 1; + if (std::max(name2, magic2) > std::max(name1, magic1)) return -1; + + if (std::min(name1, magic1) > std::min(name2, magic2)) return 1; + if (std::min(name2, magic2) > std::min(name1, magic1)) return -1; + + if (magic1 > magic2) return 1; + if (magic2 > magic1) return -1; + + return 0; } unsigned short DataTypeManager::Type::Name::match(const std::string &file) -{ - return name.match(file) > 0 ? score : 0; -} +{ return name.match(file) > 0 ? score : 0; } unsigned short DataTypeManager::Type::match_name(const std::string &file) { - unsigned short best = 0; - for (std::vector<Name>::iterator i = names.begin(); i != names.end(); i++) - { - best = std::max(best, (*i).match(file)); - } - return best; + unsigned short best = 0; + for (std::vector<Name>::iterator i = names.begin(); i != names.end(); i++) + best = std::max(best, (*i).match(file)); + return best; } bool DataTypeManager::Type::Magic::Part::match(const unsigned char *d, int l) { - if (offset + length > l) return false; - for (unsigned short i = 0, o = offset; i != length; i++, o++) - if ((d[o] & mask[i]) != data[i]) return false; - return true; + if (offset + length > l) return false; + for (unsigned short i = 0, o = offset; i != length; i++, o++) + if ((d[o] & mask[i]) != data[i]) return false; + return true; } unsigned short DataTypeManager::Type::Magic::match(const unsigned char *data, int length) { - for (std::vector<Part>::iterator i = parts.begin(); i != parts.end(); i++) - if (!(*i).match(data, length)) return 0; - return score; + for (std::vector<Part>::iterator i = parts.begin(); i != parts.end(); i++) + if (!(*i).match(data, length)) return 0; + return score; } unsigned short DataTypeManager::Type::match_magic(const unsigned char *data, int length) { - unsigned short best = 0; - for (std::vector<Magic>::iterator i = magics.begin(); i != magics.end(); i++) - best = std::max(best, (*i).match(data, length)); - return best; + unsigned short best = 0; + for (std::vector<Magic>::iterator i = magics.begin(); i != magics.end(); i++) + best = std::max(best, (*i).match(data, length)); + return best; } std::string DataTypeManager::match(const std::string &file, const unsigned char *data, unsigned int length) { - std::vector<Type>::iterator best = _types.end(); - unsigned short bestName = 0; - unsigned short bestMagic = 0; - for (std::vector<Type>::iterator i = _types.begin(); i != _types.end(); i++) + std::vector<Type>::iterator best = _types.end(); + unsigned short bestName = 0; + unsigned short bestMagic = 0; + for (std::vector<Type>::iterator i = _types.begin(); i != _types.end(); i++) { - unsigned short name = 0; - unsigned short magic = 0; - if (file.length()) name = (*i).match_name(file); - if (data && length) magic = (*i).match_magic(data, length); - if (name == 0 && magic == 0) continue; - if (best == _types.end()) - { - best = i; - bestName = name; - bestMagic = magic; - continue; - } - if (compare(bestName, bestMagic, name, magic) < 0) - { - best = i; - bestName = name; - bestMagic = magic; - continue; - } + unsigned short name = 0; + unsigned short magic = 0; + if (file.length()) name = (*i).match_name(file); + if (data && length) magic = (*i).match_magic(data, length); + if (name == 0 && magic == 0) continue; + if (best == _types.end()) + { + best = i; + bestName = name; + bestMagic = magic; + continue; + } + if (compare(bestName, bestMagic, name, magic) < 0) + { + best = i; + bestName = name; + bestMagic = magic; + continue; + } } - if (best == _types.end()) return "binary"; - else return (*best).type; + if (best == _types.end()) return "binary"; + else return (*best).type; } std::string DataTypeManager::match(const std::string &file) { - std::ifstream ifs(file.c_str()); - std::string name = File::base(file); - char unsigned data[4096]; - ifs.read(reinterpret_cast<char *>(data), 4096); - return match(name, data, ifs.gcount()); + std::ifstream ifs(file.c_str()); + std::string name = File::base(file); + char unsigned data[4096]; + ifs.read(reinterpret_cast<char *>(data), 4096); + return match(name, data, ifs.gcount()); } std::string DataTypeManager::type_to_mime(const std::string &type) { - for (std::vector<Type>::iterator i = _types.begin(); i != _types.end(); i++) - if ((*i).type == type) return (*i).mime; - return std::string(); + for (std::vector<Type>::iterator i = _types.begin(); i != _types.end(); i++) + if ((*i).type == type) return (*i).mime; + return std::string(); } std::string DataTypeManager::mime_to_type(const std::string &mime) { - for (std::vector<Type>::iterator i = _types.begin(); i != _types.end(); i++) - if ((*i).mime == mime) return (*i).type; - return std::string(); + for (std::vector<Type>::iterator i = _types.begin(); i != _types.end(); i++) + if ((*i).mime == mime) return (*i).type; + return std::string(); } Index: Directory.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/Sys/Directory.cc,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Directory.cc 21 Mar 2001 06:28:55 -0000 1.6 +++ Directory.cc 31 Oct 2003 22:33:13 -0000 1.7 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -26,94 +26,119 @@ using namespace Prague; -bool compSize(File *a, File *b) { return (a->size() > b->size());} -bool compAccTime(File *a, File *b) { return a->acc_time() < b->acc_time();} -bool compModTime(File *a, File *b) { return a->mod_time() < b->mod_time();} -bool compAlpha(File *a, File *b) { return a->name() < b->name();} +bool compSize(File *a, File *b) { return (a->size() > b->size()); } +bool compAccTime(File *a, File *b) { return a->acc_time() < b->acc_time(); } +bool compModTime(File *a, File *b) { return a->mod_time() < b->mod_time(); } +bool compAlpha(File *a, File *b) { return a->name() < b->name(); } bool compDirsFirst(File *a, File *b) { - if (a->is(File::dir) && !b->is(File::dir)) return true; - else if (!a->is(File::dir) && b->is(File::dir)) return false; - else return compAlpha(a, b); -}; + if (a->is(File::dir) && !b->is(File::dir)) return true; + else if (!a->is(File::dir) && b->is(File::dir)) return false; + else return compAlpha(a, b); +} -Directory::Directory(const std::string &n, int order, int filter) - : File(n) +Directory::Directory(const std::string &n, int order, int filter) : File(n) { - while (_longname.length() > 2 && _longname[_longname.length() - 1] == '.' && _longname[_longname.length() - 2] == '.') + while (_longname.length() > 2 && + _longname[_longname.length() - 1] == '.' && + _longname[_longname.length() - 2] == '.') { - std::string::size_type i = _longname.rfind('/', _longname.length() - 3); - _longname.erase(i, _longname.length()); + std::string::size_type i = _longname.rfind('/', _longname.length() - 3); + _longname.erase(i, _longname.length()); } - _shortname = File::base(_longname); - if (get_status() && is(File::dir)) + _shortname = File::base(_longname); + if (get_status() && is(File::dir)) { - DIR *dir = opendir(_longname.c_str()); - for (struct dirent *entry = readdir(dir); entry; entry = readdir(dir)) - { - std::string childname = _longname + '/' + entry->d_name; - if (filter == unfiltered || - filter == nohidden && entry->d_name[0] != '.' || - filter == dirs && File(childname).is(File::dir) || - filter == nodirs && !File(childname).is(File::dir)) - _children.push_back(new File(childname)); - } - closedir(dir); - switch (order) - { - case dirsfirst: sort(_children.begin(), _children.end(), compDirsFirst); break; - case size: sort(_children.begin(), _children.end(), compSize); break; - case modtime: sort(_children.begin(), _children.end(), compModTime); break; - case acctime: sort(_children.begin(), _children.end(), compAccTime); break; - case alpha: - default: sort(_children.begin(), _children.end(), compAlpha); break; - } + DIR *dir = opendir(_longname.c_str()); + for (struct dirent *entry = readdir(dir); entry; entry = readdir(dir)) + { + std::string childname = _longname + '/' + entry->d_name; + if (filter == unfiltered || + filter == nohidden && entry->d_name[0] != '.' || + filter == dirs && File(childname).is(File::dir) || + filter == nodirs && !File(childname).is(File::dir)) + _children.push_back(new File(childname)); + } + closedir(dir); + switch (order) + { + case dirsfirst: + sort(_children.begin(), _children.end(), compDirsFirst); + break; + case size: + sort(_children.begin(), _children.end(), compSize); + break; + case modtime: + sort(_children.begin(), _children.end(), compModTime); + break; + case acctime: + sort(_children.begin(), _children.end(), compAccTime); + break; + case alpha: + default: + sort(_children.begin(), _children.end(), compAlpha); + break; + } } } -Directory::Directory(const std::string &n, int order, const std::string &pattern) - : File(n) +Directory::Directory(const std::string &n, int order, const std::string &pattern) : File(n) { - while (_longname.length() > 2 && _longname[_longname.length() - 1] == '.' && _longname[_longname.length() - 2] == '.') + while (_longname.length() > 2 && + _longname[_longname.length() - 1] == '.' && + _longname[_longname.length() - 2] == '.') { - std::string::size_type i = _longname.rfind('/', _longname.length() - 3); - _longname.erase(i, _longname.length()); + std::string::size_type i = _longname.rfind('/', _longname.length() - 3); + _longname.erase(i, _longname.length()); } - _shortname = File::base(n); - if (get_status() && is(File::dir)) + _shortname = File::base(n); + if (get_status() && is(File::dir)) { - regex filter(pattern); - DIR *dir = opendir(_longname.c_str()); - for (struct dirent *entry = readdir(dir); entry; entry = readdir(dir)) - { - if (filter.search(entry->d_name)) - { - std::string childname = _longname + '/' + entry->d_name; - _children.push_back(new File(childname)); - } - } - closedir(dir); - switch (order) - { - case dirsfirst: sort(_children.begin(), _children.end(), compDirsFirst); break; - case size: sort(_children.begin(), _children.end(), compSize); break; - case modtime: sort(_children.begin(), _children.end(), compModTime); break; - case acctime: sort(_children.begin(), _children.end(), compAccTime); break; - case alpha: - default: sort(_children.begin(), _children.end(), compAlpha); break; - } + regex filter(pattern); + DIR *dir = opendir(_longname.c_str()); + for (struct dirent *entry = readdir(dir); entry; entry = readdir(dir)) + { + if (filter.search(entry->d_name)) + { + std::string childname = _longname + '/' + entry->d_name; + _children.push_back(new File(childname)); + } + } + closedir(dir); + switch (order) + { + case dirsfirst: + sort(_children.begin(), _children.end(), compDirsFirst); + break; + case size: + sort(_children.begin(), _children.end(), compSize); + break; + case modtime: + sort(_children.begin(), _children.end(), compModTime); + break; + case acctime: + sort(_children.begin(), _children.end(), compAccTime); + break; + case alpha: + default: + sort(_children.begin(), _children.end(), compAlpha); + break; + } } } -Directory::Directory(const Directory &dir) - : File(dir) +Directory::Directory(const Directory &dir) : File(dir) { - for (std::vector<File *>::const_iterator i = dir._children.begin(); i != dir._children.end(); i++) - _children.push_back(new File((*i)->name())); + for (std::vector<File *>::const_iterator i = dir._children.begin(); + i != dir._children.end(); + ++i) + _children.push_back(new File((*i)->name())); } Directory::~Directory() { - for (std::vector<File *>::iterator i = _children.begin(); i != _children.end(); i++) delete *i; + for (std::vector<File *>::iterator i = _children.begin(); + i != _children.end(); + ++i) + delete *i; } - Index: Env.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/Sys/Env.cc,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- Env.cc 29 Nov 2002 20:36:26 -0000 1.10 +++ Env.cc 31 Oct 2003 22:33:13 -0000 1.11 @@ -1,7 +1,7 @@ /* * - * This source file is a part of the Berlin Project. - * Copyright (C) 2002 Tobias Hunger <[email protected]> + * This source file is a part of the Fresco Project. + * Copyright (C) 2002 Tobias Hunger <[email protected]> * http://www.fresco.org * * This library is free software; you can redistribute it and/or @@ -28,63 +28,66 @@ #ifdef HAVE_PUTENV #include <map> -namespace Prague { - namespace Environment { +namespace Prague +{ + namespace Environment + { std::map<std::string, char *> my_vars; - }; -}; + } // namespace +} // namespace #endif #endif bool Prague::putenv(const std::string & name, const std::string & value) { #ifdef HAVE_SETENV - return setenv(name.c_str(), value.c_str(), 1) == 0; + return setenv(name.c_str(), value.c_str(), 1) == 0; #elif HAVE_PUTENV - char * env_var = new char[name.length() + value.length() + 2]; - strncpy(env_var, name.c_str(), name.length()); - env_var[name.length()] = '='; - strncpy((env_var + name.length() + 1), value.c_str(), value.length()); - env_var[name.length() + value.length() + 1] = '\0'; // make sure there's a \0 - if (::putenv(env_var) == 0) - { - Environment::my_vars[name] = env_var; - return true; - } + char * env_var = new char[name.length() + value.length() + 2]; + strncpy(env_var, name.c_str(), name.length()); + env_var[name.length()] = '='; + strncpy((env_var + name.length() + 1), value.c_str(), value.length()); + env_var[name.length() + value.length() + 1] = '\0'; // make sure there's a \0 + if (::putenv(env_var) == 0) + { + Environment::my_vars[name] = env_var; + return true; + } #else - std::cerr << "ERROR: Prague::putenv misconfiguration!" << std::endl; - exit(1); + std::cerr << "ERROR: Prague::putenv misconfiguration!" << std::endl; + exit(1); #endif - return false; + return false; } bool Prague::putenv(const std::string & name) { #ifdef HAVE_UNSETENV - unsetenv(name.c_str()); - return true; + unsetenv(name.c_str()); + return true; #elif HAVE_PUTENV - char * env_var = new char[name.length() + 1]; - strncpy(env_var, name.c_str(), name.length()); - env_var[name.length()] = '\0'; // make sure there's a \0 - if (::putenv(env_var) == 0) { - if (Environment::my_vars[name] != 0) - delete[] Environment::my_vars[name]; - Environment::my_vars.erase(name); // it was either there or - // just got created. - - return true; - } + char * env_var = new char[name.length() + 1]; + strncpy(env_var, name.c_str(), name.length()); + env_var[name.length()] = '\0'; // make sure there's a \0 + if (::putenv(env_var) == 0) + { + if (Environment::my_vars[name] != 0) + delete[] Environment::my_vars[name]; + Environment::my_vars.erase(name); // it was either there or + // just got created. + + return true; + } #else - std::cerr << "ERROR: Prague::putenv misconfiguration!" << std::endl; - exit(1); + std::cerr << "ERROR: Prague::putenv misconfiguration!" << std::endl; + exit(1); #endif - return false; + return false; } std::string Prague::getenv(const std::string & name) { - char const * const s = ::getenv(name.c_str()); - std::string const value((s!=0)?s:""); - return value; + char const * const s = ::getenv(name.c_str()); + std::string const value((s!=0)?s:""); + return value; } Index: File.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/Sys/File.cc,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- File.cc 21 Mar 2001 06:28:55 -0000 1.6 +++ File.cc 31 Oct 2003 22:33:13 -0000 1.7 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -27,84 +27,79 @@ using namespace Prague; -File::File(const std::string &n) - : _longname (n), - _shortname(File::base(n)), - _error(0) -{ - get_status(); -} +File::File(const std::string &n) : + _longname (n), + _shortname(File::base(n)), + _error(0) +{ get_status(); } -File::File(const File &f) - : _longname(f._longname), - _shortname(f._shortname), - _error(0) -{ - get_status(); -} +File::File(const File &f) : + _longname(f._longname), + _shortname(f._shortname), + _error(0) +{ get_status(); } -File::~File() {} +File::~File() { } File &File::operator = (const File &f) { - _longname = f._longname; - _shortname = f._longname; - get_status(); - return *this; + _longname = f._longname; + _shortname = f._longname; + get_status(); + return *this; } File &File::operator = (const std::string &n) { - _longname = n; - _shortname = File::base(n); - get_status(); - return *this; + _longname = n; + _shortname = File::base(n); + get_status(); + return *this; } File File::parent() const { - if (_shortname == "/") return *this; - return File(_longname.substr(0, _longname.find_last_of('/'))); + if (_shortname == "/") return *this; + return File(_longname.substr(0, _longname.find_last_of('/'))); } bool File::chmod(access_t a) { - if (::chmod(_longname.c_str(), a) == -1) _error = errno; - else if (!get_status()) return false; - else return true; - return false; + if (::chmod(_longname.c_str(), a) == -1) _error = errno; + else if (!get_status()) return false; + else return true; + return false; } bool File::mv(const std::string &name) { - if (rename(_longname.c_str(), name.c_str()) == -1) + if (rename(_longname.c_str(), name.c_str()) == -1) { - _error = errno; - return false; + _error = errno; + return false; } - else + else { - _longname = name; - _shortname = File::base(name); - return true; + _longname = name; + _shortname = File::base(name); + return true; } } bool File::rm() { - if (remove(_longname.c_str()) == -1) + if (remove(_longname.c_str()) == -1) { - _error = errno; - return false; + _error = errno; + return false; } - else + else { - _longname = ""; - _shortname = ""; - _status.st_mode = 0; - return true; + _longname = ""; + _shortname = ""; + _status.st_mode = 0; + return true; } } -const char *File::last_error() const { return strerror(_error);} - +const char *File::last_error() const { return strerror(_error); } \ No newline at end of file Index: Fork.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/Sys/Fork.cc,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Fork.cc 21 Mar 2001 06:28:55 -0000 1.7 +++ Fork.cc 31 Oct 2003 22:33:13 -0000 1.8 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * this file is based on code from the socket++ library * Copyright (C) 1992-1996 Gnanasekaran Swaminathan <[email protected]> @@ -34,26 +34,26 @@ struct Fork::Process { - struct Cleaner { ~Cleaner ();}; - struct Reaper : Signal::Notifier { virtual void notify(int);}; - struct Suicide : Signal::Notifier { virtual void notify(int);}; - friend struct Cleaner; - - static void infanticide_reason(pid_t, int); - static Cleaner cleaner; - static Reaper reaper; - static Suicide suicide; - static Process *children; - pid_t pid; - const bool killflag : 1; - const bool reason : 1; - Process *next; - - Process(bool, bool); - ~Process(); - - void kill() const; - void reap_child () const; + struct Cleaner { ~Cleaner (); }; + struct Reaper : Signal::Notifier { virtual void notify(int); }; + struct Suicide : Signal::Notifier { virtual void notify(int); }; + friend struct Cleaner; + + static void infanticide_reason(pid_t, int); + static Cleaner cleaner; + static Reaper reaper; + static Suicide suicide; + static Process *children; + pid_t pid; + const bool killflag : 1; + const bool reason : 1; + Process *next; + + Process(bool, bool); + ~Process(); + + void kill() const; + void reap_child () const; }; Fork::Process *Fork::Process::children = 0; @@ -65,131 +65,129 @@ // First, kill all children whose kill_child flag is set. // Second, wait for other children to die. { - for (Process *p = Fork::Process::children; p; p = p->next) - if (p->killflag) delete p; - while (Fork::Process::children && wait (0) > 0); + for (Process *p = Fork::Process::children; p; p = p->next) + if (p->killflag) delete p; + while (Fork::Process::children && wait (0) > 0) ; } -Fork::Process::Process (bool k, bool r) - : killflag(k), reason(r), next(0) +Fork::Process::Process (bool k, bool r) : killflag(k), reason(r), next(0) { - if (children == 0) Signal::set(Signal::child, &reaper); - pid = fork(); - if (pid > 0) + if (children == 0) Signal::set(Signal::child, &reaper); + pid = fork(); + if (pid > 0) { - next = children; - children = this; + next = children; + children = this; } - else if (pid == 0) + else if (pid == 0) { - Process *p = children; - while (p) - { - Process *n = p->next; - p->pid = 0; - delete p; - p = n; - } - children = 0; - if (killflag) Signal::set(Signal::kill, &suicide); + Process *p = children; + while (p) + { + Process *n = p->next; + p->pid = 0; + delete p; + p = n; + } + children = 0; + if (killflag) Signal::set(Signal::kill, &suicide); } } Fork::Process::~Process() { - if (pid > 0) + if (pid > 0) { - if (killflag) ::kill (pid, Signal::terminate); - reap_child(); - if (children == this) children = children->next; - else - { - for (Process *p = children; p; p = p->next) - if (p->next == this) - { - p->next = next; - break; - } - } + if (killflag) ::kill (pid, Signal::terminate); + reap_child(); + if (children == this) children = children->next; + else + { + for (Process *p = children; p; p = p->next) + if (p->next == this) + { + p->next = next; + break; + } + } } } void Fork::Process::kill() const { - if (pid > 0) + if (pid > 0) { - ::kill(pid, Signal::kill); - reap_child(); + ::kill(pid, Signal::kill); + reap_child(); } } void Fork::Process::reap_child () const { - int status; - if (pid > 0 && waitpid (pid, &status, 0) == pid && reason) - infanticide_reason (pid, status); + int status; + if (pid > 0 && waitpid (pid, &status, 0) == pid && reason) + infanticide_reason (pid, status); } void Fork::Process::infanticide_reason (pid_t pid, int status) { - if (pid <= 0) return; - if (WIFSTOPPED (status)) - std::cerr << "process " << pid << " gets " << strsignal(WSTOPSIG (status)) << std::endl; - else if (WIFEXITED (status)) - std::cerr << "process " << pid << " exited with status " << WEXITSTATUS (status) << std::endl; - else if (WIFSIGNALED (status)) - std::cerr << "process " << pid << " got " << strsignal(WTERMSIG (status)) << std::endl; + if (pid <= 0) return; + if (WIFSTOPPED (status)) + std::cerr << "process " << pid << " gets " << strsignal(WSTOPSIG (status)) << std::endl; + else if (WIFEXITED (status)) + std::cerr << "process " << pid << " exited with status " << WEXITSTATUS (status) << std::endl; + else if (WIFSIGNALED (status)) + std::cerr << "process " << pid << " got " << strsignal(WTERMSIG (status)) << std::endl; } void Fork::Process::Reaper::notify(int signo) { - if (signo != SIGCHLD) return; - int status; - pid_t wpid; - if ((wpid = waitpid (-1, &status, WNOHANG)) > 0) + if (signo != SIGCHLD) return; + int status; + pid_t wpid; + if ((wpid = waitpid (-1, &status, WNOHANG)) > 0) { - Process *prev = 0; - Process *cur = children; - while (cur) - { - if (cur->pid == wpid) - { - cur->pid = -1; - if (prev) prev->next = cur->next; - else children = children->next; - if (cur->reason) infanticide_reason (wpid, status); - delete cur; - break; - } - prev = cur; - cur = cur->next; - } + Process *prev = 0; + Process *cur = children; + while (cur) + { + if (cur->pid == wpid) + { + cur->pid = -1; + if (prev) prev->next = cur->next; + else children = children->next; + if (cur->reason) infanticide_reason (wpid, status); + delete cur; + break; + } + prev = cur; + cur = cur->next; + } } } void Fork::Process::Suicide::notify (int) { - // if this process has any children we kill them. - Process *p = children; - while (p) + // if this process has any children we kill them. + Process *p = children; + while (p) { - Process *next = p->next; - if (!p->killflag) // otherwise Process::~Process will take care - ::kill(p->pid, Signal::kill); - delete p; // Process::~Process will call reap_child (). - p = next; + Process *next = p->next; + if (!p->killflag) // otherwise Process::~Process will take care + ::kill(p->pid, Signal::kill); + delete p; // Process::~Process will call reap_child (). + p = next; } - exit (0x0f); + exit (0x0f); } -Fork::Fork (bool kill, bool reason) - : process (new Process (kill, reason)) {} -Fork::~Fork () { if (process->pid <= 0) delete process;} -bool Fork::child() const { return process->pid == 0;} -bool Fork::parent() const { return process->pid > 0;} -pid_t Fork::pid() const { return process->pid;} +Fork::Fork (bool kill, bool reason) : process (new Process (kill, reason)) { } +Fork::~Fork () { if (process->pid <= 0) delete process; } +bool Fork::child() const { return process->pid == 0; } +bool Fork::parent() const { return process->pid > 0; } +pid_t Fork::pid() const { return process->pid; } void Fork::suicide_on_signal (int signo) { - if (!Signal::set(signo, &Process::suicide)) - std::perror ("Fork: Cannot commit suicide with the specified signal"); + if (!Signal::set(signo, &Process::suicide)) + std::perror ("Fork: Cannot commit suicide with the specified signal"); } Index: GetOpt.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/Sys/GetOpt.cc,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- GetOpt.cc 31 Jan 2003 05:42:09 -0000 1.11 +++ GetOpt.cc 31 Oct 2003 22:33:13 -0000 1.12 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -25,135 +25,132 @@ using namespace Prague; -GetOpt::GetOpt(const char *program, const char *use) : p(program), u(use) {} -GetOpt::~GetOpt() {} +GetOpt::GetOpt(const char *program, const char *use) : p(program), u(use) { } +GetOpt::~GetOpt() { } void GetOpt::add(char o, const std::string &opt, type t, const std::string &desc) throw (DuplicateOption) { - table_t::const_iterator i = find(o); - if (i != table.end()) throw DuplicateOption(o); - table.push_back(cell(o, opt, t, desc)); + table_t::const_iterator i = find(o); + if (i != table.end()) throw DuplicateOption(o); + table.push_back(cell(o, opt, t, desc)); } bool GetOpt::is_set(char o) const throw (NoSuchOption) { - table_t::const_iterator i = find(o); - if (i == table.end()) throw NoSuchOption(o); - return (*i).set; + table_t::const_iterator i = find(o); + if (i == table.end()) throw NoSuchOption(o); + return (*i).set; } bool GetOpt::is_set(const std::string &option) const throw (NoSuchOption) { - table_t::const_iterator i = find(option); - if (i == table.end()) throw NoSuchOption(option); - return (*i).set; + table_t::const_iterator i = find(option); + if (i == table.end()) throw NoSuchOption(option); + return (*i).set; } bool GetOpt::get(char o, std::string *v) const throw (NoSuchOption) { - table_t::const_iterator i = find(o); - if (i == table.end()) throw NoSuchOption(); - if ((*i).value.length()) *v = (*i).value; - return (*i).set; + table_t::const_iterator i = find(o); + if (i == table.end()) throw NoSuchOption(); + if ((*i).value.length()) *v = (*i).value; + return (*i).set; } bool GetOpt::get(const std::string &option, std::string *v) const throw (NoSuchOption) { - table_t::const_iterator i = find(option); - if (i == table.end()) throw NoSuchOption(); - if ((*i).value.length()) *v = (*i).value; - return (*i).set; + table_t::const_iterator i = find(option); + if (i == table.end()) throw NoSuchOption(); + if ((*i).value.length()) *v = (*i).value; + return (*i).set; } int GetOpt::parse(int argc, char **argv) { - int unknown = 0; - int cursor = 0; - while (cursor < argc) - { - size_t consumed = 0; - if (argv[cursor][0] == '-') // option - if (argv[cursor][1] == '-') // long option - if (argv[cursor][2] == '\0') // premature end - return ++cursor; - else consumed = getlongopt(argc - cursor, argv + cursor); - else consumed = getopt(argc - cursor, argv + cursor); - if (consumed && cursor) - { - exchange(argv + cursor, consumed, argv + unknown); - unknown += consumed; - cursor += consumed; - } - else cursor += 1; - } - return unknown; + int unknown = 0; + int cursor = 0; + while (cursor < argc) + { + size_t consumed = 0; + if (argv[cursor][0] == '-') // option + if (argv[cursor][1] == '-') // long option + if (argv[cursor][2] == '\0') // premature end + return ++cursor; + else consumed = getlongopt(argc - cursor, argv + cursor); + else consumed = getopt(argc - cursor, argv + cursor); + if (consumed && cursor) + { + exchange(argv + cursor, consumed, argv + unknown); + unknown += consumed; + cursor += consumed; + } + else cursor += 1; + } + return unknown; } size_t GetOpt::getlongopt(int argc, char **argv) { - char *token = *argv + 2; - while (*token != '\0' && *token != '=') token++; - std::string name (*argv + 2, token - *argv - 2); - table_t::iterator i = find(name); - if (i == table.end()) return 0; - (*i).set = true; - if ((*i).t == novalue) return 1; - else if (*token == '=') (*i).value = token + 1; - else if ((*i).t == mandatory) std::cerr << p << ": option '--" << (*i).option << "' requires a value" << std::endl; - return 1; + char *token = *argv + 2; + while (*token != '\0' && *token != '=') token++; + std::string name (*argv + 2, token - *argv - 2); + table_t::iterator i = find(name); + if (i == table.end()) return 0; + (*i).set = true; + if ((*i).t == novalue) return 1; + else if (*token == '=') (*i).value = token + 1; + else if ((*i).t == mandatory) std::cerr << p << ": option '--" << (*i).option << "' requires a value" << std::endl; + return 1; } size_t GetOpt::getopt(int argc, char **argv) { - char *option = *argv + 1; - table_t::iterator i; - if (option[1] == '\0') + char *option = *argv + 1; + table_t::iterator i; + if (option[1] == '\0') { - i = find(*option); - if (i == table.end()) return 0; // not for us - - (*i).set = true; - if ((*i).t == novalue) - { - return 1; - } - // if there is another non-option, consume it - else if (argc > 1 && argv[1][0] != '-') - { - (*i).value = argv[1]; - return 2; - } - // no non-option but mandatory -> signal error - else if ((*i).t == mandatory) - { - std::cerr << p << ": option '-" << (*i).o << "' requires a value" << std::endl; - } - return 1; + i = find(*option); + if (i == table.end()) return 0; // not for us + + (*i).set = true; + if ((*i).t == novalue) + return 1; + + // if there is another non-option, consume it + else if (argc > 1 && argv[1][0] != '-') + { + (*i).value = argv[1]; + return 2; + } + // no non-option but mandatory -> signal error + else if ((*i).t == mandatory) + std::cerr << p << ": option '-" << (*i).o << "' requires a value" << std::endl; + return 1; } - return 0; + return 0; } void GetOpt::usage() const { - std::cout << "Usage: " << p << " " << u << "\n"; - for (table_t::const_iterator i = table.begin(); i != table.end(); i++) + std::cout << "Usage: " << p << " " << u << "\n"; + for (table_t::const_iterator i = table.begin(); i != table.end(); i++) { - std::cout << '\t'; - if ((*i).o && (*i).option.length()) std::cout << '-' << (*i).o << ", --" << (*i).option; - else if ((*i).o) std::cout << '-' << (*i).o << '\t'; - else if ((*i).option.length()) std::cout << ", --" << (*i).option; - if ((*i).t == mandatory) std::cout << " <value>"; - else if ((*i).t == optional) std::cout << " [value]"; - std::cout << " (" << (*i).description << ")\n"; + std::cout << '\t'; + if ((*i).o && (*i).option.length()) std::cout << '-' << (*i).o << ", --" << (*i).option; + else if ((*i).o) std::cout << '-' << (*i).o << '\t'; + else if ((*i).option.length()) std::cout << ", --" << (*i).option; + if ((*i).t == mandatory) std::cout << " <value>"; + else if ((*i).t == optional) std::cout << " [value]"; + std::cout << " (" << (*i).description << ")\n"; } - std::cout.flush(); + std::cout.flush(); } void GetOpt::exchange (char **a, size_t size, char **b) { - char **tmp = new char *[size]; - Memory::copy (a, tmp, size * sizeof(char **)); - Memory::copy (b, b + size, (a - b)*sizeof(char **)); - Memory::copy (tmp, b, size * sizeof(char **)); - delete [] tmp; + char **tmp = new char *[size]; + Memory::copy (a, tmp, size * sizeof(char **)); + Memory::copy (b, b + size, (a - b)*sizeof(char **)); + Memory::copy (tmp, b, size * sizeof(char **)); + delete [] tmp; } Index: MMap.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/Sys/MMap.cc,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- MMap.cc 2 Jun 2002 23:42:24 -0000 1.11 +++ MMap.cc 31 Oct 2003 22:33:13 -0000 1.12 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -35,56 +35,56 @@ using namespace Prague; -MMap::MMap(int fd, int l, int prot, int share, void *addr, off_t offset) throw(std::runtime_error) - : _base(MAP_FAILED), _length(0) +MMap::MMap(int fd, int l, int prot, int share, void *addr, off_t offset) throw(std::runtime_error) : + _base(MAP_FAILED), + _length(0) { - struct stat sb; - _length = l > -1 ? l : fstat(fd, &sb) == -1 ? -1 : sb.st_size; - if (l > static_cast<int>(_length)) + struct stat sb; + _length = l > -1 ? l : fstat(fd, &sb) == -1 ? -1 : sb.st_size; + if (l > static_cast<int>(_length)) { - _length = l; - ftruncate(fd, _length); + _length = l; + ftruncate(fd, _length); } - else if (l > 0 && l < static_cast<int>(_length)) _length = l; - _base = mmap(addr, _length, prot, share, fd, offset); - if (_base == MAP_FAILED) throw std::runtime_error(strerror(errno)); + else if (l > 0 && l < static_cast<int>(_length)) _length = l; + _base = mmap(addr, _length, prot, share, fd, offset); + if (_base == MAP_FAILED) throw std::runtime_error(strerror(errno)); } -MMap::MMap(const std::string &filename, int l, int prot, int share, void *addr, off_t offset) throw(std::runtime_error) - : _base(MAP_FAILED), _length(0) +MMap::MMap(const std::string &filename, int l, int prot, int share, void *addr, off_t offset) throw(std::runtime_error) : + _base(MAP_FAILED), + _length(0) { - int fd = -1; - if (prot == read) - fd = open(filename.c_str(), O_RDONLY); - else - fd = open(filename.c_str(), O_RDWR|O_CREAT, 0666); + int fd = -1; + if (prot == read) fd = open(filename.c_str(), O_RDONLY); + else fd = open(filename.c_str(), O_RDWR|O_CREAT, 0666); - if (fd == -1) - { - std::string message = "Failed to map \"" + filename + "\": " + - strerror(errno); - throw std::runtime_error(message); - } - struct stat sb; - _length = fstat(fd, &sb) == -1 ? -1 : sb.st_size; - if (l > static_cast<int>(_length)) + if (fd == -1) { - _length = l; - ftruncate(fd, _length); + std::string message = "Failed to map \"" + filename + "\": " + + strerror(errno); + throw std::runtime_error(message); } - else if (l > 0 && l < static_cast<int>(_length)) _length = l; - _base = mmap(addr, _length, prot, share, fd, offset); - if (_base == MAP_FAILED) - { - std::string message = "Failed to map \"" + filename + "\": " + - strerror(errno); - throw std::runtime_error(message); - } - close(fd); + struct stat sb; + _length = fstat(fd, &sb) == -1 ? -1 : sb.st_size; + if (l > static_cast<int>(_length)) + { + _length = l; + ftruncate(fd, _length); + } + else if (l > 0 && l < static_cast<int>(_length)) _length = l; + _base = mmap(addr, _length, prot, share, fd, offset); + if (_base == MAP_FAILED) + { + std::string message = "Failed to map \"" + filename + "\": " + + strerror(errno); + throw std::runtime_error(message); + } + close(fd); } -MMap::~MMap() { if (_base != MAP_FAILED) munmap(_base, _length);} -void MMap::sync(ssize_t len, bool wait) { msync(_base, len < 0 ? _length : len, wait ? MS_SYNC : MS_ASYNC);} -void MMap::sync(void *addr, size_t len, bool wait) { msync(addr, len, wait ? MS_SYNC : MS_ASYNC);} -void MMap::protect(ssize_t len, int prot) { mprotect(_base, len < 0 ? _length : len, prot);} -void MMap::protect(void *addr, size_t len, int prot) { mprotect(addr, len, prot);} +MMap::~MMap() { if (_base != MAP_FAILED) munmap(_base, _length); } +void MMap::sync(ssize_t len, bool wait) { msync(_base, len < 0 ? _length : len, wait ? MS_SYNC : MS_ASYNC); } +void MMap::sync(void *addr, size_t len, bool wait) { msync(addr, len, wait ? MS_SYNC : MS_ASYNC); } +void MMap::protect(ssize_t len, int prot) { mprotect(_base, len < 0 ? _length : len, prot); } +void MMap::protect(void *addr, size_t len, int prot) { mprotect(addr, len, prot); } Index: Path.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/Sys/Path.cc,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- Path.cc 21 Mar 2001 06:28:55 -0000 1.8 +++ Path.cc 31 Oct 2003 22:33:13 -0000 1.9 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -27,36 +27,36 @@ Path::Path(const std::string &list, char separator) { - if (list.empty()) return; - std::string::size_type b = 0; - while (b < list.size()) + if (list.empty()) return; + std::string::size_type b = 0; + while (b < list.size()) { - std::string::size_type e = list.find(separator, b); - _directories.push_back(std::string(list, b, e-b)); - b = e == std::string::npos ? std::string::npos : e + 1; + std::string::size_type e = list.find(separator, b); + _directories.push_back(std::string(list, b, e-b)); + b = e == std::string::npos ? std::string::npos : e + 1; } } std::string Path::expand_user(const std::string &path) { - if (path.empty() || path[0] != '~') return path; - std::string pfx; - std::string::size_type pos = path.find_first_of('/'); - if (path[1] == '\0' || pos == 1) + if (path.empty() || path[0] != '~') return path; + std::string pfx; + std::string::size_type pos = path.find_first_of('/'); + if (path[1] == '\0' || pos == 1) { - pfx = getenv("HOME"); - if (pfx.empty()) pfx = User().home(); + pfx = getenv("HOME"); + if (pfx.empty()) pfx = User().home(); } - else + else { - std::string name(path,1,(pos==std::string::npos) ? std::string::npos : pos-1); - User user(name.c_str()); - pfx = user.home(); + std::string name(path,1,(pos==std::string::npos) ? std::string::npos : pos-1); + User user(name.c_str()); + pfx = user.home(); } - if (pfx.empty()) return path; - std::string result = pfx; - if (pos == std::string::npos) return result; - if (result.empty() || result[result.length()-1] != '/') result += '/'; - result += std::string(path).substr(pos+1); - return result; -}; + if (pfx.empty()) return path; + std::string result = pfx; + if (pos == std::string::npos) return result; + if (result.empty() || result[result.length()-1] != '/') result += '/'; + result += std::string(path).substr(pos+1); + return result; +} Index: Profiler.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/Sys/Profiler.cc,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- Profiler.cc 2 Jun 2002 23:42:24 -0000 1.10 +++ Profiler.cc 31 Oct 2003 22:33:13 -0000 1.11 @@ -1,9 +1,9 @@ /*$Id$ * - * This source file is a part of the Berlin Project. + * This source file is a part of the Fresco Project. * Copyright (C) 1999 Brent A. Fulgham <[email protected]> - * Copyright (C) 1999,2000 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * Copyright (C) 1999,2000 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -36,84 +36,77 @@ void Profiler::CheckPoint::output(std::ostream &os, unsigned short ind) { - if (elapsed > 0.) + if (elapsed > 0.) { - indent(os, ind); - os << name << ": " << std::setw(10) << count; - os << " Times. Total Time: "; - os << std::setprecision(8) << std::setw(12); - os.setf( std::ios::fixed, std::ios::floatfield); - os << elapsed/CLOCKS_PER_SEC; - os << " Avg/Iter.: "; - os << std::setprecision(8) << std::setw(12); - os << elapsed/count/CLOCKS_PER_SEC << std::endl; + indent(os, ind); + os << name << ": " << std::setw(10) << count; + os << " Times. Total Time: "; + os << std::setprecision(8) << std::setw(12); + os.setf( std::ios::fixed, std::ios::floatfield); + os << elapsed/CLOCKS_PER_SEC; + os << " Avg/Iter.: "; + os << std::setprecision(8) << std::setw(12); + os << elapsed/count/CLOCKS_PER_SEC << std::endl; } } #if 1 typedef std::vector<Profiler::CheckPoint> chart; -struct CP_compare : public std::binary_function<Profiler::CheckPoint, Profiler::CheckPoint, bool> +struct CP_compare : public std::binary_function<Profiler::CheckPoint, Profiler::CheckPoint, bool> { - bool operator()(const Profiler::CheckPoint &cp1, const Profiler::CheckPoint &cp2) const - { - return cp1.elapsed/cp1.count > cp2.elapsed/cp2.count; - } + bool operator()(const Profiler::CheckPoint &cp1, const Profiler::CheckPoint &cp2) const + { return cp1.elapsed/cp1.count > cp2.elapsed/cp2.count; } }; struct CP_find : public std::unary_function<Profiler::CheckPoint, bool> { - CP_find(const std::string &s) : scope(s) {} - bool operator()(const Profiler::CheckPoint &cp) const { return scope == cp.name;} - std::string scope; + CP_find(const std::string &s) : scope(s) { } + bool operator()(const Profiler::CheckPoint &cp) const { return scope == cp.name; } + std::string scope; }; void Profiler::dump(std::ostream &os) { - Prague::Guard<Mutex> guard(mutex); - chart scopes; - for (ntree<CheckPoint *>::iterator i = table->begin(); i != table->end(); i++) + // FIXME: This method looks fishy to me -tobias + Prague::Guard<Mutex> guard(mutex); + chart scopes; + for (ntree<CheckPoint *>::iterator i = table->begin(); i != table->end(); ++i) { - /* - * get a copy of the checkpoint and subtract all child checkpoints from it - */ - CheckPoint cp = *(*i).value; - for (ntree<CheckPoint *>::const_child_iterator j = (*i).child_begin(); j != (*i).child_end(); j++) - cp.elapsed -= (*j).value->elapsed; - /* - * now insert it into the chart - */ - chart::iterator j = find_if(scopes.begin(), scopes.end(), CP_find(cp.name)); - if (j == scopes.end()) scopes.push_back(cp); - else - { - (*j).elapsed += cp.elapsed; - (*j).count += cp.count; - } + // get a copy of the checkpoint and subtract all child checkpoints from it + CheckPoint cp = *(*i).value; + for (ntree<CheckPoint *>::const_child_iterator j = (*i).child_begin(); + j != (*i).child_end(); + ++j) + cp.elapsed -= (*j).value->elapsed; + // now insert it into the chart + chart::iterator j = find_if(scopes.begin(), scopes.end(), CP_find(cp.name)); + if (j == scopes.end()) scopes.push_back(cp); + else + { + (*j).elapsed += cp.elapsed; + (*j).count += cp.count; + } } - /* - * finally, sort the results - */ - std::sort(scopes.begin(), scopes.end(), CP_compare()); - /* - * now dump it to the ostream - */ - for (chart::iterator i = scopes.begin(); i != scopes.end(); i++) - (*i).output(os, 0); + // finally, sort the results + std::sort(scopes.begin(), scopes.end(), CP_compare()); + // now dump it to the ostream + for (chart::iterator i = scopes.begin(); i != scopes.end(); i++) + (*i).output(os, 0); } #else void Profiler::dump(std::ostream &os) { - Prague::Guard<Mutex> guard(mutex); - dump(os, *current, 0); + Prague::Guard<Mutex> guard(mutex); + dump(os, *current, 0); } #endif void Profiler::dump(std::ostream &os, const item_t &root, unsigned short ind) { - for (const_child_iterator i = root.child_begin(); i != root.child_end(); i++) - dump(os, *i, ind + 1); - if (root.value) root.value->output(os, ind); + for (const_child_iterator i = root.child_begin(); i != root.child_end(); i++) + dump(os, *i, ind + 1); + if (root.value) root.value->output(os, ind); } Index: SHM.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/Sys/SHM.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- SHM.cc 28 Sep 2000 15:46:25 -0000 1.4 +++ SHM.cc 31 Oct 2003 22:33:13 -0000 1.5 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,8 +28,8 @@ using namespace Prague; -int SHM::allocate(key_t key, size_t bytes, int flags) { return shmget(key, bytes, flags);} -int SHM::allocate(size_t bytes, int flags) { return shmget(IPC_PRIVATE, bytes, flags);} -void SHM::deallocate(int id) { shmctl(id, IPC_RMID, 0);} -void *SHM::attach(int id) { return shmat(id, 0, SHM_RND);} -void SHM::detach(void *p) { shmdt(reinterpret_cast<char *> (p));} +int SHM::allocate(key_t key, size_t bytes, int flags) { return shmget(key, bytes, flags); } +int SHM::allocate(size_t bytes, int flags) { return shmget(IPC_PRIVATE, bytes, flags); } +void SHM::deallocate(int id) { shmctl(id, IPC_RMID, 0); } +void *SHM::attach(int id) { return shmat(id, 0, SHM_RND); } +void SHM::detach(void *p) { shmdt(reinterpret_cast<char *> (p)); } Index: Signal.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/Sys/Signal.cc,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- Signal.cc 8 May 2003 03:21:11 -0000 1.10 +++ Signal.cc 31 Oct 2003 22:33:13 -0000 1.11 @@ -1,7 +1,7 @@ /*$Id$ * * This source file is a part of the Fresco Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * Copyright (C) 1999 Stefan Seefeld <[email protected]> * http://www.fresco.org * * This library is free software; you can redistribute it and/or @@ -27,23 +27,23 @@ namespace Prague { -typedef void (*sighnd_type) (int); -void sighandler (int signo) -{ - /* - * due to the non conformance of LinuxThreads with - * POSIX 1003.1c we can't let the signal server thread - * handle the SIGCHLD signal. 'wait()' would fail. - * Instead, we have to handle it directly, trusting - * the event handler that it is reentrant and async safe - * - stefan - */ - if (signo == Signal::child) Signal::notify(signo); - else if (!Thread::id()) - Signal::queue.push(signo); -} + typedef void (*sighnd_type) (int); + void sighandler (int signo) + { + /* + * due to the non conformance of LinuxThreads with + * POSIX 1003.1c we can't let the signal server thread + * handle the SIGCHLD signal. 'wait()' would fail. + * Instead, we have to handle it directly, trusting + * the event handler that it is reentrant and async safe + * - stefan + */ + if (signo == Signal::child) Signal::notify(signo); + else if (!Thread::id()) + Signal::queue.push(signo); + } -}; +} // namespace using namespace Prague; @@ -53,154 +53,154 @@ bool Signal::set (int signum, Signal::Notifier *notifier) { - if (server.state() == Thread::READY) server.start(); - if (!notifiers[signum].size()) + if (server.state() == Thread::READY) server.start(); + if (!notifiers[signum].size()) { - struct sigaction sa; - if (sigaction (signum, 0, &sa) == -1) return false; - if (sa.sa_handler != sighnd_type (&sighandler)) - { - sa.sa_handler = sighnd_type (&sighandler); - if (sigemptyset (&sa.sa_mask) == -1) return false; - sa.sa_flags = 0; - if (sigaction (signum, &sa, 0) == -1) return false; - } + struct sigaction sa; + if (sigaction (signum, 0, &sa) == -1) return false; + if (sa.sa_handler != sighnd_type (&sighandler)) + { + sa.sa_handler = sighnd_type (&sighandler); + if (sigemptyset (&sa.sa_mask) == -1) return false; + sa.sa_flags = 0; + if (sigaction (signum, &sa, 0) == -1) return false; + } } - notifiers[signum].push_back(notifier); - return true; + notifiers[signum].push_back(notifier); + return true; } bool Signal::unset (int signum, Signal::Notifier *notifier) { - nlist_t::iterator i = find (notifiers[signum].begin(), notifiers[signum].end(), notifier); - if (i != notifiers[signum].end()) + nlist_t::iterator i = find (notifiers[signum].begin(), notifiers[signum].end(), notifier); + if (i != notifiers[signum].end()) { - notifiers[signum].erase(i); - if (!notifiers[signum].size()) unset(signum); - return true; + notifiers[signum].erase(i); + if (!notifiers[signum].size()) unset(signum); + return true; } - return false; + return false; } void Signal::unset (int signum) { - notifiers[signum].erase(notifiers[signum].begin(), notifiers[signum].end()); - struct sigaction sa; - if (sigaction (signum, 0, &sa) == -1) return; - if (sa.sa_handler == sighnd_type (&sighandler)) + notifiers[signum].erase(notifiers[signum].begin(), notifiers[signum].end()); + struct sigaction sa; + if (sigaction (signum, 0, &sa) == -1) return; + if (sa.sa_handler == sighnd_type (&sighandler)) { - sa.sa_handler = sighnd_type (SIG_DFL); - if (sigemptyset (&sa.sa_mask) == -1) return; - sa.sa_flags = 0; - if (sigaction (signum, &sa, 0) == -1) return; + sa.sa_handler = sighnd_type (SIG_DFL); + if (sigemptyset (&sa.sa_mask) == -1) return; + sa.sa_flags = 0; + if (sigaction (signum, &sa, 0) == -1) return; } } void Signal::mask (int signum) { - sigset_t s; - if (sigemptyset (&s) == -1) return; - if (sigaddset (&s, signum) == -1) return; - if (sigprocmask (SIG_BLOCK, &s, 0) == -1) return; + sigset_t s; + if (sigemptyset (&s) == -1) return; + if (sigaddset (&s, signum) == -1) return; + if (sigprocmask (SIG_BLOCK, &s, 0) == -1) return; } void Signal::mask (int siga, int sigb) { - struct sigaction sa; - if (sigaction (siga, 0, &sa) == -1) return; - if (sa.sa_handler != sighnd_type (&sighandler)) + struct sigaction sa; + if (sigaction (siga, 0, &sa) == -1) return; + if (sa.sa_handler != sighnd_type (&sighandler)) { - sa.sa_handler = sighnd_type (&sighandler); - if (sigemptyset (&sa.sa_mask) == -1) return; - sa.sa_flags = 0; + sa.sa_handler = sighnd_type (&sighandler); + if (sigemptyset (&sa.sa_mask) == -1) return; + sa.sa_flags = 0; } - if (sigaddset (&sa.sa_mask, sigb) == -1) return; - if (sigaction (siga, &sa, 0) == -1) return; + if (sigaddset (&sa.sa_mask, sigb) == -1) return; + if (sigaction (siga, &sa, 0) == -1) return; } void Signal::unmask (int signum) { - sigset_t s; - if (sigemptyset (&s) == -1) return; - if (sigaddset (&s, signum) == -1) return; - if (sigprocmask (SIG_UNBLOCK, &s, 0) == -1) return; + sigset_t s; + if (sigemptyset (&s) == -1) return; + if (sigaddset (&s, signum) == -1) return; + if (sigprocmask (SIG_UNBLOCK, &s, 0) == -1) return; } void Signal::unmask (int siga, int sigb) { - struct sigaction sa; - if (sigaction (siga, 0, &sa) == -1) return; - if (sa.sa_handler != sighnd_type (&sighandler)) + struct sigaction sa; + if (sigaction (siga, 0, &sa) == -1) return; + if (sa.sa_handler != sighnd_type (&sighandler)) { - sa.sa_handler = sighnd_type (&sighandler); - if (sigemptyset (&sa.sa_mask) == -1) return; - sa.sa_flags = 0; + sa.sa_handler = sighnd_type (&sighandler); + if (sigemptyset (&sa.sa_mask) == -1) return; + sa.sa_flags = 0; } - else { if (sigdelset (&sa.sa_mask, sigb) == -1) return;} - if (sigaction (siga, &sa, 0) == -1) return; + else { if (sigdelset (&sa.sa_mask, sigb) == -1) return;} + if (sigaction (siga, &sa, 0) == -1) return; } void Signal::sysresume (int signum, bool set) { - struct sigaction sa; - if (sigaction (signum, 0, &sa) == -1) return; - if (sa.sa_handler != sighnd_type (&sighandler)) + struct sigaction sa; + if (sigaction (signum, 0, &sa) == -1) return; + if (sa.sa_handler != sighnd_type (&sighandler)) { - sa.sa_handler = sighnd_type (&sighandler); - if (sigemptyset (&sa.sa_mask) == -1) return; - sa.sa_flags = 0; + sa.sa_handler = sighnd_type (&sighandler); + if (sigemptyset (&sa.sa_mask) == -1) return; + sa.sa_flags = 0; } - if (sigaction (signum, &sa, 0) == -1) return; + if (sigaction (signum, &sa, 0) == -1) return; } sigset_t Signal::pending () { - sigset_t s; - if (sigemptyset (&s) == -1) return s; - if (sigpending (&s) == -1) return s; - return s; + sigset_t s; + if (sigemptyset (&s) == -1) return s; + if (sigpending (&s) == -1) return s; + return s; } bool Signal::ispending (int signo) { - sigset_t s = pending(); - switch (sigismember (&s, signo)) + sigset_t s = pending(); + switch (sigismember (&s, signo)) { - case 1: return true; - case -1: perror("Signal::ispending: "); - case 0: - default: return false; + case 1: + return true; + case -1: + perror("Signal::ispending: "); + case 0: + default: + return false; } - return false; + return false; } -const char *Signal::name(int signum) -{ - return strsignal(signum); -} +const char *Signal::name(int signum) { return strsignal(signum); } struct execute { - execute(int s) : signum(s) {} - void operator () (Signal::Notifier *notifier) { notifier->notify(signum);} - int signum; + execute(int s) : signum(s) { } + void operator () (Signal::Notifier *notifier) { notifier->notify(signum); } + int signum; }; void Signal::notify(int signum) { - nlist_t tmp = notifiers[signum]; - execute e(signum); - for_each(tmp.begin(), tmp.end(), e); + nlist_t tmp = notifiers[signum]; + execute e(signum); + for_each(tmp.begin(), tmp.end(), e); } void *Signal::run(void *) { - while (true) + while (true) { - int signo = Signal::queue.top(); - Signal::queue.pop(); - Signal::notify(signo); - Thread::testcancel(); + int signo = Signal::queue.top(); + Signal::queue.pop(); + Signal::notify(signo); + Thread::testcancel(); } - return 0; + return 0; } Index: Stopwatch.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/Sys/Stopwatch.cc,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- Stopwatch.cc 3 Aug 2003 21:55:30 -0000 1.8 +++ Stopwatch.cc 31 Oct 2003 22:33:13 -0000 1.9 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -29,50 +29,49 @@ clock_t Stopwatch::_ticks = 0; -Stopwatch::Stopwatch() - : _state(undef) +Stopwatch::Stopwatch() : _state(undef) { - if (!_ticks) _ticks = sysconf(_SC_CLK_TCK); - start(); -}; + if (!_ticks) _ticks = sysconf(_SC_CLK_TCK); // FIXME: This is not the POSIX way! -tobias + start(); +} void Stopwatch::start() { - _state = running; - struct tms cpt; - _real.begin = times(&cpt); - _cpu.begin = cpt.tms_utime; - _sys.begin = cpt.tms_stime; - if (_real.begin == -1) perror("Stopwatch::start"); -}; + _state = running; + struct tms cpt; + _real.begin = times(&cpt); + _cpu.begin = cpt.tms_utime; + _sys.begin = cpt.tms_stime; + if (_real.begin == -1) perror("Stopwatch::start"); +} void Stopwatch::stop() { - _state = stopped; - struct tms cpt; - _real.end = times(&cpt); - _cpu.end = cpt.tms_utime; - _sys.end = cpt.tms_stime; - if (_real.end == -1) perror("Stopwatch::stop"); -}; + _state = stopped; + struct tms cpt; + _real.end = times(&cpt); + _cpu.end = cpt.tms_utime; + _sys.end = cpt.tms_stime; + if (_real.end == -1) perror("Stopwatch::stop"); +} double Stopwatch::real_time() { - if (_state == undef) return 0.; - else if (_state == running) stop(); - return (double) (_real.end - _real.begin)/_ticks; -}; + if (_state == undef) return 0.; + else if (_state == running) stop(); + return (double) (_real.end - _real.begin)/_ticks; +} double Stopwatch::cpu_time() { - if (_state == undef) return 0.; - else if (_state == running) stop(); - return (double) (_cpu.end - _cpu.begin)/_ticks; -}; + if (_state == undef) return 0.; + else if (_state == running) stop(); + return (double) (_cpu.end - _cpu.begin)/_ticks; +} double Stopwatch::sys_time() { - if (_state == undef) return 0.; - else if (_state == running) stop(); - return (double) (_sys.end - _sys.begin)/_ticks; -}; + if (_state == undef) return 0.; + else if (_state == running) stop(); + return (double) (_sys.end - _sys.begin)/_ticks; +} Index: Thread.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/Sys/Thread.cc,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- Thread.cc 8 May 2003 03:21:11 -0000 1.14 +++ Thread.cc 31 Oct 2003 22:33:13 -0000 1.15 @@ -1,7 +1,7 @@ /*$Id$ * * This source file is a part of the Fresco Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * Copyright (C) 1999 Stefan Seefeld <[email protected]> * http://www.fresco.org * * This library is free software; you can redistribute it and/or @@ -32,7 +32,7 @@ Thread *Thread::main = 0; Thread::Guard Thread::guard; -void id_deallocator(void *id) { delete reinterpret_cast<unsigned long *>(id);} +void id_deallocator(void *id) { delete reinterpret_cast<unsigned long *>(id); } //Mutex::Mutex(type t) //{ @@ -44,109 +44,104 @@ Thread::Guard::Guard() { - pthread_key_create(&Thread::self_key, 0); - pthread_key_create(&Thread::id_key, id_deallocator); - pthread_t pt = pthread_self(); - Thread::main = new Thread(pt); - pthread_setspecific(Thread::self_key, Thread::main); - id_mutex.lock(); - pthread_setspecific(Thread::id_key, new unsigned long (counter++)); - id_mutex.unlock(); + pthread_key_create(&Thread::self_key, 0); + pthread_key_create(&Thread::id_key, id_deallocator); + pthread_t pt = pthread_self(); + Thread::main = new Thread(pt); + pthread_setspecific(Thread::self_key, Thread::main); + id_mutex.lock(); + pthread_setspecific(Thread::id_key, new unsigned long (counter++)); + id_mutex.unlock(); } -Thread::Guard::~Guard() -{ - delete Thread::main; -} +Thread::Guard::~Guard() { delete Thread::main; } -Thread::Thread(proc pp, void *a, priority_t prio) - : my_proc(pp), - my_arg(a), - my_priority(prio), - my_state(READY), - my_detached(false) -{ -} +Thread::Thread(proc pp, void *a, priority_t prio) : + my_proc(pp), + my_arg(a), + my_priority(prio), + my_state(READY), + my_detached(false) +{ } -Thread::Thread(pthread_t pt) - : my_proc(0), - my_arg(0), - my_thread(pt), - my_priority(NORMAL), - my_state(RUNNING), - my_detached(false) -{ -} +Thread::Thread(pthread_t pt) : + my_proc(0), + my_arg(0), + my_thread(pt), + my_priority(NORMAL), + my_state(RUNNING), + my_detached(false) +{ } Thread::~Thread() { - if (this != self() && state() != READY) - { - cancel(); - if (!my_detached) join(0); - } + if (this != self() && state() != READY) + { + cancel(); + if (!my_detached) join(0); + } } void Thread::start() throw (Exception) { - Prague::Guard<Mutex> guard(my_mutex); - if ((my_state) != READY) throw Exception("thread already running"); - if (pthread_create(&my_thread, 0, &start, this) != 0) throw Exception("can't create thread"); - else my_state = RUNNING; + Prague::Guard<Mutex> guard(my_mutex); + if ((my_state) != READY) throw Exception("thread already running"); + if (pthread_create(&my_thread, 0, &start, this) != 0) throw Exception("can't create thread"); + else my_state = RUNNING; } void Thread::join(void **status) throw (Exception) { - { + { + Prague::Guard<Mutex> guard(my_mutex); + if (my_state == READY) throw Exception("can't join ready thread"); + if (this == self()) throw Exception("can't join thread 'self'"); + if (my_detached) throw Exception("can't join detached thread"); + } + void *s; + pthread_join(my_thread, &s); Prague::Guard<Mutex> guard(my_mutex); - if (my_state == READY) throw Exception("can't join ready thread"); - if (this == self()) throw Exception("can't join thread 'self'"); - if (my_detached) throw Exception("can't join detached thread"); - } - void *s; - pthread_join(my_thread, &s); - Prague::Guard<Mutex> guard(my_mutex); - my_state = READY; - if (status) *status = s; + my_state = READY; + if (status) *status = s; } void Thread::cancel() { - if (this != self() && state() == RUNNING) - pthread_cancel(my_thread); + if (this != self() && state() == RUNNING) + pthread_cancel(my_thread); } void Thread::detach() { - my_mutex.lock(); - my_detached = true; - my_mutex.unlock(); - pthread_detach(my_thread); + my_mutex.lock(); + my_detached = true; + my_mutex.unlock(); + pthread_detach(my_thread); } void Thread::exit(void *r) { - Thread *me = self(); - if (me) - { - Prague::Guard<Mutex> guard(me->my_mutex); - me->my_state = TERMINATED; - } - pthread_exit(r); + Thread *me = self(); + if (me) + { + Prague::Guard<Mutex> guard(me->my_mutex); + me->my_state = TERMINATED; + } + pthread_exit(r); } void *Thread::start(void *X) { - Thread *thread = reinterpret_cast<Thread *>(X); - pthread_setspecific(self_key, thread); - id_mutex.lock(); - pthread_setspecific(id_key, new unsigned long (counter++)); - id_mutex.unlock(); - return thread->my_proc(thread->my_arg); + Thread *thread = reinterpret_cast<Thread *>(X); + pthread_setspecific(self_key, thread); + id_mutex.lock(); + pthread_setspecific(id_key, new unsigned long (counter++)); + id_mutex.unlock(); + return thread->my_proc(thread->my_arg); } bool Thread::delay(const Time &time) { - Time t(time); - return select(0, 0, 0, 0, &t) == 0; + Time t(time); + return select(0, 0, 0, 0, &t) == 0; } Index: Time.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/Sys/Time.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Time.cc 23 Sep 2000 21:18:36 -0000 1.4 +++ Time.cc 31 Oct 2003 22:33:13 -0000 1.5 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -25,43 +25,40 @@ const Time Time::zero(0); -/* @Method{Time::Time(int hour, int minute, int second, int millisecond)} - * - * @Description{} - */ +//. @Method{Time::Time(int hour, int minute, int second, int millisecond)} +//. +//. @Description{} Time::Time(int h, int m, int s, int ms) { - tm r; - r.tm_hour = h; - r.tm_min = m; - r.tm_sec = s; - tv_sec = mktime(&r), tv_usec = 1000*ms; + tm r; + r.tm_hour = h; + r.tm_min = m; + r.tm_sec = s; + tv_sec = mktime(&r), tv_usec = 1000*ms; } -/* @Method{Time::Time(int year, int month, int day, int hour, int minute, int second, int millisecond)} - * - * @Description{} - */ +//. @Method{Time::Time(int year, int month, int day, int hour, int minute, int second, int millisecond)} +//. +//. @Description{} Time::Time(int y, int mo, int d, int h, int m, int s, int ms) { - tm r; - r.tm_year = y - 1900; - r.tm_mon = mo; - r.tm_mday = d; - r.tm_hour = h; - r.tm_min = m; - r.tm_sec = s; - r.tm_isdst= 1; - tv_sec = mktime(&r), tv_usec = 1000*ms; + tm r; + r.tm_year = y - 1900; + r.tm_mon = mo; + r.tm_mday = d; + r.tm_hour = h; + r.tm_min = m; + r.tm_sec = s; + r.tm_isdst= 1; + tv_sec = mktime(&r), tv_usec = 1000*ms; } -/* @Method{Time Time::currentTime()} - * - * @Description{returns the current time} - */ +//. @Method{Time Time::currentTime()} +//. +//. @Description{returns the current time} Time Time::currentTime() { - struct timeval current; - gettimeofday(¤t, 0); - return Time (current); -}; + struct timeval current; + gettimeofday(¤t, 0); + return Time (current); +} Index: Timer.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/Sys/Timer.cc,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- Timer.cc 8 May 2003 03:21:11 -0000 1.11 +++ Timer.cc 31 Oct 2003 22:33:13 -0000 1.12 @@ -1,7 +1,7 @@ /*$Id$ * * This source file is a part of the Fresco Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * Copyright (C) 1999 Stefan Seefeld <[email protected]> * http://www.fresco.org * * This library is free software; you can redistribute it and/or @@ -31,63 +31,62 @@ void Timer::start(const Time &t, const Time &i) { - timeout = t; - interval = i; - Timer::schedule(this); -}; + timeout = t; + interval = i; + Timer::schedule(this); +} void Timer::stop() -{ - Timer::cancel(this); -}; +{ Timer::cancel(this); } void *Timer::start(void *) { - Prague::Guard<Mutex> guard(mutex); - while (true) + Prague::Guard<Mutex> guard(mutex); + while (true) { - if (!timers.size()) condition.wait(); - else + if (!timers.size()) condition.wait(); + else { - Time time = timers.front()->timeout; - condition.wait(time); + Time time = timers.front()->timeout; + condition.wait(time); } - expire(); + expire(); } - return 0; + return 0; } void Timer::expire() { - Time now = Time::currentTime(); - while (timers.size() && timers.front()->timeout <= now) + Time now = Time::currentTime(); + while (timers.size() && timers.front()->timeout <= now) { - Timer *timer = timers.front(); - timer->notifier->notify(); - if (timer->interval != Time::zero) - { - do timer->timeout += timer->interval; - while (timer->timeout <= now); - timers.erase(timers.begin()); - timers.push_back(timer); - push_heap(timers.begin(), timers.end(), comp()); - } + Timer *timer = timers.front(); + timer->notifier->notify(); + if (timer->interval != Time::zero) + { + do + timer->timeout += timer->interval; + while (timer->timeout <= now); + timers.erase(timers.begin()); + timers.push_back(timer); + push_heap(timers.begin(), timers.end(), comp()); + } } } void Timer::schedule(Timer *timer) { - if (server.state() == Thread::READY) server.start(); - Prague::Guard<Mutex> guard(mutex); - timers.push_back(timer); - push_heap(timers.begin(), timers.end(), comp()); - condition.signal(); + if (server.state() == Thread::READY) server.start(); + Prague::Guard<Mutex> guard(mutex); + timers.push_back(timer); + push_heap(timers.begin(), timers.end(), comp()); + condition.signal(); } void Timer::cancel(Timer *timer) { - Prague::Guard<Mutex> guard(mutex); - std::vector<Timer *>::iterator i = find(timers.begin(), timers.end(), timer); - if (i != timers.end()) timers.erase(i); - condition.signal(); + Prague::Guard<Mutex> guard(mutex); + std::vector<Timer *>::iterator i = find(timers.begin(), timers.end(), timer); + if (i != timers.end()) timers.erase(i); + condition.signal(); } Index: Tracer.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/Sys/Tracer.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Tracer.cc 26 Jan 2002 22:44:27 -0000 1.4 +++ Tracer.cc 31 Oct 2003 22:33:13 -0000 1.5 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999, 2000 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999, 2000 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -35,57 +35,57 @@ std::ostream &Prague::operator << (std::ostream &os, const Prague::Tracer::Event &e) { - os.setf(std::ios::fixed); - os.precision(6); - os << e.time << '|' << e.thread << '\t' << e.type << ' ' << e.section; - if (e.object) os << " - " << e.object; - if (e.start != -1) os << " took " << (e.time-e.start); - os.unsetf(std::ios::fixed); - return os; + os.setf(std::ios::fixed); + os.precision(6); + os << e.time << '|' << e.thread << '\t' << e.type << ' ' << e.section; + if (e.object) os << " - " << e.object; + if (e.start != -1) os << " took " << (e.time-e.start); + os.unsetf(std::ios::fixed); + return os; } double Tracer::add(const char *type, const char *object, const char *section, double start) { - // Remember the start time for this function, to use in compensating an - // offset for more accurate tracer timings - Time time = Time::currentTime(); + // Remember the start time for this function, to use in compensating an + // offset for more accurate tracer timings + Time time = Time::currentTime(); - // Thread guard - Prague::Guard<Mutex> guard(_mutex); + // Thread guard + Prague::Guard<Mutex> guard(_mutex); - if (_next == _events.size()) return 0.; + if (_next == _events.size()) return 0.; - // Remember to return the time at the start of the function - double ret = _events[_next].time = time - _start; - _events[_next].thread = Thread::self()->id(); - _events[_next].type = type; - _events[_next].object = object; - _events[_next].section = section; - _events[_next].start = start; - if (_log) + // Remember to return the time at the start of the function + double ret = _events[_next].time = time - _start; + _events[_next].thread = Thread::self()->id(); + _events[_next].type = type; + _events[_next].object = object; + _events[_next].section = section; + _events[_next].start = start; + if (_log) { - for (unsigned short i = 0; i != *_indent; i++) std::cerr.put(' '); - std::cerr << _events[_next] << std::endl; + for (unsigned short i = 0; i != *_indent; i++) std::cerr.put(' '); + std::cerr << _events[_next] << std::endl; } - _next++; - if (_next == _events.size()) + _next++; + if (_next == _events.size()) { - _next = 0; - _wrapped = true; + _next = 0; + _wrapped = true; } - // Adjust for time taken in this function, which may be lengthy due to - // outputs to screen etc - Time end_time = Time::currentTime(); - _start += (end_time - time); - return ret; + // Adjust for time taken in this function, which may be lengthy due to + // outputs to screen etc + Time end_time = Time::currentTime(); + _start += (end_time - time); + return ret; } void Tracer::dump(std::ostream &os) { - std::vector<Event>::iterator e; - os << "* Tracer::dump =\n"; - if (_wrapped) for (e = _events.begin() + _next; e != _events.end(); e++) os << *e << '\n'; - for (e = _events.begin(); e != _events.begin() + _next; e++) os << *e << '\n'; - os << "* end of Tracer::dump" << std::endl; + std::vector<Event>::iterator e; + os << "* Tracer::dump =\n"; + if (_wrapped) for (e = _events.begin() + _next; e != _events.end(); e++) os << *e << '\n'; + for (e = _events.begin(); e != _events.begin() + _next; e++) os << *e << '\n'; + os << "* end of Tracer::dump" << std::endl; } Index: User.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/Sys/User.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- User.cc 21 Mar 2001 06:28:55 -0000 1.5 +++ User.cc 31 Oct 2003 22:33:13 -0000 1.6 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -27,11 +27,8 @@ User::User(int uid) { - if (uid == -1) uid = getuid(); - pwd = getpwuid(uid); -}; + if (uid == -1) uid = getuid(); + pwd = getpwuid(uid); +} -User::User(const std::string &name) -{ - pwd = getpwnam(name.c_str()); -}; +User::User(const std::string &name) { pwd = getpwnam(name.c_str()); } Index: logbuf.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/Sys/logbuf.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- logbuf.cc 18 Jul 2001 04:27:32 -0000 1.4 +++ logbuf.cc 31 Oct 2003 22:33:13 -0000 1.5 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,54 +28,52 @@ logbuf::int_type logbuf::sputc(logbuf::char_type c) { - if (pptr() == epptr()) return EOF; - *pptr() = c; - pbump(1); - if(pptr() == epptr()) + if (pptr() == epptr()) return EOF; + *pptr() = c; + pbump(1); + if(pptr() == epptr()) { - setp(pbase(), epptr()); - wrapped = true; + setp(pbase(), epptr()); + wrapped = true; } - return static_cast<int_type>(c); + return static_cast<int_type>(c); } std::streamsize logbuf::xsputn(const logbuf::char_type *s, std::streamsize n) { - if (pptr() == epptr()) return EOF; - std::streamsize length = epptr() - pptr(); - if (n <= length) + if (pptr() == epptr()) return EOF; + std::streamsize length = epptr() - pptr(); + if (n <= length) { - std::memcpy(pptr(), s, n * sizeof(char_type)); - if (length == n) - { - setp(pbase(), epptr()); - wrapped = true; - } - else pbump(n); - return n; + std::memcpy(pptr(), s, n * sizeof(char_type)); + if (length == n) + { + setp(pbase(), epptr()); + wrapped = true; + } + else pbump(n); + return n; } - else + else { - std::memcpy(pptr(), s, length * sizeof(char_type)); - setp(pbase(), epptr()); - wrapped = true; - return length + xsputn(s + length, n - length); + std::memcpy(pptr(), s, length * sizeof(char_type)); + setp(pbase(), epptr()); + wrapped = true; + return length + xsputn(s + length, n - length); } } void logbuf::dump(std::ostream &os) { - os << "* logbuf::dump =\n"; - if (wrapped) - for (char_type *i = pptr(); i != epptr(); i++) - { - if (isprint(*i) || isspace(*i)) os.put(*i); - else os << std::hex << *i; - } - for (char_type *i = pbase(); i != pptr(); i++) - { - if (isprint(*i) || isspace(*i)) os.put(*i); - else os << std::hex << *i; - } - os << "* end of logbuf::dump" << std::endl; + os << "* logbuf::dump =\n"; + if (wrapped) + for (char_type *i = pptr(); i != epptr(); i++) + { + if (isprint(*i) || isspace(*i)) os.put(*i); + else os << std::hex << *i; + } + for (char_type *i = pbase(); i != pptr(); i++) + if (isprint(*i) || isspace(*i)) os.put(*i); + else os << std::hex << *i; + os << "* end of logbuf::dump" << std::endl; } Index: regex.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/Sys/regex.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- regex.cc 21 Mar 2001 06:28:55 -0000 1.5 +++ regex.cc 31 Oct 2003 22:33:13 -0000 1.6 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -26,92 +26,89 @@ std::string regex::error(int errcode) { - if (errcode == 0) return std::string(); - size_t length = regerror(errcode, _info->rx, 0, 0); - char *buffer = new char[length]; - regerror(errcode, _info->rx, buffer, length); - std::string text = buffer; - delete[] buffer; - return text; + if (errcode == 0) return std::string(); + size_t length = regerror(errcode, _info->rx, 0, 0); + char *buffer = new char[length]; + regerror(errcode, _info->rx, buffer, length); + std::string text = buffer; + delete[] buffer; + return text; } -regex::regex(const std::string &p, int flags) - : _info(new rx_t(flags & extended)) +regex::regex(const std::string &p, int flags) : _info(new rx_t(flags & extended)) { - _info->rx = new regex_t; - int errcode = regcomp(_info->rx, p.c_str(), _info->extended ? extended : 0); - if (errcode) { delete _info->rx; _info->rx = 0;} + _info->rx = new regex_t; + int errcode = regcomp(_info->rx, p.c_str(), _info->extended ? extended : 0); + if (errcode) { delete _info->rx; _info->rx = 0;} } regex::regex(const regex &r) : _info(r._info) -{ - _info->count++; -} +{ _info->count++; } regex ®ex::operator = (const regex &r) { - if (!--_info->count) delete _info; - _info = r._info; - _info->count++; - return *this; + if (!--_info->count) delete _info; + _info = r._info; + _info->count++; + return *this; } regex ®ex::operator = (const std::string &p) { - if (_info->count != 1) + if (_info->count != 1) { - _info->count--; - _info = new rx_t(_info->extended); + _info->count--; + _info = new rx_t(_info->extended); } - _info->rx = new regex_t; - int errcode = regcomp(_info->rx, p.c_str(), extended); - if (errcode) { delete _info->rx; _info->rx = 0;} - return *this; + _info->rx = new regex_t; + int errcode = regcomp(_info->rx, p.c_str(), extended); + if (errcode) { delete _info->rx; _info->rx = 0;} + return *this; } regex::~regex() -{ - if (!--_info->count) delete _info; -} +{ if (!--_info->count) delete _info; } rxmatch regex::search(const std::string &s, int i) const { - int n = _info->rx->re_nsub + 1; - regmatch_t *rm = new regmatch_t [n]; - if (i >= 0) - while (s[i] != '\0') - { - if (regexec(_info->rx, s.c_str() + i, n, rm, i ? REG_NOTBOL : 0) == 0) return rxmatch(s, i, n, rm); - i++; - } - else + int n = _info->rx->re_nsub + 1; + regmatch_t *rm = new regmatch_t [n]; + if (i >= 0) + while (s[i] != '\0') + { + if (regexec(_info->rx, s.c_str() + i, n, rm, i ? REG_NOTBOL : 0) == 0) + return rxmatch(s, i, n, rm); + i++; + } + else { - i = s.length() - 1; - do + i = s.length() - 1; + do { - if (regexec(_info->rx, s.c_str() + i, n, rm, i ? REG_NOTBOL : 0) == 0) return rxmatch(s, i, n, rm); - i--; + if (regexec(_info->rx, s.c_str() + i, n, rm, i ? REG_NOTBOL : 0) == 0) + return rxmatch(s, i, n, rm); + i--; } - while (i >= 0); + while (i >= 0); } - return rxmatch(s, -1, n, rm); + return rxmatch(s, -1, n, rm); } std::string::size_type regex::match(const std::string &s, int i) const { - std::string substr; - if (i < 0) i += s.length(); - if (i > (int) s.length()) return std::string::npos; - regmatch_t rm; - int errcode = regexec(_info->rx, s.c_str() + i, 1, &rm, 0); - if (errcode == 0 && rm.rm_so >= 0) return rm.rm_eo - rm.rm_so; - return std::string::npos; + std::string substr; + if (i < 0) i += s.length(); + if (i > (int) s.length()) return std::string::npos; + regmatch_t rm; + int errcode = regexec(_info->rx, s.c_str() + i, 1, &rm, 0); + if (errcode == 0 && rm.rm_so >= 0) return rm.rm_eo - rm.rm_so; + return std::string::npos; } const regex rxwhite("[ \n\t\r\v\f]+"); const regex rxint("-?[0-9]+"); const regex rxdouble("-?(([0-9]+\\.[0-9]*)|([0-9]+)|(\\.[0-9]+))" - "([eE][---+]?[0-9]+)?"); + "([eE][---+]?[0-9]+)?"); const regex rxalpha("[A-Za-z]+"); const regex rxlowercase("[a-z]+"); const regex rxuppercase("[A-Z]+");