labels.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Copyright 2010, 2011, 2012, 2013, 2014, 2015
  2. Free Software Foundation, Inc.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. #include "parser.h"
  14. #include "convert.h"
  15. #include "labels.h"
  16. /* Array of recorded labels. */
  17. /* If looking through this array turns out to be slow, we might have to replace
  18. it with some kind of hash table implementation. */
  19. LABEL *labels_list = 0;
  20. size_t labels_number = 0;
  21. size_t labels_space = 0;
  22. /* Register a label, that is something that may be the target of a reference
  23. and must be unique in the document. Corresponds to @node, @anchor, and
  24. second arg of @float. */
  25. void
  26. register_label (ELEMENT *current, NODE_SPEC_EXTRA *label)
  27. {
  28. if (labels_number == labels_space)
  29. {
  30. labels_space += 1;
  31. labels_space *= 1.5;
  32. labels_list = realloc (labels_list, labels_space * sizeof (LABEL));
  33. if (!labels_list)
  34. abort ();
  35. }
  36. labels_list[labels_number++].target = current;
  37. // 2504
  38. add_extra_contents (current, "node_content", label->node_content);
  39. }
  40. void
  41. reset_labels (void)
  42. {
  43. labels_number = 0;
  44. }
  45. ELEMENT **internal_xref_list = 0;
  46. size_t internal_xref_number = 0;
  47. size_t internal_xref_space = 0;
  48. void
  49. remember_internal_xref (ELEMENT *element)
  50. {
  51. if (internal_xref_number == internal_xref_space)
  52. {
  53. internal_xref_list = realloc (internal_xref_list,
  54. (internal_xref_space += 2)
  55. * sizeof (*internal_xref_list));
  56. }
  57. internal_xref_list[internal_xref_number++] = element;
  58. }
  59. void
  60. reset_internal_xrefs (void)
  61. {
  62. internal_xref_number = 0;
  63. }