Modified version of the mbed library for use with the Nucleo boards.
Dependents: EEPROMWrite Full-Project
Fork of mbed-src by
common/FilePath.cpp@10:3bc89ef62ce7, 2013-06-14 (annotated)
- Committer:
- emilmont
- Date:
- Fri Jun 14 17:49:17 2013 +0100
- Revision:
- 10:3bc89ef62ce7
- Parent:
- 9:0ce32e54c9a7
- Child:
- 13:0645d8841f51
Unify mbed library sources
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 10:3bc89ef62ce7 | 1 | /* mbed Microcontroller Library |
emilmont | 10:3bc89ef62ce7 | 2 | * Copyright (c) 2006-2013 ARM Limited |
emilmont | 10:3bc89ef62ce7 | 3 | * |
emilmont | 10:3bc89ef62ce7 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
emilmont | 10:3bc89ef62ce7 | 5 | * you may not use this file except in compliance with the License. |
emilmont | 10:3bc89ef62ce7 | 6 | * You may obtain a copy of the License at |
emilmont | 10:3bc89ef62ce7 | 7 | * |
emilmont | 10:3bc89ef62ce7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
emilmont | 10:3bc89ef62ce7 | 9 | * |
emilmont | 10:3bc89ef62ce7 | 10 | * Unless required by applicable law or agreed to in writing, software |
emilmont | 10:3bc89ef62ce7 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
emilmont | 10:3bc89ef62ce7 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
emilmont | 10:3bc89ef62ce7 | 13 | * See the License for the specific language governing permissions and |
emilmont | 10:3bc89ef62ce7 | 14 | * limitations under the License. |
emilmont | 10:3bc89ef62ce7 | 15 | */ |
emilmont | 10:3bc89ef62ce7 | 16 | #include "FilePath.h" |
emilmont | 10:3bc89ef62ce7 | 17 | |
emilmont | 10:3bc89ef62ce7 | 18 | namespace mbed { |
emilmont | 10:3bc89ef62ce7 | 19 | |
emilmont | 10:3bc89ef62ce7 | 20 | FilePath::FilePath(const char* file_path) : file_name(NULL), fb(NULL) { |
emilmont | 10:3bc89ef62ce7 | 21 | if ((file_path[0] != '/') || (file_path[1] == 0)) return; |
emilmont | 10:3bc89ef62ce7 | 22 | |
emilmont | 10:3bc89ef62ce7 | 23 | const char* file_system = &file_path[1]; |
emilmont | 10:3bc89ef62ce7 | 24 | file_name = file_system; |
emilmont | 10:3bc89ef62ce7 | 25 | int len = 0; |
emilmont | 10:3bc89ef62ce7 | 26 | while (true) { |
emilmont | 10:3bc89ef62ce7 | 27 | char c = *file_name; |
emilmont | 10:3bc89ef62ce7 | 28 | if (c == '/') { // end of object name |
emilmont | 10:3bc89ef62ce7 | 29 | file_name++; // point to one char after the '/' |
emilmont | 10:3bc89ef62ce7 | 30 | break; |
emilmont | 10:3bc89ef62ce7 | 31 | } |
emilmont | 10:3bc89ef62ce7 | 32 | if (c == 0) { // end of object name, with no filename |
emilmont | 10:3bc89ef62ce7 | 33 | break; |
emilmont | 10:3bc89ef62ce7 | 34 | } |
emilmont | 10:3bc89ef62ce7 | 35 | len++; |
emilmont | 10:3bc89ef62ce7 | 36 | file_name++; |
emilmont | 10:3bc89ef62ce7 | 37 | } |
emilmont | 10:3bc89ef62ce7 | 38 | |
emilmont | 10:3bc89ef62ce7 | 39 | FileBase::lookup(file_system, len); |
emilmont | 10:3bc89ef62ce7 | 40 | |
emilmont | 10:3bc89ef62ce7 | 41 | |
emilmont | 10:3bc89ef62ce7 | 42 | fb = FileBase::lookup(file_system, len); |
emilmont | 10:3bc89ef62ce7 | 43 | } |
emilmont | 10:3bc89ef62ce7 | 44 | |
emilmont | 10:3bc89ef62ce7 | 45 | const char* FilePath::fileName(void) { |
emilmont | 10:3bc89ef62ce7 | 46 | return file_name; |
emilmont | 10:3bc89ef62ce7 | 47 | } |
emilmont | 10:3bc89ef62ce7 | 48 | |
emilmont | 10:3bc89ef62ce7 | 49 | bool FilePath::isFileSystem(void) { |
emilmont | 10:3bc89ef62ce7 | 50 | return (fb->getPathType() == FileSystemPathType); |
emilmont | 10:3bc89ef62ce7 | 51 | } |
emilmont | 10:3bc89ef62ce7 | 52 | |
emilmont | 10:3bc89ef62ce7 | 53 | FileSystemLike* FilePath::fileSystem(void) { |
emilmont | 10:3bc89ef62ce7 | 54 | if (isFileSystem()) { |
emilmont | 10:3bc89ef62ce7 | 55 | return (FileSystemLike*)fb; |
emilmont | 10:3bc89ef62ce7 | 56 | } |
emilmont | 10:3bc89ef62ce7 | 57 | return NULL; |
emilmont | 10:3bc89ef62ce7 | 58 | } |
emilmont | 10:3bc89ef62ce7 | 59 | |
emilmont | 10:3bc89ef62ce7 | 60 | bool FilePath::isFile(void) { |
emilmont | 10:3bc89ef62ce7 | 61 | return (fb->getPathType() == FilePathType); |
emilmont | 10:3bc89ef62ce7 | 62 | } |
emilmont | 10:3bc89ef62ce7 | 63 | |
emilmont | 10:3bc89ef62ce7 | 64 | FileLike* FilePath::file(void) { |
emilmont | 10:3bc89ef62ce7 | 65 | if (isFile()) { |
emilmont | 10:3bc89ef62ce7 | 66 | return (FileLike*)fb; |
emilmont | 10:3bc89ef62ce7 | 67 | } |
emilmont | 10:3bc89ef62ce7 | 68 | return NULL; |
emilmont | 10:3bc89ef62ce7 | 69 | } |
emilmont | 10:3bc89ef62ce7 | 70 | |
emilmont | 10:3bc89ef62ce7 | 71 | } // namespace mbed |