list.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 <stdlib.h>
  19. #include <grass/vector.h>
  20. /* Init box list */
  21. int dig_init_boxlist(struct boxlist *list, int have_boxes)
  22. {
  23. list->id = NULL;
  24. list->box = NULL;
  25. list->have_boxes = have_boxes != 0;
  26. list->n_values = 0;
  27. list->alloc_values = 0;
  28. return 1;
  29. }
  30. /* Add item to box list, does not check for duplicates */
  31. int dig_boxlist_add(struct boxlist *list, int id, const struct bound_box *box)
  32. {
  33. if (list->n_values == list->alloc_values) {
  34. size_t size = (list->n_values + 1000) * sizeof(int);
  35. void *p = G_realloc((void *)list->id, size);
  36. if (p == NULL)
  37. return 0;
  38. list->id = (int *)p;
  39. if (list->have_boxes) {
  40. size = (list->n_values + 1000) * sizeof(struct bound_box);
  41. p = G_realloc((void *)list->box, size);
  42. if (p == NULL)
  43. return 0;
  44. list->box = (struct bound_box *)p;
  45. }
  46. list->alloc_values = list->n_values + 1000;
  47. }
  48. list->id[list->n_values] = id;
  49. if (list->have_boxes)
  50. list->box[list->n_values] = *box;
  51. list->n_values++;
  52. return 1;
  53. }