| 1 | /* |
| 2 | INI LIBRARY |
| 3 | |
| 4 | Interface that allows modification of the INI file. |
| 5 | |
| 6 | Copyright (C) Dmitri Pal <[email protected]> 2014 |
| 7 | |
| 8 | INI Library is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU Lesser General Public License as published by |
| 10 | the Free Software Foundation, either version 3 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | INI Library is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU Lesser General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU Lesser General Public License |
| 19 | along with INI Library. If not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
| 21 | |
| 22 | #ifndef INI_CONFIGMOD_H |
| 23 | #define INI_CONFIGMOD_H |
| 24 | |
| 25 | |
| 26 | /** |
| 27 | * @defgroup insflags Flags used in add_xxx_value functions |
| 28 | * |
| 29 | * These flags control the behavior of the add_xxx_value functions. |
| 30 | * Use these flags to specify how you want to process the key. |
| 31 | * Do you want the function to replace an existing key? Or may be you want to |
| 32 | * generate an error when function sees that there is a duplicate key? |
| 33 | * Or may be you do not want to check anything and just add the key |
| 34 | * to the section? |
| 35 | * |
| 36 | * Individual values provide more details about use. |
| 37 | * |
| 38 | * @{ |
| 39 | */ |
| 40 | enum INI_VA { |
| 41 | /** @brief No check |
| 42 | * |
| 43 | * This is the default mode. Function will not perform |
| 44 | * any checks for duplicates and will just add a key. |
| 45 | */ |
| 46 | INI_VA_NOCHECK = 0, |
| 47 | /** |
| 48 | * @brief Update a specific value (best effort). |
| 49 | * |
| 50 | * Value of the index is used to determine which one of the duplicates |
| 51 | * needs to be updated. Index is 0-based. If the index is out of range |
| 52 | * the function will do best effort and return the last instance of the key. |
| 53 | * For example if you have five duplicates and you are searching for the tenth |
| 54 | * the function will find and return the fifth instance. |
| 55 | */ |
| 56 | INI_VA_MOD = 1, |
| 57 | /** |
| 58 | * @brief Update a specific value (with error). |
| 59 | * |
| 60 | * Value of the index is used to determine which one of the duplicates |
| 61 | * needs to be updated. Index is 0-based. If the value is not found or |
| 62 | * the index is out of range the function returns ENOENT. |
| 63 | * For example if you have five duplicates and you are searching for the tenth |
| 64 | * the error ENOENT will be returned. |
| 65 | */ |
| 66 | INI_VA_MOD_E = 2, |
| 67 | |
| 68 | /** |
| 69 | * @brief Update or add if not found (best effort). |
| 70 | * |
| 71 | * Function will check for duplicates and would overwrite the specified |
| 72 | * key if found. |
| 73 | * Value of the index is used to determine which one of the duplicates |
| 74 | * needs to be updated. Index is 0-based. If the value is not found |
| 75 | * the new value will be added following other position related arguments. |
| 76 | * This option performs best effort search. |
| 77 | * For example if you have five duplicates and you are searching for the tenth |
| 78 | * the function will find and return fifth instance. |
| 79 | */ |
| 80 | INI_VA_MODADD = 3, |
| 81 | |
| 82 | /** |
| 83 | * @brief Update or add if not found (with error). |
| 84 | * |
| 85 | * Function will check for duplicates and would overwrite the specified |
| 86 | * key if found. |
| 87 | * Value of the index is used to determine which one of the duplicates |
| 88 | * needs to be updated. Index is 0-based. If the value is not found |
| 89 | * the new value will be added following other position related arguments. |
| 90 | * This option performs an exact search. |
| 91 | * For example if you have five duplicates and you are searching for tenth |
| 92 | * the error ENOENT will be returned. |
| 93 | */ |
| 94 | INI_VA_MODADD_E = 4, |
| 95 | |
| 96 | /** @brief Clean all duplicates. |
| 97 | * |
| 98 | * Find all instances of the specific key and remove them first. |
| 99 | * Then add the new key respecting the position related arguments. |
| 100 | */ |
| 101 | INI_VA_CLEAN = 5, |
| 102 | |
| 103 | /** @brief Error if duplicate |
| 104 | * |
| 105 | * Return error EEXIST if an entry with the same key exists. |
| 106 | */ |
| 107 | INI_VA_DUPERROR = 6 |
| 108 | }; |
| 109 | /** |
| 110 | * @} |
| 111 | */ |
| 112 | |
| 113 | /** |
| 114 | * @defgroup ini_mod API to create and modify configuration objects |
| 115 | * |
| 116 | * Functions in this section allow creation, modification |
| 117 | * and deletion of sections and keys. |
| 118 | * |
| 119 | * Explanation of some of the common arguments: |
| 120 | * |
| 121 | * @param[in] position Specifies the position a key or a section |
| 122 | * should be added to.\n\n |
| 123 | * Options include: |
| 124 | * - Last in the list |
| 125 | * - First in the list |
| 126 | * - N-th element of the list |
| 127 | * - Before a specific element of the list |
| 128 | * - After a specific element of the list |
| 129 | * - As a first duplicate of a specific element |
| 130 | * - As a last duplicate of a specific element |
| 131 | * - As an N-th duplicate of a specific element |
| 132 | * \n\n |
| 133 | * Duplicates can be sequential or not, so there |
| 134 | * are different constants that specify whether |
| 135 | * to count all duplicates or just the ones that |
| 136 | * go together.\n |
| 137 | * @param[in] other_xxx Used in conjunction with 'position' constant. |
| 138 | * In some cases it is convenient to add |
| 139 | * a section or key immediately before |
| 140 | * or after another section or key. |
| 141 | * While 'position' defines |
| 142 | * where it should be added, this parameter defines |
| 143 | * the section or key to relate to. |
| 144 | * @param[in] idx Index allows treating set of sections or keys |
| 145 | * as an array and add Nth section or key. |
| 146 | |
| 147 | * @{ |
| 148 | * |
| 149 | */ |
| 150 | |
| 151 | |
| 152 | /** |
| 153 | * @brief Function to add a section. |
| 154 | * |
| 155 | * Function creates a new section in the specified position. |
| 156 | * The position is relative to other sections. Duplicate sections |
| 157 | * are not allowed. In case a duplicate section is detected function |
| 158 | * will return error EEXIST. |
| 159 | * |
| 160 | * @param[in] ini_config Configuration object to modify. |
| 161 | * @param[in] section Name of the section to add. |
| 162 | * @param[in] comments Array of comments. Can be NULL, if no comment is |
| 163 | * needed for the section. It is expected that |
| 164 | * comment lines start with the correct comment |
| 165 | * symbol. Function does not check this. |
| 166 | * Use empty string to express an empty line. |
| 167 | * @param[in] count_comment Count of comments in the array. If 0, |
| 168 | * the array is expected to be NULL terminated |
| 169 | * and function will traverse array until its end. |
| 170 | * @param[in] position A constant that specifies the way the |
| 171 | * section should be added. For more information |
| 172 | * see "disposition constants" section of |
| 173 | * the collection (collection.h) interface. |
| 174 | * The value is used only in the add operation |
| 175 | * so see the explanation in the "insert" paragraph. |
| 176 | * Since duplicate sections are not allowed |
| 177 | * any constants that request addition of |
| 178 | * a duplicate will cause function |
| 179 | * to return an error. |
| 180 | * @param[in] other_section Used in conjunction with position constant. |
| 181 | * In some cases it is convenient to add |
| 182 | * a section that is immediately before |
| 183 | * or after another section. While position defines |
| 184 | * where it should be added, this parameter defines |
| 185 | * the section to relate to. |
| 186 | * @param[in] idx Index, allows treating set of sections as |
| 187 | * an array and add Nth section. |
| 188 | * |
| 189 | * @return 0 - Success. |
| 190 | * @return EEXIST - Section already exists. |
| 191 | * @return ENOSYS - Unknown position value. |
| 192 | * @return ENOMEM - No memory to add value. |
| 193 | * @return EINVAL - Invalid argument. |
| 194 | */ |
| 195 | int ini_config_add_section(struct ini_cfgobj *ini_config, |
| 196 | const char *section, |
| 197 | const char *comments[], |
| 198 | size_t count_comment, |
| 199 | int position, |
| 200 | const char *other_section, |
| 201 | int idx); |
| 202 | |
| 203 | /** |
| 204 | * @brief Function to update a comment for a section. |
| 205 | * |
| 206 | * Function finds a section and updates or removes its comment. |
| 207 | * |
| 208 | * @param[in] ini_config Configuration object to modify. |
| 209 | * @param[in] section Name of the section to change the comment for. |
| 210 | * @param[in] comments Array of comments. Can be NULL if no comment is |
| 211 | * needed for the section. It is expected that |
| 212 | * comment lines start with the correct comment |
| 213 | * symbol. Function does not check this. |
| 214 | * Use empty string to express an empty line. |
| 215 | * @param[in] count_comment Count of comments in the array. If 0 |
| 216 | * the array is expected to be NULL terminated |
| 217 | * and function will traverse array until its end. |
| 218 | * |
| 219 | * @return 0 - Success. |
| 220 | * @return ENOENT - Section is not found. |
| 221 | * @return ENOMEM - No memory to add value. |
| 222 | * @return EINVAL - Invalid argument. |
| 223 | */ |
| 224 | int ini_config_comment_section(struct ini_cfgobj *ini_config, |
| 225 | const char *section, |
| 226 | const char *comments[], |
| 227 | size_t count_comment); |
| 228 | |
| 229 | /** |
| 230 | * @brief Function to rename a section. |
| 231 | * |
| 232 | * Function finds a section and renames it. |
| 233 | * |
| 234 | * @param[in] ini_config Configuration object to modify. |
| 235 | * @param[in] section Name of the section to find. |
| 236 | * @param[in] newname New section name. |
| 237 | * |
| 238 | * @return 0 - Success. |
| 239 | * @return ENOENT - Section is not found. |
| 240 | * @return ENOMEM - No memory to add value. |
| 241 | * @return EINVAL - Invalid argument. |
| 242 | */ |
| 243 | int ini_config_rename_section(struct ini_cfgobj *ini_config, |
| 244 | const char *section, |
| 245 | const char *newname); |
| 246 | |
| 247 | |
| 248 | /** |
| 249 | * @brief Function to delete a section by name. |
| 250 | * |
| 251 | * Function is a convenience wrapper around |
| 252 | * \ref ini_config_delete_section_by_position function. |
| 253 | * |
| 254 | * @param[in] ini_config Configuration object to modify. |
| 255 | * @param[in] section Name of the section to delete. |
| 256 | * |
| 257 | * @return 0 - Success. |
| 258 | * @return ENOENT - Section is not found. |
| 259 | * @return ENOMEM - No memory to add value. |
| 260 | * @return EINVAL - Invalid argument. |
| 261 | */ |
| 262 | int ini_config_delete_section_by_name(struct ini_cfgobj *ini_config, |
| 263 | const char *section); |
| 264 | |
| 265 | /** |
| 266 | * @brief Function to delete a section by position or name. |
| 267 | * |
| 268 | * Function allows removing a specific section by its relative position |
| 269 | * in the list of sections or by its name. |
| 270 | * |
| 271 | * @param[in] ini_config Configuration object to modify. |
| 272 | * @param[in] position A constant that specifies the way the |
| 273 | * section should be deleted. For more information |
| 274 | * see "disposition constants" section of |
| 275 | * the collection interface. The value is used |
| 276 | * only in delete operation so see the explanation |
| 277 | * in the "delete" paragraph. |
| 278 | * There can't be duplicate sections. However |
| 279 | * function respects all of the listed constants. |
| 280 | * To find and delete a particular section |
| 281 | * one can use COL_DSP_FIRSTDUP constant. |
| 282 | * One should just expect that there is only |
| 283 | * one instance of every section if any. |
| 284 | * @param[in] section Used in conjunction with position constant. |
| 285 | * In some cases it is convenient to add |
| 286 | * a section immediately before |
| 287 | * or after another value. While position defines |
| 288 | * where it should be added, this parameter defines |
| 289 | * the section to relate to. |
| 290 | * @param[in] idx Index of the position. |
| 291 | * For example one can specify |
| 292 | * that the third section should be deleted. |
| 293 | * |
| 294 | * @return 0 - Success. |
| 295 | * @return ENOENT - Section is not found. |
| 296 | * @return ENOMEM - No memory to add value. |
| 297 | * @return EINVAL - Invalid argument. |
| 298 | */ |
| 299 | int ini_config_delete_section_by_position(struct ini_cfgobj *ini_config, |
| 300 | int position, |
| 301 | const char *section, |
| 302 | int idx); |
| 303 | |
| 304 | |
| 305 | /** |
| 306 | * @brief Function to a add string value to a particular section. |
| 307 | * |
| 308 | * Depending on the flags function adds, or deletes and adds, or just modifies |
| 309 | * the configuration value stored in the configuration object. |
| 310 | * |
| 311 | * \b NOTE: all other ini_config_add_xxx_value functions are implemented |
| 312 | * as wrappers around this function so they have the same |
| 313 | * behavior and logic. |
| 314 | * |
| 315 | * @param[in] ini_config Configuration object to modify. |
| 316 | * @param[in] section Name of the section to modify. |
| 317 | * @param[in] key Key of the value to add or modify. |
| 318 | * @param[in] value String that represents the value. |
| 319 | * @param[in] comments Array of comments. Can be NULL if no comment is |
| 320 | * needed for the section. It is expected that |
| 321 | * comment lines start with the correct comment |
| 322 | * symbol. Function does not check this. |
| 323 | * Use empty string to express an empty line. |
| 324 | * @param[in] count_comment Count of comments in the array. If 0, |
| 325 | * the array is expected to be NULL terminated |
| 326 | * and function will traverse array until its end. |
| 327 | * @param[in] border The boundary the value should be wrapped at. |
| 328 | * The usual value is 80 characters. |
| 329 | * @param[in] position A constant that specifies the way the |
| 330 | * value should be added. For more information |
| 331 | * see "disposition constants" section of |
| 332 | * the collection interface. The value is used |
| 333 | * only in add operation so see the explanation |
| 334 | * in the "insert" paragraph. |
| 335 | * @param[in] other_key Used in conjunction with 'position' constant. |
| 336 | * In some cases it is convenient to add |
| 337 | * a value that should be placed immediately before |
| 338 | * or after another value. While position defines |
| 339 | * where it should be added, this parameter defines |
| 340 | * the key to relate to. |
| 341 | * @param[in] idx Index in the whole section or among |
| 342 | * duplicates. For example one can specify |
| 343 | * that the value should be added as a third |
| 344 | * duplicate. This is convenient if INI file allows |
| 345 | * duplicate keys. |
| 346 | * @param[in] flags These constants define the main behavior of |
| 347 | * the function. The function can thus be used |
| 348 | * to build configuration object from scratch |
| 349 | * (in this case no checks would be needed), |
| 350 | * to modify a specific key which can be identified |
| 351 | * by index among duplicate keys in the same |
| 352 | * section. For more information see \ref insflags. |
| 353 | * |
| 354 | * @return 0 - Success. |
| 355 | * @return EEXIST - The value already exists. |
| 356 | * @return ENOENT - The value not found. |
| 357 | * @return ENOSYS - Unknown flag or position value. |
| 358 | * @return ENOMEM - No memory to add value. |
| 359 | * @return EINVAL - Invalid argument. |
| 360 | */ |
| 361 | int ini_config_add_str_value(struct ini_cfgobj *ini_config, |
| 362 | const char *section, |
| 363 | const char *key, |
| 364 | const char *value, |
| 365 | const char *comments[], |
| 366 | size_t count_comment, |
| 367 | int border, |
| 368 | int position, |
| 369 | const char *other_key, |
| 370 | int idx, |
| 371 | enum INI_VA flags); |
| 372 | |
| 373 | /** |
| 374 | * @brief Function to add an integer value to a particular section. |
| 375 | * |
| 376 | * Function is similar to \ref ini_config_add_str_value except it uses |
| 377 | * an integer argument for the value input. |
| 378 | * |
| 379 | * For logic, behavior and return values see \ref ini_config_add_str_value. |
| 380 | */ |
| 381 | int ini_config_add_int_value(struct ini_cfgobj *ini_config, |
| 382 | const char *section, |
| 383 | const char *key, |
| 384 | int value, |
| 385 | const char *comments[], |
| 386 | size_t count_comment, |
| 387 | int border, |
| 388 | int position, |
| 389 | const char *other_key, |
| 390 | int idx, |
| 391 | enum INI_VA flags); |
| 392 | |
| 393 | /** |
| 394 | * @brief Function to add a long value to a particular section. |
| 395 | * |
| 396 | * Function is similar to \ref ini_config_add_str_value except it uses |
| 397 | * a long integer argument for the value input. |
| 398 | * |
| 399 | * For logic, behavior and return values see \ref ini_config_add_str_value. |
| 400 | */ |
| 401 | int ini_config_add_long_value(struct ini_cfgobj *ini_config, |
| 402 | const char *section, |
| 403 | const char *key, |
| 404 | long value, |
| 405 | const char *comments[], |
| 406 | size_t count_comment, |
| 407 | int border, |
| 408 | int position, |
| 409 | const char *other_key, |
| 410 | int idx, |
| 411 | enum INI_VA flags); |
| 412 | |
| 413 | /** |
| 414 | * @brief Function to add an unsigned long value to a particular section. |
| 415 | * |
| 416 | * Function is similar to \ref ini_config_add_str_value except it uses |
| 417 | * an unsigned long integer argument for the value input. |
| 418 | * |
| 419 | * For logic, behavior and return values see \ref ini_config_add_str_value. |
| 420 | */ |
| 421 | int ini_config_add_ulong_value(struct ini_cfgobj *ini_config, |
| 422 | const char *section, |
| 423 | const char *key, |
| 424 | unsigned long value, |
| 425 | const char *comments[], |
| 426 | size_t count_comment, |
| 427 | int border, |
| 428 | int position, |
| 429 | const char *other_key, |
| 430 | int idx, |
| 431 | enum INI_VA flags); |
| 432 | |
| 433 | /** |
| 434 | * @brief Function to add an unsigned value to a particular section. |
| 435 | * |
| 436 | * Function is similar to \ref ini_config_add_str_value except it uses |
| 437 | * an unsigned argument for the value input. |
| 438 | * |
| 439 | * For logic, behavior and return values see \ref ini_config_add_str_value. |
| 440 | */ |
| 441 | int ini_config_add_unsigned_value(struct ini_cfgobj *ini_config, |
| 442 | const char *section, |
| 443 | const char *key, |
| 444 | unsigned value, |
| 445 | const char *comments[], |
| 446 | size_t count_comment, |
| 447 | int border, |
| 448 | int position, |
| 449 | const char *other_key, |
| 450 | int idx, |
| 451 | enum INI_VA flags); |
| 452 | |
| 453 | /** |
| 454 | * @brief Function to add an int32 value to a particular section. |
| 455 | * |
| 456 | * Function is similar to \ref ini_config_add_str_value except it uses |
| 457 | * an int32 argument for the value input. |
| 458 | * |
| 459 | * For logic, behavior and return values see \ref ini_config_add_str_value. |
| 460 | */ |
| 461 | int ini_config_add_int32_value(struct ini_cfgobj *ini_config, |
| 462 | const char *section, |
| 463 | const char *key, |
| 464 | int32_t value, |
| 465 | const char *comments[], |
| 466 | size_t count_comment, |
| 467 | int border, |
| 468 | int position, |
| 469 | const char *other_key, |
| 470 | int idx, |
| 471 | enum INI_VA flags); |
| 472 | |
| 473 | /** |
| 474 | * @brief Function to add an uint32 value to a particular section. |
| 475 | * |
| 476 | * Function is similar to \ref ini_config_add_str_value except it uses |
| 477 | * an uint32 argument for the value input. |
| 478 | * |
| 479 | * For logic, behavior and return values see \ref ini_config_add_str_value. |
| 480 | */ |
| 481 | int ini_config_add_uint32_value(struct ini_cfgobj *ini_config, |
| 482 | const char *section, |
| 483 | const char *key, |
| 484 | uint32_t value, |
| 485 | const char *comments[], |
| 486 | size_t count_comment, |
| 487 | int border, |
| 488 | int position, |
| 489 | const char *other_key, |
| 490 | int idx, |
| 491 | enum INI_VA flags); |
| 492 | |
| 493 | /** |
| 494 | * @brief Function to add an int64 value to a particular section. |
| 495 | * |
| 496 | * Function is similar to \ref ini_config_add_str_value except it uses |
| 497 | * an int64 argument for the value input. |
| 498 | * |
| 499 | * For logic, behavior and return values see \ref ini_config_add_str_value. |
| 500 | */ |
| 501 | int ini_config_add_int64_value(struct ini_cfgobj *ini_config, |
| 502 | const char *section, |
| 503 | const char *key, |
| 504 | int64_t value, |
| 505 | const char *comments[], |
| 506 | size_t count_comment, |
| 507 | int border, |
| 508 | int position, |
| 509 | const char *other_key, |
| 510 | int idx, |
| 511 | enum INI_VA flags); |
| 512 | |
| 513 | /** |
| 514 | * @brief Function to add an uint64 value to a particular section. |
| 515 | * |
| 516 | * Function is similar to \ref ini_config_add_str_value except it uses |
| 517 | * an uint64 argument for the value input. |
| 518 | * |
| 519 | * For logic, behavior and return values see \ref ini_config_add_str_value. |
| 520 | */ |
| 521 | int ini_config_add_uint64_value(struct ini_cfgobj *ini_config, |
| 522 | const char *section, |
| 523 | const char *key, |
| 524 | uint64_t value, |
| 525 | const char *comments[], |
| 526 | size_t count_comment, |
| 527 | int border, |
| 528 | int position, |
| 529 | const char *other_key, |
| 530 | int idx, |
| 531 | enum INI_VA flags); |
| 532 | |
| 533 | /** |
| 534 | * @brief Function to add a double value to a particular section. |
| 535 | * |
| 536 | * Function is similar to \ref ini_config_add_str_value except it uses |
| 537 | * a double argument for the value input. |
| 538 | * |
| 539 | * For logic, behavior and return values see \ref ini_config_add_str_value. |
| 540 | */ |
| 541 | int ini_config_add_double_value(struct ini_cfgobj *ini_config, |
| 542 | const char *section, |
| 543 | const char *key, |
| 544 | double value, |
| 545 | const char *comments[], |
| 546 | size_t count_comment, |
| 547 | int border, |
| 548 | int position, |
| 549 | const char *other_key, |
| 550 | int idx, |
| 551 | enum INI_VA flags); |
| 552 | |
| 553 | /** |
| 554 | * @brief Function to add a binary value to a particular section. |
| 555 | * |
| 556 | * Binary values are represented by a HEX string where two HEX digits |
| 557 | * represent one byte of the source data. The value is surrounded |
| 558 | * by a pair of single quotes. |
| 559 | * |
| 560 | * Function is similar to \ref ini_config_add_str_value except it uses |
| 561 | * a void argument for the value input. The length of the data is specified by |
| 562 | * by the value_len argument. |
| 563 | * |
| 564 | * For logic, behavior and return values see \ref ini_config_add_str_value. |
| 565 | */ |
| 566 | int ini_config_add_bin_value(struct ini_cfgobj *ini_config, |
| 567 | const char *section, |
| 568 | const char *key, |
| 569 | void *value, |
| 570 | size_t value_len, |
| 571 | const char *comments[], |
| 572 | size_t count_comment, |
| 573 | int border, |
| 574 | int position, |
| 575 | const char *other_key, |
| 576 | int idx, |
| 577 | enum INI_VA flags); |
| 578 | |
| 579 | /** |
| 580 | * @brief Function to add a value that consists of an array of constant strings |
| 581 | * to a particular section. |
| 582 | * |
| 583 | * Function is similar to \ref ini_config_add_str_value except it uses |
| 584 | * a string array argument and a count for the value input. |
| 585 | * |
| 586 | * For logic, behavior and return values see \ref ini_config_add_str_value. |
| 587 | */ |
| 588 | int ini_config_add_const_str_arr_value(struct ini_cfgobj *ini_config, |
| 589 | const char *section, |
| 590 | const char *key, |
| 591 | const char *value_str_arr[], |
| 592 | size_t count_str, |
| 593 | char sep, |
| 594 | const char *comments[], |
| 595 | size_t count_comment, |
| 596 | int border, |
| 597 | int position, |
| 598 | const char *other_key, |
| 599 | int idx, |
| 600 | enum INI_VA flags); |
| 601 | |
| 602 | /** |
| 603 | * @brief Function to add a value that consists of an array of strings |
| 604 | * to a particular section. |
| 605 | * |
| 606 | * Function is similar to \ref ini_config_add_str_value except it uses |
| 607 | * a string array argument and a count for the value input. |
| 608 | * |
| 609 | * For logic, behavior and return values see \ref ini_config_add_str_value. |
| 610 | */ |
| 611 | int ini_config_add_str_arr_value(struct ini_cfgobj *ini_config, |
| 612 | const char *section, |
| 613 | const char *key, |
| 614 | char *value_str_arr[], |
| 615 | size_t count_str, |
| 616 | char sep, |
| 617 | const char *comments[], |
| 618 | size_t count_comment, |
| 619 | int border, |
| 620 | int position, |
| 621 | const char *other_key, |
| 622 | int idx, |
| 623 | enum INI_VA flags); |
| 624 | |
| 625 | /** |
| 626 | * @brief Function to add a value that consists of an array of integers |
| 627 | * to a particular section. |
| 628 | * |
| 629 | * Function is similar to \ref ini_config_add_str_value except it uses |
| 630 | * a integer array argument and a count for the value input. |
| 631 | * |
| 632 | * For logic, behavior and return values see \ref ini_config_add_str_value. |
| 633 | */ |
| 634 | int ini_config_add_int_arr_value(struct ini_cfgobj *ini_config, |
| 635 | const char *section, |
| 636 | const char *key, |
| 637 | int *value_int_arr, |
| 638 | size_t count_int, |
| 639 | char sep, |
| 640 | const char *comments[], |
| 641 | size_t count_comment, |
| 642 | int border, |
| 643 | int position, |
| 644 | const char *other_key, |
| 645 | int idx, |
| 646 | enum INI_VA flags); |
| 647 | |
| 648 | /** |
| 649 | * @brief Function to add a value that consists of an array of long integers |
| 650 | * to a particular section. |
| 651 | * |
| 652 | * Function is similar to \ref ini_config_add_str_value except it uses |
| 653 | * a long integer array argument and a count for the value input. |
| 654 | * |
| 655 | * For logic, behavior and return values see \ref ini_config_add_str_value. |
| 656 | */ |
| 657 | int ini_config_add_long_arr_value(struct ini_cfgobj *ini_config, |
| 658 | const char *section, |
| 659 | const char *key, |
| 660 | long *value_long_arr, |
| 661 | size_t count_long, |
| 662 | char sep, |
| 663 | const char *comments[], |
| 664 | size_t count_comment, |
| 665 | int border, |
| 666 | int position, |
| 667 | const char *other_key, |
| 668 | int idx, |
| 669 | enum INI_VA flags); |
| 670 | |
| 671 | /** |
| 672 | * @brief Function to add a value that consists of an array of doubles |
| 673 | * to a particular section. |
| 674 | * |
| 675 | * Function is similar to \ref ini_config_add_str_value except it uses |
| 676 | * a double array argument and a count for the value input. |
| 677 | * |
| 678 | * For logic, behavior and return values see \ref ini_config_add_str_value. |
| 679 | */ |
| 680 | int ini_config_add_double_arr_value(struct ini_cfgobj *ini_config, |
| 681 | const char *section, |
| 682 | const char *key, |
| 683 | double *value_double_arr, |
| 684 | size_t count_double, |
| 685 | char sep, |
| 686 | const char *comments[], |
| 687 | size_t count_comment, |
| 688 | int border, |
| 689 | int position, |
| 690 | const char *other_key, |
| 691 | int idx, |
| 692 | enum INI_VA flags); |
| 693 | |
| 694 | /** |
| 695 | * @brief Function to delete a value. |
| 696 | * |
| 697 | * Function deletes a value specified either by key or by position. |
| 698 | * For example the caller can remove first or last key of the section as well |
| 699 | * as first, last or specific instance of a specific key. If key is searched |
| 700 | * by index and index is out of range the function would return ENOENT |
| 701 | * indicating that specifically requested key is not found. |
| 702 | * |
| 703 | * @param[in] ini_config Configuration object to modify. |
| 704 | * @param[in] section Name of the section to remove the key from. |
| 705 | * @param[in] position A constant that specifies the way the |
| 706 | * key should be removed. For more information |
| 707 | * see "disposition constants" section of |
| 708 | * the collection interface, and specifically |
| 709 | * the "delete" paragraph. |
| 710 | * @param[in] key Used in conjunction with 'position' constant. |
| 711 | * Depending on the value of the position |
| 712 | * argument the key argument can specify |
| 713 | * the key to delete or the key that the delete |
| 714 | * operation should be relative to. |
| 715 | * @param[in] idx Index of duplicates. For example one can specify |
| 716 | * that he wants to delete the third duplicate |
| 717 | * of a specific key. If there are less duplicates, |
| 718 | * i.e. the index is out of range, the function |
| 719 | * will return ENOENT. |
| 720 | * |
| 721 | * @return 0 - Value was removed. |
| 722 | * @return ENOENT - The value not found. |
| 723 | */ |
| 724 | int ini_config_delete_value(struct ini_cfgobj *ini_config, |
| 725 | const char *section, |
| 726 | int position, |
| 727 | const char *key, |
| 728 | int idx); |
| 729 | |
| 730 | /** |
| 731 | * @brief Function to update a comment. |
| 732 | * |
| 733 | * Function can be used to find and modify a comment for a specific |
| 734 | * key in a specific section. |
| 735 | * |
| 736 | * @param[in] ini_config Configuration object to modify. |
| 737 | * @param[in] section Name of the section to find the key. |
| 738 | * @param[in] key The key to find. |
| 739 | * @param[in] comments The array of comments. Can be NULL. If NULL, |
| 740 | * the existing comment will be removed if any. |
| 741 | * The comment lines are expected to start with a |
| 742 | * standard comment symbol. The function does not |
| 743 | check this. |
| 744 | * Use empty string to express an empty line. |
| 745 | * @param[in] count_comment Count of comments. If 0 the comment is |
| 746 | * constructed using array of strings above. |
| 747 | * It is expected to be NULL terminated. |
| 748 | * @param[in] idx Index of duplicates. For example one can specify |
| 749 | * that he wants to find the third duplicate |
| 750 | * of a specific key. If there are less duplicates, |
| 751 | * i.e. the index is out of range, the function |
| 752 | * will return ENOENT. |
| 753 | * |
| 754 | * @return 0 - Value was removed. |
| 755 | * @return ENOENT - The value not found. |
| 756 | */ |
| 757 | |
| 758 | int ini_config_update_comment(struct ini_cfgobj *ini_config, |
| 759 | const char *section, |
| 760 | const char *key, |
| 761 | const char *comments[], |
| 762 | size_t count_comment, |
| 763 | int idx); |
| 764 | /** |
| 765 | * @} |
| 766 | */ |
| 767 | #endif |