mirror of
https://github.com/hyprwm/hyprlang.git
synced 2025-05-13 05:40:42 +01:00
Compare commits
54 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
557241780c | ||
![]() |
a59e86a3da | ||
![]() |
a15e7ba78a | ||
![]() |
e863ebcee9 | ||
![]() |
6726cfd54b | ||
![]() |
397600c42b | ||
![]() |
f1000c54d2 | ||
![]() |
72df3861f1 | ||
![]() |
1d7d96a278 | ||
![]() |
a7334904d5 | ||
![]() |
7a59f2de3f | ||
![]() |
f41271d35c | ||
![]() |
55608efdaa | ||
![]() |
0404833ea1 | ||
![]() |
16e59c1eb1 | ||
![]() |
9441266c89 | ||
![]() |
f7acd5dabb | ||
![]() |
1b0c595731 | ||
![]() |
058fcf84c9 | ||
![]() |
f054f2e44d | ||
![]() |
dfeb5811dd | ||
![]() |
5b175c9704 | ||
![]() |
c12ab785ce | ||
![]() |
16e5c9465f | ||
![]() |
adbefbf496 | ||
![]() |
651c8d02cc | ||
![]() |
c0704455ee | ||
![]() |
5df0174fd0 | ||
![]() |
095f54b910 | ||
![]() |
db8c528aac | ||
![]() |
ec6938c662 | ||
![]() |
87d5d98410 | ||
![]() |
c7c2d29831 | ||
![]() |
554c95a846 | ||
![]() |
969cb076e5 | ||
![]() |
073678282e | ||
![]() |
19ec261528 | ||
![]() |
78fcaa27ae | ||
![]() |
748fb531ca | ||
![]() |
c140261214 | ||
![]() |
95471ec86f | ||
![]() |
b3e430f81f | ||
![]() |
a2f3942114 | ||
![]() |
a685493fdb | ||
![]() |
84170ba0e5 | ||
![]() |
bba5daeaf9 | ||
![]() |
2e2a1992c8 | ||
![]() |
9995f54edd | ||
![]() |
66c099e097 | ||
![]() |
f1db1a7e1f | ||
![]() |
221714841a | ||
![]() |
7edc9a664e | ||
![]() |
6cb791c18c | ||
![]() |
3cc06e1687 |
21 changed files with 1138 additions and 957 deletions
101
.clang-tidy
Normal file
101
.clang-tidy
Normal file
|
@ -0,0 +1,101 @@
|
|||
WarningsAsErrors: '*'
|
||||
HeaderFilterRegex: '.*\.hpp'
|
||||
FormatStyle: 'file'
|
||||
Checks: >
|
||||
-*,
|
||||
bugprone-*,
|
||||
-bugprone-easily-swappable-parameters,
|
||||
-bugprone-forward-declaration-namespace,
|
||||
-bugprone-forward-declaration-namespace,
|
||||
-bugprone-macro-parentheses,
|
||||
-bugprone-narrowing-conversions,
|
||||
-bugprone-branch-clone,
|
||||
-bugprone-assignment-in-if-condition,
|
||||
concurrency-*,
|
||||
-concurrency-mt-unsafe,
|
||||
cppcoreguidelines-*,
|
||||
-cppcoreguidelines-owning-memory,
|
||||
-cppcoreguidelines-avoid-magic-numbers,
|
||||
-cppcoreguidelines-pro-bounds-constant-array-index,
|
||||
-cppcoreguidelines-avoid-const-or-ref-data-members,
|
||||
-cppcoreguidelines-non-private-member-variables-in-classes,
|
||||
-cppcoreguidelines-avoid-goto,
|
||||
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
|
||||
-cppcoreguidelines-avoid-do-while,
|
||||
-cppcoreguidelines-avoid-non-const-global-variables,
|
||||
-cppcoreguidelines-special-member-functions,
|
||||
-cppcoreguidelines-explicit-virtual-functions,
|
||||
-cppcoreguidelines-avoid-c-arrays,
|
||||
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
|
||||
-cppcoreguidelines-narrowing-conversions,
|
||||
-cppcoreguidelines-pro-type-union-access,
|
||||
-cppcoreguidelines-pro-type-member-init,
|
||||
-cppcoreguidelines-macro-usage,
|
||||
-cppcoreguidelines-macro-to-enum,
|
||||
-cppcoreguidelines-init-variables,
|
||||
-cppcoreguidelines-pro-type-cstyle-cast,
|
||||
-cppcoreguidelines-pro-type-vararg,
|
||||
-cppcoreguidelines-pro-type-reinterpret-cast,
|
||||
google-global-names-in-headers,
|
||||
-google-readability-casting,
|
||||
google-runtime-operator,
|
||||
misc-*,
|
||||
-misc-unused-parameters,
|
||||
-misc-no-recursion,
|
||||
-misc-non-private-member-variables-in-classes,
|
||||
-misc-include-cleaner,
|
||||
-misc-use-anonymous-namespace,
|
||||
-misc-const-correctness,
|
||||
modernize-*,
|
||||
-modernize-return-braced-init-list,
|
||||
-modernize-use-trailing-return-type,
|
||||
-modernize-use-using,
|
||||
-modernize-use-override,
|
||||
-modernize-avoid-c-arrays,
|
||||
-modernize-macro-to-enum,
|
||||
-modernize-loop-convert,
|
||||
-modernize-use-nodiscard,
|
||||
-modernize-pass-by-value,
|
||||
-modernize-use-auto,
|
||||
performance-*,
|
||||
-performance-avoid-endl,
|
||||
-performance-unnecessary-value-param,
|
||||
portability-std-allocator-const,
|
||||
readability-*,
|
||||
-readability-function-cognitive-complexity,
|
||||
-readability-function-size,
|
||||
-readability-identifier-length,
|
||||
-readability-magic-numbers,
|
||||
-readability-uppercase-literal-suffix,
|
||||
-readability-braces-around-statements,
|
||||
-readability-redundant-access-specifiers,
|
||||
-readability-else-after-return,
|
||||
-readability-container-data-pointer,
|
||||
-readability-implicit-bool-conversion,
|
||||
-readability-avoid-nested-conditional-operator,
|
||||
-readability-redundant-member-init,
|
||||
-readability-redundant-string-init,
|
||||
-readability-avoid-const-params-in-decls,
|
||||
-readability-named-parameter,
|
||||
-readability-convert-member-functions-to-static,
|
||||
-readability-qualified-auto,
|
||||
-readability-make-member-function-const,
|
||||
-readability-isolate-declaration,
|
||||
-readability-inconsistent-declaration-parameter-name,
|
||||
-clang-diagnostic-error,
|
||||
|
||||
CheckOptions:
|
||||
performance-for-range-copy.WarnOnAllAutoCopies: true
|
||||
performance-inefficient-string-concatenation.StrictMode: true
|
||||
readability-braces-around-statements.ShortStatementLines: 0
|
||||
readability-identifier-naming.ClassCase: CamelCase
|
||||
readability-identifier-naming.ClassIgnoredRegexp: I.*
|
||||
readability-identifier-naming.ClassPrefix: C # We can't use regex here?!?!?!?
|
||||
readability-identifier-naming.EnumCase: CamelCase
|
||||
readability-identifier-naming.EnumPrefix: e
|
||||
readability-identifier-naming.EnumConstantCase: UPPER_CASE
|
||||
readability-identifier-naming.FunctionCase: camelBack
|
||||
readability-identifier-naming.NamespaceCase: CamelCase
|
||||
readability-identifier-naming.NamespacePrefix: N
|
||||
readability-identifier-naming.StructPrefix: S
|
||||
readability-identifier-naming.StructCase: CamelCase
|
59
.github/workflows/arch.yml
vendored
59
.github/workflows/arch.yml
vendored
|
@ -2,39 +2,6 @@ name: Build & Test (Arch)
|
|||
|
||||
on: [push, pull_request, workflow_dispatch]
|
||||
jobs:
|
||||
gcc:
|
||||
name: "gcc build / clang test"
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: archlinux
|
||||
steps:
|
||||
- name: Checkout repository actions
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
sparse-checkout: .github/actions
|
||||
|
||||
- name: Get required pkgs
|
||||
run: |
|
||||
sed -i 's/SigLevel = Required DatabaseOptional/SigLevel = Optional TrustAll/' /etc/pacman.conf
|
||||
pacman --noconfirm --noprogressbar -Syyu
|
||||
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang
|
||||
|
||||
- name: Build hyprlang with gcc
|
||||
run: |
|
||||
CC="/usr/bin/gcc" CXX="/usr/bin/g++" cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -S . -B ./build
|
||||
CC="/usr/bin/gcc" CXX="/usr/bin/g++" cmake --build ./build --config Release --target hyprlang -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
|
||||
cmake --install ./build
|
||||
|
||||
- name: Build tests with clang
|
||||
run: |
|
||||
rm -rf ./build
|
||||
CC="/usr/bin/clang" CXX="/usr/bin/clang++" cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -S . -B ./build
|
||||
CC="/usr/bin/clang" CXX="/usr/bin/clang++" cmake --build ./build --config Release --target tests -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
|
||||
|
||||
- name: Run tests
|
||||
run: |
|
||||
cd ./build && ctest --output-on-failure
|
||||
|
||||
asan:
|
||||
name: "gcc build / ASan tests"
|
||||
runs-on: ubuntu-latest
|
||||
|
@ -50,7 +17,11 @@ jobs:
|
|||
run: |
|
||||
sed -i 's/SigLevel = Required DatabaseOptional/SigLevel = Optional TrustAll/' /etc/pacman.conf
|
||||
pacman --noconfirm --noprogressbar -Syyu
|
||||
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang
|
||||
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang git pixman
|
||||
|
||||
- name: Get hyprutils-git
|
||||
run: |
|
||||
git clone https://github.com/hyprwm/hyprutils && cd hyprutils && cmake -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -B build && cmake --build build --target hyprutils && cmake --install build
|
||||
|
||||
- name: Build with gcc
|
||||
run: |
|
||||
|
@ -77,7 +48,11 @@ jobs:
|
|||
run: |
|
||||
sed -i 's/SigLevel = Required DatabaseOptional/SigLevel = Optional TrustAll/' /etc/pacman.conf
|
||||
pacman --noconfirm --noprogressbar -Syyu
|
||||
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang
|
||||
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang git pixman
|
||||
|
||||
- name: Get hyprutils-git
|
||||
run: |
|
||||
git clone https://github.com/hyprwm/hyprutils && cd hyprutils && cmake -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -B build && cmake --build build --target hyprutils && cmake --install build
|
||||
|
||||
- name: Build with gcc
|
||||
run: |
|
||||
|
@ -104,7 +79,11 @@ jobs:
|
|||
run: |
|
||||
sed -i 's/SigLevel = Required DatabaseOptional/SigLevel = Optional TrustAll/' /etc/pacman.conf
|
||||
pacman --noconfirm --noprogressbar -Syyu
|
||||
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang
|
||||
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang git pixman
|
||||
|
||||
- name: Get hyprutils-git
|
||||
run: |
|
||||
git clone https://github.com/hyprwm/hyprutils && cd hyprutils && cmake -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -B build && cmake --build build --target hyprutils && cmake --install build
|
||||
|
||||
- name: Build with gcc
|
||||
run: |
|
||||
|
@ -131,11 +110,15 @@ jobs:
|
|||
run: |
|
||||
sed -i 's/SigLevel = Required DatabaseOptional/SigLevel = Optional TrustAll/' /etc/pacman.conf
|
||||
pacman --noconfirm --noprogressbar -Syyu
|
||||
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang
|
||||
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang libc++ git pixman
|
||||
|
||||
- name: Get hyprutils-git
|
||||
run: |
|
||||
git clone https://github.com/hyprwm/hyprutils && cd hyprutils && cmake -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -B build && cmake --build build --target hyprutils && cmake --install build
|
||||
|
||||
- name: Build hyprlang with clang
|
||||
run: |
|
||||
CC="/usr/bin/clang" CXX="/usr/bin/clang++" cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -S . -B ./build
|
||||
CC="/usr/bin/clang" CXX="/usr/bin/clang++" cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_CXX_FLAGS="-stdlib=libc++" -S . -B ./build
|
||||
CC="/usr/bin/clang" CXX="/usr/bin/clang++" cmake --build ./build --config Release --target hyprlang -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
|
||||
cmake --install ./build
|
||||
|
||||
|
|
1
.github/workflows/nix.yml
vendored
1
.github/workflows/nix.yml
vendored
|
@ -14,7 +14,6 @@ jobs:
|
|||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: DeterminateSystems/nix-installer-action@main
|
||||
- uses: DeterminateSystems/magic-nix-cache-action@main
|
||||
|
||||
# not needed (yet)
|
||||
# - uses: cachix/cachix-action@v12
|
||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -13,3 +13,4 @@ _deps
|
|||
build/
|
||||
doxygen/
|
||||
doxygen-awesome-css/
|
||||
.cache/
|
|
@ -1,11 +1,12 @@
|
|||
cmake_minimum_required(VERSION 3.19)
|
||||
|
||||
set(HYPRLANG_VERSION "0.4.1")
|
||||
file(READ "${CMAKE_SOURCE_DIR}/VERSION" VER_RAW)
|
||||
string(STRIP ${VER_RAW} HYPRLANG_VERSION)
|
||||
|
||||
project(hyprlang
|
||||
project(
|
||||
hyprlang
|
||||
VERSION ${HYPRLANG_VERSION}
|
||||
DESCRIPTION "A library to parse hypr config files"
|
||||
)
|
||||
DESCRIPTION "A library to parse hypr config files")
|
||||
|
||||
include(CTest)
|
||||
include(GNUInstallDirs)
|
||||
|
@ -16,43 +17,69 @@ set(LIBDIR ${CMAKE_INSTALL_FULL_LIBDIR})
|
|||
|
||||
configure_file(hyprlang.pc.in hyprlang.pc @ONLY)
|
||||
|
||||
if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG)
|
||||
message(STATUS "Configuring hyprlang in Debug")
|
||||
add_compile_definitions(HYPRLAND_DEBUG)
|
||||
else()
|
||||
add_compile_options(-O3)
|
||||
message(STATUS "Configuring hyprlang in Release")
|
||||
endif()
|
||||
|
||||
add_compile_definitions(HYPRLANG_INTERNAL)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
add_compile_options(
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wno-unused-parameter
|
||||
-Wno-missing-field-initializers)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(deps REQUIRED IMPORTED_TARGET hyprutils>=0.7.1)
|
||||
|
||||
file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp" "include/hyprlang.hpp")
|
||||
|
||||
add_library(hyprlang SHARED ${SRCFILES})
|
||||
target_include_directories( hyprlang
|
||||
target_include_directories(
|
||||
hyprlang
|
||||
PUBLIC "./include"
|
||||
PRIVATE "./src"
|
||||
)
|
||||
set_target_properties(hyprlang PROPERTIES
|
||||
VERSION ${HYPRLANG_VERSION}
|
||||
SOVERSION 1
|
||||
PRIVATE "./src")
|
||||
set_target_properties(
|
||||
hyprlang
|
||||
PROPERTIES VERSION ${HYPRLANG_VERSION}
|
||||
SOVERSION 2
|
||||
PUBLIC_HEADER include/hyprlang.hpp)
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
# for std::expected.
|
||||
# probably evil. Arch's clang is very outdated tho...
|
||||
target_compile_options(hyprlang PUBLIC -std=gnu++2b -D__cpp_concepts=202002L -Wno-macro-redefined)
|
||||
endif()
|
||||
target_link_libraries(hyprlang PkgConfig::deps)
|
||||
|
||||
add_library(hypr::hyprlang ALIAS hyprlang)
|
||||
install(TARGETS hyprlang)
|
||||
|
||||
# tests
|
||||
add_custom_target(tests)
|
||||
|
||||
add_executable(hyprlang_test "tests/parse/main.cpp")
|
||||
target_link_libraries(hyprlang_test PRIVATE hyprlang)
|
||||
add_test(NAME "Parsing" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests COMMAND hyprlang_test "parse")
|
||||
target_link_libraries(hyprlang_test PRIVATE hypr::hyprlang)
|
||||
add_test(
|
||||
NAME "Parsing"
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests
|
||||
COMMAND hyprlang_test "parse")
|
||||
add_dependencies(tests hyprlang_test)
|
||||
|
||||
add_executable(hyprlang_fuzz "tests/fuzz/main.cpp")
|
||||
target_link_libraries(hyprlang_fuzz PRIVATE hyprlang)
|
||||
add_test(NAME "Fuzz" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests COMMAND hyprlang_fuzz "fuzz")
|
||||
target_link_libraries(hyprlang_fuzz PRIVATE hypr::hyprlang)
|
||||
add_test(
|
||||
NAME "Fuzz"
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests
|
||||
COMMAND hyprlang_fuzz "fuzz")
|
||||
add_dependencies(tests hyprlang_fuzz)
|
||||
|
||||
# Installation
|
||||
install(TARGETS hyprlang
|
||||
install(
|
||||
TARGETS hyprlang
|
||||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
install(FILES ${CMAKE_BINARY_DIR}/hyprlang.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||
install(FILES ${CMAKE_BINARY_DIR}/hyprlang.pc
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||
|
|
2
COPYRIGHT
Normal file
2
COPYRIGHT
Normal file
|
@ -0,0 +1,2 @@
|
|||
Copyright: Copyright (C) 2023-2024 Hypr Development <vaxry@vaxry.net>
|
||||
License: LGPL-3.0-Only
|
821
LICENSE
821
LICENSE
|
@ -1,674 +1,165 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
|
@ -10,11 +10,11 @@ It's user-friendly, easy to grasp, and easy to implement.
|
|||
Building is done via CMake:
|
||||
```sh
|
||||
cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -S . -B ./build
|
||||
cmake --build ./build --config Release --target hyprlang -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
|
||||
cmake --build ./build --config Release --target hyprlang -j`nproc 2>/dev/null || getconf _NPROCESSORS_CONF`
|
||||
```
|
||||
Install with:
|
||||
```sh
|
||||
cmake --install ./build
|
||||
sudo cmake --install ./build
|
||||
```
|
||||
|
||||
## Example config
|
||||
|
@ -54,4 +54,4 @@ Visit [hyprland.org/hyprlang](https://hyprland.org/hyprlang) to see the document
|
|||
|
||||
### Example implementation
|
||||
|
||||
For an example implmentation, take a look at the `tests/` directory.
|
||||
For an example implementation, take a look at the `tests/` directory.
|
||||
|
|
1
VERSION
Normal file
1
VERSION
Normal file
|
@ -0,0 +1 @@
|
|||
0.6.3
|
30
flake.lock
30
flake.lock
|
@ -1,12 +1,35 @@
|
|||
{
|
||||
"nodes": {
|
||||
"hyprutils": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
],
|
||||
"systems": [
|
||||
"systems"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1746635225,
|
||||
"narHash": "sha256-W9G9bb0zRYDBRseHbVez0J8qVpD5QbizX67H/vsudhM=",
|
||||
"owner": "hyprwm",
|
||||
"repo": "hyprutils",
|
||||
"rev": "674ea57373f08b7609ce93baff131117a0dfe70d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hyprwm",
|
||||
"repo": "hyprutils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1708475490,
|
||||
"narHash": "sha256-g1v0TsWBQPX97ziznfJdWhgMyMGtoBFs102xSYO4syU=",
|
||||
"lastModified": 1746461020,
|
||||
"narHash": "sha256-7+pG1I9jvxNlmln4YgnlW4o+w0TZX24k688mibiFDUE=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "0e74ca98a74bc7270d28838369593635a5db3260",
|
||||
"rev": "3730d8a308f94996a9ba7c7138ede69c1b9ac4ae",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -18,6 +41,7 @@
|
|||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"hyprutils": "hyprutils",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"systems": "systems"
|
||||
}
|
||||
|
|
22
flake.nix
22
flake.nix
|
@ -4,13 +4,20 @@
|
|||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
systems.url = "github:nix-systems/default-linux";
|
||||
|
||||
hyprutils = {
|
||||
url = "github:hyprwm/hyprutils";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
inputs.systems.follows = "systems";
|
||||
};
|
||||
};
|
||||
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
systems,
|
||||
}: let
|
||||
...
|
||||
} @ inputs: let
|
||||
inherit (nixpkgs) lib;
|
||||
eachSystem = lib.genAttrs (import systems);
|
||||
pkgsFor = eachSystem (system:
|
||||
|
@ -23,16 +30,21 @@
|
|||
(builtins.substring 4 2 longDate)
|
||||
(builtins.substring 6 2 longDate)
|
||||
]);
|
||||
|
||||
version = lib.removeSuffix "\n" (builtins.readFile ./VERSION);
|
||||
in {
|
||||
overlays = {
|
||||
default = self.overlays.hyprlang;
|
||||
hyprlang = final: prev: {
|
||||
hyprlang = lib.composeManyExtensions [
|
||||
inputs.hyprutils.overlays.default
|
||||
(final: prev: {
|
||||
hyprlang = final.callPackage ./nix/default.nix {
|
||||
stdenv = final.gcc13Stdenv;
|
||||
version = "0.pre" + "+date=" + (mkDate (self.lastModifiedDate or "19700101")) + "_" + (self.shortRev or "dirty");
|
||||
stdenv = final.gcc14Stdenv;
|
||||
version = version + "+date=" + (mkDate (self.lastModifiedDate or "19700101")) + "_" + (self.shortRev or "dirty");
|
||||
};
|
||||
hyprlang-with-tests = final.hyprlang.override {doCheck = true;};
|
||||
};
|
||||
})
|
||||
];
|
||||
};
|
||||
|
||||
packages = eachSystem (system: {
|
||||
|
|
|
@ -3,16 +3,20 @@
|
|||
#ifndef HYPRLANG_HPP
|
||||
#define HYPRLANG_HPP
|
||||
|
||||
#include <typeindex>
|
||||
#include <any>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
#include <print>
|
||||
#include <cstdlib>
|
||||
|
||||
class CConfigImpl;
|
||||
struct SConfigDefaultValue;
|
||||
struct SSpecialCategory;
|
||||
|
||||
#define HYPRLANG_END_MAGIC 0x1337BEEF
|
||||
|
||||
namespace Hyprlang {
|
||||
|
||||
struct SVector2D;
|
||||
|
@ -94,26 +98,42 @@ namespace Hyprlang {
|
|||
/*!
|
||||
Don't throw errors on missing values.
|
||||
*/
|
||||
bool verifyOnly = false;
|
||||
int verifyOnly = false;
|
||||
|
||||
/*!
|
||||
Return all errors instead of just the first
|
||||
*/
|
||||
bool throwAllErrors = false;
|
||||
int throwAllErrors = false;
|
||||
|
||||
/*!
|
||||
\since 0.2.0
|
||||
|
||||
Don't throw on a missing config file. Carry on as if nothing happened.
|
||||
*/
|
||||
bool allowMissingConfig = false;
|
||||
int allowMissingConfig = false;
|
||||
|
||||
/*!
|
||||
\since 0.4.2
|
||||
|
||||
Treat configPath as a raw config stream.
|
||||
*/
|
||||
int pathIsStream = false;
|
||||
|
||||
// INTERNAL: DO NOT MODIFY
|
||||
int __internal_struct_end = HYPRLANG_END_MAGIC;
|
||||
};
|
||||
|
||||
/*!
|
||||
Generic struct for options for handlers
|
||||
*/
|
||||
struct SHandlerOptions {
|
||||
/*!
|
||||
Allow flags for this handler
|
||||
*/
|
||||
bool allowFlags = false;
|
||||
|
||||
// INTERNAL: DO NOT MODIFY
|
||||
int __internal_struct_end = HYPRLANG_END_MAGIC;
|
||||
};
|
||||
|
||||
/*!
|
||||
|
@ -130,7 +150,7 @@ namespace Hyprlang {
|
|||
/*!
|
||||
don't pop up an error if the config value is missing
|
||||
*/
|
||||
bool ignoreMissing = false;
|
||||
int ignoreMissing = false;
|
||||
|
||||
/*!
|
||||
Make this category an anonymous special one.
|
||||
|
@ -141,7 +161,10 @@ namespace Hyprlang {
|
|||
|
||||
\since 0.4.0
|
||||
*/
|
||||
bool anonymousKeyBased = false;
|
||||
int anonymousKeyBased = false;
|
||||
|
||||
// INTERNAL: DO NOT MODIFY
|
||||
int __internal_struct_end = HYPRLANG_END_MAGIC;
|
||||
};
|
||||
|
||||
/*!
|
||||
|
@ -231,7 +254,7 @@ namespace Hyprlang {
|
|||
/*!
|
||||
Get the contained value as an std::any.
|
||||
For strings, this is a const char*.
|
||||
For custom data types, this is a CConfigCustomValueType*.
|
||||
For custom data types, this is a void* representing the data ptr stored by it.
|
||||
*/
|
||||
std::any getValue() const {
|
||||
switch (m_eType) {
|
||||
|
@ -429,6 +452,93 @@ namespace Hyprlang {
|
|||
void clearState();
|
||||
void applyDefaultsToCat(SSpecialCategory& cat);
|
||||
void retrieveKeysForCat(const char* category, const char*** out, size_t* len);
|
||||
CParseResult parseRawStream(const std::string& stream);
|
||||
};
|
||||
};
|
||||
|
||||
/*!
|
||||
Templated wrapper for Hyprlang values. Much more straightforward to use.
|
||||
|
||||
\since 0.6.0
|
||||
*/
|
||||
template <typename T>
|
||||
class CSimpleConfigValue {
|
||||
public:
|
||||
CSimpleConfigValue(CConfig* const pConfig, const char* val) {
|
||||
const auto VAL = pConfig->getConfigValuePtr(val);
|
||||
|
||||
if (!VAL) {
|
||||
std::println("CSimpleConfigValue: value not found");
|
||||
abort();
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE
|
||||
p_ = VAL->getDataStaticPtr();
|
||||
|
||||
#ifdef HYPRLAND_DEBUG
|
||||
// verify type
|
||||
const auto ANY = VAL->getValue();
|
||||
const auto TYPE = std::type_index(ANY.type());
|
||||
|
||||
// exceptions
|
||||
const bool STRINGEX = (typeid(T) == typeid(std::string) && TYPE == typeid(Hyprlang::STRING));
|
||||
const bool CUSTOMEX = (typeid(T) == typeid(Hyprlang::CUSTOMTYPE) && (TYPE == typeid(Hyprlang::CUSTOMTYPE*) || TYPE == typeid(void*) /* dunno why it does this? */));
|
||||
|
||||
if (typeid(T) != TYPE && !STRINGEX && !CUSTOMEX) {
|
||||
std::println("CSimpleConfigValue: Mismatched type in CConfigValue<T>, got {} but has {}", typeid(T).name(), TYPE.name());
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
T* ptr() const {
|
||||
return *(T* const*)p_;
|
||||
}
|
||||
|
||||
T operator*() const {
|
||||
return *ptr();
|
||||
}
|
||||
|
||||
private:
|
||||
void* const* p_ = nullptr;
|
||||
};
|
||||
|
||||
template <>
|
||||
inline std::string* CSimpleConfigValue<std::string>::ptr() const {
|
||||
std::print("Impossible to implement ptr() of CConfigValue<std::string>");
|
||||
abort();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline std::string CSimpleConfigValue<std::string>::operator*() const {
|
||||
return std::string{*(Hyprlang::STRING*)p_};
|
||||
}
|
||||
|
||||
template <>
|
||||
inline Hyprlang::STRING* CSimpleConfigValue<Hyprlang::STRING>::ptr() const {
|
||||
return (Hyprlang::STRING*)p_;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline Hyprlang::STRING CSimpleConfigValue<Hyprlang::STRING>::operator*() const {
|
||||
return *(Hyprlang::STRING*)p_;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline Hyprlang::CUSTOMTYPE* CSimpleConfigValue<Hyprlang::CUSTOMTYPE>::ptr() const {
|
||||
return *(Hyprlang::CUSTOMTYPE* const*)p_;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline Hyprlang::CUSTOMTYPE CSimpleConfigValue<Hyprlang::CUSTOMTYPE>::operator*() const {
|
||||
std::print("Impossible to implement operator* of CConfigValue<Hyprlang::CUSTOMTYPE>, use ptr()");
|
||||
abort();
|
||||
return *ptr();
|
||||
}
|
||||
};
|
||||
|
||||
#ifndef HYPRLANG_INTERNAL
|
||||
#undef HYPRLANG_END_MAGIC
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -2,6 +2,8 @@
|
|||
lib,
|
||||
stdenv,
|
||||
cmake,
|
||||
hyprutils,
|
||||
pkg-config,
|
||||
version ? "git",
|
||||
doCheck ? false,
|
||||
}:
|
||||
|
@ -10,14 +12,19 @@ stdenv.mkDerivation {
|
|||
inherit version doCheck;
|
||||
src = ../.;
|
||||
|
||||
nativeBuildInputs = [cmake];
|
||||
nativeBuildInputs = [
|
||||
cmake
|
||||
pkg-config
|
||||
];
|
||||
|
||||
buildInputs = [hyprutils];
|
||||
|
||||
outputs = ["out" "dev"];
|
||||
|
||||
meta = with lib; {
|
||||
homepage = "https://github.com/hyprwm/hyprlang";
|
||||
description = "The official implementation library for the hypr config language";
|
||||
license = licenses.gpl3Plus;
|
||||
license = licenses.lgpl3Only;
|
||||
platforms = platforms.linux;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "public.hpp"
|
||||
#include "config.hpp"
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
|
||||
using namespace Hyprlang;
|
||||
|
||||
|
@ -30,38 +30,28 @@ CConfigValue::~CConfigValue() {
|
|||
}
|
||||
}
|
||||
|
||||
CConfigValue::CConfigValue(const int64_t value) {
|
||||
m_pData = new int64_t;
|
||||
CConfigValue::CConfigValue(const int64_t value) : m_eType(CONFIGDATATYPE_INT), m_pData(new int64_t) {
|
||||
*reinterpret_cast<int64_t*>(m_pData) = value;
|
||||
m_eType = CONFIGDATATYPE_INT;
|
||||
}
|
||||
|
||||
CConfigValue::CConfigValue(const float value) {
|
||||
m_pData = new float;
|
||||
CConfigValue::CConfigValue(const float value) : m_eType(CONFIGDATATYPE_FLOAT), m_pData(new float) {
|
||||
*reinterpret_cast<float*>(m_pData) = value;
|
||||
m_eType = CONFIGDATATYPE_FLOAT;
|
||||
}
|
||||
|
||||
CConfigValue::CConfigValue(const SVector2D value) {
|
||||
m_pData = new SVector2D;
|
||||
CConfigValue::CConfigValue(const SVector2D value) : m_eType(CONFIGDATATYPE_VEC2), m_pData(new SVector2D) {
|
||||
*reinterpret_cast<SVector2D*>(m_pData) = value;
|
||||
m_eType = CONFIGDATATYPE_VEC2;
|
||||
}
|
||||
|
||||
CConfigValue::CConfigValue(const char* value) {
|
||||
m_pData = new char[strlen(value) + 1];
|
||||
CConfigValue::CConfigValue(const char* value) : m_eType(CONFIGDATATYPE_STR), m_pData(new char[strlen(value) + 1]) {
|
||||
strncpy((char*)m_pData, value, strlen(value));
|
||||
((char*)m_pData)[strlen(value)] = '\0';
|
||||
m_eType = CONFIGDATATYPE_STR;
|
||||
}
|
||||
|
||||
CConfigValue::CConfigValue(CConfigCustomValueType&& value) {
|
||||
m_pData = new CConfigCustomValueType(value);
|
||||
m_eType = CONFIGDATATYPE_CUSTOM;
|
||||
CConfigValue::CConfigValue(CConfigCustomValueType&& value) : m_eType(CONFIGDATATYPE_CUSTOM), m_pData(new CConfigCustomValueType(value)) {
|
||||
;
|
||||
}
|
||||
|
||||
CConfigValue::CConfigValue(const CConfigValue& other) {
|
||||
m_eType = other.m_eType;
|
||||
CConfigValue::CConfigValue(const CConfigValue& other) : m_eType(other.m_eType) {
|
||||
setFrom(&other);
|
||||
}
|
||||
|
||||
|
@ -77,11 +67,9 @@ void* const* CConfigValue::getDataStaticPtr() const {
|
|||
return &m_pData;
|
||||
}
|
||||
|
||||
CConfigCustomValueType::CConfigCustomValueType(PCONFIGCUSTOMVALUEHANDLERFUNC handler_, PCONFIGCUSTOMVALUEDESTRUCTOR dtor_, const char* def) {
|
||||
handler = handler_;
|
||||
dtor = dtor_;
|
||||
defaultVal = def;
|
||||
lastVal = def;
|
||||
CConfigCustomValueType::CConfigCustomValueType(PCONFIGCUSTOMVALUEHANDLERFUNC handler_, PCONFIGCUSTOMVALUEDESTRUCTOR dtor_, const char* def) :
|
||||
handler(handler_), dtor(dtor_), defaultVal(def), lastVal(def) {
|
||||
;
|
||||
}
|
||||
|
||||
CConfigCustomValueType::~CConfigCustomValueType() {
|
||||
|
|
473
src/config.cpp
473
src/config.cpp
|
@ -1,43 +1,77 @@
|
|||
#include "config.hpp"
|
||||
#include <exception>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <format>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <expected>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include <hyprutils/string/VarList.hpp>
|
||||
#include <hyprutils/string/String.hpp>
|
||||
#include <hyprutils/string/ConstVarList.hpp>
|
||||
|
||||
using namespace Hyprlang;
|
||||
using namespace Hyprutils::String;
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <crt_externs.h>
|
||||
#define environ (*_NSGetEnviron())
|
||||
#else
|
||||
// NOLINTNEXTLINE
|
||||
extern "C" char** environ;
|
||||
#endif
|
||||
|
||||
// defines
|
||||
inline constexpr const char* ANONYMOUS_KEY = "__hyprlang_internal_anonymous_key";
|
||||
inline constexpr const char* MULTILINE_SPACE_CHARSET = " \t";
|
||||
//
|
||||
|
||||
static std::string removeBeginEndSpacesTabs(std::string str) {
|
||||
if (str.empty())
|
||||
return str;
|
||||
|
||||
int countBefore = 0;
|
||||
while (str[countBefore] == ' ' || str[countBefore] == '\t') {
|
||||
countBefore++;
|
||||
static size_t seekABIStructSize(const void* begin, size_t startOffset, size_t maxSize) {
|
||||
for (size_t off = startOffset; off < maxSize; off += 4) {
|
||||
if (*(int*)((unsigned char*)begin + off) == HYPRLANG_END_MAGIC)
|
||||
return off;
|
||||
}
|
||||
|
||||
int countAfter = 0;
|
||||
while ((int)str.length() - countAfter - 1 >= 0 && (str[str.length() - countAfter - 1] == ' ' || str[str.length() - 1 - countAfter] == '\t')) {
|
||||
countAfter++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
str = str.substr(countBefore, str.length() - countBefore - countAfter);
|
||||
static std::expected<std::string, eGetNextLineFailure> getNextLine(std::istream& str, int& rawLineNum, int& lineNum) {
|
||||
std::string line = "";
|
||||
std::string nextLine = "";
|
||||
|
||||
return str;
|
||||
if (!std::getline(str, line))
|
||||
return std::unexpected(GETNEXTLINEFAILURE_EOF);
|
||||
|
||||
lineNum = ++rawLineNum;
|
||||
|
||||
while (line.length() > 0 && line.at(line.length() - 1) == '\\') {
|
||||
const auto lastNonSpace = line.length() < 2 ? -1 : line.find_last_not_of(MULTILINE_SPACE_CHARSET, line.length() - 2);
|
||||
line = line.substr(0, lastNonSpace + 1);
|
||||
|
||||
if (!std::getline(str, nextLine))
|
||||
return std::unexpected(GETNEXTLINEFAILURE_BACKSLASH);
|
||||
|
||||
++rawLineNum;
|
||||
line += nextLine;
|
||||
}
|
||||
|
||||
CConfig::CConfig(const char* path, const Hyprlang::SConfigOptions& options) {
|
||||
impl = new CConfigImpl;
|
||||
return line;
|
||||
}
|
||||
|
||||
CConfig::CConfig(const char* path, const Hyprlang::SConfigOptions& options_) : impl(new CConfigImpl) {
|
||||
SConfigOptions options;
|
||||
std::memcpy(&options, &options_, seekABIStructSize(&options_, 16, sizeof(SConfigOptions)));
|
||||
|
||||
if (options.pathIsStream)
|
||||
impl->rawConfigString = path;
|
||||
else
|
||||
impl->path = path;
|
||||
|
||||
if (!std::filesystem::exists(impl->path)) {
|
||||
if (!options.pathIsStream && !std::filesystem::exists(impl->path)) {
|
||||
if (!options.allowMissingConfig)
|
||||
throw "File does not exist";
|
||||
}
|
||||
|
@ -50,7 +84,7 @@ CConfig::CConfig(const char* path, const Hyprlang::SConfigOptions& options) {
|
|||
impl->envVariables.push_back({VARIABLE, VALUE});
|
||||
}
|
||||
|
||||
std::sort(impl->envVariables.begin(), impl->envVariables.end(), [&](const auto& a, const auto& b) { return a.name.length() > b.name.length(); });
|
||||
std::ranges::sort(impl->envVariables, [&](const auto& a, const auto& b) { return a.name.length() > b.name.length(); });
|
||||
|
||||
impl->configOptions = options;
|
||||
}
|
||||
|
@ -64,40 +98,42 @@ void CConfig::addConfigValue(const char* name, const CConfigValue& value) {
|
|||
throw "Cannot addConfigValue after commence()";
|
||||
|
||||
if ((eDataType)value.m_eType != CONFIGDATATYPE_CUSTOM && (eDataType)value.m_eType != CONFIGDATATYPE_STR)
|
||||
impl->defaultValues.emplace(name, SConfigDefaultValue{value.getValue(), (eDataType)value.m_eType});
|
||||
impl->defaultValues.emplace(name, SConfigDefaultValue{.data = value.getValue(), .type = (eDataType)value.m_eType});
|
||||
else if ((eDataType)value.m_eType == CONFIGDATATYPE_STR)
|
||||
impl->defaultValues.emplace(name, SConfigDefaultValue{std::string{std::any_cast<const char*>(value.getValue())}, (eDataType)value.m_eType});
|
||||
impl->defaultValues.emplace(name, SConfigDefaultValue{.data = std::string{std::any_cast<const char*>(value.getValue())}, .type = (eDataType)value.m_eType});
|
||||
else
|
||||
impl->defaultValues.emplace(name,
|
||||
SConfigDefaultValue{reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->defaultVal, (eDataType)value.m_eType,
|
||||
reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->handler,
|
||||
reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->dtor});
|
||||
SConfigDefaultValue{.data = reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->defaultVal,
|
||||
.type = (eDataType)value.m_eType,
|
||||
.handler = reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->handler,
|
||||
.dtor = reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->dtor});
|
||||
}
|
||||
|
||||
void CConfig::addSpecialConfigValue(const char* cat, const char* name, const CConfigValue& value) {
|
||||
const auto IT = std::find_if(impl->specialCategoryDescriptors.begin(), impl->specialCategoryDescriptors.end(), [&](const auto& other) { return other->name == cat; });
|
||||
const auto IT = std::ranges::find_if(impl->specialCategoryDescriptors, [&](const auto& other) { return other->name == cat; });
|
||||
|
||||
if (IT == impl->specialCategoryDescriptors.end())
|
||||
throw "No such category";
|
||||
|
||||
if ((eDataType)value.m_eType != CONFIGDATATYPE_CUSTOM && (eDataType)value.m_eType != CONFIGDATATYPE_STR)
|
||||
IT->get()->defaultValues.emplace(name, SConfigDefaultValue{value.getValue(), (eDataType)value.m_eType});
|
||||
IT->get()->defaultValues.emplace(name, SConfigDefaultValue{.data = value.getValue(), .type = (eDataType)value.m_eType});
|
||||
else if ((eDataType)value.m_eType == CONFIGDATATYPE_STR)
|
||||
IT->get()->defaultValues.emplace(name, SConfigDefaultValue{std::string{std::any_cast<const char*>(value.getValue())}, (eDataType)value.m_eType});
|
||||
IT->get()->defaultValues.emplace(name, SConfigDefaultValue{.data = std::string{std::any_cast<const char*>(value.getValue())}, .type = (eDataType)value.m_eType});
|
||||
else
|
||||
IT->get()->defaultValues.emplace(name,
|
||||
SConfigDefaultValue{reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->defaultVal, (eDataType)value.m_eType,
|
||||
reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->handler,
|
||||
reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->dtor});
|
||||
SConfigDefaultValue{.data = reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->defaultVal,
|
||||
.type = (eDataType)value.m_eType,
|
||||
.handler = reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->handler,
|
||||
.dtor = reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->dtor});
|
||||
|
||||
const auto CAT = std::find_if(impl->specialCategories.begin(), impl->specialCategories.end(), [cat, name](const auto& other) { return other->name == cat && other->isStatic; });
|
||||
const auto CAT = std::ranges::find_if(impl->specialCategories, [cat](const auto& other) { return other->name == cat && other->isStatic; });
|
||||
|
||||
if (CAT != impl->specialCategories.end())
|
||||
CAT->get()->values[name].defaultFrom(IT->get()->defaultValues[name]);
|
||||
}
|
||||
|
||||
void CConfig::removeSpecialConfigValue(const char* cat, const char* name) {
|
||||
const auto IT = std::find_if(impl->specialCategoryDescriptors.begin(), impl->specialCategoryDescriptors.end(), [&](const auto& other) { return other->name == cat; });
|
||||
const auto IT = std::ranges::find_if(impl->specialCategoryDescriptors, [&](const auto& other) { return other->name == cat; });
|
||||
|
||||
if (IT == impl->specialCategoryDescriptors.end())
|
||||
throw "No such category";
|
||||
|
@ -105,7 +141,10 @@ void CConfig::removeSpecialConfigValue(const char* cat, const char* name) {
|
|||
std::erase_if(IT->get()->defaultValues, [name](const auto& other) { return other.first == name; });
|
||||
}
|
||||
|
||||
void CConfig::addSpecialCategory(const char* name, SSpecialCategoryOptions options) {
|
||||
void CConfig::addSpecialCategory(const char* name, SSpecialCategoryOptions options_) {
|
||||
SSpecialCategoryOptions options;
|
||||
std::memcpy(&options, &options_, seekABIStructSize(&options_, 8, sizeof(SSpecialCategoryOptions)));
|
||||
|
||||
const auto PDESC = impl->specialCategoryDescriptors.emplace_back(std::make_unique<SSpecialCategoryDescriptor>()).get();
|
||||
PDESC->name = name;
|
||||
PDESC->key = options.key ? options.key : "";
|
||||
|
@ -125,9 +164,8 @@ void CConfig::addSpecialCategory(const char* name, SSpecialCategoryOptions optio
|
|||
}
|
||||
|
||||
// sort longest to shortest
|
||||
std::sort(impl->specialCategories.begin(), impl->specialCategories.end(), [](const auto& a, const auto& b) -> int { return a->name.length() > b->name.length(); });
|
||||
std::sort(impl->specialCategoryDescriptors.begin(), impl->specialCategoryDescriptors.end(),
|
||||
[](const auto& a, const auto& b) -> int { return a->name.length() > b->name.length(); });
|
||||
std::ranges::sort(impl->specialCategories, [](const auto& a, const auto& b) -> int { return a->name.length() > b->name.length(); });
|
||||
std::ranges::sort(impl->specialCategoryDescriptors, [](const auto& a, const auto& b) -> int { return a->name.length() > b->name.length(); });
|
||||
}
|
||||
|
||||
void CConfig::removeSpecialCategory(const char* name) {
|
||||
|
@ -148,98 +186,77 @@ void CConfig::commence() {
|
|||
}
|
||||
}
|
||||
|
||||
static bool isNumber(const std::string& str, bool allowfloat) {
|
||||
|
||||
std::string copy = str;
|
||||
if (*copy.begin() == '-')
|
||||
copy = copy.substr(1);
|
||||
|
||||
if (copy.empty())
|
||||
return false;
|
||||
|
||||
bool point = !allowfloat;
|
||||
for (auto& c : copy) {
|
||||
if (c == '.') {
|
||||
if (point)
|
||||
return false;
|
||||
point = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!std::isdigit(c))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void replaceAll(std::string& str, const std::string& from, const std::string& to) {
|
||||
if (from.empty())
|
||||
return;
|
||||
size_t pos = 0;
|
||||
while ((pos = str.find(from, pos)) != std::string::npos) {
|
||||
str.replace(pos, from.length(), to);
|
||||
pos += to.length();
|
||||
}
|
||||
}
|
||||
|
||||
static std::expected<int64_t, std::string> configStringToInt(const std::string& VALUE) {
|
||||
auto parseHex = [](const std::string& value) -> std::expected<int64_t, std::string> {
|
||||
try {
|
||||
size_t position;
|
||||
auto result = stoll(value, &position, 16);
|
||||
if (position == value.size())
|
||||
return result;
|
||||
} catch (const std::exception&) {}
|
||||
return std::unexpected("invalid hex " + value);
|
||||
};
|
||||
if (VALUE.starts_with("0x")) {
|
||||
// Values with 0x are hex
|
||||
const auto VALUEWITHOUTHEX = VALUE.substr(2);
|
||||
return stoll(VALUEWITHOUTHEX, nullptr, 16);
|
||||
return parseHex(VALUE);
|
||||
} else if (VALUE.starts_with("rgba(") && VALUE.ends_with(')')) {
|
||||
const auto VALUEWITHOUTFUNC = removeBeginEndSpacesTabs(VALUE.substr(5, VALUE.length() - 6));
|
||||
const auto VALUEWITHOUTFUNC = trim(VALUE.substr(5, VALUE.length() - 6));
|
||||
|
||||
// try doing it the comma way first
|
||||
if (std::count(VALUEWITHOUTFUNC.begin(), VALUEWITHOUTFUNC.end(), ',') == 3) {
|
||||
// cool
|
||||
std::string rolling = VALUEWITHOUTFUNC;
|
||||
auto r = configStringToInt(removeBeginEndSpacesTabs(rolling.substr(0, rolling.find(','))));
|
||||
auto r = configStringToInt(trim(rolling.substr(0, rolling.find(','))));
|
||||
rolling = rolling.substr(rolling.find(',') + 1);
|
||||
auto g = configStringToInt(removeBeginEndSpacesTabs(rolling.substr(0, rolling.find(','))));
|
||||
auto g = configStringToInt(trim(rolling.substr(0, rolling.find(','))));
|
||||
rolling = rolling.substr(rolling.find(',') + 1);
|
||||
auto b = configStringToInt(removeBeginEndSpacesTabs(rolling.substr(0, rolling.find(','))));
|
||||
auto b = configStringToInt(trim(rolling.substr(0, rolling.find(','))));
|
||||
rolling = rolling.substr(rolling.find(',') + 1);
|
||||
uint8_t a = 0;
|
||||
try {
|
||||
a = std::round(std::stof(removeBeginEndSpacesTabs(rolling.substr(0, rolling.find(',')))) * 255.f);
|
||||
a = std::round(std::stof(trim(rolling.substr(0, rolling.find(',')))) * 255.f);
|
||||
} catch (std::exception& e) { return std::unexpected("failed parsing " + VALUEWITHOUTFUNC); }
|
||||
|
||||
if (!r.has_value() || !g.has_value() || !b.has_value())
|
||||
return std::unexpected("failed parsing " + VALUEWITHOUTFUNC);
|
||||
|
||||
return a * (Hyprlang::INT)0x1000000 + r.value() * (Hyprlang::INT)0x10000 + g.value() * (Hyprlang::INT)0x100 + b.value();
|
||||
return (a * (Hyprlang::INT)0x1000000) + (r.value() * (Hyprlang::INT)0x10000) + (g.value() * (Hyprlang::INT)0x100) + b.value();
|
||||
} else if (VALUEWITHOUTFUNC.length() == 8) {
|
||||
const auto RGBA = std::stoll(VALUEWITHOUTFUNC, nullptr, 16);
|
||||
const auto RGBA = parseHex(VALUEWITHOUTFUNC);
|
||||
|
||||
if (!RGBA.has_value())
|
||||
return RGBA;
|
||||
|
||||
// now we need to RGBA -> ARGB. The config holds ARGB only.
|
||||
return (RGBA >> 8) + 0x1000000 * (RGBA & 0xFF);
|
||||
return (RGBA.value() >> 8) + (0x1000000 * (RGBA.value() & 0xFF));
|
||||
}
|
||||
|
||||
return std::unexpected("rgba() expects length of 8 characters (4 bytes) or 4 comma separated values");
|
||||
|
||||
} else if (VALUE.starts_with("rgb(") && VALUE.ends_with(')')) {
|
||||
const auto VALUEWITHOUTFUNC = removeBeginEndSpacesTabs(VALUE.substr(4, VALUE.length() - 5));
|
||||
const auto VALUEWITHOUTFUNC = trim(VALUE.substr(4, VALUE.length() - 5));
|
||||
|
||||
// try doing it the comma way first
|
||||
if (std::count(VALUEWITHOUTFUNC.begin(), VALUEWITHOUTFUNC.end(), ',') == 2) {
|
||||
// cool
|
||||
std::string rolling = VALUEWITHOUTFUNC;
|
||||
auto r = configStringToInt(removeBeginEndSpacesTabs(rolling.substr(0, rolling.find(','))));
|
||||
auto r = configStringToInt(trim(rolling.substr(0, rolling.find(','))));
|
||||
rolling = rolling.substr(rolling.find(',') + 1);
|
||||
auto g = configStringToInt(removeBeginEndSpacesTabs(rolling.substr(0, rolling.find(','))));
|
||||
auto g = configStringToInt(trim(rolling.substr(0, rolling.find(','))));
|
||||
rolling = rolling.substr(rolling.find(',') + 1);
|
||||
auto b = configStringToInt(removeBeginEndSpacesTabs(rolling.substr(0, rolling.find(','))));
|
||||
auto b = configStringToInt(trim(rolling.substr(0, rolling.find(','))));
|
||||
|
||||
if (!r.has_value() || !g.has_value() || !b.has_value())
|
||||
return std::unexpected("failed parsing " + VALUEWITHOUTFUNC);
|
||||
|
||||
return (Hyprlang::INT)0xFF000000 + r.value() * (Hyprlang::INT)0x10000 + g.value() * (Hyprlang::INT)0x100 + b.value();
|
||||
return (Hyprlang::INT)0xFF000000 + (r.value() * (Hyprlang::INT)0x10000) + (g.value() * (Hyprlang::INT)0x100) + b.value();
|
||||
} else if (VALUEWITHOUTFUNC.length() == 6) {
|
||||
const auto RGB = std::stoll(VALUEWITHOUTFUNC, nullptr, 16);
|
||||
const auto RGB = parseHex(VALUEWITHOUTFUNC);
|
||||
|
||||
return RGB + 0xFF000000;
|
||||
if (!RGB.has_value())
|
||||
return RGB;
|
||||
|
||||
return RGB.value() + 0xFF000000;
|
||||
}
|
||||
|
||||
return std::unexpected("rgb() expects length of 6 characters (3 bytes) or 3 comma separated values");
|
||||
|
@ -264,13 +281,45 @@ CParseResult CConfig::configSetValueSafe(const std::string& command, const std::
|
|||
CParseResult result;
|
||||
|
||||
std::string valueName;
|
||||
std::string catPrefix;
|
||||
for (auto& c : impl->categories) {
|
||||
valueName += c + ':';
|
||||
catPrefix += c + ':';
|
||||
}
|
||||
|
||||
valueName += command;
|
||||
|
||||
const auto VALUEONLYNAME = valueName.contains(":") ? valueName.substr(valueName.find_last_of(':') + 1) : valueName;
|
||||
const auto VALUEONLYNAME = command.starts_with(catPrefix) ? command.substr(catPrefix.length()) : command;
|
||||
|
||||
// FIXME: this will bug with nested.
|
||||
if (valueName.contains('[') && valueName.contains(']')) {
|
||||
const auto L = valueName.find_first_of('[');
|
||||
const auto R = valueName.find_last_of(']');
|
||||
|
||||
if (L < R) {
|
||||
const auto CATKEY = valueName.substr(L + 1, R - L - 1);
|
||||
impl->currentSpecialKey = CATKEY;
|
||||
|
||||
valueName = valueName.substr(0, L) + valueName.substr(R + 1);
|
||||
|
||||
// if it doesn't exist, make it
|
||||
for (auto& sc : impl->specialCategoryDescriptors) {
|
||||
if (sc->key.empty() || !valueName.starts_with(sc->name))
|
||||
continue;
|
||||
|
||||
// bingo
|
||||
const auto PCAT = impl->specialCategories.emplace_back(std::make_unique<SSpecialCategory>()).get();
|
||||
PCAT->descriptor = sc.get();
|
||||
PCAT->name = sc->name;
|
||||
PCAT->key = sc->key;
|
||||
addSpecialConfigValue(sc->name.c_str(), sc->key.c_str(), CConfigValue(CATKEY.c_str()));
|
||||
|
||||
applyDefaultsToCat(*PCAT);
|
||||
|
||||
PCAT->values[sc->key].setFrom(CATKEY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto VALUEIT = impl->values.find(valueName);
|
||||
if (VALUEIT == impl->values.end()) {
|
||||
|
@ -333,8 +382,7 @@ CParseResult CConfig::configSetValueSafe(const std::string& command, const std::
|
|||
// find suitable key
|
||||
size_t biggest = 0;
|
||||
for (auto& catt : impl->specialCategories) {
|
||||
if (catt->anonymousID > biggest)
|
||||
biggest = catt->anonymousID;
|
||||
biggest = std::max(catt->anonymousID, biggest);
|
||||
}
|
||||
|
||||
biggest++;
|
||||
|
@ -393,7 +441,7 @@ CParseResult CConfig::configSetValueSafe(const std::string& command, const std::
|
|||
if (LHS.contains(" ") || RHS.contains(" "))
|
||||
throw std::runtime_error("too many args");
|
||||
|
||||
VALUEIT->second.setFrom(SVector2D{std::stof(LHS), std::stof(RHS)});
|
||||
VALUEIT->second.setFrom(SVector2D{.x = std::stof(LHS), .y = std::stof(RHS)});
|
||||
} catch (std::exception& e) {
|
||||
result.setError(std::format("failed parsing a vec2: {}", e.what()));
|
||||
return result;
|
||||
|
@ -427,14 +475,14 @@ CParseResult CConfig::configSetValueSafe(const std::string& command, const std::
|
|||
}
|
||||
|
||||
CParseResult CConfig::parseVariable(const std::string& lhs, const std::string& rhs, bool dynamic) {
|
||||
auto IT = std::find_if(impl->variables.begin(), impl->variables.end(), [&](const auto& v) { return v.name == lhs.substr(1); });
|
||||
auto IT = std::ranges::find_if(impl->variables, [&](const auto& v) { return v.name == lhs.substr(1); });
|
||||
|
||||
if (IT != impl->variables.end())
|
||||
IT->value = rhs;
|
||||
else {
|
||||
impl->variables.push_back({lhs.substr(1), rhs});
|
||||
std::sort(impl->variables.begin(), impl->variables.end(), [](const auto& lhs, const auto& rhs) { return lhs.name.length() > rhs.name.length(); });
|
||||
IT = std::find_if(impl->variables.begin(), impl->variables.end(), [&](const auto& v) { return v.name == lhs.substr(1); });
|
||||
std::ranges::sort(impl->variables, [](const auto& lhs, const auto& rhs) { return lhs.name.length() > rhs.name.length(); });
|
||||
IT = std::ranges::find_if(impl->variables, [&](const auto& v) { return v.name == lhs.substr(1); });
|
||||
}
|
||||
|
||||
if (dynamic) {
|
||||
|
@ -451,10 +499,80 @@ CParseResult CConfig::parseVariable(const std::string& lhs, const std::string& r
|
|||
return result;
|
||||
}
|
||||
|
||||
void CConfigImpl::parseComment(const std::string& comment) {
|
||||
const auto COMMENT = trim(comment);
|
||||
|
||||
if (!COMMENT.starts_with("hyprlang"))
|
||||
return;
|
||||
|
||||
CVarList args(COMMENT, 0, 's', true);
|
||||
|
||||
if (args[1] == "noerror")
|
||||
currentFlags.noError = args[2] == "true" || args[2] == "yes" || args[2] == "enable" || args[2] == "enabled" || args[2] == "set";
|
||||
}
|
||||
|
||||
std::expected<float, std::string> CConfigImpl::parseExpression(const std::string& s) {
|
||||
// for now, we only support very basic expressions.
|
||||
// + - * / and only one per $()
|
||||
// TODO: something better
|
||||
|
||||
if (s.empty())
|
||||
return std::unexpected("Expression is empty");
|
||||
|
||||
CConstVarList args(s, 0, 's', true);
|
||||
|
||||
if (args[1] != "+" && args[1] != "-" && args[1] != "*" && args[1] != "/")
|
||||
return std::unexpected("Invalid expression type: supported +, -, *, /");
|
||||
|
||||
auto LHS_VAR = std::ranges::find_if(variables, [&](const auto& v) { return v.name == args[0]; });
|
||||
auto RHS_VAR = std::ranges::find_if(variables, [&](const auto& v) { return v.name == args[2]; });
|
||||
|
||||
float left = 0;
|
||||
float right = 0;
|
||||
|
||||
if (LHS_VAR != variables.end()) {
|
||||
try {
|
||||
left = std::stof(LHS_VAR->value);
|
||||
} catch (...) { return std::unexpected("Failed to parse expression: value 1 holds a variable that does not look like a number"); }
|
||||
} else {
|
||||
try {
|
||||
left = std::stof(std::string{args[0]});
|
||||
} catch (...) { return std::unexpected("Failed to parse expression: value 1 does not look like a number or the variable doesn't exist"); }
|
||||
}
|
||||
|
||||
if (RHS_VAR != variables.end()) {
|
||||
try {
|
||||
right = std::stof(RHS_VAR->value);
|
||||
} catch (...) { return std::unexpected("Failed to parse expression: value 1 holds a variable that does not look like a number"); }
|
||||
} else {
|
||||
try {
|
||||
right = std::stof(std::string{args[2]});
|
||||
} catch (...) { return std::unexpected("Failed to parse expression: value 1 does not look like a number or the variable doesn't exist"); }
|
||||
}
|
||||
|
||||
switch (args[1][0]) {
|
||||
case '+': return left + right;
|
||||
case '-': return left - right;
|
||||
case '*': return left * right;
|
||||
case '/': return left / right;
|
||||
default: break;
|
||||
}
|
||||
|
||||
return std::unexpected("Unknown error while parsing expression");
|
||||
}
|
||||
|
||||
CParseResult CConfig::parseLine(std::string line, bool dynamic) {
|
||||
CParseResult result;
|
||||
|
||||
line = trim(line);
|
||||
|
||||
auto commentPos = line.find('#');
|
||||
|
||||
if (commentPos == 0) {
|
||||
impl->parseComment(line.substr(1));
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t lastHashPos = 0;
|
||||
|
||||
while (commentPos != std::string::npos) {
|
||||
|
@ -475,11 +593,14 @@ CParseResult CConfig::parseLine(std::string line, bool dynamic) {
|
|||
}
|
||||
}
|
||||
|
||||
line = removeBeginEndSpacesTabs(line);
|
||||
line = trim(line);
|
||||
|
||||
if (line.empty())
|
||||
return result;
|
||||
|
||||
auto equalsPos = line.find('=');
|
||||
|
||||
if (equalsPos == std::string::npos && !line.ends_with("{") && line != "}" && !line.empty()) {
|
||||
if (equalsPos == std::string::npos && !line.ends_with("{") && line != "}") {
|
||||
// invalid line
|
||||
result.setError("Invalid config line");
|
||||
return result;
|
||||
|
@ -488,37 +609,57 @@ CParseResult CConfig::parseLine(std::string line, bool dynamic) {
|
|||
if (equalsPos != std::string::npos) {
|
||||
// set value or call handler
|
||||
CParseResult ret;
|
||||
auto LHS = removeBeginEndSpacesTabs(line.substr(0, equalsPos));
|
||||
auto RHS = removeBeginEndSpacesTabs(line.substr(equalsPos + 1));
|
||||
auto LHS = trim(line.substr(0, equalsPos));
|
||||
auto RHS = trim(line.substr(equalsPos + 1));
|
||||
|
||||
if (LHS.empty()) {
|
||||
result.setError("Empty lhs.");
|
||||
return result;
|
||||
}
|
||||
|
||||
if (*LHS.begin() == '$')
|
||||
return parseVariable(LHS, RHS, dynamic);
|
||||
const bool ISVARIABLE = *LHS.begin() == '$';
|
||||
|
||||
// limit unwrapping iterations to 100. if exceeds, raise error
|
||||
for (size_t i = 0; i < 100; ++i) {
|
||||
bool anyMatch = false;
|
||||
|
||||
// parse variables
|
||||
for (auto& var : impl->variables) {
|
||||
const auto LHSIT = LHS.find("$" + var.name);
|
||||
// don't parse LHS variables if this is a variable...
|
||||
const auto LHSIT = ISVARIABLE ? std::string::npos : LHS.find("$" + var.name);
|
||||
const auto RHSIT = RHS.find("$" + var.name);
|
||||
|
||||
if (LHSIT != std::string::npos)
|
||||
replaceAll(LHS, "$" + var.name, var.value);
|
||||
replaceInString(LHS, "$" + var.name, var.value);
|
||||
if (RHSIT != std::string::npos)
|
||||
replaceAll(RHS, "$" + var.name, var.value);
|
||||
replaceInString(RHS, "$" + var.name, var.value);
|
||||
|
||||
if (RHSIT == std::string::npos && LHSIT == std::string::npos)
|
||||
continue;
|
||||
else
|
||||
else if (!dynamic)
|
||||
var.linesContainingVar.push_back({line, impl->categories, impl->currentSpecialCategory});
|
||||
|
||||
anyMatch = true;
|
||||
}
|
||||
|
||||
// parse expressions $(somevar + 2)
|
||||
// We only support single expressions for now
|
||||
while (RHS.contains("{{")) {
|
||||
const auto BEGIN_EXPR = RHS.find("{{");
|
||||
const auto END_EXPR = RHS.find("}}", BEGIN_EXPR + 2);
|
||||
if (END_EXPR != std::string::npos) {
|
||||
// try to parse the expression
|
||||
const auto RESULT = impl->parseExpression(RHS.substr(BEGIN_EXPR + 2, END_EXPR - BEGIN_EXPR - 2));
|
||||
if (!RESULT.has_value()) {
|
||||
result.setError(RESULT.error());
|
||||
return result;
|
||||
}
|
||||
|
||||
RHS = RHS.substr(0, BEGIN_EXPR) + std::format("{}", RESULT.value()) + RHS.substr(END_EXPR + 2);
|
||||
} else
|
||||
break;
|
||||
}
|
||||
|
||||
if (!anyMatch)
|
||||
break;
|
||||
|
||||
|
@ -528,12 +669,42 @@ CParseResult CConfig::parseLine(std::string line, bool dynamic) {
|
|||
}
|
||||
}
|
||||
|
||||
if (ISVARIABLE)
|
||||
return parseVariable(LHS, RHS, dynamic);
|
||||
|
||||
bool found = false;
|
||||
|
||||
for (auto& h : impl->handlers) {
|
||||
if (!h.options.allowFlags && h.name != LHS)
|
||||
// we want to handle potentially nested keywords and ensure
|
||||
// we only call the handler if they are scoped correctly,
|
||||
// unless the keyword is not scoped itself
|
||||
|
||||
const bool UNSCOPED = !h.name.contains(":");
|
||||
const auto HANDLERNAME = !h.name.empty() && h.name.at(0) == ':' ? h.name.substr(1) : h.name;
|
||||
|
||||
if (!h.options.allowFlags && !UNSCOPED) {
|
||||
size_t colon = 0;
|
||||
size_t idx = 0;
|
||||
size_t depth = 0;
|
||||
|
||||
while ((colon = HANDLERNAME.find(':', idx)) != std::string::npos && impl->categories.size() > depth) {
|
||||
auto actual = HANDLERNAME.substr(idx, colon - idx);
|
||||
|
||||
if (actual != impl->categories[depth])
|
||||
break;
|
||||
|
||||
idx = colon + 1;
|
||||
++depth;
|
||||
}
|
||||
|
||||
if (depth != impl->categories.size() || HANDLERNAME.substr(idx) != LHS)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (UNSCOPED && HANDLERNAME != LHS && !h.options.allowFlags)
|
||||
continue;
|
||||
|
||||
if (h.options.allowFlags && !LHS.starts_with(h.name))
|
||||
if (h.options.allowFlags && (!LHS.starts_with(HANDLERNAME) || LHS.contains(':') /* avoid cases where a category is called the same as a handler */))
|
||||
continue;
|
||||
|
||||
ret = h.func(LHS.c_str(), RHS.c_str());
|
||||
|
@ -545,7 +716,7 @@ CParseResult CConfig::parseLine(std::string line, bool dynamic) {
|
|||
|
||||
if (ret.error)
|
||||
return ret;
|
||||
} else if (!line.empty()) {
|
||||
} else {
|
||||
// has to be a set
|
||||
if (line.contains("}")) {
|
||||
// easiest. } or invalid.
|
||||
|
@ -570,7 +741,7 @@ CParseResult CConfig::parseLine(std::string line, bool dynamic) {
|
|||
}
|
||||
|
||||
line.pop_back();
|
||||
line = removeBeginEndSpacesTabs(line);
|
||||
line = trim(line);
|
||||
impl->categories.push_back(line);
|
||||
}
|
||||
}
|
||||
|
@ -591,6 +762,9 @@ CParseResult CConfig::parse() {
|
|||
applyDefaultsToCat(*sc);
|
||||
}
|
||||
|
||||
CParseResult fileParseResult;
|
||||
|
||||
if (impl->rawConfigString.empty()) {
|
||||
bool fileExists = std::filesystem::exists(impl->path);
|
||||
|
||||
// implies options.allowMissingConfig
|
||||
|
@ -604,11 +778,62 @@ CParseResult CConfig::parse() {
|
|||
|
||||
std::string canonical = std::filesystem::canonical(impl->path);
|
||||
|
||||
CParseResult fileParseResult = parseFile(canonical.c_str());
|
||||
fileParseResult = parseFile(canonical.c_str());
|
||||
} else {
|
||||
fileParseResult = parseRawStream(impl->rawConfigString);
|
||||
}
|
||||
|
||||
return fileParseResult;
|
||||
}
|
||||
|
||||
CParseResult CConfig::parseRawStream(const std::string& stream) {
|
||||
CParseResult result;
|
||||
|
||||
int rawLineNum = 0;
|
||||
int lineNum = 0;
|
||||
|
||||
std::stringstream str(stream);
|
||||
|
||||
while (true) {
|
||||
const auto line = getNextLine(str, rawLineNum, lineNum);
|
||||
|
||||
if (!line) {
|
||||
switch (line.error()) {
|
||||
case GETNEXTLINEFAILURE_EOF: break;
|
||||
case GETNEXTLINEFAILURE_BACKSLASH:
|
||||
if (!impl->parseError.empty())
|
||||
impl->parseError += "\n";
|
||||
impl->parseError += std::format("Config error: Last line ends with backslash");
|
||||
result.setError(impl->parseError);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
const auto RET = parseLine(line.value());
|
||||
|
||||
if (RET.error && (impl->parseError.empty() || impl->configOptions.throwAllErrors)) {
|
||||
if (!impl->parseError.empty())
|
||||
impl->parseError += "\n";
|
||||
impl->parseError += std::format("Config error at line {}: {}", lineNum, RET.errorStdString);
|
||||
result.setError(impl->parseError);
|
||||
}
|
||||
}
|
||||
|
||||
if (!impl->categories.empty()) {
|
||||
if (impl->parseError.empty() || impl->configOptions.throwAllErrors) {
|
||||
if (!impl->parseError.empty())
|
||||
impl->parseError += "\n";
|
||||
impl->parseError += std::format("Config error: Unclosed category at EOF");
|
||||
result.setError(impl->parseError);
|
||||
}
|
||||
|
||||
impl->categories.clear();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
CParseResult CConfig::parseFile(const char* file) {
|
||||
CParseResult result;
|
||||
|
||||
|
@ -618,21 +843,33 @@ CParseResult CConfig::parseFile(const char* file) {
|
|||
return result;
|
||||
}
|
||||
|
||||
std::string line = "";
|
||||
int linenum = 1;
|
||||
int rawLineNum = 0;
|
||||
int lineNum = 0;
|
||||
|
||||
while (std::getline(iffile, line)) {
|
||||
while (true) {
|
||||
const auto line = getNextLine(iffile, rawLineNum, lineNum);
|
||||
|
||||
const auto RET = parseLine(line);
|
||||
|
||||
if (RET.error && (impl->parseError.empty() || impl->configOptions.throwAllErrors)) {
|
||||
if (!line) {
|
||||
switch (line.error()) {
|
||||
case GETNEXTLINEFAILURE_EOF: break;
|
||||
case GETNEXTLINEFAILURE_BACKSLASH:
|
||||
if (!impl->parseError.empty())
|
||||
impl->parseError += "\n";
|
||||
impl->parseError += std::format("Config error in file {} at line {}: {}", file, linenum, RET.errorStdString);
|
||||
impl->parseError += std::format("Config error in file {}: Last line ends with backslash", file);
|
||||
result.setError(impl->parseError);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
++linenum;
|
||||
const auto RET = parseLine(line.value());
|
||||
|
||||
if (!impl->currentFlags.noError && RET.error && (impl->parseError.empty() || impl->configOptions.throwAllErrors)) {
|
||||
if (!impl->parseError.empty())
|
||||
impl->parseError += "\n";
|
||||
impl->parseError += std::format("Config error in file {} at line {}: {}", file, lineNum, RET.errorStdString);
|
||||
result.setError(impl->parseError);
|
||||
}
|
||||
}
|
||||
|
||||
iffile.close();
|
||||
|
@ -690,8 +927,10 @@ CConfigValue* CConfig::getSpecialConfigValuePtr(const char* category, const char
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void CConfig::registerHandler(PCONFIGHANDLERFUNC func, const char* name, SHandlerOptions options) {
|
||||
impl->handlers.push_back(SHandler{name, options, func});
|
||||
void CConfig::registerHandler(PCONFIGHANDLERFUNC func, const char* name, SHandlerOptions options_) {
|
||||
SHandlerOptions options;
|
||||
std::memcpy(&options, &options_, seekABIStructSize(&options_, 0, sizeof(SHandlerOptions)));
|
||||
impl->handlers.push_back(SHandler{.name = name, .options = options, .func = func});
|
||||
}
|
||||
|
||||
void CConfig::unregisterHandler(const char* name) {
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <expected>
|
||||
|
||||
struct SHandler {
|
||||
std::string name = "";
|
||||
|
@ -64,11 +66,19 @@ struct SSpecialCategory {
|
|||
size_t anonymousID = 0;
|
||||
};
|
||||
|
||||
enum eGetNextLineFailure : uint8_t {
|
||||
GETNEXTLINEFAILURE_EOF = 0,
|
||||
GETNEXTLINEFAILURE_BACKSLASH,
|
||||
};
|
||||
|
||||
class CConfigImpl {
|
||||
public:
|
||||
std::string path = "";
|
||||
std::string originalPath = "";
|
||||
|
||||
// if not-empty, used instead of path
|
||||
std::string rawConfigString = "";
|
||||
|
||||
std::unordered_map<std::string, Hyprlang::CConfigValue> values;
|
||||
std::unordered_map<std::string, SConfigDefaultValue> defaultValues;
|
||||
std::vector<SHandler> handlers;
|
||||
|
@ -84,4 +94,11 @@ class CConfigImpl {
|
|||
std::string parseError = "";
|
||||
|
||||
Hyprlang::SConfigOptions configOptions;
|
||||
|
||||
void parseComment(const std::string& comment);
|
||||
std::expected<float, std::string> parseExpression(const std::string& s);
|
||||
|
||||
struct {
|
||||
bool noError = false;
|
||||
} currentFlags;
|
||||
};
|
|
@ -1,5 +1,10 @@
|
|||
|
||||
# Test comment
|
||||
## This is also a comment
|
||||
## This is a comment with space as a first character
|
||||
## This is a comment with tab as a first character
|
||||
## This is a comment with leading spaces and tabs
|
||||
##### Comment with more hash tags
|
||||
|
||||
testInt = 123
|
||||
testFloat = 123.456
|
||||
|
@ -9,12 +14,26 @@ $MY_VAR = 1337
|
|||
$MY_VAR_2 = $MY_VAR
|
||||
testVar = $MY_VAR$MY_VAR_2
|
||||
|
||||
$EXPR_VAR = {{MY_VAR + 2}}
|
||||
testExpr = {{EXPR_VAR - 4}}
|
||||
|
||||
testEnv = $SHELL
|
||||
|
||||
source = ./colors.conf
|
||||
|
||||
customType = abc
|
||||
|
||||
testStringColon = ee:ee:ee
|
||||
|
||||
# hyprlang noerror true
|
||||
|
||||
errorVariable = true
|
||||
|
||||
# hyprlang noerror false
|
||||
|
||||
categoryKeyword = oops, this one shouldn't call the handler, not fun
|
||||
testUseKeyword = yes
|
||||
|
||||
testCategory {
|
||||
testValueInt = 123456
|
||||
testValueHex = 0xF
|
||||
|
@ -23,12 +42,20 @@ testCategory {
|
|||
testColor2 = rgba(0, 0, 0, 1.0)
|
||||
testColor3 = rgba(ffeeff22)
|
||||
|
||||
testIgnoreKeyword = aaa
|
||||
testUseKeyword = no
|
||||
|
||||
nested1 {
|
||||
testValueNest = 1
|
||||
nested2 {
|
||||
testValueNest = 1
|
||||
}
|
||||
categoryKeyword = this one should not either
|
||||
}
|
||||
|
||||
categoryKeyword = we are having fun
|
||||
categoryKeyword = so much fun
|
||||
categoryKeyword = im the fun one at parties
|
||||
}
|
||||
|
||||
$SPECIALVAL1 = 1
|
||||
|
@ -38,8 +65,7 @@ special {
|
|||
value = $SPECIALVAL1
|
||||
}
|
||||
|
||||
special {
|
||||
key = b
|
||||
special[b] {
|
||||
value = 2
|
||||
}
|
||||
|
||||
|
@ -63,8 +89,21 @@ specialAnonymous {
|
|||
value = 3
|
||||
}
|
||||
|
||||
flagsStuff {
|
||||
value = 2
|
||||
}
|
||||
|
||||
multiline = \
|
||||
very \
|
||||
long \
|
||||
command
|
||||
|
||||
testCategory:testValueHex = 0xFFfFaAbB
|
||||
|
||||
$RECURSIVE1 = a
|
||||
$RECURSIVE2 = $RECURSIVE1b
|
||||
testStringRecursive = $RECURSIVE2c
|
||||
|
||||
testStringQuotes = "Hello World!"
|
||||
#testDefault = 123
|
||||
|
||||
|
@ -72,4 +111,3 @@ doABarrelRoll = woohoo, some, params # Funny!
|
|||
flagsabc = test
|
||||
#doSomethingFunny = 1, 2, 3, 4 # Funnier!
|
||||
#testSpaces = abc , def # many spaces, should be trimmed
|
||||
|
||||
|
|
15
tests/config/invalid-numbers.conf
Normal file
15
tests/config/invalid-numbers.conf
Normal file
|
@ -0,0 +1,15 @@
|
|||
# Every number/color in this file is invalid
|
||||
|
||||
invalidHex = 0x1Q
|
||||
emptyHex = 0x
|
||||
hugeHex = 0xFFFFFFFFFFFFFFFF
|
||||
|
||||
invalidInt = 1A
|
||||
emptyInt =
|
||||
|
||||
invalidColor = rgb(ABCDEQ)
|
||||
invalidFirstCharColor = rgb(QABCDE)
|
||||
|
||||
invalidColorAlpha = rgba(9ABCDEFQ)
|
||||
invalidFirstCharColorAlpha = rgba(Q9ABCDEF)
|
||||
|
20
tests/config/multiline-errors.conf
Normal file
20
tests/config/multiline-errors.conf
Normal file
|
@ -0,0 +1,20 @@
|
|||
# Careful when modifying this file. Line numbers are part of the test.
|
||||
|
||||
multiline = \
|
||||
one \
|
||||
two \
|
||||
three
|
||||
|
||||
# Line numbers reported in errors should match the actual line numbers of the source file
|
||||
# even after multi-line configs. Any errors reported should use the line number of the
|
||||
# first line of any multi-line config.
|
||||
|
||||
this \
|
||||
should \
|
||||
cause \
|
||||
error \
|
||||
on \
|
||||
line \
|
||||
12
|
||||
|
||||
# A config file cannot end with a bashslash because we are expecting another line! Even in a comment! \
|
|
@ -11,7 +11,7 @@ std::string garbage() {
|
|||
|
||||
std::string chars;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
chars += rand() % 254 + 1;
|
||||
chars += std::to_string((rand() % 254) + 1);
|
||||
}
|
||||
|
||||
return chars;
|
||||
|
|
|
@ -27,6 +27,9 @@ bool barrelRoll = false;
|
|||
std::string flagsFound = "";
|
||||
Hyprlang::CConfig* pConfig = nullptr;
|
||||
std::string currentPath = "";
|
||||
std::string ignoreKeyword = "";
|
||||
std::string useKeyword = "";
|
||||
static std::vector<std::string> categoryKeywordActualValues;
|
||||
|
||||
static Hyprlang::CParseResult handleDoABarrelRoll(const char* COMMAND, const char* VALUE) {
|
||||
if (std::string(VALUE) == "woohoo, some, params")
|
||||
|
@ -44,6 +47,28 @@ static Hyprlang::CParseResult handleFlagsTest(const char* COMMAND, const char* V
|
|||
return result;
|
||||
}
|
||||
|
||||
static Hyprlang::CParseResult handleCategoryKeyword(const char* COMMAND, const char* VALUE) {
|
||||
categoryKeywordActualValues.emplace_back(VALUE);
|
||||
|
||||
return Hyprlang::CParseResult();
|
||||
}
|
||||
|
||||
static Hyprlang::CParseResult handleTestIgnoreKeyword(const char* COMMAND, const char* VALUE) {
|
||||
ignoreKeyword = VALUE;
|
||||
|
||||
return Hyprlang::CParseResult();
|
||||
}
|
||||
|
||||
static Hyprlang::CParseResult handleTestUseKeyword(const char* COMMAND, const char* VALUE) {
|
||||
useKeyword = VALUE;
|
||||
|
||||
return Hyprlang::CParseResult();
|
||||
}
|
||||
|
||||
static Hyprlang::CParseResult handleNoop(const char* COMMAND, const char* VALUE) {
|
||||
return Hyprlang::CParseResult();
|
||||
}
|
||||
|
||||
static Hyprlang::CParseResult handleSource(const char* COMMAND, const char* VALUE) {
|
||||
std::string PATH = std::filesystem::canonical(currentPath + "/" + VALUE);
|
||||
return pConfig->parseFile(PATH.c_str());
|
||||
|
@ -82,40 +107,52 @@ int main(int argc, char** argv, char** envp) {
|
|||
|
||||
// setup config
|
||||
config.addConfigValue("testInt", (Hyprlang::INT)0);
|
||||
config.addConfigValue("testExpr", (Hyprlang::INT)0);
|
||||
config.addConfigValue("testFloat", 0.F);
|
||||
config.addConfigValue("testVec", Hyprlang::SVector2D{69, 420});
|
||||
config.addConfigValue("testVec", Hyprlang::SVector2D{.x = 69, .y = 420});
|
||||
config.addConfigValue("testString", "");
|
||||
config.addConfigValue("testStringColon", "");
|
||||
config.addConfigValue("testEnv", "");
|
||||
config.addConfigValue("testVar", (Hyprlang::INT)0);
|
||||
config.addConfigValue("categoryKeyword", (Hyprlang::STRING) "");
|
||||
config.addConfigValue("testStringQuotes", "");
|
||||
config.addConfigValue("testStringRecursive", "");
|
||||
config.addConfigValue("testCategory:testValueInt", (Hyprlang::INT)0);
|
||||
config.addConfigValue("testCategory:testValueHex", (Hyprlang::INT)0xA);
|
||||
config.addConfigValue("testCategory:nested1:testValueNest", (Hyprlang::INT)0);
|
||||
config.addConfigValue("testCategory:nested1:nested2:testValueNest", (Hyprlang::INT)0);
|
||||
config.addConfigValue("testCategory:nested1:categoryKeyword", (Hyprlang::STRING) "");
|
||||
config.addConfigValue("testDefault", (Hyprlang::INT)123);
|
||||
config.addConfigValue("testCategory:testColor1", (Hyprlang::INT)0);
|
||||
config.addConfigValue("testCategory:testColor2", (Hyprlang::INT)0);
|
||||
config.addConfigValue("testCategory:testColor3", (Hyprlang::INT)0);
|
||||
config.addConfigValue("flagsStuff:value", (Hyprlang::INT)0);
|
||||
config.addConfigValue("myColors:pink", (Hyprlang::INT)0);
|
||||
config.addConfigValue("myColors:green", (Hyprlang::INT)0);
|
||||
config.addConfigValue("myColors:random", (Hyprlang::INT)0);
|
||||
config.addConfigValue("customType", {Hyprlang::CConfigCustomValueType{&handleCustomValueSet, &handleCustomValueDestroy, "def"}});
|
||||
|
||||
config.registerHandler(&handleDoABarrelRoll, "doABarrelRoll", {false});
|
||||
config.registerHandler(&handleFlagsTest, "flags", {true});
|
||||
config.registerHandler(&handleSource, "source", {false});
|
||||
config.registerHandler(&handleDoABarrelRoll, "doABarrelRoll", {.allowFlags = false});
|
||||
config.registerHandler(&handleFlagsTest, "flags", {.allowFlags = true});
|
||||
config.registerHandler(&handleSource, "source", {.allowFlags = false});
|
||||
config.registerHandler(&handleTestIgnoreKeyword, "testIgnoreKeyword", {.allowFlags = false});
|
||||
config.registerHandler(&handleTestUseKeyword, ":testUseKeyword", {.allowFlags = false});
|
||||
config.registerHandler(&handleNoop, "testCategory:testUseKeyword", {.allowFlags = false});
|
||||
config.registerHandler(&handleCategoryKeyword, "testCategory:categoryKeyword", {.allowFlags = false});
|
||||
|
||||
config.addSpecialCategory("special", {"key"});
|
||||
config.addSpecialCategory("special", {.key = "key"});
|
||||
config.addSpecialConfigValue("special", "value", (Hyprlang::INT)0);
|
||||
|
||||
config.addSpecialCategory("specialAnonymous", {nullptr, false, true});
|
||||
config.addSpecialCategory("specialAnonymous", {.key = nullptr, .ignoreMissing = false, .anonymousKeyBased = true});
|
||||
config.addSpecialConfigValue("specialAnonymous", "value", (Hyprlang::INT)0);
|
||||
|
||||
config.addConfigValue("multiline", "");
|
||||
|
||||
config.commence();
|
||||
|
||||
config.addSpecialCategory("specialGeneric:one", {nullptr, true});
|
||||
config.addSpecialCategory("specialGeneric:one", {.key = nullptr, .ignoreMissing = true});
|
||||
config.addSpecialConfigValue("specialGeneric:one", "value", (Hyprlang::INT)0);
|
||||
config.addSpecialCategory("specialGeneric:two", {nullptr, true});
|
||||
config.addSpecialCategory("specialGeneric:two", {.key = nullptr, .ignoreMissing = true});
|
||||
config.addSpecialConfigValue("specialGeneric:two", "value", (Hyprlang::INT)0);
|
||||
|
||||
const Hyprlang::CConfigValue copyTest = {(Hyprlang::INT)1};
|
||||
|
@ -133,7 +170,7 @@ int main(int argc, char** argv, char** envp) {
|
|||
std::cout << " → Testing values\n";
|
||||
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testInt")), 123);
|
||||
EXPECT(std::any_cast<float>(config.getConfigValue("testFloat")), 123.456f);
|
||||
auto EXP = Hyprlang::SVector2D{69, 420};
|
||||
auto EXP = Hyprlang::SVector2D{.x = 69, .y = 420};
|
||||
EXPECT(std::any_cast<Hyprlang::SVector2D>(config.getConfigValue("testVec")), EXP);
|
||||
EXPECT(std::any_cast<const char*>(config.getConfigValue("testString")), std::string{"Hello World! # This is not a comment!"});
|
||||
EXPECT(std::any_cast<const char*>(config.getConfigValue("testStringQuotes")), std::string{"\"Hello World!\""});
|
||||
|
@ -145,6 +182,25 @@ int main(int argc, char** argv, char** envp) {
|
|||
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testCategory:testColor1")), (Hyprlang::INT)0xFFFFFFFF);
|
||||
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testCategory:testColor2")), (Hyprlang::INT)0xFF000000);
|
||||
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testCategory:testColor3")), (Hyprlang::INT)0x22ffeeff);
|
||||
EXPECT(std::any_cast<const char*>(config.getConfigValue("testStringColon")), std::string{"ee:ee:ee"});
|
||||
EXPECT(std::any_cast<const char*>(config.getConfigValue("categoryKeyword")), std::string{"oops, this one shouldn't call the handler, not fun"});
|
||||
EXPECT(std::any_cast<const char*>(config.getConfigValue("testCategory:nested1:categoryKeyword")), std::string{"this one should not either"});
|
||||
EXPECT(ignoreKeyword, "aaa");
|
||||
EXPECT(useKeyword, "yes");
|
||||
|
||||
// Test templated wrapper
|
||||
auto T1 = Hyprlang::CSimpleConfigValue<Hyprlang::INT>(&config, "testInt");
|
||||
auto T2 = Hyprlang::CSimpleConfigValue<Hyprlang::FLOAT>(&config, "testFloat");
|
||||
auto T3 = Hyprlang::CSimpleConfigValue<Hyprlang::SVector2D>(&config, "testVec");
|
||||
auto T4 = Hyprlang::CSimpleConfigValue<std::string>(&config, "testString");
|
||||
EXPECT(*T1, 123);
|
||||
EXPECT(*T2, 123.456F);
|
||||
EXPECT(*T3, EXP);
|
||||
EXPECT(*T4, "Hello World! # This is not a comment!");
|
||||
|
||||
// test expressions
|
||||
std::cout << " → Testing expressions\n";
|
||||
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testExpr")), 1335);
|
||||
|
||||
// test static values
|
||||
std::cout << " → Testing static values\n";
|
||||
|
@ -158,6 +214,10 @@ int main(int argc, char** argv, char** envp) {
|
|||
EXPECT(barrelRoll, true);
|
||||
EXPECT(flagsFound, std::string{"abc"});
|
||||
|
||||
EXPECT(categoryKeywordActualValues.at(0), "we are having fun");
|
||||
EXPECT(categoryKeywordActualValues.at(1), "so much fun");
|
||||
EXPECT(categoryKeywordActualValues.at(2), "im the fun one at parties");
|
||||
|
||||
// test dynamic
|
||||
std::cout << " → Testing dynamic\n";
|
||||
barrelRoll = false;
|
||||
|
@ -165,6 +225,10 @@ int main(int argc, char** argv, char** envp) {
|
|||
EXPECT(barrelRoll, true);
|
||||
EXPECT(config.parseDynamic("testCategory:testValueHex", "0xaabbccdd").error, false);
|
||||
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testCategory:testValueHex")), (Hyprlang::INT)0xAABBCCDD);
|
||||
EXPECT(config.parseDynamic("testStringColon", "1:3:3:7").error, false);
|
||||
EXPECT(std::any_cast<const char*>(config.getConfigValue("testStringColon")), std::string{"1:3:3:7"});
|
||||
EXPECT(config.parseDynamic("flagsStuff:value = 69").error, false);
|
||||
EXPECT(std::any_cast<int64_t>(config.getConfigValue("flagsStuff:value")), (Hyprlang::INT)69);
|
||||
|
||||
// test dynamic special
|
||||
config.addSpecialConfigValue("specialGeneric:one", "boom", (Hyprlang::INT)0);
|
||||
|
@ -174,12 +238,20 @@ int main(int argc, char** argv, char** envp) {
|
|||
// test variables
|
||||
std::cout << " → Testing variables\n";
|
||||
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testVar")), 13371337);
|
||||
EXPECT(std::any_cast<const char*>(config.getConfigValue("testStringRecursive")), std::string{"abc"});
|
||||
|
||||
// test dynamic variables
|
||||
std::cout << " → Testing dynamic variables\n";
|
||||
EXPECT(config.parseDynamic("$MY_VAR_2 = 420").error, false);
|
||||
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testVar")), 1337420);
|
||||
|
||||
EXPECT(config.parseDynamic("$RECURSIVE1 = d").error, false);
|
||||
EXPECT(std::any_cast<const char*>(config.getConfigValue("testStringRecursive")), std::string{"dbc"});
|
||||
|
||||
// test dynamic exprs
|
||||
EXPECT(config.parseDynamic("testExpr = {{EXPR_VAR * 2}}").error, false);
|
||||
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testExpr")), 1339L * 2);
|
||||
|
||||
// test env variables
|
||||
std::cout << " → Testing env variables\n";
|
||||
EXPECT(std::any_cast<const char*>(config.getConfigValue("testEnv")), std::string{getenv("SHELL")});
|
||||
|
@ -190,6 +262,8 @@ int main(int argc, char** argv, char** envp) {
|
|||
EXPECT(std::any_cast<int64_t>(config.getSpecialConfigValue("special", "value", "b")), 2);
|
||||
EXPECT(std::any_cast<int64_t>(config.getSpecialConfigValue("specialGeneric:one", "value")), 1);
|
||||
EXPECT(std::any_cast<int64_t>(config.getSpecialConfigValue("specialGeneric:two", "value")), 2);
|
||||
EXPECT(config.parseDynamic("special[b]:value = 3").error, false);
|
||||
EXPECT(std::any_cast<int64_t>(config.getSpecialConfigValue("special", "value", "b")), 3);
|
||||
|
||||
// test dynamic special variable
|
||||
EXPECT(config.parseDynamic("$SPECIALVAL1 = 2").error, false);
|
||||
|
@ -216,6 +290,9 @@ int main(int argc, char** argv, char** envp) {
|
|||
std::cout << " → Testing custom types\n";
|
||||
EXPECT(*reinterpret_cast<int64_t*>(std::any_cast<void*>(config.getConfigValue("customType"))), (Hyprlang::INT)1);
|
||||
|
||||
// test multiline config
|
||||
EXPECT(std::any_cast<const char*>(config.getConfigValue("multiline")), std::string{"very long command"});
|
||||
|
||||
std::cout << " → Testing error.conf\n";
|
||||
Hyprlang::CConfig errorConfig("./config/error.conf", {.verifyOnly = true, .throwAllErrors = true});
|
||||
|
||||
|
@ -226,6 +303,35 @@ int main(int argc, char** argv, char** envp) {
|
|||
const auto ERRORSTR = std::string{ERRORS.getError()};
|
||||
EXPECT(std::count(ERRORSTR.begin(), ERRORSTR.end(), '\n'), 1);
|
||||
|
||||
std::cout << " → Testing invalid-numbers.conf\n";
|
||||
Hyprlang::CConfig invalidNumbersConfig("./config/invalid-numbers.conf", {.throwAllErrors = true});
|
||||
invalidNumbersConfig.addConfigValue("invalidHex", (Hyprlang::INT)0);
|
||||
invalidNumbersConfig.addConfigValue("emptyHex", (Hyprlang::INT)0);
|
||||
invalidNumbersConfig.addConfigValue("hugeHex", (Hyprlang::INT)0);
|
||||
invalidNumbersConfig.addConfigValue("invalidInt", (Hyprlang::INT)0);
|
||||
invalidNumbersConfig.addConfigValue("emptyInt", (Hyprlang::INT)0);
|
||||
invalidNumbersConfig.addConfigValue("invalidColor", (Hyprlang::INT)0);
|
||||
invalidNumbersConfig.addConfigValue("invalidFirstCharColor", (Hyprlang::INT)0);
|
||||
invalidNumbersConfig.addConfigValue("invalidColorAlpha", (Hyprlang::INT)0);
|
||||
invalidNumbersConfig.addConfigValue("invalidFirstCharColorAlpha", (Hyprlang::INT)0);
|
||||
|
||||
invalidNumbersConfig.commence();
|
||||
const auto ERRORS2 = invalidNumbersConfig.parse();
|
||||
|
||||
EXPECT(ERRORS2.error, true);
|
||||
const auto ERRORSTR2 = std::string{ERRORS2.getError()};
|
||||
EXPECT(std::count(ERRORSTR2.begin(), ERRORSTR2.end(), '\n'), 9 - 1);
|
||||
|
||||
Hyprlang::CConfig multilineErrorConfig("./config/multiline-errors.conf", {.verifyOnly = true, .throwAllErrors = true});
|
||||
multilineErrorConfig.commence();
|
||||
const auto ERRORS3 = multilineErrorConfig.parse();
|
||||
EXPECT(ERRORS3.error, true);
|
||||
const auto ERRORSTR3 = std::string{ERRORS3.getError()};
|
||||
|
||||
// Error on line 12
|
||||
EXPECT(ERRORSTR3.contains("12"), true);
|
||||
// Backslash at end of file
|
||||
EXPECT(ERRORSTR3.contains("backslash"), true);
|
||||
} catch (const char* e) {
|
||||
std::cout << Colors::RED << "Error: " << Colors::RESET << e << "\n";
|
||||
return 1;
|
||||
|
|
Loading…
Reference in a new issue