Ticket #8727: lastPathComponent (2).patch
File lastPathComponent (2).patch, 39.4 KB (added by , 17 years ago) |
---|
-
home/david/Projects/scummvm/backends/fs/abstract-fs.h
Property changes on: /home/david/Projects/scummvm ___________________________________________________________________ Name: svn:ignore - config.log scummvm scummvm-static config.h config.mk .gdb_history dumps Credits.rtf *.mshark + .project
65 65 * @param name String containing the name of the child to create a new node. 66 66 */ 67 67 virtual AbstractFilesystemNode *getChild(const String &name) const = 0; 68 68 69 69 /** 70 70 * The parent node of this directory. 71 71 * The parent of the root is the root itself. … … 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
56 56 String _sPath; 57 57 bool _bIsDirectory; 58 58 bool _bIsValid; 59 59 60 60 public: 61 61 /** 62 62 * Creates a AmigaOSFilesystemNode with the root node as path. … … 89 89 90 90 virtual bool exists() const { return true; } //FIXME: this is just a stub 91 91 virtual String getDisplayName() const { return _sDisplayName; }; 92 virtual String getName() const { return _sDisplayName; };92 virtual String getName() const; 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 /**113 * Returns the last component of a given path.114 *115 * @param str String containing the path.116 * @return Pointer to the first char of the last component inside str.117 */118 const char *lastPathComponent(const Common::String &str) {119 int offset = str.size();120 const char *p = str.c_str();121 122 while (offset > 0 && (p[offset-1] == '/' || p[offset-1] == ':'))123 offset--;124 125 while (offset > 0 && (p[offset-1] != '/' && p[offset-1] != ':'))126 offset--;127 128 return p + offset;129 }130 131 108 AmigaOSFilesystemNode::AmigaOSFilesystemNode() { 132 109 ENTER(); 133 110 _sDisplayName = "Available Disks"; … … 151 128 } 152 129 153 130 _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); 131 _sDisplayName = getName(); 167 132 _pFileLock = 0; 168 133 _bIsDirectory = false; 169 134 … … 352 317 if (lock) { 353 318 AmigaOSFilesystemNode *entry = new AmigaOSFilesystemNode(lock, (char *)ead->ed_Name); 354 319 if (entry) { 355 if (entry->isValid()) 320 //FIXME: since the isValid() function is no longer part of the AbstractFilesystemNode 321 // specification, the following call had to be changed: 322 // if (entry->isValid()) 323 // Please verify that the logic of the code remains coherent. Also, remember 324 // that the isReadable() and isWritable() methods are available. 325 if (entry->exists()) 356 326 myList.push_back(entry); 357 327 else 358 328 delete entry; … … 375 345 return true; 376 346 } 377 347 348 Common::String AmigaOSFilesystemNode::getName() const { 349 if (_sPath == "") 350 return ""; 351 352 int offset = _sPath.size(); 353 354 if (offset <= 0) { 355 debug(6, "Bad offset"); 356 return; 357 } 358 359 const char *str = _sPath.c_str(); 360 361 while (offset > 0 && (str[offset-1] == '/' || str[offset-1] == ':')) 362 offset--; 363 364 while (offset > 0 && (str[offset-1] != '/' && str[offset-1] != ':')) { 365 len++; 366 offset--; 367 } 368 369 return Common::String(str + offset, len); 370 } 371 378 372 AbstractFilesystemNode *AmigaOSFilesystemNode::getParent() const { 379 373 ENTER(); 380 374 … … 453 447 454 448 AmigaOSFilesystemNode *entry = new AmigaOSFilesystemNode(volumeLock, buffer); 455 449 if (entry) { 456 if (entry->isValid()) 450 //FIXME: since the isValid() function is no longer part of the AbstractFilesystemNode 451 // specification, the following call had to be changed: 452 // if (entry->isValid()) 453 // Please verify that the logic of the code remains coherent. Also, remember 454 // that the isReadable() and isWritable() methods are available. 455 if(entry->exists()) 457 456 myList.push_back(entry); 458 457 else 459 458 delete entry; -
home/david/Projects/scummvm/backends/fs/dc/dc-fs.cpp
58 58 59 59 virtual bool exists() const { return true; } //FIXME: this is just a stub 60 60 virtual String getDisplayName() const { return _displayName; } 61 virtual String getName() const { return _displayName; }61 virtual String getName() const; 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; … … 70 69 virtual AbstractFilesystemNode *getParent() const; 71 70 }; 72 71 73 /**74 * Returns the last component of a given path.75 *76 * Examples:77 * /foo/bar.txt would return /bar.txt78 * /foo/bar/ would return /bar/79 *80 * @param str String containing the path.81 * @return Pointer to the first char of the last component inside str.82 */83 const char *lastPathComponent(const Common::String &str) {84 const char *start = str.c_str();85 const char *cur = start + str.size() - 2;86 87 while (cur >= start && *cur != '/') {88 --cur;89 }90 91 return cur + 1;92 }93 94 72 RoninCDFilesystemNode::RoninCDFilesystemNode() { 95 73 // The root dir. 96 74 _path = "/"; … … 103 81 assert(p.size() > 0); 104 82 105 83 _path = p; 106 _displayName = lastPathComponent(_path);84 _displayName = getName(); 107 85 _isValid = true; 108 86 _isDirectory = true; 109 87 … … 178 156 return true; 179 157 } 180 158 159 /** 160 * Returns the last component of _path. 161 * 162 * Examples: 163 * /foo/bar.txt would return /bar.txt 164 * /foo/bar/ would return /bar/ 165 */ 166 String RoninCDFilesystemNode::getName() const { 167 if (_path == "") 168 return ""; 169 170 const char *start = _path.c_str(); 171 const char *cur = start + _path.size() - 2; 172 173 while (cur >= start && *cur != '/') { 174 --cur; 175 } 176 177 return String(cur + 1); 178 } 179 181 180 AbstractFilesystemNode *RoninCDFilesystemNode::getParent() const { 182 181 if (_path == "/") 183 182 return 0; … … 183 182 return 0; 184 183 185 184 const char *start = _path.c_str(); 186 const char *end = lastPathComponent(_path);185 const char *end = getName().c_str(); 187 186 188 187 return new RoninCDFilesystemNode(String(start, end - start), false); 189 188 } -
home/david/Projects/scummvm/backends/fs/ds/ds-fs.cpp
37 37 char currentDir[128]; 38 38 39 39 DSFileSystemNode::DSFileSystemNode() { 40 _path = "ds:/"; 40 41 _displayName = "ds:/"; 41 _path = "ds:/";42 42 _isValid = true; 43 43 _isDirectory = true; 44 _path = "ds:/";45 44 46 45 /* if (!_archive) { 47 46 _archive = (GBFS_FILE *) find_first_gbfs_file(scummdata); … … 56 55 DSFileSystemNode::DSFileSystemNode(const String& path) { 57 56 // consolePrintf("--%s ",path.c_str()); 58 57 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 58 _path = path; 59 _displayName = getName(); 73 60 // _isValid = true; 74 61 // _isDirectory = false; 75 62 63 char* pathStr = (char *) path.c_str(); 76 64 if (!strncmp(pathStr, "ds:/", 4)) { 77 65 pathStr += 4; 78 66 } … … 99 87 DSFileSystemNode::DSFileSystemNode(const String& path, bool isDir) { 100 88 // consolePrintf("--%s ",path.c_str()); 101 89 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 90 _path = path; 91 _displayName = getName(); 115 92 _isValid = true; 116 93 _isDirectory = isDir; 117 94 … … 179 156 return true; 180 157 } 181 158 159 String DSFileSystemNode::getName() const { 160 if (_path == "") 161 return ""; 162 163 char disp[128]; 164 char* pathStr = (char *) _path.c_str(); 165 int lastSlash = 3; 166 167 for (int r = 0; r < (int) strlen(pathStr) - 1; r++) { 168 if (path[r] == '\\') { 169 lastSlash = r; 170 } 171 } 172 173 strcpy(disp, pathStr + lastSlash + 1); 174 175 return String(disp); 176 } 177 182 178 AbstractFilesystemNode* DSFileSystemNode::getParent() const { 183 179 // consolePrintf("parent\n"); 184 180 DSFileSystemNode *p; … … 207 203 ////////////////////////////////////////////////////////////////////////// 208 204 209 205 GBAMPFileSystemNode::GBAMPFileSystemNode() { 206 _path = "mp:/"; 210 207 _displayName = "mp:/"; 211 _path = "mp:/";212 208 _isValid = true; 213 209 _isDirectory = true; 214 _path = "mp:/";215 210 } 216 211 217 212 GBAMPFileSystemNode::GBAMPFileSystemNode(const String& path) { … … 217 212 GBAMPFileSystemNode::GBAMPFileSystemNode(const String& path) { 218 213 // consolePrintf("'%s'",path.c_str()); 219 214 220 char disp[128];221 char* pathStr = (char *) path.c_str();222 int lastSlash = 3;223 for (int r = 0; r < (int) strlen(pathStr) - 1; r++) {224 if ((path[r] == '\\') || (path[r] == '/')) {225 lastSlash = r;226 }227 }228 229 strcpy(disp, pathStr + lastSlash + 1);230 231 215 char check[128]; 232 216 int success; 233 217 … … 243 227 } 244 228 // consolePrintf("Path: %s (%d)\n", check, success); 245 229 246 _displayName = String(disp);247 230 _path = path; 231 _displayName = getName(); 248 232 _isValid = success == FT_FILE; 249 233 _isDirectory = success == FT_DIR; 250 234 } … … 252 236 GBAMPFileSystemNode::GBAMPFileSystemNode(const String& path, bool isDirectory) { 253 237 // consolePrintf("'%s'",path.c_str()); 254 238 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 239 _path = path; 240 _displayName = getName(); 268 241 _isValid = true; 269 242 _isDirectory = isDirectory; 270 243 } … … 340 313 return true; 341 314 } 342 315 316 String GBAMPFileSystemNode::getName() const { 317 if (_path == "") 318 return ""; 319 320 char disp[128]; 321 char* pathStr = (char *) _path.c_str(); 322 int lastSlash = 3; 323 324 for (int r = 0; r < (int) strlen(pathStr) - 1; r++) { 325 if ((path[r] == '\\') || (path[r] == '/')) { 326 lastSlash = r; 327 } 328 } 329 330 strcpy(disp, pathStr + lastSlash + 1); 331 332 return String(disp); 333 } 334 343 335 AbstractFilesystemNode* GBAMPFileSystemNode::getParent() const { 344 336 // consolePrintf("parent\n"); 345 337 GBAMPFileSystemNode *p; -
home/david/Projects/scummvm/backends/fs/ds/ds-fs.h
79 79 80 80 virtual bool exists() const { return true; } //FIXME: this is just a stub 81 81 virtual String getDisplayName() const { return _displayName; } 82 virtual String getName() const { return _displayName; }82 virtual String getName() const; 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 /** … … 145 144 146 145 virtual bool exists() const { return true; } //FIXME: this is just a stub 147 146 virtual String getDisplayName() const { return _displayName; } 148 virtual String getName() const { return _displayName; }147 virtual String getName() const; 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
54 54 55 55 virtual bool exists() const { return true; } //FIXME: this is just a stub 56 56 virtual String getDisplayName() const { return _displayName; } 57 virtual String getName() const { return _displayName; }57 virtual String getName() const; 58 58 virtual String getPath() const { return _path; } 59 59 virtual bool isDirectory() const { return _isDirectory; } 60 60 // FIXME: isValid should return false if this Node can't be used! … … 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; … … 72 71 //char gpCurrentPath[MAX_PATH_SIZE] = "gp:\\"; // must end with '\' 73 72 74 73 /** 75 * Returns the last component of a given path.76 *77 * Examples:78 * gp:\foo\bar.txt would return "\bar.txt"79 * gp:\foo\bar\ would return "\bar\"80 *81 * @param str Path to obtain the last component from.82 * @return Pointer to the first char of the last component inside str.83 */84 const char *lastPathComponent(const Common::String &str) {85 const char *start = str.c_str();86 const char *cur = start + str.size() - 2;87 88 while (cur >= start && *cur != '\\') {89 --cur;90 }91 92 return cur + 1;93 }94 95 /**96 74 * FIXME: document this function. 97 75 * 98 76 * @param path … … 239 217 return true; 240 218 } 241 219 220 /** 221 * Returns the last component of _path. 222 * 223 * Examples: 224 * gp:\foo\bar.txt would return "\bar.txt" 225 * gp:\foo\bar\ would return "\bar\" 226 */ 227 String GP32FilesystemNode::getName() const { 228 if (_path == "") 229 return ""; 230 231 const char *start = _path.c_str(); 232 const char *cur = start + _path.size() - 2; 233 234 while (cur >= start && *cur != '\\') { 235 --cur; 236 } 237 238 return String(cur + 1); 239 } 240 242 241 AbstractFilesystemNode *GP32FilesystemNode::getParent() const { 243 242 if (_isRoot) 244 243 return 0; … … 244 243 return 0; 245 244 246 245 const char *start = _path.c_str(); 247 const char *end = lastPathComponent(_path);246 const char *end = getName().c_str(); 248 247 249 248 GP32FilesystemNode *p = new GP32FilesystemNode(String(start, end - start)); 250 249 -
home/david/Projects/scummvm/backends/fs/morphos/abox-fs.cpp
45 45 String _path; 46 46 bool _isDirectory; 47 47 bool _isValid; 48 48 49 49 public: 50 50 /** 51 51 * Creates a ABoxFilesystemNode with the root node as path. … … 76 76 77 77 virtual bool exists() const { return true; } //FIXME: this is just a stub 78 78 virtual String getDisplayName() const { return _displayName; } 79 virtual String getName() const { return _displayName; };79 virtual String getName() const; 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; … … 95 94 96 95 ABoxFilesystemNode::ABoxFilesystemNode() 97 96 { 97 _path = ""; 98 98 _displayName = "Mounted Volumes"; 99 99 _isValid = true; 100 100 _isDirectory = true; 101 _path = "";102 101 _lock = NULL; 103 102 } 104 103 … … 108 107 assert(offset > 0); 109 108 110 109 _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); 110 _displayName = getName(); 121 111 _lock = NULL; 122 112 _isDirectory = false; 123 113 … … 127 117 debug(6, "FileInfoBlock is NULL"); 128 118 return; 129 119 } 130 120 131 121 // Check whether the node exists and if it is a directory 132 122 BPTR pLock = Lock((STRPTR)_path.c_str(), SHARED_LOCK); 133 123 if (pLock) … … 212 202 213 203 ABoxFilesystemNode::ABoxFilesystemNode(const ABoxFilesystemNode& node) 214 204 { 205 _path = node._path; 215 206 _displayName = node._displayName; 216 207 _isValid = node._isValid; 217 208 _isDirectory = node._isDirectory; 218 _path = node._path;219 209 _lock = DupLock(node._lock); 220 210 } 221 211 … … 299 289 entry = new ABoxFilesystemNode(lock, fib->fib_FileName); 300 290 if (entry) 301 291 { 302 if (entry->isValid()) 292 //FIXME: since the isValid() function is no longer part of the AbstractFilesystemNode 293 // specification, the following call had to be changed: 294 // if (entry->isValid()) 295 // Please verify that the logic of the code remains coherent. Also, remember 296 // that the isReadable() and isWritable() methods are available. 297 if (entry->exists()) 303 298 list.push_back(entry); 304 299 else 305 300 delete entry; … … 318 313 return true; 319 314 } 320 315 316 String ABoxFilesystemNode::getName() const { 317 if (_path == "") 318 return ""; 319 320 const char *str = _path.c_str(); 321 while (offset > 0 && (str[offset-1] == '/' || str[offset-1] == ':') ) 322 offset--; 323 while (offset > 0 && (str[offset-1] != '/' && str[offset-1] != ':')) { 324 len++; 325 offset--; 326 } 327 328 return String(str + offset, len); 329 } 330 321 331 AbstractFilesystemNode *ABoxFilesystemNode::getParent() const 322 332 { 323 333 AbstractFilesystemNode *node = NULL; … … 378 388 entry = new ABoxFilesystemNode(volume_lock, name); 379 389 if (entry) 380 390 { 381 if (entry->isValid()) 391 //FIXME: since the isValid() function is no longer part of the AbstractFilesystemNode 392 // specification, the following call had to be changed: 393 // if (entry->isValid()) 394 // Please verify that the logic of the code remains coherent. Also, remember 395 // that the isReadable() and isWritable() methods are available. 396 if (entry->exists()) 382 397 list.push_back(entry); 383 398 else 384 399 delete entry; -
home/david/Projects/scummvm/backends/fs/palmos/palmos-fs.cpp
57 57 58 58 virtual bool exists() const { return true; } //FIXME: this is just a stub 59 59 virtual String getDisplayName() const { return _displayName; } 60 virtual String getName() const { return _displayName; }60 virtual String getName() const; 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; … … 81 80 static void addFile(AbstractFSList &list, ListMode mode, const Char *base, FileInfoType* find_data); 82 81 }; 83 82 84 /**85 * Returns the last component of a given path.86 *87 * Examples:88 * /foo/bar.txt would return /bar.txt89 * /foo/bar/ would return /bar/90 *91 * @param str String containing the path.92 * @return Pointer to the first char of the last component inside str.93 */94 const char *lastPathComponent(const Common::String &str) {95 const char *start = str.c_str();96 const char *cur = start + str.size() - 2;97 98 while (cur >= start && *cur != '/') {99 --cur;100 }101 102 return cur + 1;103 }104 105 83 void PalmOSFilesystemNode::addFile(AbstractFSList &list, ListMode mode, const char *base, FileInfoType* find_data) { 106 84 PalmOSFilesystemNode entry; 107 85 bool isDir; … … 136 114 137 115 PalmOSFilesystemNode::PalmOSFilesystemNode(const String &p) { 138 116 _path = p; 139 _displayName = lastPathComponent(p);117 _displayName = getName(); 140 118 141 119 UInt32 attr; 142 120 FileRef handle; … … 208 186 return true; 209 187 } 210 188 189 /** 190 * Returns the last component of _path. 191 * 192 * Examples: 193 * /foo/bar.txt would return /bar.txt 194 * /foo/bar/ would return /bar/ 195 */ 196 Common::String PalmOSFilesystemNode::getName() const { 197 if (_path == "") 198 return ""; 199 200 const char *start = _path.c_str(); 201 const char *cur = start + _path.size() - 2; 202 203 while (cur >= start && *cur != '/') { 204 --cur; 205 } 206 207 return Common::String(cur + 1); 208 } 209 211 210 AbstractFilesystemNode *PalmOSFilesystemNode::getParent() const { 212 211 PalmOSFilesystemNode *p = 0; 213 212 … … 213 212 214 213 if (!_isPseudoRoot) { 215 214 const char *start = _path.c_str(); 216 const char *end = lastPathComponent(_path);215 const char *end = getName().c_str(); 217 216 218 217 p = new PalmOSFilesystemNode(); 219 218 p->_path = String(start, end - start); … … 219 218 p->_path = String(start, end - start); 220 219 p->_isValid = true; 221 220 p->_isDirectory = true; 222 p->_displayName = lastPathComponent(p->_path);221 p->_displayName = p->getName(); 223 222 p->_isPseudoRoot =(p->_path == "/"); 224 223 } 225 224 -
home/david/Projects/scummvm/backends/fs/posix/posix-fs.cpp
46 46 String _path; 47 47 bool _isDirectory; 48 48 bool _isValid; 49 49 50 50 public: 51 51 /** 52 52 * Creates a POSIXFilesystemNode with the root node as path. … … 63 63 64 64 virtual bool exists() const { return access(_path.c_str(), F_OK) == 0; } 65 65 virtual String getDisplayName() const { return _displayName; } 66 virtual String getName() const { return _displayName; }66 virtual String getName() const; 67 67 virtual String getPath() const { return _path; } 68 68 virtual bool isDirectory() const { return _isDirectory; } 69 69 virtual bool isReadable() const { return access(_path.c_str(), R_OK) == 0; } … … 80 80 virtual void setFlags(); 81 81 }; 82 82 83 /**84 * Returns the last component of a given path.85 *86 * Examples:87 * /foo/bar.txt would return /bar.txt88 * /foo/bar/ would return /bar/89 *90 * @param str String containing the path.91 * @return Pointer to the first char of the last component inside str.92 */93 const char *lastPathComponent(const Common::String &str) {94 const char *start = str.c_str();95 const char *cur = start + str.size() - 2;96 97 while (cur >= start && *cur != '/') {98 --cur;99 }100 101 return cur + 1;102 }103 104 83 void POSIXFilesystemNode::setFlags() { 105 84 struct stat st; 106 85 … … 141 120 assert(p.size() > 0); 142 121 143 122 _path = p; 144 _displayName = lastPathComponent(_path);123 _displayName = getName(); 145 124 146 125 if (verify) { 147 126 setFlags(); … … 235 214 return true; 236 215 } 237 216 217 /** 218 * Returns the last component of _path. 219 * 220 * Examples: 221 * /foo/bar.txt would return /bar.txt 222 * /foo/bar/ would return /bar/ 223 */ 224 Common::String POSIXFilesystemNode::getName() const { 225 if (_path == "") 226 return ""; 227 228 const char *start = _path.c_str(); 229 const char *cur = start + _path.size() - 2; 230 231 while (cur >= start && *cur != '/') { 232 --cur; 233 } 234 235 return Common::String(cur + 1); 236 } 237 238 238 AbstractFilesystemNode *POSIXFilesystemNode::getParent() const { 239 239 if (_path == "/") 240 240 return 0; … … 240 240 return 0; 241 241 242 242 const char *start = _path.c_str(); 243 const char *end = lastPathComponent(_path);243 const char *end = getName().c_str(); 244 244 245 245 return new POSIXFilesystemNode(String(start, end - start), true); 246 246 } -
home/david/Projects/scummvm/backends/fs/ps2/ps2-fs.cpp
43 43 String _path; 44 44 bool _isDirectory; 45 45 bool _isRoot; 46 46 47 47 public: 48 48 /** 49 49 * Creates a PS2FilesystemNode with the root node as path. … … 64 64 65 65 virtual bool exists() const { return true; } //FIXME: this is just a stub 66 66 virtual String getDisplayName() const { return _displayName; } 67 virtual String getName() const { return _displayName; }67 virtual String getName() const; 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); } … … 218 217 } 219 218 } 220 219 220 String *Ps2FilesystemNode::getName() const { 221 //FIXME: implement this method properly 222 assert(false); 223 } 224 221 225 AbstractFilesystemNode *Ps2FilesystemNode::getParent() const { 222 226 if (_isRoot) 223 227 return new Ps2FilesystemNode(this); -
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; … … 72 71 virtual AbstractFilesystemNode *getParent() const; 73 72 }; 74 73 75 /**76 * Returns the last component of a given path.77 *78 * Examples:79 * /foo/bar.txt would return /bar.txt80 * /foo/bar/ would return /bar/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 const char *start = str.c_str();87 const char *cur = start + str.size() - 2;88 89 while (cur >= start && *cur != '/') {90 --cur;91 }92 93 return cur + 1;94 }95 96 74 PSPFilesystemNode::PSPFilesystemNode() { 97 75 _isDirectory = true; 98 76 _displayName = "Root"; … … 104 82 assert(p.size() > 0); 105 83 106 84 _path = p; 107 _displayName = lastPathComponent(_path);85 _displayName = getName(); 108 86 _isValid = true; 109 87 _isDirectory = true; 110 88 … … 169 147 } 170 148 } 171 149 150 /** 151 * Returns the last component of _path. 152 * 153 * Examples: 154 * /foo/bar.txt would return /bar.txt 155 * /foo/bar/ would return /bar/ 156 */ 157 String PSPFilesystemNode::getName() const { 158 if (_path == "") 159 return ""; 160 161 const char *start = _path.c_str(); 162 const char *cur = start + _path.size() - 2; 163 164 while (cur >= start && *cur != '/') { 165 --cur; 166 } 167 168 return String(cur + 1); 169 } 170 172 171 AbstractFilesystemNode *PSPFilesystemNode::getParent() const { 173 assert(_isValid);172 //assert(_isValid); 174 173 175 174 if (_path == ROOT_PATH) 176 175 return 0; … … 176 175 return 0; 177 176 178 177 const char *start = _path.c_str(); 179 const char *end = lastPathComponent(_path);178 const char *end = getName().c_str(); 180 179 181 180 return new PSPFilesystemNode(String(start, end - start), false); 182 181 } -
home/david/Projects/scummvm/backends/fs/symbian/symbian-fs.cpp
42 42 bool _isDirectory; 43 43 bool _isValid; 44 44 bool _isPseudoRoot; 45 45 46 46 public: 47 47 /** 48 48 * Creates a SymbianFilesystemNode with the root node as path. … … 60 60 61 61 virtual bool exists() const { return true; } //FIXME: this is just a stub 62 62 virtual String getDisplayName() const { return _displayName; } 63 virtual String getName() const { return _displayName; }63 virtual String getName() const; 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; … … 73 72 }; 74 73 75 74 /** 76 * Returns the last component of a given path.77 *78 * Examples:79 * c:\foo\bar.txt would return "\bar.txt"80 * c:\foo\bar\ would return "\bar\"81 *82 * @param str Path to obtain the last component from.83 * @return Pointer to the first char of the last component inside str.84 */85 const char *lastPathComponent(const Common::String &str) {86 const char *start = str.c_str();87 const char *cur = start + str.size() - 2;88 89 while (cur >= start && *cur != '\\') {90 --cur;91 }92 93 return cur + 1;94 }95 96 /**97 75 * Fixes the path by changing all slashes to backslashes. 98 76 * 99 77 * @param path String with the path to be fixed. … … 127 105 128 106 fixFilePath(_path); 129 107 130 _displayName = lastPathComponent(_path);108 _displayName = getName(); 131 109 132 110 TEntry fileAttribs; 133 111 TFileName fname; … … 240 218 return true; 241 219 } 242 220 221 /** 222 * Returns the last component of _path. 223 * 224 * Examples: 225 * c:\foo\bar.txt would return "\bar.txt" 226 * c:\foo\bar\ would return "\bar\" 227 */ 228 Common::String SymbianFilesystemNode::getName() { 229 if (_path == "") 230 return ""; 231 232 const char *start = _path.c_str(); 233 const char *cur = start + _path.size() - 2; 234 235 while (cur >= start && *cur != '\\') { 236 --cur; 237 } 238 239 return Common::String(cur + 1); 240 } 241 243 242 AbstractFilesystemNode *SymbianFilesystemNode::getParent() const { 244 243 SymbianFilesystemNode *p =NULL; 245 244 … … 248 247 if (!_isPseudoRoot && _path.size() > 3) { 249 248 p = new SymbianFilesystemNode(false); 250 249 const char *start = _path.c_str(); 251 const char *end = lastPathComponent(_path);250 const char *end = getName().c_str(); 252 251 253 252 p->_path = String(start, end - start); 254 253 p->_isValid = true; … … 253 252 p->_path = String(start, end - start); 254 253 p->_isValid = true; 255 254 p->_isDirectory = true; 256 p->_displayName = lastPathComponent(p->_path);255 p->_displayName = p->getName(); 257 256 } 258 257 else 259 258 { -
home/david/Projects/scummvm/backends/fs/windows/windows-fs.cpp
63 63 bool _isDirectory; 64 64 bool _isPseudoRoot; 65 65 bool _isValid; 66 66 67 67 public: 68 68 /** 69 69 * Creates a WindowsFilesystemNode with the root node as path. … … 88 88 89 89 virtual bool exists() const { return _access(_path.c_str(), F_OK) == 0; } 90 90 virtual String getDisplayName() const { return _displayName; } 91 virtual String getName() const { return _displayName; }91 virtual String getName() const; 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; … … 128 127 static const TCHAR* toUnicode(const char *str); 129 128 }; 130 129 131 /**132 * Returns the last component of a given path.133 *134 * Examples:135 * c:\foo\bar.txt would return "\bar.txt"136 * c:\foo\bar\ would return "\bar\"137 *138 * @param str Path to obtain the last component from.139 * @return Pointer to the first char of the last component inside str.140 */141 const char *lastPathComponent(const Common::String &str) {142 const char *start = str.c_str();143 const char *cur = start + str.size() - 2;144 145 while (cur >= start && *cur != '\\') {146 --cur;147 }148 149 return cur + 1;150 }151 152 130 void WindowsFilesystemNode::addFile(AbstractFSList &list, ListMode mode, const char *base, WIN32_FIND_DATA* find_data) { 153 131 WindowsFilesystemNode entry; 154 132 char *asciiName = toAscii(find_data->cFileName); … … 222 200 assert(p.size() > 0); 223 201 _path = p; 224 202 } 225 226 _displayName = lastPathComponent(_path);203 204 _displayName = getName(); 227 205 228 206 // Check whether it is a directory, and whether the file actually exists 229 207 DWORD fileAttribs = GetFileAttributes(toUnicode(_path.c_str())); … … 309 287 return true; 310 288 } 311 289 290 /** 291 * Returns the last component of _path. 292 * 293 * Examples: 294 * c:\foo\bar.txt would return "\bar.txt" 295 * c:\foo\bar\ would return "\bar\" 296 */ 297 String WindowsFilesystemNode::getName() const { 298 if (_path == "") 299 return ""; 300 301 const char *start = _path.c_str(); 302 const char *cur = start + _path.size() - 2; 303 304 while (cur >= start && *cur != '\\') { 305 --cur; 306 } 307 308 return String(cur + 1); 309 } 310 312 311 AbstractFilesystemNode *WindowsFilesystemNode::getParent() const { 313 312 assert(_isValid || _isPseudoRoot); 314 313 … … 318 317 WindowsFilesystemNode *p = new WindowsFilesystemNode(); 319 318 if (_path.size() > 3) { 320 319 const char *start = _path.c_str(); 321 const char *end = lastPathComponent(_path);320 const char *end = getName().c_str(); 322 321 323 322 p = new WindowsFilesystemNode(); 324 323 p->_path = String(start, end - start); … … 324 323 p->_path = String(start, end - start); 325 324 p->_isValid = true; 326 325 p->_isDirectory = true; 327 p->_displayName = lastPathComponent(p->_path);326 p->_displayName = p->getName); 328 327 p->_isPseudoRoot = false; 329 328 } 330 329 -
home/david/Projects/scummvm/common/fs.cpp
26 26 #include "backends/fs/abstract-fs.h" 27 27 #include "backends/fs/abstract-fs-factory.h" 28 28 29 /**30 * Simple DOS-style pattern matching function (understands * and ? like used in DOS).31 * Taken from exult/files/listfiles.cc32 */33 static bool matchString(const char *str, const char *pat) {34 const char *p = 0;35 const char *q = 0;36 37 for (;;) {38 switch (*pat) {39 case '*':40 p = ++pat;41 q = str;42 break;43 44 default:45 if (*pat != *str) {46 if (p) {47 pat = p;48 str = ++q;49 if (!*str)50 return !*pat;51 break;52 }53 else54 return false;55 }56 // fallthrough57 case '?':58 if (!*str)59 return !*pat;60 pat++;61 str++;62 }63 }64 }65 66 29 FilesystemNode::FilesystemNode() { 67 30 _realNode = 0; 68 31 _refCount = 0; … … 233 196 return ((matches > 0) ? true : false); 234 197 } 235 198 236 // HACK HACK HACK237 extern const char *lastPathComponent(const Common::String &str);238 239 199 int FilesystemNode::lookupFileRec(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const 240 200 { 241 201 FSList entries; … … 242 202 FSList children; 243 203 int matches = 0; 244 204 dir.getChildren(entries, FilesystemNode::kListAll, hidden); 245 205 246 206 //Breadth search (entries in the same level) 247 207 for (FSList::iterator entry = entries.begin(); entry != entries.end(); ++entry) { 248 208 if (entry->isDirectory()) { … … 248 208 if (entry->isDirectory()) { 249 209 children.push_back(*entry); 250 210 } else { 251 //TODO: here we assume all backends implement the lastPathComponent method. It is currently static, 252 // so it might be a good idea to include it inside the backend class. This would enforce its 253 // implementation by all ports. 254 if (matchString(lastPathComponent(entry->getPath()), filename.c_str())) { 211 if (Common::matchString(entry->getName().c_str(), filename.c_str())) { 255 212 results.push_back(*entry); 256 213 matches++; 257 214 -
home/david/Projects/scummvm/common/util.cpp
61 61 62 62 namespace Common { 63 63 64 bool matchString(const char *str, const char *pat) { 65 const char *p = 0; 66 const char *q = 0; 67 68 for (;;) { 69 switch (*pat) { 70 case '*': 71 p = ++pat; 72 q = str; 73 break; 74 75 default: 76 if (*pat != *str) { 77 if (p) { 78 pat = p; 79 str = ++q; 80 if (!*str) 81 return !*pat; 82 break; 83 } 84 else 85 return false; 86 } 87 // fallthrough 88 case '?': 89 if (!*str) 90 return !*pat; 91 pat++; 92 str++; 93 } 94 } 95 } 96 64 97 // 65 98 // Print hexdump of the data passed in 66 99 // -
home/david/Projects/scummvm/common/util.h
53 53 namespace Common { 54 54 55 55 /** 56 * Simple DOS-style pattern matching function (understands * and ? like used in DOS). 57 * Taken from exult/files/listfiles.cc 58 * 59 * Token meaning: 60 * "*": any character, any amount of times. 61 * "?": any character, only once. 62 * 63 * Example strings/patterns: 64 * String: monkey.s?? Pattern: monkey.s01 => true 65 * String: monkey.s?? Pattern: monkey.s99 => true 66 * String: monkey.s?? Pattern: monkey.s101 => false 67 * String: monkey.s?1 Pattern: monkey.s01 => true 68 * String: monkey.s?1 Pattern: monkey.s99 => false 69 * String: monkey.s?1 Pattern: monkey.s101 => false 70 * String: monkey.s* Pattern: monkey.s01 => true 71 * String: monkey.s* Pattern: monkey.s99 => true 72 * String: monkey.s* Pattern: monkey.s101 => true 73 * String: monkey.s*1 Pattern: monkey.s01 => true 74 * String: monkey.s*1 Pattern: monkey.s99 => false 75 * String: monkey.s*1 Pattern: monkey.s101 => true 76 * 77 * @param str Text to be matched against the given pattern. 78 * @param pat Glob pattern. 79 * 80 * @return true if str matches the pattern, false otherwise. 81 */ 82 bool matchString(const char *str, const char *pat); 83 84 /** 56 85 * Print a hexdump of the data passed in. The number of bytes per line is 57 86 * customizable. 58 87 * @param data the data to be dumped