This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
Hexnumber #1903
Merged
Merged
Hexnumber #1903
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1a6a8a3
hexnumber: initial version of hex plugin
kodebach ec992d8
hexnumber: added additional documentation
kodebach f235ad3
hexnumber: add hexnumber entry in plugins README
kodebach 7d736f5
hexnumber: update with suggestions form pull request
kodebach a13e073
hexnumber: added more tests, fixed bugs
kodebach c19ee13
hexnumber: fixed README, added to METADATA
kodebach ffa1a7b
hexnumber: added release notes line
kodebach 3d2148a
hexnumber: updated example in README.md
kodebach 268a1fa
hexnumber: use /tests in examples, fix string length bug in conversion
kodebach c725704
hexnumber: incorporate notes from review
kodebach 87780c1
hexnumber: fix formatting
kodebach 1099b7b
hexnumber: use array of types instead of semicolon separated list
kodebach 40d84fb
hexnumber: update README and fix formatting
kodebach f69bfa1
hexnumber: update README and fix minor problems
kodebach 713836d
hexnumber: produce error on invalid value
kodebach dba906e
hexnumber: reformat cmake file
kodebach 33542cd
hexnumber: fix memory leaks
kodebach 900285d
hexnumber: remove elektraArrayGetStrings from kdbease.h
kodebach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include (LibAddMacros) | ||
|
||
add_plugin (hexnumber SOURCES hexnumber.h hexnumber.c LINK_ELEKTRA elektra-ease ADD_TEST TEST_README) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
- infos = Information about the hexnumber plugin is in keys below | ||
- infos/author = Klemens Böswirth <k.boeswirth+git@gmail.com> | ||
- infos/licence = BSD | ||
- infos/needs = | ||
- infos/provides = conv check | ||
- infos/recommends = | ||
- infos/placements = postgetstorage presetstorage | ||
- infos/status = nodep unittest maintained | ||
- infos/metadata = unit/base type | ||
- infos/ordering = type | ||
- infos/description = converts hexadecimal values into decimal and back | ||
|
||
## Introduction | ||
|
||
This plugin is used to read configuration files that use hexadecimal values. All "hex-values" (see below) will be | ||
converted into decimal when Elektra reads values from the mounted file. When Elektra writes back to the file the converted values | ||
will be converted back and stored as before (`0X` will be replaced with `0x`). | ||
|
||
### What are "hex-values"? | ||
There are multiple ways you can signal to the hexnumber plugin, that a value should be converted: | ||
|
||
1. If a Key has the metadata `unit/base` set to `hex` it will always be interpreted as a hex-value. The plugin will also produce an error, | ||
if the value contained in such a Key does not start with `0x` (or `0X`). | ||
2. If `unit/base` is not present and | ||
- the `type` metadata is set to one of the recognized integer-types (default: `byte`, `short`, `unsigned_short`, `long`, `unsigned_long`, | ||
`long_long`, `unsigned_long_long`) | ||
- AND the configuration value itself starts with `0x` (or `0X`) it will be interpreted as a hex-value. | ||
3. If forced conversion mode (`/force` plugin configuration, see below) is enabled all values starting with `0x` (or `0X`) are considered hex-values. | ||
|
||
## Configuration | ||
|
||
When mounting a backend with the hexnumber plugin, a few settings can be configured. | ||
|
||
1. To enable forced conversion mode set `/force` to any value. In forced conversion mode the plugin tries to convert **ALL** strings | ||
starting with `0x` (or `0X`) into decimal before passing the value on to the rest of Elektra. This can be useful for importing a | ||
configuration file that uses hexadecimal values into Elektra without writing a specification for the file. | ||
|
||
NOTE: be careful when using this option, as any configuration value that contains invalid non-hexadecimal characters | ||
(i.e. does not match `0[xX][0-9A-Fa-f]+`) will result in an error. | ||
|
||
``` | ||
sudo kdb mount test.ecf /examples/hexnumber/forced hexnumber /force=1 | ||
``` | ||
|
||
2. The types recognized as integers can be configured. For this purpose specify all *additional* types you want to be considered for | ||
possible hexadecimal conversion as an Elektra array. All keys with a type from `/accept/types/#`, or one of the default types, will | ||
be converted to hexadecimal if the value starts with `0x` (or `0X`). | ||
|
||
``` | ||
sudo kdb mount test.ecf /examples/hexnumber/customtypes hexnumber /accept/types/#0=customint /accept/types/#1=othercustomint | ||
``` | ||
|
||
## Usage & Example | ||
- To mount a simple backend that uses hexadecimal numbers, you can use: | ||
```sh | ||
sudo kdb mount test.ecf user/tests/hexnumber hexnumber | ||
``` | ||
|
||
- A few examples on how to use the plugin: | ||
```sh | ||
# Example 1: read hex value | ||
kdb set user/tests/hexnumber/hex 0x1F | ||
kdb setmeta user/tests/hexnumber/hex type long | ||
|
||
kdb get user/tests/hexnumber/hex | ||
#> 31 | ||
|
||
# Example 2: decimal value not converted | ||
kdb set user/tests/hexnumber/dec 26 | ||
kdb setmeta user/tests/hexnumber/dec type long | ||
|
||
kdb get user/tests/hexnumber/dec | ||
#> 26 | ||
|
||
# Example 3: string untouched | ||
kdb set user/tests/hexnumber/string value | ||
kdb setmeta user/tests/hexnumber/string type string | ||
|
||
kdb get user/tests/hexnumber/string | ||
#> value | ||
|
||
# Example 4: read hex value with unit/base | ||
kdb set user/tests/hexnumber/hex2 0xF | ||
kdb setmeta user/tests/hexnumber/hex2 unit/base hex | ||
|
||
kdb get user/tests/hexnumber/hex2 | ||
#> 15 | ||
|
||
# Undo changes | ||
kdb rm -r user/tests/hexnumber | ||
``` | ||
|
||
- To unmount the plugin use the following command: | ||
```sh | ||
kdb umount user/tests/hexnumber | ||
#> | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please format this file with the script
reformat-cmake
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for noting, we should enforce that with the buildserver. Isn't this just a matter of installing two tools?
Ideally the build server should directly tell that something like that is wrong.
@ingwinlu What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already do that in the Travis Linux builds.
Yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
knock yourself out :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sanssecours It seems you need to manually install libyaml as well as PyYAML for the
reformat-cmake
script to work. This should probably be reflected in our documentation. Especially because otherwise the script throws an error for each CMake file and also deletes the contents of all these files.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know
cmake-format
has no dependencies:.
While
reformat-cmake
is certainly not perfect, it checks for the binariescmake-format
andsponge
beforehand. If you did not install one of these tools it should just fail printing a (broken) error message. I tried this myself, first by uninstallingcmake-format
and invoking the script. After that I uninstalledmoreutils
and ran the command again. At no point did the script change any file in my copy of the repo, at least as far as I can tell. Are you sure that the script deleted you CMake files? If so, can you please describe steps to reproduce the problem?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It did not delete the files themselves, just their contents. I think this is because stdout of
cmake-format
is piped back into the CMake file, but stdout is empty because of the error.I also looked at the
cmake-format
github page and could not find any mention of the dependency. But here the moduleyaml
is imported, which is the cause of the error.The problem could probably be solved by using the
json
orpython
format for the.cmake-format
file, because these two modules are part of the python standard library.If you still want me to, I can try to find out how to reproduce the error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the detailed description. I opened pull request #2011, which should fix the problem by checking the exit code of
cmake-format CMakeLists.txt
before it updates any file.That might even be a better solution, than the one I came up with. Anyway, since I prefer the human readability of YAML over JSON or the Python config style, I did not change the format of the config file.