list.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. ****************************************************************************
  3. *
  4. * MODULE: Vector 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/writing/manipulating vectors.
  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 <grass/config.h>
  19. #include <stdlib.h>
  20. #include <grass/gis.h>
  21. #include <grass/Vect.h>
  22. /* Init int_list */
  23. int dig_init_list(struct ilist *list)
  24. {
  25. list->value = NULL;
  26. list->n_values = 0;
  27. list->alloc_values = 0;
  28. return 1;
  29. }
  30. /* Init add item to list */
  31. int dig_list_add(struct ilist *list, int val)
  32. {
  33. void *p;
  34. int size;
  35. if (list->n_values == list->alloc_values) {
  36. size = (list->n_values + 1000) * sizeof(int);
  37. p = G_realloc((void *)list->value, size);
  38. if (p == NULL)
  39. return 0;
  40. list->value = (int *)p;
  41. list->alloc_values = list->n_values + 1000;
  42. }
  43. list->value[list->n_values] = val;
  44. list->n_values++;
  45. return 1;
  46. }