├── .gitignore ├── .gitmodules ├── esp_idf ├── include │ ├── idf_reent.h │ ├── esp_log.h │ ├── lock.h │ ├── esp_err.h │ └── esp_errno.h ├── errno.c ├── idf_reent.c ├── freertos │ ├── CMakeLists.txt │ ├── include │ │ ├── queue.h │ │ ├── semphr.h │ │ └── FreeRTOS.h │ └── semphr.c ├── CMakeLists.txt └── lock.c ├── filesystem ├── diskio │ ├── CMakeLists.txt │ ├── include │ │ ├── FatPartition.h │ │ ├── diskio_RAM.h │ │ ├── Flash_Access.h │ │ └── diskio.h │ ├── FatPartition.cpp │ ├── diskio.c │ └── diskio_RAM.cpp ├── vfs │ ├── CMakeLists.txt │ ├── include │ │ ├── user_vfs.h │ │ ├── idf_dirent.h │ │ └── esp_vfs.h │ └── user_vfs.c └── fatfs │ ├── CMakeLists.txt │ ├── include │ ├── integer.h │ ├── esp_vfs_fat.h │ └── ffconf.h │ └── syscall.c ├── Config.h.in ├── sdkconfig.h ├── .github └── workflows │ └── main.yml ├── tclap ├── COPYING ├── Visitor.h ├── IgnoreRestVisitor.h ├── OptionalUnlabeledTracker.h ├── Constraint.h ├── CmdLineOutput.h ├── HelpVisitor.h ├── VersionVisitor.h ├── ArgTraits.h ├── ValuesConstraint.h ├── CmdLineInterface.h ├── XorHandler.h ├── StandardTraits.h ├── ArgException.h ├── MultiSwitchArg.h ├── SwitchArg.h ├── ZshCompletionOutput.h ├── DocBookOutput.h ├── StdOutput.h ├── UnlabeledMultiArg.h ├── UnlabeledValueArg.h └── MultiArg.h ├── pack_fat.h ├── pack_littlefs.h ├── CMakeLists.txt ├── .vscode └── settings.json ├── README.md └── main.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.a 3 | /build/ 4 | /CMakeFiles/ 5 | /out/ 6 | /.vscode/ 7 | /.vs/ 8 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "filesystem/littlefs"] 2 | path = filesystem/littlefs 3 | url = https://github.com/ARMmbed/mbed-littlefs.git 4 | -------------------------------------------------------------------------------- /esp_idf/include/idf_reent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | struct _idf_reent { 5 | int _errno; 6 | }; 7 | 8 | struct _idf_reent* __idf_getreent(); 9 | 10 | 11 | -------------------------------------------------------------------------------- /esp_idf/errno.c: -------------------------------------------------------------------------------- 1 | #include "esp_errno.h" 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | 8 | int esp_errno; 9 | 10 | 11 | #ifdef __cplusplus 12 | } 13 | #endif 14 | -------------------------------------------------------------------------------- /esp_idf/idf_reent.c: -------------------------------------------------------------------------------- 1 | 2 | #include "idf_reent.h" 3 | 4 | 5 | static struct _idf_reent s_r; 6 | 7 | struct _idf_reent* __idf_getreent() { 8 | return &s_r; 9 | } 10 | 11 | 12 | -------------------------------------------------------------------------------- /esp_idf/freertos/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 查找当前目录下的所有源文件 2 | # 并将名称保存到 DIR_LIB_SRCS 变量 3 | aux_source_directory(. DIR_LIB_SRCS) 4 | 5 | include_directories(include) 6 | 7 | # 生成链接库 8 | add_library (freertos ${DIR_LIB_SRCS}) 9 | -------------------------------------------------------------------------------- /esp_idf/freertos/include/queue.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | typedef void * QueueHandle_t; 9 | 10 | 11 | #ifdef __cplusplus 12 | } 13 | #endif 14 | 15 | -------------------------------------------------------------------------------- /filesystem/diskio/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 查找当前目录下的所有源文件 2 | # 并将名称保存到 DIR_LIB_SRCS 变量 3 | aux_source_directory(. DIR_LIB_SRCS) 4 | 5 | include_directories(include) 6 | 7 | # 生成链接库 8 | add_library (diskio ${DIR_LIB_SRCS}) 9 | -------------------------------------------------------------------------------- /esp_idf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 查找当前目录下的所有源文件 2 | # 并将名称保存到 DIR_LIB_SRCS 变量 3 | aux_source_directory(. DIR_LIB_SRCS) 4 | 5 | include_directories(include) 6 | include_directories(freertos/include) 7 | 8 | # 生成链接库 9 | add_library (esp-idf ${DIR_LIB_SRCS}) 10 | -------------------------------------------------------------------------------- /Config.h.in: -------------------------------------------------------------------------------- 1 | // the configured options and settings for Tutorial 2 | #define mkfatfs_VERSION_MAJOR @mkfatfs_VERSION_MAJOR@ 3 | #define mkfatfs_VERSION_MINOR @mkfatfs_VERSION_MINOR@ 4 | #define mkfatfs_VERSION_PATCH @mkfatfs_VERSION_PATCH@ 5 | #define mkfatfs_VERSION "@mkfatfs_VERSION@" -------------------------------------------------------------------------------- /filesystem/vfs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 查找当前目录下的所有源文件 2 | # 并将名称保存到 DIR_LIB_SRCS 变量 3 | aux_source_directory(. DIR_LIB_SRCS) 4 | 5 | include_directories(include) 6 | include_directories(../diskio/include) 7 | include_directories(../fatfs/include) 8 | 9 | # 生成链接库 10 | add_library (vfs ${DIR_LIB_SRCS}) 11 | -------------------------------------------------------------------------------- /sdkconfig.h: -------------------------------------------------------------------------------- 1 | #define CONFIG_RAM_SECTOR_SIZE_512 1 2 | #define CONFIG_RAM_SECTOR_SIZE 4096 3 | #define CONFIG_WL_SECTOR_MODE 1 4 | #define CONFIG_WL_SECTOR_MODE_SAFE 1 5 | #define CONFIG_FATFS_CODEPAGE_437 1 6 | #define CONFIG_FATFS_CODEPAGE 437 7 | #define CONFIG_FATFS_LFN_HEAP 1 8 | #define CONFIG_FATFS_MAX_LFN 127 9 | -------------------------------------------------------------------------------- /filesystem/fatfs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 查找当前目录下的所有源文件 2 | # 并将名称保存到 DIR_LIB_SRCS 变量 3 | aux_source_directory(. DIR_LIB_SRCS) 4 | 5 | include_directories(include) 6 | include_directories(../../../esp_idf/include) 7 | include_directories(../../../esp_idf/freertos/include) 8 | 9 | # 生成链接库 10 | add_library (fatfs ${DIR_LIB_SRCS}) 11 | -------------------------------------------------------------------------------- /esp_idf/freertos/semphr.c: -------------------------------------------------------------------------------- 1 | 2 | #include "semphr.h" 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | SemaphoreHandle_t xSemaphoreCreateMutex() {return (SemaphoreHandle_t)1;} 9 | void vSemaphoreDelete( SemaphoreHandle_t xSemaphore ) {} 10 | BaseType_t xSemaphoreTake( SemaphoreHandle_t xSemaphore, TickType_t xBlockTime ) {return pdTRUE;} 11 | BaseType_t xSemaphoreGive( SemaphoreHandle_t xSemaphore ) {return pdTRUE;} 12 | 13 | #ifdef __cplusplus 14 | } 15 | #endif 16 | 17 | 18 | -------------------------------------------------------------------------------- /esp_idf/freertos/include/semphr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "FreeRTOS.h" 4 | #include "queue.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | typedef QueueHandle_t SemaphoreHandle_t; 11 | 12 | SemaphoreHandle_t xSemaphoreCreateMutex(); 13 | void vSemaphoreDelete( SemaphoreHandle_t xSemaphore ); 14 | BaseType_t xSemaphoreTake( SemaphoreHandle_t xSemaphore, TickType_t xBlockTime ); 15 | BaseType_t xSemaphoreGive( SemaphoreHandle_t xSemaphore ); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /esp_idf/lock.c: -------------------------------------------------------------------------------- 1 | #include "lock.h" 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | void _lock_init(_lock_t *lock) {} 8 | void _lock_init_recursive(_lock_t *lock) {} 9 | void _lock_close(_lock_t *lock) {} 10 | void _lock_close_recursive(_lock_t *lock) {} 11 | void _lock_acquire(_lock_t *lock) {} 12 | void _lock_acquire_recursive(_lock_t *lock) {} 13 | int _lock_try_acquire(_lock_t *lock) {return 0;} 14 | int _lock_try_acquire_recursive(_lock_t *lock) {return 0;} 15 | void _lock_release(_lock_t *lock) {} 16 | void _lock_release_recursive(_lock_t *lock) {} 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | -------------------------------------------------------------------------------- /esp_idf/include/esp_log.h: -------------------------------------------------------------------------------- 1 | 2 | extern int g_debugLevel; 3 | 4 | #define ESP_LOGE(x, ...) {if(g_debugLevel >= 0) {printf("E %s: ",x); printf(__VA_ARGS__); printf("\n");}} 5 | #define ESP_LOGW(x, ...) {if(g_debugLevel >= 1) {printf("W %s: ",x); printf(__VA_ARGS__); printf("\n");}} 6 | #define ESP_LOGI(x, ...) {if(g_debugLevel >= 2) {printf("I %s: ",x); printf(__VA_ARGS__); printf("\n");}} 7 | #define ESP_LOGD(x, ...) {if(g_debugLevel >= 3) {printf("D %s: ",x); printf(__VA_ARGS__); printf("\n");}} 8 | #define ESP_LOGV(x, ...) {if(g_debugLevel >= 4) {printf("V %s: ",x); printf(__VA_ARGS__); printf("\n");}} 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | on: push 2 | name: Tests / test-user-mirror 3 | jobs: 4 | run: 5 | name: Run 6 | runs-on: ubuntu-latest 7 | steps: 8 | - name: Checkout source codes 9 | uses: actions/checkout@v1 10 | - name: Mirror Github to Gitee with white list 11 | uses: ./. 12 | with: 13 | src: github/labplus-cn/mkfatfs 14 | dst: gitee/labplus-cn/mkfatfs 15 | dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} 16 | dst_token: ${{ secrets.GITEE_TOKEN }} 17 | static_list: 'hub-mirror-action,hashes,simple-spring' 18 | force_update: true 19 | debug: true 20 | -------------------------------------------------------------------------------- /esp_idf/include/lock.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | typedef int _lock_t; 8 | typedef _lock_t _LOCK_RECURSIVE_T; 9 | typedef _lock_t _LOCK_T; 10 | 11 | void _lock_init(_lock_t *lock); 12 | void _lock_init_recursive(_lock_t *lock); 13 | void _lock_close(_lock_t *lock); 14 | void _lock_close_recursive(_lock_t *lock); 15 | void _lock_acquire(_lock_t *lock); 16 | void _lock_acquire_recursive(_lock_t *lock); 17 | int _lock_try_acquire(_lock_t *lock); 18 | int _lock_try_acquire_recursive(_lock_t *lock); 19 | void _lock_release(_lock_t *lock); 20 | void _lock_release_recursive(_lock_t *lock); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | -------------------------------------------------------------------------------- /esp_idf/freertos/include/FreeRTOS.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include //for malloc/free 4 | #include // uint32_t etc 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | 11 | #define portBASE_TYPE int 12 | typedef portBASE_TYPE BaseType_t; 13 | typedef unsigned portBASE_TYPE UBaseType_t; 14 | 15 | #if( configUSE_16_BIT_TICKS == 1 ) 16 | typedef uint16_t TickType_t; 17 | #define portMAX_DELAY ( TickType_t ) 0xffff 18 | #else 19 | typedef uint32_t TickType_t; 20 | #define portMAX_DELAY ( TickType_t ) 0xffffffffUL 21 | #endif 22 | 23 | #define pdFALSE ( ( BaseType_t ) 0 ) 24 | #define pdTRUE ( ( BaseType_t ) 1 ) 25 | 26 | #define pdPASS ( pdTRUE ) 27 | #define pdFAIL ( pdFALSE ) 28 | 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | -------------------------------------------------------------------------------- /filesystem/diskio/include/FatPartition.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "esp_err.h" 5 | #include "esp_partition.h" 6 | #include "Flash_Access.h" 7 | 8 | extern std::vector g_flashmem; 9 | 10 | /** 11 | * @brief This class is used to access partition. Class implements Flash_Access interface 12 | * 13 | */ 14 | class FatPartition : public Flash_Access 15 | { 16 | 17 | public: 18 | FatPartition(const esp_partition_t *partition); 19 | 20 | virtual size_t chip_size(); 21 | 22 | virtual esp_err_t erase_sector(size_t sector); 23 | virtual esp_err_t erase_range(size_t start_address, size_t size); 24 | 25 | virtual esp_err_t write(size_t dest_addr, const void *src, size_t size); 26 | virtual esp_err_t read(size_t src_addr, void *dest, size_t size); 27 | 28 | virtual size_t sector_size(); 29 | 30 | virtual ~FatPartition(); 31 | protected: 32 | const esp_partition_t *partition; 33 | 34 | }; 35 | 36 | 37 | -------------------------------------------------------------------------------- /filesystem/fatfs/include/integer.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------*/ 2 | /* Integer type definitions for FatFs module */ 3 | /*-------------------------------------------*/ 4 | 5 | #ifndef _FF_INTEGER 6 | #define _FF_INTEGER 7 | 8 | #ifdef _WIN32 /* FatFs development platform */ 9 | 10 | #include 11 | #include 12 | typedef unsigned __int64 QWORD; 13 | 14 | 15 | #else /* Embedded platform */ 16 | 17 | /* These types MUST be 16-bit or 32-bit */ 18 | typedef int INT; 19 | typedef unsigned int UINT; 20 | 21 | /* This type MUST be 8-bit */ 22 | typedef unsigned char BYTE; 23 | 24 | /* These types MUST be 16-bit */ 25 | typedef short SHORT; 26 | typedef unsigned short WORD; 27 | typedef unsigned short WCHAR; 28 | 29 | /* These types MUST be 32-bit */ 30 | //MVA VVV 31 | //typedef long LONG; 32 | //typedef unsigned long DWORD; 33 | typedef int LONG; 34 | typedef unsigned int DWORD; 35 | //MVA ^^^ 36 | 37 | 38 | /* This type MUST be 64-bit (Remove this for C89 compatibility) */ 39 | typedef unsigned long long QWORD; 40 | 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /tclap/COPYING: -------------------------------------------------------------------------------- 1 | 2 | 3 | Copyright (c) 2003 Michael E. Smoot 4 | 5 | Permission is hereby granted, free of charge, to any person 6 | obtaining a copy of this software and associated documentation 7 | files (the "Software"), to deal in the Software without restriction, 8 | including without limitation the rights to use, copy, modify, merge, 9 | publish, distribute, sublicense, and/or sell copies of the Software, 10 | and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 20 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 21 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 22 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | 26 | -------------------------------------------------------------------------------- /filesystem/diskio/include/diskio_RAM.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _DISKIO_RAM 16 | #define _DISKIO_RAM 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | #include "integer.h" 23 | #include "esp_partition.h" 24 | 25 | typedef int32_t RAM_handle_t; 26 | #define RAM_INVALID_HANDLE -1 27 | /** 28 | * Register spi flash partition 29 | * 30 | * @param pdrv drive number 31 | * @param RAM_handle handle of the wear levelling partition. 32 | */ 33 | esp_err_t ff_diskio_register_RAM_partition(BYTE pdrv, RAM_handle_t RAM_handle, esp_partition_t *data_partition); 34 | esp_err_t ff_diskio_unregister_RAM_partition(BYTE pdrv, RAM_handle_t RAM_handle); 35 | BYTE ff_diskio_get_pdrv_RAM(RAM_handle_t RAM_handle); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif // _DISKIO_SPIFLASH_DEFINED 42 | -------------------------------------------------------------------------------- /filesystem/diskio/include/Flash_Access.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | 15 | #ifndef _Flash_Access_H_ 16 | #define _Flash_Access_H_ 17 | #include "esp_err.h" 18 | 19 | /** 20 | * @brief Universal flash access interface class 21 | * 22 | */ 23 | class Flash_Access 24 | { 25 | public: 26 | virtual size_t chip_size() = 0; 27 | 28 | virtual esp_err_t erase_sector(size_t sector) = 0; 29 | virtual esp_err_t erase_range(size_t start_address, size_t size) = 0; 30 | 31 | virtual esp_err_t write(size_t dest_addr, const void *src, size_t size) = 0; 32 | virtual esp_err_t read(size_t src_addr, void *dest, size_t size) = 0; 33 | 34 | virtual size_t sector_size() = 0; 35 | 36 | virtual esp_err_t flush() 37 | { 38 | return ESP_OK; 39 | }; 40 | 41 | virtual ~Flash_Access() {}; 42 | }; 43 | 44 | #endif // _Flash_Access_H_ -------------------------------------------------------------------------------- /tclap/Visitor.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: Visitor.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot . 7 | * All rights reverved. 8 | * 9 | * See the file COPYING in the top directory of this distribution for 10 | * more information. 11 | * 12 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 15 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | *****************************************************************************/ 21 | 22 | 23 | #ifndef TCLAP_VISITOR_H 24 | #define TCLAP_VISITOR_H 25 | 26 | namespace TCLAP { 27 | 28 | /** 29 | * A base class that defines the interface for visitors. 30 | */ 31 | class Visitor 32 | { 33 | public: 34 | 35 | /** 36 | * Constructor. Does nothing. 37 | */ 38 | Visitor() { } 39 | 40 | /** 41 | * Destructor. Does nothing. 42 | */ 43 | virtual ~Visitor() { } 44 | 45 | /** 46 | * Does nothing. Should be overridden by child. 47 | */ 48 | virtual void visit() { } 49 | }; 50 | 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /pack_fat.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #if defined(_WIN32) 16 | #include 17 | #endif 18 | #include 19 | #include "esp_vfs_fat.h" 20 | #include "user_vfs.h" 21 | #include "esp_err.h" 22 | #include "esp_log.h" 23 | #include "FatPartition.h" 24 | 25 | /** 26 | * @brief This class is used to pack/upack filesystem. 27 | * 28 | */ 29 | class Pack_fat 30 | { 31 | public: 32 | Pack_fat(); 33 | ~Pack_fat(); 34 | int actionPack(std::string s_dirName, std::string s_imageName, int s_imageSize); 35 | int actionUnpack(std::string s_imageName, std::string s_dirName,int s_imageSize); 36 | 37 | private: 38 | bool fsMount(int s_imageSize); 39 | bool fsUnmount(); 40 | size_t getFileSize(FILE* fp); 41 | bool dirExists(const char* path); 42 | bool dirCreate(const char* path); 43 | int parkDirToRamFS(const char* name); 44 | int parkFileToRamFS(char* path_src, const char* path_des); 45 | bool parkFilesToRamFS(const char* dirSrc, const char* dirDes); 46 | int unparkFileFromRamFS(const char* path_src, const char* path_des); 47 | bool unparkFilesFromRamFS(const char* dirSrc, const char* dirDes); 48 | 49 | protected: 50 | 51 | }; 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /tclap/IgnoreRestVisitor.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: IgnoreRestVisitor.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot . 7 | * All rights reverved. 8 | * 9 | * See the file COPYING in the top directory of this distribution for 10 | * more information. 11 | * 12 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 15 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | *****************************************************************************/ 21 | 22 | 23 | #ifndef TCLAP_IGNORE_REST_VISITOR_H 24 | #define TCLAP_IGNORE_REST_VISITOR_H 25 | 26 | #include "Visitor.h" 27 | #include "Arg.h" 28 | 29 | namespace TCLAP { 30 | 31 | /** 32 | * A Vistor that tells the CmdLine to begin ignoring arguments after 33 | * this one is parsed. 34 | */ 35 | class IgnoreRestVisitor: public Visitor 36 | { 37 | public: 38 | 39 | /** 40 | * Constructor. 41 | */ 42 | IgnoreRestVisitor() : Visitor() {} 43 | 44 | /** 45 | * Sets Arg::_ignoreRest. 46 | */ 47 | void visit() { Arg::beginIgnoring(); } 48 | }; 49 | 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /pack_littlefs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #if defined(_WIN32) 16 | #include 17 | #endif 18 | #include 19 | #include "lfs2.h" 20 | #include "lfs2_rambd.h" 21 | 22 | #define READ_SIZE 32 23 | #define PROC_SIZE 32 24 | #define LOOKAHEAD_SIZE 32 25 | #define BLOCK_SIZE 4096 26 | #define BLOCK_COUNT 512 27 | 28 | /** 29 | * @brief This class is used to pack/upack filesystem. 30 | * 31 | */ 32 | class Pack_littlefs 33 | { 34 | public: 35 | Pack_littlefs(); 36 | ~Pack_littlefs(); 37 | int actionPack(std::string s_dirName, std::string s_imageName, int s_imageSize); 38 | int actionUnpack(std::string s_imageName, std::string s_dirName,int s_imageSize); 39 | 40 | private: 41 | void lfsConfig(int s_imageSize); 42 | bool fsMount(std::string s_imageName, int s_imageSize, bool format=false); 43 | bool fsUnmount(); 44 | size_t getFileSize(FILE* fp); 45 | bool dirExists(const char* path); 46 | bool dirCreate(const char* path); 47 | int parkFileToRamFS(char* path_src, const char* path_des); 48 | bool parkFilesToRamFS(const char* dirSrc, const char* dirDes); 49 | bool unparkFileFromRamFS(const char* path_src, lfs2_info *littlefsFile, const char* path_des); 50 | bool unparkFilesFromRamFS(const char* dirSrc, std::string dirDes); 51 | 52 | lfs2_t s_fs; 53 | lfs2_config s_cfg; 54 | lfs2_file_t f; 55 | lfs2_rambd_config rambd_cfg; 56 | lfs2_rambd_t bd; 57 | 58 | protected: 59 | 60 | }; 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0.0) 2 | project(mkfatfs VERSION 2.0.1) 3 | 4 | # specify the C++ standard 5 | set(CMAKE_CXX_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD_REQUIRED True) 7 | 8 | configure_file(Config.h.in Config.h) 9 | 10 | include(CTest) 11 | enable_testing() 12 | 13 | include_directories(.) 14 | include_directories(esp_idf/include) 15 | include_directories(esp_idf/freertos/include) 16 | include_directories(filesystem/diskio/include) 17 | include_directories(filesystem/fatfs/include) 18 | include_directories(filesystem/vfs/include) 19 | include_directories(tclap) 20 | include_directories(filesystem/littlefs/littlefs) 21 | include_directories(filesystem/littlefs/littlefs/bd) 22 | 23 | aux_source_directory(. DIR_SRCS) 24 | aux_source_directory(esp_idf DIR_ESP_IDF) 25 | aux_source_directory(esp_idf/freertos DIR_RTOS) 26 | aux_source_directory(filesystem/diskio DIR_DISKIO) 27 | aux_source_directory(filesystem/fatfs DIR_FATFS) 28 | aux_source_directory(filesystem/vfs DIR_VFS) 29 | aux_source_directory(filesystem/littlefs/littlefs DIR_LITTLEFS) 30 | set(SRC_RAMBD filesystem/littlefs/littlefs/bd/lfs2_rambd.c ) 31 | 32 | add_executable(mkfatfs ${DIR_SRCS} ${DIR_ESP_IDF} ${DIR_RTOS} ${DIR_DISKIO} ${DIR_FATFS} ${DIR_VFS} ${DIR_LITTLEFS} ${SRC_RAMBD}) 33 | 34 | # add_subdirectory(esp_idf) 35 | # add_subdirectory(filesystem/diskio) 36 | # add_subdirectory(filesystem/fatfs) 37 | # add_subdirectory(filesystem/vfs) 38 | # add_subdirectory(esp_idf/freertos) 39 | 40 | # add_executable(mkfatfs main.cpp pack.cpp) 41 | 42 | # target_link_libraries(mkfatfs -Wl,--start-group esp-idf vfs diskio fatfs freertos -Wl,--end-group -Wl,--hash-style=sysv) 43 | 44 | set(CPACK_PROJECT_NAME ${PROJECT_NAME}) 45 | set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) 46 | include(CPack) 47 | 48 | target_include_directories(mkfatfs PUBLIC 49 | "${PROJECT_BINARY_DIR}" 50 | ) 51 | -------------------------------------------------------------------------------- /filesystem/vfs/include/user_vfs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __USER_VFS_H__ 4 | #define __USER_VFS_H__ 5 | /* 6 | * spiffs.h 7 | * 8 | * Created on: September 20, 2017 9 | * Author: kearins 10 | */ 11 | 12 | #include "esp_err.h" 13 | #include "diskio_RAM.h" 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | esp_err_t emulate_esp_vfs_fat_spiflash_mount(const char* base_path, 20 | //const char* partition_label, 21 | const esp_vfs_fat_mount_config_t* mount_config, 22 | RAM_handle_t* RAM_handle, 23 | FATFS** out_fs, 24 | int imageSize 25 | ); 26 | 27 | esp_err_t emulate_esp_vfs_fat_spiflash_unmount(const char *base_path, RAM_handle_t wl_handle); 28 | 29 | //vfs.c 30 | ssize_t emulate_esp_vfs_write(int fd, const void * data, size_t size); 31 | off_t emulate_esp_vfs_lseek(int fd, off_t size, int mode); 32 | ssize_t emulate_esp_vfs_read(int fd, void * dst, size_t size); 33 | int emulate_esp_vfs_open(const char * path, int flags, int mode); 34 | int emulate_esp_vfs_close(int fd); 35 | int emulate_esp_vfs_fstat(int fd, struct stat * st); 36 | int emulate_esp_vfs_stat(const char * path, struct stat * st); 37 | int emulate_esp_vfs_link(const char* n1, const char* n2); 38 | int emulate_esp_vfs_unlink(const char *path); 39 | int emulate_esp_vfs_rename(const char *src, const char *dst); 40 | 41 | //------- 42 | 43 | DIR* emulate_vfs_opendir(const char* name); 44 | struct dirent* emulate_vfs_readdir(DIR* pdir); 45 | int emulate_vfs_readdir_r(DIR* pdir, struct dirent* entry, struct dirent** out_dirent); 46 | long emulate_vfs_telldir(DIR* pdir); 47 | void emulate_vfs_seekdir(DIR* pdir, long loc); 48 | void emulate_vfs_rewinddir(DIR* pdir); 49 | int emulate_vfs_closedir(DIR* pdir); 50 | int emulate_vfs_mkdir(const char* name, mode_t mode); 51 | int emulate_vfs_rmdir(const char* name); 52 | int emulate_vfs_fcntl(int fd, int cmd, ...); 53 | 54 | 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif 61 | 62 | -------------------------------------------------------------------------------- /tclap/OptionalUnlabeledTracker.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /****************************************************************************** 4 | * 5 | * file: OptionalUnlabeledTracker.h 6 | * 7 | * Copyright (c) 2005, Michael E. Smoot . 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | 24 | #ifndef TCLAP_OPTIONAL_UNLABELED_TRACKER_H 25 | #define TCLAP_OPTIONAL_UNLABELED_TRACKER_H 26 | 27 | #include 28 | 29 | namespace TCLAP { 30 | 31 | class OptionalUnlabeledTracker 32 | { 33 | 34 | public: 35 | 36 | static void check( bool req, const std::string& argName ); 37 | 38 | static void gotOptional() { alreadyOptionalRef() = true; } 39 | 40 | static bool& alreadyOptional() { return alreadyOptionalRef(); } 41 | 42 | private: 43 | 44 | static bool& alreadyOptionalRef() { static bool ct = false; return ct; } 45 | }; 46 | 47 | 48 | inline void OptionalUnlabeledTracker::check( bool req, const std::string& argName ) 49 | { 50 | if ( OptionalUnlabeledTracker::alreadyOptional() ) 51 | throw( SpecificationException( 52 | "You can't specify ANY Unlabeled Arg following an optional Unlabeled Arg", 53 | argName ) ); 54 | 55 | if ( !req ) 56 | OptionalUnlabeledTracker::gotOptional(); 57 | } 58 | 59 | 60 | } // namespace TCLAP 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /tclap/Constraint.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: Constraint.h 5 | * 6 | * Copyright (c) 2005, Michael E. Smoot 7 | * All rights reverved. 8 | * 9 | * See the file COPYING in the top directory of this distribution for 10 | * more information. 11 | * 12 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 15 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | *****************************************************************************/ 21 | 22 | #ifndef TCLAP_CONSTRAINT_H 23 | #define TCLAP_CONSTRAINT_H 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | namespace TCLAP { 33 | 34 | /** 35 | * The interface that defines the interaction between the Arg and Constraint. 36 | */ 37 | template 38 | class Constraint 39 | { 40 | 41 | public: 42 | /** 43 | * Returns a description of the Constraint. 44 | */ 45 | virtual std::string description() const =0; 46 | 47 | /** 48 | * Returns the short ID for the Constraint. 49 | */ 50 | virtual std::string shortID() const =0; 51 | 52 | /** 53 | * The method used to verify that the value parsed from the command 54 | * line meets the constraint. 55 | * \param value - The value that will be checked. 56 | */ 57 | virtual bool check(const T& value) const =0; 58 | 59 | /** 60 | * Destructor. 61 | * Silences warnings about Constraint being a base class with virtual 62 | * functions but without a virtual destructor. 63 | */ 64 | virtual ~Constraint() { ; } 65 | }; 66 | 67 | } //namespace TCLAP 68 | #endif 69 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "C_Cpp.default.configurationProvider": "go2sh.cmake-integration", 3 | "files.associations": { 4 | "algorithm": "cpp", 5 | "cctype": "cpp", 6 | "cmath": "cpp", 7 | "concepts": "cpp", 8 | "cstddef": "cpp", 9 | "cstdint": "cpp", 10 | "cstdio": "cpp", 11 | "cstdlib": "cpp", 12 | "cstring": "cpp", 13 | "ctime": "cpp", 14 | "cwchar": "cpp", 15 | "exception": "cpp", 16 | "initializer_list": "cpp", 17 | "iomanip": "cpp", 18 | "ios": "cpp", 19 | "iosfwd": "cpp", 20 | "iostream": "cpp", 21 | "istream": "cpp", 22 | "limits": "cpp", 23 | "list": "cpp", 24 | "map": "cpp", 25 | "memory": "cpp", 26 | "new": "cpp", 27 | "ostream": "cpp", 28 | "sstream": "cpp", 29 | "stdexcept": "cpp", 30 | "streambuf": "cpp", 31 | "string": "cpp", 32 | "strstream": "cpp", 33 | "system_error": "cpp", 34 | "tuple": "cpp", 35 | "type_traits": "cpp", 36 | "typeinfo": "cpp", 37 | "utility": "cpp", 38 | "vector": "cpp", 39 | "xfacet": "cpp", 40 | "xiosbase": "cpp", 41 | "xlocale": "cpp", 42 | "xlocinfo": "cpp", 43 | "xlocmon": "cpp", 44 | "xlocnum": "cpp", 45 | "xloctime": "cpp", 46 | "xmemory": "cpp", 47 | "xstddef": "cpp", 48 | "xstring": "cpp", 49 | "xtr1common": "cpp", 50 | "xtree": "cpp", 51 | "xutility": "cpp", 52 | "array": "cpp", 53 | "atomic": "cpp", 54 | "*.tcc": "cpp", 55 | "clocale": "cpp", 56 | "cstdarg": "cpp", 57 | "cwctype": "cpp", 58 | "deque": "cpp", 59 | "unordered_map": "cpp", 60 | "functional": "cpp", 61 | "iterator": "cpp", 62 | "memory_resource": "cpp", 63 | "numeric": "cpp", 64 | "optional": "cpp", 65 | "random": "cpp", 66 | "string_view": "cpp", 67 | "fstream": "cpp" 68 | } 69 | } -------------------------------------------------------------------------------- /tclap/CmdLineOutput.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /****************************************************************************** 4 | * 5 | * file: CmdLineOutput.h 6 | * 7 | * Copyright (c) 2004, Michael E. Smoot 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | #ifndef TCLAP_CMDLINEOUTPUT_H 24 | #define TCLAP_CMDLINEOUTPUT_H 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | namespace TCLAP { 34 | 35 | class CmdLineInterface; 36 | class ArgException; 37 | 38 | /** 39 | * The interface that any output object must implement. 40 | */ 41 | class CmdLineOutput 42 | { 43 | 44 | public: 45 | 46 | /** 47 | * Virtual destructor. 48 | */ 49 | virtual ~CmdLineOutput() {} 50 | 51 | /** 52 | * Generates some sort of output for the USAGE. 53 | * \param c - The CmdLine object the output is generated for. 54 | */ 55 | virtual void usage(CmdLineInterface& c)=0; 56 | 57 | /** 58 | * Generates some sort of output for the version. 59 | * \param c - The CmdLine object the output is generated for. 60 | */ 61 | virtual void version(CmdLineInterface& c)=0; 62 | 63 | /** 64 | * Generates some sort of output for a failure. 65 | * \param c - The CmdLine object the output is generated for. 66 | * \param e - The ArgException that caused the failure. 67 | */ 68 | virtual void failure( CmdLineInterface& c, 69 | ArgException& e )=0; 70 | 71 | }; 72 | 73 | } //namespace TCLAP 74 | #endif 75 | -------------------------------------------------------------------------------- /tclap/HelpVisitor.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: HelpVisitor.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot . 7 | * All rights reverved. 8 | * 9 | * See the file COPYING in the top directory of this distribution for 10 | * more information. 11 | * 12 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 15 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | *****************************************************************************/ 21 | 22 | #ifndef TCLAP_HELP_VISITOR_H 23 | #define TCLAP_HELP_VISITOR_H 24 | 25 | #include "CmdLineInterface.h" 26 | #include "CmdLineOutput.h" 27 | #include "Visitor.h" 28 | 29 | namespace TCLAP { 30 | 31 | /** 32 | * A Visitor object that calls the usage method of the given CmdLineOutput 33 | * object for the specified CmdLine object. 34 | */ 35 | class HelpVisitor: public Visitor 36 | { 37 | private: 38 | /** 39 | * Prevent accidental copying. 40 | */ 41 | HelpVisitor(const HelpVisitor& rhs); 42 | HelpVisitor& operator=(const HelpVisitor& rhs); 43 | 44 | protected: 45 | 46 | /** 47 | * The CmdLine the output will be generated for. 48 | */ 49 | CmdLineInterface* _cmd; 50 | 51 | /** 52 | * The output object. 53 | */ 54 | CmdLineOutput** _out; 55 | 56 | public: 57 | 58 | /** 59 | * Constructor. 60 | * \param cmd - The CmdLine the output will be generated for. 61 | * \param out - The type of output. 62 | */ 63 | HelpVisitor(CmdLineInterface* cmd, CmdLineOutput** out) 64 | : Visitor(), _cmd( cmd ), _out( out ) { } 65 | 66 | /** 67 | * Calls the usage method of the CmdLineOutput for the 68 | * specified CmdLine. 69 | */ 70 | void visit() { (*_out)->usage(*_cmd); throw ExitException(0); } 71 | 72 | }; 73 | 74 | } 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /tclap/VersionVisitor.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 2 | 3 | /****************************************************************************** 4 | * 5 | * file: VersionVisitor.h 6 | * 7 | * Copyright (c) 2003, Michael E. Smoot . 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | 24 | #ifndef TCLAP_VERSION_VISITOR_H 25 | #define TCLAP_VERSION_VISITOR_H 26 | 27 | #include "CmdLineInterface.h" 28 | #include "CmdLineOutput.h" 29 | #include "Visitor.h" 30 | 31 | namespace TCLAP { 32 | 33 | /** 34 | * A Vistor that will call the version method of the given CmdLineOutput 35 | * for the specified CmdLine object and then exit. 36 | */ 37 | class VersionVisitor: public Visitor 38 | { 39 | private: 40 | /** 41 | * Prevent accidental copying 42 | */ 43 | VersionVisitor(const VersionVisitor& rhs); 44 | VersionVisitor& operator=(const VersionVisitor& rhs); 45 | 46 | protected: 47 | 48 | /** 49 | * The CmdLine of interest. 50 | */ 51 | CmdLineInterface* _cmd; 52 | 53 | /** 54 | * The output object. 55 | */ 56 | CmdLineOutput** _out; 57 | 58 | public: 59 | 60 | /** 61 | * Constructor. 62 | * \param cmd - The CmdLine the output is generated for. 63 | * \param out - The type of output. 64 | */ 65 | VersionVisitor( CmdLineInterface* cmd, CmdLineOutput** out ) 66 | : Visitor(), _cmd( cmd ), _out( out ) { } 67 | 68 | /** 69 | * Calls the version method of the output object using the 70 | * specified CmdLine. 71 | */ 72 | void visit() { 73 | (*_out)->version(*_cmd); 74 | throw ExitException(0); 75 | } 76 | 77 | }; 78 | 79 | } 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /filesystem/vfs/include/idf_dirent.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #ifndef __IDF_DIRENT_H__ 18 | #define __IDF_DIRENT_H__ 19 | 20 | #include 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | /** 27 | * This header file provides POSIX-compatible definitions of directory 28 | * access functions and related data types. 29 | * See http://pubs.opengroup.org/onlinepubs/7908799/xsh/dirent.h.html 30 | * for reference. 31 | */ 32 | 33 | /** 34 | * @brief Opaque directory structure 35 | */ 36 | typedef struct { 37 | uint16_t dd_vfs_idx; /*!< VFS index, not to be used by applications */ 38 | uint16_t dd_rsv; /*!< field reserved for future extension */ 39 | /* remaining fields are defined by VFS implementation */ 40 | } DIR; 41 | 42 | /** 43 | * @brief Directory entry structure 44 | */ 45 | struct dirent { 46 | int d_ino; /*!< file number */ 47 | uint8_t d_type; /*!< not defined in POSIX, but present in BSD and Linux */ 48 | uint8_t no_use[3]; 49 | #define DT_UNKNOWN 0 50 | #define DT_REG 1 51 | #define DT_DIR 2 52 | char d_name[256]; /*!< zero-terminated file name */ 53 | }; 54 | 55 | //MVA add prefix vfs_ 56 | //VVV 57 | DIR* vfs_opendir(const char* name); 58 | struct dirent* vfs_readdir(DIR* pdir); 59 | int vfs_readdir_r(DIR* pdir, struct dirent* entry, struct dirent** out_dirent); 60 | long vfs_telldir(DIR* pdir); 61 | void vfs_seekdir(DIR* pdir, long loc); 62 | void vfs_rewinddir(DIR* pdir); 63 | int vfs_closedir(DIR* pdir); 64 | int vfs_mkdir(const char* name, mode_t mode); 65 | int vfs_rmdir(const char* name); 66 | int vfs_fcntl(int fd, int cmd, ...); 67 | //MVA ^^^ 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mkfatfs 2 | Tool to build and unpack [FATFS](https://github.com/jkearins/ESP32_mkfatfs) images. 3 | 4 | 5 | ## Usage 6 | 7 | ``` 8 | 9 | in windows: 10 | 11 | mkfatfs {-c |-u |-l|-i} [-d <0-5>] [-b ] 12 | [-p ] [-s ] [--] [--version] [-t ] [-h] 13 | 14 | 15 | in linux: 16 | ./mkfatfs {-c |-u |-l|-i} [-d <0-5>] [-b ] 17 | [-p ] [-s ] [--] [--version] [-t ] [-h] 18 | 19 | 20 | eg: 21 | pack: 22 | windows: 23 | mkfatfs.exe -c Test -s 0x200000 -t littlefs test.bin 24 | linux: 25 | ./mkfatfs -c Test -s 0x200000 -t littlefs test.bin 26 | 27 | unpack: 28 | windows: 29 | mkfatfs.exe -u Test -s 0 -t littlefs test.bin 30 | linux: 31 | ./mkfatfs -u Test -s 0 -t littlefs test.bin 32 | 33 | Where: 34 | 35 | -c , --create 36 | (OR required) create fatfs image from a directory 37 | -- OR -- 38 | -u , --unpack 39 | (OR required) unpack fatfs image to a directory 40 | -- OR -- 41 | -l, --list 42 | (OR required) list files in fatfs image 43 | -- OR -- 44 | -i, --visualize 45 | (OR required) visualize fatfs image 46 | 47 | 48 | -d <0-5>, --debug <0-5> 49 | Debug level. 0 means no debug output. 50 | 51 | -b , --block 52 | fs block size, in bytes 53 | 54 | -p , --page 55 | fs page size, in bytes 56 | 57 | -s , --size 58 | fs image size, in bytes 59 | 60 | -t --type 61 | fs type, surport fatfs and littlefs 62 | 63 | --, --ignore_rest 64 | Ignores the rest of the labeled arguments following this flag. 65 | 66 | --version 67 | Displays version information and exits. 68 | 69 | -h, --help 70 | Displays usage information and exits. 71 | 72 | 73 | (required) fatfs image file 74 | 75 | 76 | ``` 77 | ## Build 78 | 79 | You need gcc (≥4.8) or clang(≥600.0.57), and make. On Windows, use MinGW. 80 | You need cmake (≥3.0.0). 81 | Youn can develop in vscode. install extension CMake and CMake Tools. 82 | More help for build project, please read the extension's help. 83 | in linux: 84 | cd mkfatfs 85 | cmake . 86 | make 87 | 88 | ## License 89 | 90 | MIT 91 | 92 | ## To do 93 | 94 | - [ ] Flag -u is not released yet 95 | - [ ] Flag -l is not released yet 96 | - [ ] Flag -i is not released yet 97 | - [ ] Add more debug output and print FATFS debug output 98 | - [ ] Error handling 99 | - [ ] Determine the image size automatically when opening a file 100 | - [ ] Code cleanup 101 | -------------------------------------------------------------------------------- /filesystem/diskio/FatPartition.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | #include // memset/memcpy 15 | #include "esp_log.h" 16 | #include "FatPartition.h" 17 | #include "sdkconfig.h" 18 | 19 | #define SPI_FLASH_SEC_SIZE CONFIG_RAM_SECTOR_SIZE 20 | 21 | static const char *TAG = "FatPartition"; 22 | 23 | std::vector g_flashmem; 24 | 25 | 26 | FatPartition::FatPartition(const esp_partition_t *partition) 27 | { 28 | this->partition = partition; 29 | } 30 | 31 | size_t FatPartition::chip_size() 32 | { 33 | return this->partition->size; 34 | } 35 | 36 | esp_err_t FatPartition::erase_sector(size_t sector) 37 | { 38 | esp_err_t result = ESP_OK; 39 | result = erase_range(sector * SPI_FLASH_SEC_SIZE, SPI_FLASH_SEC_SIZE); 40 | return result; 41 | } 42 | 43 | esp_err_t FatPartition::erase_range(size_t start_address, size_t size) 44 | { 45 | esp_err_t result = ESP_FAIL; 46 | if (g_flashmem.size() >= (start_address + size)) { 47 | result = ESP_OK; 48 | memset(&g_flashmem[0] + start_address, 0xff, size); 49 | } 50 | if (result == ESP_OK) { 51 | //The z portion is a length specifier which says the argument will be size_t in length. 52 | ESP_LOGV(TAG, "erase_range - start_address=0x%08zx, size=0x%08zx, result=0x%08x", start_address, size, result); 53 | } else { 54 | ESP_LOGE(TAG, "erase_range - start_address=0x%08zx, size=0x%08zx, result=0x%08x", start_address, size, result); 55 | } 56 | return result; 57 | } 58 | 59 | esp_err_t FatPartition::write(size_t dest_addr, const void *src, size_t size) 60 | { 61 | esp_err_t result = ESP_FAIL; 62 | if (g_flashmem.size() >= (dest_addr + size)) { 63 | result = ESP_OK; 64 | memcpy(&g_flashmem[0] + dest_addr, src, size); 65 | } 66 | return result; 67 | } 68 | 69 | esp_err_t FatPartition::read(size_t src_addr, void *dest, size_t size) 70 | { 71 | esp_err_t result = ESP_FAIL; 72 | if (g_flashmem.size() >= (src_addr + size)) { 73 | result = ESP_OK; 74 | memcpy(dest, &g_flashmem[0] + src_addr, size); 75 | } 76 | return result; 77 | } 78 | 79 | size_t FatPartition::sector_size() 80 | { 81 | ESP_LOGI(TAG, "%s() returns sector_size=%d", __func__, SPI_FLASH_SEC_SIZE); 82 | return SPI_FLASH_SEC_SIZE; 83 | } 84 | 85 | FatPartition::~FatPartition() 86 | { 87 | 88 | } 89 | -------------------------------------------------------------------------------- /tclap/ArgTraits.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 2 | 3 | /****************************************************************************** 4 | * 5 | * file: ArgTraits.h 6 | * 7 | * Copyright (c) 2007, Daniel Aarno, Michael E. Smoot . 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | // This is an internal tclap file, you should probably not have to 24 | // include this directly 25 | 26 | #ifndef TCLAP_ARGTRAITS_H 27 | #define TCLAP_ARGTRAITS_H 28 | 29 | namespace TCLAP { 30 | 31 | // We use two empty structs to get compile type specialization 32 | // function to work 33 | 34 | /** 35 | * A value like argument value type is a value that can be set using 36 | * operator>>. This is the default value type. 37 | */ 38 | struct ValueLike { 39 | typedef ValueLike ValueCategory; 40 | virtual ~ValueLike() {} 41 | }; 42 | 43 | /** 44 | * A string like argument value type is a value that can be set using 45 | * operator=(string). Usefull if the value type contains spaces which 46 | * will be broken up into individual tokens by operator>>. 47 | */ 48 | struct StringLike { 49 | virtual ~StringLike() {} 50 | }; 51 | 52 | /** 53 | * A class can inherit from this object to make it have string like 54 | * traits. This is a compile time thing and does not add any overhead 55 | * to the inherenting class. 56 | */ 57 | struct StringLikeTrait { 58 | typedef StringLike ValueCategory; 59 | virtual ~StringLikeTrait() {} 60 | }; 61 | 62 | /** 63 | * A class can inherit from this object to make it have value like 64 | * traits. This is a compile time thing and does not add any overhead 65 | * to the inherenting class. 66 | */ 67 | struct ValueLikeTrait { 68 | typedef ValueLike ValueCategory; 69 | virtual ~ValueLikeTrait() {} 70 | }; 71 | 72 | /** 73 | * Arg traits are used to get compile type specialization when parsing 74 | * argument values. Using an ArgTraits you can specify the way that 75 | * values gets assigned to any particular type during parsing. The two 76 | * supported types are StringLike and ValueLike. 77 | */ 78 | template 79 | struct ArgTraits { 80 | typedef typename T::ValueCategory ValueCategory; 81 | virtual ~ArgTraits() {} 82 | //typedef ValueLike ValueCategory; 83 | }; 84 | 85 | #endif 86 | 87 | } // namespace 88 | -------------------------------------------------------------------------------- /esp_idf/include/esp_err.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | typedef int32_t esp_err_t; 25 | 26 | /* Definitions for error constants. */ 27 | 28 | #define ESP_OK 0 29 | #define ESP_FAIL -1 30 | 31 | #define ESP_ERR_NO_MEM 0x101 32 | #define ESP_ERR_INVALID_ARG 0x102 33 | #define ESP_ERR_INVALID_STATE 0x103 34 | #define ESP_ERR_INVALID_SIZE 0x104 35 | #define ESP_ERR_NOT_FOUND 0x105 36 | #define ESP_ERR_NOT_SUPPORTED 0x106 37 | #define ESP_ERR_TIMEOUT 0x107 38 | #define ESP_ERR_INVALID_RESPONSE 0x108 39 | #define ESP_ERR_INVALID_CRC 0x109 40 | #define ESP_ERR_INVALID_VERSION 0x10A 41 | #define ESP_ERR_INVALID_MAC 0x10B 42 | 43 | #define ESP_ERR_WIFI_BASE 0x3000 /*!< Starting number of WiFi error codes */ 44 | 45 | void _esp_error_check_failed(esp_err_t rc, const char *file, int line, const char *function, const char *expression) __attribute__((noreturn)); 46 | 47 | #ifndef __ASSERT_FUNC 48 | /* This won't happen on IDF, which defines __ASSERT_FUNC in assert.h, but it does happen when building on the host which 49 | uses /usr/include/assert.h or equivalent. 50 | */ 51 | #ifdef __ASSERT_FUNCTION 52 | #define __ASSERT_FUNC __ASSERT_FUNCTION /* used in glibc assert.h */ 53 | #else 54 | #define __ASSERT_FUNC "??" 55 | #endif 56 | #endif 57 | 58 | /** 59 | * Macro which can be used to check the error code, 60 | * and terminate the program in case the code is not ESP_OK. 61 | * Prints the error code, error location, and the failed statement to serial output. 62 | * 63 | * Disabled if assertions are disabled. 64 | */ 65 | #ifdef NDEBUG 66 | #define ESP_ERROR_CHECK(x) do { \ 67 | esp_err_t rc = (x); \ 68 | (void) sizeof(rc); \ 69 | } while(0); 70 | #else 71 | #define ESP_ERROR_CHECK(x) do { \ 72 | esp_err_t rc = (x); \ 73 | if (rc != ESP_OK) { \ 74 | _esp_error_check_failed(rc, __FILE__, __LINE__, \ 75 | __ASSERT_FUNC, #x); \ 76 | } \ 77 | } while(0); 78 | #endif 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | -------------------------------------------------------------------------------- /filesystem/diskio/diskio.c: -------------------------------------------------------------------------------- 1 | /*-----------------------------------------------------------------------*/ 2 | /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2016 */ 3 | /* ESP-IDF port Copyright 2016 Espressif Systems (Shanghai) PTE LTD */ 4 | /*-----------------------------------------------------------------------*/ 5 | /* If a working storage control module is available, it should be */ 6 | /* attached to the FatFs via a glue function rather than modifying it. */ 7 | /* This is an example of glue functions to attach various exsisting */ 8 | /* storage control modules to the FatFs module with a defined API. */ 9 | /*-----------------------------------------------------------------------*/ 10 | 11 | #include 12 | #include 13 | #include 14 | #include "diskio.h" /* FatFs lower layer API */ 15 | #include "ffconf.h" 16 | #include "ff.h" 17 | 18 | static ff_diskio_impl_t * s_impls[_VOLUMES] = { NULL }; //驱动器操作函数结构数组,记录对应驱动器的驱动函数入口,目前支持两个驱动器。 19 | 20 | #if _MULTI_PARTITION /* Multiple partition configuration */ 21 | PARTITION VolToPart[] = { 22 | {0, 0}, /* Logical drive 0 ==> Physical drive 0, auto detection */ 23 | {1, 0} /* Logical drive 1 ==> Physical drive 1, auto detection */ 24 | }; 25 | #endif 26 | 27 | /* 查找未用驱动器号 28 | 上层通过获取驱动器号,实现对该驱动器的访问。 29 | */ 30 | esp_err_t ff_diskio_get_drive(BYTE* out_pdrv) 31 | { 32 | BYTE i; 33 | for(i=0; i<_VOLUMES; i++) { 34 | if (!s_impls[i]) { 35 | *out_pdrv = i; 36 | return ESP_OK; 37 | } 38 | } 39 | return ESP_ERR_NOT_FOUND; 40 | } 41 | 42 | void ff_diskio_register(BYTE pdrv, const ff_diskio_impl_t* discio_impl) 43 | { 44 | assert(pdrv < _VOLUMES); 45 | 46 | if (s_impls[pdrv]) { //如果本驱动器号已挂载驱动,释放之 47 | ff_diskio_impl_t* im = s_impls[pdrv]; 48 | s_impls[pdrv] = NULL; 49 | free(im); 50 | } 51 | 52 | if (!discio_impl) { 53 | return; 54 | } 55 | /* 重新分配资源,挂载新的驱动*/ 56 | ff_diskio_impl_t * impl = (ff_diskio_impl_t *)malloc(sizeof(ff_diskio_impl_t)); 57 | assert(impl != NULL); 58 | memcpy(impl, discio_impl, sizeof(ff_diskio_impl_t)); 59 | s_impls[pdrv] = impl; 60 | } 61 | 62 | DSTATUS ff_disk_initialize (BYTE pdrv) 63 | { 64 | return s_impls[pdrv]->init(pdrv); 65 | } 66 | DSTATUS ff_disk_status (BYTE pdrv) 67 | { 68 | return s_impls[pdrv]->status(pdrv); 69 | } 70 | DRESULT ff_disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count) 71 | { 72 | return s_impls[pdrv]->read(pdrv, buff, sector, count); 73 | } 74 | DRESULT ff_disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count) 75 | { 76 | return s_impls[pdrv]->write(pdrv, buff, sector, count); 77 | } 78 | DRESULT ff_disk_ioctl (BYTE pdrv, BYTE cmd, void* buff) 79 | { 80 | return s_impls[pdrv]->ioctl(pdrv, cmd, buff); 81 | } 82 | 83 | DWORD get_fattime(void) 84 | { 85 | time_t t = time(NULL); 86 | struct tm *tmr = gmtime(&t); 87 | int year = tmr->tm_year < 80 ? 0 : tmr->tm_year - 80; 88 | return ((DWORD)(year) << 25) 89 | | ((DWORD)(tmr->tm_mon + 1) << 21) 90 | | ((DWORD)tmr->tm_mday << 16) 91 | | (WORD)(tmr->tm_hour << 11) 92 | | (WORD)(tmr->tm_min << 5) 93 | | (WORD)(tmr->tm_sec >> 1); 94 | } 95 | -------------------------------------------------------------------------------- /tclap/ValuesConstraint.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /****************************************************************************** 4 | * 5 | * file: ValuesConstraint.h 6 | * 7 | * Copyright (c) 2005, Michael E. Smoot 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | #ifndef TCLAP_VALUESCONSTRAINT_H 24 | #define TCLAP_VALUESCONSTRAINT_H 25 | 26 | #include 27 | #include 28 | #include "Constraint.h" 29 | 30 | #ifdef HAVE_CONFIG_H 31 | #include 32 | #else 33 | #define HAVE_SSTREAM 34 | #endif 35 | 36 | #if defined(HAVE_SSTREAM) 37 | #include 38 | #elif defined(HAVE_STRSTREAM) 39 | #include 40 | #else 41 | #error "Need a stringstream (sstream or strstream) to compile!" 42 | #endif 43 | 44 | namespace TCLAP { 45 | 46 | /** 47 | * A Constraint that constrains the Arg to only those values specified 48 | * in the constraint. 49 | */ 50 | template 51 | class ValuesConstraint : public Constraint 52 | { 53 | 54 | public: 55 | 56 | /** 57 | * Constructor. 58 | * \param allowed - vector of allowed values. 59 | */ 60 | ValuesConstraint(std::vector& allowed); 61 | 62 | /** 63 | * Virtual destructor. 64 | */ 65 | virtual ~ValuesConstraint() {} 66 | 67 | /** 68 | * Returns a description of the Constraint. 69 | */ 70 | virtual std::string description() const; 71 | 72 | /** 73 | * Returns the short ID for the Constraint. 74 | */ 75 | virtual std::string shortID() const; 76 | 77 | /** 78 | * The method used to verify that the value parsed from the command 79 | * line meets the constraint. 80 | * \param value - The value that will be checked. 81 | */ 82 | virtual bool check(const T& value) const; 83 | 84 | protected: 85 | 86 | /** 87 | * The list of valid values. 88 | */ 89 | std::vector _allowed; 90 | 91 | /** 92 | * The string used to describe the allowed values of this constraint. 93 | */ 94 | std::string _typeDesc; 95 | 96 | }; 97 | 98 | template 99 | ValuesConstraint::ValuesConstraint(std::vector& allowed) 100 | : _allowed(allowed), 101 | _typeDesc("") 102 | { 103 | for ( unsigned int i = 0; i < _allowed.size(); i++ ) 104 | { 105 | 106 | #if defined(HAVE_SSTREAM) 107 | std::ostringstream os; 108 | #elif defined(HAVE_STRSTREAM) 109 | std::ostrstream os; 110 | #else 111 | #error "Need a stringstream (sstream or strstream) to compile!" 112 | #endif 113 | 114 | os << _allowed[i]; 115 | 116 | std::string temp( os.str() ); 117 | 118 | if ( i > 0 ) 119 | _typeDesc += "|"; 120 | _typeDesc += temp; 121 | } 122 | } 123 | 124 | template 125 | bool ValuesConstraint::check( const T& val ) const 126 | { 127 | if ( std::find(_allowed.begin(),_allowed.end(),val) == _allowed.end() ) 128 | return false; 129 | else 130 | return true; 131 | } 132 | 133 | template 134 | std::string ValuesConstraint::shortID() const 135 | { 136 | return _typeDesc; 137 | } 138 | 139 | template 140 | std::string ValuesConstraint::description() const 141 | { 142 | return _typeDesc; 143 | } 144 | 145 | 146 | } //namespace TCLAP 147 | #endif 148 | 149 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp 3 | // mkfatfs 4 | // 5 | // Created by Victor Mizikov on 20/09/2017. 6 | // Copyright (c) 2017 Victor Mizikov. All rights reserved. 7 | // 8 | #include "Config.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "esp_err.h" 17 | #include "esp_log.h" 18 | #define TCLAP_SETBASE_ZERO 1 19 | #include "tclap/CmdLine.h" 20 | #include "tclap/UnlabeledValueArg.h" 21 | #include "pack_fat.h" 22 | #include "pack_littlefs.h" 23 | 24 | #define APP_VERSION mkfatfs_VERSION 25 | 26 | int g_debugLevel = 0; 27 | 28 | enum Action { ACTION_NONE, ACTION_PACK, ACTION_UNPACK, ACTION_LIST, ACTION_VISUALIZE }; 29 | static Action s_action = ACTION_NONE; 30 | 31 | static std::string s_dirName; 32 | static std::string s_imageName; 33 | static int s_imageSize; 34 | static std::string s_fs; 35 | 36 | void processArgs(int argc, const char** argv) { 37 | TCLAP::CmdLine cmd("", ' ', APP_VERSION); 38 | TCLAP::ValueArg packArg( "c", "create", "create fatFS image from a directory", true, "", "pack_dir"); 39 | TCLAP::ValueArg unpackArg( "u", "unpack", "unpack fatFS image to a directory", true, "", "dest_dir"); 40 | TCLAP::SwitchArg listArg( "l", "list", "list files in fatFS image", false); 41 | TCLAP::SwitchArg visualizeArg( "i", "visualize", "visualize fatFS image", false); 42 | TCLAP::UnlabeledValueArg outNameArg( "image_file", "fatFS image file", true, "", "image_file" ); 43 | TCLAP::ValueArg imageSizeArg( "s", "size", "fs image size, in bytes", false, 0x200000, "number" ); 44 | TCLAP::ValueArg debugArg( "d", "debug", "Debug level. 0 means no debug output.", false, 0, "0-5" ); 45 | TCLAP::ValueArg fsType( "t", "type", "Select file system type, suport fatfs littlefs now.", false, "fatfs", "fatfs or littlefs" ); 46 | 47 | cmd.add( imageSizeArg ); 48 | cmd.add(debugArg); 49 | std::vector args = {&packArg, &unpackArg, &listArg, &visualizeArg}; 50 | cmd.xorAdd( args ); 51 | cmd.add( outNameArg ); 52 | cmd.add( fsType ); 53 | cmd.parse( argc, argv ); 54 | 55 | if (debugArg.getValue() > 0) { 56 | std::cout << "Debug output enabled" << std::endl; 57 | g_debugLevel = debugArg.getValue(); 58 | } 59 | 60 | if (packArg.isSet()) { 61 | s_dirName = packArg.getValue(); 62 | s_action = ACTION_PACK; 63 | } else if (unpackArg.isSet()) { 64 | s_dirName = unpackArg.getValue(); 65 | s_action = ACTION_UNPACK; 66 | } else if (listArg.isSet()) { 67 | s_action = ACTION_LIST; 68 | } else if (visualizeArg.isSet()) { 69 | s_action = ACTION_VISUALIZE; 70 | } 71 | 72 | s_imageName = outNameArg.getValue(); 73 | s_imageSize = imageSizeArg.getValue(); 74 | s_fs = fsType.getValue(); 75 | } 76 | 77 | int main(int argc, const char * argv[]) { 78 | try { 79 | processArgs(argc, argv); 80 | } catch(...) { 81 | std::cerr << "Invalid arguments" << std::endl; 82 | return 1; 83 | } 84 | 85 | Pack_fat pack_fat = Pack_fat(); 86 | Pack_littlefs pack_littlefs = Pack_littlefs(); 87 | 88 | switch (s_action) { 89 | case ACTION_PACK: 90 | if(s_fs == "fatfs") 91 | return pack_fat.actionPack(s_dirName, s_imageName, s_imageSize); 92 | else if(s_fs == "littlefs") 93 | return pack_littlefs.actionPack(s_dirName, s_imageName, s_imageSize); 94 | break; 95 | case ACTION_UNPACK: 96 | if(s_fs == "fatfs") 97 | return pack_fat.actionUnpack(s_imageName, s_dirName, s_imageSize); 98 | else if(s_fs == "littlefs") 99 | return pack_littlefs.actionUnpack(s_imageName, s_dirName, s_imageSize); 100 | break; 101 | break; 102 | case ACTION_LIST: 103 | 104 | break; 105 | case ACTION_VISUALIZE: 106 | 107 | break; 108 | default: 109 | break; 110 | } 111 | 112 | return 1; 113 | } 114 | -------------------------------------------------------------------------------- /filesystem/fatfs/syscall.c: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------*/ 2 | /* Sample code of OS dependent controls for FatFs */ 3 | /* (C)ChaN, 2014 */ 4 | /*------------------------------------------------------------------------*/ 5 | 6 | 7 | #include "ff.h" 8 | #include "semphr.h" 9 | 10 | #if _FS_REENTRANT 11 | /*------------------------------------------------------------------------*/ 12 | /* Create a Synchronization Object */ 13 | /*------------------------------------------------------------------------*/ 14 | /* This function is called in f_mount() function to create a new 15 | / synchronization object, such as semaphore and mutex. When a 0 is returned, 16 | / the f_mount() function fails with FR_INT_ERR. 17 | */ 18 | 19 | int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */ 20 | BYTE vol, /* Corresponding volume (logical drive number) */ 21 | _SYNC_t *sobj /* Pointer to return the created sync object */ 22 | ) 23 | { 24 | *sobj = xSemaphoreCreateMutex(); 25 | return (*sobj != NULL) ? 1 : 0; 26 | } 27 | 28 | 29 | 30 | /*------------------------------------------------------------------------*/ 31 | /* Delete a Synchronization Object */ 32 | /*------------------------------------------------------------------------*/ 33 | /* This function is called in f_mount() function to delete a synchronization 34 | / object that created with ff_cre_syncobj() function. When a 0 is returned, 35 | / the f_mount() function fails with FR_INT_ERR. 36 | */ 37 | 38 | int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to any error */ 39 | _SYNC_t sobj /* Sync object tied to the logical drive to be deleted */ 40 | ) 41 | { 42 | vSemaphoreDelete(sobj); 43 | return 1; 44 | } 45 | 46 | 47 | 48 | /*------------------------------------------------------------------------*/ 49 | /* Request Grant to Access the Volume */ 50 | /*------------------------------------------------------------------------*/ 51 | /* This function is called on entering file functions to lock the volume. 52 | / When a 0 is returned, the file function fails with FR_TIMEOUT. 53 | */ 54 | 55 | int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */ 56 | _SYNC_t sobj /* Sync object to wait */ 57 | ) 58 | { 59 | return (xSemaphoreTake(sobj, _FS_TIMEOUT) == pdTRUE) ? 1 : 0; 60 | } 61 | 62 | 63 | 64 | /*------------------------------------------------------------------------*/ 65 | /* Release Grant to Access the Volume */ 66 | /*------------------------------------------------------------------------*/ 67 | /* This function is called on leaving file functions to unlock the volume. 68 | */ 69 | 70 | void ff_rel_grant ( 71 | _SYNC_t sobj /* Sync object to be signaled */ 72 | ) 73 | { 74 | xSemaphoreGive(sobj); 75 | } 76 | 77 | #endif 78 | 79 | 80 | 81 | 82 | #if _USE_LFN == 3 /* LFN with a working buffer on the heap */ 83 | /*------------------------------------------------------------------------*/ 84 | /* Allocate a memory block */ 85 | /*------------------------------------------------------------------------*/ 86 | /* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE. 87 | */ 88 | 89 | void* ff_memalloc ( /* Returns pointer to the allocated memory block */ 90 | UINT msize /* Number of bytes to allocate */ 91 | ) 92 | { 93 | return malloc(msize); /* Allocate a new memory block with POSIX API */ 94 | } 95 | 96 | 97 | /*------------------------------------------------------------------------*/ 98 | /* Free a memory block */ 99 | /*------------------------------------------------------------------------*/ 100 | 101 | void ff_memfree ( 102 | void* mblock /* Pointer to the memory block to free */ 103 | ) 104 | { 105 | free(mblock); /* Discard the memory block with POSIX API */ 106 | } 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /tclap/CmdLineInterface.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: CmdLineInterface.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot . 7 | * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | #ifndef TCLAP_COMMANDLINE_INTERFACE_H 24 | #define TCLAP_COMMANDLINE_INTERFACE_H 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | 33 | namespace TCLAP { 34 | 35 | class Arg; 36 | class CmdLineOutput; 37 | class XorHandler; 38 | 39 | /** 40 | * The base class that manages the command line definition and passes 41 | * along the parsing to the appropriate Arg classes. 42 | */ 43 | class CmdLineInterface 44 | { 45 | public: 46 | 47 | /** 48 | * Destructor 49 | */ 50 | virtual ~CmdLineInterface() {} 51 | 52 | /** 53 | * Adds an argument to the list of arguments to be parsed. 54 | * \param a - Argument to be added. 55 | */ 56 | virtual void add( Arg& a )=0; 57 | 58 | /** 59 | * An alternative add. Functionally identical. 60 | * \param a - Argument to be added. 61 | */ 62 | virtual void add( Arg* a )=0; 63 | 64 | /** 65 | * Add two Args that will be xor'd. 66 | * If this method is used, add does 67 | * not need to be called. 68 | * \param a - Argument to be added and xor'd. 69 | * \param b - Argument to be added and xor'd. 70 | */ 71 | virtual void xorAdd( Arg& a, Arg& b )=0; 72 | 73 | /** 74 | * Add a list of Args that will be xor'd. If this method is used, 75 | * add does not need to be called. 76 | * \param xors - List of Args to be added and xor'd. 77 | */ 78 | virtual void xorAdd( std::vector& xors )=0; 79 | 80 | /** 81 | * Parses the command line. 82 | * \param argc - Number of arguments. 83 | * \param argv - Array of arguments. 84 | */ 85 | virtual void parse(int argc, const char * const * argv)=0; 86 | 87 | /** 88 | * Parses the command line. 89 | * \param args - A vector of strings representing the args. 90 | * args[0] is still the program name. 91 | */ 92 | void parse(std::vector& args); 93 | 94 | /** 95 | * Returns the CmdLineOutput object. 96 | */ 97 | virtual CmdLineOutput* getOutput()=0; 98 | 99 | /** 100 | * \param co - CmdLineOutput object that we want to use instead. 101 | */ 102 | virtual void setOutput(CmdLineOutput* co)=0; 103 | 104 | /** 105 | * Returns the version string. 106 | */ 107 | virtual std::string& getVersion()=0; 108 | 109 | /** 110 | * Returns the program name string. 111 | */ 112 | virtual std::string& getProgramName()=0; 113 | 114 | /** 115 | * Returns the argList. 116 | */ 117 | virtual std::list& getArgList()=0; 118 | 119 | /** 120 | * Returns the XorHandler. 121 | */ 122 | virtual XorHandler& getXorHandler()=0; 123 | 124 | /** 125 | * Returns the delimiter string. 126 | */ 127 | virtual char getDelimiter()=0; 128 | 129 | /** 130 | * Returns the message string. 131 | */ 132 | virtual std::string& getMessage()=0; 133 | 134 | /** 135 | * Indicates whether or not the help and version switches were created 136 | * automatically. 137 | */ 138 | virtual bool hasHelpAndVersion()=0; 139 | 140 | /** 141 | * Resets the instance as if it had just been constructed so that the 142 | * instance can be reused. 143 | */ 144 | virtual void reset()=0; 145 | }; 146 | 147 | } //namespace 148 | 149 | 150 | #endif 151 | -------------------------------------------------------------------------------- /filesystem/diskio/diskio_RAM.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include "diskio.h" 17 | #include "ffconf.h" 18 | #include "ff.h" 19 | #include "esp_log.h" 20 | #include "diskio_RAM.h" 21 | #include "FatPartition.h" 22 | 23 | static const char* TAG = "ff_diskio_RAM"; 24 | 25 | FatPartition *part[_VOLUMES] = {NULL, NULL}; 26 | 27 | RAM_handle_t ff_RAM_handles[_VOLUMES] = { //支持两个RAM驱动器 28 | RAM_INVALID_HANDLE, 29 | RAM_INVALID_HANDLE, 30 | }; 31 | 32 | DSTATUS ff_RAM_initialize (BYTE pdrv) 33 | { 34 | return 0; 35 | } 36 | 37 | DSTATUS ff_RAM_status (BYTE pdrv) 38 | { 39 | return 0; 40 | } 41 | 42 | DRESULT ff_RAM_read (BYTE pdrv, BYTE *buff, DWORD sector, UINT count) 43 | { 44 | ESP_LOGV(TAG, "ff_RAM_read - pdrv=%i, sector=%i, count=%i\n", (unsigned int)pdrv, (unsigned int)sector, (unsigned int)count); 45 | RAM_handle_t RAM_handle = ff_RAM_handles[pdrv]; 46 | assert(RAM_handle + 1); 47 | esp_err_t err = part[RAM_handle]->read(sector * part[RAM_handle]->sector_size(), buff, count * part[RAM_handle]->sector_size()); 48 | if (err != ESP_OK) { 49 | ESP_LOGE(TAG, "RAM_read failed (%d)", err); 50 | return RES_ERROR; 51 | } 52 | return RES_OK; 53 | } 54 | 55 | DRESULT ff_RAM_write (BYTE pdrv, const BYTE *buff, DWORD sector, UINT count) 56 | { 57 | ESP_LOGV(TAG, "ff_RAM_write - pdrv=%i, sector=%i, count=%i\n", (unsigned int)pdrv, (unsigned int)sector, (unsigned int)count); 58 | RAM_handle_t RAM_handle = ff_RAM_handles[pdrv]; 59 | assert(RAM_handle + 1); 60 | esp_err_t err = part[RAM_handle]->erase_range(sector * part[RAM_handle]->sector_size(), count * part[RAM_handle]->sector_size()); 61 | if (err != ESP_OK) { 62 | ESP_LOGE(TAG, "RAM_erase_range failed (%d)", err); 63 | return RES_ERROR; 64 | } 65 | err = part[RAM_handle]->write(sector * part[RAM_handle]->sector_size(), buff, count * part[RAM_handle] -> sector_size()); 66 | if (err != ESP_OK) { 67 | ESP_LOGE(TAG, "RAM_write failed (%d)", err); 68 | return RES_ERROR; 69 | } 70 | return RES_OK; 71 | } 72 | 73 | DRESULT ff_RAM_ioctl (BYTE pdrv, BYTE cmd, void *buff) 74 | { 75 | RAM_handle_t RAM_handle = ff_RAM_handles[pdrv]; 76 | ESP_LOGV(TAG, "ff_RAM_ioctl: cmd=%i\n", cmd); 77 | assert(RAM_handle + 1); 78 | switch (cmd) { 79 | case CTRL_SYNC: 80 | return RES_OK; 81 | case GET_SECTOR_COUNT: 82 | *((uint32_t *) buff) = part[RAM_handle]->chip_size() / part[RAM_handle]->sector_size(); 83 | return RES_OK; 84 | case GET_SECTOR_SIZE: 85 | *((uint32_t *) buff) = part[RAM_handle]->sector_size(); 86 | return RES_OK; 87 | case GET_BLOCK_SIZE: 88 | return RES_ERROR; 89 | } 90 | return RES_ERROR; 91 | } 92 | 93 | 94 | esp_err_t ff_diskio_register_RAM_partition(BYTE pdrv, RAM_handle_t RAM_handle, esp_partition_t *data_partition) 95 | { 96 | void *part_ptr = NULL; 97 | if (pdrv >= _VOLUMES) { 98 | return ESP_ERR_INVALID_ARG; 99 | } 100 | static const ff_diskio_impl_t RAM_impl = { 101 | .init = &ff_RAM_initialize, 102 | .status = &ff_RAM_status, 103 | .read = &ff_RAM_read, 104 | .write = &ff_RAM_write, 105 | .ioctl = &ff_RAM_ioctl 106 | }; 107 | ff_RAM_handles[pdrv] = RAM_handle; 108 | ff_diskio_register(pdrv, &RAM_impl); 109 | 110 | // Allocate memory for a Partition object, and then initialize the object 111 | // using placement new operator. This way we can recover from out of 112 | // memory condition. 113 | part_ptr = malloc(sizeof(FatPartition)); 114 | if (part_ptr == NULL) { 115 | ESP_LOGE(TAG, "%s: can't allocate FatPartition", __func__); 116 | return ESP_FAIL; 117 | } 118 | part[pdrv] = new (part_ptr) FatPartition(data_partition); 119 | return ESP_OK; 120 | } 121 | 122 | esp_err_t ff_diskio_unregister_RAM_partition(BYTE pdrv, RAM_handle_t RAM_handle) 123 | { 124 | // delete part[pdrv]; 125 | return ESP_OK; 126 | } 127 | 128 | BYTE ff_diskio_get_pdrv_RAM(RAM_handle_t RAM_handle) 129 | { 130 | for (int i = 0; i < _VOLUMES; i++) { 131 | if (RAM_handle == ff_RAM_handles[i]) { 132 | return i; 133 | } 134 | } 135 | return 0xff; 136 | } 137 | -------------------------------------------------------------------------------- /tclap/XorHandler.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: XorHandler.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot . 7 | * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | #ifndef TCLAP_XORHANDLER_H 24 | #define TCLAP_XORHANDLER_H 25 | 26 | #include "Arg.h" 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | namespace TCLAP { 33 | 34 | /** 35 | * This class handles lists of Arg's that are to be XOR'd on the command 36 | * line. This is used by CmdLine and you shouldn't ever use it. 37 | */ 38 | class XorHandler 39 | { 40 | protected: 41 | 42 | /** 43 | * The list of of lists of Arg's to be or'd together. 44 | */ 45 | std::vector< std::vector > _orList; 46 | 47 | public: 48 | 49 | /** 50 | * Constructor. Does nothing. 51 | */ 52 | XorHandler( ) : _orList(std::vector< std::vector >()) {} 53 | 54 | /** 55 | * Add a list of Arg*'s that will be orred together. 56 | * \param ors - list of Arg* that will be xor'd. 57 | */ 58 | void add( std::vector& ors ); 59 | 60 | /** 61 | * Checks whether the specified Arg is in one of the xor lists and 62 | * if it does match one, returns the size of the xor list that the 63 | * Arg matched. If the Arg matches, then it also sets the rest of 64 | * the Arg's in the list. You shouldn't use this. 65 | * \param a - The Arg to be checked. 66 | */ 67 | int check( const Arg* a ); 68 | 69 | /** 70 | * Returns the XOR specific short usage. 71 | */ 72 | std::string shortUsage(); 73 | 74 | /** 75 | * Prints the XOR specific long usage. 76 | * \param os - Stream to print to. 77 | */ 78 | void printLongUsage(std::ostream& os); 79 | 80 | /** 81 | * Simply checks whether the Arg is contained in one of the arg 82 | * lists. 83 | * \param a - The Arg to be checked. 84 | */ 85 | bool contains( const Arg* a ); 86 | 87 | std::vector< std::vector >& getXorList(); 88 | 89 | }; 90 | 91 | 92 | ////////////////////////////////////////////////////////////////////// 93 | //BEGIN XOR.cpp 94 | ////////////////////////////////////////////////////////////////////// 95 | inline void XorHandler::add( std::vector& ors ) 96 | { 97 | _orList.push_back( ors ); 98 | } 99 | 100 | inline int XorHandler::check( const Arg* a ) 101 | { 102 | // iterate over each XOR list 103 | for ( int i = 0; static_cast(i) < _orList.size(); i++ ) 104 | { 105 | // if the XOR list contains the arg.. 106 | ArgVectorIterator ait = std::find( _orList[i].begin(), 107 | _orList[i].end(), a ); 108 | if ( ait != _orList[i].end() ) 109 | { 110 | // first check to see if a mutually exclusive switch 111 | // has not already been set 112 | for ( ArgVectorIterator it = _orList[i].begin(); 113 | it != _orList[i].end(); 114 | it++ ) 115 | if ( a != (*it) && (*it)->isSet() ) 116 | throw(CmdLineParseException( 117 | "Mutually exclusive argument already set!", 118 | (*it)->toString())); 119 | 120 | // go through and set each arg that is not a 121 | for ( ArgVectorIterator it = _orList[i].begin(); 122 | it != _orList[i].end(); 123 | it++ ) 124 | if ( a != (*it) ) 125 | (*it)->xorSet(); 126 | 127 | // return the number of required args that have now been set 128 | if ( (*ait)->allowMore() ) 129 | return 0; 130 | else 131 | return static_cast(_orList[i].size()); 132 | } 133 | } 134 | 135 | if ( a->isRequired() ) 136 | return 1; 137 | else 138 | return 0; 139 | } 140 | 141 | inline bool XorHandler::contains( const Arg* a ) 142 | { 143 | for ( int i = 0; static_cast(i) < _orList.size(); i++ ) 144 | for ( ArgVectorIterator it = _orList[i].begin(); 145 | it != _orList[i].end(); 146 | it++ ) 147 | if ( a == (*it) ) 148 | return true; 149 | 150 | return false; 151 | } 152 | 153 | inline std::vector< std::vector >& XorHandler::getXorList() 154 | { 155 | return _orList; 156 | } 157 | 158 | 159 | 160 | ////////////////////////////////////////////////////////////////////// 161 | //END XOR.cpp 162 | ////////////////////////////////////////////////////////////////////// 163 | 164 | } //namespace TCLAP 165 | 166 | #endif 167 | -------------------------------------------------------------------------------- /filesystem/diskio/include/diskio.h: -------------------------------------------------------------------------------- 1 | /*-----------------------------------------------------------------------/ 2 | / Low level disk interface modlue include file (C)ChaN, 2014 / 3 | /-----------------------------------------------------------------------*/ 4 | 5 | #ifndef _DISKIO_DEFINED 6 | #define _DISKIO_DEFINED 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #include "integer.h" 13 | #include "esp_err.h" 14 | // #include "sdmmc_cmd.h" 15 | // #include "driver/sdmmc_host.h" 16 | 17 | /* Status of Disk Functions */ 18 | typedef BYTE DSTATUS; 19 | 20 | /* Results of Disk Functions */ 21 | typedef enum { 22 | RES_OK = 0, /* 0: Successful */ 23 | RES_ERROR, /* 1: R/W Error */ 24 | RES_WRPRT, /* 2: Write Protected */ 25 | RES_NOTRDY, /* 3: Not Ready */ 26 | RES_PARERR /* 4: Invalid Parameter */ 27 | } DRESULT; 28 | 29 | 30 | /*---------------------------------------*/ 31 | /* Prototypes for disk control functions */ 32 | 33 | 34 | /* Redefine names of disk IO functions to prevent name collisions */ 35 | #define disk_initialize ff_disk_initialize 36 | #define disk_status ff_disk_status 37 | #define disk_read ff_disk_read 38 | #define disk_write ff_disk_write 39 | #define disk_ioctl ff_disk_ioctl 40 | 41 | 42 | DSTATUS disk_initialize (BYTE pdrv); 43 | DSTATUS disk_status (BYTE pdrv); 44 | DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count); 45 | DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count); 46 | DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff); 47 | 48 | /** 49 | * Structure of pointers to disk IO driver functions. 50 | * 51 | * See FatFs documentation for details about these functions 52 | */ 53 | typedef struct { 54 | DSTATUS (*init) (BYTE pdrv); /*!< disk initialization function */ 55 | DSTATUS (*status) (BYTE pdrv); /*!< disk status check function */ 56 | DRESULT (*read) (BYTE pdrv, BYTE* buff, DWORD sector, UINT count); /*!< sector read function */ 57 | DRESULT (*write) (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count); /*!< sector write function */ 58 | DRESULT (*ioctl) (BYTE pdrv, BYTE cmd, void* buff); /*!< function to get info about disk and do some misc operations */ 59 | } ff_diskio_impl_t; 60 | 61 | /** 62 | * Register or unregister diskio driver for given drive number. 63 | * 64 | * When FATFS library calls one of disk_xxx functions for driver number pdrv, 65 | * corresponding function in discio_impl for given pdrv will be called. 66 | * 67 | * @param pdrv drive number 68 | * @param discio_impl pointer to ff_diskio_impl_t structure with diskio functions 69 | * or NULL to unregister and free previously registered drive 70 | */ 71 | void ff_diskio_register(BYTE pdrv, const ff_diskio_impl_t* discio_impl); 72 | 73 | #define ff_diskio_unregister(pdrv_) ff_diskio_register(pdrv_, NULL) 74 | 75 | /** 76 | * Register SD/MMC diskio driver 77 | * 78 | * @param pdrv drive number 79 | * @param card pointer to sdmmc_card_t structure describing a card; card should be initialized before calling f_mount. 80 | */ 81 | // void ff_diskio_register_sdmmc(BYTE pdrv, sdmmc_card_t* card); 82 | 83 | /** 84 | * Get next available drive number 85 | * 86 | * @param out_pdrv pointer to the byte to set if successful 87 | * 88 | * @return ESP_OK on success 89 | * ESP_ERR_NOT_FOUND if all drives are attached 90 | */ 91 | esp_err_t ff_diskio_get_drive(BYTE* out_pdrv); 92 | 93 | /* Disk Status Bits (DSTATUS) */ 94 | 95 | #define STA_NOINIT 0x01 /* Drive not initialized */ 96 | #define STA_NODISK 0x02 /* No medium in the drive */ 97 | #define STA_PROTECT 0x04 /* Write protected */ 98 | 99 | 100 | /* Command code for disk_ioctrl fucntion */ 101 | 102 | /* Generic command (Used by FatFs) */ 103 | #define CTRL_SYNC 0 /* Complete pending write process (needed at _FS_READONLY == 0) */ 104 | #define GET_SECTOR_COUNT 1 /* Get media size (needed at _USE_MKFS == 1) */ 105 | #define GET_SECTOR_SIZE 2 /* Get sector size (needed at _MAX_SS != _MIN_SS) */ 106 | #define GET_BLOCK_SIZE 3 /* Get erase block size (needed at _USE_MKFS == 1) */ 107 | #define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */ 108 | 109 | /* Generic command (Not used by FatFs) */ 110 | #define CTRL_POWER 5 /* Get/Set power status */ 111 | #define CTRL_LOCK 6 /* Lock/Unlock media removal */ 112 | #define CTRL_EJECT 7 /* Eject media */ 113 | #define CTRL_FORMAT 8 /* Create physical format on the media */ 114 | 115 | /* MMC/SDC specific ioctl command */ 116 | #define MMC_GET_TYPE 10 /* Get card type */ 117 | #define MMC_GET_CSD 11 /* Get CSD */ 118 | #define MMC_GET_CID 12 /* Get CID */ 119 | #define MMC_GET_OCR 13 /* Get OCR */ 120 | #define MMC_GET_SDSTAT 14 /* Get SD status */ 121 | #define ISDIO_READ 55 /* Read data form SD iSDIO register */ 122 | #define ISDIO_WRITE 56 /* Write data to SD iSDIO register */ 123 | #define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */ 124 | 125 | /* ATA/CF specific ioctl command */ 126 | #define ATA_GET_REV 20 /* Get F/W revision */ 127 | #define ATA_GET_MODEL 21 /* Get model name */ 128 | #define ATA_GET_SN 22 /* Get serial number */ 129 | 130 | #ifdef __cplusplus 131 | } 132 | #endif 133 | 134 | #endif 135 | -------------------------------------------------------------------------------- /tclap/StandardTraits.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 2 | 3 | /****************************************************************************** 4 | * 5 | * file: StandardTraits.h 6 | * 7 | * Copyright (c) 2007, Daniel Aarno, Michael E. Smoot . 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | // This is an internal tclap file, you should probably not have to 24 | // include this directly 25 | 26 | #ifndef TCLAP_STANDARD_TRAITS_H 27 | #define TCLAP_STANDARD_TRAITS_H 28 | 29 | #ifdef HAVE_CONFIG_H 30 | #include // To check for long long 31 | #endif 32 | 33 | // If Microsoft has already typedef'd wchar_t as an unsigned 34 | // short, then compiles will break because it's as if we're 35 | // creating ArgTraits twice for unsigned short. Thus... 36 | #ifdef _MSC_VER 37 | #ifndef _NATIVE_WCHAR_T_DEFINED 38 | #define TCLAP_DONT_DECLARE_WCHAR_T_ARGTRAITS 39 | #endif 40 | #endif 41 | 42 | namespace TCLAP { 43 | 44 | // ====================================================================== 45 | // Integer types 46 | // ====================================================================== 47 | 48 | /** 49 | * longs have value-like semantics. 50 | */ 51 | template<> 52 | struct ArgTraits { 53 | typedef ValueLike ValueCategory; 54 | }; 55 | 56 | /** 57 | * ints have value-like semantics. 58 | */ 59 | template<> 60 | struct ArgTraits { 61 | typedef ValueLike ValueCategory; 62 | }; 63 | 64 | /** 65 | * shorts have value-like semantics. 66 | */ 67 | template<> 68 | struct ArgTraits { 69 | typedef ValueLike ValueCategory; 70 | }; 71 | 72 | /** 73 | * chars have value-like semantics. 74 | */ 75 | template<> 76 | struct ArgTraits { 77 | typedef ValueLike ValueCategory; 78 | }; 79 | 80 | #ifdef HAVE_LONG_LONG 81 | /** 82 | * long longs have value-like semantics. 83 | */ 84 | template<> 85 | struct ArgTraits { 86 | typedef ValueLike ValueCategory; 87 | }; 88 | #endif 89 | 90 | // ====================================================================== 91 | // Unsigned integer types 92 | // ====================================================================== 93 | 94 | /** 95 | * unsigned longs have value-like semantics. 96 | */ 97 | template<> 98 | struct ArgTraits { 99 | typedef ValueLike ValueCategory; 100 | }; 101 | 102 | /** 103 | * unsigned ints have value-like semantics. 104 | */ 105 | template<> 106 | struct ArgTraits { 107 | typedef ValueLike ValueCategory; 108 | }; 109 | 110 | /** 111 | * unsigned shorts have value-like semantics. 112 | */ 113 | template<> 114 | struct ArgTraits { 115 | typedef ValueLike ValueCategory; 116 | }; 117 | 118 | /** 119 | * unsigned chars have value-like semantics. 120 | */ 121 | template<> 122 | struct ArgTraits { 123 | typedef ValueLike ValueCategory; 124 | }; 125 | 126 | // Microsoft implements size_t awkwardly. 127 | #if defined(_MSC_VER) && defined(_M_X64) 128 | /** 129 | * size_ts have value-like semantics. 130 | */ 131 | template<> 132 | struct ArgTraits { 133 | typedef ValueLike ValueCategory; 134 | }; 135 | #endif 136 | 137 | 138 | #ifdef HAVE_LONG_LONG 139 | /** 140 | * unsigned long longs have value-like semantics. 141 | */ 142 | template<> 143 | struct ArgTraits { 144 | typedef ValueLike ValueCategory; 145 | }; 146 | #endif 147 | 148 | // ====================================================================== 149 | // Float types 150 | // ====================================================================== 151 | 152 | /** 153 | * floats have value-like semantics. 154 | */ 155 | template<> 156 | struct ArgTraits { 157 | typedef ValueLike ValueCategory; 158 | }; 159 | 160 | /** 161 | * doubles have value-like semantics. 162 | */ 163 | template<> 164 | struct ArgTraits { 165 | typedef ValueLike ValueCategory; 166 | }; 167 | 168 | // ====================================================================== 169 | // Other types 170 | // ====================================================================== 171 | 172 | /** 173 | * bools have value-like semantics. 174 | */ 175 | template<> 176 | struct ArgTraits { 177 | typedef ValueLike ValueCategory; 178 | }; 179 | 180 | 181 | /** 182 | * wchar_ts have value-like semantics. 183 | */ 184 | #ifndef TCLAP_DONT_DECLARE_WCHAR_T_ARGTRAITS 185 | template<> 186 | struct ArgTraits { 187 | typedef ValueLike ValueCategory; 188 | }; 189 | #endif 190 | 191 | /** 192 | * Strings have string like argument traits. 193 | */ 194 | template<> 195 | struct ArgTraits { 196 | typedef StringLike ValueCategory; 197 | }; 198 | 199 | template 200 | void SetString(T &dst, const std::string &src) 201 | { 202 | dst = src; 203 | } 204 | 205 | } // namespace 206 | 207 | #endif 208 | 209 | -------------------------------------------------------------------------------- /tclap/ArgException.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 2 | 3 | /****************************************************************************** 4 | * 5 | * file: ArgException.h 6 | * 7 | * Copyright (c) 2003, Michael E. Smoot . 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | 24 | #ifndef TCLAP_ARG_EXCEPTION_H 25 | #define TCLAP_ARG_EXCEPTION_H 26 | 27 | #include 28 | #include 29 | 30 | namespace TCLAP { 31 | 32 | /** 33 | * A simple class that defines and argument exception. Should be caught 34 | * whenever a CmdLine is created and parsed. 35 | */ 36 | class ArgException : public std::exception 37 | { 38 | public: 39 | 40 | /** 41 | * Constructor. 42 | * \param text - The text of the exception. 43 | * \param id - The text identifying the argument source. 44 | * \param td - Text describing the type of ArgException it is. 45 | * of the exception. 46 | */ 47 | ArgException( const std::string& text = "undefined exception", 48 | const std::string& id = "undefined", 49 | const std::string& td = "Generic ArgException") 50 | : std::exception(), 51 | _errorText(text), 52 | _argId( id ), 53 | _typeDescription(td) 54 | { } 55 | 56 | /** 57 | * Destructor. 58 | */ 59 | virtual ~ArgException() throw() { } 60 | 61 | /** 62 | * Returns the error text. 63 | */ 64 | std::string error() const { return ( _errorText ); } 65 | 66 | /** 67 | * Returns the argument id. 68 | */ 69 | std::string argId() const 70 | { 71 | if ( _argId == "undefined" ) 72 | return " "; 73 | else 74 | return ( "Argument: " + _argId ); 75 | } 76 | 77 | /** 78 | * Returns the arg id and error text. 79 | */ 80 | const char* what() const throw() 81 | { 82 | static std::string ex; 83 | ex = _argId + " -- " + _errorText; 84 | return ex.c_str(); 85 | } 86 | 87 | /** 88 | * Returns the type of the exception. Used to explain and distinguish 89 | * between different child exceptions. 90 | */ 91 | std::string typeDescription() const 92 | { 93 | return _typeDescription; 94 | } 95 | 96 | 97 | private: 98 | 99 | /** 100 | * The text of the exception message. 101 | */ 102 | std::string _errorText; 103 | 104 | /** 105 | * The argument related to this exception. 106 | */ 107 | std::string _argId; 108 | 109 | /** 110 | * Describes the type of the exception. Used to distinguish 111 | * between different child exceptions. 112 | */ 113 | std::string _typeDescription; 114 | 115 | }; 116 | 117 | /** 118 | * Thrown from within the child Arg classes when it fails to properly 119 | * parse the argument it has been passed. 120 | */ 121 | class ArgParseException : public ArgException 122 | { 123 | public: 124 | /** 125 | * Constructor. 126 | * \param text - The text of the exception. 127 | * \param id - The text identifying the argument source 128 | * of the exception. 129 | */ 130 | ArgParseException( const std::string& text = "undefined exception", 131 | const std::string& id = "undefined" ) 132 | : ArgException( text, 133 | id, 134 | std::string( "Exception found while parsing " ) + 135 | std::string( "the value the Arg has been passed." )) 136 | { } 137 | }; 138 | 139 | /** 140 | * Thrown from CmdLine when the arguments on the command line are not 141 | * properly specified, e.g. too many arguments, required argument missing, etc. 142 | */ 143 | class CmdLineParseException : public ArgException 144 | { 145 | public: 146 | /** 147 | * Constructor. 148 | * \param text - The text of the exception. 149 | * \param id - The text identifying the argument source 150 | * of the exception. 151 | */ 152 | CmdLineParseException( const std::string& text = "undefined exception", 153 | const std::string& id = "undefined" ) 154 | : ArgException( text, 155 | id, 156 | std::string( "Exception found when the values ") + 157 | std::string( "on the command line do not meet ") + 158 | std::string( "the requirements of the defined ") + 159 | std::string( "Args." )) 160 | { } 161 | }; 162 | 163 | /** 164 | * Thrown from Arg and CmdLine when an Arg is improperly specified, e.g. 165 | * same flag as another Arg, same name, etc. 166 | */ 167 | class SpecificationException : public ArgException 168 | { 169 | public: 170 | /** 171 | * Constructor. 172 | * \param text - The text of the exception. 173 | * \param id - The text identifying the argument source 174 | * of the exception. 175 | */ 176 | SpecificationException( const std::string& text = "undefined exception", 177 | const std::string& id = "undefined" ) 178 | : ArgException( text, 179 | id, 180 | std::string("Exception found when an Arg object ")+ 181 | std::string("is improperly defined by the ") + 182 | std::string("developer." )) 183 | { } 184 | 185 | }; 186 | 187 | class ExitException { 188 | public: 189 | ExitException(int estat) : _estat(estat) {} 190 | 191 | int getExitStatus() const { return _estat; } 192 | 193 | private: 194 | int _estat; 195 | }; 196 | 197 | } // namespace TCLAP 198 | 199 | #endif 200 | 201 | -------------------------------------------------------------------------------- /tclap/MultiSwitchArg.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: MultiSwitchArg.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot . 7 | * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. 8 | * Copyright (c) 2005, Michael E. Smoot, Daniel Aarno, Erik Zeek. 9 | * All rights reverved. 10 | * 11 | * See the file COPYING in the top directory of this distribution for 12 | * more information. 13 | * 14 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * 22 | *****************************************************************************/ 23 | 24 | 25 | #ifndef TCLAP_MULTI_SWITCH_ARG_H 26 | #define TCLAP_MULTI_SWITCH_ARG_H 27 | 28 | #include 29 | #include 30 | 31 | #include "SwitchArg.h" 32 | 33 | namespace TCLAP { 34 | 35 | /** 36 | * A multiple switch argument. If the switch is set on the command line, then 37 | * the getValue method will return the number of times the switch appears. 38 | */ 39 | class MultiSwitchArg : public SwitchArg 40 | { 41 | protected: 42 | 43 | /** 44 | * The value of the switch. 45 | */ 46 | int _value; 47 | 48 | /** 49 | * Used to support the reset() method so that ValueArg can be 50 | * reset to their constructed value. 51 | */ 52 | int _default; 53 | 54 | public: 55 | 56 | /** 57 | * MultiSwitchArg constructor. 58 | * \param flag - The one character flag that identifies this 59 | * argument on the command line. 60 | * \param name - A one word name for the argument. Can be 61 | * used as a long flag on the command line. 62 | * \param desc - A description of what the argument is for or 63 | * does. 64 | * \param init - Optional. The initial/default value of this Arg. 65 | * Defaults to 0. 66 | * \param v - An optional visitor. You probably should not 67 | * use this unless you have a very good reason. 68 | */ 69 | MultiSwitchArg(const std::string& flag, 70 | const std::string& name, 71 | const std::string& desc, 72 | int init = 0, 73 | Visitor* v = NULL); 74 | 75 | 76 | /** 77 | * MultiSwitchArg constructor. 78 | * \param flag - The one character flag that identifies this 79 | * argument on the command line. 80 | * \param name - A one word name for the argument. Can be 81 | * used as a long flag on the command line. 82 | * \param desc - A description of what the argument is for or 83 | * does. 84 | * \param parser - A CmdLine parser object to add this Arg to 85 | * \param init - Optional. The initial/default value of this Arg. 86 | * Defaults to 0. 87 | * \param v - An optional visitor. You probably should not 88 | * use this unless you have a very good reason. 89 | */ 90 | MultiSwitchArg(const std::string& flag, 91 | const std::string& name, 92 | const std::string& desc, 93 | CmdLineInterface& parser, 94 | int init = 0, 95 | Visitor* v = NULL); 96 | 97 | 98 | /** 99 | * Handles the processing of the argument. 100 | * This re-implements the SwitchArg version of this method to set the 101 | * _value of the argument appropriately. 102 | * \param i - Pointer the the current argument in the list. 103 | * \param args - Mutable list of strings. Passed 104 | * in from main(). 105 | */ 106 | virtual bool processArg(int* i, std::vector& args); 107 | 108 | /** 109 | * Returns int, the number of times the switch has been set. 110 | */ 111 | int getValue(); 112 | 113 | /** 114 | * Returns the shortID for this Arg. 115 | */ 116 | std::string shortID(const std::string& val) const; 117 | 118 | /** 119 | * Returns the longID for this Arg. 120 | */ 121 | std::string longID(const std::string& val) const; 122 | 123 | void reset(); 124 | 125 | }; 126 | 127 | ////////////////////////////////////////////////////////////////////// 128 | //BEGIN MultiSwitchArg.cpp 129 | ////////////////////////////////////////////////////////////////////// 130 | inline MultiSwitchArg::MultiSwitchArg(const std::string& flag, 131 | const std::string& name, 132 | const std::string& desc, 133 | int init, 134 | Visitor* v ) 135 | : SwitchArg(flag, name, desc, false, v), 136 | _value( init ), 137 | _default( init ) 138 | { } 139 | 140 | inline MultiSwitchArg::MultiSwitchArg(const std::string& flag, 141 | const std::string& name, 142 | const std::string& desc, 143 | CmdLineInterface& parser, 144 | int init, 145 | Visitor* v ) 146 | : SwitchArg(flag, name, desc, false, v), 147 | _value( init ), 148 | _default( init ) 149 | { 150 | parser.add( this ); 151 | } 152 | 153 | inline int MultiSwitchArg::getValue() { return _value; } 154 | 155 | inline bool MultiSwitchArg::processArg(int *i, std::vector& args) 156 | { 157 | if ( _ignoreable && Arg::ignoreRest() ) 158 | return false; 159 | 160 | if ( argMatches( args[*i] )) 161 | { 162 | // so the isSet() method will work 163 | _alreadySet = true; 164 | 165 | // Matched argument: increment value. 166 | ++_value; 167 | 168 | _checkWithVisitor(); 169 | 170 | return true; 171 | } 172 | else if ( combinedSwitchesMatch( args[*i] ) ) 173 | { 174 | // so the isSet() method will work 175 | _alreadySet = true; 176 | 177 | // Matched argument: increment value. 178 | ++_value; 179 | 180 | // Check for more in argument and increment value. 181 | while ( combinedSwitchesMatch( args[*i] ) ) 182 | ++_value; 183 | 184 | _checkWithVisitor(); 185 | 186 | return false; 187 | } 188 | else 189 | return false; 190 | } 191 | 192 | inline std::string 193 | MultiSwitchArg::shortID(const std::string& val) const 194 | { 195 | return Arg::shortID(val) + " ... "; 196 | } 197 | 198 | inline std::string 199 | MultiSwitchArg::longID(const std::string& val) const 200 | { 201 | return Arg::longID(val) + " (accepted multiple times)"; 202 | } 203 | 204 | inline void 205 | MultiSwitchArg::reset() 206 | { 207 | MultiSwitchArg::_value = MultiSwitchArg::_default; 208 | } 209 | 210 | ////////////////////////////////////////////////////////////////////// 211 | //END MultiSwitchArg.cpp 212 | ////////////////////////////////////////////////////////////////////// 213 | 214 | } //namespace TCLAP 215 | 216 | #endif 217 | -------------------------------------------------------------------------------- /filesystem/vfs/user_vfs.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "esp_log.h" 5 | #include "esp_err.h" 6 | #include "diskio.h" 7 | #include "diskio_RAM.h" 8 | #include "esp_vfs_fat.h" 9 | #include "esp_vfs.h" 10 | 11 | #include "user_vfs.h" 12 | 13 | 14 | static const char *TAG = "fatfs"; 15 | 16 | static esp_partition_t s_partition = { 17 | /*esp_partition_type_t*/ .type = ESP_PARTITION_TYPE_DATA, /*!< partition type (app/data) */ 18 | /*esp_partition_subtype_t*/ .subtype = ESP_PARTITION_SUBTYPE_DATA_FAT, /*!< partition subtype */ 19 | /*uint32_t*/ .address = 0, /*!< starting address of the partition in flash */ 20 | /*uint32_t*/ .size = 0, /*!< size of the partition, in bytes */ 21 | /*char*/ .label = "storage", /*!< partition label, zero-terminated ASCII string */ 22 | /*bool*/ .encrypted = false, /*!< flag is set to true if partition is encrypted */ 23 | }; 24 | 25 | 26 | 27 | esp_err_t emulate_esp_vfs_fat_spiflash_mount(const char* base_path, 28 | //const char* partition_label, 29 | const esp_vfs_fat_mount_config_t* mount_config, 30 | RAM_handle_t* RAM_handle, 31 | FATFS** out_fs, 32 | int imageSize) 33 | { 34 | esp_err_t result = ESP_OK; 35 | const size_t workbuf_size = 4096; 36 | void *workbuf = NULL; 37 | 38 | *out_fs = NULL; //MVA 39 | 40 | s_partition.size = imageSize; 41 | esp_partition_t *data_partition = &s_partition; //记录分区相关信息 42 | 43 | // connect driver to FATFS 44 | BYTE pdrv = 0xFF; 45 | if (ff_diskio_get_drive(&pdrv) != ESP_OK) { //获取一个空驱动器号 46 | ESP_LOGD(TAG, "the maximum count of volumes is already mounted"); 47 | return ESP_ERR_NO_MEM; 48 | } 49 | ESP_LOGD(TAG, "using pdrv=%i", pdrv); 50 | char drv[3] = {(char)('0' + pdrv), ':', 0}; 51 | 52 | result = ff_diskio_register_RAM_partition(pdrv, *RAM_handle, data_partition); 53 | if (result != ESP_OK) { 54 | ESP_LOGE(TAG, "ff_diskio_register_RAM_partition failed pdrv=%i, error - 0x(%x)", pdrv, result); 55 | goto fail; 56 | } 57 | FATFS *fs = NULL; 58 | result = esp_vfs_fat_register(base_path, drv, mount_config->max_files, &fs); 59 | if (result == ESP_ERR_INVALID_STATE) { 60 | // it's okay, already registered with VFS 61 | } else if (result != ESP_OK) { 62 | ESP_LOGD(TAG, "esp_vfs_fat_register failed 0x(%x)", result); 63 | goto fail; 64 | } 65 | *out_fs = fs; 66 | 67 | // Try to mount partition 68 | FRESULT fresult = f_mount(fs, drv, 1); 69 | if (fresult != FR_OK) { 70 | ESP_LOGW(TAG, "f_mount failed (%d)", fresult); 71 | if (!(fresult == FR_NO_FILESYSTEM && mount_config->format_if_mount_failed)) { 72 | result = ESP_FAIL; 73 | goto fail; 74 | } 75 | workbuf = malloc(workbuf_size); 76 | ESP_LOGI(TAG, "Formatting FATFS partition"); 77 | fresult = f_mkfs(drv, FM_ANY | FM_SFD, workbuf_size, workbuf, workbuf_size); 78 | if (fresult != FR_OK) { 79 | result = ESP_FAIL; 80 | ESP_LOGE(TAG, "f_mkfs failed (%d)", fresult); 81 | goto fail; 82 | } 83 | free(workbuf); 84 | workbuf = NULL; 85 | ESP_LOGI(TAG, "Mounting again"); 86 | fresult = f_mount(fs, drv, 0); 87 | if (fresult != FR_OK) { 88 | result = ESP_FAIL; 89 | ESP_LOGE(TAG, "f_mount failed after formatting (%d)", fresult); 90 | goto fail; 91 | } 92 | } 93 | return ESP_OK; 94 | 95 | fail: 96 | free(workbuf); 97 | esp_vfs_fat_unregister_path(base_path); 98 | ff_diskio_unregister(pdrv); 99 | return result; 100 | } 101 | 102 | 103 | esp_err_t emulate_esp_vfs_fat_spiflash_unmount(const char *base_path, RAM_handle_t RAM_handle) 104 | { 105 | BYTE pdrv = ff_diskio_get_pdrv_RAM(RAM_handle); 106 | if (pdrv == 0xff) { 107 | return ESP_ERR_INVALID_STATE; 108 | } 109 | char drv[3] = {(char)('0' + pdrv), ':', 0}; 110 | 111 | f_mount(0, drv, 0); 112 | ff_diskio_unregister(pdrv); 113 | // release partition driver 114 | // esp_err_t err_drv = wl_unmount(RAM_handle); 115 | // ff_diskio_unregister_RAM_partition(pdrv, RAM_handle); 116 | esp_err_t err = esp_vfs_fat_unregister_path(base_path); 117 | // if (err == ESP_OK) err = err_drv; 118 | return err; 119 | } 120 | 121 | //------------------------------- 122 | // vfs.c 123 | //------------------------------- 124 | 125 | ssize_t emulate_esp_vfs_write(int fd, const void * data, size_t size) { 126 | struct _idf_reent *r = __idf_getreent(); 127 | return esp_vfs_write(r, fd, data, size); 128 | } 129 | 130 | off_t emulate_esp_vfs_lseek(int fd, off_t size, int mode) { 131 | struct _idf_reent *r = __idf_getreent(); 132 | return esp_vfs_lseek(r, fd, size, mode); 133 | } 134 | 135 | ssize_t emulate_esp_vfs_read(int fd, void * dst, size_t size) { 136 | struct _idf_reent *r = __idf_getreent(); 137 | return esp_vfs_read(r, fd, dst, size); 138 | } 139 | 140 | int emulate_esp_vfs_open(const char * path, int flags, int mode) { 141 | struct _idf_reent *r = __idf_getreent(); 142 | return esp_vfs_open(r, path, flags, mode); 143 | } 144 | 145 | int emulate_esp_vfs_close(int fd) { 146 | struct _idf_reent *r = __idf_getreent(); 147 | return esp_vfs_close(r, fd); 148 | } 149 | 150 | int emulate_esp_vfs_fstat(int fd, struct stat * st) { 151 | struct _idf_reent *r = __idf_getreent(); 152 | return esp_vfs_fstat(r, fd, st); 153 | } 154 | 155 | int emulate_esp_vfs_stat(const char * path, struct stat * st) { 156 | struct _idf_reent *r = __idf_getreent(); 157 | return esp_vfs_stat(r, path, st); 158 | } 159 | 160 | int emulate_esp_vfs_link(const char* n1, const char* n2) { 161 | struct _idf_reent *r = __idf_getreent(); 162 | return esp_vfs_link(r, n1, n2); 163 | } 164 | 165 | int emulate_esp_vfs_unlink(const char *path) { 166 | struct _idf_reent *r = __idf_getreent(); 167 | return esp_vfs_unlink(r, path); 168 | } 169 | 170 | int emulate_esp_vfs_rename(const char *src, const char *dst) { 171 | struct _idf_reent *r = __idf_getreent(); 172 | return esp_vfs_rename(r, src, dst); 173 | } 174 | 175 | //------- 176 | 177 | DIR* emulate_vfs_opendir(const char* name) { 178 | return vfs_opendir(name); 179 | } 180 | 181 | struct dirent* emulate_vfs_readdir(DIR* pdir) { 182 | return vfs_readdir(pdir); 183 | } 184 | 185 | int emulate_vfs_readdir_r(DIR* pdir, struct dirent* entry, struct dirent** out_dirent) { 186 | return vfs_readdir_r(pdir, entry, out_dirent); 187 | } 188 | 189 | long emulate_vfs_telldir(DIR* pdir) { 190 | return vfs_telldir(pdir); 191 | } 192 | 193 | void emulate_vfs_seekdir(DIR* pdir, long loc) { 194 | return vfs_seekdir(pdir, loc); 195 | } 196 | 197 | void emulate_vfs_rewinddir(DIR* pdir) { 198 | return vfs_rewinddir(pdir); 199 | } 200 | 201 | int emulate_vfs_closedir(DIR* pdir) { 202 | return vfs_closedir(pdir); 203 | } 204 | 205 | int emulate_vfs_mkdir(const char* name, mode_t mode) { 206 | return vfs_mkdir(name, mode); 207 | } 208 | 209 | int emulate_vfs_rmdir(const char* name) { 210 | return vfs_rmdir(name); 211 | } 212 | 213 | int emulate_vfs_fcntl(int fd, int cmd, ...) { 214 | int result; 215 | va_list args; 216 | va_start(args, cmd); 217 | result = vfs_fcntl(fd, cmd, args); 218 | va_end(args); 219 | return result; 220 | } 221 | 222 | 223 | -------------------------------------------------------------------------------- /filesystem/vfs/include/esp_vfs.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __ESP_VFS_H__ 16 | #define __ESP_VFS_H__ 17 | 18 | #include 19 | #include 20 | #include 21 | #include "esp_err.h" 22 | #include 23 | #include //MVA was 24 | #include 25 | #include //MVA was 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /** 32 | * Maximum length of path prefix (not including zero terminator) 33 | */ 34 | #define ESP_VFS_PATH_MAX 15 35 | 36 | /** 37 | * Default value of flags member in esp_vfs_t structure. 38 | */ 39 | #define ESP_VFS_FLAG_DEFAULT 0 40 | 41 | /** 42 | * Flag which indicates that FS needs extra context pointer in syscalls. 43 | */ 44 | #define ESP_VFS_FLAG_CONTEXT_PTR 1 45 | 46 | /** 47 | * @brief VFS definition structure 48 | * 49 | * This structure should be filled with pointers to corresponding 50 | * FS driver functions. 51 | * 52 | * If the FS implementation has an option to use certain offset for 53 | * all file descriptors, this value should be passed into fd_offset 54 | * field. Otherwise VFS component will translate all FDs to start 55 | * at zero offset. 56 | * 57 | * Some FS implementations expect some state (e.g. pointer to some structure) 58 | * to be passed in as a first argument. For these implementations, 59 | * populate the members of this structure which have _p suffix, set 60 | * flags member to ESP_VFS_FLAG_CONTEXT_PTR and provide the context pointer 61 | * to esp_vfs_register function. 62 | * If the implementation doesn't use this extra argument, populate the 63 | * members without _p suffix and set flags member to ESP_VFS_FLAG_DEFAULT. 64 | * 65 | * If the FS driver doesn't provide some of the functions, set corresponding 66 | * members to NULL. 67 | */ 68 | typedef struct 69 | { 70 | int fd_offset; /*!< file descriptor offset, determined by the FS driver */ 71 | int flags; /*!< ESP_VFS_FLAG_CONTEXT_PTR or ESP_VFS_FLAG_DEFAULT */ 72 | union { 73 | ssize_t (*write_p)(void* p, int fd, const void * data, size_t size); 74 | ssize_t (*write)(int fd, const void * data, size_t size); 75 | }; 76 | union { 77 | off_t (*lseek_p)(void* p, int fd, off_t size, int mode); 78 | off_t (*lseek)(int fd, off_t size, int mode); 79 | }; 80 | union { 81 | ssize_t (*read_p)(void* ctx, int fd, void * dst, size_t size); 82 | ssize_t (*read)(int fd, void * dst, size_t size); 83 | }; 84 | union { 85 | int (*open_p)(void* ctx, const char * path, int flags, int mode); 86 | int (*open)(const char * path, int flags, int mode); 87 | }; 88 | union { 89 | int (*close_p)(void* ctx, int fd); 90 | int (*close)(int fd); 91 | }; 92 | union { 93 | int (*fstat_p)(void* ctx, int fd, struct stat * st); 94 | int (*fstat)(int fd, struct stat * st); 95 | }; 96 | union { 97 | int (*stat_p)(void* ctx, const char * path, struct stat * st); 98 | int (*stat)(const char * path, struct stat * st); 99 | }; 100 | union { 101 | int (*link_p)(void* ctx, const char* n1, const char* n2); 102 | int (*link)(const char* n1, const char* n2); 103 | }; 104 | union { 105 | int (*unlink_p)(void* ctx, const char *path); 106 | int (*unlink)(const char *path); 107 | }; 108 | union { 109 | int (*rename_p)(void* ctx, const char *src, const char *dst); 110 | int (*rename)(const char *src, const char *dst); 111 | }; 112 | union { 113 | DIR* (*opendir_p)(void* ctx, const char* name); 114 | DIR* (*opendir)(const char* name); 115 | }; 116 | union { 117 | struct dirent* (*readdir_p)(void* ctx, DIR* pdir); 118 | struct dirent* (*readdir)(DIR* pdir); 119 | }; 120 | union { 121 | int (*readdir_r_p)(void* ctx, DIR* pdir, struct dirent* entry, struct dirent** out_dirent); 122 | int (*readdir_r)(DIR* pdir, struct dirent* entry, struct dirent** out_dirent); 123 | }; 124 | union { 125 | long (*telldir_p)(void* ctx, DIR* pdir); 126 | long (*telldir)(DIR* pdir); 127 | }; 128 | union { 129 | void (*seekdir_p)(void* ctx, DIR* pdir, long offset); 130 | void (*seekdir)(DIR* pdir, long offset); 131 | }; 132 | union { 133 | int (*closedir_p)(void* ctx, DIR* pdir); 134 | int (*closedir)(DIR* pdir); 135 | }; 136 | union { 137 | int (*mkdir_p)(void* ctx, const char* name, mode_t mode); 138 | int (*mkdir)(const char* name, mode_t mode); 139 | }; 140 | union { 141 | int (*rmdir_p)(void* ctx, const char* name); 142 | int (*rmdir)(const char* name); 143 | }; 144 | union { 145 | int (*fcntl_p)(void* ctx, int fd, int cmd, va_list args); 146 | int (*fcntl)(int fd, int cmd, va_list args); 147 | }; 148 | } esp_vfs_t; 149 | 150 | 151 | /** 152 | * Register a virtual filesystem for given path prefix. 153 | * 154 | * @param base_path file path prefix associated with the filesystem. 155 | * Must be a zero-terminated C string, up to ESP_VFS_PATH_MAX 156 | * characters long, and at least 2 characters long. 157 | * Name must start with a "/" and must not end with "/". 158 | * For example, "/data" or "/dev/spi" are valid. 159 | * These VFSes would then be called to handle file paths such as 160 | * "/data/myfile.txt" or "/dev/spi/0". 161 | * @param vfs Pointer to esp_vfs_t, a structure which maps syscalls to 162 | * the filesystem driver functions. VFS component doesn't 163 | * assume ownership of this pointer. 164 | * @param ctx If vfs->flags has ESP_VFS_FLAG_CONTEXT_PTR set, a pointer 165 | * which should be passed to VFS functions. Otherwise, NULL. 166 | * 167 | * @return ESP_OK if successful, ESP_ERR_NO_MEM if too many VFSes are 168 | * registered. 169 | */ 170 | esp_err_t esp_vfs_register(const char* base_path, const esp_vfs_t* vfs, void* ctx); 171 | 172 | 173 | /** 174 | * Unregister a virtual filesystem for given path prefix 175 | * 176 | * @param base_path file prefix previously used in esp_vfs_register call 177 | * @return ESP_OK if successful, ESP_ERR_INVALID_STATE if VFS for given prefix 178 | * hasn't been registered 179 | */ 180 | esp_err_t esp_vfs_unregister(const char* base_path); 181 | 182 | /** 183 | * These functions are to be used in newlib syscall table. They will be called by 184 | * newlib when it needs to use any of the syscalls. 185 | */ 186 | /**@{*/ 187 | 188 | ssize_t esp_vfs_write(struct _idf_reent *r, int fd, const void * data, size_t size); 189 | off_t esp_vfs_lseek(struct _idf_reent *r, int fd, off_t size, int mode); 190 | ssize_t esp_vfs_read(struct _idf_reent *r, int fd, void * dst, size_t size); 191 | int esp_vfs_open(struct _idf_reent *r, const char * path, int flags, int mode); 192 | int esp_vfs_close(struct _idf_reent *r, int fd); 193 | int esp_vfs_fstat(struct _idf_reent *r, int fd, struct stat * st); 194 | int esp_vfs_stat(struct _idf_reent *r, const char * path, struct stat * st); 195 | int esp_vfs_link(struct _idf_reent *r, const char* n1, const char* n2); 196 | int esp_vfs_unlink(struct _idf_reent *r, const char *path); 197 | int esp_vfs_rename(struct _idf_reent *r, const char *src, const char *dst); 198 | 199 | 200 | 201 | /**@}*/ 202 | 203 | 204 | #ifdef __cplusplus 205 | } // extern "C" 206 | #endif 207 | 208 | #endif //__ESP_VFS_H__ 209 | -------------------------------------------------------------------------------- /esp_idf/include/esp_errno.h: -------------------------------------------------------------------------------- 1 | /* errno is not a global variable, because that would make using it 2 | non-reentrant. Instead, its address is returned by the function 3 | __errno. */ 4 | 5 | #ifndef _SYS_ERRNO_H_ 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | #define _SYS_ERRNO_H_ 10 | 11 | #include "idf_reent.h" //MVA was 12 | 13 | //MVA VVV 14 | /* 15 | #ifndef _REENT_ONLY 16 | #define errno (*__errno()) 17 | extern int *__errno _PARAMS ((void)); 18 | #endif 19 | 20 | 21 | // Please don't use these variables directly. Use strerror instead. 22 | extern __IMPORT _CONST char * _CONST _sys_errlist[]; 23 | extern __IMPORT int _sys_nerr; 24 | #ifdef __CYGWIN__ 25 | extern __IMPORT const char * const sys_errlist[]; 26 | extern __IMPORT int sys_nerr; 27 | extern __IMPORT char *program_invocation_name; 28 | extern __IMPORT char *program_invocation_short_name; 29 | #endif 30 | */ 31 | 32 | extern int esp_errno; 33 | //MVA ^^^ 34 | 35 | 36 | 37 | #define __errno_r(ptr) ((ptr)->_errno) 38 | 39 | #define EPERM 1 /* Not owner */ 40 | #define ENOENT 2 /* No such file or directory */ 41 | #define ESRCH 3 /* No such process */ 42 | #define EINTR 4 /* Interrupted system call */ 43 | #define EIO 5 /* I/O error */ 44 | #define ENXIO 6 /* No such device or address */ 45 | #define E2BIG 7 /* Arg list too long */ 46 | #define ENOEXEC 8 /* Exec format error */ 47 | #define EBADF 9 /* Bad file number */ 48 | #define ECHILD 10 /* No children */ 49 | #define EAGAIN 11 /* No more processes */ 50 | #define ENOMEM 12 /* Not enough space */ 51 | #define EACCES 13 /* Permission denied */ 52 | #define EFAULT 14 /* Bad address */ 53 | #ifdef __LINUX_ERRNO_EXTENSIONS__ 54 | #define ENOTBLK 15 /* Block device required */ 55 | #endif 56 | #define EBUSY 16 /* Device or resource busy */ 57 | #define EEXIST 17 /* File exists */ 58 | #define EXDEV 18 /* Cross-device link */ 59 | #define ENODEV 19 /* No such device */ 60 | #define ENOTDIR 20 /* Not a directory */ 61 | #define EISDIR 21 /* Is a directory */ 62 | #define EINVAL 22 /* Invalid argument */ 63 | #define ENFILE 23 /* Too many open files in system */ 64 | #define EMFILE 24 /* File descriptor value too large */ 65 | #define ENOTTY 25 /* Not a character device */ 66 | #define ETXTBSY 26 /* Text file busy */ 67 | #define EFBIG 27 /* File too large */ 68 | #define ENOSPC 28 /* No space left on device */ 69 | #define ESPIPE 29 /* Illegal seek */ 70 | #define EROFS 30 /* Read-only file system */ 71 | #define EMLINK 31 /* Too many links */ 72 | #define EPIPE 32 /* Broken pipe */ 73 | #define EDOM 33 /* Mathematics argument out of domain of function */ 74 | #define ERANGE 34 /* Result too large */ 75 | #define ENOMSG 35 /* No message of desired type */ 76 | #define EIDRM 36 /* Identifier removed */ 77 | #ifdef __LINUX_ERRNO_EXTENSIONS__ 78 | #define ECHRNG 37 /* Channel number out of range */ 79 | #define EL2NSYNC 38 /* Level 2 not synchronized */ 80 | #define EL3HLT 39 /* Level 3 halted */ 81 | #define EL3RST 40 /* Level 3 reset */ 82 | #define ELNRNG 41 /* Link number out of range */ 83 | #define EUNATCH 42 /* Protocol driver not attached */ 84 | #define ENOCSI 43 /* No CSI structure available */ 85 | #define EL2HLT 44 /* Level 2 halted */ 86 | #endif 87 | #define EDEADLK 45 /* Deadlock */ 88 | #define ENOLCK 46 /* No lock */ 89 | #ifdef __LINUX_ERRNO_EXTENSIONS__ 90 | #define EBADE 50 /* Invalid exchange */ 91 | #define EBADR 51 /* Invalid request descriptor */ 92 | #define EXFULL 52 /* Exchange full */ 93 | #define ENOANO 53 /* No anode */ 94 | #define EBADRQC 54 /* Invalid request code */ 95 | #define EBADSLT 55 /* Invalid slot */ 96 | #define EDEADLOCK 56 /* File locking deadlock error */ 97 | #define EBFONT 57 /* Bad font file fmt */ 98 | #endif 99 | #define ENOSTR 60 /* Not a stream */ 100 | #define ENODATA 61 /* No data (for no delay io) */ 101 | #define ETIME 62 /* Stream ioctl timeout */ 102 | #define ENOSR 63 /* No stream resources */ 103 | #ifdef __LINUX_ERRNO_EXTENSIONS__ 104 | #define ENONET 64 /* Machine is not on the network */ 105 | #define ENOPKG 65 /* Package not installed */ 106 | #define EREMOTE 66 /* The object is remote */ 107 | #endif 108 | #define ENOLINK 67 /* Virtual circuit is gone */ 109 | #ifdef __LINUX_ERRNO_EXTENSIONS__ 110 | #define EADV 68 /* Advertise error */ 111 | #define ESRMNT 69 /* Srmount error */ 112 | #define ECOMM 70 /* Communication error on send */ 113 | #endif 114 | #define EPROTO 71 /* Protocol error */ 115 | #define EMULTIHOP 74 /* Multihop attempted */ 116 | #ifdef __LINUX_ERRNO_EXTENSIONS__ 117 | #define ELBIN 75 /* Inode is remote (not really error) */ 118 | #define EDOTDOT 76 /* Cross mount point (not really error) */ 119 | #endif 120 | #define EBADMSG 77 /* Bad message */ 121 | #define EFTYPE 79 /* Inappropriate file type or format */ 122 | #ifdef __LINUX_ERRNO_EXTENSIONS__ 123 | #define ENOTUNIQ 80 /* Given log. name not unique */ 124 | #define EBADFD 81 /* f.d. invalid for this operation */ 125 | #define EREMCHG 82 /* Remote address changed */ 126 | #define ELIBACC 83 /* Can't access a needed shared lib */ 127 | #define ELIBBAD 84 /* Accessing a corrupted shared lib */ 128 | #define ELIBSCN 85 /* .lib section in a.out corrupted */ 129 | #define ELIBMAX 86 /* Attempting to link in too many libs */ 130 | #define ELIBEXEC 87 /* Attempting to exec a shared library */ 131 | #endif 132 | #define ENOSYS 88 /* Function not implemented */ 133 | #ifdef __CYGWIN__ 134 | #define ENMFILE 89 /* No more files */ 135 | #endif 136 | #define ENOTEMPTY 90 /* Directory not empty */ 137 | #define ENAMETOOLONG 91 /* File or path name too long */ 138 | #define ELOOP 92 /* Too many symbolic links */ 139 | #define EOPNOTSUPP 95 /* Operation not supported on socket */ 140 | #define EPFNOSUPPORT 96 /* Protocol family not supported */ 141 | #define ECONNRESET 104 /* Connection reset by peer */ 142 | #define ENOBUFS 105 /* No buffer space available */ 143 | #define EAFNOSUPPORT 106 /* Address family not supported by protocol family */ 144 | #define EPROTOTYPE 107 /* Protocol wrong type for socket */ 145 | #define ENOTSOCK 108 /* Socket operation on non-socket */ 146 | #define ENOPROTOOPT 109 /* Protocol not available */ 147 | #ifdef __LINUX_ERRNO_EXTENSIONS__ 148 | #define ESHUTDOWN 110 /* Can't send after socket shutdown */ 149 | #endif 150 | #define ECONNREFUSED 111 /* Connection refused */ 151 | #define EADDRINUSE 112 /* Address already in use */ 152 | #define ECONNABORTED 113 /* Software caused connection abort */ 153 | #define ENETUNREACH 114 /* Network is unreachable */ 154 | #define ENETDOWN 115 /* Network interface is not configured */ 155 | #define ETIMEDOUT 116 /* Connection timed out */ 156 | #define EHOSTDOWN 117 /* Host is down */ 157 | #define EHOSTUNREACH 118 /* Host is unreachable */ 158 | #define EINPROGRESS 119 /* Connection already in progress */ 159 | #define EALREADY 120 /* Socket already connected */ 160 | #define EDESTADDRREQ 121 /* Destination address required */ 161 | #define EMSGSIZE 122 /* Message too long */ 162 | #define EPROTONOSUPPORT 123 /* Unknown protocol */ 163 | #ifdef __LINUX_ERRNO_EXTENSIONS__ 164 | #define ESOCKTNOSUPPORT 124 /* Socket type not supported */ 165 | #endif 166 | #define EADDRNOTAVAIL 125 /* Address not available */ 167 | #define ENETRESET 126 /* Connection aborted by network */ 168 | #define EISCONN 127 /* Socket is already connected */ 169 | #define ENOTCONN 128 /* Socket is not connected */ 170 | #define ETOOMANYREFS 129 171 | #ifdef __LINUX_ERRNO_EXTENSIONS__ 172 | #define EPROCLIM 130 173 | #define EUSERS 131 174 | #endif 175 | #define EDQUOT 132 176 | #define ESTALE 133 177 | #define ENOTSUP 134 /* Not supported */ 178 | #ifdef __LINUX_ERRNO_EXTENSIONS__ 179 | #define ENOMEDIUM 135 /* No medium (in tape drive) */ 180 | #endif 181 | #ifdef __CYGWIN__ 182 | #define ENOSHARE 136 /* No such host or network path */ 183 | #define ECASECLASH 137 /* Filename exists with different case */ 184 | #endif 185 | #define EILSEQ 138 /* Illegal byte sequence */ 186 | #define EOVERFLOW 139 /* Value too large for defined data type */ 187 | #define ECANCELED 140 /* Operation canceled */ 188 | #define ENOTRECOVERABLE 141 /* State not recoverable */ 189 | #define EOWNERDEAD 142 /* Previous owner died */ 190 | #ifdef __LINUX_ERRNO_EXTENSIONS__ 191 | #define ESTRPIPE 143 /* Streams pipe error */ 192 | #endif 193 | #define EWOULDBLOCK EAGAIN /* Operation would block */ 194 | 195 | #define __ELASTERROR 2000 /* Users can add values starting here */ 196 | 197 | #ifdef __cplusplus 198 | } 199 | #endif 200 | #endif /* _SYS_ERRNO_H */ 201 | -------------------------------------------------------------------------------- /tclap/SwitchArg.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: SwitchArg.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot . 7 | * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | 24 | #ifndef TCLAP_SWITCH_ARG_H 25 | #define TCLAP_SWITCH_ARG_H 26 | 27 | #include 28 | #include 29 | 30 | #include "Arg.h" 31 | 32 | namespace TCLAP { 33 | 34 | /** 35 | * A simple switch argument. If the switch is set on the command line, then 36 | * the getValue method will return the opposite of the default value for the 37 | * switch. 38 | */ 39 | class SwitchArg : public Arg 40 | { 41 | protected: 42 | 43 | /** 44 | * The value of the switch. 45 | */ 46 | bool _value; 47 | 48 | /** 49 | * Used to support the reset() method so that ValueArg can be 50 | * reset to their constructed value. 51 | */ 52 | bool _default; 53 | 54 | public: 55 | 56 | /** 57 | * SwitchArg constructor. 58 | * \param flag - The one character flag that identifies this 59 | * argument on the command line. 60 | * \param name - A one word name for the argument. Can be 61 | * used as a long flag on the command line. 62 | * \param desc - A description of what the argument is for or 63 | * does. 64 | * \param def - The default value for this Switch. 65 | * \param v - An optional visitor. You probably should not 66 | * use this unless you have a very good reason. 67 | */ 68 | SwitchArg(const std::string& flag, 69 | const std::string& name, 70 | const std::string& desc, 71 | bool def = false, 72 | Visitor* v = NULL); 73 | 74 | 75 | /** 76 | * SwitchArg constructor. 77 | * \param flag - The one character flag that identifies this 78 | * argument on the command line. 79 | * \param name - A one word name for the argument. Can be 80 | * used as a long flag on the command line. 81 | * \param desc - A description of what the argument is for or 82 | * does. 83 | * \param parser - A CmdLine parser object to add this Arg to 84 | * \param def - The default value for this Switch. 85 | * \param v - An optional visitor. You probably should not 86 | * use this unless you have a very good reason. 87 | */ 88 | SwitchArg(const std::string& flag, 89 | const std::string& name, 90 | const std::string& desc, 91 | CmdLineInterface& parser, 92 | bool def = false, 93 | Visitor* v = NULL); 94 | 95 | 96 | /** 97 | * Handles the processing of the argument. 98 | * This re-implements the Arg version of this method to set the 99 | * _value of the argument appropriately. 100 | * \param i - Pointer the the current argument in the list. 101 | * \param args - Mutable list of strings. Passed 102 | * in from main(). 103 | */ 104 | virtual bool processArg(int* i, std::vector& args); 105 | 106 | /** 107 | * Checks a string to see if any of the chars in the string 108 | * match the flag for this Switch. 109 | */ 110 | bool combinedSwitchesMatch(std::string& combined); 111 | 112 | /** 113 | * Returns bool, whether or not the switch has been set. 114 | */ 115 | bool getValue(); 116 | 117 | virtual void reset(); 118 | 119 | private: 120 | /** 121 | * Checks to see if we've found the last match in 122 | * a combined string. 123 | */ 124 | bool lastCombined(std::string& combined); 125 | 126 | /** 127 | * Does the common processing of processArg. 128 | */ 129 | void commonProcessing(); 130 | }; 131 | 132 | ////////////////////////////////////////////////////////////////////// 133 | //BEGIN SwitchArg.cpp 134 | ////////////////////////////////////////////////////////////////////// 135 | inline SwitchArg::SwitchArg(const std::string& flag, 136 | const std::string& name, 137 | const std::string& desc, 138 | bool default_val, 139 | Visitor* v ) 140 | : Arg(flag, name, desc, false, false, v), 141 | _value( default_val ), 142 | _default( default_val ) 143 | { } 144 | 145 | inline SwitchArg::SwitchArg(const std::string& flag, 146 | const std::string& name, 147 | const std::string& desc, 148 | CmdLineInterface& parser, 149 | bool default_val, 150 | Visitor* v ) 151 | : Arg(flag, name, desc, false, false, v), 152 | _value( default_val ), 153 | _default(default_val) 154 | { 155 | parser.add( this ); 156 | } 157 | 158 | inline bool SwitchArg::getValue() { return _value; } 159 | 160 | inline bool SwitchArg::lastCombined(std::string& combinedSwitches ) 161 | { 162 | for ( unsigned int i = 1; i < combinedSwitches.length(); i++ ) 163 | if ( combinedSwitches[i] != Arg::blankChar() ) 164 | return false; 165 | 166 | return true; 167 | } 168 | 169 | inline bool SwitchArg::combinedSwitchesMatch(std::string& combinedSwitches ) 170 | { 171 | // make sure this is actually a combined switch 172 | if ( combinedSwitches.length() > 0 && 173 | combinedSwitches[0] != Arg::flagStartString()[0] ) 174 | return false; 175 | 176 | // make sure it isn't a long name 177 | if ( combinedSwitches.substr( 0, Arg::nameStartString().length() ) == 178 | Arg::nameStartString() ) 179 | return false; 180 | 181 | // make sure the delimiter isn't in the string 182 | if ( combinedSwitches.find_first_of( Arg::delimiter() ) != std::string::npos ) 183 | return false; 184 | 185 | // ok, we're not specifying a ValueArg, so we know that we have 186 | // a combined switch list. 187 | for ( unsigned int i = 1; i < combinedSwitches.length(); i++ ) 188 | if ( _flag.length() > 0 && 189 | combinedSwitches[i] == _flag[0] && 190 | _flag[0] != Arg::flagStartString()[0] ) 191 | { 192 | // update the combined switches so this one is no longer present 193 | // this is necessary so that no unlabeled args are matched 194 | // later in the processing. 195 | //combinedSwitches.erase(i,1); 196 | combinedSwitches[i] = Arg::blankChar(); 197 | return true; 198 | } 199 | 200 | // none of the switches passed in the list match. 201 | return false; 202 | } 203 | 204 | inline void SwitchArg::commonProcessing() 205 | { 206 | if ( _xorSet ) 207 | throw(CmdLineParseException( 208 | "Mutually exclusive argument already set!", toString())); 209 | 210 | if ( _alreadySet ) 211 | throw(CmdLineParseException("Argument already set!", toString())); 212 | 213 | _alreadySet = true; 214 | 215 | if ( _value == true ) 216 | _value = false; 217 | else 218 | _value = true; 219 | 220 | _checkWithVisitor(); 221 | } 222 | 223 | inline bool SwitchArg::processArg(int *i, std::vector& args) 224 | { 225 | if ( _ignoreable && Arg::ignoreRest() ) 226 | return false; 227 | 228 | // if the whole string matches the flag or name string 229 | if ( argMatches( args[*i] ) ) 230 | { 231 | commonProcessing(); 232 | 233 | return true; 234 | } 235 | // if a substring matches the flag as part of a combination 236 | else if ( combinedSwitchesMatch( args[*i] ) ) 237 | { 238 | // check again to ensure we don't misinterpret 239 | // this as a MultiSwitchArg 240 | if ( combinedSwitchesMatch( args[*i] ) ) 241 | throw(CmdLineParseException("Argument already set!", 242 | toString())); 243 | 244 | commonProcessing(); 245 | 246 | // We only want to return true if we've found the last combined 247 | // match in the string, otherwise we return true so that other 248 | // switches in the combination will have a chance to match. 249 | return lastCombined( args[*i] ); 250 | } 251 | else 252 | return false; 253 | } 254 | 255 | inline void SwitchArg::reset() 256 | { 257 | Arg::reset(); 258 | _value = _default; 259 | } 260 | ////////////////////////////////////////////////////////////////////// 261 | //End SwitchArg.cpp 262 | ////////////////////////////////////////////////////////////////////// 263 | 264 | } //namespace TCLAP 265 | 266 | #endif 267 | -------------------------------------------------------------------------------- /filesystem/fatfs/include/esp_vfs_fat.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | #ifndef __ESP_VFS_FAT_H__ 17 | #define __ESP_VFS_FAT_H__ 18 | 19 | #include 20 | #include "esp_err.h" 21 | #include "ff.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /** 28 | * @brief Register FATFS with VFS component 29 | * 30 | * This function registers given FAT drive in VFS, at the specified base path. 31 | * If only one drive is used, fat_drive argument can be an empty string. 32 | * Refer to FATFS library documentation on how to specify FAT drive. 33 | * This function also allocates FATFS structure which should be used for f_mount 34 | * call. 35 | * 36 | * @note This function doesn't mount the drive into FATFS, it just connects 37 | * POSIX and C standard library IO function with FATFS. You need to mount 38 | * desired drive into FATFS separately. 39 | * 40 | * @param base_path path prefix where FATFS should be registered 41 | * @param fat_drive FATFS drive specification; if only one drive is used, can be an empty string 42 | * @param max_files maximum number of files which can be open at the same time 43 | * @param[out] out_fs pointer to FATFS structure which can be used for FATFS f_mount call is returned via this argument. 44 | * @return 45 | * - ESP_OK on success 46 | * - ESP_ERR_INVALID_STATE if esp_vfs_fat_register was already called 47 | * - ESP_ERR_NO_MEM if not enough memory or too many VFSes already registered 48 | */ 49 | esp_err_t esp_vfs_fat_register(const char* base_path, const char* fat_drive, 50 | size_t max_files, FATFS** out_fs); 51 | 52 | /** 53 | * @brief Un-register FATFS from VFS 54 | * 55 | * @note FATFS structure returned by esp_vfs_fat_register is destroyed after 56 | * this call. Make sure to call f_mount function to unmount it before 57 | * calling esp_vfs_fat_unregister. 58 | * This function is left for compatibility and will be changed in 59 | * future versions to accept base_path and replace the method below 60 | * @return 61 | * - ESP_OK on success 62 | * - ESP_ERR_INVALID_STATE if FATFS is not registered in VFS 63 | */ 64 | esp_err_t esp_vfs_fat_unregister() __attribute__((deprecated)); 65 | 66 | /** 67 | * @brief Un-register FATFS from VFS 68 | * 69 | * @note FATFS structure returned by esp_vfs_fat_register is destroyed after 70 | * this call. Make sure to call f_mount function to unmount it before 71 | * calling esp_vfs_fat_unregister_ctx. 72 | * Difference between this function and the one above is that this one 73 | * will release the correct drive, while the one above will release 74 | * the last registered one 75 | * 76 | * @param base_path path prefix where FATFS is registered. This is the same 77 | * used when esp_vfs_fat_register was called 78 | * @return 79 | * - ESP_OK on success 80 | * - ESP_ERR_INVALID_STATE if FATFS is not registered in VFS 81 | */ 82 | esp_err_t esp_vfs_fat_unregister_path(const char* base_path); 83 | 84 | 85 | /** 86 | * @brief Configuration arguments for esp_vfs_fat_sdmmc_mount and esp_vfs_fat_spiflash_mount functions 87 | */ 88 | typedef struct { 89 | bool format_if_mount_failed; ///< If FAT partition can not be mounted, and this parameter is true, create partition table and format the filesystem 90 | int max_files; ///< Max number of open files 91 | } esp_vfs_fat_mount_config_t; 92 | 93 | // Compatibility definition 94 | typedef esp_vfs_fat_mount_config_t esp_vfs_fat_sdmmc_mount_config_t; 95 | 96 | /** 97 | * @brief Convenience function to get FAT filesystem on SD card registered in VFS 98 | * 99 | * This is an all-in-one function which does the following: 100 | * - initializes SDMMC driver or SPI driver with configuration in host_config 101 | * - initializes SD card with configuration in slot_config 102 | * - mounts FAT partition on SD card using FATFS library, with configuration in mount_config 103 | * - registers FATFS library with VFS, with prefix given by base_prefix variable 104 | * 105 | * This function is intended to make example code more compact. 106 | * For real world applications, developers should implement the logic of 107 | * probing SD card, locating and mounting partition, and registering FATFS in VFS, 108 | * with proper error checking and handling of exceptional conditions. 109 | * 110 | * @param base_path path where partition should be registered (e.g. "/sdcard") 111 | * @param host_config Pointer to structure describing SDMMC host. When using 112 | * SDMMC peripheral, this structure can be initialized using 113 | * SDMMC_HOST_DEFAULT() macro. When using SPI peripheral, 114 | * this structure can be initialized using SDSPI_HOST_DEFAULT() 115 | * macro. 116 | * @param slot_config Pointer to structure with slot configuration. 117 | * For SDMMC peripheral, pass a pointer to sdmmc_slot_config_t 118 | * structure initialized using SDMMC_SLOT_CONFIG_DEFAULT. 119 | * For SPI peripheral, pass a pointer to sdspi_slot_config_t 120 | * structure initialized using SDSPI_SLOT_CONFIG_DEFAULT. 121 | * @param mount_config pointer to structure with extra parameters for mounting FATFS 122 | * @param[out] out_card if not NULL, pointer to the card information structure will be returned via this argument 123 | * @return 124 | * - ESP_OK on success 125 | * - ESP_ERR_INVALID_STATE if esp_vfs_fat_sdmmc_mount was already called 126 | * - ESP_ERR_NO_MEM if memory can not be allocated 127 | * - ESP_FAIL if partition can not be mounted 128 | * - other error codes from SDMMC or SPI drivers, SDMMC protocol, or FATFS drivers 129 | */ 130 | // esp_err_t esp_vfs_fat_sdmmc_mount(const char* base_path, 131 | // const sdmmc_host_t* host_config, 132 | // const void* slot_config, 133 | // const esp_vfs_fat_mount_config_t* mount_config, 134 | // sdmmc_card_t** out_card); 135 | 136 | /** 137 | * @brief Unmount FAT filesystem and release resources acquired using esp_vfs_fat_sdmmc_mount 138 | * 139 | * @return 140 | * - ESP_OK on success 141 | * - ESP_ERR_INVALID_STATE if esp_vfs_fat_sdmmc_mount hasn't been called 142 | */ 143 | // esp_err_t esp_vfs_fat_sdmmc_unmount(); 144 | 145 | /** 146 | * @brief Convenience function to initialize FAT filesystem in SPI flash and register it in VFS 147 | * 148 | * This is an all-in-one function which does the following: 149 | * 150 | * - finds the partition with defined partition_label. Partition label should be 151 | * configured in the partition table. 152 | * - initializes flash wear levelling library on top of the given partition 153 | * - mounts FAT partition using FATFS library on top of flash wear levelling 154 | * library 155 | * - registers FATFS library with VFS, with prefix given by base_prefix variable 156 | * 157 | * This function is intended to make example code more compact. 158 | * 159 | * @param base_path path where FATFS partition should be mounted (e.g. "/spiflash") 160 | * @param partition_label label of the partition which should be used 161 | * @param mount_config pointer to structure with extra parameters for mounting FATFS 162 | * @param[out] wl_handle wear levelling driver handle 163 | * @return 164 | * - ESP_OK on success 165 | * - ESP_ERR_NOT_FOUND if the partition table does not contain FATFS partition with given label 166 | * - ESP_ERR_INVALID_STATE if esp_vfs_fat_spiflash_mount was already called 167 | * - ESP_ERR_NO_MEM if memory can not be allocated 168 | * - ESP_FAIL if partition can not be mounted 169 | * - other error codes from wear levelling library, SPI flash driver, or FATFS drivers 170 | */ 171 | // esp_err_t esp_vfs_fat_spiflash_mount(const char* base_path, 172 | // const char* partition_label, 173 | // const esp_vfs_fat_mount_config_t* mount_config, 174 | // wl_handle_t* wl_handle); 175 | 176 | /** 177 | * @brief Unmount FAT filesystem and release resources acquired using esp_vfs_fat_spiflash_mount 178 | * 179 | * @param base_path path where partition should be registered (e.g. "/spiflash") 180 | * @param wl_handle wear levelling driver handle returned by esp_vfs_fat_spiflash_mount 181 | * 182 | * @return 183 | * - ESP_OK on success 184 | * - ESP_ERR_INVALID_STATE if esp_vfs_fat_spiflash_mount hasn't been called 185 | */ 186 | // esp_err_t esp_vfs_fat_spiflash_unmount(const char* base_path, wl_handle_t wl_handle); 187 | 188 | #ifdef __cplusplus 189 | } 190 | #endif 191 | 192 | #endif 193 | 194 | -------------------------------------------------------------------------------- /tclap/ZshCompletionOutput.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 2 | 3 | /****************************************************************************** 4 | * 5 | * file: ZshCompletionOutput.h 6 | * 7 | * Copyright (c) 2006, Oliver Kiddle 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | #ifndef TCLAP_ZSHCOMPLETIONOUTPUT_H 24 | #define TCLAP_ZSHCOMPLETIONOUTPUT_H 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "CmdLineInterface.h" 33 | #include "CmdLineOutput.h" 34 | #include "XorHandler.h" 35 | #include "Arg.h" 36 | 37 | namespace TCLAP { 38 | 39 | /** 40 | * A class that generates a Zsh completion function as output from the usage() 41 | * method for the given CmdLine and its Args. 42 | */ 43 | class ZshCompletionOutput : public CmdLineOutput 44 | { 45 | 46 | public: 47 | 48 | ZshCompletionOutput(); 49 | 50 | /** 51 | * Prints the usage to stdout. Can be overridden to 52 | * produce alternative behavior. 53 | * \param c - The CmdLine object the output is generated for. 54 | */ 55 | virtual void usage(CmdLineInterface& c); 56 | 57 | /** 58 | * Prints the version to stdout. Can be overridden 59 | * to produce alternative behavior. 60 | * \param c - The CmdLine object the output is generated for. 61 | */ 62 | virtual void version(CmdLineInterface& c); 63 | 64 | /** 65 | * Prints (to stderr) an error message, short usage 66 | * Can be overridden to produce alternative behavior. 67 | * \param c - The CmdLine object the output is generated for. 68 | * \param e - The ArgException that caused the failure. 69 | */ 70 | virtual void failure(CmdLineInterface& c, 71 | ArgException& e ); 72 | 73 | protected: 74 | 75 | void basename( std::string& s ); 76 | void quoteSpecialChars( std::string& s ); 77 | 78 | std::string getMutexList( CmdLineInterface& _cmd, Arg* a ); 79 | void printOption( Arg* it, std::string mutex ); 80 | void printArg( Arg* it ); 81 | 82 | std::map common; 83 | char theDelimiter; 84 | }; 85 | 86 | ZshCompletionOutput::ZshCompletionOutput() 87 | : common(std::map()), 88 | theDelimiter('=') 89 | { 90 | common["host"] = "_hosts"; 91 | common["hostname"] = "_hosts"; 92 | common["file"] = "_files"; 93 | common["filename"] = "_files"; 94 | common["user"] = "_users"; 95 | common["username"] = "_users"; 96 | common["directory"] = "_directories"; 97 | common["path"] = "_directories"; 98 | common["url"] = "_urls"; 99 | } 100 | 101 | inline void ZshCompletionOutput::version(CmdLineInterface& _cmd) 102 | { 103 | std::cout << _cmd.getVersion() << std::endl; 104 | } 105 | 106 | inline void ZshCompletionOutput::usage(CmdLineInterface& _cmd ) 107 | { 108 | std::list argList = _cmd.getArgList(); 109 | std::string progName = _cmd.getProgramName(); 110 | std::string xversion = _cmd.getVersion(); 111 | theDelimiter = _cmd.getDelimiter(); 112 | basename(progName); 113 | 114 | std::cout << "#compdef " << progName << std::endl << std::endl << 115 | "# " << progName << " version " << _cmd.getVersion() << std::endl << std::endl << 116 | "_arguments -s -S"; 117 | 118 | for (ArgListIterator it = argList.begin(); it != argList.end(); it++) 119 | { 120 | if ( (*it)->shortID().at(0) == '<' ) 121 | printArg((*it)); 122 | else if ( (*it)->getFlag() != "-" ) 123 | printOption((*it), getMutexList(_cmd, *it)); 124 | } 125 | 126 | std::cout << std::endl; 127 | } 128 | 129 | inline void ZshCompletionOutput::failure( CmdLineInterface& _cmd, 130 | ArgException& e ) 131 | { 132 | static_cast(_cmd); // unused 133 | std::cout << e.what() << std::endl; 134 | } 135 | 136 | inline void ZshCompletionOutput::quoteSpecialChars( std::string& s ) 137 | { 138 | size_t idx = s.find_last_of(':'); 139 | while ( idx != std::string::npos ) 140 | { 141 | s.insert(idx, 1, '\\'); 142 | idx = s.find_last_of(':', idx); 143 | } 144 | idx = s.find_last_of('\''); 145 | while ( idx != std::string::npos ) 146 | { 147 | s.insert(idx, "'\\'"); 148 | if (idx == 0) 149 | idx = std::string::npos; 150 | else 151 | idx = s.find_last_of('\'', --idx); 152 | } 153 | } 154 | 155 | inline void ZshCompletionOutput::basename( std::string& s ) 156 | { 157 | size_t p = s.find_last_of('/'); 158 | if ( p != std::string::npos ) 159 | { 160 | s.erase(0, p + 1); 161 | } 162 | } 163 | 164 | inline void ZshCompletionOutput::printArg(Arg* a) 165 | { 166 | static int count = 1; 167 | 168 | std::cout << " \\" << std::endl << " '"; 169 | if ( a->acceptsMultipleValues() ) 170 | std::cout << '*'; 171 | else 172 | std::cout << count++; 173 | std::cout << ':'; 174 | if ( !a->isRequired() ) 175 | std::cout << ':'; 176 | 177 | std::cout << a->getName() << ':'; 178 | std::map::iterator compArg = common.find(a->getName()); 179 | if ( compArg != common.end() ) 180 | { 181 | std::cout << compArg->second; 182 | } 183 | else 184 | { 185 | std::cout << "_guard \"^-*\" " << a->getName(); 186 | } 187 | std::cout << '\''; 188 | } 189 | 190 | inline void ZshCompletionOutput::printOption(Arg* a, std::string mutex) 191 | { 192 | std::string flag = a->flagStartChar() + a->getFlag(); 193 | std::string name = a->nameStartString() + a->getName(); 194 | std::string desc = a->getDescription(); 195 | 196 | // remove full stop and capitalisation from description as 197 | // this is the convention for zsh function 198 | if (!desc.compare(0, 12, "(required) ")) 199 | { 200 | desc.erase(0, 12); 201 | } 202 | if (!desc.compare(0, 15, "(OR required) ")) 203 | { 204 | desc.erase(0, 15); 205 | } 206 | size_t len = desc.length(); 207 | if (len && desc.at(--len) == '.') 208 | { 209 | desc.erase(len); 210 | } 211 | if (len) 212 | { 213 | desc.replace(0, 1, 1, tolower(desc.at(0))); 214 | } 215 | 216 | std::cout << " \\" << std::endl << " '" << mutex; 217 | 218 | if ( a->getFlag().empty() ) 219 | { 220 | std::cout << name; 221 | } 222 | else 223 | { 224 | std::cout << "'{" << flag << ',' << name << "}'"; 225 | } 226 | if ( theDelimiter == '=' && a->isValueRequired() ) 227 | std::cout << "=-"; 228 | quoteSpecialChars(desc); 229 | std::cout << '[' << desc << ']'; 230 | 231 | if ( a->isValueRequired() ) 232 | { 233 | std::string arg = a->shortID(); 234 | arg.erase(0, arg.find_last_of(theDelimiter) + 1); 235 | if ( arg.at(arg.length()-1) == ']' ) 236 | arg.erase(arg.length()-1); 237 | if ( arg.at(arg.length()-1) == ']' ) 238 | { 239 | arg.erase(arg.length()-1); 240 | } 241 | if ( arg.at(0) == '<' ) 242 | { 243 | arg.erase(arg.length()-1); 244 | arg.erase(0, 1); 245 | } 246 | size_t p = arg.find('|'); 247 | if ( p != std::string::npos ) 248 | { 249 | do 250 | { 251 | arg.replace(p, 1, 1, ' '); 252 | } 253 | while ( (p = arg.find_first_of('|', p)) != std::string::npos ); 254 | quoteSpecialChars(arg); 255 | std::cout << ": :(" << arg << ')'; 256 | } 257 | else 258 | { 259 | std::cout << ':' << arg; 260 | std::map::iterator compArg = common.find(arg); 261 | if ( compArg != common.end() ) 262 | { 263 | std::cout << ':' << compArg->second; 264 | } 265 | } 266 | } 267 | 268 | std::cout << '\''; 269 | } 270 | 271 | inline std::string ZshCompletionOutput::getMutexList( CmdLineInterface& _cmd, Arg* a) 272 | { 273 | XorHandler xorHandler = _cmd.getXorHandler(); 274 | std::vector< std::vector > xorList = xorHandler.getXorList(); 275 | 276 | if (a->getName() == "help" || a->getName() == "version") 277 | { 278 | return "(-)"; 279 | } 280 | 281 | std::ostringstream list; 282 | if ( a->acceptsMultipleValues() ) 283 | { 284 | list << '*'; 285 | } 286 | 287 | for ( int i = 0; static_cast(i) < xorList.size(); i++ ) 288 | { 289 | for ( ArgVectorIterator it = xorList[i].begin(); 290 | it != xorList[i].end(); 291 | it++) 292 | if ( a == (*it) ) 293 | { 294 | list << '('; 295 | for ( ArgVectorIterator iu = xorList[i].begin(); 296 | iu != xorList[i].end(); 297 | iu++ ) 298 | { 299 | bool notCur = (*iu) != a; 300 | bool hasFlag = !(*iu)->getFlag().empty(); 301 | if ( iu != xorList[i].begin() && (notCur || hasFlag) ) 302 | list << ' '; 303 | if (hasFlag) 304 | list << (*iu)->flagStartChar() << (*iu)->getFlag() << ' '; 305 | if ( notCur || hasFlag ) 306 | list << (*iu)->nameStartString() << (*iu)->getName(); 307 | } 308 | list << ')'; 309 | return list.str(); 310 | } 311 | } 312 | 313 | // wasn't found in xor list 314 | if (!a->getFlag().empty()) { 315 | list << "(" << a->flagStartChar() << a->getFlag() << ' ' << 316 | a->nameStartString() << a->getName() << ')'; 317 | } 318 | 319 | return list.str(); 320 | } 321 | 322 | } //namespace TCLAP 323 | #endif 324 | -------------------------------------------------------------------------------- /tclap/DocBookOutput.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 2 | 3 | /****************************************************************************** 4 | * 5 | * file: DocBookOutput.h 6 | * 7 | * Copyright (c) 2004, Michael E. Smoot 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | #ifndef TCLAP_DOCBOOKOUTPUT_H 24 | #define TCLAP_DOCBOOKOUTPUT_H 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "CmdLineInterface.h" 33 | #include "CmdLineOutput.h" 34 | #include "XorHandler.h" 35 | #include "Arg.h" 36 | 37 | namespace TCLAP { 38 | 39 | /** 40 | * A class that generates DocBook output for usage() method for the 41 | * given CmdLine and its Args. 42 | */ 43 | class DocBookOutput : public CmdLineOutput 44 | { 45 | 46 | public: 47 | 48 | /** 49 | * Prints the usage to stdout. Can be overridden to 50 | * produce alternative behavior. 51 | * \param c - The CmdLine object the output is generated for. 52 | */ 53 | virtual void usage(CmdLineInterface& c); 54 | 55 | /** 56 | * Prints the version to stdout. Can be overridden 57 | * to produce alternative behavior. 58 | * \param c - The CmdLine object the output is generated for. 59 | */ 60 | virtual void version(CmdLineInterface& c); 61 | 62 | /** 63 | * Prints (to stderr) an error message, short usage 64 | * Can be overridden to produce alternative behavior. 65 | * \param c - The CmdLine object the output is generated for. 66 | * \param e - The ArgException that caused the failure. 67 | */ 68 | virtual void failure(CmdLineInterface& c, 69 | ArgException& e ); 70 | 71 | protected: 72 | 73 | /** 74 | * Substitutes the char r for string x in string s. 75 | * \param s - The string to operate on. 76 | * \param r - The char to replace. 77 | * \param x - What to replace r with. 78 | */ 79 | void substituteSpecialChars( std::string& s, char r, std::string& x ); 80 | void removeChar( std::string& s, char r); 81 | void basename( std::string& s ); 82 | 83 | void printShortArg(Arg* it); 84 | void printLongArg(Arg* it); 85 | 86 | char theDelimiter; 87 | }; 88 | 89 | 90 | inline void DocBookOutput::version(CmdLineInterface& _cmd) 91 | { 92 | std::cout << _cmd.getVersion() << std::endl; 93 | } 94 | 95 | inline void DocBookOutput::usage(CmdLineInterface& _cmd ) 96 | { 97 | std::list argList = _cmd.getArgList(); 98 | std::string progName = _cmd.getProgramName(); 99 | std::string xversion = _cmd.getVersion(); 100 | theDelimiter = _cmd.getDelimiter(); 101 | XorHandler xorHandler = _cmd.getXorHandler(); 102 | std::vector< std::vector > xorList = xorHandler.getXorList(); 103 | basename(progName); 104 | 105 | std::cout << "" << std::endl; 106 | std::cout << "" << std::endl << std::endl; 108 | 109 | std::cout << "" << std::endl; 110 | 111 | std::cout << "" << std::endl; 112 | std::cout << "" << progName << "" << std::endl; 113 | std::cout << "1" << std::endl; 114 | std::cout << "" << std::endl; 115 | 116 | std::cout << "" << std::endl; 117 | std::cout << "" << progName << "" << std::endl; 118 | std::cout << "" << _cmd.getMessage() << "" << std::endl; 119 | std::cout << "" << std::endl; 120 | 121 | std::cout << "" << std::endl; 122 | std::cout << "" << std::endl; 123 | 124 | std::cout << "" << progName << "" << std::endl; 125 | 126 | // xor 127 | for ( int i = 0; (unsigned int)i < xorList.size(); i++ ) 128 | { 129 | std::cout << "" << std::endl; 130 | for ( ArgVectorIterator it = xorList[i].begin(); 131 | it != xorList[i].end(); it++ ) 132 | printShortArg((*it)); 133 | 134 | std::cout << "" << std::endl; 135 | } 136 | 137 | // rest of args 138 | for (ArgListIterator it = argList.begin(); it != argList.end(); it++) 139 | if ( !xorHandler.contains( (*it) ) ) 140 | printShortArg((*it)); 141 | 142 | std::cout << "" << std::endl; 143 | std::cout << "" << std::endl; 144 | 145 | std::cout << "" << std::endl; 146 | std::cout << "Description" << std::endl; 147 | std::cout << "" << std::endl; 148 | std::cout << _cmd.getMessage() << std::endl; 149 | std::cout << "" << std::endl; 150 | std::cout << "" << std::endl; 151 | 152 | std::cout << "" << std::endl; 153 | std::cout << "Options" << std::endl; 154 | 155 | std::cout << "" << std::endl; 156 | 157 | for (ArgListIterator it = argList.begin(); it != argList.end(); it++) 158 | printLongArg((*it)); 159 | 160 | std::cout << "" << std::endl; 161 | std::cout << "" << std::endl; 162 | 163 | std::cout << "" << std::endl; 164 | std::cout << "Version" << std::endl; 165 | std::cout << "" << std::endl; 166 | std::cout << xversion << std::endl; 167 | std::cout << "" << std::endl; 168 | std::cout << "" << std::endl; 169 | 170 | std::cout << "" << std::endl; 171 | 172 | } 173 | 174 | inline void DocBookOutput::failure( CmdLineInterface& _cmd, 175 | ArgException& e ) 176 | { 177 | static_cast(_cmd); // unused 178 | std::cout << e.what() << std::endl; 179 | throw ExitException(1); 180 | } 181 | 182 | inline void DocBookOutput::substituteSpecialChars( std::string& s, 183 | char r, 184 | std::string& x ) 185 | { 186 | size_t p; 187 | while ( (p = s.find_first_of(r)) != std::string::npos ) 188 | { 189 | s.erase(p,1); 190 | s.insert(p,x); 191 | } 192 | } 193 | 194 | inline void DocBookOutput::removeChar( std::string& s, char r) 195 | { 196 | size_t p; 197 | while ( (p = s.find_first_of(r)) != std::string::npos ) 198 | { 199 | s.erase(p,1); 200 | } 201 | } 202 | 203 | inline void DocBookOutput::basename( std::string& s ) 204 | { 205 | size_t p = s.find_last_of('/'); 206 | if ( p != std::string::npos ) 207 | { 208 | s.erase(0, p + 1); 209 | } 210 | } 211 | 212 | inline void DocBookOutput::printShortArg(Arg* a) 213 | { 214 | std::string lt = "<"; 215 | std::string gt = ">"; 216 | 217 | std::string id = a->shortID(); 218 | substituteSpecialChars(id,'<',lt); 219 | substituteSpecialChars(id,'>',gt); 220 | removeChar(id,'['); 221 | removeChar(id,']'); 222 | 223 | std::string choice = "opt"; 224 | if ( a->isRequired() ) 225 | choice = "plain"; 226 | 227 | std::cout << "acceptsMultipleValues() ) 229 | std::cout << " rep='repeat'"; 230 | 231 | 232 | std::cout << '>'; 233 | if ( !a->getFlag().empty() ) 234 | std::cout << a->flagStartChar() << a->getFlag(); 235 | else 236 | std::cout << a->nameStartString() << a->getName(); 237 | if ( a->isValueRequired() ) 238 | { 239 | std::string arg = a->shortID(); 240 | removeChar(arg,'['); 241 | removeChar(arg,']'); 242 | removeChar(arg,'<'); 243 | removeChar(arg,'>'); 244 | arg.erase(0, arg.find_last_of(theDelimiter) + 1); 245 | std::cout << theDelimiter; 246 | std::cout << "" << arg << ""; 247 | } 248 | std::cout << "" << std::endl; 249 | 250 | } 251 | 252 | inline void DocBookOutput::printLongArg(Arg* a) 253 | { 254 | std::string lt = "<"; 255 | std::string gt = ">"; 256 | 257 | std::string desc = a->getDescription(); 258 | substituteSpecialChars(desc,'<',lt); 259 | substituteSpecialChars(desc,'>',gt); 260 | 261 | std::cout << "" << std::endl; 262 | 263 | if ( !a->getFlag().empty() ) 264 | { 265 | std::cout << "" << std::endl; 266 | std::cout << "" << std::endl; 269 | std::cout << "" << std::endl; 270 | } 271 | 272 | std::cout << "" << std::endl; 273 | std::cout << "" << std::endl; 287 | std::cout << "" << std::endl; 288 | 289 | std::cout << "" << std::endl; 290 | std::cout << "" << std::endl; 291 | std::cout << desc << std::endl; 292 | std::cout << "" << std::endl; 293 | std::cout << "" << std::endl; 294 | 295 | std::cout << "" << std::endl; 296 | } 297 | 298 | } //namespace TCLAP 299 | #endif 300 | -------------------------------------------------------------------------------- /tclap/StdOutput.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 2 | 3 | /****************************************************************************** 4 | * 5 | * file: StdOutput.h 6 | * 7 | * Copyright (c) 2004, Michael E. Smoot 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | #ifndef TCLAP_STDCMDLINEOUTPUT_H 24 | #define TCLAP_STDCMDLINEOUTPUT_H 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "CmdLineInterface.h" 33 | #include "CmdLineOutput.h" 34 | #include "XorHandler.h" 35 | #include "Arg.h" 36 | 37 | namespace TCLAP { 38 | 39 | /** 40 | * A class that isolates any output from the CmdLine object so that it 41 | * may be easily modified. 42 | */ 43 | class StdOutput : public CmdLineOutput 44 | { 45 | 46 | public: 47 | 48 | /** 49 | * Prints the usage to stdout. Can be overridden to 50 | * produce alternative behavior. 51 | * \param c - The CmdLine object the output is generated for. 52 | */ 53 | virtual void usage(CmdLineInterface& c); 54 | 55 | /** 56 | * Prints the version to stdout. Can be overridden 57 | * to produce alternative behavior. 58 | * \param c - The CmdLine object the output is generated for. 59 | */ 60 | virtual void version(CmdLineInterface& c); 61 | 62 | /** 63 | * Prints (to stderr) an error message, short usage 64 | * Can be overridden to produce alternative behavior. 65 | * \param c - The CmdLine object the output is generated for. 66 | * \param e - The ArgException that caused the failure. 67 | */ 68 | virtual void failure(CmdLineInterface& c, 69 | ArgException& e ); 70 | 71 | protected: 72 | 73 | /** 74 | * Writes a brief usage message with short args. 75 | * \param c - The CmdLine object the output is generated for. 76 | * \param os - The stream to write the message to. 77 | */ 78 | void _shortUsage( CmdLineInterface& c, std::ostream& os ) const; 79 | 80 | /** 81 | * Writes a longer usage message with long and short args, 82 | * provides descriptions and prints message. 83 | * \param c - The CmdLine object the output is generated for. 84 | * \param os - The stream to write the message to. 85 | */ 86 | void _longUsage( CmdLineInterface& c, std::ostream& os ) const; 87 | 88 | /** 89 | * This function inserts line breaks and indents long strings 90 | * according the params input. It will only break lines at spaces, 91 | * commas and pipes. 92 | * \param os - The stream to be printed to. 93 | * \param s - The string to be printed. 94 | * \param maxWidth - The maxWidth allowed for the output line. 95 | * \param indentSpaces - The number of spaces to indent the first line. 96 | * \param secondLineOffset - The number of spaces to indent the second 97 | * and all subsequent lines in addition to indentSpaces. 98 | */ 99 | void spacePrint( std::ostream& os, 100 | const std::string& s, 101 | int maxWidth, 102 | int indentSpaces, 103 | int secondLineOffset ) const; 104 | 105 | }; 106 | 107 | 108 | inline void StdOutput::version(CmdLineInterface& _cmd) 109 | { 110 | std::string progName = _cmd.getProgramName(); 111 | std::string xversion = _cmd.getVersion(); 112 | 113 | std::cout << std::endl << progName << " version: " 114 | << xversion << std::endl << std::endl; 115 | } 116 | 117 | inline void StdOutput::usage(CmdLineInterface& _cmd ) 118 | { 119 | std::cout << std::endl << "USAGE: " << std::endl << std::endl; 120 | 121 | _shortUsage( _cmd, std::cout ); 122 | 123 | std::cout << std::endl << std::endl << "Where: " << std::endl << std::endl; 124 | 125 | _longUsage( _cmd, std::cout ); 126 | 127 | std::cout << std::endl; 128 | 129 | } 130 | 131 | inline void StdOutput::failure( CmdLineInterface& _cmd, 132 | ArgException& e ) 133 | { 134 | std::string progName = _cmd.getProgramName(); 135 | 136 | std::cerr << "PARSE ERROR: " << e.argId() << std::endl 137 | << " " << e.error() << std::endl << std::endl; 138 | 139 | if ( _cmd.hasHelpAndVersion() ) 140 | { 141 | std::cerr << "Brief USAGE: " << std::endl; 142 | 143 | _shortUsage( _cmd, std::cerr ); 144 | 145 | std::cerr << std::endl << "For complete USAGE and HELP type: " 146 | << std::endl << " " << progName << " --help" 147 | << std::endl << std::endl; 148 | } 149 | else 150 | usage(_cmd); 151 | 152 | throw ExitException(1); 153 | } 154 | 155 | inline void 156 | StdOutput::_shortUsage( CmdLineInterface& _cmd, 157 | std::ostream& os ) const 158 | { 159 | std::list argList = _cmd.getArgList(); 160 | std::string progName = _cmd.getProgramName(); 161 | XorHandler xorHandler = _cmd.getXorHandler(); 162 | std::vector< std::vector > xorList = xorHandler.getXorList(); 163 | 164 | std::string s = progName + " "; 165 | 166 | // first the xor 167 | for ( int i = 0; static_cast(i) < xorList.size(); i++ ) 168 | { 169 | s += " {"; 170 | for ( ArgVectorIterator it = xorList[i].begin(); 171 | it != xorList[i].end(); it++ ) 172 | s += (*it)->shortID() + "|"; 173 | 174 | s[s.length()-1] = '}'; 175 | } 176 | 177 | // then the rest 178 | for (ArgListIterator it = argList.begin(); it != argList.end(); it++) 179 | if ( !xorHandler.contains( (*it) ) ) 180 | s += " " + (*it)->shortID(); 181 | 182 | // if the program name is too long, then adjust the second line offset 183 | int secondLineOffset = static_cast(progName.length()) + 2; 184 | if ( secondLineOffset > 75/2 ) 185 | secondLineOffset = static_cast(75/2); 186 | 187 | spacePrint( os, s, 75, 3, secondLineOffset ); 188 | } 189 | 190 | inline void 191 | StdOutput::_longUsage( CmdLineInterface& _cmd, 192 | std::ostream& os ) const 193 | { 194 | std::list argList = _cmd.getArgList(); 195 | std::string message = _cmd.getMessage(); 196 | XorHandler xorHandler = _cmd.getXorHandler(); 197 | std::vector< std::vector > xorList = xorHandler.getXorList(); 198 | 199 | // first the xor 200 | for ( int i = 0; static_cast(i) < xorList.size(); i++ ) 201 | { 202 | for ( ArgVectorIterator it = xorList[i].begin(); 203 | it != xorList[i].end(); 204 | it++ ) 205 | { 206 | spacePrint( os, (*it)->longID(), 75, 3, 3 ); 207 | spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); 208 | 209 | if ( it+1 != xorList[i].end() ) 210 | spacePrint(os, "-- OR --", 75, 9, 0); 211 | } 212 | os << std::endl << std::endl; 213 | } 214 | 215 | // then the rest 216 | for (ArgListIterator it = argList.begin(); it != argList.end(); it++) 217 | if ( !xorHandler.contains( (*it) ) ) 218 | { 219 | spacePrint( os, (*it)->longID(), 75, 3, 3 ); 220 | spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); 221 | os << std::endl; 222 | } 223 | 224 | os << std::endl; 225 | 226 | spacePrint( os, message, 75, 3, 0 ); 227 | } 228 | 229 | inline void StdOutput::spacePrint( std::ostream& os, 230 | const std::string& s, 231 | int maxWidth, 232 | int indentSpaces, 233 | int secondLineOffset ) const 234 | { 235 | int len = static_cast(s.length()); 236 | 237 | if ( (len + indentSpaces > maxWidth) && maxWidth > 0 ) 238 | { 239 | int allowedLen = maxWidth - indentSpaces; 240 | int start = 0; 241 | while ( start < len ) 242 | { 243 | // find the substring length 244 | // int stringLen = std::min( len - start, allowedLen ); 245 | // doing it this way to support a VisualC++ 2005 bug 246 | using namespace std; 247 | int stringLen = min( len - start, allowedLen ); 248 | 249 | // trim the length so it doesn't end in middle of a word 250 | if ( stringLen == allowedLen ) 251 | while ( stringLen >= 0 && 252 | s[stringLen+start] != ' ' && 253 | s[stringLen+start] != ',' && 254 | s[stringLen+start] != '|' ) 255 | stringLen--; 256 | 257 | // ok, the word is longer than the line, so just split 258 | // wherever the line ends 259 | if ( stringLen <= 0 ) 260 | stringLen = allowedLen; 261 | 262 | // check for newlines 263 | for ( int i = 0; i < stringLen; i++ ) 264 | if ( s[start+i] == '\n' ) 265 | stringLen = i+1; 266 | 267 | // print the indent 268 | for ( int i = 0; i < indentSpaces; i++ ) 269 | os << " "; 270 | 271 | if ( start == 0 ) 272 | { 273 | // handle second line offsets 274 | indentSpaces += secondLineOffset; 275 | 276 | // adjust allowed len 277 | allowedLen -= secondLineOffset; 278 | } 279 | 280 | os << s.substr(start,stringLen) << std::endl; 281 | 282 | // so we don't start a line with a space 283 | while ( s[stringLen+start] == ' ' && start < len ) 284 | start++; 285 | 286 | start += stringLen; 287 | } 288 | } 289 | else 290 | { 291 | for ( int i = 0; i < indentSpaces; i++ ) 292 | os << " "; 293 | os << s << std::endl; 294 | } 295 | } 296 | 297 | } //namespace TCLAP 298 | #endif 299 | -------------------------------------------------------------------------------- /tclap/UnlabeledMultiArg.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: UnlabeledMultiArg.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot. 7 | * All rights reverved. 8 | * 9 | * See the file COPYING in the top directory of this distribution for 10 | * more information. 11 | * 12 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 15 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | *****************************************************************************/ 21 | 22 | 23 | #ifndef TCLAP_MULTIPLE_UNLABELED_ARGUMENT_H 24 | #define TCLAP_MULTIPLE_UNLABELED_ARGUMENT_H 25 | 26 | #include 27 | #include 28 | 29 | #include "MultiArg.h" 30 | #include "OptionalUnlabeledTracker.h" 31 | 32 | namespace TCLAP { 33 | 34 | /** 35 | * Just like a MultiArg, except that the arguments are unlabeled. Basically, 36 | * this Arg will slurp up everything that hasn't been matched to another 37 | * Arg. 38 | */ 39 | template 40 | class UnlabeledMultiArg : public MultiArg 41 | { 42 | 43 | // If compiler has two stage name lookup (as gcc >= 3.4 does) 44 | // this is requried to prevent undef. symbols 45 | using MultiArg::_ignoreable; 46 | using MultiArg::_hasBlanks; 47 | using MultiArg::_extractValue; 48 | using MultiArg::_typeDesc; 49 | using MultiArg::_name; 50 | using MultiArg::_description; 51 | using MultiArg::_alreadySet; 52 | using MultiArg::toString; 53 | 54 | public: 55 | 56 | /** 57 | * Constructor. 58 | * \param name - The name of the Arg. Note that this is used for 59 | * identification, not as a long flag. 60 | * \param desc - A description of what the argument is for or 61 | * does. 62 | * \param req - Whether the argument is required on the command 63 | * line. 64 | * \param typeDesc - A short, human readable description of the 65 | * type that this object expects. This is used in the generation 66 | * of the USAGE statement. The goal is to be helpful to the end user 67 | * of the program. 68 | * \param ignoreable - Whether or not this argument can be ignored 69 | * using the "--" flag. 70 | * \param v - An optional visitor. You probably should not 71 | * use this unless you have a very good reason. 72 | */ 73 | UnlabeledMultiArg( const std::string& name, 74 | const std::string& desc, 75 | bool req, 76 | const std::string& typeDesc, 77 | bool ignoreable = false, 78 | Visitor* v = NULL ); 79 | /** 80 | * Constructor. 81 | * \param name - The name of the Arg. Note that this is used for 82 | * identification, not as a long flag. 83 | * \param desc - A description of what the argument is for or 84 | * does. 85 | * \param req - Whether the argument is required on the command 86 | * line. 87 | * \param typeDesc - A short, human readable description of the 88 | * type that this object expects. This is used in the generation 89 | * of the USAGE statement. The goal is to be helpful to the end user 90 | * of the program. 91 | * \param parser - A CmdLine parser object to add this Arg to 92 | * \param ignoreable - Whether or not this argument can be ignored 93 | * using the "--" flag. 94 | * \param v - An optional visitor. You probably should not 95 | * use this unless you have a very good reason. 96 | */ 97 | UnlabeledMultiArg( const std::string& name, 98 | const std::string& desc, 99 | bool req, 100 | const std::string& typeDesc, 101 | CmdLineInterface& parser, 102 | bool ignoreable = false, 103 | Visitor* v = NULL ); 104 | 105 | /** 106 | * Constructor. 107 | * \param name - The name of the Arg. Note that this is used for 108 | * identification, not as a long flag. 109 | * \param desc - A description of what the argument is for or 110 | * does. 111 | * \param req - Whether the argument is required on the command 112 | * line. 113 | * \param constraint - A pointer to a Constraint object used 114 | * to constrain this Arg. 115 | * \param ignoreable - Whether or not this argument can be ignored 116 | * using the "--" flag. 117 | * \param v - An optional visitor. You probably should not 118 | * use this unless you have a very good reason. 119 | */ 120 | UnlabeledMultiArg( const std::string& name, 121 | const std::string& desc, 122 | bool req, 123 | Constraint* constraint, 124 | bool ignoreable = false, 125 | Visitor* v = NULL ); 126 | 127 | /** 128 | * Constructor. 129 | * \param name - The name of the Arg. Note that this is used for 130 | * identification, not as a long flag. 131 | * \param desc - A description of what the argument is for or 132 | * does. 133 | * \param req - Whether the argument is required on the command 134 | * line. 135 | * \param constraint - A pointer to a Constraint object used 136 | * to constrain this Arg. 137 | * \param parser - A CmdLine parser object to add this Arg to 138 | * \param ignoreable - Whether or not this argument can be ignored 139 | * using the "--" flag. 140 | * \param v - An optional visitor. You probably should not 141 | * use this unless you have a very good reason. 142 | */ 143 | UnlabeledMultiArg( const std::string& name, 144 | const std::string& desc, 145 | bool req, 146 | Constraint* constraint, 147 | CmdLineInterface& parser, 148 | bool ignoreable = false, 149 | Visitor* v = NULL ); 150 | 151 | /** 152 | * Handles the processing of the argument. 153 | * This re-implements the Arg version of this method to set the 154 | * _value of the argument appropriately. It knows the difference 155 | * between labeled and unlabeled. 156 | * \param i - Pointer the the current argument in the list. 157 | * \param args - Mutable list of strings. Passed from main(). 158 | */ 159 | virtual bool processArg(int* i, std::vector& args); 160 | 161 | /** 162 | * Returns the a short id string. Used in the usage. 163 | * \param val - value to be used. 164 | */ 165 | virtual std::string shortID(const std::string& val="val") const; 166 | 167 | /** 168 | * Returns the a long id string. Used in the usage. 169 | * \param val - value to be used. 170 | */ 171 | virtual std::string longID(const std::string& val="val") const; 172 | 173 | /** 174 | * Opertor ==. 175 | * \param a - The Arg to be compared to this. 176 | */ 177 | virtual bool operator==(const Arg& a) const; 178 | 179 | /** 180 | * Pushes this to back of list rather than front. 181 | * \param argList - The list this should be added to. 182 | */ 183 | virtual void addToList( std::list& argList ) const; 184 | }; 185 | 186 | template 187 | UnlabeledMultiArg::UnlabeledMultiArg(const std::string& name, 188 | const std::string& desc, 189 | bool req, 190 | const std::string& typeDesc, 191 | bool ignoreable, 192 | Visitor* v) 193 | : MultiArg("", name, desc, req, typeDesc, v) 194 | { 195 | _ignoreable = ignoreable; 196 | OptionalUnlabeledTracker::check(true, toString()); 197 | } 198 | 199 | template 200 | UnlabeledMultiArg::UnlabeledMultiArg(const std::string& name, 201 | const std::string& desc, 202 | bool req, 203 | const std::string& typeDesc, 204 | CmdLineInterface& parser, 205 | bool ignoreable, 206 | Visitor* v) 207 | : MultiArg("", name, desc, req, typeDesc, v) 208 | { 209 | _ignoreable = ignoreable; 210 | OptionalUnlabeledTracker::check(true, toString()); 211 | parser.add( this ); 212 | } 213 | 214 | 215 | template 216 | UnlabeledMultiArg::UnlabeledMultiArg(const std::string& name, 217 | const std::string& desc, 218 | bool req, 219 | Constraint* constraint, 220 | bool ignoreable, 221 | Visitor* v) 222 | : MultiArg("", name, desc, req, constraint, v) 223 | { 224 | _ignoreable = ignoreable; 225 | OptionalUnlabeledTracker::check(true, toString()); 226 | } 227 | 228 | template 229 | UnlabeledMultiArg::UnlabeledMultiArg(const std::string& name, 230 | const std::string& desc, 231 | bool req, 232 | Constraint* constraint, 233 | CmdLineInterface& parser, 234 | bool ignoreable, 235 | Visitor* v) 236 | : MultiArg("", name, desc, req, constraint, v) 237 | { 238 | _ignoreable = ignoreable; 239 | OptionalUnlabeledTracker::check(true, toString()); 240 | parser.add( this ); 241 | } 242 | 243 | 244 | template 245 | bool UnlabeledMultiArg::processArg(int *i, std::vector& args) 246 | { 247 | 248 | if ( _hasBlanks( args[*i] ) ) 249 | return false; 250 | 251 | // never ignore an unlabeled multi arg 252 | 253 | 254 | // always take the first value, regardless of the start string 255 | _extractValue( args[(*i)] ); 256 | 257 | /* 258 | // continue taking args until we hit the end or a start string 259 | while ( (unsigned int)(*i)+1 < args.size() && 260 | args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 && 261 | args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 ) 262 | _extractValue( args[++(*i)] ); 263 | */ 264 | 265 | _alreadySet = true; 266 | 267 | return true; 268 | } 269 | 270 | template 271 | std::string UnlabeledMultiArg::shortID(const std::string& val) const 272 | { 273 | static_cast(val); // Ignore input, don't warn 274 | return std::string("<") + _typeDesc + "> ..."; 275 | } 276 | 277 | template 278 | std::string UnlabeledMultiArg::longID(const std::string& val) const 279 | { 280 | static_cast(val); // Ignore input, don't warn 281 | return std::string("<") + _typeDesc + "> (accepted multiple times)"; 282 | } 283 | 284 | template 285 | bool UnlabeledMultiArg::operator==(const Arg& a) const 286 | { 287 | if ( _name == a.getName() || _description == a.getDescription() ) 288 | return true; 289 | else 290 | return false; 291 | } 292 | 293 | template 294 | void UnlabeledMultiArg::addToList( std::list& argList ) const 295 | { 296 | argList.push_back( const_cast(static_cast(this)) ); 297 | } 298 | 299 | } 300 | 301 | #endif 302 | -------------------------------------------------------------------------------- /filesystem/fatfs/include/ffconf.h: -------------------------------------------------------------------------------- 1 | #include "sdkconfig.h" 2 | /*---------------------------------------------------------------------------/ 3 | / FatFs - FAT file system module configuration file 4 | /---------------------------------------------------------------------------*/ 5 | 6 | #define _FFCONF 68020 /* Revision ID */ 7 | 8 | /*---------------------------------------------------------------------------/ 9 | / Function Configurations 10 | /---------------------------------------------------------------------------*/ 11 | 12 | #define _FS_READONLY 0 13 | /* This option switches read-only configuration. (0:Read/Write or 1:Read-only) 14 | / Read-only configuration removes writing API functions, f_write(), f_sync(), 15 | / f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree() 16 | / and optional writing functions as well. */ 17 | 18 | 19 | #define _FS_MINIMIZE 0 20 | /* This option defines minimization level to remove some basic API functions. 21 | / 22 | / 0: All basic functions are enabled. 23 | / 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename() 24 | / are removed. 25 | / 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1. 26 | / 3: f_lseek() function is removed in addition to 2. */ 27 | 28 | 29 | #define _USE_STRFUNC 0 30 | /* This option switches string functions, f_gets(), f_putc(), f_puts() and 31 | / f_printf(). 32 | / 33 | / 0: Disable string functions. 34 | / 1: Enable without LF-CRLF conversion. 35 | / 2: Enable with LF-CRLF conversion. */ 36 | 37 | 38 | #define _USE_FIND 0 39 | /* This option switches filtered directory read functions, f_findfirst() and 40 | / f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */ 41 | 42 | 43 | #define _USE_MKFS 1 44 | /* This option switches f_mkfs() function. (0:Disable or 1:Enable) */ 45 | 46 | 47 | #define _USE_FASTSEEK 0 48 | /* This option switches fast seek function. (0:Disable or 1:Enable) */ 49 | 50 | 51 | #define _USE_EXPAND 0 52 | /* This option switches f_expand function. (0:Disable or 1:Enable) */ 53 | 54 | 55 | #define _USE_CHMOD 0 56 | /* This option switches attribute manipulation functions, f_chmod() and f_utime(). 57 | / (0:Disable or 1:Enable) Also _FS_READONLY needs to be 0 to enable this option. */ 58 | 59 | 60 | #define _USE_LABEL 0 61 | /* This option switches volume label functions, f_getlabel() and f_setlabel(). 62 | / (0:Disable or 1:Enable) */ 63 | 64 | 65 | #define _USE_FORWARD 0 66 | /* This option switches f_forward() function. (0:Disable or 1:Enable) */ 67 | 68 | 69 | /*---------------------------------------------------------------------------/ 70 | / Locale and Namespace Configurations 71 | /---------------------------------------------------------------------------*/ 72 | 73 | #define _CODE_PAGE CONFIG_FATFS_CODEPAGE 74 | /* This option specifies the OEM code page to be used on the target system. 75 | / Incorrect setting of the code page can cause a file open failure. 76 | / 77 | / 1 - ASCII (No extended character. Non-LFN cfg. only) 78 | / 437 - U.S. 79 | / 720 - Arabic 80 | / 737 - Greek 81 | / 771 - KBL 82 | / 775 - Baltic 83 | / 850 - Latin 1 84 | / 852 - Latin 2 85 | / 855 - Cyrillic 86 | / 857 - Turkish 87 | / 860 - Portuguese 88 | / 861 - Icelandic 89 | / 862 - Hebrew 90 | / 863 - Canadian French 91 | / 864 - Arabic 92 | / 865 - Nordic 93 | / 866 - Russian 94 | / 869 - Greek 2 95 | / 932 - Japanese (DBCS) 96 | / 936 - Simplified Chinese (DBCS) 97 | / 949 - Korean (DBCS) 98 | / 950 - Traditional Chinese (DBCS) 99 | */ 100 | 101 | #if defined(CONFIG_FATFS_LFN_STACK) 102 | #define _USE_LFN 2 103 | #elif defined(CONFIG_FATFS_LFN_HEAP) 104 | #define _USE_LFN 3 105 | #else /* CONFIG_FATFS_LFN_NONE */ 106 | #define _USE_LFN 0 107 | #endif 108 | 109 | #ifdef CONFIG_FATFS_MAX_LFN 110 | #define _MAX_LFN CONFIG_FATFS_MAX_LFN 111 | #endif 112 | /* The _USE_LFN switches the support of long file name (LFN). 113 | / 114 | / 0: Disable support of LFN. _MAX_LFN has no effect. 115 | / 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe. 116 | / 2: Enable LFN with dynamic working buffer on the STACK. 117 | / 3: Enable LFN with dynamic working buffer on the HEAP. 118 | / 119 | / To enable the LFN, Unicode handling functions (option/unicode.c) must be added 120 | / to the project. The working buffer occupies (_MAX_LFN + 1) * 2 bytes and 121 | / additional 608 bytes at exFAT enabled. _MAX_LFN can be in range from 12 to 255. 122 | / It should be set 255 to support full featured LFN operations. 123 | / When use stack for the working buffer, take care on stack overflow. When use heap 124 | / memory for the working buffer, memory management functions, ff_memalloc() and 125 | / ff_memfree(), must be added to the project. */ 126 | 127 | 128 | #define _LFN_UNICODE 0 129 | /* This option switches character encoding on the API. (0:ANSI/OEM or 1:UTF-16) 130 | / To use Unicode string for the path name, enable LFN and set _LFN_UNICODE = 1. 131 | / This option also affects behavior of string I/O functions. */ 132 | 133 | 134 | #define _STRF_ENCODE 3 135 | /* When _LFN_UNICODE == 1, this option selects the character encoding ON THE FILE to 136 | / be read/written via string I/O functions, f_gets(), f_putc(), f_puts and f_printf(). 137 | / 138 | / 0: ANSI/OEM 139 | / 1: UTF-16LE 140 | / 2: UTF-16BE 141 | / 3: UTF-8 142 | / 143 | / This option has no effect when _LFN_UNICODE == 0. */ 144 | 145 | 146 | #define _FS_RPATH 0 147 | /* This option configures support of relative path. 148 | / 149 | / 0: Disable relative path and remove related functions. 150 | / 1: Enable relative path. f_chdir() and f_chdrive() are available. 151 | / 2: f_getcwd() function is available in addition to 1. 152 | */ 153 | 154 | 155 | /*---------------------------------------------------------------------------/ 156 | / Drive/Volume Configurations 157 | /---------------------------------------------------------------------------*/ 158 | 159 | #define _VOLUMES 2 160 | /* Number of volumes (logical drives) to be used. */ 161 | 162 | 163 | #define _STR_VOLUME_ID 0 164 | #define _VOLUME_STRS "RAM","NAND","CF","SD","SD2","USB","USB2","USB3" 165 | /* _STR_VOLUME_ID switches string support of volume ID. 166 | / When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive 167 | / number in the path name. _VOLUME_STRS defines the drive ID strings for each 168 | / logical drives. Number of items must be equal to _VOLUMES. Valid characters for 169 | / the drive ID strings are: A-Z and 0-9. */ 170 | 171 | 172 | #define _MULTI_PARTITION 1 173 | /* This option switches support of multi-partition on a physical drive. 174 | / By default (0), each logical drive number is bound to the same physical drive 175 | / number and only an FAT volume found on the physical drive will be mounted. 176 | / When multi-partition is enabled (1), each logical drive number can be bound to 177 | / arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk() 178 | / funciton will be available. */ 179 | 180 | 181 | #define _MIN_SS 512 182 | #define _MAX_SS 4096 183 | /* These options configure the range of sector size to be supported. (512, 1024, 184 | / 2048 or 4096) Always set both 512 for most systems, all type of memory cards and 185 | / harddisk. But a larger value may be required for on-board flash memory and some 186 | / type of optical media. When _MAX_SS is larger than _MIN_SS, FatFs is configured 187 | / to variable sector size and GET_SECTOR_SIZE command must be implemented to the 188 | / disk_ioctl() function. */ 189 | 190 | 191 | #define _USE_TRIM 0 192 | /* This option switches support of ATA-TRIM. (0:Disable or 1:Enable) 193 | / To enable Trim function, also CTRL_TRIM command should be implemented to the 194 | / disk_ioctl() function. */ 195 | 196 | 197 | #define _FS_NOFSINFO 0 198 | /* If you need to know correct free space on the FAT32 volume, set bit 0 of this 199 | / option, and f_getfree() function at first time after volume mount will force 200 | / a full FAT scan. Bit 1 controls the use of last allocated cluster number. 201 | / 202 | / bit0=0: Use free cluster count in the FSINFO if available. 203 | / bit0=1: Do not trust free cluster count in the FSINFO. 204 | / bit1=0: Use last allocated cluster number in the FSINFO if available. 205 | / bit1=1: Do not trust last allocated cluster number in the FSINFO. 206 | */ 207 | 208 | 209 | 210 | /*---------------------------------------------------------------------------/ 211 | / System Configurations 212 | /---------------------------------------------------------------------------*/ 213 | 214 | #define _FS_TINY 0 215 | /* This option switches tiny buffer configuration. (0:Normal or 1:Tiny) 216 | / At the tiny configuration, size of file object (FIL) is reduced _MAX_SS bytes. 217 | / Instead of private sector buffer eliminated from the file object, common sector 218 | / buffer in the file system object (FATFS) is used for the file data transfer. */ 219 | 220 | 221 | #define _FS_EXFAT 0 222 | /* This option switches support of exFAT file system. (0:Disable or 1:Enable) 223 | / When enable exFAT, also LFN needs to be enabled. (_USE_LFN >= 1) 224 | / Note that enabling exFAT discards C89 compatibility. */ 225 | 226 | 227 | #define _FS_NORTC 0 228 | #define _NORTC_MON 1 229 | #define _NORTC_MDAY 1 230 | #define _NORTC_YEAR 2016 231 | /* The option _FS_NORTC switches timestamp functiton. If the system does not have 232 | / any RTC function or valid timestamp is not needed, set _FS_NORTC = 1 to disable 233 | / the timestamp function. All objects modified by FatFs will have a fixed timestamp 234 | / defined by _NORTC_MON, _NORTC_MDAY and _NORTC_YEAR in local time. 235 | / To enable timestamp function (_FS_NORTC = 0), get_fattime() function need to be 236 | / added to the project to get current time form real-time clock. _NORTC_MON, 237 | / _NORTC_MDAY and _NORTC_YEAR have no effect. 238 | / These options have no effect at read-only configuration (_FS_READONLY = 1). */ 239 | 240 | 241 | #define _FS_LOCK 0 242 | /* The option _FS_LOCK switches file lock function to control duplicated file open 243 | / and illegal operation to open objects. This option must be 0 when _FS_READONLY 244 | / is 1. 245 | / 246 | / 0: Disable file lock function. To avoid volume corruption, application program 247 | / should avoid illegal open, remove and rename to the open objects. 248 | / >0: Enable file lock function. The value defines how many files/sub-directories 249 | / can be opened simultaneously under file lock control. Note that the file 250 | / lock control is independent of re-entrancy. */ 251 | 252 | 253 | #define _FS_REENTRANT 1 254 | #define _FS_TIMEOUT 1000 255 | #define _SYNC_t SemaphoreHandle_t 256 | /* The option _FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs 257 | / module itself. Note that regardless of this option, file access to different 258 | / volume is always re-entrant and volume control functions, f_mount(), f_mkfs() 259 | / and f_fdisk() function, are always not re-entrant. Only file/directory access 260 | / to the same volume is under control of this function. 261 | / 262 | / 0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect. 263 | / 1: Enable re-entrancy. Also user provided synchronization handlers, 264 | / ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj() 265 | / function, must be added to the project. Samples are available in 266 | / option/syscall.c. 267 | / 268 | / The _FS_TIMEOUT defines timeout period in unit of time tick. 269 | / The _SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*, 270 | / SemaphoreHandle_t and etc.. A header file for O/S definitions needs to be 271 | / included somewhere in the scope of ff.h. */ 272 | 273 | #include "FreeRTOS.h" 274 | #include "semphr.h" 275 | 276 | /*--- End of configuration options ---*/ 277 | -------------------------------------------------------------------------------- /tclap/UnlabeledValueArg.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: UnlabeledValueArg.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot . 7 | * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | 24 | #ifndef TCLAP_UNLABELED_VALUE_ARGUMENT_H 25 | #define TCLAP_UNLABELED_VALUE_ARGUMENT_H 26 | 27 | #include 28 | #include 29 | 30 | #include "ValueArg.h" 31 | #include "OptionalUnlabeledTracker.h" 32 | 33 | 34 | namespace TCLAP { 35 | 36 | /** 37 | * The basic unlabeled argument that parses a value. 38 | * This is a template class, which means the type T defines the type 39 | * that a given object will attempt to parse when an UnlabeledValueArg 40 | * is reached in the list of args that the CmdLine iterates over. 41 | */ 42 | template 43 | class UnlabeledValueArg : public ValueArg 44 | { 45 | 46 | // If compiler has two stage name lookup (as gcc >= 3.4 does) 47 | // this is requried to prevent undef. symbols 48 | using ValueArg::_ignoreable; 49 | using ValueArg::_hasBlanks; 50 | using ValueArg::_extractValue; 51 | using ValueArg::_typeDesc; 52 | using ValueArg::_name; 53 | using ValueArg::_description; 54 | using ValueArg::_alreadySet; 55 | using ValueArg::toString; 56 | 57 | public: 58 | 59 | /** 60 | * UnlabeledValueArg constructor. 61 | * \param name - A one word name for the argument. Note that this is used for 62 | * identification, not as a long flag. 63 | * \param desc - A description of what the argument is for or 64 | * does. 65 | * \param req - Whether the argument is required on the command 66 | * line. 67 | * \param value - The default value assigned to this argument if it 68 | * is not present on the command line. 69 | * \param typeDesc - A short, human readable description of the 70 | * type that this object expects. This is used in the generation 71 | * of the USAGE statement. The goal is to be helpful to the end user 72 | * of the program. 73 | * \param ignoreable - Allows you to specify that this argument can be 74 | * ignored if the '--' flag is set. This defaults to false (cannot 75 | * be ignored) and should generally stay that way unless you have 76 | * some special need for certain arguments to be ignored. 77 | * \param v - Optional Vistor. You should leave this blank unless 78 | * you have a very good reason. 79 | */ 80 | UnlabeledValueArg( const std::string& name, 81 | const std::string& desc, 82 | bool req, 83 | T value, 84 | const std::string& typeDesc, 85 | bool ignoreable = false, 86 | Visitor* v = NULL); 87 | 88 | /** 89 | * UnlabeledValueArg constructor. 90 | * \param name - A one word name for the argument. Note that this is used for 91 | * identification, not as a long flag. 92 | * \param desc - A description of what the argument is for or 93 | * does. 94 | * \param req - Whether the argument is required on the command 95 | * line. 96 | * \param value - The default value assigned to this argument if it 97 | * is not present on the command line. 98 | * \param typeDesc - A short, human readable description of the 99 | * type that this object expects. This is used in the generation 100 | * of the USAGE statement. The goal is to be helpful to the end user 101 | * of the program. 102 | * \param parser - A CmdLine parser object to add this Arg to 103 | * \param ignoreable - Allows you to specify that this argument can be 104 | * ignored if the '--' flag is set. This defaults to false (cannot 105 | * be ignored) and should generally stay that way unless you have 106 | * some special need for certain arguments to be ignored. 107 | * \param v - Optional Vistor. You should leave this blank unless 108 | * you have a very good reason. 109 | */ 110 | UnlabeledValueArg( const std::string& name, 111 | const std::string& desc, 112 | bool req, 113 | T value, 114 | const std::string& typeDesc, 115 | CmdLineInterface& parser, 116 | bool ignoreable = false, 117 | Visitor* v = NULL ); 118 | 119 | /** 120 | * UnlabeledValueArg constructor. 121 | * \param name - A one word name for the argument. Note that this is used for 122 | * identification, not as a long flag. 123 | * \param desc - A description of what the argument is for or 124 | * does. 125 | * \param req - Whether the argument is required on the command 126 | * line. 127 | * \param value - The default value assigned to this argument if it 128 | * is not present on the command line. 129 | * \param constraint - A pointer to a Constraint object used 130 | * to constrain this Arg. 131 | * \param ignoreable - Allows you to specify that this argument can be 132 | * ignored if the '--' flag is set. This defaults to false (cannot 133 | * be ignored) and should generally stay that way unless you have 134 | * some special need for certain arguments to be ignored. 135 | * \param v - Optional Vistor. You should leave this blank unless 136 | * you have a very good reason. 137 | */ 138 | UnlabeledValueArg( const std::string& name, 139 | const std::string& desc, 140 | bool req, 141 | T value, 142 | Constraint* constraint, 143 | bool ignoreable = false, 144 | Visitor* v = NULL ); 145 | 146 | 147 | /** 148 | * UnlabeledValueArg constructor. 149 | * \param name - A one word name for the argument. Note that this is used for 150 | * identification, not as a long flag. 151 | * \param desc - A description of what the argument is for or 152 | * does. 153 | * \param req - Whether the argument is required on the command 154 | * line. 155 | * \param value - The default value assigned to this argument if it 156 | * is not present on the command line. 157 | * \param constraint - A pointer to a Constraint object used 158 | * to constrain this Arg. 159 | * \param parser - A CmdLine parser object to add this Arg to 160 | * \param ignoreable - Allows you to specify that this argument can be 161 | * ignored if the '--' flag is set. This defaults to false (cannot 162 | * be ignored) and should generally stay that way unless you have 163 | * some special need for certain arguments to be ignored. 164 | * \param v - Optional Vistor. You should leave this blank unless 165 | * you have a very good reason. 166 | */ 167 | UnlabeledValueArg( const std::string& name, 168 | const std::string& desc, 169 | bool req, 170 | T value, 171 | Constraint* constraint, 172 | CmdLineInterface& parser, 173 | bool ignoreable = false, 174 | Visitor* v = NULL); 175 | 176 | /** 177 | * Handles the processing of the argument. 178 | * This re-implements the Arg version of this method to set the 179 | * _value of the argument appropriately. Handling specific to 180 | * unlabled arguments. 181 | * \param i - Pointer the the current argument in the list. 182 | * \param args - Mutable list of strings. 183 | */ 184 | virtual bool processArg(int* i, std::vector& args); 185 | 186 | /** 187 | * Overrides shortID for specific behavior. 188 | */ 189 | virtual std::string shortID(const std::string& val="val") const; 190 | 191 | /** 192 | * Overrides longID for specific behavior. 193 | */ 194 | virtual std::string longID(const std::string& val="val") const; 195 | 196 | /** 197 | * Overrides operator== for specific behavior. 198 | */ 199 | virtual bool operator==(const Arg& a ) const; 200 | 201 | /** 202 | * Instead of pushing to the front of list, push to the back. 203 | * \param argList - The list to add this to. 204 | */ 205 | virtual void addToList( std::list& argList ) const; 206 | 207 | }; 208 | 209 | /** 210 | * Constructor implemenation. 211 | */ 212 | template 213 | UnlabeledValueArg::UnlabeledValueArg(const std::string& name, 214 | const std::string& desc, 215 | bool req, 216 | T val, 217 | const std::string& typeDesc, 218 | bool ignoreable, 219 | Visitor* v) 220 | : ValueArg("", name, desc, req, val, typeDesc, v) 221 | { 222 | _ignoreable = ignoreable; 223 | 224 | OptionalUnlabeledTracker::check(req, toString()); 225 | 226 | } 227 | 228 | template 229 | UnlabeledValueArg::UnlabeledValueArg(const std::string& name, 230 | const std::string& desc, 231 | bool req, 232 | T val, 233 | const std::string& typeDesc, 234 | CmdLineInterface& parser, 235 | bool ignoreable, 236 | Visitor* v) 237 | : ValueArg("", name, desc, req, val, typeDesc, v) 238 | { 239 | _ignoreable = ignoreable; 240 | OptionalUnlabeledTracker::check(req, toString()); 241 | parser.add( this ); 242 | } 243 | 244 | /** 245 | * Constructor implemenation. 246 | */ 247 | template 248 | UnlabeledValueArg::UnlabeledValueArg(const std::string& name, 249 | const std::string& desc, 250 | bool req, 251 | T val, 252 | Constraint* constraint, 253 | bool ignoreable, 254 | Visitor* v) 255 | : ValueArg("", name, desc, req, val, constraint, v) 256 | { 257 | _ignoreable = ignoreable; 258 | OptionalUnlabeledTracker::check(req, toString()); 259 | } 260 | 261 | template 262 | UnlabeledValueArg::UnlabeledValueArg(const std::string& name, 263 | const std::string& desc, 264 | bool req, 265 | T val, 266 | Constraint* constraint, 267 | CmdLineInterface& parser, 268 | bool ignoreable, 269 | Visitor* v) 270 | : ValueArg("", name, desc, req, val, constraint, v) 271 | { 272 | _ignoreable = ignoreable; 273 | OptionalUnlabeledTracker::check(req, toString()); 274 | parser.add( this ); 275 | } 276 | 277 | /** 278 | * Implementation of processArg(). 279 | */ 280 | template 281 | bool UnlabeledValueArg::processArg(int *i, std::vector& args) 282 | { 283 | 284 | if ( _alreadySet ) 285 | return false; 286 | 287 | if ( _hasBlanks( args[*i] ) ) 288 | return false; 289 | 290 | // never ignore an unlabeled arg 291 | 292 | _extractValue( args[*i] ); 293 | _alreadySet = true; 294 | return true; 295 | } 296 | 297 | /** 298 | * Overriding shortID for specific output. 299 | */ 300 | template 301 | std::string UnlabeledValueArg::shortID(const std::string& val) const 302 | { 303 | static_cast(val); // Ignore input, don't warn 304 | return std::string("<") + _typeDesc + ">"; 305 | } 306 | 307 | /** 308 | * Overriding longID for specific output. 309 | */ 310 | template 311 | std::string UnlabeledValueArg::longID(const std::string& val) const 312 | { 313 | static_cast(val); // Ignore input, don't warn 314 | 315 | // Ideally we would like to be able to use RTTI to return the name 316 | // of the type required for this argument. However, g++ at least, 317 | // doesn't appear to return terribly useful "names" of the types. 318 | return std::string("<") + _typeDesc + ">"; 319 | } 320 | 321 | /** 322 | * Overriding operator== for specific behavior. 323 | */ 324 | template 325 | bool UnlabeledValueArg::operator==(const Arg& a ) const 326 | { 327 | if ( _name == a.getName() || _description == a.getDescription() ) 328 | return true; 329 | else 330 | return false; 331 | } 332 | 333 | template 334 | void UnlabeledValueArg::addToList( std::list& argList ) const 335 | { 336 | argList.push_back( const_cast(static_cast(this)) ); 337 | } 338 | 339 | } 340 | #endif 341 | -------------------------------------------------------------------------------- /tclap/MultiArg.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * file: MultiArg.h 4 | * 5 | * Copyright (c) 2003, Michael E. Smoot . 6 | * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. 7 | * All rights reverved. 8 | * 9 | * See the file COPYING in the top directory of this distribution for 10 | * more information. 11 | * 12 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 15 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | *****************************************************************************/ 21 | 22 | 23 | #ifndef TCLAP_MULTIPLE_ARGUMENT_H 24 | #define TCLAP_MULTIPLE_ARGUMENT_H 25 | 26 | #include 27 | #include 28 | 29 | #include "Arg.h" 30 | #include "Constraint.h" 31 | 32 | namespace TCLAP { 33 | /** 34 | * An argument that allows multiple values of type T to be specified. Very 35 | * similar to a ValueArg, except a vector of values will be returned 36 | * instead of just one. 37 | */ 38 | template 39 | class MultiArg : public Arg 40 | { 41 | public: 42 | typedef std::vector container_type; 43 | typedef typename container_type::iterator iterator; 44 | typedef typename container_type::const_iterator const_iterator; 45 | 46 | protected: 47 | 48 | /** 49 | * The list of values parsed from the CmdLine. 50 | */ 51 | std::vector _values; 52 | 53 | /** 54 | * The description of type T to be used in the usage. 55 | */ 56 | std::string _typeDesc; 57 | 58 | /** 59 | * A list of constraint on this Arg. 60 | */ 61 | Constraint* _constraint; 62 | 63 | /** 64 | * Extracts the value from the string. 65 | * Attempts to parse string as type T, if this fails an exception 66 | * is thrown. 67 | * \param val - The string to be read. 68 | */ 69 | void _extractValue( const std::string& val ); 70 | 71 | /** 72 | * Used by XorHandler to decide whether to keep parsing for this arg. 73 | */ 74 | bool _allowMore; 75 | 76 | public: 77 | 78 | /** 79 | * Constructor. 80 | * \param flag - The one character flag that identifies this 81 | * argument on the command line. 82 | * \param name - A one word name for the argument. Can be 83 | * used as a long flag on the command line. 84 | * \param desc - A description of what the argument is for or 85 | * does. 86 | * \param req - Whether the argument is required on the command 87 | * line. 88 | * \param typeDesc - A short, human readable description of the 89 | * type that this object expects. This is used in the generation 90 | * of the USAGE statement. The goal is to be helpful to the end user 91 | * of the program. 92 | * \param v - An optional visitor. You probably should not 93 | * use this unless you have a very good reason. 94 | */ 95 | MultiArg( const std::string& flag, 96 | const std::string& name, 97 | const std::string& desc, 98 | bool req, 99 | const std::string& typeDesc, 100 | Visitor* v = NULL); 101 | 102 | /** 103 | * Constructor. 104 | * \param flag - The one character flag that identifies this 105 | * argument on the command line. 106 | * \param name - A one word name for the argument. Can be 107 | * used as a long flag on the command line. 108 | * \param desc - A description of what the argument is for or 109 | * does. 110 | * \param req - Whether the argument is required on the command 111 | * line. 112 | * \param typeDesc - A short, human readable description of the 113 | * type that this object expects. This is used in the generation 114 | * of the USAGE statement. The goal is to be helpful to the end user 115 | * of the program. 116 | * \param parser - A CmdLine parser object to add this Arg to 117 | * \param v - An optional visitor. You probably should not 118 | * use this unless you have a very good reason. 119 | */ 120 | MultiArg( const std::string& flag, 121 | const std::string& name, 122 | const std::string& desc, 123 | bool req, 124 | const std::string& typeDesc, 125 | CmdLineInterface& parser, 126 | Visitor* v = NULL ); 127 | 128 | /** 129 | * Constructor. 130 | * \param flag - The one character flag that identifies this 131 | * argument on the command line. 132 | * \param name - A one word name for the argument. Can be 133 | * used as a long flag on the command line. 134 | * \param desc - A description of what the argument is for or 135 | * does. 136 | * \param req - Whether the argument is required on the command 137 | * line. 138 | * \param constraint - A pointer to a Constraint object used 139 | * to constrain this Arg. 140 | * \param v - An optional visitor. You probably should not 141 | * use this unless you have a very good reason. 142 | */ 143 | MultiArg( const std::string& flag, 144 | const std::string& name, 145 | const std::string& desc, 146 | bool req, 147 | Constraint* constraint, 148 | Visitor* v = NULL ); 149 | 150 | /** 151 | * Constructor. 152 | * \param flag - The one character flag that identifies this 153 | * argument on the command line. 154 | * \param name - A one word name for the argument. Can be 155 | * used as a long flag on the command line. 156 | * \param desc - A description of what the argument is for or 157 | * does. 158 | * \param req - Whether the argument is required on the command 159 | * line. 160 | * \param constraint - A pointer to a Constraint object used 161 | * to constrain this Arg. 162 | * \param parser - A CmdLine parser object to add this Arg to 163 | * \param v - An optional visitor. You probably should not 164 | * use this unless you have a very good reason. 165 | */ 166 | MultiArg( const std::string& flag, 167 | const std::string& name, 168 | const std::string& desc, 169 | bool req, 170 | Constraint* constraint, 171 | CmdLineInterface& parser, 172 | Visitor* v = NULL ); 173 | 174 | /** 175 | * Handles the processing of the argument. 176 | * This re-implements the Arg version of this method to set the 177 | * _value of the argument appropriately. It knows the difference 178 | * between labeled and unlabeled. 179 | * \param i - Pointer the the current argument in the list. 180 | * \param args - Mutable list of strings. Passed from main(). 181 | */ 182 | virtual bool processArg(int* i, std::vector& args); 183 | 184 | /** 185 | * Returns a vector of type T containing the values parsed from 186 | * the command line. 187 | */ 188 | const std::vector& getValue(); 189 | 190 | /** 191 | * Returns an iterator over the values parsed from the command 192 | * line. 193 | */ 194 | const_iterator begin() const { return _values.begin(); } 195 | 196 | /** 197 | * Returns the end of the values parsed from the command 198 | * line. 199 | */ 200 | const_iterator end() const { return _values.end(); } 201 | 202 | /** 203 | * Returns the a short id string. Used in the usage. 204 | * \param val - value to be used. 205 | */ 206 | virtual std::string shortID(const std::string& val="val") const; 207 | 208 | /** 209 | * Returns the a long id string. Used in the usage. 210 | * \param val - value to be used. 211 | */ 212 | virtual std::string longID(const std::string& val="val") const; 213 | 214 | /** 215 | * Once we've matched the first value, then the arg is no longer 216 | * required. 217 | */ 218 | virtual bool isRequired() const; 219 | 220 | virtual bool allowMore(); 221 | 222 | virtual void reset(); 223 | 224 | private: 225 | /** 226 | * Prevent accidental copying 227 | */ 228 | MultiArg(const MultiArg& rhs); 229 | MultiArg& operator=(const MultiArg& rhs); 230 | 231 | }; 232 | 233 | template 234 | MultiArg::MultiArg(const std::string& flag, 235 | const std::string& name, 236 | const std::string& desc, 237 | bool req, 238 | const std::string& typeDesc, 239 | Visitor* v) : 240 | Arg( flag, name, desc, req, true, v ), 241 | _values(std::vector()), 242 | _typeDesc( typeDesc ), 243 | _constraint( NULL ), 244 | _allowMore(false) 245 | { 246 | _acceptsMultipleValues = true; 247 | } 248 | 249 | template 250 | MultiArg::MultiArg(const std::string& flag, 251 | const std::string& name, 252 | const std::string& desc, 253 | bool req, 254 | const std::string& typeDesc, 255 | CmdLineInterface& parser, 256 | Visitor* v) 257 | : Arg( flag, name, desc, req, true, v ), 258 | _values(std::vector()), 259 | _typeDesc( typeDesc ), 260 | _constraint( NULL ), 261 | _allowMore(false) 262 | { 263 | parser.add( this ); 264 | _acceptsMultipleValues = true; 265 | } 266 | 267 | /** 268 | * 269 | */ 270 | template 271 | MultiArg::MultiArg(const std::string& flag, 272 | const std::string& name, 273 | const std::string& desc, 274 | bool req, 275 | Constraint* constraint, 276 | Visitor* v) 277 | : Arg( flag, name, desc, req, true, v ), 278 | _values(std::vector()), 279 | _typeDesc( constraint->shortID() ), 280 | _constraint( constraint ), 281 | _allowMore(false) 282 | { 283 | _acceptsMultipleValues = true; 284 | } 285 | 286 | template 287 | MultiArg::MultiArg(const std::string& flag, 288 | const std::string& name, 289 | const std::string& desc, 290 | bool req, 291 | Constraint* constraint, 292 | CmdLineInterface& parser, 293 | Visitor* v) 294 | : Arg( flag, name, desc, req, true, v ), 295 | _values(std::vector()), 296 | _typeDesc( constraint->shortID() ), 297 | _constraint( constraint ), 298 | _allowMore(false) 299 | { 300 | parser.add( this ); 301 | _acceptsMultipleValues = true; 302 | } 303 | 304 | template 305 | const std::vector& MultiArg::getValue() { return _values; } 306 | 307 | template 308 | bool MultiArg::processArg(int *i, std::vector& args) 309 | { 310 | if ( _ignoreable && Arg::ignoreRest() ) 311 | return false; 312 | 313 | if ( _hasBlanks( args[*i] ) ) 314 | return false; 315 | 316 | std::string flag = args[*i]; 317 | std::string value = ""; 318 | 319 | trimFlag( flag, value ); 320 | 321 | if ( argMatches( flag ) ) 322 | { 323 | if ( Arg::delimiter() != ' ' && value == "" ) 324 | throw( ArgParseException( 325 | "Couldn't find delimiter for this argument!", 326 | toString() ) ); 327 | 328 | // always take the first one, regardless of start string 329 | if ( value == "" ) 330 | { 331 | (*i)++; 332 | if ( static_cast(*i) < args.size() ) 333 | _extractValue( args[*i] ); 334 | else 335 | throw( ArgParseException("Missing a value for this argument!", 336 | toString() ) ); 337 | } 338 | else 339 | _extractValue( value ); 340 | 341 | /* 342 | // continuing taking the args until we hit one with a start string 343 | while ( (unsigned int)(*i)+1 < args.size() && 344 | args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 && 345 | args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 ) 346 | _extractValue( args[++(*i)] ); 347 | */ 348 | 349 | _alreadySet = true; 350 | _checkWithVisitor(); 351 | 352 | return true; 353 | } 354 | else 355 | return false; 356 | } 357 | 358 | /** 359 | * 360 | */ 361 | template 362 | std::string MultiArg::shortID(const std::string& val) const 363 | { 364 | static_cast(val); // Ignore input, don't warn 365 | return Arg::shortID(_typeDesc) + " ... "; 366 | } 367 | 368 | /** 369 | * 370 | */ 371 | template 372 | std::string MultiArg::longID(const std::string& val) const 373 | { 374 | static_cast(val); // Ignore input, don't warn 375 | return Arg::longID(_typeDesc) + " (accepted multiple times)"; 376 | } 377 | 378 | /** 379 | * Once we've matched the first value, then the arg is no longer 380 | * required. 381 | */ 382 | template 383 | bool MultiArg::isRequired() const 384 | { 385 | if ( _required ) 386 | { 387 | if ( _values.size() > 1 ) 388 | return false; 389 | else 390 | return true; 391 | } 392 | else 393 | return false; 394 | 395 | } 396 | 397 | template 398 | void MultiArg::_extractValue( const std::string& val ) 399 | { 400 | try { 401 | T tmp; 402 | ExtractValue(tmp, val, typename ArgTraits::ValueCategory()); 403 | _values.push_back(tmp); 404 | } catch( ArgParseException &e) { 405 | throw ArgParseException(e.error(), toString()); 406 | } 407 | 408 | if ( _constraint != NULL ) 409 | if ( ! _constraint->check( _values.back() ) ) 410 | throw( CmdLineParseException( "Value '" + val + 411 | "' does not meet constraint: " + 412 | _constraint->description(), 413 | toString() ) ); 414 | } 415 | 416 | template 417 | bool MultiArg::allowMore() 418 | { 419 | bool am = _allowMore; 420 | _allowMore = true; 421 | return am; 422 | } 423 | 424 | template 425 | void MultiArg::reset() 426 | { 427 | Arg::reset(); 428 | _values.clear(); 429 | } 430 | 431 | } // namespace TCLAP 432 | 433 | #endif 434 | --------------------------------------------------------------------------------