Skip to content

Commit

Permalink
Commit #126
Browse files Browse the repository at this point in the history
  • Loading branch information
madmurphy committed Nov 11, 2018
1 parent 8fe0464 commit 4e34376
Show file tree
Hide file tree
Showing 56 changed files with 1,884 additions and 1,539 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ indent_size = 4

[src/confini.h]
charset = utf-8
indent_style = tab
indent_size = 8
indent_style = space
indent_size = 4
15 changes: 15 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@ Change Log {#changelog}
=======================


## 1.8.2 -- 2018-11-11

Changes:

* Code review (private function `further_cuts()`)
* Optimization flag `-O2` seems to be working better than `-O3` on Unix systems:
conditionally use `-O2` or `-O3` depending on the host
* Use **libtool**'s `-avoid-version` only when compiling under native Microsoft
Windows environment
* Added `--clean` option to the `autogen.sh` script
* Updated **Autotools** macros
* Documentation
* Examples


## 1.8.1 -- 2018-11-04

Changes:
Expand Down
96 changes: 47 additions & 49 deletions MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ email = john.smith@example.com
[receiver]
name = Mario Rossi # He's a fat guy
name = Mario Rossi # He's a big guy
email = mario.rossi@example.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -96,7 +96,7 @@ nodes, as in the following example:
location=Colosseum;place=Rome;[sender] name=John Smith;
email=john.smith@example.com;
[receiver] name=Mario Rossi; # He's a fat guy
[receiver] name=Mario Rossi; # He's a big guy
email=mario.rossi@example.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -129,9 +129,9 @@ _unknown type_ (example: `= foo`). If the **value part** is missing the key
element is considered empty (example: `foo =`). If the delimiter is missing (and
therefore the **value part** as well), according to some formats the key element
is considered to be an _implicit key_ -- typically representing the boolean
`TRUE` (example: `foo`). For instance, in the following example from
`true` (example: `foo`). For instance, in the following example from
`/etc/pacman.conf`, `IgnorePkg` is an empty key, while `Color` is an implicit
key (representing a `TRUE` boolean -- i.e. `Color = YES`):
key (representing a `true` boolean -- i.e. `Color = YES`):

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.ini}
HoldPkg = pacman glibc
Expand Down Expand Up @@ -386,7 +386,7 @@ static int my_callback (IniDispatch * dispatch, void * v_null) {
int main () {
FILE * const ini_file = fopen("ini_files/example.conf", "rb");
FILE * const ini_file = fopen("ini_files/delivery.conf", "rb");
if (ini_file == NULL) {
Expand Down Expand Up @@ -437,7 +437,7 @@ static int my_callback (IniDispatch * dispatch, void * v_null) {
int main () {
if (load_ini_path(
"ini_files/example.conf",
"ini_files/delivery.conf",
INI_DEFAULT_FORMAT,
NULL,
my_callback,
Expand Down Expand Up @@ -608,7 +608,7 @@ sequences will be unescaped, then
* **Values**, if `format.do_not_collapse_values` is active, will only be cleaned
of spaces at the beginning and at the end; otherwise will be rendered
according to the same algorithm used for key names (with the difference that,
if `format.preserve_empty_quotes` is set to `1`, empty quotes surrounded by
if `format.preserve_empty_quotes` is set to `true`, empty quotes surrounded by
spaces will be preserved).
* **Comments**, in multi-line formats, will be rendered according to ECMAScript
`comment_string.replace(/(^|\n\r?|\r\n?)[ \t\v\f]*[#;]+/g, "$1")`; elsewhere,
Expand Down Expand Up @@ -673,7 +673,7 @@ static int ini_listener (IniDispatch * dispatch, void * v_null) {
int main () {
if (load_ini_path(
"ini_files/example.conf",
"ini_files/self_explaining.conf",
INI_DEFAULT_FORMAT,
NULL,
ini_listener,
Expand Down Expand Up @@ -858,9 +858,10 @@ quotes. This function is very similar to `ini_string_parse()`, except that does
not bother collapsing the sequences of more than one space that might result
from removing empty quotes -- this is never necessary since empty quotes
surrounded by spaces in key and section names are always collapsed before being
dispatched (you could use `ini_string_parse()` as well to parse key and section
names, but you would obtain the same result with a slightly bigger effort from
the CPU).
dispatched.

You could use `ini_string_parse()` as well to parse key and section names, but
you would obtain the same result with a slightly bigger effort from the CPU.


### FORMATTING THE SECTION PATHS
Expand All @@ -879,7 +880,7 @@ of a section path, depending on the content and the format of the INI file.
### IMPLICIT KEYS

In order to set the value to be assigned to implicit keys, please use the
`ini_global_set_implicit_value()` function. A _zero-length `TRUE`-boolean_ is
`ini_global_set_implicit_value()` function. A _zero-length `true`-boolean_ is
usually a good choice:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.c}
Expand Down Expand Up @@ -998,7 +999,7 @@ is found. Hence, by using the flag `#CONFINI_ERROR`, the code below
distinguishes a non-zero value generated by the listener from a non-zero value
due to a parsing error.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.c}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.c}
/* examples/topics/ini_string_match_si.c */
#include <stdio.h>
Expand Down Expand Up @@ -1027,7 +1028,7 @@ int main () {
/* Load INI file */
int retval = load_ini_path(
"ini_files/example.conf",
"ini_files/self_explaining.conf",
INI_DEFAULT_FORMAT,
NULL,
passfinder,
Expand All @@ -1045,7 +1046,7 @@ int main () {
/* Check if parsing has been interrupted by `passfinder()` */
retval == CONFINI_FEINTR ?
printf(
"We found it! It's the INI element number #%d!\n",
"We found it! It's the INI element number #%zu!\n",
membid
)
:
Expand All @@ -1054,7 +1055,7 @@ int main () {
return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


### THE FORMATTING FUNCTIONS
Expand Down Expand Up @@ -1121,12 +1122,11 @@ makes it harder to maintain, and does not give the user the real freedom to
choose what suits best to each single case.

When a user needs it, the data parsed by **libconfini** can still be stored in
a third-party hash table while it is still being dispatched. By doing so the
resulting performance will equal that of an INI parser with a hash table
included by default, since the only job of **libconfini** is that of scrolling
the content of an INI file linearly from the beginning to the end -- and there
are not more efficient ways to parse and indicize the content of a serialized
tree.
a third-party hash table while it is being dispatched. By doing so the resulting
performance will equal that of an INI parser with a hash table included by
default, since the only job of **libconfini** is that of scrolling the content
of an INI file linearly from the beginning to the end -- and there are not more
efficient ways to parse and indicize the content of a serialized tree.

If you are interested in combining **libconfini** with a hash table, I have left
a general example of how to use **GLib**'s `GHashTable` together with
Expand All @@ -1139,9 +1139,9 @@ example as a model other solutions can be easily explored as well.
Within an INI file it is granted that if one sums together all the
`(disp->d_len + 1)` and all the `(disp->v_len > 0 ? disp->v_len + 1 : 0)`
received, the result will always be less-than or equal-to `(stats->bytes + 1)`
(where `+ 1` represents the NUL terminators and `disp` and `stats` are
-- where `+ 1` represents the NUL terminators and `disp` and `stats` are
respectively the `IniDispatch` and `IniStatistics` structures passed as
arguments to the callback functions). **If one adds to this also all the
arguments to the callback functions. **If one adds to this also all the
`disp->at_len` properties, or if the `disp->v_len` properties of implicit keys
are non-zero, the sum may exceed it.** This might be relevant or irrelevant
depending on your code.
Expand Down Expand Up @@ -1190,11 +1190,11 @@ int main () {
printf(
"The file is %d bytes large.\n\n"
"The file is %zu bytes large.\n\n"
"The sum of the lengths of all "
"`IniDispatch::data` plus the lengths of all\n"
"non-empty `IniDispatch::value` is %d.\n",
"The sum of the lengths of all `disp->data` "
"plus the lengths of all non-empty\n"
"`disp->value`s is %zu.\n",
check.bytes, check.buff_lengths
Expand All @@ -1220,33 +1220,31 @@ int main () {

Besides the two global variables `#INI_GLOBAL_IMPLICIT_VALUE` and
`#INI_GLOBAL_IMPLICIT_V_LEN`, a third variable named
`#INI_GLOBAL_LOWERCASE_MODE` tells **libconfini** whether to dispatch key names
and section paths lower-case or not in case-insensitive INI files.
`#INI_GLOBAL_LOWERCASE_MODE` tells **libconfini** whether to dispatch in lower
case all key names and section paths of case-insensitive INI files.

As with the other global variables, you can declare the variable
`#INI_GLOBAL_LOWERCASE_MODE` at the beginning of your code:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.c}
#define FALSE 0
#define TRUE 1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.c}
#include <stdbool.h>
#include <confini.h>
_Bool INI_GLOBAL_LOWERCASE_MODE = FALSE;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bool INI_GLOBAL_LOWERCASE_MODE = false;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Alternatively, this variable can be set through the function
`ini_global_set_lowercase_mode()` without being explicitly declared.

When the variable `#INI_GLOBAL_LOWERCASE_MODE` is set to `TRUE`, **libconfini**
will always dispatch lowercase _all_ ASCII letters of key and section names in
When the variable `#INI_GLOBAL_LOWERCASE_MODE` is set to `true`, **libconfini**
always dispatches in lower case _all_ ASCII letters of key and section names in
case-insensitive formats -- _even when these are enclosed within quotes_ -- but
will **not** convert UTF-8 code points to lowercase (for instance, `Ā` will not
be rendered as `ā`, but will be rather rendered verbatim). _In general it is a
good practice to use UTF-8 within values, but to use ASCII only within key and
section names._
does **not** dispatch in lower case UTF-8 code points out of the ASCII range
(for instance, `Ā` will not be rendered as `ā`, but will be rather rendered
verbatim). _In general it is a good practice to use UTF-8 within values, but to
use ASCII only within key and section names._

Normally `#INI_GLOBAL_LOWERCASE_MODE` does not need to be set to `TRUE`, since
Normally `#INI_GLOBAL_LOWERCASE_MODE` does not need to be set to `true`, since
string comparisons made by libconfini are always either case-sensitive or
case-insensitive depending on the format given.

Expand Down Expand Up @@ -1350,7 +1348,7 @@ int main () {
seconds = (double) (end - start) / CLOCKS_PER_SEC;
printf(
"%d bytes parsed in %f seconds.\n"
"%zu bytes parsed in %f seconds.\n"
"Number of bytes parsed per second: %f\n",
bytes, seconds, bytes / seconds
);
Expand Down Expand Up @@ -1532,7 +1530,7 @@ Reliable general patterns:
disambiguation. If you believe that this solution is too artificial, think
that `/etc/samba/smb.conf` and `/etc/pulse/daemon.conf` are systematically
distributed using this pattern.
* `IniFormat::disabled_after_space` -- Setting this property to `FALSE`, due to
* `IniFormat::disabled_after_space` -- Setting this property to `false`, due to
the initial space that follows the comment marker (`# INI...`), forces
`# INI key/value delimiter: = (everywhere)` to be considered as a comment.
Some authors use this syntax to distinguish between comments and disabled
Expand All @@ -1542,15 +1540,15 @@ Temporary workarounds:

* `IniFormat::no_spaces_in_names` -- If our INI file has only comments
containing more than one word and we are sure that key and section names
cannot contain internal white spaces, we can set this property to `TRUE` to
cannot contain internal white spaces, we can set this property to `true` to
enhance disambiguation.
* `IniFormat::disabled_can_be_implicit` -- This property, if set to `FALSE`,
* `IniFormat::disabled_can_be_implicit` -- This property, if set to `false`,
forces all comments that do not contain a key-value delimiter to be never
considered as disabled entries. Despite not having an impact on our example,
it has a big impact on the disambiguation algorithms used by **libconfini**.
Its value in `#INI_DEFAULT_FORMAT` is set to `FALSE`.
Its value in `#INI_DEFAULT_FORMAT` is set to `false`.

As a general rule **libconfini** will always try to parse as a disabled entry
As a general rule, **libconfini** will always try to parse as a disabled entry
whatever comment is allowed (by the format) to contain one. Only if this attempt
fails, the block will be dispatched as a normal comment.

Expand Down
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ examplesinifilesdir = $(examplesdir)/ini_files
examplesinifiles_DATA = \
examples/ini_files/ambiguous.conf \
examples/ini_files/bad_ini.conf \
examples/ini_files/example.conf \
examples/ini_files/delivery.conf \
examples/ini_files/hash_table.conf \
examples/ini_files/self_explaining.conf \
examples/ini_files/typed_ini.conf \
examples/ini_files/unix-like.conf

Expand Down
Loading

0 comments on commit 4e34376

Please sign in to comment.