1
0

ark_parser.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // Copyright 2026 Aarav Ravindra Kharade
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. #ifndef ARK_PARSER_H
  17. #define ARK_PARSER_H
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #define MAX_LINE_LEN 1024
  22. #define MAX_KEYS 128
  23. #define MAX_SECTIONS 32
  24. #define MAX_STANDALONE 32
  25. #define MAX_LIST_ITEMS 64
  26. typedef struct {
  27. char key[256];
  28. char value[512];
  29. } ArkKeyValuePair;
  30. typedef struct {
  31. char name[256];
  32. ArkKeyValuePair pairs[MAX_KEYS];
  33. int pair_count;
  34. } ArkSection;
  35. typedef struct {
  36. char filepath[512];
  37. ArkKeyValuePair global_pairs[MAX_KEYS];
  38. int global_count;
  39. ArkSection sections[MAX_SECTIONS];
  40. int section_count;
  41. char standalone[MAX_STANDALONE][512];
  42. int standalone_count;
  43. } ArkConfig;
  44. /* Parsed list result — caller must free items */
  45. typedef struct {
  46. char items[MAX_LIST_ITEMS][256];
  47. int count;
  48. } ArkList;
  49. ArkConfig *ark_parse(const char *filepath);
  50. const char *ark_get_global(ArkConfig *config, const char *key);
  51. const char *ark_get_section_val(ArkConfig *config, const char *section,
  52. const char *key);
  53. void ark_set_global(ArkConfig *config, const char *key, const char *value);
  54. void ark_dump(ArkConfig *config, const char *filepath);
  55. void ark_free(ArkConfig *config);
  56. /* New: List value support (comma-separated values) */
  57. ArkList ark_get_list(ArkConfig *config, const char *key);
  58. ArkList ark_get_section_list(ArkConfig *config, const char *section,
  59. const char *key);
  60. /* New: Boolean value support (true/false, yes/no, 1/0) */
  61. int ark_get_bool(ArkConfig *config, const char *key, int default_val);
  62. int ark_get_section_bool(ArkConfig *config, const char *section,
  63. const char *key, int default_val);
  64. #endif // ARK_PARSER_H