Ticket #8727: lastPathComponent (3).patch
File lastPathComponent (3).patch, 20.0 KB (added by , 17 years ago) |
---|
-
home/david/Projects/scummvm/backends/fs/abstract-fs.h
101 101 * @note By default, this method returns the value of getName(). 102 102 */ 103 103 virtual String getDisplayName() const { return getName(); } 104 104 105 105 /** 106 * Returns a string with an architecture dependent path description. 106 * Returns the last component of the path pointed by this FilesystemNode. 107 * 108 * Examples (POSIX): 109 * /foo/bar.txt would return /bar.txt 110 * /foo/bar/ would return /bar/ 111 * 112 * @note This method is very architecture dependent, please check the concrete implementation for more information. 107 113 */ 108 114 virtual String getName() const = 0; 109 115 -
home/david/Projects/scummvm/backends/fs/amigaos4/amigaos4-fs.cpp
93 93 virtual String getPath() const { return _sPath; }; 94 94 virtual bool isDirectory() const { return _bIsDirectory; }; 95 95 virtual bool isReadable() const { return true; } //FIXME: this is just a stub 96 virtual bool isValid() const { return _bIsValid; };97 96 virtual bool isWritable() const { return true; } //FIXME: this is just a stub 98 97 99 98 virtual AbstractFilesystemNode *getChild(const String &n) const; … … 106 105 virtual AbstractFSList listVolumes() const; 107 106 }; 108 107 109 // TODO: this is ripped of110 // AmigaOSFilesystemNode::AmigaOSFilesystemNode(const String &p)111 // maybe change it to use this function instead?112 108 /** 113 109 * Returns the last component of a given path. 114 110 * … … 117 113 */ 118 114 const char *lastPathComponent(const Common::String &str) { 119 115 int offset = str.size(); 116 117 if (offset <= 0) { 118 debug(6, "Bad offset"); 119 return; 120 } 121 120 122 const char *p = str.c_str(); 121 123 122 124 while (offset > 0 && (p[offset-1] == '/' || p[offset-1] == ':')) … … 151 153 } 152 154 153 155 _sPath = p; 154 155 // Extract last component from path 156 const char *str = p.c_str(); 157 158 while (offset > 0 && (str[offset-1] == '/' || str[offset-1] == ':')) 159 offset--; 160 161 while (offset > 0 && (str[offset-1] != '/' && str[offset-1] != ':')) { 162 len++; 163 offset--; 164 } 165 166 _sDisplayName = String(str + offset, len); 156 _sDisplayName = lastPathComponent(_sPath); 167 157 _pFileLock = 0; 168 158 _bIsDirectory = false; 169 159 … … 352 342 if (lock) { 353 343 AmigaOSFilesystemNode *entry = new AmigaOSFilesystemNode(lock, (char *)ead->ed_Name); 354 344 if (entry) { 355 if (entry->isValid()) 345 //FIXME: since the isValid() function is no longer part of the AbstractFilesystemNode 346 // specification, the following call had to be changed: 347 // if (entry->isValid()) 348 // Please verify that the logic of the code remains coherent. Also, remember 349 // that the isReadable() and isWritable() methods are available. 350 if (entry->exists()) 356 351 myList.push_back(entry); 357 352 else 358 353 delete entry; … … 453 448 454 449 AmigaOSFilesystemNode *entry = new AmigaOSFilesystemNode(volumeLock, buffer); 455 450 if (entry) { 456 if (entry->isValid()) 451 //FIXME: since the isValid() function is no longer part of the AbstractFilesystemNode 452 // specification, the following call had to be changed: 453 // if (entry->isValid()) 454 // Please verify that the logic of the code remains coherent. Also, remember 455 // that the isReadable() and isWritable() methods are available. 456 if(entry->exists()) 457 457 myList.push_back(entry); 458 458 else 459 459 delete entry; -
home/david/Projects/scummvm/backends/fs/dc/dc-fs.cpp
62 62 virtual String getPath() const { return _path; } 63 63 virtual bool isDirectory() const { return _isDirectory; } 64 64 virtual bool isReadable() const { return true; } //FIXME: this is just a stub 65 virtual bool isValid() const { return _isValid; }66 65 virtual bool isWritable() const { return true; } //FIXME: this is just a stub 67 66 68 67 virtual AbstractFilesystemNode *getChild(const String &n) const; … … 81 80 * @return Pointer to the first char of the last component inside str. 82 81 */ 83 82 const char *lastPathComponent(const Common::String &str) { 83 if(str.empty()) 84 return ""; 85 84 86 const char *start = str.c_str(); 85 87 const char *cur = start + str.size() - 2; 86 88 -
home/david/Projects/scummvm/backends/fs/ds/ds-fs.cpp
36 36 ZipFile* DSFileSystemNode::_zipFile = NULL; 37 37 char currentDir[128]; 38 38 39 const char *lastPathComponentDS(const Common::String &str) { 40 if (str.empty()) 41 return ""; 42 43 char disp[128]; 44 char* pathStr = (char *) str.c_str(); 45 int lastSlash = 3; 46 47 for (int r = 0; r < (int) strlen(pathStr) - 1; r++) { 48 if (path[r] == '\\') { 49 lastSlash = r; 50 } 51 } 52 53 strcpy(disp, pathStr + lastSlash + 1); 54 55 return disp; 56 } 57 39 58 DSFileSystemNode::DSFileSystemNode() { 59 _path = "ds:/"; 40 60 _displayName = "ds:/"; 41 _path = "ds:/";42 61 _isValid = true; 43 62 _isDirectory = true; 44 _path = "ds:/";45 63 46 64 /* if (!_archive) { 47 65 _archive = (GBFS_FILE *) find_first_gbfs_file(scummdata); … … 56 74 DSFileSystemNode::DSFileSystemNode(const String& path) { 57 75 // consolePrintf("--%s ",path.c_str()); 58 76 59 char disp[128];60 char* pathStr = (char *) path.c_str();61 62 int lastSlash = 3;63 for (int r = 0; r < (int) strlen(pathStr) - 1; r++) {64 if (path[r] == '\\') {65 lastSlash = r;66 }67 }68 69 strcpy(disp, pathStr + lastSlash + 1);70 71 _displayName = String(disp);72 77 _path = path; 78 _displayName = lastPathComponentDS(_path); 73 79 // _isValid = true; 74 80 // _isDirectory = false; 75 81 82 char* pathStr = (char *) path.c_str(); 76 83 if (!strncmp(pathStr, "ds:/", 4)) { 77 84 pathStr += 4; 78 85 } … … 99 106 DSFileSystemNode::DSFileSystemNode(const String& path, bool isDir) { 100 107 // consolePrintf("--%s ",path.c_str()); 101 108 102 char disp[128];103 char* pathStr = (char *) path.c_str();104 int lastSlash = 3;105 for (int r = 0; r < (int) strlen(pathStr) - 1; r++) {106 if (path[r] == '\\') {107 lastSlash = r;108 }109 }110 111 strcpy(disp, pathStr + lastSlash + 1);112 113 _displayName = String(disp);114 109 _path = path; 110 _displayName = lastPathComponentDS(_path); 115 111 _isValid = true; 116 112 _isDirectory = isDir; 117 113 … … 206 202 // GBAMPFileSystemNode - File system using GBA Movie Player and CF card // 207 203 ////////////////////////////////////////////////////////////////////////// 208 204 209 GBAMPFileSystemNode::GBAMPFileSystemNode() { 210 _displayName = "mp:/"; 211 _path = "mp:/"; 212 _isValid = true; 213 _isDirectory = true; 214 _path = "mp:/"; 215 } 216 217 GBAMPFileSystemNode::GBAMPFileSystemNode(const String& path) { 218 // consolePrintf("'%s'",path.c_str()); 205 const char *lastPathComponentGBAMP(const Common::String &str) { 206 if (str.empty()) 207 return ""; 219 208 220 209 char disp[128]; 221 char* pathStr = (char *) path.c_str();210 char* pathStr = (char *) str.c_str(); 222 211 int lastSlash = 3; 212 223 213 for (int r = 0; r < (int) strlen(pathStr) - 1; r++) { 224 214 if ((path[r] == '\\') || (path[r] == '/')) { 225 215 lastSlash = r; … … 227 217 } 228 218 229 219 strcpy(disp, pathStr + lastSlash + 1); 220 221 return disp; 222 } 223 224 GBAMPFileSystemNode::GBAMPFileSystemNode() { 225 _path = "mp:/"; 226 _displayName = "mp:/"; 227 _isValid = true; 228 _isDirectory = true; 229 } 230 230 231 GBAMPFileSystemNode::GBAMPFileSystemNode(const String& path) { 232 // consolePrintf("'%s'",path.c_str()); 233 231 234 char check[128]; 232 235 int success; 233 236 … … 243 246 } 244 247 // consolePrintf("Path: %s (%d)\n", check, success); 245 248 246 _displayName = String(disp);247 249 _path = path; 250 _displayName = lastPathComponentGBAMP(_path); 248 251 _isValid = success == FT_FILE; 249 252 _isDirectory = success == FT_DIR; 250 253 } … … 252 255 GBAMPFileSystemNode::GBAMPFileSystemNode(const String& path, bool isDirectory) { 253 256 // consolePrintf("'%s'",path.c_str()); 254 257 255 char disp[128];256 char* pathStr = (char *) path.c_str();257 int lastSlash = 3;258 for (int r = 0; r < (int) strlen(pathStr) - 1; r++) {259 if ((path[r] == '\\') || (path[r] == '/')) {260 lastSlash = r;261 }262 }263 264 strcpy(disp, pathStr + lastSlash + 1);265 266 _displayName = String(disp);267 258 _path = path; 259 _displayName = lastPathComponentGBAMP(_path); 268 260 _isValid = true; 269 261 _isDirectory = isDirectory; 270 262 } -
home/david/Projects/scummvm/backends/fs/ds/ds-fs.h
83 83 virtual String getPath() const { return _path; } 84 84 virtual bool isDirectory() const { return _isDirectory; } 85 85 virtual bool isReadable() const { return true; } //FIXME: this is just a stub 86 virtual bool isValid() const { return _isValid; }87 86 virtual bool isWritable() const { return true; } //FIXME: this is just a stub 88 87 89 88 /** … … 149 148 virtual String getPath() const { return _path; } 150 149 virtual bool isDirectory() const { return _isDirectory; } 151 150 virtual bool isReadable() const { return true; } //FIXME: this is just a stub 152 virtual bool isValid() const { return _isValid; }153 151 virtual bool isWritable() const { return true; } //FIXME: this is just a stub 154 152 155 153 /** -
home/david/Projects/scummvm/backends/fs/gp32/gp32-fs.cpp
60 60 // FIXME: isValid should return false if this Node can't be used! 61 61 // so client code can rely on the return value. 62 62 virtual bool isReadable() const { return true; } //FIXME: this is just a stub 63 virtual bool isValid() const { return true; }64 63 virtual bool isWritable() const { return true; } //FIXME: this is just a stub 65 64 66 65 virtual AbstractFilesystemNode *getChild(const String &n) const; … … 82 81 * @return Pointer to the first char of the last component inside str. 83 82 */ 84 83 const char *lastPathComponent(const Common::String &str) { 84 if(str.empty()) 85 return ""; 86 85 87 const char *start = str.c_str(); 86 88 const char *cur = start + str.size() - 2; 87 89 -
home/david/Projects/scummvm/backends/fs/morphos/abox-fs.cpp
80 80 virtual String getPath() const { return _path; } 81 81 virtual bool isDirectory() const { return _isDirectory; } 82 82 virtual bool isReadable() const { return true; } //FIXME: this is just a stub 83 virtual bool isValid() const { return _isValid; }84 83 virtual bool isWritable() const { return true; } //FIXME: this is just a stub 85 84 86 85 virtual AbstractFilesystemNode *getChild(const String &name) const; … … 93 92 static AbstractFSList getRootChildren(); 94 93 }; 95 94 95 /** 96 * Returns the last component of a given path. 97 * 98 * @param str String containing the path. 99 * @return Pointer to the first char of the last component inside str. 100 */ 101 const char *lastPathComponent(const Common::String &str) { 102 if (str.empty()) 103 return ""; 104 105 const char *str = _path.c_str(); 106 while (offset > 0 && (str[offset-1] == '/' || str[offset-1] == ':') ) 107 offset--; 108 while (offset > 0 && (str[offset-1] != '/' && str[offset-1] != ':')) { 109 len++; 110 offset--; 111 } 112 113 return str + offset; 114 } 115 96 116 ABoxFilesystemNode::ABoxFilesystemNode() 97 117 { 118 _path = ""; 98 119 _displayName = "Mounted Volumes"; 99 120 _isValid = true; 100 121 _isDirectory = true; 101 _path = "";102 122 _lock = NULL; 103 123 } 104 124 … … 108 128 assert(offset > 0); 109 129 110 130 _path = p; 111 112 // Extract last component from path 113 const char *str = p.c_str(); 114 while (offset > 0 && (str[offset-1] == '/' || str[offset-1] == ':') ) 115 offset--; 116 while (offset > 0 && (str[offset-1] != '/' && str[offset-1] != ':')) { 117 len++; 118 offset--; 119 } 120 _displayName = String(str + offset, len); 131 _displayName = lastPathComponent(_path); 121 132 _lock = NULL; 122 133 _isDirectory = false; 123 134 … … 212 223 213 224 ABoxFilesystemNode::ABoxFilesystemNode(const ABoxFilesystemNode& node) 214 225 { 226 _path = node._path; 215 227 _displayName = node._displayName; 216 228 _isValid = node._isValid; 217 229 _isDirectory = node._isDirectory; 218 _path = node._path;219 230 _lock = DupLock(node._lock); 220 231 } 221 232 … … 299 310 entry = new ABoxFilesystemNode(lock, fib->fib_FileName); 300 311 if (entry) 301 312 { 302 if (entry->isValid()) 313 //FIXME: since the isValid() function is no longer part of the AbstractFilesystemNode 314 // specification, the following call had to be changed: 315 // if (entry->isValid()) 316 // Please verify that the logic of the code remains coherent. Also, remember 317 // that the isReadable() and isWritable() methods are available. 318 if (entry->exists()) 303 319 list.push_back(entry); 304 320 else 305 321 delete entry; … … 378 394 entry = new ABoxFilesystemNode(volume_lock, name); 379 395 if (entry) 380 396 { 381 if (entry->isValid()) 397 //FIXME: since the isValid() function is no longer part of the AbstractFilesystemNode 398 // specification, the following call had to be changed: 399 // if (entry->isValid()) 400 // Please verify that the logic of the code remains coherent. Also, remember 401 // that the isReadable() and isWritable() methods are available. 402 if (entry->exists()) 382 403 list.push_back(entry); 383 404 else 384 405 delete entry; -
home/david/Projects/scummvm/backends/fs/palmos/palmos-fs.cpp
61 61 virtual String getPath() const { return _path; } 62 62 virtual bool isDirectory() const { return _isDirectory; } 63 63 virtual bool isReadable() const { return true; } //FIXME: this is just a stub 64 virtual bool isValid() const { return _isValid; }65 64 virtual bool isWritable() const { return true; } //FIXME: this is just a stub 66 65 67 66 virtual AbstractFilesystemNode *getChild(const String &n) const; … … 92 91 * @return Pointer to the first char of the last component inside str. 93 92 */ 94 93 const char *lastPathComponent(const Common::String &str) { 94 if(str.empty()) 95 return ""; 96 95 97 const char *start = str.c_str(); 96 98 const char *cur = start + str.size() - 2; 97 99 … … 136 138 137 139 PalmOSFilesystemNode::PalmOSFilesystemNode(const String &p) { 138 140 _path = p; 139 _displayName = lastPathComponent( p);141 _displayName = lastPathComponent(_path); 140 142 141 143 UInt32 attr; 142 144 FileRef handle; -
home/david/Projects/scummvm/backends/fs/posix/posix-fs.cpp
91 91 * @return Pointer to the first char of the last component inside str. 92 92 */ 93 93 const char *lastPathComponent(const Common::String &str) { 94 if(str.empty()) 95 return ""; 96 94 97 const char *start = str.c_str(); 95 98 const char *cur = start + str.size() - 2; 96 99 -
home/david/Projects/scummvm/backends/fs/ps2/ps2-fs.cpp
68 68 virtual String getPath() const { return _path; } 69 69 virtual bool isDirectory() const { return _isDirectory; } 70 70 virtual bool isReadable() const { return true; } //FIXME: this is just a stub 71 virtual bool isValid() const { return !_isRoot; }72 71 virtual bool isWritable() const { return true; } //FIXME: this is just a stub 73 72 74 73 virtual AbstractFilesystemNode *clone() const { return new Ps2FilesystemNode(this); } … … 77 76 virtual AbstractFilesystemNode *getParent() const; 78 77 }; 79 78 79 /** 80 * Returns the last component of a given path. 81 * 82 * @param str String containing the path. 83 * @return Pointer to the first char of the last component inside str. 84 */ 85 const char *lastPathComponent(const Common::String &str) { 86 //FIXME: implement this method properly. 87 // This code is probably around the constructors, 88 // but I couldn't figure it out without having 89 // doubts on the correctness of my assumptions. 90 // Therefore, I leave it to the porter to correctly 91 // implement this method. 92 assert(false); 93 } 94 80 95 Ps2FilesystemNode::Ps2FilesystemNode() { 81 96 _isDirectory = true; 82 97 _isRoot = true; -
home/david/Projects/scummvm/backends/fs/psp/psp-fs.cpp
64 64 virtual String getPath() const { return _path; } 65 65 virtual bool isDirectory() const { return _isDirectory; } 66 66 virtual bool isReadable() const { return true; } //FIXME: this is just a stub 67 virtual bool isValid() const { return _isValid; }68 67 virtual bool isWritable() const { return true; } //FIXME: this is just a stub 69 68 70 69 virtual AbstractFilesystemNode *getChild(const String &n) const; … … 83 82 * @return Pointer to the first char of the last component inside str. 84 83 */ 85 84 const char *lastPathComponent(const Common::String &str) { 85 if(str.empty()) 86 return ""; 87 86 88 const char *start = str.c_str(); 87 89 const char *cur = start + str.size() - 2; 88 90 … … 170 172 } 171 173 172 174 AbstractFilesystemNode *PSPFilesystemNode::getParent() const { 173 assert(_isValid);174 175 175 if (_path == ROOT_PATH) 176 176 return 0; 177 177 -
home/david/Projects/scummvm/backends/fs/symbian/symbian-fs.cpp
64 64 virtual String getPath() const { return _path; } 65 65 virtual bool isDirectory() const { return _isDirectory; } 66 66 virtual bool isReadable() const { return true; } //FIXME: this is just a stub 67 virtual bool isValid() const { return _isValid; }68 67 virtual bool isWritable() const { return true; } //FIXME: this is just a stub 69 68 70 69 virtual AbstractFilesystemNode *getChild(const String &n) const; … … 83 82 * @return Pointer to the first char of the last component inside str. 84 83 */ 85 84 const char *lastPathComponent(const Common::String &str) { 85 if(str.empty()) 86 return ""; 87 86 88 const char *start = str.c_str(); 87 89 const char *cur = start + str.size() - 2; 88 90 -
home/david/Projects/scummvm/backends/fs/windows/windows-fs.cpp
92 92 virtual String getPath() const { return _path; } 93 93 virtual bool isDirectory() const { return _isDirectory; } 94 94 virtual bool isReadable() const { return _access(_path.c_str(), R_OK) == 0; } 95 virtual bool isValid() const { return _isValid; }96 95 virtual bool isWritable() const { return _access(_path.c_str(), W_OK) == 0; } 97 96 98 97 virtual AbstractFilesystemNode *getChild(const String &n) const; … … 139 138 * @return Pointer to the first char of the last component inside str. 140 139 */ 141 140 const char *lastPathComponent(const Common::String &str) { 141 if(str.empty()) 142 return ""; 143 142 144 const char *start = str.c_str(); 143 145 const char *cur = start + str.size() - 2; 144 146