ilist.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. ****************************************************************************
  3. *
  4. * MODULE: gis library
  5. *
  6. * AUTHOR(S): Original author CERL, probably Dave Gerdes.
  7. * Update to GRASS 5.7 Radim Blazek.
  8. *
  9. * PURPOSE: Lower level functions for reading and manipulating integer list
  10. *
  11. * COPYRIGHT: (C) 2001 by the GRASS Development Team
  12. *
  13. * This program is free software under the GNU General Public
  14. * License (>=v2). Read the file COPYING that comes with GRASS
  15. * for details.
  16. *
  17. *****************************************************************************/
  18. #include <stdlib.h>
  19. #include <grass/gis.h>
  20. /**
  21. * Init an integer list
  22. *
  23. * \param list The pointer to an integer list
  24. *
  25. * */
  26. void G_init_ilist(struct ilist *list)
  27. {
  28. list->value = NULL;
  29. list->n_values = 0;
  30. list->alloc_values = 0;
  31. }
  32. /**
  33. * \brief Add item to ilist
  34. *
  35. * This function adds an integer to the list but does not check for duplicates.
  36. * In case reallocation fails, G_fatal_error() will be invoked by the
  37. * allocation function.
  38. *
  39. * \param ilist The ilist pointer
  40. * \param val The value to attach
  41. *
  42. * */
  43. void G_ilist_add(struct ilist *list, int val)
  44. {
  45. if (list->n_values == list->alloc_values) {
  46. size_t size = (list->n_values + 1000) * sizeof(int);
  47. void *p = G_realloc((void *)list->value, size);
  48. list->value = (int *)p;
  49. list->alloc_values = list->n_values + 1000;
  50. }
  51. list->value[list->n_values] = val;
  52. list->n_values++;
  53. }