| 1 | /* |
| 2 | INI LIBRARY |
| 3 | |
| 4 | Header file for comment object. |
| 5 | |
| 6 | Copyright (C) Dmitri Pal <[email protected]> 2010 |
| 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_COMMENT_H |
| 23 | #define INI_COMMENT_H |
| 24 | |
| 25 | #include <stdint.h> |
| 26 | #include <stdio.h> |
| 27 | |
| 28 | #ifndef EOK |
| 29 | #define EOK 0 |
| 30 | #endif |
| 31 | |
| 32 | struct ini_comment; |
| 33 | |
| 34 | /** |
| 35 | * Create a comment object |
| 36 | */ |
| 37 | int ini_comment_create(struct ini_comment **ic); |
| 38 | |
| 39 | /** |
| 40 | * Construct a comment out of array or strings. |
| 41 | * |
| 42 | * If count is 0 then the array of strings must |
| 43 | * be NULL terminated i.e. last entry in the array |
| 44 | * should point to a NULL string. |
| 45 | * If it is not NULL it specifies the number of |
| 46 | * strings expected to be in the array. |
| 47 | */ |
| 48 | int ini_comment_construct(const char **comments, |
| 49 | size_t count_comment, |
| 50 | struct ini_comment **ic); |
| 51 | |
| 52 | /** |
| 53 | * Destroy the comment object |
| 54 | */ |
| 55 | void ini_comment_destroy(struct ini_comment *ic); |
| 56 | |
| 57 | /** |
| 58 | * Build up a comment object - use this when reading |
| 59 | * comments from a file. |
| 60 | */ |
| 61 | int ini_comment_build(struct ini_comment *ic, |
| 62 | const char *line); |
| 63 | |
| 64 | /** |
| 65 | * Build up a comment object - use this when reading |
| 66 | * comments from a file when length is known. |
| 67 | */ |
| 68 | int ini_comment_build_wl(struct ini_comment *ic, |
| 69 | const char *line, |
| 70 | uint32_t length); |
| 71 | |
| 72 | /** |
| 73 | * Modify comment by instering a line. |
| 74 | * |
| 75 | * idx can be: |
| 76 | * 0 - as first |
| 77 | * 1 - after first |
| 78 | * 2 - after second |
| 79 | * ... |
| 80 | * If greater than number of lines |
| 81 | * missing lines are added automatically |
| 82 | * as empty lines |
| 83 | */ |
| 84 | int ini_comment_insert(struct ini_comment *ic, |
| 85 | uint32_t idx, |
| 86 | const char *line); |
| 87 | |
| 88 | /** |
| 89 | * Modify comment by appending a line. |
| 90 | */ |
| 91 | int ini_comment_append(struct ini_comment *ic, |
| 92 | const char *line); |
| 93 | |
| 94 | /** |
| 95 | * Remove line from the comment. |
| 96 | */ |
| 97 | int ini_comment_remove(struct ini_comment *ic, |
| 98 | uint32_t idx); |
| 99 | |
| 100 | /** |
| 101 | * Clear line in the comment. |
| 102 | * Line is replaced with an empty line |
| 103 | */ |
| 104 | int ini_comment_clear(struct ini_comment *ic, |
| 105 | uint32_t idx); |
| 106 | |
| 107 | /** |
| 108 | * Replace a line in the comment |
| 109 | */ |
| 110 | int ini_comment_replace(struct ini_comment *ic, |
| 111 | uint32_t idx, |
| 112 | const char *line); |
| 113 | |
| 114 | /** |
| 115 | * Reset the comment - clean all lines. |
| 116 | */ |
| 117 | int ini_comment_reset(struct ini_comment *ic); |
| 118 | |
| 119 | /** |
| 120 | * Get number of lines |
| 121 | */ |
| 122 | int ini_comment_get_numlines(struct ini_comment *ic, |
| 123 | uint32_t *num); |
| 124 | |
| 125 | /** |
| 126 | * Get line |
| 127 | */ |
| 128 | int ini_comment_get_line(struct ini_comment *ic, |
| 129 | uint32_t idx, |
| 130 | char **line, |
| 131 | uint32_t *line_len); |
| 132 | |
| 133 | /** |
| 134 | * Swap lines |
| 135 | */ |
| 136 | int ini_comment_swap(struct ini_comment *ic, |
| 137 | uint32_t idx1, |
| 138 | uint32_t idx2); |
| 139 | |
| 140 | /** |
| 141 | * Create a copy of the comment object |
| 142 | */ |
| 143 | int ini_comment_copy(struct ini_comment *ic, |
| 144 | struct ini_comment **ic_copy); |
| 145 | |
| 146 | /** |
| 147 | * Add one comment to another |
| 148 | */ |
| 149 | int ini_comment_add(struct ini_comment *ic_to_add, |
| 150 | struct ini_comment *ic); |
| 151 | |
| 152 | /** |
| 153 | * Internal function to print comment |
| 154 | */ |
| 155 | void ini_comment_print(struct ini_comment *ic, FILE *file); |
| 156 | |
| 157 | |
| 158 | #endif |