├── components ├── spiffs │ ├── spiffs.zip │ ├── component.mk │ ├── spiffs_vfs.h │ ├── spiffs_cache.c │ └── spiffs_config.h ├── mkspiffs │ ├── component.mk │ ├── Makefile.projbuild │ ├── src │ │ ├── appveyor.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 │ │ ├── spiffs │ │ │ ├── esp_spiffs.h │ │ │ ├── esp_spiffs.c │ │ │ ├── spiffs_cache.c │ │ │ └── spiffs_config.h │ │ ├── README.md │ │ ├── Makefile │ │ └── Makefile.original │ └── .travis.yml ├── spiffs_image │ ├── component.mk │ ├── spiffs_image.img │ ├── image │ │ ├── fonts │ │ │ ├── BigFont.fon │ │ │ ├── Ubuntu.fon │ │ │ ├── SmallFont.fon │ │ │ ├── DejaVuSans12.fon │ │ │ ├── DejaVuSans18.fon │ │ │ ├── DejaVuSans24.fon │ │ │ ├── DotMatrix_M.fon │ │ │ ├── Grotesk24x48.fon │ │ │ ├── arial_bold.fon │ │ │ └── swiss721_outline.fon │ │ ├── images │ │ │ ├── test1.jpg │ │ │ ├── test2.jpg │ │ │ ├── test3.jpg │ │ │ └── test4.jpg │ │ └── spiffs.info │ └── Makefile.projbuild └── ymodem │ ├── component.mk │ └── ymodem.h ├── Makefile ├── main ├── component.mk └── Kconfig.projbuild ├── partitions_example.csv ├── .gitignore ├── sdkconfig.defaults └── README.md /components/spiffs/spiffs.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loboris/ESP32_ymodem_example/HEAD/components/spiffs/spiffs.zip -------------------------------------------------------------------------------- /components/mkspiffs/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Component Makefile 3 | # 4 | 5 | COMPONENT_SRCDIRS := 6 | COMPONENT_ADD_INCLUDEDIRS := 7 | -------------------------------------------------------------------------------- /components/spiffs_image/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Component Makefile 3 | # 4 | 5 | COMPONENT_SRCDIRS := 6 | COMPONENT_ADD_INCLUDEDIRS := 7 | -------------------------------------------------------------------------------- /components/spiffs_image/spiffs_image.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loboris/ESP32_ymodem_example/HEAD/components/spiffs_image/spiffs_image.img -------------------------------------------------------------------------------- /components/spiffs_image/image/fonts/BigFont.fon: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loboris/ESP32_ymodem_example/HEAD/components/spiffs_image/image/fonts/BigFont.fon -------------------------------------------------------------------------------- /components/spiffs_image/image/fonts/Ubuntu.fon: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loboris/ESP32_ymodem_example/HEAD/components/spiffs_image/image/fonts/Ubuntu.fon -------------------------------------------------------------------------------- /components/spiffs_image/image/images/test1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loboris/ESP32_ymodem_example/HEAD/components/spiffs_image/image/images/test1.jpg -------------------------------------------------------------------------------- /components/spiffs_image/image/images/test2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loboris/ESP32_ymodem_example/HEAD/components/spiffs_image/image/images/test2.jpg -------------------------------------------------------------------------------- /components/spiffs_image/image/images/test3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loboris/ESP32_ymodem_example/HEAD/components/spiffs_image/image/images/test3.jpg -------------------------------------------------------------------------------- /components/spiffs_image/image/images/test4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loboris/ESP32_ymodem_example/HEAD/components/spiffs_image/image/images/test4.jpg -------------------------------------------------------------------------------- /components/spiffs_image/image/fonts/SmallFont.fon: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loboris/ESP32_ymodem_example/HEAD/components/spiffs_image/image/fonts/SmallFont.fon -------------------------------------------------------------------------------- /components/spiffs/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Component Makefile 3 | # 4 | 5 | COMPONENT_SRCDIRS := . 6 | COMPONENT_ADD_INCLUDEDIRS := . 7 | COMPONENT_PRIV_INCLUDEDIRS := -------------------------------------------------------------------------------- /components/spiffs_image/image/fonts/DejaVuSans12.fon: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loboris/ESP32_ymodem_example/HEAD/components/spiffs_image/image/fonts/DejaVuSans12.fon -------------------------------------------------------------------------------- /components/spiffs_image/image/fonts/DejaVuSans18.fon: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loboris/ESP32_ymodem_example/HEAD/components/spiffs_image/image/fonts/DejaVuSans18.fon -------------------------------------------------------------------------------- /components/spiffs_image/image/fonts/DejaVuSans24.fon: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loboris/ESP32_ymodem_example/HEAD/components/spiffs_image/image/fonts/DejaVuSans24.fon -------------------------------------------------------------------------------- /components/spiffs_image/image/fonts/DotMatrix_M.fon: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loboris/ESP32_ymodem_example/HEAD/components/spiffs_image/image/fonts/DotMatrix_M.fon -------------------------------------------------------------------------------- /components/spiffs_image/image/fonts/Grotesk24x48.fon: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loboris/ESP32_ymodem_example/HEAD/components/spiffs_image/image/fonts/Grotesk24x48.fon -------------------------------------------------------------------------------- /components/spiffs_image/image/fonts/arial_bold.fon: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loboris/ESP32_ymodem_example/HEAD/components/spiffs_image/image/fonts/arial_bold.fon -------------------------------------------------------------------------------- /components/spiffs_image/image/fonts/swiss721_outline.fon: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loboris/ESP32_ymodem_example/HEAD/components/spiffs_image/image/fonts/swiss721_outline.fon -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | 6 | PROJECT_NAME := ymodem_example_main 7 | 8 | include $(IDF_PATH)/make/project.mk 9 | 10 | -------------------------------------------------------------------------------- /main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main Makefile. This is basically the same as a component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | 6 | COMPONENT_SRCDIRS := . 7 | COMPONENT_ADD_INCLUDEDIRS := . 8 | -------------------------------------------------------------------------------- /components/ymodem/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main Makefile. This is basically the same as a component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | 6 | COMPONENT_SRCDIRS := . 7 | COMPONENT_ADD_INCLUDEDIRS := . 8 | -------------------------------------------------------------------------------- /partitions_example.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild 3 | nvs, data, nvs, 0x9000, 0x6000, 4 | phy_init, data, phy, 0xf000, 0x1000, 5 | factory, app, factory, 0x10000, 1M, 6 | storage, data, spiffs, 0x180000, 1M, 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .config 2 | *.o 3 | *.pyc 4 | *.a 5 | *.d 6 | 7 | # gtags 8 | GTAGS 9 | GRTAGS 10 | GPATH 11 | 12 | # emacs 13 | .dir-locals.el 14 | 15 | # emacs temp file suffixes 16 | *~ 17 | .#* 18 | \#*# 19 | 20 | sdkconfig 21 | sdkconfig.old 22 | sdkconfig.lobo 23 | .cproject 24 | .project 25 | .settings 26 | BUILD 27 | build/ 28 | temp/ 29 | local/ 30 | *.dis 31 | *.elf 32 | *.map 33 | **/.DS_Store 34 | -------------------------------------------------------------------------------- /sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | CONFIG_PARTITION_TABLE_CUSTOM=y 2 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_example.csv" 3 | CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET=0x10000 4 | CONFIG_PARTITION_TABLE_FILENAME="partitions_example.csv" 5 | CONFIG_APP_OFFSET=0x10000 6 | CONFIG_ESP32_PANIC_PRINT_HALT=y 7 | CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y 8 | CONFIG_FREERTOS_HZ=1000 9 | CONFIG_MAIN_TASK_STACK_SIZE=16384 10 | CONFIG_TASK_WDT_TIMEOUT_S=10 11 | -------------------------------------------------------------------------------- /components/mkspiffs/Makefile.projbuild: -------------------------------------------------------------------------------- 1 | MKSPIFFS_COMPONENT_PATH := $(COMPONENT_PATH) 2 | MKSPIFFS_BUILD_DIR=$(abspath $(MKSPIFFS_COMPONENT_PATH)/mkspiffs) 3 | 4 | # Custom recursive make for mkspiffs sub-project 5 | MKSPIFFS_MAKE=+$(MAKE) -C $(MKSPIFFS_COMPONENT_PATH)/src 6 | 7 | .PHONY: mkspiffs clean 8 | 9 | mkspiffs: $(SDKCONFIG_MAKEFILE) 10 | $(MKSPIFFS_MAKE) all 11 | 12 | clean: $(SDKCONFIG_MAKEFILE) 13 | $(MKSPIFFS_MAKE) clean 14 | 15 | -------------------------------------------------------------------------------- /components/spiffs_image/image/spiffs.info: -------------------------------------------------------------------------------- 1 | INTRODUCTION 2 | 3 | Spiffs is a file system intended for SPI NOR flash devices on embedded targets. 4 | Spiffs is designed with following characteristics in mind: 5 | 6 | * Small (embedded) targets, sparse RAM without heap 7 | * Only big areas of data (blocks) can be erased 8 | * An erase will reset all bits in block to ones 9 | * Writing pulls one to zeroes 10 | * Zeroes can only be pulled to ones by erase 11 | * Wear leveling 12 | -------------------------------------------------------------------------------- /components/mkspiffs/src/appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 0.0.{build} 2 | 3 | platform: 4 | - x86 5 | 6 | skip_commits: 7 | message: /\[ci skip\]/ 8 | 9 | matrix: 10 | fast_finish: true 11 | 12 | build_script: 13 | - SET PATH=C:\MinGW\bin;C:\MinGW\msys\1.0\bin;%PATH% 14 | - make dist 15 | 16 | artifacts: 17 | - path: '*.zip' 18 | 19 | deploy: 20 | release: $(PRODUCT_VERSION) 21 | provider: GitHub 22 | auth_token: 23 | secure: 'PGg5fnoBpP1Omzr6f3KIYDiD8J30rretQjSl/MITRpzvSCmN88kM6VDMz1TBGZTA' 24 | artifact: /.*\.zip/ 25 | draft: true 26 | prerelease: false 27 | on: 28 | appveyor_repo_tag: true 29 | -------------------------------------------------------------------------------- /components/spiffs/spiffs_vfs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * spiffs VFS public function 3 | * 4 | * Author: LoBo (loboris@gmail.com / https://github.com/loboris) 5 | * 6 | * Part of this code is copied from or inspired by LUA-RTOS_ESP32 project: 7 | * 8 | * https://github.com/whitecatboard/Lua-RTOS-ESP32 9 | * IBEROXARXA SERVICIOS INTEGRALES, S.L. & CSS IBÉRICA, S.L. 10 | * Jaume Olivé (jolive@iberoxarxa.com / jolive@whitecatboard.org) 11 | * 12 | */ 13 | 14 | #define SPIFFS_BASE_PATH "/spiffs" 15 | 16 | 17 | extern int spiffs_is_registered; 18 | extern int spiffs_is_mounted; 19 | extern uint32_t max_lock; 20 | extern uint32_t max_file_lock; 21 | 22 | void vfs_spiffs_register(); 23 | int spiffs_mount(); 24 | int spiffs_unmount(int unreg); 25 | void spiffs_fs_stat(uint32_t *total, uint32_t *used); 26 | -------------------------------------------------------------------------------- /components/spiffs_image/Makefile.projbuild: -------------------------------------------------------------------------------- 1 | SPIFFS_IMAGE_COMPONENT_PATH := $(COMPONENT_PATH) 2 | 3 | .PHONY: flashfs 4 | .PHONY: makefs 5 | .PHONY: copyfs 6 | 7 | flashfs: $(SDKCONFIG_MAKEFILE) mkspiffs 8 | @echo "Making spiffs image ..." 9 | @echo "$(ESPTOOLPY_WRITE_FLASH)" 10 | $(MKSPIFFS_COMPONENT_PATH)/../mkspiffs/src/mkspiffs -c $(SPIFFS_IMAGE_COMPONENT_PATH)/image -b $(CONFIG_SPIFFS_LOG_BLOCK_SIZE) -p $(CONFIG_SPIFFS_LOG_PAGE_SIZE) -s $(CONFIG_SPIFFS_SIZE) $(BUILD_DIR_BASE)/spiffs_image.img 11 | $(ESPTOOLPY_WRITE_FLASH) $(CONFIG_SPIFFS_BASE_ADDR) $(BUILD_DIR_BASE)/spiffs_image.img 12 | 13 | makefs: $(SDKCONFIG_MAKEFILE) mkspiffs 14 | @echo "Making spiffs image ..." 15 | @echo "$(ESPTOOLPY_WRITE_FLASH)" 16 | $(MKSPIFFS_COMPONENT_PATH)/../mkspiffs/src/mkspiffs -c $(SPIFFS_IMAGE_COMPONENT_PATH)/image -b $(CONFIG_SPIFFS_LOG_BLOCK_SIZE) -p $(CONFIG_SPIFFS_LOG_PAGE_SIZE) -s $(CONFIG_SPIFFS_SIZE) $(BUILD_DIR_BASE)/spiffs_image.img 17 | 18 | copyfs: 19 | @echo "Flashing spiffs image ..." 20 | @echo "$(ESPTOOLPY_WRITE_FLASH)" 21 | $(ESPTOOLPY_WRITE_FLASH) $(CONFIG_SPIFFS_BASE_ADDR) $(SPIFFS_IMAGE_COMPONENT_PATH)/spiffs_image.img 22 | -------------------------------------------------------------------------------- /components/mkspiffs/src/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 | -------------------------------------------------------------------------------- /components/mkspiffs/.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | addons: 3 | apt: 4 | sources: 5 | - ubuntu-toolchain-r-test 6 | packages: 7 | - g++-4.8 8 | script: 9 | - export CXX="g++-4.8" CC="gcc-4.8" 10 | - make dist 11 | notifications: 12 | email: 13 | recipients: 14 | - ivan@esp8266.com 15 | on_success: change 16 | on_failure: always 17 | deploy: 18 | provider: releases 19 | api_key: 20 | secure: k/DDoCfLXIct8TcGjekKm5CAoTL6Wy6LXhI74Ssgc8VSbjJQ1crO2J4V5HnQw7QplgAXwqjkoAUkzEJiz34wqBaAv0w9o8+5jPwCP6rMQ/VEvbn1MPI52KIFbYqKxmXe5J24B00BttbGc773ldXPnvmv+qPWWcXDTpcosni2laBt3z8bxCGVwkQ7nuQUaAelzs21wQuhjmKQ6F1dgNN5XhdJ5qgFYYM8cwiigvcqIaCwLMcrOs7gj22TS242pzp38etWhfxUbqUKejWgOH4qYeU3Tf5gsu4WV0otbqXYMvV18gVSoAiMnodDfYJUNHlfelCAEqebvECrIvvE8D0syuVYz6fh2/BrxZ6HeiYj1CXILghOjPUZZZ7/chKglWnA1vL+6Uxn5LtyTJ5gbgMYXvKQUXrRVZ3Zd9xrmv/YaMnGq+6BDBkS30aXpSK2X0HvW9/6JyQ9L1sjnKdOzDmagvikHm2rrPXBRMMfYTt4nucgUBWqJqyFe0uGva/n8TG5RzOzdOgRxFx/lF8XudtR4Z4gUBUFpve/meVHVVK82+cxzfN97aFdxvBzyGq18EDjOEpDi7k7mZjXUycvD8UZ7o12sxJ0Zr6/9esiFUsaqyE+2Vi6bMbgEHGx7hfWbdfREnpOtjFLH+u5mAPIqOh89a/UJ6SbYm0cON+ewTMUkJ8= 21 | file: mkspiffs-$TRAVIS_TAG-linux64.tar.gz 22 | on: 23 | repo: igrr/mkspiffs 24 | tags: true 25 | -------------------------------------------------------------------------------- /components/mkspiffs/src/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 | -------------------------------------------------------------------------------- /main/Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "Ymodem Example Configuration" 2 | 3 | config EXAMPLE_BAUDRATE 4 | int "Uart baudrate" 5 | range 38400 921600 6 | default 115200 7 | help 8 | Set the UART baudrate used in the example 9 | 10 | config SPIFFS_BASE_ADDR 11 | hex "SPIFFS Base address" 12 | range 0x100000 0x1FFE000 13 | default 0x180000 14 | help 15 | Starting address of the SPIFFS area in ESP32 Flash 16 | Write the address in hex format, 0x180000 17 | 18 | config SPIFFS_SIZE 19 | int "SPIFFS Size in bytes" 20 | range 262144 15728640 21 | default 1048576 22 | 23 | config SPIFFS_LOG_BLOCK_SIZE 24 | int "SPIFFS Logical block size" 25 | range 2048 65536 26 | default 4096 27 | 28 | config SPIFFS_LOG_PAGE_SIZE 29 | int "SPIFFS Logical page size" 30 | range 256 2048 31 | default 256 32 | help 33 | Set it to the phisycal page size og the used SPI Flash chip. 34 | 35 | config EXAMPLE_USE_WIFI 36 | bool "Use wifi in this example" 37 | default y 38 | help 39 | If WiFi is used ntp server will be used to provide the exact time 40 | and file timestamps will be correct. 41 | config WIFI_SSID 42 | string "WiFi SSID" 43 | depends on EXAMPLE_USE_WIFI 44 | default "myssid" 45 | help 46 | SSID (network name) for the example to connect to. 47 | 48 | config WIFI_PASSWORD 49 | string "WiFi Password" 50 | depends on EXAMPLE_USE_WIFI 51 | default "mypassword" 52 | help 53 | WiFi password (WPA or WPA2) for the example to use. 54 | 55 | 56 | endmenu 57 | -------------------------------------------------------------------------------- /components/mkspiffs/src/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 | -------------------------------------------------------------------------------- /components/mkspiffs/src/spiffs/esp_spiffs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Lua RTOS, write syscall implementation 3 | * 4 | * Copyright (C) 2015 - 2017 5 | * IBEROXARXA SERVICIOS INTEGRALES, S.L. & CSS IBÉRICA, S.L. 6 | * 7 | * Author: Jaume Olivé (jolive@iberoxarxa.com / jolive@whitecatboard.org) 8 | * 9 | * All rights reserved. 10 | * 11 | * Permission to use, copy, modify, and distribute this software 12 | * and its documentation for any purpose and without fee is hereby 13 | * granted, provided that the above copyright notice appear in all 14 | * copies and that both that the copyright notice and this 15 | * permission notice and warranty disclaimer appear in supporting 16 | * documentation, and that the name of the author not be used in 17 | * advertising or publicity pertaining to distribution of the 18 | * software without specific, written prior permission. 19 | * 20 | * The author disclaim all warranties with regard to this 21 | * software, including all implied warranties of merchantability 22 | * and fitness. In no event shall the author be liable for any 23 | * special, indirect or consequential damages or any damages 24 | * whatsoever resulting from loss of use, data or profits, whether 25 | * in an action of contract, negligence or other tortious action, 26 | * arising out of or in connection with the use or performance of 27 | * this software. 28 | */ 29 | 30 | #ifndef __ESP_SPIFFS_H__ 31 | #define __ESP_SPIFFS_H__ 32 | 33 | #include "spiffs.h" 34 | 35 | s32_t esp32_spi_flash_read(u32_t addr, u32_t size, u8_t *dst); 36 | s32_t esp32_spi_flash_write(u32_t addr, u32_t size, const u8_t *src); 37 | s32_t esp32_spi_flash_erase(u32_t addr, u32_t size); 38 | 39 | #define low_spiffs_read (spiffs_read *)esp32_spi_flash_read 40 | #define low_spiffs_write (spiffs_write *)esp32_spi_flash_write 41 | #define low_spiffs_erase (spiffs_erase *)esp32_spi_flash_erase 42 | 43 | #endif // __ESP_SPIFFS_H__ 44 | -------------------------------------------------------------------------------- /components/mkspiffs/src/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 | -------------------------------------------------------------------------------- /components/mkspiffs/src/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 | -------------------------------------------------------------------------------- /components/mkspiffs/src/README.md: -------------------------------------------------------------------------------- 1 | # mkspiffs 2 | Tool to build and unpack [SPIFFS](https://github.com/pellepl/spiffs) images. 3 | 4 | 5 | ## Usage 6 | 7 | ``` 8 | 9 | mkspiffs {-c |-u |-l|-i} [-d <0-5>] [-b ] 10 | [-p ] [-s ] [--] [--version] [-h] 11 | 12 | 13 | 14 | Where: 15 | 16 | -c , --create 17 | (OR required) create spiffs image from a directory 18 | -- OR -- 19 | -u , --unpack 20 | (OR required) unpack spiffs image to a directory 21 | -- OR -- 22 | -l, --list 23 | (OR required) list files in spiffs image 24 | -- OR -- 25 | -i, --visualize 26 | (OR required) visualize spiffs image 27 | 28 | 29 | -d <0-5>, --debug <0-5> 30 | Debug level. 0 means no debug output. 31 | 32 | -b , --block 33 | fs block size, in bytes 34 | 35 | -p , --page 36 | fs page size, in bytes 37 | 38 | -s , --size 39 | fs image size, in bytes 40 | 41 | --, --ignore_rest 42 | Ignores the rest of the labeled arguments following this flag. 43 | 44 | --version 45 | Displays version information and exits. 46 | 47 | -h, --help 48 | Displays usage information and exits. 49 | 50 | 51 | (required) spiffs image file 52 | 53 | 54 | ``` 55 | ## Build 56 | 57 | You need gcc (≥4.8) or clang(≥600.0.57), and make. On Windows, use MinGW. 58 | 59 | Run: 60 | ```bash 61 | $ make dist 62 | ``` 63 | 64 | ### Build status 65 | 66 | Linux | Windows 67 | ------|------- 68 | [![Linux build status](http://img.shields.io/travis/igrr/mkspiffs.svg)](https://travis-ci.org/igrr/mkspiffs) | [![Windows build status](http://img.shields.io/appveyor/ci/igrr/mkspiffs.svg)](https://ci.appveyor.com/project/igrr/mkspiffs) 69 | 70 | 71 | ## License 72 | 73 | MIT 74 | 75 | ## To do 76 | 77 | - [ ] Add more debug output and print SPIFFS debug output 78 | - [ ] Error handling 79 | - [ ] Determine the image size automatically when opening a file 80 | - [ ] Code cleanup 81 | -------------------------------------------------------------------------------- /components/mkspiffs/src/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 | -------------------------------------------------------------------------------- /components/mkspiffs/src/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 | -------------------------------------------------------------------------------- /components/mkspiffs/src/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 | -------------------------------------------------------------------------------- /components/mkspiffs/src/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS ?= -std=gnu99 -Os -Wall 2 | CXXFLAGS ?= -std=gnu++11 -Os -Wall 3 | 4 | ifeq ($(OS),Windows_NT) 5 | TARGET_OS := WINDOWS 6 | DIST_SUFFIX := windows 7 | ARCHIVE_CMD := 7z a 8 | ARCHIVE_EXTENSION := zip 9 | TARGET := mkspiffs.exe 10 | CC=gcc.exe 11 | CXX=g++.exe 12 | TARGET_CFLAGS := -mno-ms-bitfields 13 | TARGET_LDFLAGS := -Wl,-static -static-libgcc 14 | 15 | else 16 | UNAME_S := $(shell uname -s) 17 | ifeq ($(UNAME_S),Linux) 18 | TARGET_OS := LINUX 19 | UNAME_P := $(shell uname -p) 20 | ifeq ($(UNAME_P),x86_64) 21 | DIST_SUFFIX := linux64 22 | endif 23 | ifneq ($(filter %86,$(UNAME_P)),) 24 | DIST_SUFFIX := linux32 25 | endif 26 | CC=gcc 27 | CXX=g++ 28 | TARGET_CFLAGS = -std=gnu99 -Os -Wall -Itclap -Ispiffs -I. -D$(TARGET_OS) -DVERSION=\"$(VERSION)\" -D__NO_INLINE__ 29 | TARGET_CXXFLAGS = -std=gnu++11 -Os -Wall -Itclap -Ispiffs -I. -D$(TARGET_OS) -DVERSION=\"$(VERSION)\" -D__NO_INLINE__ 30 | endif 31 | ifeq ($(UNAME_S),Darwin) 32 | TARGET_OS := OSX 33 | DIST_SUFFIX := osx 34 | CC=clang 35 | CXX=clang++ 36 | TARGET_CFLAGS = -std=gnu99 -Os -Wall -Itclap -Ispiffs -I. -D$(TARGET_OS) -DVERSION=\"$(VERSION)\" -D__NO_INLINE__ -mmacosx-version-min=10.7 -arch x86_64 37 | TARGET_CXXFLAGS = -std=gnu++11 -Os -Wall -Itclap -Ispiffs -I. -D$(TARGET_OS) -DVERSION=\"$(VERSION)\" -D__NO_INLINE__ -mmacosx-version-min=10.7 -arch x86_64 -stdlib=libc++ 38 | TARGET_LDFLAGS = -arch x86_64 -stdlib=libc++ 39 | endif 40 | ARCHIVE_CMD := tar czf 41 | ARCHIVE_EXTENSION := tar.gz 42 | TARGET := mkspiffs 43 | endif 44 | 45 | OBJ := main.o \ 46 | spiffs/spiffs_cache.o \ 47 | spiffs/spiffs_check.o \ 48 | spiffs/spiffs_gc.o \ 49 | spiffs/spiffs_hydrogen.o \ 50 | spiffs/spiffs_nucleus.o \ 51 | 52 | VERSION ?= $(shell git describe --always) 53 | 54 | .PHONY: all clean 55 | 56 | all: $(TARGET) 57 | 58 | $(TARGET): 59 | @echo "Building mkspiffs ..." 60 | $(CC) $(TARGET_CFLAGS) -c spiffs/spiffs_cache.c -o spiffs/spiffs_cache.o 61 | $(CC) $(TARGET_CFLAGS) -c spiffs/spiffs_check.c -o spiffs/spiffs_check.o 62 | $(CC) $(TARGET_CFLAGS) -c spiffs/spiffs_gc.c -o spiffs/spiffs_gc.o 63 | $(CC) $(TARGET_CFLAGS) -c spiffs/spiffs_hydrogen.c -o spiffs/spiffs_hydrogen.o 64 | $(CC) $(TARGET_CFLAGS) -c spiffs/spiffs_nucleus.c -o spiffs/spiffs_nucleus.o 65 | $(CXX) $(TARGET_CXXFLAGS) -c main.cpp -o main.o 66 | $(CXX) $(TARGET_CFLAGS) -o $(TARGET) $(OBJ) $(TARGET_LDFLAGS) 67 | 68 | clean: 69 | @rm -f *.o 70 | @rm -f spiffs/*.o 71 | @rm -f $(TARGET) -------------------------------------------------------------------------------- /components/mkspiffs/src/Makefile.original: -------------------------------------------------------------------------------- 1 | CFLAGS ?= -std=gnu99 -Os -Wall 2 | CXXFLAGS ?= -std=gnu++11 -Os -Wall 3 | 4 | ifeq ($(OS),Windows_NT) 5 | TARGET_OS := WINDOWS 6 | DIST_SUFFIX := windows 7 | ARCHIVE_CMD := 7z a 8 | ARCHIVE_EXTENSION := zip 9 | TARGET := mkspiffs.exe 10 | TARGET_CFLAGS := -mno-ms-bitfields 11 | TARGET_LDFLAGS := -Wl,-static -static-libgcc 12 | 13 | else 14 | UNAME_S := $(shell uname -s) 15 | ifeq ($(UNAME_S),Linux) 16 | TARGET_OS := LINUX 17 | UNAME_P := $(shell uname -p) 18 | ifeq ($(UNAME_P),x86_64) 19 | DIST_SUFFIX := linux64 20 | endif 21 | ifneq ($(filter %86,$(UNAME_P)),) 22 | DIST_SUFFIX := linux32 23 | endif 24 | endif 25 | ifeq ($(UNAME_S),Darwin) 26 | TARGET_OS := OSX 27 | DIST_SUFFIX := osx 28 | CC=clang 29 | CXX=clang++ 30 | TARGET_CFLAGS = -mmacosx-version-min=10.7 -arch i386 -arch x86_64 31 | TARGET_CXXFLAGS = -mmacosx-version-min=10.7 -arch i386 -arch x86_64 -stdlib=libc++ 32 | TARGET_LDFLAGS = -arch i386 -arch x86_64 -stdlib=libc++ 33 | endif 34 | ARCHIVE_CMD := tar czf 35 | ARCHIVE_EXTENSION := tar.gz 36 | TARGET := mkspiffs 37 | endif 38 | 39 | VERSION ?= $(shell git describe --always) 40 | 41 | OBJ := main.o \ 42 | spiffs/spiffs_cache.o \ 43 | spiffs/spiffs_check.o \ 44 | spiffs/spiffs_gc.o \ 45 | spiffs/spiffs_hydrogen.o \ 46 | spiffs/spiffs_nucleus.o \ 47 | 48 | INCLUDES := -Itclap -Ispiffs -I. 49 | 50 | CFLAGS += $(TARGET_CFLAGS) 51 | CXXFLAGS += $(TARGET_CXXFLAGS) 52 | LDFLAGS += $(TARGET_LDFLAGS) 53 | 54 | CPPFLAGS += $(INCLUDES) -D$(TARGET_OS) -DVERSION=\"$(VERSION)\" -D__NO_INLINE__ 55 | 56 | DIST_NAME := mkspiffs-$(VERSION)-$(DIST_SUFFIX) 57 | DIST_DIR := $(DIST_NAME) 58 | DIST_ARCHIVE := $(DIST_NAME).$(ARCHIVE_EXTENSION) 59 | 60 | .PHONY: all clean dist 61 | 62 | all: $(TARGET) 63 | 64 | dist: test $(DIST_ARCHIVE) 65 | 66 | $(DIST_ARCHIVE): $(TARGET) $(DIST_DIR) 67 | cp $(TARGET) $(DIST_DIR)/ 68 | $(ARCHIVE_CMD) $(DIST_ARCHIVE) $(DIST_DIR) 69 | 70 | $(TARGET): $(OBJ) 71 | $(CXX) $^ -o $@ $(LDFLAGS) 72 | strip $(TARGET) 73 | 74 | $(DIST_DIR): 75 | @mkdir -p $@ 76 | 77 | clean: 78 | @rm -f *.o 79 | @rm -f spiffs/*.o 80 | @rm -f $(TARGET) 81 | 82 | SPIFFS_TEST_FS_CONFIG := -s 0x100000 -p 512 -b 0x2000 83 | 84 | test: $(TARGET) 85 | ls -1 spiffs > out.list0 86 | ./mkspiffs -c spiffs $(SPIFFS_TEST_FS_CONFIG) out.spiffs | sort | sed s/^\\/// > out.list1 87 | ./mkspiffs -u spiffs_u $(SPIFFS_TEST_FS_CONFIG) out.spiffs | sort | sed s/^\\/// > out.list_u 88 | ./mkspiffs -l $(SPIFFS_TEST_FS_CONFIG) out.spiffs | cut -f 2 | sort | sed s/^\\/// > out.list2 89 | diff --strip-trailing-cr out.list0 out.list1 90 | diff --strip-trailing-cr out.list0 out.list2 91 | diff spiffs spiffs_u 92 | rm -f out.{list0,list1,list2,list_u,spiffs} 93 | rm -R spiffs_u 94 | -------------------------------------------------------------------------------- /components/mkspiffs/src/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 | -------------------------------------------------------------------------------- /components/ymodem/ymodem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESP32 YModem driver 3 | * 4 | * Copyright (C) LoBo 2017 5 | * 6 | * Author: Boris Lovosevic (loboris@gmail.com) 7 | * 8 | * All rights reserved. 9 | * 10 | * Permission to use, copy, modify, and distribute this software 11 | * and its documentation for any purpose and without fee is hereby 12 | * granted, provided that the above copyright notice appear in all 13 | * copies and that both that the copyright notice and this 14 | * permission notice and warranty disclaimer appear in supporting 15 | * documentation, and that the name of the author not be used in 16 | * advertising or publicity pertaining to distribution of the 17 | * software without specific, written prior permission. 18 | * 19 | * The author disclaim all warranties with regard to this 20 | * software, including all implied warranties of merchantability 21 | * and fitness. In no event shall the author be liable for any 22 | * special, indirect or consequential damages or any damages 23 | * whatsoever resulting from loss of use, data or profits, whether 24 | * in an action of contract, negligence or other tortious action, 25 | * arising out of or in connection with the use or performance of 26 | * this software. 27 | */ 28 | 29 | 30 | #ifndef __YMODEM_H__ 31 | #define __YMODEM_H__ 32 | 33 | #include 34 | 35 | // === UART DEFINES ==== 36 | #define EX_UART_NUM UART_NUM_0 37 | #define BUF_SIZE (1080) 38 | 39 | // === LED pin used to show transfer activity === 40 | // === Set to 0 if you don't want to use it === 41 | #define YMODEM_LED_ACT 0 42 | #define YMODEM_LED_ACT_ON 1 // pin level for LED ON 43 | 44 | 45 | // ==== Y-MODEM defines ==== 46 | #define PACKET_SEQNO_INDEX (1) 47 | #define PACKET_SEQNO_COMP_INDEX (2) 48 | 49 | #define PACKET_HEADER (3) 50 | #define PACKET_TRAILER (2) 51 | #define PACKET_OVERHEAD (PACKET_HEADER + PACKET_TRAILER) 52 | #define PACKET_SIZE (128) 53 | #define PACKET_1K_SIZE (1024) 54 | 55 | #define FILE_SIZE_LENGTH (16) 56 | 57 | #define SOH (0x01) /* start of 128-byte data packet */ 58 | #define STX (0x02) /* start of 1024-byte data packet */ 59 | #define EOT (0x04) /* end of transmission */ 60 | #define ACK (0x06) /* acknowledge */ 61 | #define NAK (0x15) /* negative acknowledge */ 62 | #define CA (0x18) /* two of these in succession aborts transfer */ 63 | #define CRC16 (0x43) /* 'C' == 0x43, request 16-bit CRC */ 64 | 65 | #define ABORT1 (0x41) /* 'A' == 0x41, abort by user */ 66 | #define ABORT2 (0x61) /* 'a' == 0x61, abort by user */ 67 | 68 | #define NAK_TIMEOUT (1000) 69 | #define MAX_ERRORS (45) 70 | 71 | #define YM_MAX_FILESIZE (10*1024*1024) 72 | 73 | int Ymodem_Receive (FILE *ffd, unsigned int maxsize, char* getname); 74 | int Ymodem_Transmit (char* sendFileName, unsigned int sizeFile, FILE *ffd); 75 | 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /components/mkspiffs/src/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 | -------------------------------------------------------------------------------- /components/mkspiffs/src/spiffs/esp_spiffs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Lua RTOS, SPIFFS low access 3 | * 4 | * Copyright (C) 2015 - 2017 5 | * IBEROXARXA SERVICIOS INTEGRALES, S.L. & CSS IBÉRICA, S.L. 6 | * 7 | * Author: Jaume Olivé (jolive@iberoxarxa.com / jolive@whitecatboard.org) 8 | * 9 | * All rights reserved. 10 | * 11 | * Permission to use, copy, modify, and distribute this software 12 | * and its documentation for any purpose and without fee is hereby 13 | * granted, provided that the above copyright notice appear in all 14 | * copies and that both that the copyright notice and this 15 | * permission notice and warranty disclaimer appear in supporting 16 | * documentation, and that the name of the author not be used in 17 | * advertising or publicity pertaining to distribution of the 18 | * software without specific, written prior permission. 19 | * 20 | * The author disclaim all warranties with regard to this 21 | * software, including all implied warranties of merchantability 22 | * and fitness. In no event shall the author be liable for any 23 | * special, indirect or consequential damages or any damages 24 | * whatsoever resulting from loss of use, data or profits, whether 25 | * in an action of contract, negligence or other tortious action, 26 | * arising out of or in connection with the use or performance of 27 | * this software. 28 | */ 29 | 30 | #include 31 | 32 | #include "esp_spiffs.h" 33 | #include "esp_attr.h" 34 | 35 | #include "spiffs.h" 36 | 37 | #include 38 | 39 | s32_t esp32_spi_flash_read(u32_t addr, u32_t size, u8_t *dst) { 40 | u32_t aaddr; 41 | u8_t *buff = NULL; 42 | u8_t *abuff = NULL; 43 | u32_t asize; 44 | 45 | asize = size; 46 | 47 | // Align address to 4 byte 48 | aaddr = (addr + (4 - 1)) & (u32_t)-4; 49 | if (aaddr != addr) { 50 | aaddr -= 4; 51 | asize += (addr - aaddr); 52 | } 53 | 54 | // Align size to 4 byte 55 | asize = (asize + (4 - 1)) & (u32_t)-4; 56 | 57 | if ((aaddr != addr) || (asize != size)) { 58 | // Align buffer 59 | buff = malloc(asize + 4); 60 | if (!buff) { 61 | return SPIFFS_ERR_INTERNAL; 62 | } 63 | 64 | abuff = (u8_t *)(((ptrdiff_t)buff + (4 - 1)) & (u32_t)-4); 65 | 66 | if (spi_flash_read(aaddr, (void *)abuff, asize) != 0) { 67 | free(buff); 68 | return SPIFFS_ERR_INTERNAL; 69 | } 70 | 71 | memcpy(dst, abuff + (addr - aaddr), size); 72 | 73 | free(buff); 74 | } else { 75 | if (spi_flash_read(addr, (void *)dst, size) != 0) { 76 | return SPIFFS_ERR_INTERNAL; 77 | } 78 | } 79 | 80 | return SPIFFS_OK; 81 | } 82 | 83 | s32_t esp32_spi_flash_write(u32_t addr, u32_t size, const u8_t *src) { 84 | u32_t aaddr; 85 | u8_t *buff = NULL; 86 | u8_t *abuff = NULL; 87 | u32_t asize; 88 | 89 | asize = size; 90 | 91 | // Align address to 4 byte 92 | aaddr = (addr + (4 - 1)) & -4; 93 | if (aaddr != addr) { 94 | aaddr -= 4; 95 | asize += (addr - aaddr); 96 | } 97 | 98 | // Align size to 4 byte 99 | asize = (asize + (4 - 1)) & -4; 100 | 101 | if ((aaddr != addr) || (asize != size)) { 102 | // Align buffer 103 | buff = malloc(asize + 4); 104 | if (!buff) { 105 | return SPIFFS_ERR_INTERNAL; 106 | } 107 | 108 | abuff = (u8_t *)(((ptrdiff_t)buff + (4 - 1)) & -4); 109 | 110 | if (spi_flash_read(aaddr, (void *)abuff, asize) != 0) { 111 | free(buff); 112 | return SPIFFS_ERR_INTERNAL; 113 | } 114 | 115 | memcpy(abuff + (addr - aaddr), src, size); 116 | 117 | if (spi_flash_write(aaddr, (uint32_t *)abuff, asize) != 0) { 118 | free(buff); 119 | return SPIFFS_ERR_INTERNAL; 120 | } 121 | 122 | free(buff); 123 | } else { 124 | if (spi_flash_write(addr, (uint32_t *)src, size) != 0) { 125 | return SPIFFS_ERR_INTERNAL; 126 | } 127 | } 128 | 129 | return SPIFFS_OK; 130 | } 131 | 132 | s32_t IRAM_ATTR esp32_spi_flash_erase(u32_t addr, u32_t size) { 133 | if (spi_flash_erase_sector(addr >> 12) != 0) { 134 | return SPIFFS_ERR_INTERNAL; 135 | } 136 | 137 | return SPIFFS_OK; 138 | } 139 | -------------------------------------------------------------------------------- /components/mkspiffs/src/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 | -------------------------------------------------------------------------------- /components/mkspiffs/src/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 | -------------------------------------------------------------------------------- /components/mkspiffs/src/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 | -------------------------------------------------------------------------------- /components/mkspiffs/src/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 | -------------------------------------------------------------------------------- /components/mkspiffs/src/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 | -------------------------------------------------------------------------------- /components/mkspiffs/src/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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ### Example of using YModem protocol on ESP32 3 | 4 | --- 5 | 6 | 7 | #### Features 8 | 9 | * Enables **YModem** protocol file transfer over UART 10 | * Send and receive functions included 11 | * **Demo application** included 12 | * Used terminal application must support ymodem file transfer. Tested with **minicom** 13 | 14 | --- 15 | 16 | #### How to build 17 | 18 | Configure your esp32 build environment as for **esp-idf examples** 19 | 20 | Clone the repository 21 | 22 | `git clone https://github.com/loboris/ESP32_ymodem_example.git` 23 | 24 | Execute menuconfig and configure your Serial flash config and other settings. Included *sdkconfig.defaults* sets some defaults to be used. 25 | 26 | Navigate to **Ymodem example** and set **SPIFFS** options. 27 | 28 | Select if you want to use **wifi** (recommended) to get the time from **NTP** server and set your WiFi SSID and password. 29 | 30 | `make menuconfig` 31 | 32 | Make and flash the example. 33 | 34 | `make all && make flash` 35 | 36 | --- 37 | 38 | #### Prepare **SPIFFS** image 39 | 40 | *The example uses spiffs file system to receive and send files* 41 | 42 | The file system will be formated on first start, unless you flashed prepared spiffs image before the first start. 43 | 44 | --- 45 | 46 | You can prepare SFPIFFS **image** and flash it to ESP32. 47 | 48 | Files to be included on spiffs must be placed in **components/spiffs_image/image/** directory. You can add or remove the files you want to include. 49 | 50 | Then execute: 51 | 52 | `make makefs` 53 | 54 | to create **spiffs image** in *build* directory **without flashing** to ESP32 55 | 56 | Or execute: 57 | 58 | `make flashfs` 59 | 60 | to create **spiffs image** in *build* directory and **flash** it to ESP32 61 | 62 | --- 63 | 64 | To flash already prepared image **components/spiffs_image/spiffs_image.img** execute: 65 | 66 | `make copyfs` 67 | 68 | --- 69 | 70 | **Example output:** 71 | 72 | ``` 73 | 74 | I (1079) cpu_start: Pro cpu up. 75 | I (1091) cpu_start: Starting app cpu, entry point is 0x40080f18 76 | I (0) cpu_start: App cpu up. 77 | I (1124) heap_alloc_caps: Initializing. RAM available for dynamic allocation: 78 | I (1146) heap_alloc_caps: At 3FFAE2A0 len 00001D60 (7 KiB): DRAM 79 | I (1167) heap_alloc_caps: At 3FFB7AD8 len 00028528 (161 KiB): DRAM 80 | I (1188) heap_alloc_caps: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM 81 | I (1209) heap_alloc_caps: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM 82 | I (1231) heap_alloc_caps: At 40094980 len 0000B680 (45 KiB): IRAM 83 | I (1252) cpu_start: Pro cpu start user code 84 | I (1306) cpu_start: Starting scheduler on PRO CPU. 85 | I (197) cpu_start: Starting scheduler on APP CPU. 86 | I (197) uart: queue free spaces: 10 87 | I (197) [Ymodem example]: Time is not set yet. Connecting to WiFi and getting time over NTP. 88 | I (237) wifi: wifi firmware version: 9bf11be 89 | I (237) wifi: config NVS flash: enabled 90 | I (237) wifi: config nano formating: disabled 91 | I (237) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE 92 | I (247) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE 93 | I (277) wifi: Init dynamic tx buffer num: 32 94 | I (277) wifi: Init dynamic rx buffer num: 32 95 | I (277) wifi: wifi driver task: 3ffc3194, prio:23, stack:4096 96 | I (287) wifi: Init static rx buffer num: 10 97 | I (287) wifi: Init dynamic rx buffer num: 32 98 | I (287) wifi: Init rx ampdu len mblock:7 99 | I (297) wifi: Init lldesc rx ampdu entry mblock:4 100 | I (297) wifi: wifi power manager task: 0x3ffc855c prio: 21 stack: 2560 101 | I (307) [Ymodem example]: Setting WiFi configuration SSID LoBoInternet... 102 | I (317) wifi: wifi timer task: 3ffc95dc, prio:22, stack:3584 103 | I (337) phy: phy_version: 355.0, 2888565, May 23 2017, 16:12:06, 1, 0 104 | I (337) wifi: mode : sta (24:0a:c4:00:97:c0) 105 | I (467) wifi: n:1 0, o:1 0, ap:255 255, sta:1 0, prof:1 106 | I (1447) wifi: state: init -> auth (b0) 107 | I (1447) wifi: state: auth -> assoc (0) 108 | I (1447) wifi: state: assoc -> run (10) 109 | I (1487) wifi: connected with LoBoInternet, channel 1 110 | I (3697) event: ip: 192.168.0.16, mask: 255.255.255.0, gw: 192.168.0.1 111 | I (3697) [Ymodem example]: Initializing SNTP 112 | I (4197) [Ymodem example]: System time is set. 113 | I (4197) wifi: state: run -> init (0) 114 | I (4197) wifi: n:1 0, o:1 0, ap:255 255, sta:1 0, prof:1 115 | E (4197) wifi: esp_wifi_connect 816 wifi not start 116 | 117 | 118 | I (5197) [SPIFFS]: Registering SPIFFS file system 119 | I (5197) [SPIFFS]: Mounting SPIFFS files system 120 | I (5197) [SPIFFS]: Start address: 0x180000; Size 1024 KB 121 | I (5197) [SPIFFS]: Work buffer: 2048 B 122 | I (5207) [SPIFFS]: FDS buffer: 384 B 123 | I (5207) [SPIFFS]: Cache size: 2048 B 124 | I (5267) [SPIFFS]: Mounted 125 | I (5267) [Ymodem example]: File system mounted. 126 | Removed "/spiffs/yfile-1.bin" 127 | Removed "/spiffs/yfile-6.bin" 128 | LIST of DIR [/spiffs/] 129 | T Size Date/Time Name 130 | ----------------------------------- 131 | d - /spiffs 132 | d - 12/06/2017 15:09 images 133 | d - 12/06/2017 15:09 fonts 134 | f 405 12/06/2017 15:09 spiffs.info 135 | ----------------------------------- 136 | 405 in 1 file(s) 137 | ----------------------------------- 138 | SPIFFS: free 776 KB of 957 KB 139 | 140 | 141 | 142 | Receiving file, please start YModem transfer on host ... 143 | CCCCCCCCCCC 144 | I (41427) [Ymodem example]: Transfer complete, Size=97543, orig name: "/spiffs/yfile-1.bin" 145 | LIST of DIR [/spiffs/] 146 | T Size Date/Time Name 147 | ----------------------------------- 148 | f 97543 13/06/2017 14:20 yfile-1.bin 149 | ----------------------------------- 150 | 97543 in 1 file(s) 151 | ----------------------------------- 152 | SPIFFS: free 680 KB of 957 KB 153 | 154 | Sending file "/spiffs/yfile-1.bin", please start YModem receive on host ... 155 | CCCCC 156 | I (66667) [Ymodem example]: Transfer complete. 157 | 158 | ``` 159 | -------------------------------------------------------------------------------- /components/mkspiffs/src/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 | -------------------------------------------------------------------------------- /components/mkspiffs/src/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 | -------------------------------------------------------------------------------- /components/mkspiffs/src/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 | -------------------------------------------------------------------------------- /components/mkspiffs/src/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 | -------------------------------------------------------------------------------- /components/mkspiffs/src/spiffs/spiffs_cache.c: -------------------------------------------------------------------------------- 1 | /* 2 | * spiffs_cache.c 3 | * 4 | * Created on: Jun 23, 2013 5 | * Author: petera 6 | */ 7 | 8 | #include "spiffs.h" 9 | #include "spiffs_nucleus.h" 10 | 11 | #if SPIFFS_CACHE 12 | 13 | // returns cached page for give page index, or null if no such cached page 14 | static spiffs_cache_page *spiffs_cache_page_get(spiffs *fs, spiffs_page_ix pix) { 15 | spiffs_cache *cache = spiffs_get_cache(fs); 16 | if ((cache->cpage_use_map & cache->cpage_use_mask) == 0) return 0; 17 | int i; 18 | for (i = 0; i < cache->cpage_count; i++) { 19 | spiffs_cache_page *cp = spiffs_get_cache_page_hdr(fs, cache, i); 20 | if ((cache->cpage_use_map & (1<flags & SPIFFS_CACHE_FLAG_TYPE_WR) == 0 && 22 | cp->pix == pix ) { 23 | SPIFFS_CACHE_DBG("CACHE_GET: have cache page "_SPIPRIi" for "_SPIPRIpg"\n", i, pix); 24 | cp->last_access = cache->last_access; 25 | return cp; 26 | } 27 | } 28 | //SPIFFS_CACHE_DBG("CACHE_GET: no cache for "_SPIPRIpg"\n", pix); 29 | return 0; 30 | } 31 | 32 | // frees cached page 33 | static s32_t spiffs_cache_page_free(spiffs *fs, int ix, u8_t write_back) { 34 | s32_t res = SPIFFS_OK; 35 | spiffs_cache *cache = spiffs_get_cache(fs); 36 | spiffs_cache_page *cp = spiffs_get_cache_page_hdr(fs, cache, ix); 37 | if (cache->cpage_use_map & (1<flags & SPIFFS_CACHE_FLAG_TYPE_WR) == 0 && 40 | (cp->flags & SPIFFS_CACHE_FLAG_DIRTY)) { 41 | u8_t *mem = spiffs_get_cache_page(fs, cache, ix); 42 | res = SPIFFS_HAL_WRITE(fs, SPIFFS_PAGE_TO_PADDR(fs, cp->pix), SPIFFS_CFG_LOG_PAGE_SZ(fs), mem); 43 | } 44 | 45 | cp->flags = 0; 46 | cache->cpage_use_map &= ~(1 << ix); 47 | 48 | if (cp->flags & SPIFFS_CACHE_FLAG_TYPE_WR) { 49 | SPIFFS_CACHE_DBG("CACHE_FREE: free cache page "_SPIPRIi" objid "_SPIPRIid"\n", ix, cp->obj_id); 50 | } else { 51 | SPIFFS_CACHE_DBG("CACHE_FREE: free cache page "_SPIPRIi" pix "_SPIPRIpg"\n", ix, cp->pix); 52 | } 53 | } 54 | 55 | return res; 56 | } 57 | 58 | // removes the oldest accessed cached page 59 | static s32_t spiffs_cache_page_remove_oldest(spiffs *fs, u8_t flag_mask, u8_t flags) { 60 | s32_t res = SPIFFS_OK; 61 | spiffs_cache *cache = spiffs_get_cache(fs); 62 | 63 | if ((cache->cpage_use_map & cache->cpage_use_mask) != cache->cpage_use_mask) { 64 | // at least one free cpage 65 | return SPIFFS_OK; 66 | } 67 | 68 | // all busy, scan thru all to find the cpage which has oldest access 69 | int i; 70 | int cand_ix = -1; 71 | u32_t oldest_val = 0; 72 | for (i = 0; i < cache->cpage_count; i++) { 73 | spiffs_cache_page *cp = spiffs_get_cache_page_hdr(fs, cache, i); 74 | if ((cache->last_access - cp->last_access) > oldest_val && 75 | (cp->flags & flag_mask) == flags) { 76 | oldest_val = cache->last_access - cp->last_access; 77 | cand_ix = i; 78 | } 79 | } 80 | 81 | if (cand_ix >= 0) { 82 | res = spiffs_cache_page_free(fs, cand_ix, 1); 83 | } 84 | 85 | return res; 86 | } 87 | 88 | // allocates a new cached page and returns it, or null if all cache pages are busy 89 | static spiffs_cache_page *spiffs_cache_page_allocate(spiffs *fs) { 90 | spiffs_cache *cache = spiffs_get_cache(fs); 91 | if (cache->cpage_use_map == 0xffffffff) { 92 | // out of cache memory 93 | return 0; 94 | } 95 | int i; 96 | for (i = 0; i < cache->cpage_count; i++) { 97 | if ((cache->cpage_use_map & (1<cpage_use_map |= (1<last_access = cache->last_access; 101 | SPIFFS_CACHE_DBG("CACHE_ALLO: allocated cache page "_SPIPRIi"\n", i); 102 | return cp; 103 | } 104 | } 105 | // out of cache entries 106 | return 0; 107 | } 108 | 109 | // drops the cache page for give page index 110 | void spiffs_cache_drop_page(spiffs *fs, spiffs_page_ix pix) { 111 | spiffs_cache_page *cp = spiffs_cache_page_get(fs, pix); 112 | if (cp) { 113 | spiffs_cache_page_free(fs, cp->ix, 0); 114 | } 115 | } 116 | 117 | // ------------------------------ 118 | 119 | // reads from spi flash or the cache 120 | s32_t spiffs_phys_rd( 121 | spiffs *fs, 122 | u8_t op, 123 | spiffs_file fh, 124 | u32_t addr, 125 | u32_t len, 126 | u8_t *dst) { 127 | (void)fh; 128 | s32_t res = SPIFFS_OK; 129 | spiffs_cache *cache = spiffs_get_cache(fs); 130 | spiffs_cache_page *cp = spiffs_cache_page_get(fs, SPIFFS_PADDR_TO_PAGE(fs, addr)); 131 | cache->last_access++; 132 | if (cp) { 133 | // we've already got one, you see 134 | #if SPIFFS_CACHE_STATS 135 | fs->cache_hits++; 136 | #endif 137 | cp->last_access = cache->last_access; 138 | u8_t *mem = spiffs_get_cache_page(fs, cache, cp->ix); 139 | memcpy(dst, &mem[SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr)], len); 140 | } else { 141 | if ((op & SPIFFS_OP_TYPE_MASK) == SPIFFS_OP_T_OBJ_LU2) { 142 | // for second layer lookup functions, we do not cache in order to prevent shredding 143 | return SPIFFS_HAL_READ(fs, addr, len, dst); 144 | } 145 | #if SPIFFS_CACHE_STATS 146 | fs->cache_misses++; 147 | #endif 148 | // this operation will always free one cache page (unless all already free), 149 | // the result code stems from the write operation of the possibly freed cache page 150 | res = spiffs_cache_page_remove_oldest(fs, SPIFFS_CACHE_FLAG_TYPE_WR, 0); 151 | 152 | cp = spiffs_cache_page_allocate(fs); 153 | if (cp) { 154 | cp->flags = SPIFFS_CACHE_FLAG_WRTHRU; 155 | cp->pix = SPIFFS_PADDR_TO_PAGE(fs, addr); 156 | 157 | s32_t res2 = SPIFFS_HAL_READ(fs, 158 | addr - SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr), 159 | SPIFFS_CFG_LOG_PAGE_SZ(fs), 160 | spiffs_get_cache_page(fs, cache, cp->ix)); 161 | if (res2 != SPIFFS_OK) { 162 | // honor read failure before possible write failure (bad idea?) 163 | res = res2; 164 | } 165 | u8_t *mem = spiffs_get_cache_page(fs, cache, cp->ix); 166 | memcpy(dst, &mem[SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr)], len); 167 | } else { 168 | // this will never happen, last resort for sake of symmetry 169 | s32_t res2 = SPIFFS_HAL_READ(fs, addr, len, dst); 170 | if (res2 != SPIFFS_OK) { 171 | // honor read failure before possible write failure (bad idea?) 172 | res = res2; 173 | } 174 | } 175 | } 176 | return res; 177 | } 178 | 179 | // writes to spi flash and/or the cache 180 | s32_t spiffs_phys_wr( 181 | spiffs *fs, 182 | u8_t op, 183 | spiffs_file fh, 184 | u32_t addr, 185 | u32_t len, 186 | u8_t *src) { 187 | (void)fh; 188 | spiffs_page_ix pix = SPIFFS_PADDR_TO_PAGE(fs, addr); 189 | spiffs_cache *cache = spiffs_get_cache(fs); 190 | spiffs_cache_page *cp = spiffs_cache_page_get(fs, pix); 191 | 192 | if (cp && (op & SPIFFS_OP_COM_MASK) != SPIFFS_OP_C_WRTHRU) { 193 | // have a cache page 194 | // copy in data to cache page 195 | 196 | if ((op & SPIFFS_OP_COM_MASK) == SPIFFS_OP_C_DELE && 197 | (op & SPIFFS_OP_TYPE_MASK) != SPIFFS_OP_T_OBJ_LU) { 198 | // page is being deleted, wipe from cache - unless it is a lookup page 199 | spiffs_cache_page_free(fs, cp->ix, 0); 200 | return SPIFFS_HAL_WRITE(fs, addr, len, src); 201 | } 202 | 203 | u8_t *mem = spiffs_get_cache_page(fs, cache, cp->ix); 204 | memcpy(&mem[SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr)], src, len); 205 | 206 | cache->last_access++; 207 | cp->last_access = cache->last_access; 208 | 209 | if (cp->flags & SPIFFS_CACHE_FLAG_WRTHRU) { 210 | // page is being updated, no write-cache, just pass thru 211 | return SPIFFS_HAL_WRITE(fs, addr, len, src); 212 | } else { 213 | return SPIFFS_OK; 214 | } 215 | } else { 216 | // no cache page, no write cache - just write thru 217 | return SPIFFS_HAL_WRITE(fs, addr, len, src); 218 | } 219 | } 220 | 221 | #if SPIFFS_CACHE_WR 222 | // returns the cache page that this fd refers, or null if no cache page 223 | spiffs_cache_page *spiffs_cache_page_get_by_fd(spiffs *fs, spiffs_fd *fd) { 224 | spiffs_cache *cache = spiffs_get_cache(fs); 225 | 226 | if ((cache->cpage_use_map & cache->cpage_use_mask) == 0) { 227 | // all cpages free, no cpage cannot be assigned to obj_id 228 | return 0; 229 | } 230 | 231 | int i; 232 | for (i = 0; i < cache->cpage_count; i++) { 233 | spiffs_cache_page *cp = spiffs_get_cache_page_hdr(fs, cache, i); 234 | if ((cache->cpage_use_map & (1<flags & SPIFFS_CACHE_FLAG_TYPE_WR) && 236 | cp->obj_id == fd->obj_id) { 237 | return cp; 238 | } 239 | } 240 | 241 | return 0; 242 | } 243 | 244 | // allocates a new cache page and refers this to given fd - flushes an old cache 245 | // page if all cache is busy 246 | spiffs_cache_page *spiffs_cache_page_allocate_by_fd(spiffs *fs, spiffs_fd *fd) { 247 | // before this function is called, it is ensured that there is no already existing 248 | // cache page with same object id 249 | spiffs_cache_page_remove_oldest(fs, SPIFFS_CACHE_FLAG_TYPE_WR, 0); 250 | spiffs_cache_page *cp = spiffs_cache_page_allocate(fs); 251 | if (cp == 0) { 252 | // could not get cache page 253 | return 0; 254 | } 255 | 256 | cp->flags = SPIFFS_CACHE_FLAG_TYPE_WR; 257 | cp->obj_id = fd->obj_id; 258 | fd->cache_page = cp; 259 | return cp; 260 | } 261 | 262 | // unrefers all fds that this cache page refers to and releases the cache page 263 | void spiffs_cache_fd_release(spiffs *fs, spiffs_cache_page *cp) { 264 | if (cp == 0) return; 265 | u32_t i; 266 | spiffs_fd *fds = (spiffs_fd *)fs->fd_space; 267 | for (i = 0; i < fs->fd_count; i++) { 268 | spiffs_fd *cur_fd = &fds[i]; 269 | if (cur_fd->file_nbr != 0 && cur_fd->cache_page == cp) { 270 | cur_fd->cache_page = 0; 271 | } 272 | } 273 | spiffs_cache_page_free(fs, cp->ix, 0); 274 | 275 | cp->obj_id = 0; 276 | } 277 | 278 | #endif 279 | 280 | // initializes the cache 281 | void spiffs_cache_init(spiffs *fs) { 282 | if (fs->cache == 0) return; 283 | u32_t sz = fs->cache_size; 284 | u32_t cache_mask = 0; 285 | int i; 286 | int cache_entries = 287 | (sz - sizeof(spiffs_cache)) / (SPIFFS_CACHE_PAGE_SIZE(fs)); 288 | if (cache_entries <= 0) return; 289 | 290 | for (i = 0; i < cache_entries; i++) { 291 | cache_mask <<= 1; 292 | cache_mask |= 1; 293 | } 294 | 295 | spiffs_cache cache; 296 | memset(&cache, 0, sizeof(spiffs_cache)); 297 | cache.cpage_count = cache_entries; 298 | cache.cpages = (u8_t *)((u8_t *)fs->cache + sizeof(spiffs_cache)); 299 | 300 | cache.cpage_use_map = 0xffffffff; 301 | cache.cpage_use_mask = cache_mask; 302 | memcpy(fs->cache, &cache, sizeof(spiffs_cache)); 303 | 304 | spiffs_cache *c = spiffs_get_cache(fs); 305 | 306 | memset(c->cpages, 0, c->cpage_count * SPIFFS_CACHE_PAGE_SIZE(fs)); 307 | 308 | c->cpage_use_map &= ~(c->cpage_use_mask); 309 | for (i = 0; i < cache.cpage_count; i++) { 310 | spiffs_get_cache_page_hdr(fs, c, i)->ix = i; 311 | } 312 | } 313 | 314 | #endif // SPIFFS_CACHE 315 | -------------------------------------------------------------------------------- /components/spiffs/spiffs_cache.c: -------------------------------------------------------------------------------- 1 | /* 2 | * spiffs_cache.c 3 | * 4 | * Created on: Jun 23, 2013 5 | * Author: petera 6 | */ 7 | 8 | #include "spiffs.h" 9 | #include "spiffs_nucleus.h" 10 | 11 | #if SPIFFS_CACHE 12 | 13 | // returns cached page for give page index, or null if no such cached page 14 | static spiffs_cache_page *spiffs_cache_page_get(spiffs *fs, spiffs_page_ix pix) { 15 | spiffs_cache *cache = spiffs_get_cache(fs); 16 | if ((cache->cpage_use_map & cache->cpage_use_mask) == 0) return 0; 17 | int i; 18 | for (i = 0; i < cache->cpage_count; i++) { 19 | spiffs_cache_page *cp = spiffs_get_cache_page_hdr(fs, cache, i); 20 | if ((cache->cpage_use_map & (1<flags & SPIFFS_CACHE_FLAG_TYPE_WR) == 0 && 22 | cp->pix == pix ) { 23 | //SPIFFS_CACHE_DBG("CACHE_GET: have cache page "_SPIPRIi" for "_SPIPRIpg"\n", i, pix); 24 | cp->last_access = cache->last_access; 25 | return cp; 26 | } 27 | } 28 | //SPIFFS_CACHE_DBG("CACHE_GET: no cache for "_SPIPRIpg"\n", pix); 29 | return 0; 30 | } 31 | 32 | // frees cached page 33 | static s32_t spiffs_cache_page_free(spiffs *fs, int ix, u8_t write_back) { 34 | s32_t res = SPIFFS_OK; 35 | spiffs_cache *cache = spiffs_get_cache(fs); 36 | spiffs_cache_page *cp = spiffs_get_cache_page_hdr(fs, cache, ix); 37 | if (cache->cpage_use_map & (1<flags & SPIFFS_CACHE_FLAG_TYPE_WR) == 0 && 40 | (cp->flags & SPIFFS_CACHE_FLAG_DIRTY)) { 41 | u8_t *mem = spiffs_get_cache_page(fs, cache, ix); 42 | SPIFFS_CACHE_DBG("CACHE_FREE: write cache page "_SPIPRIi" pix "_SPIPRIpg"\n", ix, cp->pix); 43 | res = SPIFFS_HAL_WRITE(fs, SPIFFS_PAGE_TO_PADDR(fs, cp->pix), SPIFFS_CFG_LOG_PAGE_SZ(fs), mem); 44 | } 45 | 46 | #if SPIFFS_CACHE_WR 47 | if (cp->flags & SPIFFS_CACHE_FLAG_TYPE_WR) { 48 | SPIFFS_CACHE_DBG("CACHE_FREE: free cache page "_SPIPRIi" objid "_SPIPRIid"\n", ix, cp->obj_id); 49 | } else 50 | #endif 51 | { 52 | SPIFFS_CACHE_DBG("CACHE_FREE: free cache page "_SPIPRIi" pix "_SPIPRIpg"\n", ix, cp->pix); 53 | } 54 | cache->cpage_use_map &= ~(1 << ix); 55 | cp->flags = 0; 56 | } 57 | 58 | return res; 59 | } 60 | 61 | // removes the oldest accessed cached page 62 | static s32_t spiffs_cache_page_remove_oldest(spiffs *fs, u8_t flag_mask, u8_t flags) { 63 | s32_t res = SPIFFS_OK; 64 | spiffs_cache *cache = spiffs_get_cache(fs); 65 | 66 | if ((cache->cpage_use_map & cache->cpage_use_mask) != cache->cpage_use_mask) { 67 | // at least one free cpage 68 | return SPIFFS_OK; 69 | } 70 | 71 | // all busy, scan thru all to find the cpage which has oldest access 72 | int i; 73 | int cand_ix = -1; 74 | u32_t oldest_val = 0; 75 | for (i = 0; i < cache->cpage_count; i++) { 76 | spiffs_cache_page *cp = spiffs_get_cache_page_hdr(fs, cache, i); 77 | if ((cache->last_access - cp->last_access) > oldest_val && 78 | (cp->flags & flag_mask) == flags) { 79 | oldest_val = cache->last_access - cp->last_access; 80 | cand_ix = i; 81 | } 82 | } 83 | 84 | if (cand_ix >= 0) { 85 | res = spiffs_cache_page_free(fs, cand_ix, 1); 86 | } 87 | 88 | return res; 89 | } 90 | 91 | // allocates a new cached page and returns it, or null if all cache pages are busy 92 | static spiffs_cache_page *spiffs_cache_page_allocate(spiffs *fs) { 93 | spiffs_cache *cache = spiffs_get_cache(fs); 94 | if (cache->cpage_use_map == 0xffffffff) { 95 | // out of cache memory 96 | return 0; 97 | } 98 | int i; 99 | for (i = 0; i < cache->cpage_count; i++) { 100 | if ((cache->cpage_use_map & (1<cpage_use_map |= (1<last_access = cache->last_access; 104 | //SPIFFS_CACHE_DBG("CACHE_ALLO: allocated cache page "_SPIPRIi"\n", i); 105 | return cp; 106 | } 107 | } 108 | // out of cache entries 109 | return 0; 110 | } 111 | 112 | // drops the cache page for give page index 113 | void spiffs_cache_drop_page(spiffs *fs, spiffs_page_ix pix) { 114 | spiffs_cache_page *cp = spiffs_cache_page_get(fs, pix); 115 | if (cp) { 116 | spiffs_cache_page_free(fs, cp->ix, 0); 117 | } 118 | } 119 | 120 | // ------------------------------ 121 | 122 | // reads from spi flash or the cache 123 | s32_t spiffs_phys_rd( 124 | spiffs *fs, 125 | u8_t op, 126 | spiffs_file fh, 127 | u32_t addr, 128 | u32_t len, 129 | u8_t *dst) { 130 | (void)fh; 131 | s32_t res = SPIFFS_OK; 132 | spiffs_cache *cache = spiffs_get_cache(fs); 133 | spiffs_cache_page *cp = spiffs_cache_page_get(fs, SPIFFS_PADDR_TO_PAGE(fs, addr)); 134 | cache->last_access++; 135 | if (cp) { 136 | // we've already got one, you see 137 | #if SPIFFS_CACHE_STATS 138 | fs->cache_hits++; 139 | #endif 140 | cp->last_access = cache->last_access; 141 | u8_t *mem = spiffs_get_cache_page(fs, cache, cp->ix); 142 | _SPIFFS_MEMCPY(dst, &mem[SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr)], len); 143 | } else { 144 | if ((op & SPIFFS_OP_TYPE_MASK) == SPIFFS_OP_T_OBJ_LU2) { 145 | // for second layer lookup functions, we do not cache in order to prevent shredding 146 | return SPIFFS_HAL_READ(fs, addr, len, dst); 147 | } 148 | #if SPIFFS_CACHE_STATS 149 | fs->cache_misses++; 150 | #endif 151 | // this operation will always free one cache page (unless all already free), 152 | // the result code stems from the write operation of the possibly freed cache page 153 | res = spiffs_cache_page_remove_oldest(fs, SPIFFS_CACHE_FLAG_TYPE_WR, 0); 154 | 155 | cp = spiffs_cache_page_allocate(fs); 156 | if (cp) { 157 | cp->flags = SPIFFS_CACHE_FLAG_WRTHRU; 158 | cp->pix = SPIFFS_PADDR_TO_PAGE(fs, addr); 159 | SPIFFS_CACHE_DBG("CACHE_ALLO: allocated cache page "_SPIPRIi" for pix "_SPIPRIpg "\n", cp->ix, cp->pix); 160 | 161 | s32_t res2 = SPIFFS_HAL_READ(fs, 162 | addr - SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr), 163 | SPIFFS_CFG_LOG_PAGE_SZ(fs), 164 | spiffs_get_cache_page(fs, cache, cp->ix)); 165 | if (res2 != SPIFFS_OK) { 166 | // honor read failure before possible write failure (bad idea?) 167 | res = res2; 168 | } 169 | u8_t *mem = spiffs_get_cache_page(fs, cache, cp->ix); 170 | _SPIFFS_MEMCPY(dst, &mem[SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr)], len); 171 | } else { 172 | // this will never happen, last resort for sake of symmetry 173 | s32_t res2 = SPIFFS_HAL_READ(fs, addr, len, dst); 174 | if (res2 != SPIFFS_OK) { 175 | // honor read failure before possible write failure (bad idea?) 176 | res = res2; 177 | } 178 | } 179 | } 180 | return res; 181 | } 182 | 183 | // writes to spi flash and/or the cache 184 | s32_t spiffs_phys_wr( 185 | spiffs *fs, 186 | u8_t op, 187 | spiffs_file fh, 188 | u32_t addr, 189 | u32_t len, 190 | u8_t *src) { 191 | (void)fh; 192 | spiffs_page_ix pix = SPIFFS_PADDR_TO_PAGE(fs, addr); 193 | spiffs_cache *cache = spiffs_get_cache(fs); 194 | spiffs_cache_page *cp = spiffs_cache_page_get(fs, pix); 195 | 196 | if (cp && (op & SPIFFS_OP_COM_MASK) != SPIFFS_OP_C_WRTHRU) { 197 | // have a cache page 198 | // copy in data to cache page 199 | 200 | if ((op & SPIFFS_OP_COM_MASK) == SPIFFS_OP_C_DELE && 201 | (op & SPIFFS_OP_TYPE_MASK) != SPIFFS_OP_T_OBJ_LU) { 202 | // page is being deleted, wipe from cache - unless it is a lookup page 203 | spiffs_cache_page_free(fs, cp->ix, 0); 204 | return SPIFFS_HAL_WRITE(fs, addr, len, src); 205 | } 206 | 207 | u8_t *mem = spiffs_get_cache_page(fs, cache, cp->ix); 208 | _SPIFFS_MEMCPY(&mem[SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr)], src, len); 209 | 210 | cache->last_access++; 211 | cp->last_access = cache->last_access; 212 | 213 | if (cp->flags & SPIFFS_CACHE_FLAG_WRTHRU) { 214 | // page is being updated, no write-cache, just pass thru 215 | return SPIFFS_HAL_WRITE(fs, addr, len, src); 216 | } else { 217 | return SPIFFS_OK; 218 | } 219 | } else { 220 | // no cache page, no write cache - just write thru 221 | return SPIFFS_HAL_WRITE(fs, addr, len, src); 222 | } 223 | } 224 | 225 | #if SPIFFS_CACHE_WR 226 | // returns the cache page that this fd refers, or null if no cache page 227 | spiffs_cache_page *spiffs_cache_page_get_by_fd(spiffs *fs, spiffs_fd *fd) { 228 | spiffs_cache *cache = spiffs_get_cache(fs); 229 | 230 | if ((cache->cpage_use_map & cache->cpage_use_mask) == 0) { 231 | // all cpages free, no cpage cannot be assigned to obj_id 232 | return 0; 233 | } 234 | 235 | int i; 236 | for (i = 0; i < cache->cpage_count; i++) { 237 | spiffs_cache_page *cp = spiffs_get_cache_page_hdr(fs, cache, i); 238 | if ((cache->cpage_use_map & (1<flags & SPIFFS_CACHE_FLAG_TYPE_WR) && 240 | cp->obj_id == fd->obj_id) { 241 | return cp; 242 | } 243 | } 244 | 245 | return 0; 246 | } 247 | 248 | // allocates a new cache page and refers this to given fd - flushes an old cache 249 | // page if all cache is busy 250 | spiffs_cache_page *spiffs_cache_page_allocate_by_fd(spiffs *fs, spiffs_fd *fd) { 251 | // before this function is called, it is ensured that there is no already existing 252 | // cache page with same object id 253 | spiffs_cache_page_remove_oldest(fs, SPIFFS_CACHE_FLAG_TYPE_WR, 0); 254 | spiffs_cache_page *cp = spiffs_cache_page_allocate(fs); 255 | if (cp == 0) { 256 | // could not get cache page 257 | return 0; 258 | } 259 | 260 | cp->flags = SPIFFS_CACHE_FLAG_TYPE_WR; 261 | cp->obj_id = fd->obj_id; 262 | fd->cache_page = cp; 263 | SPIFFS_CACHE_DBG("CACHE_ALLO: allocated cache page "_SPIPRIi" for fd "_SPIPRIfd ":"_SPIPRIid "\n", cp->ix, fd->file_nbr, fd->obj_id); 264 | return cp; 265 | } 266 | 267 | // unrefers all fds that this cache page refers to and releases the cache page 268 | void spiffs_cache_fd_release(spiffs *fs, spiffs_cache_page *cp) { 269 | if (cp == 0) return; 270 | u32_t i; 271 | spiffs_fd *fds = (spiffs_fd *)fs->fd_space; 272 | for (i = 0; i < fs->fd_count; i++) { 273 | spiffs_fd *cur_fd = &fds[i]; 274 | if (cur_fd->file_nbr != 0 && cur_fd->cache_page == cp) { 275 | cur_fd->cache_page = 0; 276 | } 277 | } 278 | spiffs_cache_page_free(fs, cp->ix, 0); 279 | 280 | cp->obj_id = 0; 281 | } 282 | 283 | #endif 284 | 285 | // initializes the cache 286 | void spiffs_cache_init(spiffs *fs) { 287 | if (fs->cache == 0) return; 288 | u32_t sz = fs->cache_size; 289 | u32_t cache_mask = 0; 290 | int i; 291 | int cache_entries = 292 | (sz - sizeof(spiffs_cache)) / (SPIFFS_CACHE_PAGE_SIZE(fs)); 293 | if (cache_entries <= 0) return; 294 | 295 | for (i = 0; i < cache_entries; i++) { 296 | cache_mask <<= 1; 297 | cache_mask |= 1; 298 | } 299 | 300 | spiffs_cache cache; 301 | memset(&cache, 0, sizeof(spiffs_cache)); 302 | cache.cpage_count = cache_entries; 303 | cache.cpages = (u8_t *)((u8_t *)fs->cache + sizeof(spiffs_cache)); 304 | 305 | cache.cpage_use_map = 0xffffffff; 306 | cache.cpage_use_mask = cache_mask; 307 | _SPIFFS_MEMCPY(fs->cache, &cache, sizeof(spiffs_cache)); 308 | 309 | spiffs_cache *c = spiffs_get_cache(fs); 310 | 311 | memset(c->cpages, 0, c->cpage_count * SPIFFS_CACHE_PAGE_SIZE(fs)); 312 | 313 | c->cpage_use_map &= ~(c->cpage_use_mask); 314 | for (i = 0; i < cache.cpage_count; i++) { 315 | spiffs_get_cache_page_hdr(fs, c, i)->ix = i; 316 | } 317 | } 318 | 319 | #endif // SPIFFS_CACHE 320 | -------------------------------------------------------------------------------- /components/mkspiffs/src/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 | -------------------------------------------------------------------------------- /components/spiffs/spiffs_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * spiffs_config.h 3 | * 4 | * Created on: Jul 3, 2013 5 | * Author: petera 6 | */ 7 | 8 | #ifndef SPIFFS_CONFIG_H_ 9 | #define SPIFFS_CONFIG_H_ 10 | 11 | // ----------- 8< ------------ 12 | // Following includes are for the linux test build of spiffs 13 | // These may/should/must be removed/altered/replaced in your target 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | // ----------- >8 ------------ 22 | 23 | #include "freertos/FreeRTOS.h" 24 | #include "freertos/queue.h" 25 | #include "freertos/semphr.h" 26 | 27 | typedef signed int s32_t; 28 | typedef unsigned int u32_t; 29 | typedef signed short s16_t; 30 | typedef unsigned short u16_t; 31 | typedef signed char s8_t; 32 | typedef unsigned char u8_t; 33 | 34 | extern void spiffs_api_lock(void); 35 | extern void spiffs_api_unlock(void); 36 | 37 | // compile time switches 38 | 39 | // Set generic spiffs debug output call. 40 | #ifndef SPIFFS_DBG 41 | #define SPIFFS_DBG(...) //printf(__VA_ARGS__) 42 | #endif 43 | // Set spiffs debug output call for garbage collecting. 44 | #ifndef SPIFFS_GC_DBG 45 | #define SPIFFS_GC_DBG(...) //printf(__VA_ARGS__) 46 | #endif 47 | // Set spiffs debug output call for caching. 48 | #ifndef SPIFFS_CACHE_DBG 49 | #define SPIFFS_CACHE_DBG(...) //printf(__VA_ARGS__) 50 | #endif 51 | // Set spiffs debug output call for system consistency checks. 52 | #ifndef SPIFFS_CHECK_DBG 53 | #define SPIFFS_CHECK_DBG(...) //printf(__VA_ARGS__) 54 | #endif 55 | #define SPIFFS_API_DBG(...) 56 | 57 | 58 | // Defines spiffs debug print formatters 59 | // some general signed number 60 | #ifndef _SPIPRIi 61 | #define _SPIPRIi "%d" 62 | #endif 63 | // address 64 | #ifndef _SPIPRIad 65 | #define _SPIPRIad "%08x" 66 | #endif 67 | // block 68 | #ifndef _SPIPRIbl 69 | #define _SPIPRIbl "%04x" 70 | #endif 71 | // page 72 | #ifndef _SPIPRIpg 73 | #define _SPIPRIpg "%04x" 74 | #endif 75 | // span index 76 | #ifndef _SPIPRIsp 77 | #define _SPIPRIsp "%04x" 78 | #endif 79 | // file descriptor 80 | #ifndef _SPIPRIfd 81 | #define _SPIPRIfd "%d" 82 | #endif 83 | // file object id 84 | #ifndef _SPIPRIid 85 | #define _SPIPRIid "%04x" 86 | #endif 87 | // file flags 88 | #ifndef _SPIPRIfl 89 | #define _SPIPRIfl "%02x" 90 | #endif 91 | 92 | // Enable/disable API functions to determine exact number of bytes 93 | // for filedescriptor and cache buffers. Once decided for a configuration, 94 | // this can be disabled to reduce flash. 95 | #define SPIFFS_BUFFER_HELP 0 96 | 97 | // Enables/disable memory read caching of nucleus file system operations. 98 | // If enabled, memory area must be provided for cache in SPIFFS_mount. 99 | #define SPIFFS_CACHE 1 100 | 101 | #if SPIFFS_CACHE 102 | // Enables memory write caching for file descriptors in hydrogen 103 | #define SPIFFS_CACHE_WR 1 104 | 105 | // Enable/disable statistics on caching. Debug/test purpose only. 106 | #define SPIFFS_CACHE_STATS 0 107 | #endif 108 | 109 | // Always check header of each accessed page to ensure consistent state. 110 | // If enabled it will increase number of reads, will increase flash. 111 | #define SPIFFS_PAGE_CHECK 1 112 | 113 | // Define maximum number of gc runs to perform to reach desired free pages. 114 | #define SPIFFS_GC_MAX_RUNS 10 115 | 116 | // Enable/disable statistics on gc. Debug/test purpose only. 117 | #define SPIFFS_GC_STATS 0 118 | 119 | // Garbage collecting examines all pages in a block which and sums up 120 | // to a block score. Deleted pages normally gives positive score and 121 | // used pages normally gives a negative score (as these must be moved). 122 | // To have a fair wear-leveling, the erase age is also included in score, 123 | // whose factor normally is the most positive. 124 | // The larger the score, the more likely it is that the block will 125 | // picked for garbage collection. 126 | 127 | // Garbage collecting heuristics - weight used for deleted pages. 128 | #define SPIFFS_GC_HEUR_W_DELET (5) 129 | // Garbage collecting heuristics - weight used for used pages. 130 | #define SPIFFS_GC_HEUR_W_USED (-1) 131 | // Garbage collecting heuristics - weight used for time between 132 | // last erased and erase of this block. 133 | #define SPIFFS_GC_HEUR_W_ERASE_AGE (50) 134 | 135 | // Object name maximum length. Note that this length include the 136 | // zero-termination character, meaning maximum string of characters 137 | // can at most be SPIFFS_OBJ_NAME_LEN - 1. 138 | #define SPIFFS_OBJ_NAME_LEN (64) 139 | 140 | // Maximum length of the metadata associated with an object. 141 | // Setting to non-zero value enables metadata-related API but also 142 | // changes the on-disk format, so the change is not backward-compatible. 143 | // 144 | // Do note: the meta length must never exceed 145 | // logical_page_size - (SPIFFS_OBJ_NAME_LEN + 64) 146 | // 147 | // This is derived from following: 148 | // logical_page_size - (SPIFFS_OBJ_NAME_LEN + sizeof(spiffs_page_header) + 149 | // spiffs_object_ix_header fields + at least some LUT entries) 150 | #define SPIFFS_OBJ_META_LEN (16) 151 | 152 | // Size of buffer allocated on stack used when copying data. 153 | // Lower value generates more read/writes. No meaning having it bigger 154 | // than logical page size. 155 | #define SPIFFS_COPY_BUFFER_STACK (256) 156 | 157 | // Enable this to have an identifiable spiffs filesystem. This will look for 158 | // a magic in all sectors to determine if this is a valid spiffs system or 159 | // not on mount point. If not, SPIFFS_format must be called prior to mounting 160 | // again. 161 | #define SPIFFS_USE_MAGIC (1) 162 | 163 | #if SPIFFS_USE_MAGIC 164 | // Only valid when SPIFFS_USE_MAGIC is enabled. If SPIFFS_USE_MAGIC_LENGTH is 165 | // enabled, the magic will also be dependent on the length of the filesystem. 166 | // For example, a filesystem configured and formatted for 4 megabytes will not 167 | // be accepted for mounting with a configuration defining the filesystem as 2 168 | // megabytes. 169 | #define SPIFFS_USE_MAGIC_LENGTH (1) 170 | #endif 171 | 172 | // SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on api level 173 | // These should be defined on a multithreaded system 174 | 175 | // define this to enter a mutex if you're running on a multithreaded system 176 | #ifndef SPIFFS_LOCK 177 | //#define SPIFFS_LOCK(fs) xSemaphoreTake(spiffs_mutex, portMAX_DELAY) 178 | #define SPIFFS_LOCK(fs) spiffs_api_lock() 179 | #endif 180 | // define this to exit a mutex if you're running on a multithreaded system 181 | #ifndef SPIFFS_UNLOCK 182 | //#define SPIFFS_UNLOCK(fs) xSemaphoreGive(spiffs_mutex) 183 | #define SPIFFS_UNLOCK(fs) spiffs_api_unlock() 184 | #endif 185 | 186 | // Enable if only one spiffs instance with constant configuration will exist 187 | // on the target. This will reduce calculations, flash and memory accesses. 188 | // Parts of configuration must be defined below instead of at time of mount. 189 | #define SPIFFS_SINGLETON 0 190 | 191 | // Enable this if your target needs aligned data for index tables 192 | #define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 0 193 | 194 | // Enable this if you want the HAL callbacks to be called with the spiffs struct 195 | #define SPIFFS_HAL_CALLBACK_EXTRA 0 196 | 197 | // Enable this if you want to add an integer offset to all file handles 198 | // (spiffs_file). This is useful if running multiple instances of spiffs on 199 | // same target, in order to recognise to what spiffs instance a file handle 200 | // belongs. 201 | // NB: This adds config field fh_ix_offset in the configuration struct when 202 | // mounting, which must be defined. 203 | #define SPIFFS_FILEHDL_OFFSET 0 204 | 205 | // Enable this to compile a read only version of spiffs. 206 | // This will reduce binary size of spiffs. All code comprising modification 207 | // of the file system will not be compiled. Some config will be ignored. 208 | // HAL functions for erasing and writing to spi-flash may be null. Cache 209 | // can be disabled for even further binary size reduction (and ram savings). 210 | // Functions modifying the fs will return SPIFFS_ERR_RO_NOT_IMPL. 211 | // If the file system cannot be mounted due to aborted erase operation and 212 | // SPIFFS_USE_MAGIC is enabled, SPIFFS_ERR_RO_ABORTED_OPERATION will be 213 | // returned. 214 | // Might be useful for e.g. bootloaders and such. 215 | #define SPIFFS_READ_ONLY 0 216 | 217 | // Enable this to add a temporal file cache using the fd buffer. 218 | // The effects of the cache is that SPIFFS_open will find the file faster in 219 | // certain cases. It will make it a lot easier for spiffs to find files 220 | // opened frequently, reducing number of readings from the spi flash for 221 | // finding those files. 222 | // This will grow each fd by 6 bytes. If your files are opened in patterns 223 | // with a degree of temporal locality, the system is optimized. 224 | // Examples can be letting spiffs serve web content, where one file is the css. 225 | // The css is accessed for each html file that is opened, meaning it is 226 | // accessed almost every second time a file is opened. Another example could be 227 | // a log file that is often opened, written, and closed. 228 | // The size of the cache is number of given file descriptors, as it piggybacks 229 | // on the fd update mechanism. The cache lives in the closed file descriptors. 230 | // When closed, the fd know the whereabouts of the file. Instead of forgetting 231 | // this, the temporal cache will keep handling updates to that file even if the 232 | // fd is closed. If the file is opened again, the location of the file is found 233 | // directly. If all available descriptors become opened, all cache memory is 234 | // lost. 235 | #define SPIFFS_TEMPORAL_FD_CACHE 1 236 | 237 | // Temporal file cache hit score. Each time a file is opened, all cached files 238 | // will lose one point. If the opened file is found in cache, that entry will 239 | // gain SPIFFS_TEMPORAL_CACHE_HIT_SCORE points. One can experiment with this 240 | // value for the specific access patterns of the application. However, it must 241 | // be between 1 (no gain for hitting a cached entry often) and 255. 242 | #define SPIFFS_TEMPORAL_CACHE_HIT_SCORE 4 243 | 244 | // Enable to be able to map object indices to memory. 245 | // This allows for faster and more deterministic reading if cases of reading 246 | // large files and when changing file offset by seeking around a lot. 247 | // When mapping a file's index, the file system will be scanned for index pages 248 | // and the info will be put in memory provided by user. When reading, the 249 | // memory map can be looked up instead of searching for index pages on the 250 | // medium. This way, user can trade memory against performance. 251 | // Whole, parts of, or future parts not being written yet can be mapped. The 252 | // memory array will be owned by spiffs and updated accordingly during garbage 253 | // collecting or when modifying the indices. The latter is invoked by when the 254 | // file is modified in some way. The index buffer is tied to the file 255 | // descriptor. 256 | #define SPIFFS_IX_MAP 1 257 | 258 | // Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function 259 | // in the api. This function will visualize all filesystem using given printf 260 | // function. 261 | #define SPIFFS_TEST_VISUALISATION 0 262 | 263 | #if SPIFFS_TEST_VISUALISATION 264 | #ifndef spiffs_printf 265 | #define spiffs_printf(...) printf(__VA_ARGS__) 266 | #endif 267 | // spiffs_printf argument for a free page 268 | #ifndef SPIFFS_TEST_VIS_FREE_STR 269 | #define SPIFFS_TEST_VIS_FREE_STR "_" 270 | #endif 271 | // spiffs_printf argument for a deleted page 272 | #ifndef SPIFFS_TEST_VIS_DELE_STR 273 | #define SPIFFS_TEST_VIS_DELE_STR "/" 274 | #endif 275 | // spiffs_printf argument for an index page for given object id 276 | #ifndef SPIFFS_TEST_VIS_INDX_STR 277 | #define SPIFFS_TEST_VIS_INDX_STR(id) "i" 278 | #endif 279 | // spiffs_printf argument for a data page for given object id 280 | #ifndef SPIFFS_TEST_VIS_DATA_STR 281 | #define SPIFFS_TEST_VIS_DATA_STR(id) "d" 282 | #endif 283 | #endif 284 | 285 | // Types depending on configuration such as the amount of flash bytes 286 | // given to spiffs file system in total (spiffs_file_system_size), 287 | // the logical block size (log_block_size), and the logical page size 288 | // (log_page_size) 289 | 290 | // Block index type. Make sure the size of this type can hold 291 | // the highest number of all blocks - i.e. spiffs_file_system_size / log_block_size 292 | typedef u16_t spiffs_block_ix; 293 | // Page index type. Make sure the size of this type can hold 294 | // the highest page number of all pages - i.e. spiffs_file_system_size / log_page_size 295 | typedef u16_t spiffs_page_ix; 296 | // Object id type - most significant bit is reserved for index flag. Make sure the 297 | // size of this type can hold the highest object id on a full system, 298 | // i.e. 2 + (spiffs_file_system_size / (2*log_page_size))*2 299 | typedef u16_t spiffs_obj_id; 300 | // Object span index type. Make sure the size of this type can 301 | // hold the largest possible span index on the system - 302 | // i.e. (spiffs_file_system_size / log_page_size) - 1 303 | typedef u16_t spiffs_span_ix; 304 | 305 | #endif /* SPIFFS_CONFIG_H_ */ 306 | -------------------------------------------------------------------------------- /components/mkspiffs/src/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 | -------------------------------------------------------------------------------- /components/mkspiffs/src/spiffs/spiffs_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * spiffs_config.h 3 | * 4 | * Created on: Jul 3, 2013 5 | * Author: petera 6 | */ 7 | 8 | #ifndef SPIFFS_CONFIG_H_ 9 | #define SPIFFS_CONFIG_H_ 10 | 11 | // ----------- 8< ------------ 12 | // Following includes are for the linux test build of spiffs 13 | // These may/should/must be removed/altered/replaced in your target 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | // ----------- >8 ------------ 22 | 23 | typedef signed int s32_t; 24 | typedef unsigned int u32_t; 25 | typedef signed short s16_t; 26 | typedef unsigned short u16_t; 27 | typedef signed char s8_t; 28 | typedef unsigned char u8_t; 29 | 30 | // compile time switches 31 | 32 | // Set generic spiffs debug output call. 33 | #ifndef SPIFFS_DBG 34 | #define SPIFFS_DBG(...) //printf(__VA_ARGS__) 35 | #endif 36 | // Set spiffs debug output call for garbage collecting. 37 | #ifndef SPIFFS_GC_DBG 38 | #define SPIFFS_GC_DBG(...) //printf(__VA_ARGS__) 39 | #endif 40 | // Set spiffs debug output call for caching. 41 | #ifndef SPIFFS_CACHE_DBG 42 | #define SPIFFS_CACHE_DBG(...) //printf(__VA_ARGS__) 43 | #endif 44 | // Set spiffs debug output call for system consistency checks. 45 | #ifndef SPIFFS_CHECK_DBG 46 | #define SPIFFS_CHECK_DBG(...) //printf(__VA_ARGS__) 47 | #endif 48 | 49 | 50 | // Defines spiffs debug print formatters 51 | // some general signed number 52 | #ifndef _SPIPRIi 53 | #define _SPIPRIi "%d" 54 | #endif 55 | // address 56 | #ifndef _SPIPRIad 57 | #define _SPIPRIad "%08x" 58 | #endif 59 | // block 60 | #ifndef _SPIPRIbl 61 | #define _SPIPRIbl "%04x" 62 | #endif 63 | // page 64 | #ifndef _SPIPRIpg 65 | #define _SPIPRIpg "%04x" 66 | #endif 67 | // span index 68 | #ifndef _SPIPRIsp 69 | #define _SPIPRIsp "%04x" 70 | #endif 71 | // file descriptor 72 | #ifndef _SPIPRIfd 73 | #define _SPIPRIfd "%d" 74 | #endif 75 | // file object id 76 | #ifndef _SPIPRIid 77 | #define _SPIPRIid "%04x" 78 | #endif 79 | // file flags 80 | #ifndef _SPIPRIfl 81 | #define _SPIPRIfl "%02x" 82 | #endif 83 | 84 | // Enable/disable API functions to determine exact number of bytes 85 | // for filedescriptor and cache buffers. Once decided for a configuration, 86 | // this can be disabled to reduce flash. 87 | #ifndef SPIFFS_BUFFER_HELP 88 | #define SPIFFS_BUFFER_HELP 0 89 | #endif 90 | 91 | // Enables/disable memory read caching of nucleus file system operations. 92 | // If enabled, memory area must be provided for cache in SPIFFS_mount. 93 | #ifndef SPIFFS_CACHE 94 | #define SPIFFS_CACHE 1 95 | #endif 96 | #if SPIFFS_CACHE 97 | // Enables memory write caching for file descriptors in hydrogen 98 | #ifndef SPIFFS_CACHE_WR 99 | #define SPIFFS_CACHE_WR 1 100 | #endif 101 | 102 | // Enable/disable statistics on caching. Debug/test purpose only. 103 | #ifndef SPIFFS_CACHE_STATS 104 | #define SPIFFS_CACHE_STATS 0 105 | #endif 106 | #endif 107 | 108 | // Always check header of each accessed page to ensure consistent state. 109 | // If enabled it will increase number of reads, will increase flash. 110 | #ifndef SPIFFS_PAGE_CHECK 111 | #define SPIFFS_PAGE_CHECK 1 112 | #endif 113 | 114 | // Define maximum number of gc runs to perform to reach desired free pages. 115 | #ifndef SPIFFS_GC_MAX_RUNS 116 | #define SPIFFS_GC_MAX_RUNS 5 117 | #endif 118 | 119 | // Enable/disable statistics on gc. Debug/test purpose only. 120 | #ifndef SPIFFS_GC_STATS 121 | #define SPIFFS_GC_STATS 0 122 | #endif 123 | 124 | // Garbage collecting examines all pages in a block which and sums up 125 | // to a block score. Deleted pages normally gives positive score and 126 | // used pages normally gives a negative score (as these must be moved). 127 | // To have a fair wear-leveling, the erase age is also included in score, 128 | // whose factor normally is the most positive. 129 | // The larger the score, the more likely it is that the block will 130 | // picked for garbage collection. 131 | 132 | // Garbage collecting heuristics - weight used for deleted pages. 133 | #ifndef SPIFFS_GC_HEUR_W_DELET 134 | #define SPIFFS_GC_HEUR_W_DELET (5) 135 | #endif 136 | // Garbage collecting heuristics - weight used for used pages. 137 | #ifndef SPIFFS_GC_HEUR_W_USED 138 | #define SPIFFS_GC_HEUR_W_USED (-1) 139 | #endif 140 | // Garbage collecting heuristics - weight used for time between 141 | // last erased and erase of this block. 142 | #ifndef SPIFFS_GC_HEUR_W_ERASE_AGE 143 | #define SPIFFS_GC_HEUR_W_ERASE_AGE (50) 144 | #endif 145 | 146 | // Object name maximum length. Note that this length include the 147 | // zero-termination character, meaning maximum string of characters 148 | // can at most be SPIFFS_OBJ_NAME_LEN - 1. 149 | #ifndef SPIFFS_OBJ_NAME_LEN 150 | #define SPIFFS_OBJ_NAME_LEN (64) 151 | #endif 152 | 153 | // Maximum length of the metadata associated with an object. 154 | // Setting to non-zero value enables metadata-related API but also 155 | // changes the on-disk format, so the change is not backward-compatible. 156 | // 157 | // Do note: the meta length must never exceed 158 | // logical_page_size - (SPIFFS_OBJ_NAME_LEN + 64) 159 | // 160 | // This is derived from following: 161 | // logical_page_size - (SPIFFS_OBJ_NAME_LEN + sizeof(spiffs_page_header) + 162 | // spiffs_object_ix_header fields + at least some LUT entries) 163 | #ifndef SPIFFS_OBJ_META_LEN 164 | #define SPIFFS_OBJ_META_LEN (64) 165 | #endif 166 | 167 | // Size of buffer allocated on stack used when copying data. 168 | // Lower value generates more read/writes. No meaning having it bigger 169 | // than logical page size. 170 | #ifndef SPIFFS_COPY_BUFFER_STACK 171 | #define SPIFFS_COPY_BUFFER_STACK (256) 172 | #endif 173 | 174 | // Enable this to have an identifiable spiffs filesystem. This will look for 175 | // a magic in all sectors to determine if this is a valid spiffs system or 176 | // not on mount point. If not, SPIFFS_format must be called prior to mounting 177 | // again. 178 | #ifndef SPIFFS_USE_MAGIC 179 | #define SPIFFS_USE_MAGIC (1) 180 | #endif 181 | 182 | #if SPIFFS_USE_MAGIC 183 | // Only valid when SPIFFS_USE_MAGIC is enabled. If SPIFFS_USE_MAGIC_LENGTH is 184 | // enabled, the magic will also be dependent on the length of the filesystem. 185 | // For example, a filesystem configured and formatted for 4 megabytes will not 186 | // be accepted for mounting with a configuration defining the filesystem as 2 187 | // megabytes. 188 | #ifndef SPIFFS_USE_MAGIC_LENGTH 189 | #define SPIFFS_USE_MAGIC_LENGTH (1) 190 | #endif 191 | #endif 192 | 193 | // SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on api level 194 | // These should be defined on a multithreaded system 195 | 196 | // define this to enter a mutex if you're running on a multithreaded system 197 | #ifndef SPIFFS_LOCK 198 | #define SPIFFS_LOCK(fs) 199 | #endif 200 | // define this to exit a mutex if you're running on a multithreaded system 201 | #ifndef SPIFFS_UNLOCK 202 | #define SPIFFS_UNLOCK(fs) 203 | #endif 204 | 205 | // Enable if only one spiffs instance with constant configuration will exist 206 | // on the target. This will reduce calculations, flash and memory accesses. 207 | // Parts of configuration must be defined below instead of at time of mount. 208 | #ifndef SPIFFS_SINGLETON 209 | #define SPIFFS_SINGLETON 0 210 | #endif 211 | 212 | #if SPIFFS_SINGLETON 213 | // Instead of giving parameters in config struct, singleton build must 214 | // give parameters in defines below. 215 | #ifndef SPIFFS_CFG_PHYS_SZ 216 | #define SPIFFS_CFG_PHYS_SZ(ignore) (1024*1024*2) 217 | #endif 218 | #ifndef SPIFFS_CFG_PHYS_ERASE_SZ 219 | #define SPIFFS_CFG_PHYS_ERASE_SZ(ignore) (65536) 220 | #endif 221 | #ifndef SPIFFS_CFG_PHYS_ADDR 222 | #define SPIFFS_CFG_PHYS_ADDR(ignore) (0) 223 | #endif 224 | #ifndef SPIFFS_CFG_LOG_PAGE_SZ 225 | #define SPIFFS_CFG_LOG_PAGE_SZ(ignore) (256) 226 | #endif 227 | #ifndef SPIFFS_CFG_LOG_BLOCK_SZ 228 | #define SPIFFS_CFG_LOG_BLOCK_SZ(ignore) (65536) 229 | #endif 230 | #endif 231 | 232 | // Enable this if your target needs aligned data for index tables 233 | #ifndef SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 234 | #define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 1 235 | #endif 236 | 237 | // Enable this if you want the HAL callbacks to be called with the spiffs struct 238 | #ifndef SPIFFS_HAL_CALLBACK_EXTRA 239 | #define SPIFFS_HAL_CALLBACK_EXTRA 0 240 | #endif 241 | 242 | // Enable this if you want to add an integer offset to all file handles 243 | // (spiffs_file). This is useful if running multiple instances of spiffs on 244 | // same target, in order to recognise to what spiffs instance a file handle 245 | // belongs. 246 | // NB: This adds config field fh_ix_offset in the configuration struct when 247 | // mounting, which must be defined. 248 | #ifndef SPIFFS_FILEHDL_OFFSET 249 | #define SPIFFS_FILEHDL_OFFSET 0 250 | #endif 251 | 252 | // Enable this to compile a read only version of spiffs. 253 | // This will reduce binary size of spiffs. All code comprising modification 254 | // of the file system will not be compiled. Some config will be ignored. 255 | // HAL functions for erasing and writing to spi-flash may be null. Cache 256 | // can be disabled for even further binary size reduction (and ram savings). 257 | // Functions modifying the fs will return SPIFFS_ERR_RO_NOT_IMPL. 258 | // If the file system cannot be mounted due to aborted erase operation and 259 | // SPIFFS_USE_MAGIC is enabled, SPIFFS_ERR_RO_ABORTED_OPERATION will be 260 | // returned. 261 | // Might be useful for e.g. bootloaders and such. 262 | #ifndef SPIFFS_READ_ONLY 263 | #define SPIFFS_READ_ONLY 0 264 | #endif 265 | 266 | // Enable this to add a temporal file cache using the fd buffer. 267 | // The effects of the cache is that SPIFFS_open will find the file faster in 268 | // certain cases. It will make it a lot easier for spiffs to find files 269 | // opened frequently, reducing number of readings from the spi flash for 270 | // finding those files. 271 | // This will grow each fd by 6 bytes. If your files are opened in patterns 272 | // with a degree of temporal locality, the system is optimized. 273 | // Examples can be letting spiffs serve web content, where one file is the css. 274 | // The css is accessed for each html file that is opened, meaning it is 275 | // accessed almost every second time a file is opened. Another example could be 276 | // a log file that is often opened, written, and closed. 277 | // The size of the cache is number of given file descriptors, as it piggybacks 278 | // on the fd update mechanism. The cache lives in the closed file descriptors. 279 | // When closed, the fd know the whereabouts of the file. Instead of forgetting 280 | // this, the temporal cache will keep handling updates to that file even if the 281 | // fd is closed. If the file is opened again, the location of the file is found 282 | // directly. If all available descriptors become opened, all cache memory is 283 | // lost. 284 | #ifndef SPIFFS_TEMPORAL_FD_CACHE 285 | #define SPIFFS_TEMPORAL_FD_CACHE 1 286 | #endif 287 | 288 | // Temporal file cache hit score. Each time a file is opened, all cached files 289 | // will lose one point. If the opened file is found in cache, that entry will 290 | // gain SPIFFS_TEMPORAL_CACHE_HIT_SCORE points. One can experiment with this 291 | // value for the specific access patterns of the application. However, it must 292 | // be between 1 (no gain for hitting a cached entry often) and 255. 293 | #ifndef SPIFFS_TEMPORAL_CACHE_HIT_SCORE 294 | #define SPIFFS_TEMPORAL_CACHE_HIT_SCORE 8 295 | #endif 296 | 297 | // Enable to be able to map object indices to memory. 298 | // This allows for faster and more deterministic reading if cases of reading 299 | // large files and when changing file offset by seeking around a lot. 300 | // When mapping a file's index, the file system will be scanned for index pages 301 | // and the info will be put in memory provided by user. When reading, the 302 | // memory map can be looked up instead of searching for index pages on the 303 | // medium. This way, user can trade memory against performance. 304 | // Whole, parts of, or future parts not being written yet can be mapped. The 305 | // memory array will be owned by spiffs and updated accordingly during garbage 306 | // collecting or when modifying the indices. The latter is invoked by when the 307 | // file is modified in some way. The index buffer is tied to the file 308 | // descriptor. 309 | #ifndef SPIFFS_IX_MAP 310 | #define SPIFFS_IX_MAP 1 311 | #endif 312 | 313 | // Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function 314 | // in the api. This function will visualize all filesystem using given printf 315 | // function. 316 | #ifndef SPIFFS_TEST_VISUALISATION 317 | #define SPIFFS_TEST_VISUALISATION 0 318 | #endif 319 | #if SPIFFS_TEST_VISUALISATION 320 | #ifndef spiffs_printf 321 | #define spiffs_printf(...) printf(__VA_ARGS__) 322 | #endif 323 | // spiffs_printf argument for a free page 324 | #ifndef SPIFFS_TEST_VIS_FREE_STR 325 | #define SPIFFS_TEST_VIS_FREE_STR "_" 326 | #endif 327 | // spiffs_printf argument for a deleted page 328 | #ifndef SPIFFS_TEST_VIS_DELE_STR 329 | #define SPIFFS_TEST_VIS_DELE_STR "/" 330 | #endif 331 | // spiffs_printf argument for an index page for given object id 332 | #ifndef SPIFFS_TEST_VIS_INDX_STR 333 | #define SPIFFS_TEST_VIS_INDX_STR(id) "i" 334 | #endif 335 | // spiffs_printf argument for a data page for given object id 336 | #ifndef SPIFFS_TEST_VIS_DATA_STR 337 | #define SPIFFS_TEST_VIS_DATA_STR(id) "d" 338 | #endif 339 | #endif 340 | 341 | // Types depending on configuration such as the amount of flash bytes 342 | // given to spiffs file system in total (spiffs_file_system_size), 343 | // the logical block size (log_block_size), and the logical page size 344 | // (log_page_size) 345 | 346 | // Block index type. Make sure the size of this type can hold 347 | // the highest number of all blocks - i.e. spiffs_file_system_size / log_block_size 348 | typedef u16_t spiffs_block_ix; 349 | // Page index type. Make sure the size of this type can hold 350 | // the highest page number of all pages - i.e. spiffs_file_system_size / log_page_size 351 | typedef u16_t spiffs_page_ix; 352 | // Object id type - most significant bit is reserved for index flag. Make sure the 353 | // size of this type can hold the highest object id on a full system, 354 | // i.e. 2 + (spiffs_file_system_size / (2*log_page_size))*2 355 | typedef u16_t spiffs_obj_id; 356 | // Object span index type. Make sure the size of this type can 357 | // hold the largest possible span index on the system - 358 | // i.e. (spiffs_file_system_size / log_page_size) - 1 359 | typedef u16_t spiffs_span_ix; 360 | 361 | #endif /* SPIFFS_CONFIG_H_ */ 362 | --------------------------------------------------------------------------------