From ff769c65c2eb9f11e15fc6bc3e1f09dd412496c0 Mon Sep 17 00:00:00 2001 From: Nikita Fediuchin Date: Fri, 7 Jun 2024 20:43:16 +0200 Subject: [PATCH] Change syntax style from " = " to ": " separator --- README.md | 20 ++++++------- docs/annotated.html | 2 +- docs/classconf_1_1_reader.html | 2 +- docs/classconf_1_1_writer.html | 2 +- docs/classes.html | 2 +- docs/common_8h.html | 2 +- .../dir_0af74dce6ed792f14cfe74ff7f287b3e.html | 2 +- .../dir_5078fa4b037495af7f2183084da91e6b.html | 2 +- .../dir_5cec92fd47c0900910bbc2480fdfd7be.html | 2 +- .../dir_b83c5bfa094d9549d67909f0b459d78c.html | 2 +- .../dir_d44c64559bbebec7f509842c48db8b23.html | 2 +- docs/doxygen_crawl.html | 8 ++--- docs/files.html | 2 +- docs/functions.html | 2 +- docs/functions_func.html | 2 +- docs/globals.html | 2 +- docs/globals_enum.html | 2 +- docs/globals_func.html | 2 +- docs/globals_type.html | 2 +- docs/index.html | 22 +++++++------- docs/md__b_u_i_l_d_i_n_g.html | 2 +- docs/pages.html | 2 +- docs/reader_8h.html | 2 +- docs/reader_8hpp.html | 2 +- docs/sitemap.xml | 12 ++++---- docs/writer_8h.html | 2 +- docs/writer_8hpp.html | 2 +- source/reader.c | 7 ++--- source/writer.c | 18 +++++------ tests/test_reader.c | 30 +++++++++---------- tests/test_writer.c | 16 +++++----- 31 files changed, 89 insertions(+), 90 deletions(-) diff --git a/README.md b/README.md index 32cb63a..5f1ff6d 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ See the [documentation](https://cfnptr.github.io/conf). ## Features -* Simple configuration syntax (similar to .ini) +* Simple configuration syntax (similar to YAML) * Automatic variable parsing (int, float, bool, string) * Built-in configuration syntax validation * C and C++ implementations @@ -69,21 +69,21 @@ void confWriterExampleC() ``` # Conf comment syntax example -integerValue = 123 -NegativeOne = -1 +integerValue: 123 +NegativeOne: -1 # Supported floating values -FloatingPI = 3.141 -minus Infinity = -INF -Oh nooo = NaN +FloatingPI: 3.141 +minus Infinity: -INF +Oh nooo: NaN # Also some booleans -is.planet.round = true -caseSensitive = False +is.planet.round: true +caseSensitive: False # And everything else is strings -hackingExploit = Hello world! -Not recommended key example? = Yes :) +hackingExploit: Hello world! +Not recommended key example? : Yes :) ``` ## Supported operating systems diff --git a/docs/annotated.html b/docs/annotated.html index 41d1749..86ef2ac 100644 --- a/docs/annotated.html +++ b/docs/annotated.html @@ -73,7 +73,7 @@ diff --git a/docs/classconf_1_1_reader.html b/docs/classconf_1_1_reader.html index 16ecde7..cac86d2 100644 --- a/docs/classconf_1_1_reader.html +++ b/docs/classconf_1_1_reader.html @@ -714,7 +714,7 @@

    - +
diff --git a/docs/classconf_1_1_writer.html b/docs/classconf_1_1_writer.html index 69fa550..2ed5437 100644 --- a/docs/classconf_1_1_writer.html +++ b/docs/classconf_1_1_writer.html @@ -774,7 +774,7 @@

    - +
diff --git a/docs/classes.html b/docs/classes.html index 8e0d23b..6e75209 100644 --- a/docs/classes.html +++ b/docs/classes.html @@ -75,7 +75,7 @@ diff --git a/docs/common_8h.html b/docs/common_8h.html index 1df6c37..78ca355 100644 --- a/docs/common_8h.html +++ b/docs/common_8h.html @@ -116,7 +116,7 @@ diff --git a/docs/dir_0af74dce6ed792f14cfe74ff7f287b3e.html b/docs/dir_0af74dce6ed792f14cfe74ff7f287b3e.html index b833af0..3a5f993 100644 --- a/docs/dir_0af74dce6ed792f14cfe74ff7f287b3e.html +++ b/docs/dir_0af74dce6ed792f14cfe74ff7f287b3e.html @@ -73,7 +73,7 @@ diff --git a/docs/dir_5078fa4b037495af7f2183084da91e6b.html b/docs/dir_5078fa4b037495af7f2183084da91e6b.html index 531ca07..abdd76e 100644 --- a/docs/dir_5078fa4b037495af7f2183084da91e6b.html +++ b/docs/dir_5078fa4b037495af7f2183084da91e6b.html @@ -80,7 +80,7 @@ diff --git a/docs/dir_5cec92fd47c0900910bbc2480fdfd7be.html b/docs/dir_5cec92fd47c0900910bbc2480fdfd7be.html index cf7b279..728236a 100644 --- a/docs/dir_5cec92fd47c0900910bbc2480fdfd7be.html +++ b/docs/dir_5cec92fd47c0900910bbc2480fdfd7be.html @@ -67,7 +67,7 @@ diff --git a/docs/dir_b83c5bfa094d9549d67909f0b459d78c.html b/docs/dir_b83c5bfa094d9549d67909f0b459d78c.html index 49bc20d..2ce270c 100644 --- a/docs/dir_b83c5bfa094d9549d67909f0b459d78c.html +++ b/docs/dir_b83c5bfa094d9549d67909f0b459d78c.html @@ -77,7 +77,7 @@ diff --git a/docs/dir_d44c64559bbebec7f509842c48db8b23.html b/docs/dir_d44c64559bbebec7f509842c48db8b23.html index 60525cf..a83ec62 100644 --- a/docs/dir_d44c64559bbebec7f509842c48db8b23.html +++ b/docs/dir_d44c64559bbebec7f509842c48db8b23.html @@ -73,7 +73,7 @@ diff --git a/docs/doxygen_crawl.html b/docs/doxygen_crawl.html index e73cd84..e9f0b8d 100644 --- a/docs/doxygen_crawl.html +++ b/docs/doxygen_crawl.html @@ -8,14 +8,14 @@ + + + - - - - + diff --git a/docs/files.html b/docs/files.html index 632ab53..f77a6c4 100644 --- a/docs/files.html +++ b/docs/files.html @@ -80,7 +80,7 @@ diff --git a/docs/functions.html b/docs/functions.html index 0bdb4e1..e97e457 100644 --- a/docs/functions.html +++ b/docs/functions.html @@ -74,7 +74,7 @@ diff --git a/docs/functions_func.html b/docs/functions_func.html index 85430d3..3b3516f 100644 --- a/docs/functions_func.html +++ b/docs/functions_func.html @@ -74,7 +74,7 @@ diff --git a/docs/globals.html b/docs/globals.html index c518ea6..e7a8c61 100644 --- a/docs/globals.html +++ b/docs/globals.html @@ -89,7 +89,7 @@ diff --git a/docs/globals_enum.html b/docs/globals_enum.html index 2355f8f..96b22af 100644 --- a/docs/globals_enum.html +++ b/docs/globals_enum.html @@ -67,7 +67,7 @@ diff --git a/docs/globals_func.html b/docs/globals_func.html index 6695321..1741dcb 100644 --- a/docs/globals_func.html +++ b/docs/globals_func.html @@ -81,7 +81,7 @@ diff --git a/docs/globals_type.html b/docs/globals_type.html index cab7e7d..80eae5d 100644 --- a/docs/globals_type.html +++ b/docs/globals_type.html @@ -71,7 +71,7 @@ diff --git a/docs/index.html b/docs/index.html index b4f1c7f..30f98a4 100644 --- a/docs/index.html +++ b/docs/index.html @@ -66,7 +66,7 @@

Features

    -
  • Simple configuration syntax (similar to .ini)
  • +
  • Simple configuration syntax (similar to YAML)
  • Automatic variable parsing (int, float, bool, string)
  • Built-in configuration syntax validation
  • C and C++ implementations
  • @@ -136,21 +136,21 @@

    Configuration file example

    # Conf comment syntax example
    -
    integerValue = 123
    -
    NegativeOne = -1
    +
    integerValue: 123
    +
    NegativeOne: -1
    # Supported floating values
    -
    FloatingPI = 3.141
    -
    minus Infinity = -INF
    -
    Oh nooo = NaN
    +
    FloatingPI: 3.141
    +
    minus Infinity: -INF
    +
    Oh nooo: NaN
    # Also some booleans
    -
    is.planet.round = true
    -
    caseSensitive = False
    +
    is.planet.round: true
    +
    caseSensitive: False
    # And everything else is strings
    -
    hackingExploit = Hello world!
    -
    Not recommended key example? = Yes :)
    +
    hackingExploit: Hello world!
    +
    Not recommended key example? : Yes :)

    Supported operating systems

      @@ -208,7 +208,7 @@

      diff --git a/docs/md__b_u_i_l_d_i_n_g.html b/docs/md__b_u_i_l_d_i_n_g.html index 12760b7..f0624bc 100644 --- a/docs/md__b_u_i_l_d_i_n_g.html +++ b/docs/md__b_u_i_l_d_i_n_g.html @@ -147,7 +147,7 @@

      diff --git a/docs/pages.html b/docs/pages.html index 840242c..8f016a1 100644 --- a/docs/pages.html +++ b/docs/pages.html @@ -71,7 +71,7 @@ diff --git a/docs/reader_8h.html b/docs/reader_8h.html index bd1cea5..6c3a387 100644 --- a/docs/reader_8h.html +++ b/docs/reader_8h.html @@ -437,7 +437,7 @@

        - +
      diff --git a/docs/reader_8hpp.html b/docs/reader_8hpp.html index b8d5696..7b0f011 100644 --- a/docs/reader_8hpp.html +++ b/docs/reader_8hpp.html @@ -87,7 +87,7 @@ diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 29cd7e6..7b318ae 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -5,28 +5,28 @@ xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> - https://cfnptr.github.io/conf/reader_8h.html + https://cfnptr.github.io/conf/writer_8hpp.html - https://cfnptr.github.io/conf/reader_8hpp.html + https://cfnptr.github.io/conf/writer_8h.html https://cfnptr.github.io/conf/common_8h.html - https://cfnptr.github.io/conf/writer_8h.html + https://cfnptr.github.io/conf/reader_8h.html - https://cfnptr.github.io/conf/writer_8hpp.html + https://cfnptr.github.io/conf/reader_8hpp.html https://cfnptr.github.io/conf/md__b_u_i_l_d_i_n_g.html - https://cfnptr.github.io/conf/classconf_1_1_writer.html + https://cfnptr.github.io/conf/classconf_1_1_reader.html - https://cfnptr.github.io/conf/classconf_1_1_reader.html + https://cfnptr.github.io/conf/classconf_1_1_writer.html https://cfnptr.github.io/conf/dir_5078fa4b037495af7f2183084da91e6b.html diff --git a/docs/writer_8h.html b/docs/writer_8h.html index c29cc42..3c77530 100644 --- a/docs/writer_8h.html +++ b/docs/writer_8h.html @@ -400,7 +400,7 @@

        - +
      diff --git a/docs/writer_8hpp.html b/docs/writer_8hpp.html index a4905b9..d7e98f1 100644 --- a/docs/writer_8hpp.html +++ b/docs/writer_8hpp.html @@ -87,7 +87,7 @@ diff --git a/source/reader.c b/source/reader.c index d971934..559a270 100644 --- a/source/reader.c +++ b/source/reader.c @@ -117,9 +117,9 @@ inline static ConfResult createConfItems(int(*getNextChar)(void*), void* handle, while (true) { int currentChar = getNextChar(handle); - if (currentChar == '=' && item.keySize == 0) + if (currentChar == ':' && item.keySize == 0) { - if (bufferSize <= 1 || buffer[bufferSize - 1] != ' ') + if (bufferSize == 0) { free(buffer); destroyConfItems(items, itemCount); if (errorLine) @@ -127,7 +127,7 @@ inline static ConfResult createConfItems(int(*getNextChar)(void*), void* handle, return BAD_KEY_CONF_RESULT; } - char* key = malloc(bufferSize * sizeof(char)); + char* key = malloc((bufferSize + 1) * sizeof(char)); if (!key) { free(buffer); destroyConfItems(items, itemCount); @@ -136,7 +136,6 @@ inline static ConfResult createConfItems(int(*getNextChar)(void*), void* handle, return FAILED_TO_ALLOCATE_CONF_RESULT; } - bufferSize--; memcpy(key, buffer, bufferSize * sizeof(char)); key[bufferSize] = '\0'; diff --git a/source/writer.c b/source/writer.c index a01a1e7..27eda8b 100644 --- a/source/writer.c +++ b/source/writer.c @@ -71,7 +71,7 @@ bool writeConfInt(ConfWriter confWriter, const char* key, int64_t value) { assert(confWriter); assert(key); - return fprintf(confWriter->file, "%s = %lld\n", key, (long long int)value) > 0; + return fprintf(confWriter->file, "%s: %lld\n", key, (long long int)value) > 0; } inline static bool getDoubleDigitCount(double value, uint8_t* count) @@ -96,15 +96,15 @@ bool writeConfFloat(ConfWriter confWriter, const char* key, double value, uint8_ if (value == INFINITY) { - return fprintf( confWriter->file, "%s = inf\n", key) > 0; + return fprintf( confWriter->file, "%s: inf\n", key) > 0; } else if (value == -INFINITY) { - return fprintf(confWriter->file, "%s = -inf\n", key) > 0; + return fprintf(confWriter->file, "%s: -inf\n", key) > 0; } else if (isnan(value)) { - return fprintf(confWriter->file, "%s = nan\n", key) > 0; + return fprintf(confWriter->file, "%s: nan\n", key) > 0; } else { @@ -115,7 +115,7 @@ bool writeConfFloat(ConfWriter confWriter, const char* key, double value, uint8_ if (precision > 0 && precision < digitCount) digitCount = precision; - return fprintf(confWriter->file, "%s = %.*f\n", key, digitCount, value) > 0; + return fprintf(confWriter->file, "%s: %.*f\n", key, digitCount, value) > 0; } } @@ -125,9 +125,9 @@ bool writeConfBool(ConfWriter confWriter, const char* key, bool value) assert(key); if (value) - return fprintf(confWriter->file, "%s = true\n", key) > 0; + return fprintf(confWriter->file, "%s: true\n", key) > 0; else - return fprintf( confWriter->file, "%s = false\n", key) > 0; + return fprintf( confWriter->file, "%s: false\n", key) > 0; } bool writeConfString(ConfWriter confWriter, const char* key, const char* value, size_t length) @@ -137,7 +137,7 @@ bool writeConfString(ConfWriter confWriter, const char* key, const char* value, assert(value); if (length == 0) - return fprintf(confWriter->file, "%s = %s\n", key, value) > 0; + return fprintf(confWriter->file, "%s: %s\n", key, value) > 0; else - return fprintf(confWriter->file, "%s = %.*s\n", key, (int)length, value) > 0; + return fprintf(confWriter->file, "%s: %.*s\n", key, (int)length, value) > 0; } \ No newline at end of file diff --git a/tests/test_reader.c b/tests/test_reader.c index a7fba0e..cf14bea 100644 --- a/tests/test_reader.c +++ b/tests/test_reader.c @@ -79,7 +79,7 @@ inline static bool testFailedToOpenFile() } inline static bool testGoodComment() { - if (!createTestFile("# Some conf comment x=1 ")) + if (!createTestFile("# Some conf comment x: 1 ")) return false; ConfReader confReader; @@ -120,7 +120,7 @@ inline static bool testBadComment() } inline static bool testBadKey() { - if (!createTestFile(" = 123")) + if (!createTestFile(": 123")) return false; ConfReader confReader; @@ -140,7 +140,7 @@ inline static bool testBadKey() } inline static bool testBadValue() { - if (!createTestFile("someKey = ")) + if (!createTestFile("someKey: ")) return false; ConfReader confReader; @@ -160,7 +160,7 @@ inline static bool testBadValue() } inline static bool testBadKeySpacing() { - if (!createTestFile("someKey= 123")) + if (!createTestFile("someKey :123")) return false; ConfReader confReader; @@ -180,7 +180,7 @@ inline static bool testBadKeySpacing() } inline static bool testBadValueSpacing() { - if (!createTestFile("someKey =123")) + if (!createTestFile("someKey:123")) return false; ConfReader confReader; @@ -205,7 +205,7 @@ inline static bool testInteger(int64_t value, const char* stringValue) const char* keyName = "someInteger"; char content[256]; - sprintf(content, "%s = %s", keyName, stringValue); + sprintf(content, "%s: %s", keyName, stringValue); if (!createTestFile(content)) return false; ConfReader confReader; @@ -252,7 +252,7 @@ inline static bool testFloating(double value, const char* stringValue) const char* keyName = "someFloating"; char content[256]; - sprintf(content, "%s = %s", keyName, stringValue); + sprintf(content, "%s: %s", keyName, stringValue); if (!createTestFile(content)) return false; @@ -307,7 +307,7 @@ inline static bool testBoolean(double value, const char* stringValue) const char* keyName = "someBoolean"; char content[256]; - sprintf(content, "%s = %s", keyName, stringValue); + sprintf(content, "%s: %s", keyName, stringValue); if (!createTestFile(content)) return false; ConfReader confReader; @@ -352,7 +352,7 @@ inline static bool testKey(const char* key) assert(key); char content[256]; - sprintf(content, "%s = 123", key); + sprintf(content, "%s: 123", key); if (!createTestFile(content)) return false; ConfReader confReader; @@ -401,7 +401,7 @@ inline static bool testString(const char* value) const char* keyName = "someString"; char content[256]; - sprintf(content, "%s = %s", keyName, value); + sprintf(content, "%s: %s", keyName, value); if (!createTestFile(content)) return false; ConfReader confReader; @@ -447,15 +447,15 @@ static const char* const testConfigString = "#similar to real \n" "\n" "# Some integer value\n" - "integer = 123456789\n" + "integer: 123456789\n" "\n" "\n" "# SOME_DOUBLE_VALUE?\n" "\n" - "DOUBLE = 0.123\n" - "Boolean = True\n" + "DOUBLE: 0.123\n" + "Boolean: True\n" "\n" - "string = Hello world!\n" + "string : Hello world!\n" "#comment\n"; inline static bool testConfig(ConfReader confReader) { @@ -563,7 +563,7 @@ inline static bool testFileConfig() bool result = testConfig(confReader); destroyConfReader(confReader); - return removeTestFile() & result; + return removeTestFile() && result; } inline static bool testDataConfig() { diff --git a/tests/test_writer.c b/tests/test_writer.c index 937e8b7..b753ba9 100644 --- a/tests/test_writer.c +++ b/tests/test_writer.c @@ -163,7 +163,7 @@ inline static bool testInteger(int64_t value, const char* stringValue) destroyConfWriter(confWriter); char buffer[256]; - sprintf(buffer, "%s = %s\n", keyName, stringValue); + sprintf(buffer, "%s: %s\n", keyName, stringValue); if (!compareTestFile(buffer)) { @@ -201,7 +201,7 @@ inline static bool testFloating(double value, const char* stringValue) destroyConfWriter(confWriter); char buffer[256]; - sprintf(buffer, "%s = %s\n", keyName, stringValue); + sprintf(buffer, "%s: %s\n", keyName, stringValue); if (!compareTestFile(buffer)) { @@ -239,7 +239,7 @@ inline static bool testBoolean(bool value, const char* stringValue) destroyConfWriter(confWriter); char buffer[256]; - sprintf(buffer, "%s = %s\n", keyName, stringValue); + sprintf(buffer, "%s: %s\n", keyName, stringValue); if (!compareTestFile(buffer)) { @@ -281,7 +281,7 @@ inline static bool testString(const char* value) destroyConfWriter(confWriter); char buffer[256]; - sprintf(buffer, "%s = %s\n", keyName, value); + sprintf(buffer, "%s: %s\n", keyName, value); if (!compareTestFile(buffer)) { @@ -362,11 +362,11 @@ inline static bool testConfig() result = compareTestFile( "# Conf file test\n" - "someInteger = 123\n" + "someInteger: 123\n" "\n" - "Floating = 1.0\n" - "BOOLEAN = true\n" - "string = Hello world!\n"); + "Floating: 1.0\n" + "BOOLEAN: true\n" + "string : Hello world!\n"); if (!result) {