From 53bdc8a2876b57840010d5708b20dca3a46bcef5 Mon Sep 17 00:00:00 2001 From: Armaan Bhojwani <3fb650a9-b47e-4604-a282-1dd91953b2ee@anonaddy.me> Date: Tue, 27 Oct 2020 09:40:51 -0400 Subject: [PATCH] removed libshared dependency --- AUTHORS | 30 - README.md | 2 +- src/CMakeLists.txt | 31 +- src/diag.cpp | 132 - src/help.cpp | 38 - src/libshared/AUTHORS | 21 - src/libshared/CMakeLists.txt | 28 - src/libshared/LICENSE | 23 - src/libshared/cmake.h.in | 36 - src/libshared/cmake/CXXSniffer.cmake | 51 - src/libshared/src/Args.cpp | 246 -- src/libshared/src/Args.h | 68 - src/libshared/src/CMakeLists.txt | 65 - src/libshared/src/Color.cpp | 682 ----- src/libshared/src/Color.h | 78 - src/libshared/src/Composite.cpp | 148 - src/libshared/src/Composite.h | 47 - src/libshared/src/Configuration.cpp | 323 --- src/libshared/src/Configuration.h | 66 - src/libshared/src/Datetime.cpp | 3787 -------------------------- src/libshared/src/Datetime.h | 215 -- src/libshared/src/Duration.cpp | 552 ---- src/libshared/src/Duration.h | 81 - src/libshared/src/FS.cpp | 1025 ------- src/libshared/src/FS.h | 149 - src/libshared/src/JSON.cpp | 490 ---- src/libshared/src/JSON.h | 183 -- src/libshared/src/Lexer.cpp | 943 ------- src/libshared/src/Lexer.h | 119 - src/libshared/src/Log.cpp | 123 - src/libshared/src/Log.h | 56 - src/libshared/src/Msg.cpp | 115 - src/libshared/src/Msg.h | 54 - src/libshared/src/PEG.cpp | 436 --- src/libshared/src/PEG.h | 89 - src/libshared/src/Packrat.cpp | 770 ------ src/libshared/src/Packrat.h | 70 - src/libshared/src/Palette.cpp | 82 - src/libshared/src/Palette.h | 51 - src/libshared/src/Pig.cpp | 668 ----- src/libshared/src/Pig.h | 81 - src/libshared/src/README | 16 - src/libshared/src/RX.cpp | 159 -- src/libshared/src/RX.h | 58 - src/libshared/src/SAX.cpp | 579 ---- src/libshared/src/Table.cpp | 374 --- src/libshared/src/Table.h | 100 - src/libshared/src/Timer.cpp | 94 - src/libshared/src/Timer.h | 53 - src/libshared/src/Tree.cpp | 275 -- src/libshared/src/Tree.h | 76 - src/libshared/src/format.cpp | 353 --- src/libshared/src/format.h | 87 - src/libshared/src/ip.cpp | 237 -- src/libshared/src/lex.cpp | 20 - src/libshared/src/shared.cpp | 861 ------ src/libshared/src/shared.h | 95 - src/libshared/src/unicode.cpp | 133 - src/libshared/src/unicode.h | 39 - src/libshared/src/utf8.cpp | 295 -- src/libshared/src/utf8.h | 44 - src/libshared/src/wcwidth6.cpp | 211 -- src/main.cpp | 10 +- src/prompt.cpp | 6 - src/shell.cpp | 46 - 65 files changed, 16 insertions(+), 16459 deletions(-) delete mode 100644 AUTHORS delete mode 100644 src/diag.cpp delete mode 100644 src/help.cpp delete mode 100644 src/libshared/AUTHORS delete mode 100644 src/libshared/CMakeLists.txt delete mode 100644 src/libshared/LICENSE delete mode 100644 src/libshared/cmake.h.in delete mode 100644 src/libshared/cmake/CXXSniffer.cmake delete mode 100644 src/libshared/src/Args.cpp delete mode 100644 src/libshared/src/Args.h delete mode 100644 src/libshared/src/CMakeLists.txt delete mode 100644 src/libshared/src/Color.cpp delete mode 100644 src/libshared/src/Color.h delete mode 100644 src/libshared/src/Composite.cpp delete mode 100644 src/libshared/src/Composite.h delete mode 100644 src/libshared/src/Configuration.cpp delete mode 100644 src/libshared/src/Configuration.h delete mode 100644 src/libshared/src/Datetime.cpp delete mode 100644 src/libshared/src/Datetime.h delete mode 100644 src/libshared/src/Duration.cpp delete mode 100644 src/libshared/src/Duration.h delete mode 100644 src/libshared/src/FS.cpp delete mode 100644 src/libshared/src/FS.h delete mode 100644 src/libshared/src/JSON.cpp delete mode 100644 src/libshared/src/JSON.h delete mode 100644 src/libshared/src/Lexer.cpp delete mode 100644 src/libshared/src/Lexer.h delete mode 100644 src/libshared/src/Log.cpp delete mode 100644 src/libshared/src/Log.h delete mode 100644 src/libshared/src/Msg.cpp delete mode 100644 src/libshared/src/Msg.h delete mode 100644 src/libshared/src/PEG.cpp delete mode 100644 src/libshared/src/PEG.h delete mode 100644 src/libshared/src/Packrat.cpp delete mode 100644 src/libshared/src/Packrat.h delete mode 100644 src/libshared/src/Palette.cpp delete mode 100644 src/libshared/src/Palette.h delete mode 100644 src/libshared/src/Pig.cpp delete mode 100644 src/libshared/src/Pig.h delete mode 100644 src/libshared/src/README delete mode 100644 src/libshared/src/RX.cpp delete mode 100644 src/libshared/src/RX.h delete mode 100644 src/libshared/src/SAX.cpp delete mode 100644 src/libshared/src/Table.cpp delete mode 100644 src/libshared/src/Table.h delete mode 100644 src/libshared/src/Timer.cpp delete mode 100644 src/libshared/src/Timer.h delete mode 100644 src/libshared/src/Tree.cpp delete mode 100644 src/libshared/src/Tree.h delete mode 100644 src/libshared/src/format.cpp delete mode 100644 src/libshared/src/format.h delete mode 100644 src/libshared/src/ip.cpp delete mode 100644 src/libshared/src/lex.cpp delete mode 100644 src/libshared/src/shared.cpp delete mode 100644 src/libshared/src/shared.h delete mode 100644 src/libshared/src/unicode.cpp delete mode 100644 src/libshared/src/unicode.h delete mode 100644 src/libshared/src/utf8.cpp delete mode 100644 src/libshared/src/utf8.h delete mode 100644 src/libshared/src/wcwidth6.cpp delete mode 100644 src/shell.cpp diff --git a/AUTHORS b/AUTHORS deleted file mode 100644 index e05dce9..0000000 --- a/AUTHORS +++ /dev/null @@ -1,30 +0,0 @@ -Gen-shell is created by Armaan Bhojwani - -Tasksh was made by the following people: - The development of tasksh was made possible by the significant contributions of - the following people: - - Paul Beckingham (Principal Author) - Federico Hernandez (Principal Author) - Dirk Deimeke (Technical Advisor & Evangelist) - - The following submitted code, packages or analysis, and deserve special thanks: - - Jörg Krause - Ben Boeckel - ilove zfs - Paul Fenwick - - Thanks to the following, who submitted detailed bug reports and excellent - suggestions: - - Kevin Gunn - Fidel Mato - David Stahl - David Patrick - jonbobbly - hosaka - Lars Kumbier - Iain R. Learmonth - Eric Hymowitz - bjonnh diff --git a/README.md b/README.md index ead6bf4..72a4662 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # gen-shell ![Jenkins](https://img.shields.io/jenkins/build?jobUrl=https%3A%2F%2Fbuild.bhojwani.org%2Fjob%2Fgen-shell%2F) -A work in progress generic shell forked form [taskshell](https://github.com/GothenburgBitFactory/taskshell) +A work in progress generic shell. This is a very reduced fork of [taskshell](https://github.com/GothenburgBitFactory/taskshell) ## Installation Binaries can be downloaded [from here](https://build.bhojwani.org/job/gen-shell/lastSuccessfulBuild/artifact/build/src/gen-shell). Note that these binaries are compiled against libreadline7, so if your system only has libreadline8, you should symlink 8 to 7 with `sudo ln -s /usr/lib/x86_64-linux-gnu/libreadline.so.8.0 /usr/lib/x86_64-linux-gnu/libreadline.so.7`. This isn't a great solution, but it gets the job done. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d16e986..9d48f22 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,28 +4,25 @@ include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src/libshared/src ${TASKSH_INCLUDE_DIRS}) -set (tasksh_SRCS diag.cpp - help.cpp - prompt.cpp - shell.cpp) +set (tasksh_SRCS prompt.cpp) -set (libshared_SRCS libshared/src/Color.cpp libshared/src/Color.h - libshared/src/Datetime.cpp libshared/src/Datetime.h - libshared/src/Duration.cpp libshared/src/Duration.h - libshared/src/FS.cpp libshared/src/FS.h - libshared/src/Lexer.cpp libshared/src/Lexer.h - libshared/src/Pig.cpp libshared/src/Pig.h - libshared/src/shared.cpp libshared/src/shared.h - libshared/src/format.cpp libshared/src/format.h - libshared/src/unicode.cpp libshared/src/unicode.h - libshared/src/utf8.cpp libshared/src/utf8.h - libshared/src/wcwidth6.cpp) +# set (libshared_SRCS libshared/src/Color.cpp libshared/src/Color.h + # libshared/src/Datetime.cpp libshared/src/Datetime.h + # libshared/src/Duration.cpp libshared/src/Duration.h + # libshared/src/FS.cpp libshared/src/FS.h + # libshared/src/Lexer.cpp libshared/src/Lexer.h + # libshared/src/Pig.cpp libshared/src/Pig.h + # libshared/src/shared.cpp libshared/src/shared.h + # libshared/src/format.cpp libshared/src/format.h + # libshared/src/unicode.cpp libshared/src/unicode.h + # libshared/src/utf8.cpp libshared/src/utf8.h + # libshared/src/wcwidth6.cpp) add_library (tasksh STATIC ${tasksh_SRCS}) -add_library (libshared STATIC ${libshared_SRCS}) +# add_library (libshared STATIC ${libshared_SRCS}) add_executable (gen-sh_executable main.cpp) -target_link_libraries (gen-sh_executable tasksh libshared ${GEN-SHELL_LIBRARIES}) +target_link_libraries (gen-sh_executable tasksh ${GEN-SHELL_LIBRARIES}) set_property (TARGET gen-sh_executable PROPERTY OUTPUT_NAME "gen-shell") diff --git a/src/diag.cpp b/src/diag.cpp deleted file mode 100644 index 54c5184..0000000 --- a/src/diag.cpp +++ /dev/null @@ -1,132 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2006 - 2017, Paul Beckingham, Federico Hernandez, 2020 Armaan Bhojwani. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// -// http://www.opensource.org/licenses/mit-license.php -// -//////////////////////////////////////////////////////////////////////////////// - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_READLINE -#include -#include -#endif - -//////////////////////////////////////////////////////////////////////////////// -int cmdDiagnostics () -{ - Color bold ("bold"); - - std::cout << "\n" - << bold.colorize (PACKAGE_STRING) - << "\n" - << " " << "Platform: " << osName () - << "\n\n"; - - // Compiler. - std::cout << bold.colorize ("Compiler") - << "\n" -#ifdef __VERSION__ - << " " << "Version: " - << __VERSION__ << "\n" -#endif - << " " << "Caps:" -#ifdef __STDC__ - << " +stdc" -#endif -#ifdef __STDC_HOSTED__ - << " +stdc_hosted" -#endif -#ifdef __STDC_VERSION__ - << " +" << __STDC_VERSION__ -#endif -#ifdef _POSIX_VERSION - << " +" << _POSIX_VERSION -#endif -#ifdef _POSIX2_C_VERSION - << " +" << _POSIX2_C_VERSION -#endif -#ifdef _ILP32 - << " +ILP32" -#endif -#ifdef _LP64 - << " +LP64" -#endif - << " +c" << 8 * sizeof (char) - << " +i" << 8 * sizeof (int) - << " +l" << 8 * sizeof (long) - << " +vp" << 8 * sizeof (void*) - << " +time_t" << 8 * sizeof (time_t) - << "\n"; - - // Compiler compliance level. - std::cout << " Compliance: " - << cppCompliance () - << "\n\n"; - - std::cout << bold.colorize ("Build Features") - << "\n"; - - std::cout << "libreadline: " -#ifdef HAVE_READLINE -#ifdef RL_VERSION_MAJOR - << RL_VERSION_MAJOR << "." << RL_VERSION_MINOR -#elif defined RL_READLINE_VERSION - << "0x" << std::hex << RL_READLINE_VERSION -#endif -#else - << "n/a" -#endif - << "\n"; - - std::cout << " Build type: " -#ifdef CMAKE_BUILD_TYPE - << CMAKE_BUILD_TYPE -#else - << "-" -#endif - << "\n\n"; - - std::cout << bold.colorize ("Configuration") - << "\n"; - - auto env = getenv ("TASKRC"); - std::cout << " TASKRC: " - << (env ? env : "") - << "\n"; - - env = getenv ("TASKDATA"); - std::cout << " TASKDATA: " - << (env ? env : "") - << "\n"; -} - -//////////////////////////////////////////////////////////////////////////////// diff --git a/src/help.cpp b/src/help.cpp deleted file mode 100644 index be2ede2..0000000 --- a/src/help.cpp +++ /dev/null @@ -1,38 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2006 - 2017, Paul Beckingham, Federico Hernandez, 2020 Armaan Bhojwani. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// -// http://www.opensource.org/licenses/mit-license.php -// -//////////////////////////////////////////////////////////////////////////////// - -#include -#include - -//////////////////////////////////////////////////////////////////////////////// -int cmdHelp () -{ - std::cout << '\n' - << "A generic shell"; - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// diff --git a/src/libshared/AUTHORS b/src/libshared/AUTHORS deleted file mode 100644 index 8aab4e2..0000000 --- a/src/libshared/AUTHORS +++ /dev/null @@ -1,21 +0,0 @@ -The development of libshared was made possible by the significant contributions -of the following people: - - Paul Beckingham (Principal Author) - Federico Hernandez (Principal Author) - -The following submitted code, packages or analysis, and deserve special thanks: - - Lynoure Braakman - Jörg Krause - Ben Boeckel - Iain R. Learmonth - Toyam Cox - -Thanks to the following, who submitted detailed bug reports and excellent -suggestions: - - Sunil Joshi - Ellington Santos - Yury Vidineev - hosaka diff --git a/src/libshared/CMakeLists.txt b/src/libshared/CMakeLists.txt deleted file mode 100644 index c1fccb2..0000000 --- a/src/libshared/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -cmake_minimum_required (VERSION 2.8) -set (CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required -set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") -set (HAVE_CMAKE true) - -project (shared) -include (CXXSniffer) - -set (PROJECT_VERSION "1.0.0") - -set (PACKAGE "${PROJECT_NAME}") -set (VERSION "${PROJECT_VERSION}") -set (PACKAGE_BUGREPORT "support@taskwarrior.org") -set (PACKAGE_NAME "${PACKAGE}") -set (PACKAGE_TARNAME "${PACKAGE}") -set (PACKAGE_VERSION "${VERSION}") -set (PACKAGE_STRING "${PACKAGE} ${VERSION}") - -message ("-- Configuring cmake.h") -configure_file ( - ${CMAKE_SOURCE_DIR}/cmake.h.in - ${CMAKE_SOURCE_DIR}/cmake.h) - -add_subdirectory (src) -if (EXISTS ${CMAKE_SOURCE_DIR}/test) - add_subdirectory (test EXCLUDE_FROM_ALL) -endif (EXISTS ${CMAKE_SOURCE_DIR}/test) - diff --git a/src/libshared/LICENSE b/src/libshared/LICENSE deleted file mode 100644 index 4cd3104..0000000 --- a/src/libshared/LICENSE +++ /dev/null @@ -1,23 +0,0 @@ -libshared - -Copyright 2015 - 2017, Paul Beckingham, Federico Hernandez. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -http://www.opensource.org/licenses/mit-license.php diff --git a/src/libshared/cmake.h.in b/src/libshared/cmake.h.in deleted file mode 100644 index 92d4b9b..0000000 --- a/src/libshared/cmake.h.in +++ /dev/null @@ -1,36 +0,0 @@ -/* cmake.h.in. Creates cmake.h during a cmake run */ - -/* Package information */ -#define PACKAGE "${PACKAGE}" -#define VERSION "${VERSION}" -#define PACKAGE_BUGREPORT "${PACKAGE_BUGREPORT}" -#define PACKAGE_NAME "${PACKAGE_NAME}" -#define PACKAGE_TARNAME "${PACKAGE_TARNAME}" -#define PACKAGE_VERSION "${PACKAGE_VERSION}" -#define PACKAGE_STRING "${PACKAGE_STRING}" - -#define CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" - -/* Compiling platform */ -#cmakedefine LINUX -#cmakedefine DARWIN -#cmakedefine CYGWIN -#cmakedefine FREEBSD -#cmakedefine OPENBSD -#cmakedefine NETBSD -#cmakedefine SOLARIS -#cmakedefine KFREEBSD -#cmakedefine GNUHURD -#cmakedefine UNKNOWN - -/* Found tm.tm_gmtoff struct member */ -#cmakedefine HAVE_TM_GMTOFF - -/* Found st.st_birthtime struct member */ -#cmakedefine HAVE_ST_BIRTHTIME - -/* Functions */ -#cmakedefine HAVE_GET_CURRENT_DIR_NAME -#cmakedefine HAVE_TIMEGM -#cmakedefine HAVE_UUID_UNPARSE_LOWER - diff --git a/src/libshared/cmake/CXXSniffer.cmake b/src/libshared/cmake/CXXSniffer.cmake deleted file mode 100644 index cf6482a..0000000 --- a/src/libshared/cmake/CXXSniffer.cmake +++ /dev/null @@ -1,51 +0,0 @@ -message ("-- Configuring C++11") -message ("-- System: ${CMAKE_SYSTEM_NAME}") - -include (CheckCXXCompilerFlag) - -# NOTE: Phase out -std=gnu++0x and --std=c++0x as soon as realistically possible. -CHECK_CXX_COMPILER_FLAG("-std=c++11" _HAS_CXX11) -CHECK_CXX_COMPILER_FLAG("-std=c++0x" _HAS_CXX0X) -CHECK_CXX_COMPILER_FLAG("-std=gnu++0x" _HAS_GNU0X) - -if (_HAS_CXX11) - set (_CXX11_FLAGS "-std=c++11") -elseif (_HAS_CXX0X) - message (WARNING "Enabling -std=c++0x draft compile flag. Your compiler does not support the standard '-std=c++11' option. Consider upgrading.") - set (_CXX11_FLAGS "-std=c++0x") -elseif (_HAS_GNU0X) - message (WARNING "Enabling -std=gnu++0x draft compile flag. Your compiler does not support the standard '-std=c++11' option. Consider upgrading.") - set (_CXX11_FLAGS "-std=gnu++0x") -else (_HAS_CXX11) - message (FATAL_ERROR "C++11 support missing. Try upgrading your C++ compiler.") -endif (_HAS_CXX11) - -if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - set (LINUX true) -elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - set (DARWIN true) - set (_CXX11_FLAGS "${_CXX11_FLAGS} -stdlib=libc++") -elseif (${CMAKE_SYSTEM_NAME} MATCHES "kFreeBSD") - set (KFREEBSD true) -elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") - set (FREEBSD true) -elseif (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") - set (OPENBSD true) -elseif (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD") - set (NETBSD true) -elseif (${CMAKE_SYSTEM_NAME} MATCHES "SunOS") - set (SOLARIS true) -elseif (${CMAKE_SYSTEM_NAME} STREQUAL "GNU") - set (GNUHURD true) -elseif (${CMAKE_SYSTEM_NAME} STREQUAL "CYGWIN") - set (CYGWIN true) - # NOTE: Not setting -std=gnu++0x leads to compile errors even with - # GCC 4.8.3, and debugging those leads to insanity. Adding this - # workaround instead of fixing Cygwin. - set (_CXX11_FLAGS "-std=gnu++0x") -else (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - set (UNKNOWN true) -endif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - -set (CMAKE_CXX_FLAGS "${_CXX11_FLAGS} ${CMAKE_CXX_FLAGS}") -set (CMAKE_CXX_FLAGS "-Wall -Wextra -Wsign-compare -Wreturn-type ${CMAKE_CXX_FLAGS}") diff --git a/src/libshared/src/Args.cpp b/src/libshared/src/Args.cpp deleted file mode 100644 index 0c396f0..0000000 --- a/src/libshared/src/Args.cpp +++ /dev/null @@ -1,246 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2012 - 2017, Paul Beckingham, Federico Hernandez. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// -// http://www.opensource.org/licenses/mit-license.php -// -//////////////////////////////////////////////////////////////////////////////// - -#include -#include -#include -#include -#include - -//////////////////////////////////////////////////////////////////////////////// -void Args::addOption (const std::string& name, bool defaultValue) -{ - _options[name] = defaultValue; - _optionCount[name] = 0; -} - -//////////////////////////////////////////////////////////////////////////////// -void Args::addNamed (const std::string& name, const std::string& defaultValue) -{ - _named[name] = defaultValue; -} - -//////////////////////////////////////////////////////////////////////////////// -void Args::limitPositionals (int limit) -{ - _limit = limit; -} - -//////////////////////////////////////////////////////////////////////////////// -void Args::enableNegatives () -{ - _negatives = true; -} - -//////////////////////////////////////////////////////////////////////////////// -void Args::scan (int argc, const char** argv) -{ - for (int i = 1; i < argc; ++i) - { - // Is an option or named arg. - if (argv[i][0] == '-' && strlen (argv[i]) > 1) - { - auto name = ltrim (argv[i], "-"); - - std::string canonical; - if (canonicalizeOption (name, canonical)) - { - bool negated = _negatives && name.find ("no") == 0; - _options[canonical] = ! negated; - _optionCount[canonical]++; - } - - else if (canonicalizeNamed (name, canonical)) - { - if (i >= argc) - throw std::string ("Argument '" + canonical + "' has no value."); - - ++i; - _named[canonical] = argv[i]; - } - - else - throw std::string ("Unrecognized argument '" + name + "'."); - } - - // Or a positional. - else - { - _positionals.push_back (argv[i]); - if (_limit != -1 && - static_cast (_positionals.size ()) > _limit) - throw std::string ("Too many positional arguments."); - } - } -} - -//////////////////////////////////////////////////////////////////////////////// -bool Args::getOption (const std::string& name) const -{ - if (_options.find (name) == _options.end ()) - return false; - - return _options.at (name); -} - -//////////////////////////////////////////////////////////////////////////////// -int Args::getOptionCount (const std::string& name) const -{ - if (_optionCount.find (name) == _optionCount.end ()) - return false; - - return _optionCount.at (name); -} - -//////////////////////////////////////////////////////////////////////////////// -std::string Args::getNamed (const std::string& name) const -{ - if (_named.find (name) == _named.end ()) - return ""; - - return _named.at (name); -} - -//////////////////////////////////////////////////////////////////////////////// -int Args::getPositionalCount () const -{ - return static_cast (_positionals.size ()); -} - -//////////////////////////////////////////////////////////////////////////////// -std::string Args::getPositional (int n) const -{ - return _positionals.at (n); -} - -//////////////////////////////////////////////////////////////////////////////// -// Assuming "abc" is a declared option, support the following canonicalization: -// -// abc --> abc (exact match always canonicalizes) -// ab --> abc (if unique) -// a --> abc (if unique) -// noabc --> abc (exact negation match always canonicalizes) -// noab --> abc (if unique) -// noa --> abc (if unique) -// -bool Args::canonicalizeOption (const std::string& partial, std::string& canonical) const -{ - bool negated = _negatives && partial.find ("no") == 0; - - // Look for exact positive or negative matches first, which should succeed - // regardless of any longer partial matches. - if (_options.find (partial) != _options.end ()) - { - canonical = partial; - return true; - } - - if (negated && - _options.find (partial.substr (2)) != _options.end ()) - { - canonical = partial.substr (2); - return true; - } - - // Iterate over all options, and look for partial matches. If there is only - // one, we have canonicalization. - std::vector candidates; - for (const auto& option : _options) - { - if (option.first.find (partial) == 0 || - (negated && option.first.find (partial, 2) == 2)) - { - candidates.push_back (option.first); - } - } - - if (candidates.size () == 1) - { - canonical = candidates[0]; - return true; - } - - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -// Assuming "abc" is a declared name, support the following canonicalization: -// -// abc --> abc (exact match always canonicalizes) -// ab --> abc (if unique) -// a --> abc (if unique) -// -bool Args::canonicalizeNamed (const std::string& partial, std::string& canonical) const -{ - // Look for exact positive or negative matches first, which should succeed - // regardless of longer partial matches. - if (_named.find (partial) != _named.end ()) - { - canonical = partial; - return true; - } - - // Iterate over all options, and look for partial matches. If there is only - // one, we have canonicalization. - std::vector candidates; - for (const auto& name : _named) - if (name.first.find (partial) == 0) - candidates.push_back (name.first); - - if (candidates.size () == 1) - { - canonical = candidates[0]; - return true; - } - - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -std::string Args::dump () const -{ - std::stringstream out; - out << "Args\n" - << " Options\n"; - for (const auto& arg : _options) - out << " " << arg.first << " = " << arg.second << " (" << _optionCount.at (arg.first) << ")\n"; - - out << " Named\n"; - for (const auto& arg : _named) - out << " " << arg.first << " = " << arg.second << '\n'; - - out << " Positionals\n" - << " limit = " << _limit << '\n'; - for (const auto& arg : _positionals) - out << " " << arg << '\n'; - - out << " Negatives\n" - << " enabled = " << _negatives << '\n'; - - return out.str (); -} - -//////////////////////////////////////////////////////////////////////////////// diff --git a/src/libshared/src/Args.h b/src/libshared/src/Args.h deleted file mode 100644 index 84a0070..0000000 --- a/src/libshared/src/Args.h +++ /dev/null @@ -1,68 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2012 - 2017, Paul Beckingham, Federico Hernandez. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// -// http://www.opensource.org/licenses/mit-license.php -// -//////////////////////////////////////////////////////////////////////////////// - -#ifndef INCLUDED_ARGS -#define INCLUDED_ARGS - -#include -#include -#include - -class Args -{ -public: - Args () = default; - - void addOption (const std::string&, bool defaultValue = true); - void addNamed (const std::string&, const std::string& defaultValue = ""); - void limitPositionals (int); - void enableNegatives (); - - void scan (int, const char**); - - bool getOption (const std::string&) const; - int getOptionCount (const std::string&) const; - std::string getNamed (const std::string&) const; - int getPositionalCount () const; - std::string getPositional (int) const; - - std::string dump () const; - -private: - bool canonicalizeOption (const std::string&, std::string&) const; - bool canonicalizeNamed (const std::string&, std::string&) const; - -private: - std::map _options {}; - std::map _optionCount {}; - std::map _named {}; - std::vector _positionals {}; - int _limit {-1}; - bool _negatives {false}; -}; - -#endif - diff --git a/src/libshared/src/CMakeLists.txt b/src/libshared/src/CMakeLists.txt deleted file mode 100644 index 8b3ec70..0000000 --- a/src/libshared/src/CMakeLists.txt +++ /dev/null @@ -1,65 +0,0 @@ -cmake_minimum_required (VERSION 2.8) -include_directories (${CMAKE_SOURCE_DIR} - ${CMAKE_SOURCE_DIR}/src) - -set (shared_HEADERS Args.h - Color.h - Composite.h - Configuration.h - Datetime.h - Duration.h - FS.h - JSON.h - Lexer.h - Log.h - Msg.h - Packrat.h - Palette.h - PEG.h - Pig.h - RX.h - Table.h - Timer.h - Tree.h - shared.h - format.h - unicode.h - utf8.h) - -set (shared_SRCS Args.cpp - Color.cpp - Composite.cpp - Configuration.cpp - Datetime.cpp - Duration.cpp - FS.cpp - JSON.cpp - Lexer.cpp - Log.cpp - Msg.cpp - Packrat.cpp - Palette.cpp - PEG.cpp - Pig.cpp - RX.cpp - SAX.cpp - Table.cpp - Timer.cpp - Tree.cpp - format.cpp - ip.cpp - shared.cpp - unicode.cpp - utf8.cpp - wcwidth6.cpp - ${shared_HEADERS}) - -add_library (shared STATIC ${shared_SRCS}) - -set (CMAKE_INSTALL_LIBDIR lib CACHE PATH "Output directory for libraries") -install (TARGETS shared DESTINATION lib) -install (FILES ${shared_HEADERS} DESTINATION include) - -add_executable (lex_executable lex.cpp) -target_link_libraries (lex_executable shared) -set_property (TARGET lex_executable PROPERTY OUTPUT_NAME "lex") diff --git a/src/libshared/src/Color.cpp b/src/libshared/src/Color.cpp deleted file mode 100644 index 0673d81..0000000 --- a/src/libshared/src/Color.cpp +++ /dev/null @@ -1,682 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2006 - 2017, Paul Beckingham, Federico Hernandez. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// -// http://www.opensource.org/licenses/mit-license.php -// -//////////////////////////////////////////////////////////////////////////////// - -#include -#include -#include -#include -#include -#include -#include - -// uint to string lookup table for Color::_colorize() -// _colorize() gets called _a lot_, having this lookup table is a cheap -// performance optimization. -const char *colorstring[] = { - "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", - "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", - "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", - "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", - "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", - "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", - "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", - "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", - "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", - "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", - "100", "101", "102", "103", "104", "105", "106", "107", "108", "109", - "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", - "120", "121", "122", "123", "124", "125", "126", "127", "128", "129", - "130", "131", "132", "133", "134", "135", "136", "137", "138", "139", - "140", "141", "142", "143", "144", "145", "146", "147", "148", "149", - "150", "151", "152", "153", "154", "155", "156", "157", "158", "159", - "160", "161", "162", "163", "164", "165", "166", "167", "168", "169", - "170", "171", "172", "173", "174", "175", "176", "177", "178", "179", - "180", "181", "182", "183", "184", "185", "186", "187", "188", "189", - "190", "191", "192", "193", "194", "195", "196", "197", "198", "199", - "200", "201", "202", "203", "204", "205", "206", "207", "208", "209", - "210", "211", "212", "213", "214", "215", "216", "217", "218", "219", - "220", "221", "222", "223", "224", "225", "226", "227", "228", "229", - "230", "231", "232", "233", "234", "235", "236", "237", "238", "239", - "240", "241", "242", "243", "244", "245", "246", "247", "248", "249", - "250", "251", "252", "253", "254", "255" -}; - -//////////////////////////////////////////////////////////////////////////////// -static struct -{ - Color::color_id id; - std::string english_name; - int index; // offset red=3 (therefore fg=33, bg=43) -} allColors[] = -{ - // Color.h enum English Index - { Color::nocolor, "none", 0}, - { Color::black, "black", 1}, // fg 29+0 bg 39+0 - { Color::red, "red", 2}, - { Color::green, "green", 3}, - { Color::yellow, "yellow", 4}, - { Color::blue, "blue", 5}, - { Color::magenta, "magenta", 6}, - { Color::cyan, "cyan", 7}, - { Color::white, "white", 8}, - -}; - -#define NUM_COLORS (sizeof (allColors) / sizeof (allColors[0])) - -//////////////////////////////////////////////////////////////////////////////// -Color::Color () -: _value (0) -{ -} - -//////////////////////////////////////////////////////////////////////////////// -Color::Color (const Color& other) -{ - _value = other._value; -} - -//////////////////////////////////////////////////////////////////////////////// -Color::Color (unsigned int c) -: _value (0) -{ - if (!(c & _COLOR_HASFG)) _value &= ~_COLOR_FG; - if (!(c & _COLOR_HASBG)) _value &= ~_COLOR_BG; - - _value = c & (_COLOR_256 | _COLOR_HASBG | _COLOR_HASFG |_COLOR_UNDERLINE | - _COLOR_INVERSE | _COLOR_BOLD | _COLOR_BRIGHT | _COLOR_BG | - _COLOR_FG); -} - -//////////////////////////////////////////////////////////////////////////////// -// Supports the following constructs: -// [bright] [color] [on color] [bright] [underline] -// -// Where [color] is one of: -// black -// red -// ... -// grayN 0 <= N <= 23 fg 38;5;232 + N bg 48;5;232 + N -// greyN 0 <= N <= 23 fg 38;5;232 + N bg 48;5;232 + N -// colorN 0 <= N <= 255 fg 38;5;N bg 48;5;N -// rgbRGB 0 <= R,G,B <= 5 fg 38;5;16 + R*36 + G*6 + B bg 48;5;16 + R*36 + G*6 + B -Color::Color (const std::string& spec) -: _value (0) -{ - // Split spec into words. - auto words = split (spec, ' '); - - // Construct the color as two separate colors, then blend them later. This - // make it possible to declare a color such as "color1 on black", and have - // the upgrade work properly. - unsigned int fg_value = 0; - unsigned int bg_value = 0; - - bool bg = false; - int index; - for (auto& word : words) - { - word = lowerCase (trim (word)); - - if (word == "bold") fg_value |= _COLOR_BOLD; - else if (word == "bright") bg_value |= _COLOR_BRIGHT; - else if (word == "underline") fg_value |= _COLOR_UNDERLINE; - else if (word == "inverse") fg_value |= _COLOR_INVERSE; - else if (word == "on") bg = true; - - // X where X is one of black, red, blue ... - else if ((index = find (word)) != -1) - { - if (index) - { - if (bg) - { - bg_value |= _COLOR_HASBG; - bg_value |= index << 8; - } - else - { - fg_value |= _COLOR_HASFG; - fg_value |= index; - } - } - } - - // greyN/grayN, where 0 <= N <= 23. - else if (! word.compare (0, 4, "grey", 4) || - ! word.compare (0, 4, "gray", 4)) - { - index = strtol (word.substr (4).c_str (), nullptr, 10); - if (index < 0 || index > 23) - throw format ("The color '{1}' is not recognized.", word); - - if (bg) - { - bg_value |= _COLOR_HASBG; - bg_value |= (index + 232) << 8; - bg_value |= _COLOR_256; - } - else - { - fg_value |= _COLOR_HASFG; - fg_value |= index + 232; - fg_value |= _COLOR_256; - } - } - - // rgbRGB, where 0 <= R,G,B <= 5. - else if (! word.compare (0, 3, "rgb", 3)) - { - index = strtol (word.substr (3).c_str (), nullptr, 10); - if (word.length () != 6 || - index < 0 || index > 555) - throw format ("The color '{1}' is not recognized.", word); - - int r = strtol (word.substr (3, 1).c_str (), nullptr, 10); - int g = strtol (word.substr (4, 1).c_str (), nullptr, 10); - int b = strtol (word.substr (5, 1).c_str (), nullptr, 10); - if (r < 0 || r > 5 || - g < 0 || g > 5 || - b < 0 || b > 5) - throw format ("The color '{1}' is not recognized.", word); - - index = 16 + r*36 + g*6 + b; - - if (bg) - { - bg_value |= _COLOR_HASBG; - bg_value |= index << 8; - bg_value |= _COLOR_256; - } - else - { - fg_value |= _COLOR_HASFG; - fg_value |= index; - fg_value |= _COLOR_256; - } - } - - // colorN, where 0 <= N <= 255. - else if (! word.compare (0, 5, "color", 5)) - { - index = strtol (word.substr (5).c_str (), nullptr, 10); - if (index < 0 || index > 255) - throw format ("The color '{1}' is not recognized.", word); - - upgrade (); - - if (bg) - { - bg_value |= _COLOR_HASBG; - bg_value |= index << 8; - bg_value |= _COLOR_256; - } - else - { - fg_value |= _COLOR_HASFG; - fg_value |= index; - fg_value |= _COLOR_256; - } - } - else if (word != "") - throw format ("The color '{1}' is not recognized.", word); - } - - // Now combine the fg and bg into a single color. - _value = fg_value; - blend (Color (bg_value)); -} - -//////////////////////////////////////////////////////////////////////////////// -Color::Color (color_id fg) -: _value (0) -{ - if (fg != Color::nocolor) - { - _value |= _COLOR_HASFG; - _value |= fg; - } -} - -//////////////////////////////////////////////////////////////////////////////// -Color::Color (color_id fg, color_id bg, bool underline, bool bold, bool bright) -: _value (0) -{ - _value |= ((underline ? 1 : 0) << 18) - | ((bold ? 1 : 0) << 17) - | ((bright ? 1 : 0) << 16); - - if (bg != Color::nocolor) - { - _value |= _COLOR_HASBG; - _value |= (bg << 8); - } - - if (fg != Color::nocolor) - { - _value |= _COLOR_HASFG; - _value |= fg; - } -} - -//////////////////////////////////////////////////////////////////////////////// -Color::operator std::string () const -{ - std::string description; - if (_value & _COLOR_BOLD) description += "bold"; - - if (_value & _COLOR_UNDERLINE) - description += std::string (description.length () ? " " : "") + "underline"; - - if (_value & _COLOR_INVERSE) - description += std::string (description.length () ? " " : "") + "inverse"; - - if (_value & _COLOR_HASFG) - description += std::string (description.length () ? " " : "") + fg (); - - if (_value & _COLOR_HASBG) - { - description += std::string (description.length () ? " " : "") + "on"; - - if (_value & _COLOR_BRIGHT) - description += std::string (description.length () ? " " : "") + "bright"; - - description += " " + bg (); - } - - return description; -} - -//////////////////////////////////////////////////////////////////////////////// -Color::operator int () const -{ - return (int) _value; -} - -//////////////////////////////////////////////////////////////////////////////// -// If 'other' has styles that are compatible, merge them into this. Colors in -// other take precedence. -void Color::blend (const Color& other) -{ - if (!other.nontrivial ()) - return; - - Color c (other); - _value |= (c._value & _COLOR_UNDERLINE); // Always inherit underline. - _value |= (c._value & _COLOR_INVERSE); // Always inherit inverse. - - // 16 <-- 16. - if (!(_value & _COLOR_256) && - !(c._value & _COLOR_256)) - { - _value |= (c._value & _COLOR_BOLD); // Inherit bold. - _value |= (c._value & _COLOR_BRIGHT); // Inherit bright. - - if (c._value & _COLOR_HASFG) - { - _value |= _COLOR_HASFG; // There is now a color. - _value &= ~_COLOR_FG; // Remove previous color. - _value |= (c._value & _COLOR_FG); // Apply other color. - } - - if (c._value & _COLOR_HASBG) - { - _value |= _COLOR_HASBG; // There is now a color. - _value &= ~_COLOR_BG; // Remove previous color. - _value |= (c._value & _COLOR_BG); // Apply other color. - } - - return; - } - else - { - // Upgrade either color, if necessary. - if (!(_value & _COLOR_256)) upgrade (); - if (!(c._value & _COLOR_256)) c.upgrade (); - - // 256 <-- 256. - if (c._value & _COLOR_HASFG) - { - _value |= _COLOR_HASFG; // There is now a color. - _value &= ~_COLOR_FG; // Remove previous color. - _value |= (c._value & _COLOR_FG); // Apply other color. - } - - if (c._value & _COLOR_HASBG) - { - _value |= _COLOR_HASBG; // There is now a color. - _value &= ~_COLOR_BG; // Remove previous color. - _value |= (c._value & _COLOR_BG); // Apply other color. - } - } -} - -//////////////////////////////////////////////////////////////////////////////// -void Color::upgrade () -{ - if (!(_value & _COLOR_256)) - { - if (_value & _COLOR_HASFG) - { - bool bold = _value & _COLOR_BOLD; - unsigned int fg = _value & _COLOR_FG; - _value &= ~_COLOR_FG; - _value &= ~_COLOR_BOLD; - _value |= (bold ? fg + 7 : fg - 1); - } - - if (_value & _COLOR_HASBG) - { - bool bright = _value & _COLOR_BRIGHT; - unsigned int bg = (_value & _COLOR_BG) >> 8; - _value &= ~_COLOR_BG; - _value &= ~_COLOR_BRIGHT; - _value |= (bright ? bg + 7 : bg - 1) << 8; - } - - _value |= _COLOR_256; - } -} - -//////////////////////////////////////////////////////////////////////////////// -std::string Color::colorize (const std::string& input) const -{ - std::string result; - _colorize (result, input); - return result; -} - -//////////////////////////////////////////////////////////////////////////////// -// Sample color codes: -// red \033[31m -// bold red \033[91m -// underline red \033[4;31m -// bold underline red \033[1;4;31m -// -// on red \033[41m -// on bright red \033[101m -// -// 256 fg \033[38;5;Nm -// 256 bg \033[48;5;Nm -void Color::_colorize (std::string &result, const std::string& input) const -{ - if (!nontrivial ()) - { - result += input; - return; - } - - int count = 0; - - // 256 color - if (_value & _COLOR_256) - { - if (_value & _COLOR_UNDERLINE) - result += "\033[4m"; - - if (_value & _COLOR_INVERSE) - result += "\033[7m"; - - if (_value & _COLOR_HASFG) - { - result += "\033[38;5;"; - result += colorstring[(_value & _COLOR_FG)]; - result += 'm'; - } - - if (_value & _COLOR_HASBG) - { - result += "\033[48;5;"; - result += colorstring[((_value & _COLOR_BG) >> 8)]; - result += 'm'; - } - - result += input; - result += "\033[0m"; - } - - // 16 color - else - { - result += "\033["; - - if (_value & _COLOR_BOLD) - { - if (count++) result += ';'; - result += '1'; - } - - if (_value & _COLOR_UNDERLINE) - { - if (count++) result += ';'; - result += '4'; - } - - if (_value & _COLOR_INVERSE) - { - if (count++) result += ';'; - result += '7'; - } - - if (_value & _COLOR_HASFG) - { - if (count++) result += ';'; - result += colorstring[(29 + (_value & _COLOR_FG))]; - } - - if (_value & _COLOR_HASBG) - { - if (count++) result += ';'; - result += colorstring[((_value & _COLOR_BRIGHT ? 99 : 39) + ((_value & _COLOR_BG) >> 8))]; - } - - result += 'm'; - result += input; - result += "\033[0m"; - } -} - -//////////////////////////////////////////////////////////////////////////////// -// Remove color codes from a string. -std::string Color::strip (const std::string& input) -{ - int length = input.length (); - bool inside = false; - std::string output; - for (int i = 0; i < length; ++i) - { - if (inside) - { - if (input[i] == 'm') - inside = false; - } - else - { - if (input[i] == 033) - inside = true; - else - output += input[i]; - } - } - - return output; -} - -//////////////////////////////////////////////////////////////////////////////// -std::string Color::colorize (const std::string& input, const std::string& spec) -{ - Color c (spec); - return c.colorize (input); -} - -//////////////////////////////////////////////////////////////////////////////// -std::string Color::code () const -{ - if (! nontrivial ()) - return ""; - - std::string result; - - // 256 color - if (_value & _COLOR_256) - { - if (_value & _COLOR_UNDERLINE) - result += "\033[4m"; - - if (_value & _COLOR_INVERSE) - result += "\033[7m"; - - if (_value & _COLOR_HASFG) - { - result += "\033[38;5;"; - result += colorstring[(_value & _COLOR_FG)]; - result += 'm'; - } - - if (_value & _COLOR_HASBG) - { - result += "\033[48;5;"; - result += colorstring[((_value & _COLOR_BG) >> 8)]; - result += 'm'; - } - } - - // 16 color - else - { - int count = 0; - result += "\033["; - - if (_value & _COLOR_BOLD) - { - if (count++) result += ';'; - result += '1'; - } - - if (_value & _COLOR_UNDERLINE) - { - if (count++) result += ';'; - result += '4'; - } - - if (_value & _COLOR_INVERSE) - { - if (count++) result += ';'; - result += '7'; - } - - if (_value & _COLOR_HASFG) - { - if (count++) result += ';'; - result += colorstring[(29 + (_value & _COLOR_FG))]; - } - - if (_value & _COLOR_HASBG) - { - if (count++) result += ';'; - result += colorstring[((_value & _COLOR_BRIGHT ? 99 : 39) + ((_value & _COLOR_BG) >> 8))]; - } - - result += 'm'; - } - - return result; -} - -//////////////////////////////////////////////////////////////////////////////// -std::string Color::end () const -{ - if (nontrivial ()) - return "\033[0m"; - - return ""; -} - -//////////////////////////////////////////////////////////////////////////////// -bool Color::nontrivial () const -{ - return _value != 0 ? true : false; -} - -//////////////////////////////////////////////////////////////////////////////// -int Color::find (const std::string& input) -{ - for (unsigned int i = 0; i < NUM_COLORS; ++i) - if (allColors[i].english_name == input) - return (int) i; - - return -1; -} - -//////////////////////////////////////////////////////////////////////////////// -std::string Color::fg () const -{ - int index = _value & _COLOR_FG; - - if (_value & _COLOR_256) - { - if (_value & _COLOR_HASFG) - { - std::stringstream s; - s << "color" << (_value & _COLOR_FG); - return s.str (); - } - } - else - { - for (unsigned int i = 0; i < NUM_COLORS; ++i) - if (allColors[i].index == index) - return allColors[i].english_name; - } - - return ""; -} - -//////////////////////////////////////////////////////////////////////////////// -std::string Color::bg () const -{ - int index = (_value & _COLOR_BG) >> 8; - - if (_value & _COLOR_256) - { - if (_value & _COLOR_HASBG) - { - std::stringstream s; - s << "color" << ((_value & _COLOR_BG) >> 8); - return s.str (); - } - } - else - { - for (unsigned int i = 0; i < NUM_COLORS; ++i) - if (allColors[i].index == index) - return allColors[i].english_name; - } - - return ""; -} - -//////////////////////////////////////////////////////////////////////////////// diff --git a/src/libshared/src/Color.h b/src/libshared/src/Color.h deleted file mode 100644 index d8393c2..0000000 --- a/src/libshared/src/Color.h +++ /dev/null @@ -1,78 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2006 - 2017, Paul Beckingham, Federico Hernandez. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// -// http://www.opensource.org/licenses/mit-license.php -// -//////////////////////////////////////////////////////////////////////////////// - -#ifndef INCLUDED_COLOR -#define INCLUDED_COLOR - -#include - -#define _COLOR_INVERSE 0x00400000 // Inverse attribute. -#define _COLOR_256 0x00200000 // 256-color mode. -#define _COLOR_HASBG 0x00100000 // Has background color (all values taken). -#define _COLOR_HASFG 0x00080000 // Has foreground color (all values taken). -#define _COLOR_UNDERLINE 0x00040000 // General underline attribute. -#define _COLOR_BOLD 0x00020000 // 16-color bold attribute. -#define _COLOR_BRIGHT 0x00010000 // 16-color bright background attribute. -#define _COLOR_BG 0x0000FF00 // 8-bit background color index. -#define _COLOR_FG 0x000000FF // 8-bit foreground color index. - -class Color -{ -public: - enum color_id {nocolor = 0, black, red, green, yellow, blue, magenta, cyan, white}; - - Color (); - Color (const Color&); - Color (unsigned int); // 256 | INVERSE | UNDERLINE | BOLD | BRIGHT | (BG << 8) | FG - Color (const std::string&); // "red on bright black" - Color (color_id); // fg. - Color (color_id, color_id, bool, bool, bool); // fg, bg, underline, bold, bright - operator std::string () const; - operator int () const; - - void upgrade (); - void blend (const Color&); - - std::string colorize (const std::string&) const; - static std::string colorize (const std::string&, const std::string&); - void _colorize (std::string&, const std::string&) const; - static std::string strip (const std::string&); - - std::string code () const; - std::string end () const; - - bool nontrivial () const; - -private: - int find (const std::string&); - std::string fg () const; - std::string bg () const; - -private: - unsigned int _value; -}; - -#endif diff --git a/src/libshared/src/Composite.cpp b/src/libshared/src/Composite.cpp deleted file mode 100644 index 98bd49c..0000000 --- a/src/libshared/src/Composite.cpp +++ /dev/null @@ -1,148 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2015 - 2017, Paul Beckingham, Federico Hernandez. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// -// http://www.opensource.org/licenses/mit-license.php -// -//////////////////////////////////////////////////////////////////////////////// - -#include -#include -#include -#include -#include - -//////////////////////////////////////////////////////////////////////////////// -// Initially assume no text, but infinite virtual space. -// -// Ållow overlay placement of arbitrary text at any offset, real or virtual, and -// using a specific color. -// -// For example: -// Composite c; -// c.add ("aaaaaaaaaa", 2, Color ("...")); // Layer 1 -// c.add ("bbbbb", 5, Color ("...")); // Layer 2 -// c.add ("c", 15, Color ("...")); // Layer 3 -// -// _layers = { std::make_tuple ("aaaaaaaaaa", 2, Color ("...")), -// std::make_tuple ("bbbbb", 5, Color ("...")), -// std::make_tuple ("c", 15, Color ("..."))}; -// -void Composite::add ( - const std::string& text, - std::string::size_type offset, - const Color& color) -{ - _layers.push_back (std::make_tuple (text, offset, color)); -} - -//////////////////////////////////////////////////////////////////////////////// -// Merge the layers of text and color into one string. -// -// For example: -// Composite c; -// c.add ("aaaaaaaaaa", 2, Color ("...")); // Layer 1 -// c.add ("bbbbb", 5, Color ("...")); // Layer 2 -// c.add ("c", 15, Color ("...")); // Layer 3 -// -// _layers = { std::make_tuple ("aaaaaaaaaa", 2, Color ("...")), -// std::make_tuple ("bbbbb", 5, Color ("...")), -// std::make_tuple ("c", 15, Color ("..."))}; -// -// Arrange strings conceptually: -// 111111 -// 0123456789012345 // Position -// -// aaaaaaaaaa // Layer 1 -// bbbbb // Layer 2 -// c // Layer 3 -// -// Walk all strings left to right, selecting the character and color from the -// highest numbered layer. Emit color codes only on edge detection. -// -std::string Composite::str () const -{ - // The strings are broken into a vector of int, for UTF8 support. - std::vector characters; - std::vector colors; - for (unsigned int layer = 0; layer < _layers.size (); ++layer) - { - auto text = std::get <0> (_layers[layer]); - auto offset = std::get <1> (_layers[layer]); - auto len = utf8_text_length (text); - - // Make sure the vectors are large enough to support a write operator[]. - if (characters.size () < offset + len) - { - characters.resize (offset + len, 32); - colors.resize (offset + len, 0); - } - - // Copy in the layer characters and color indexes. - std::string::size_type cursor = 0; - int character; - int count = 0; - while ((character = utf8_next_char (text, cursor))) - { - characters[offset + count] = character; - colors [offset + count] = layer + 1; - ++count; - } - } - - // Now walk the character and color vector, emitting every character and - // every detected color change. - std::stringstream out; - int prev_color = 0; - for (unsigned int i = 0; i < characters.size (); ++i) - { - // A change in color triggers a code emit. - if (prev_color != colors[i]) - { - if (prev_color) - out << std::get <2> (_layers[prev_color - 1]).end (); - - if (colors[i]) - out << std::get <2> (_layers[colors[i] - 1]).code (); - else - out << std::get <2> (_layers[prev_color - 1]).end (); - - prev_color = colors[i]; - } - - out << utf8_character (characters[i]); - } - - // Terminate the color codes, if necessary. - if (prev_color) - out << std::get <2> (_layers[prev_color - 1]).end (); - - return out.str (); -} - -//////////////////////////////////////////////////////////////////////////////// -// So the same instance can be reused. -void Composite::clear () -{ - _layers.clear (); -} - -//////////////////////////////////////////////////////////////////////////////// diff --git a/src/libshared/src/Composite.h b/src/libshared/src/Composite.h deleted file mode 100644 index 7309c51..0000000 --- a/src/libshared/src/Composite.h +++ /dev/null @@ -1,47 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2015 - 2017, Paul Beckingham, Federico Hernandez. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// -// http://www.opensource.org/licenses/mit-license.php -// -//////////////////////////////////////////////////////////////////////////////// - -#ifndef INCLUDED_COMPOSITE -#define INCLUDED_COMPOSITE - -#include -#include -#include -#include - -class Composite -{ -public: - Composite () = default; - void add (const std::string&, std::string::size_type, const Color&); - std::string str () const; - void clear (); - -private: - std::vector > _layers; -}; - -#endif diff --git a/src/libshared/src/Configuration.cpp b/src/libshared/src/Configuration.cpp deleted file mode 100644 index fc9331c..0000000 --- a/src/libshared/src/Configuration.cpp +++ /dev/null @@ -1,323 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2006 - 2017, Paul Beckingham, Federico Hernandez. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// -// http://www.opensource.org/licenses/mit-license.php -// -//////////////////////////////////////////////////////////////////////////////// - -#include -#include -#include -#include -#include -#include -#include -#include - -//////////////////////////////////////////////////////////////////////////////// -bool setVariableInFile ( - const std::string& file, - const std::string& name, - const std::string& value) -{ - // Read the file contents. - std::vector contents; - File::read (file, contents); - - bool found = false; - bool change = false; - - for (auto& line : contents) - { - // If there is a comment on the line, it must follow the pattern. - auto comment = line.find ('#'); - auto pos = line.find (name + '='); - - if (pos != std::string::npos && - (comment == std::string::npos || - comment > pos)) - { - found = true; - if (comment != std::string::npos) - line = name + '=' + value + ' ' + line.substr (comment); - else - line = name + '=' + value; - - change = true; - } - } - - // Not found, so append instead. - if (! found) - { - contents.push_back (name + '=' + value); - change = true; - } - - if (change) - File::write (file, contents); - - return change; -} - -//////////////////////////////////////////////////////////////////////////////// -bool unsetVariableInFile ( - const std::string& file, - const std::string& name) -{ - // Read configuration file. - std::vector contents; - File::read (file, contents); - - bool change = false; - - for (auto line = contents.begin (); line != contents.end (); ) - { - bool lineDeleted = false; - - // If there is a comment on the line, it must follow the pattern. - auto comment = line->find ('#'); - auto pos = line->find (name + '='); - - if (pos != std::string::npos && - (comment == std::string::npos || - comment > pos)) - { - // vector::erase method returns a valid iterator to the next object - line = contents.erase (line); - lineDeleted = true; - change = true; - } - - if (! lineDeleted) - line++; - } - - if (change) - File::write (file, contents); - - return change; -} - -//////////////////////////////////////////////////////////////////////////////// -// Read the Configuration file and populate the *this map. The file format is -// simply lines with name=value pairs. Whitespace between name, = and value is -// not tolerated, but blank lines and comments starting with # are allowed. -// -// Nested files are now supported, with the following construct: -// include /absolute/path/to/file -// -void Configuration::load (const std::string& file, int nest /* = 1 */) -{ - if (nest > 10) - throw std::string ("Configuration files may only be nested to 10 levels."); - - // Read the file, then parse the contents. - File config (file); - - if (nest == 1) - _original_file = config; - - if (config.exists () && - config.readable ()) - { - std::string contents; - if (File::read (file, contents) && contents.length ()) - parse (contents, nest); - } -} - -//////////////////////////////////////////////////////////////////////////////// -// Write the Configuration file. -void Configuration::save () -{ - std::string contents; - for (const auto& i : *this) - contents += i.first + "=" + i.second + '\n'; - - File::write (_original_file, contents); - _dirty = false; -} - -//////////////////////////////////////////////////////////////////////////////// -void Configuration::parse (const std::string& input, int nest /* = 1 */) -{ - // Shortcut case for default constructor. - if (input.length () == 0) - return; - - // Parse each line. - for (auto& line : split (input, '\n')) - { - // Remove comments. - auto pound = line.find ('#'); - if (pound != std::string::npos) - line = line.substr (0, pound); - - // Skip empty lines. - line = trim (line); - if (line.length () > 0) - { - auto equal = line.find ('='); - if (equal != std::string::npos) - { - std::string key = trim (line.substr (0, equal)); - std::string value = trim (line.substr (equal+1, line.length () - equal)); - - (*this)[key] = json::decode (value); - } - else - { - auto include = line.find ("include"); - if (include != std::string::npos) - { - Path included (trim (line.substr (include + 7))); - if (included.is_absolute ()) - { - if (included.readable ()) - load (included, nest + 1); - else - throw format ("Could not read include file '{1}'.", included._data); - } - else - throw format ("Can only include files with absolute paths, not '{1}'", included._data); - } - else - throw format ("Malformed entry '{1}' in config file.", line); - } - } - } - - _dirty = true; -} - -//////////////////////////////////////////////////////////////////////////////// -bool Configuration::has (const std::string& key) const -{ - return (*this).find (key) != (*this).end (); -} - -//////////////////////////////////////////////////////////////////////////////// -// Return the configuration value given the specified key. -std::string Configuration::get (const std::string& key) const -{ - auto found = find (key); - if (found != end ()) - return found->second; - - return ""; -} - -//////////////////////////////////////////////////////////////////////////////// -int Configuration::getInteger (const std::string& key) const -{ - auto found = find (key); - if (found != end ()) - return strtoimax (found->second.c_str (), nullptr, 10); - - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -double Configuration::getReal (const std::string& key) const -{ - auto found = find (key); - if (found != end ()) - return strtod (found->second.c_str (), nullptr); - - return 0.0; -} - -//////////////////////////////////////////////////////////////////////////////// -bool Configuration::getBoolean (const std::string& key) const -{ - auto found = find (key); - if (found != end ()) - { - auto value = lowerCase (found->second); - if (value == "true" || - value == "1" || - value == "y" || - value == "yes" || - value == "on") - return true; - } - - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -void Configuration::set (const std::string& key, const int value) -{ - (*this)[key] = format (value); - _dirty = true; -} - -//////////////////////////////////////////////////////////////////////////////// -void Configuration::set (const std::string& key, const double value) -{ - (*this)[key] = format (value, 1, 8); - _dirty = true; -} - -//////////////////////////////////////////////////////////////////////////////// -void Configuration::set (const std::string& key, const std::string& value) -{ - (*this)[key] = value; - _dirty = true; -} - -//////////////////////////////////////////////////////////////////////////////// -// Autovivification is ok here. -void Configuration::setIfBlank (const std::string& key, const std::string& value) -{ - if ((*this)[key] == "") - { - (*this)[key] = value; - _dirty = true; - } -} - -//////////////////////////////////////////////////////////////////////////////// -// Provide a vector of all configuration keys. -std::vector Configuration::all () const -{ - std::vector items; - for (const auto& it : *this) - items.push_back (it.first); - - return items; -} - -//////////////////////////////////////////////////////////////////////////////// -std::string Configuration::file () const -{ - return _original_file._data; -} - -//////////////////////////////////////////////////////////////////////////////// -bool Configuration::dirty () -{ - return _dirty; -} - -//////////////////////////////////////////////////////////////////////////////// diff --git a/src/libshared/src/Configuration.h b/src/libshared/src/Configuration.h deleted file mode 100644 index 067affe..0000000 --- a/src/libshared/src/Configuration.h +++ /dev/null @@ -1,66 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2006 - 2017, Paul Beckingham, Federico Hernandez. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// -// http://www.opensource.org/licenses/mit-license.php -// -//////////////////////////////////////////////////////////////////////////////// - -#ifndef INCLUDED_CONFIGURATION -#define INCLUDED_CONFIGURATION - -#include -#include -#include -#include - -bool setVariableInFile (const std::string&, const std::string&, const std::string&); -bool unsetVariableInFile (const std::string&, const std::string&); - -class Configuration : public std::map -{ -public: - void load (const std::string&, int nest = 1); - void save (); - void parse (const std::string&, int nest = 1); - - bool has (const std::string&) const; - std::string get (const std::string&) const; - int getInteger (const std::string&) const; - double getReal (const std::string&) const; - bool getBoolean (const std::string&) const; - - void set (const std::string&, const int); - void set (const std::string&, const double); - void set (const std::string&, const std::string&); - void setIfBlank (const std::string&, const std::string&); - std::vector all () const; - - std::string file () const; - - bool dirty (); - -private: - File _original_file {}; - bool _dirty {false}; -}; - -#endif diff --git a/src/libshared/src/Datetime.cpp b/src/libshared/src/Datetime.cpp deleted file mode 100644 index 726d9dc..0000000 --- a/src/libshared/src/Datetime.cpp +++ /dev/null @@ -1,3787 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2006 - 2017, Paul Beckingham, Federico Hernandez. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// -// http://www.opensource.org/licenses/mit-license.php -// -//////////////////////////////////////////////////////////////////////////////// - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static std::vector dayNames { - "sunday", - "monday", - "tuesday", - "wednesday", - "thursday", - "friday", - "saturday"}; - -static std::vector monthNames { - "january", - "february", - "march", - "april", - "may", - "june", - "july", - "august", - "september", - "october", - "november", - "december"}; - -int Datetime::weekstart = 1; // Monday, per ISO-8601. -int Datetime::minimumMatchLength = 3; -bool Datetime::isoEnabled = true; -bool Datetime::standaloneDateEnabled = true; -bool Datetime::standaloneTimeEnabled = true; - -//////////////////////////////////////////////////////////////////////////////// -Datetime::Datetime () -{ - clear (); - _date = time (nullptr); -} - -//////////////////////////////////////////////////////////////////////////////// -Datetime::Datetime (const std::string& input, const std::string& format) -{ - clear (); - std::string::size_type start = 0; - if (! parse (input, start, format)) - throw ::format ("'{1}' is not a valid date in the '{2}' format.", input, format); -} - -//////////////////////////////////////////////////////////////////////////////// -Datetime::Datetime (const time_t t) -{ - clear (); - _date = t; -} - -//////////////////////////////////////////////////////////////////////////////// -Datetime::Datetime (const int y, const int m, const int d) -{ - // Protect against arguments being passed in the wrong order. - assert (y >= 1969 && y < 2100); - assert (m >= 1 && m <= 12); - assert (d >= 1 && d <= 31); - - clear (); - - // Error if not valid. - struct tm t {}; - t.tm_isdst = -1; // Requests that mktime determine summer time effect. - t.tm_mday = d; - t.tm_mon = m - 1; - t.tm_year = y - 1900; - - _date = mktime (&t); -} - -//////////////////////////////////////////////////////////////////////////////// -Datetime::Datetime (const int y, const int m, const int d, - const int hr, const int mi, const int se) -{ - // Protect against arguments being passed in the wrong order. - assert (y >= 1969 && y < 2100); - assert (m >= 1 && m <= 12); - assert (d >= 1 && d <= 31); - assert (hr >= 0 && hr <= 24); - assert (mi >= 0 && mi < 60); - assert (se >= 0 && se < 60); - - clear (); - - // Error if not valid. - struct tm t {}; - t.tm_isdst = -1; // Requests that mktime determine summer time effect. - t.tm_mday = d; - t.tm_mon = m - 1; - t.tm_year = y - 1900; - t.tm_hour = hr; - t.tm_min = mi; - t.tm_sec = se; - - _date = mktime (&t); -} - -//////////////////////////////////////////////////////////////////////////////// -bool Datetime::parse ( - const std::string& input, - std::string::size_type& start, - const std::string& format) -{ - auto i = start; - Pig pig (input); - if (i) - pig.skipN (static_cast (i)); - - auto checkpoint = pig.cursor (); - - // Parse epoch first, as it's the most common scenario. - if (parse_epoch (pig)) - { - // ::validate and ::resolve are not needed in this case. - start = pig.cursor (); - return true; - } - - if (parse_formatted (pig, format)) - { - // Check the values and determine time_t. - if (validate ()) - { - start = pig.cursor (); - resolve (); - return true; - } - } - - // Allow parse_date_time and parse_date_time_ext regardless of - // Datetime::isoEnabled setting, because these formats are relied upon by - // the 'import' command, JSON parser and hook system. - if (parse_date_time_ext (pig) || // Strictest first. - parse_date_time (pig) || - (Datetime::isoEnabled && - ( parse_date_ext (pig) || - (Datetime::standaloneDateEnabled && parse_date (pig)) || - parse_time_utc_ext (pig) || - parse_time_utc (pig) || - parse_time_off_ext (pig) || - parse_time_off (pig) || - parse_time_ext (pig) || - (Datetime::standaloneTimeEnabled && parse_time (pig)) // Time last, as it is the most permissive. - ) - ) - ) - { - // Check the values and determine time_t. - if (validate ()) - { - start = pig.cursor (); - resolve (); - return true; - } - } - - pig.restoreTo (checkpoint); - - if (parse_named (pig)) - { - // ::validate and ::resolve are not needed in this case. - start = pig.cursor (); - return true; - } - - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -void Datetime::clear () -{ - _year = 0; - _month = 0; - _week = 0; - _weekday = 0; - _julian = 0; - _day = 0; - _seconds = 0; - _offset = 0; - _utc = false; - _date = 0; -} - -//////////////////////////////////////////////////////////////////////////////// -bool Datetime::parse_formatted (Pig& pig, const std::string& format) -{ - // Short-circuit on missing format. - if (format == "") - return false; - - auto checkpoint = pig.cursor (); - - int month {-1}; // So we can check later. - int day {-1}; - int year {-1}; - int hour {-1}; - int minute {-1}; - int second {-1}; - - // For parsing, unused. - int wday {-1}; - int week {-1}; - - for (unsigned int f = 0; f < format.length (); ++f) - { - switch (format[f]) - { - case 'm': - if (pig.getDigit (month)) - { - if (month == 0) - pig.getDigit (month); - - if (month == 1) - if (pig.getDigit (month)) - month += 10; - } - else - { - pig.restoreTo (checkpoint); - return false; - } - break; - - case 'M': - if (! pig.getDigit2 (month)) - { - pig.restoreTo (checkpoint); - return false; - } - break; - - case 'd': - if (pig.getDigit (day)) - { - if (day == 0) - pig.getDigit (day); - - if (day == 1 || day == 2 || day == 3) - { - int tens = day; - if (pig.getDigit (day)) - day += 10 * tens; - } - } - else - { - pig.restoreTo (checkpoint); - return false; - } - break; - - case 'D': - if (! pig.getDigit2 (day)) - { - pig.restoreTo (checkpoint); - return false; - } - break; - - case 'y': - if (! pig.getDigit2 (year)) - { - pig.restoreTo (checkpoint); - return false; - } - year += 2000; - break; - - case 'Y': - if (! pig.getDigit4 (year)) - { - pig.restoreTo (checkpoint); - return false; - } - break; - - case 'h': - if (pig.getDigit (hour)) - { - if (hour == 0) - pig.getDigit (hour); - - if (hour == 1 || hour == 2) - { - int tens = hour; - if (pig.getDigit (hour)) - hour += 10 * tens; - } - } - else - { - pig.restoreTo (checkpoint); - return false; - } - break; - - case 'H': - if (! pig.getDigit2 (hour)) - { - pig.restoreTo (checkpoint); - return false; - } - break; - - case 'n': - if (pig.getDigit (minute)) - { - if (minute == 0) - pig.getDigit (minute); - - if (minute < 6) - { - int tens = minute; - if (pig.getDigit (minute)) - minute += 10 * tens; - } - } - else - { - pig.restoreTo (checkpoint); - return false; - } - break; - - case 'N': - if (! pig.getDigit2 (minute)) - { - pig.restoreTo (checkpoint); - return false; - } - break; - - case 's': - if (pig.getDigit (second)) - { - if (second == 0) - pig.getDigit (second); - - if (second < 6) - { - int tens = second; - if (pig.getDigit (second)) - second += 10 * tens; - } - } - else - { - pig.restoreTo (checkpoint); - return false; - } - break; - - case 'S': - if (! pig.getDigit2 (second)) - { - pig.restoreTo (checkpoint); - return false; - } - break; - - case 'v': - if (pig.getDigit (week)) - { - if (week == 0) - pig.getDigit (week); - - if (week < 6) - { - int tens = week; - if (pig.getDigit (week)) - week += 10 * tens; - } - } - else - { - pig.restoreTo (checkpoint); - return false; - } - break; - - case 'V': - if (! pig.getDigit2 (week)) - { - pig.restoreTo (checkpoint); - return false; - } - break; - - case 'a': - wday = Datetime::dayOfWeek (pig.str ().substr (0, 3)); - if (wday == -1) - { - pig.restoreTo (checkpoint); - return false; - } - - pig.skipN (3); - break; - - case 'A': - { - std::string dayName; - if (pig.getUntil (format[f + 1], dayName)) - { - wday = Datetime::dayOfWeek (dayName); - if (wday == -1) - { - pig.restoreTo (checkpoint); - return false; - } - } - } - break; - - case 'b': - month = Datetime::monthOfYear (pig.str ().substr (0, 3)); - if (month == -1) - { - pig.restoreTo (checkpoint); - return false; - } - - pig.skipN (3); - break; - - case 'B': - { - std::string monthName; - if (pig.getUntil (format[f + 1], monthName)) - { - month = Datetime::monthOfYear (monthName); - if (month == -1) - { - pig.restoreTo (checkpoint); - return false; - } - } - } - break; - - default: - if (! pig.skip (format[f])) - { - pig.restoreTo (checkpoint); - return false; - } - break; - } - } - - // It is possible that the format='Y-M-D', and the input is Y-M-DTH:N:SZ, and - // this should not be considered a match. - if (! pig.eos () && ! unicodeWhitespace (pig.peek ())) - { - pig.restoreTo (checkpoint); - return false; - } - - // Missing values are filled in from the current date. - if (year == -1) - { - Datetime now; - year = now.year (); - if (month == -1) - { - month = now.month (); - if (day == -1) - { - day = now.day (); - if (hour == -1) - { - hour = now.hour (); - if (minute == -1) - { - minute = now.minute (); - if (second == -1) - second = now.second (); - } - } - } - } - } - - // Any remaining undefined values are assigned defaults. - if (month == -1) month = 1; - if (day == -1) day = 1; - if (hour == -1) hour = 0; - if (minute == -1) minute = 0; - if (second == -1) second = 0; - - _year = year; - _month = month; - _day = day; - _seconds = (hour * 3600) + (minute * 60) + second; - - return true; -} - -//////////////////////////////////////////////////////////////////////////////// -// Note how these are all single words. -// -// Examples and descriptions, assuming now == 2017-03-05T12:34:56. -// -// Example Notes -// ------------------- ------------------ -// now 2017-03-05T12:34:56 Unaffected -// yesterday 2017-03-04T00:00:00 Unaffected -// today 2017-03-05T00:00:00 Unaffected -// tomorrow 2017-03-06T00:00:00 Unaffected -// 12th 2017-03-12T00:00:00 -// monday 2017-03-06T00:00:00 -// april 2017-04-01T00:00:00 -// later 2038-01-18T00:00:00 Unaffected -// someday 2038-01-18T00:00:00 Unaffected -// sopd 2017-03-04T00:00:00 Unaffected -// sod 2017-03-05T00:00:00 Unaffected -// sond 2017-03-06T00:00:00 Unaffected -// eopd 2017-03-05T00:00:00 Unaffected -// eod 2017-03-06T00:00:00 Unaffected -// eond 2017-03-07T00:00:00 Unaffected -// sopw 2017-02-26T00:00:00 Unaffected -// sow 2017-03-05T00:00:00 Unaffected -// sonw 2017-03-12T00:00:00 Unaffected -// eopw 2017-03-05T00:00:00 Unaffected -// eow 2017-03-12T00:00:00 Unaffected -// eonw 2017-03-19T00:00:00 Unaffected -// sopww 2017-02-27T00:00:00 Unaffected -// soww 2017-03-06T00:00:00 -// sonww 2017-03-06T00:00:00 Unaffected -// eopww 2017-03-03T00:00:00 Unaffected -// eoww 2017-03-10T00:00:00 -// eonww 2017-03-17T00:00:00 Unaffected -// sopm 2017-02-01T00:00:00 Unaffected -// som 2017-03-01T00:00:00 Unaffected -// sonm 2017-04-01T00:00:00 Unaffected -// eopm 2017-03-01T00:00:00 Unaffected -// eom 2017-04-01T00:00:00 Unaffected -// eonm 2017-05-01T00:00:00 Unaffected -// sopq 2017-10-01T00:00:00 Unaffected -// soq 2017-01-01T00:00:00 Unaffected -// sonq 2017-04-01T00:00:00 Unaffected -// eopq 2017-01-01T00:00:00 Unaffected -// eoq 2017-04-01T00:00:00 Unaffected -// eonq 2017-07-01T00:00:00 Unaffected -// sopy 2016-01-01T00:00:00 Unaffected -// soy 2017-01-01T00:00:00 Unaffected -// sony 2018-01-01T00:00:00 Unaffected -// eopy 2017-01-01T00:00:00 Unaffected -// eoy 2018-01-01T00:00:00 Unaffected -// eony 2019-01-01T00:00:00 Unaffected -// easter 2017-04-16T00:00:00 -// eastermonday 2017-04-16T00:00:00 -// ascension 2017-05-25T00:00:00 -// pentecost 2017-06-04T00:00:00 -// goodfriday 2017-04-14T00:00:00 -// midsommar 2017-06-24T00:00:00 midnight, 1st Saturday after 20th June -// midsommarafton 2017-06-23T00:00:00 midnight, 1st Friday after 19th June -// juhannus 2017-06-23T00:00:00 midnight, 1st Friday after 19th June -// -bool Datetime::parse_named (Pig& pig) -{ - auto checkpoint = pig.cursor (); - - // Experimental handling of date phrases, such as "first monday in march". - // Note that this requires that phrases are deliminted by EOS or WS. - std::string token; - std::vector tokens; - while (pig.getUntilWS (token)) - { - tokens.push_back (token); - if (! pig.skipWS ()) - break; - } - -/* - // This grpoup contains "1st monday ..." which must be processed before - // initializeOrdinal below. - if (initializeNthDayInMonth (tokens)) - { - return true; - } -*/ - - // Restoration necessary because of the tokenization. - pig.restoreTo (checkpoint); - - if (initializeNow (pig) || - initializeYesterday (pig) || - initializeToday (pig) || - initializeTomorrow (pig) || - initializeOrdinal (pig) || - initializeDayName (pig) || - initializeMonthName (pig) || - initializeLater (pig) || - initializeSopd (pig) || - initializeSod (pig) || - initializeSond (pig) || - initializeEopd (pig) || - initializeEod (pig) || - initializeEond (pig) || - initializeSopw (pig) || - initializeSow (pig) || - initializeSonw (pig) || - initializeEopw (pig) || - initializeEow (pig) || - initializeEonw (pig) || - initializeSopww (pig) || // Must appear after sopw - initializeSonww (pig) || // Must appear after sonw - initializeSoww (pig) || // Must appear after sow - initializeEopww (pig) || // Must appear after eopw - initializeEonww (pig) || // Must appear after eonw - initializeEoww (pig) || // Must appear after eow - initializeSopm (pig) || - initializeSom (pig) || - initializeSonm (pig) || - initializeEopm (pig) || - initializeEom (pig) || - initializeEonm (pig) || - initializeSopq (pig) || - initializeSoq (pig) || - initializeSonq (pig) || - initializeEopq (pig) || - initializeEoq (pig) || - initializeEonq (pig) || - initializeSopy (pig) || - initializeSoy (pig) || - initializeSony (pig) || - initializeEopy (pig) || - initializeEoy (pig) || - initializeEony (pig) || - initializeEaster (pig) || - initializeMidsommar (pig) || - initializeMidsommarafton (pig) || - initializeInformalTime (pig)) - { - return true; - } - - pig.restoreTo (checkpoint); - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -// Valid epoch values are unsigned integers after 1980-01-01T00:00:00Z. This -// restriction means that '12' will not be identified as an epoch date. -bool Datetime::parse_epoch (Pig& pig) -{ - auto checkpoint = pig.cursor (); - - int epoch {}; - if (pig.getDigits (epoch) && - ! unicodeLatinAlpha (pig.peek ()) && - epoch >= 315532800) - { - _date = static_cast (epoch); - //std::cout << "# parse_epoch succeed " << pig.dump () << "\n"; - return true; - } - - //std::cout << "# parse_epoch fail\n"; - pig.restoreTo (checkpoint); - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -// date_ext 'T' time_utc_ext 'Z' -// date_ext 'T' time_off_ext -// date_ext 'T' time_ext -bool Datetime::parse_date_time_ext (Pig& pig) -{ - auto checkpoint = pig.cursor (); - - if (parse_date_ext (pig) && - pig.skip ('T') && - (parse_time_utc_ext (pig) || - parse_time_off_ext (pig) || - parse_time_ext (pig))) - { - return true; - } - - pig.restoreTo (checkpoint); - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -// YYYY-MM-DD -// YYYY-MM -// YYYY-DDD -// YYYY-Www-D -// YYYY-Www -bool Datetime::parse_date_ext (Pig& pig) -{ - auto checkpoint = pig.cursor (); - - int year {}; - if (parse_year (pig, year) && - pig.skip ('-')) - { - auto checkpointYear = pig.cursor (); - - int month {}; - int day {}; - int julian {}; - - if (pig.skip ('W') && - parse_week (pig, _week)) - { - if (pig.skip ('-') && - pig.getDigit (_weekday)) - { - // What is happening here - must be something to do? - } - - if (! unicodeLatinDigit (pig.peek ())) - { - _year = year; - return true; - } - } - - pig.restoreTo (checkpointYear); - - if (parse_month (pig, month) && - pig.skip ('-') && - parse_day (pig, day) && - ! unicodeLatinDigit (pig.peek ())) - { - _year = year; - _month = month; - _day = day; - return true; - } - - pig.restoreTo (checkpointYear); - - if (parse_julian (pig, julian) && - ! unicodeLatinDigit (pig.peek ())) - { - _year = year; - _julian = julian; - return true; - } - - pig.restoreTo (checkpointYear); - - if (parse_month (pig, month) && - pig.peek () != '-' && - ! unicodeLatinDigit (pig.peek ())) - { - _year = year; - _month = month; - _day = 1; - return true; - } - } - - pig.restoreTo (checkpoint); - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -// ±hh[:mm] -bool Datetime::parse_off_ext (Pig& pig) -{ - auto checkpoint = pig.cursor (); - - int sign = pig.peek (); - if (sign == '+' || sign == '-') - { - pig.skipN (1); - - int hour {0}; - int minute {0}; - - if (parse_off_hour (pig, hour)) - { - if (pig.skip (':')) - { - if (! parse_off_minute (pig, minute)) - { - pig.restoreTo (checkpoint); - return false; - } - } - - _offset = (hour * 3600) + (minute * 60); - if (sign == '-') - _offset = - _offset; - - if (! unicodeLatinDigit (pig.peek ())) - return true; - } - } - - pig.restoreTo (checkpoint); - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -// hh:mm[:ss] -bool Datetime::parse_time_ext (Pig& pig, bool terminated) -{ - auto checkpoint = pig.cursor (); - - int hour {}; - int minute {}; - if (parse_hour (pig, hour) && - pig.skip (':') && - parse_minute (pig, minute)) - { - if (pig.skip (':')) - { - int second {}; - if (parse_second (pig, second) && - ! unicodeLatinDigit (pig.peek ()) && - (! terminated || (pig.peek () != '-' && pig.peek () != '+'))) - { - _seconds = (hour * 3600) + (minute * 60) + second; - return true; - } - - pig.restoreTo (checkpoint); - return false; - } - - auto following = pig.peek (); - if (! unicodeLatinDigit (following) && - (! terminated || (following != '+' && following != '-')) && - following != 'A' && - following != 'a' && - following != 'P' && - following != 'p') - { - _seconds = (hour * 3600) + (minute * 60); - return true; - } - } - - pig.restoreTo (checkpoint); - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -// time-ext 'Z' -bool Datetime::parse_time_utc_ext (Pig& pig) -{ - auto checkpoint = pig.cursor (); - - if (parse_time_ext (pig, false) && - pig.skip ('Z')) - { - if (! unicodeLatinDigit (pig.peek ())) - { - _utc = true; - return true; - } - } - - pig.restoreTo (checkpoint); - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -// time-ext off-ext -bool Datetime::parse_time_off_ext (Pig& pig) -{ - auto checkpoint = pig.cursor (); - - if (parse_time_ext (pig, false) && - parse_off_ext (pig)) - { - return true; - } - - pig.restoreTo (checkpoint); - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -// YYYYMMDDTHHMMSSZ -// YYYYMMDDTHHMMSS -bool Datetime::parse_date_time (Pig& pig) -{ - auto checkpoint = pig.cursor (); - - if (parse_date (pig) && - pig.skip ('T') && - (parse_time_utc (pig) || - parse_time_off (pig) || - parse_time (pig))) - { - return true; - } - - pig.restoreTo (checkpoint); - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -// YYYYWww -// YYYYDDD -// YYYYMMDD -// YYYYMM -bool Datetime::parse_date (Pig& pig) -{ - auto checkpoint = pig.cursor (); - - int year {}; - int month {}; - int julian {}; - int week {}; - int weekday {}; - int day {}; - if (parse_year (pig, year)) - { - auto checkpointYear = pig.cursor (); - - if (pig.skip ('W') && - parse_week (pig, week)) - { - if (pig.getDigit (weekday)) - _weekday = weekday; - - if (! unicodeLatinDigit (pig.peek ())) - { - _year = year; - _week = week; - return true; - } - } - - pig.restoreTo (checkpointYear); - - if (parse_julian (pig, julian) && - ! unicodeLatinDigit (pig.peek ())) - { - _year = year; - _julian = julian; - return true; - } - - pig.restoreTo (checkpointYear); - - if (parse_month (pig, month)) - { - if (parse_day (pig, day)) - { - if (! unicodeLatinDigit (pig.peek ())) - { - _year = year; - _month = month; - _day = day; - return true; - } - } - else - { - if (! unicodeLatinDigit (pig.peek ())) - { - _year = year; - _month = month; - _day = 1; - return true; - } - } - } - } - - pig.restoreTo (checkpoint); - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -//