1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
|
/*
* parlist.h - parameters list
*
* Copyright (C) 1999-2001 by Roman Khnykin <romaroma@rr.org.ua>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* Created: 22.06.1999 romaroma Initial revision.
* Changed: 05.03.2000 romaroma Documentation added.
* Changed: 19.07.2000 romaroma Bugfix.
* Changed: 17.08.2000 romaroma New functions.
* Changed: 20.08.2000 romaroma New functions.
*
*/
#ifndef _PARLIST_H
#define _PARLIST_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
/*****************************************************************************/
/* Internal list data */
/*****************************************************************************/
#define LIST_VALUE 0
#define LIST_ARRAY 1
#define LIST_LIST 2
typedef struct pparam_struct {
char *name;
void *value;
int vsize;
int vtype;
} pparam;
typedef struct pparamslist_struct {
pparam *items;
int count;
} pparamslist;
/*****************************************************************************/
/* Functions for create/delete lists */
/*****************************************************************************/
/*
* pparamslist_create - Create a new list.
*
* Parameters:
* none
*
* Return value:
* pparamslist * - new list address
*/
pparamslist *pparamslist_create();
/*
* pparamslist_free - Delete list.
*
* Parameters:
* pparamslist *list - list address
*
* Return value:
* none
*/
void pparamslist_free(pparamslist *list);
/*****************************************************************************/
/* Functions for manipulate list items */
/*****************************************************************************/
/*
* pparamslist_add - Add new text value to list.
*
* Parameters:
* char *name - variable name
* char *value - variable value
* pparamslist *list - list address
*
* Return value:
* int - index of new variable
*/
int pparamslist_add(const char *name, const char *value, pparamslist *list);
/*
* pparamslist_add_ptr - Add new pointer to list (not create copy of value).
*
* Parameters:
* char *name - variable name
* void *value - variable value
* int vsize - variable size. If it's zero - value never be freed.
* pparamslist *list - list address
*
* Return value:
* int - index of new variable
*/
int pparamslist_add_ptr(const char *name, const void *value, int vsize, pparamslist *list);
/*
* pparamslist_add_format - Add new text value to list using printf format.
*
* Parameters:
* char *name - variable name
* pparamslist *list - list address
* char *format - value format string
* ... - values
*
* Return value:
* int - index of new variable
*/
int pparamslist_add_format(const char *name, pparamslist *list, const char *format, ...);
/*
* pparamslist_add_list - Create new sub-list and add it to exist list as item.
*
* Parameters:
* char *name - new list name
* pparamslist *list - list address
*
* Return value:
* pparamslist * - new sub-list address
*/
pparamslist *pparamslist_add_list(const char *name, pparamslist *list);
/*
* pparamslist_add_array - Create new array and add it to exist list as item.
* This function can copy data from any existing array.
*
* Parameters:
* char *name - array name
* char **values - existing array (or NULL if doesn't need copy)
* int *arsize - existing array length (or 0 if doesn't need copy)
* pparamslist *list - list address
*
* Return value:
* none
*/
void pparamslist_add_array(const char *name, const char **values, int arrsize, pparamslist *list);
/*
* pparamslist_set - Set new variable value.
* If variable not found it will be created.
*
* Parameters:
* char *name - variable name
* char *value - variable value
* pparamslist *list - list address
*
* Return value:
* none
*/
void pparamslist_set(const char *name, const char *value, pparamslist *list);
/*
* pparamslist_set_ptr - Set new variable pointer (not create copy of value).
* If variable not found it will be created.
*
* Parameters:
* char *name - variable name
* void *value - variable pointer
* int vsize - variable size. If it's zero - value never be freed.
* pparamslist *list - list address
*
* Return value:
* none
*/
void pparamslist_set_ptr(const char *name, const void *value, int vsize, pparamslist *list);
/*
* pparamslist_set_format - Set new text value to list using prinf format.
* If variable not found it will be created.
*
* Parameters:
* char *name - variable name
* pparamslist *list - list address
* char *format - value format string
* ... - values
*
* Return value:
* none
*/
void pparamslist_set_format(const char *name, pparamslist *list, const char *format, ...);
/*
* pparamslist_unset - Delete variable from list.
* WARNING: This function can't remove lists or arrays!
*
* Parameters:
* char *name - variable name
* pparamslist *list - list address
*
* Return value:
* none
*/
void pparamslist_unset(const char *name, pparamslist *list);
/*
* pparamslist_delete - Delete item from list.
*
* Parameters:
* int index - item index
* pparamslist *list - list address
*
* Return value:
* int - count of items in list
*/
int pparamslist_delete(int index, pparamslist *list);
/*
* pparamslist_clear - Delete all items from list.
*
* Parameters:
* pparamslist *list - list address
*
* Return value:
* none
*/
void pparamslist_clear(pparamslist *list);
/*
* pparamslist_get - Get item by name.
*
* Parameters:
* char *name - item name
* pparamslist *list - list address
*
* Return value:
* pparam * - item address (or NULL if no items found)
*/
pparam *pparamslist_get(const char *name, pparamslist *list);
/*
* pparamslist_getI - Get item by index.
*
* Parameters:
* int index - item index
* pparamslist *list - list address
*
* Return value:
* pparam * - item address (or NULL if no items found)
*/
pparam *pparamslist_getI(int index, pparamslist *list);
/*
* pparamslist_value - Get value from list.
* This function try to get value from list using nested lists and arrays.
* If value name is a name of list or array function will return their
* sizes.
*
* Parameters:
* char *name - value name
* for nested lists/arrays it's possible to use use name with dots
* (ex. "aaa.bbb.ccc.0")
* pparamslist *list - list address
*
* Return value:
* char * - value address (or NULL if no items found)
*/
char *pparamslist_value(const char *name, pparamslist *list);
/*
* pparamslist_index - Get item index by name.
*
* Parameters:
* char *name - item name
* pparamslist *list - list address
*
* Return value:
* int - item index (or -1 if no items founs)
*/
int pparamslist_index(const char *name, pparamslist *list);
/*
* pparamslist_exist - Check for item exists.
* This function tries to get item from list using nested lists and arrays
* and returns state of item.
*
* Parameters:
* char *name - value name
* for nested lists/arrays it's possible to use use name with dots
* (ex. "aaa.bbb.ccc.0")
* pparamslist *list - list address
*
* Return value:
* int - not zero if item exist
*/
int pparamslist_exist(const char *name, pparamslist *list);
/*****************************************************************************/
/* Functions for manipulate arrays */
/*****************************************************************************/
/*
* pparamslist_add_array_value - Add new value to array specified by name.
* This function finds array in list and add a new value to it.
*
* Parameters:
* char *name - array name
* char *value - new value
* pparamslist *list - list address
*
* Return value:
* int - new array size
*/
int pparamslist_add_array_value(const char *name, const char *value, pparamslist *list);
/*
* pparamslist_add_array_valuef - Add new value to array specified by name using
* printf format.
* This function finds array in list and add a new value to it.
*
* Parameters:
* char *name - array name
* pparamslist *list - list address
* const char *format - value format string
* ... - values
*
* Return value:
* int - new array size
*/
int pparamslist_add_array_valuef(const char *name, pparamslist *list, const char *format, ...);
/*
* pparamslist_add_array_valueI - Add new value to array specified by index.
* This function finds array in list and add a new value to it.
*
* Parameters:
* int index - array index
* char *value - new value
* pparamslist *list - list address
*
* Return value:
* int - new array size
*/
int pparamslist_add_array_valueI(int index, const char *value, pparamslist *list);
/*
* pparamslist_add_array_value_ - Add new value to array.
* This function adds a new value to array specified as list item.
*
* Parameters:
* pparam *p - array item
* char *value - new value
*
* Return value:
* int - new array size
*/
int pparamslist_add_array_value_(pparam *p, const char *value);
/*
* pparamslist_clear_array_ - Clear array.
* This function clears a array specified as list item.
*
* Parameters:
* pparam *p - array item
*
* Return value:
* none
*/
void pparamslist_clear_array_(pparam *p);
/*
* pparamslist_array2list - Convert array, specified by name, to sub-list.
* New sub-list items will be named by index ("0", "1", etc.).
*
* Parameters:
* char *name - array name
* pparamslist *list - list address
*
* Return value:
* pparam * - new item address
*/
pparam *pparamslist_array2list(const char *name, pparamslist *list);
#ifdef __cplusplus
}
#endif
#endif
/* _PARLIST_H
*/
|