Skip to content

Commit

Permalink
Merge pull request ElektraInitiative#3292 from bauhaus93/plugin_toml
Browse files Browse the repository at this point in the history
TOML storage plugin
  • Loading branch information
mpranj committed Sep 3, 2020
2 parents bce8291 + 100a34d commit 15d8cf8
Show file tree
Hide file tree
Showing 82 changed files with 8,480 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ bsd_task:
pkg install -y
bison
cmake
flex
git
libgit2
ninja
Expand Down Expand Up @@ -125,6 +126,7 @@ mac_task:
brew install dbus
brew install discount
brew install doxygen
brew install flex
brew install glib
brew install go
brew install gpgme
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ matrix:
- bison
- dbus
- discount
- flex
- gpgme
- libev
- libgcrypt
Expand Down
11 changes: 11 additions & 0 deletions doc/METADATA.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1314,3 +1314,14 @@ status = implemented
usedby/plugins = cache
type = boolean
description = tells the cache plugin to remove all cache files during the next `kdbGet` in a safe way.

[tomltype]
status = implemented
usedby/plugins = toml
type = enum
simpletable
tablearray
inlinetable
descriptions = Tells the TOML plugin, which kind of TOML structure a key represents. When reading a TOML file, the plugin sets this metakey when encountering a TOML structure.
On writing, it is used for writing the structure back into a TOML file.
No metakey inference is done on writing, it's either set by a previous read of a TOML file or set explicitly by the user.
3 changes: 3 additions & 0 deletions doc/man/man7/elektra-plugins.7
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ passwd \fIpasswd/\fR for passwd files
specload \fIspecload/\fR calls an external application to request its specification, depends on quickdump \fIquickdump/\fR
.
.IP "\(bu" 4
toml \fItoml/\fR reads and writes data using a parser generated by Flex \fIhttps://github\.com/westes/flex\fR and Bison \fIhttps://www\.gnu\.org/software/bison\fR
.
.IP "\(bu" 4
yamlcpp \fIyamlcpp/\fR reads and writes data in the YAML \fIhttp://www\.yaml\.org\fR format using yaml\-cpp \fIhttps://github\.com/jbeder/yaml\-cpp\fR
.
.IP "\(bu" 4
Expand Down
6 changes: 2 additions & 4 deletions doc/news/_preparation_next_release.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ The following section lists news about the [modules](https://www.libelektra.org/
- <<TODO>>
- <<TODO>>

### <<Plugin2>>
### TOML

- <<TODO>>
- <<TODO>>
- <<TODO>>
- Added the TOML plugin, which can read and write TOML files using flex and bison. _(Jakob Fischer)_

### <<Plugin3>>

Expand Down
1 change: 1 addition & 0 deletions scripts/docker/alpine/3.11/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ RUN apk update \
curl \
diffutils \
file \
flex \
git \
gtest-dev \
ninja \
Expand Down
3 changes: 2 additions & 1 deletion scripts/docker/cirrus/fedora/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ FROM fedora:32

RUN dnf upgrade -y && dnf install -y \
augeas-devel \
bison \
boost-devel \
cmake \
curl \
dbus-devel \
diffutils \
file \
findutils \
flex \
gcc-c++ \
git \
glib2 \
Expand Down Expand Up @@ -49,4 +51,3 @@ RUN mkdir -p ${GTEST_ROOT} \
-L https://github.com/google/googletest/archive/${GTEST_VER}.tar.gz \
&& tar -zxvf gtest.tar.gz --strip-components=1 -C ${GTEST_ROOT} \
&& rm gtest.tar.gz

2 changes: 2 additions & 0 deletions scripts/docker/debian/buster/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ RUN apt-get update \
automake \
autotools-dev \
bison \
flex \
libc6-dbg \
build-essential \
cmake \
curl \
Expand Down
2 changes: 2 additions & 0 deletions scripts/docker/debian/sid/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ RUN apt-get update && apt-get -y install \
default-jdk \
dh-lua \
ed \
flex \
libc6-dbg \
gawk \
git \
gnupg2 \
Expand Down
2 changes: 1 addition & 1 deletion scripts/docker/debian/stretch/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ RUN apt-get update \
dnsutils \
virtualenv \
bison \
flex \
uuid-dev \
ninja-build \
&& rm -rf /var/lib/apt/lists/*
Expand Down Expand Up @@ -172,4 +173,3 @@ RUN virtualenv "${COVERALLS_VIRTUALENV_PATH}" \
&& pip install cpp-coveralls \
&& deactivate
ENV PATH="${PATH}:${COVERALLS_VIRTUALENV_PATH}/bin"

1 change: 1 addition & 0 deletions scripts/docker/ubuntu/disco/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ RUN apt-get update && apt-get -y install \
cmake \
curl \
ed \
flex \
git \
googletest \
libantlr4-runtime-dev \
Expand Down
2 changes: 1 addition & 1 deletion scripts/vagrant/ubuntu/artful32/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Vagrant.configure("2") do |config|
config.vm.provision "shell", inline: <<-SHELL
apt-get update
apt-get -y upgrade
apt-get -y install curl build-essential autotools-dev automake cmake pkg-config doxygen graphviz bison ruby-dev python-dev python3-dev liblua5.2-dev tclcl-dev libaugeas-dev libyajl-dev libgit2-dev libboost-all-dev libssl-dev libcurl4-gnutls-dev libdbus-1-dev libpcre3-dev libpcre++-dev checkinstall vim valgrind clang-5.0 clang-format-5.0 htop zlib1g-dev git openjdk-8-jdk python-pip locales bison libpython3-dev liblua5.3-dev libxerces-c-dev swig
apt-get -y install curl build-essential autotools-dev automake cmake pkg-config doxygen graphviz bison flex ruby-dev python-dev python3-dev liblua5.2-dev tclcl-dev libaugeas-dev libyajl-dev libgit2-dev libboost-all-dev libssl-dev libcurl4-gnutls-dev libdbus-1-dev libpcre3-dev libpcre++-dev checkinstall vim valgrind clang-5.0 clang-format-5.0 htop zlib1g-dev git openjdk-8-jdk python-pip locales bison libpython3-dev liblua5.3-dev libxerces-c-dev swig
pip install cmake-format[yaml]==0.6.3
Expand Down
43 changes: 25 additions & 18 deletions src/libs/meta/meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -873,31 +873,38 @@ int keySetCTime (Key * key, time_t ctime)
int elektraKeyCmpOrder (const Key * ka, const Key * kb)
{

if (!ka && !kb) return 0;

if (ka && !kb) return 1;
if (ka == NULL && kb == NULL)
{
return 0;
}

if (!ka && kb) return -1;
if (ka != NULL && kb == NULL)
{
return 1;
}

int aorder = -1;
int border = -1;
if (ka == NULL && kb != NULL)
{
return -1;
}

const Key * kam = keyGetMeta (ka, "order");
const Key * kbm = keyGetMeta (kb, "order");

if (kam) aorder = atoi (keyString (kam));
if (kbm) border = atoi (keyString (kbm));

if (aorder > 0 && border > 0) return aorder - border;

if (aorder < 0 && border < 0) return 0;

if (aorder < 0 && border >= 0) return -1;

if (aorder >= 0 && border < 0) return 1;
if (kam == NULL && kbm == NULL)
{
return 0;
}
if (kam != NULL && kbm == NULL)
{
return 1;
}
if (kam == NULL && kbm != NULL)
{
return -1;
}

/* cannot happen anyway */
return 0;
return atoi (keyString (kam)) - atoi (keyString (kbm));
}


Expand Down
1 change: 1 addition & 0 deletions src/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ productive use:
- [mozprefs](mozprefs/) for Mozilla preference files
- [passwd](passwd/) for passwd files
- [specload](specload/) calls an external application to request its specification, depends on [quickdump](quickdump/)
- [toml](toml/) reads and writes data using a parser generated by [Flex](https://github.com/westes/flex) and [Bison](https://www.gnu.org/software/bison)
- [yamlcpp](yamlcpp/) reads and writes data in the [YAML][] format using [yaml-cpp](https://github.com/jbeder/yaml-cpp)
- [yanlr](yanlr/) reads data using a parser generated by [ANTLR](http://www.antlr.org)

Expand Down
152 changes: 152 additions & 0 deletions src/plugins/toml/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
function (check_dependencies)
set (
FOUND_DEPENDENCIES
FALSE
PARENT_SCOPE)

set (USE_HOMEBREW_FLEX ${APPLE} AND EXISTS /usr/local/opt/flex)
if (USE_HOMEBREW_FLEX)
list (APPEND CMAKE_PREFIX_PATH "/usr/local/opt/flex")
endif (USE_HOMEBREW_FLEX)
find_package (FLEX 2.6.2 QUIET)

set (USE_HOMEBREW_BISON ${APPLE} AND EXISTS /usr/local/opt/bison)
if (USE_HOMEBREW_BISON)
list (APPEND CMAKE_PREFIX_PATH "/usr/local/opt/bison")
endif (USE_HOMEBREW_BISON)
find_package (BISON 3 QUIET)

if ((NOT FLEX_FOUND) AND (NOT BISON_FOUND))
set (
FAILURE_MESSAGE
"Flex and Bison could not be found"
PARENT_SCOPE)
return ()
endif ((NOT FLEX_FOUND) AND (NOT BISON_FOUND))
if (NOT FLEX_FOUND)
set (
FAILURE_MESSAGE
"Flex could not be found"
PARENT_SCOPE)
return ()
endif (NOT FLEX_FOUND)
if (NOT BISON_FOUND)
set (
FAILURE_MESSAGE
"Bison could not be found"
PARENT_SCOPE)
return ()
endif (NOT BISON_FOUND)

set (
FOUND_DEPENDENCIES
TRUE
PARENT_SCOPE)
endfunction (check_dependencies)

function (generate_code)
set (
GENERATED_CODE
FALSE
PARENT_SCOPE)

flex_target (TOMLScanner ${CMAKE_CURRENT_SOURCE_DIR}/lexer.l ${CMAKE_CURRENT_BINARY_DIR}/lexer.c)
bison_target (TOMLParser ${CMAKE_CURRENT_SOURCE_DIR}/parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.c VERBOSE bison_verbose.txt)
add_flex_bison_dependency (TOMLScanner TOMLParser)

if ((NOT FLEX_TOMLScanner_DEFINED) AND (NOT BISON_TOMLParser_DEFINED))
set (
FAILURE_MESSAGE
"Flex and Bison code could not be generated"
PARENT_SCOPE)
return ()
endif ((NOT FLEX_TOMLScanner_DEFINED) AND (NOT BISON_TOMLParser_DEFINED))
if (NOT FLEX_TOMLScanner_DEFINED)
set (
FAILURE_MESSAGE
"Flex code could not be generated"
PARENT_SCOPE)
return ()
endif (NOT FLEX_TOMLScanner_DEFINED)
if (NOT BISON_TOMLParser_DEFINED)
set (
FAILURE_MESSAGE
"Bison code could not be generated"
PARENT_SCOPE)
return ()
endif (NOT BISON_TOMLParser_DEFINED)

set (
FLEX_OUTPUT_SOURCE
${FLEX_TOMLScanner_OUTPUTS}
PARENT_SCOPE)
set (
FLEX_OUTPUT_HEADER
${FLEX_TOMLScanner_OUTPUT_HEADER}
PARENT_SCOPE)
set (
BISON_OUTPUT_SOURCE
${BISON_TOMLParser_OUTPUT_SOURCE}
PARENT_SCOPE)
set (
BISON_OUTPUT_HEADER
${BISON_TOMLParser_OUTPUT_HEADER}
PARENT_SCOPE)

set (
GENERATED_CODE
TRUE
PARENT_SCOPE)

endfunction (generate_code)

if (DEPENDENCY_PHASE)

check_dependencies ()
if (NOT FOUND_DEPENDENCIES)
remove_plugin (toml ${FAILURE_MESSAGE})
else (NOT FOUND_DEPENDENCIES)
generate_code ()
if (NOT GENERATED_CODE)
remove_plugin (toml ${FAILURE_MESSAGE})
endif (NOT GENERATED_CODE)
endif (NOT FOUND_DEPENDENCIES)

set (
SOURCE_FILES
toml.h
toml.c
driver.h
driver.c
scalar.h
scalar.c
table_array.h
table_array.c
comment_list.h
comment_list.c
codepoint.h
codepoint.c
utility.h
utility.c
write.h
write.c
node.h
node.c
prepare.c
prepare.h
type.h
type.c
error.h
error.c
${FLEX_OUTPUT_HEADER}
${FLEX_OUTPUT_SOURCE}
${BISON_OUTPUT_HEADER}
${BISON_OUTPUT_SOURCE})

endif (DEPENDENCY_PHASE)

add_plugin (
toml ADD_TEST INSTALL_TEST_DATA
LINK_ELEKTRA elektra-meta
SOURCES ${SOURCE_FILES}
INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR})
Loading

0 comments on commit 15d8cf8

Please sign in to comment.