gvcontext.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*************************************************************************
  2. * Copyright (c) 2011 AT&T Intellectual Property
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors: Details at https://graphviz.org
  9. *************************************************************************/
  10. /*
  11. A gvcontext is a single instance of a GVC_t data structure providing
  12. for a set of plugins for processing one graph at a time, and a job
  13. description provividing for a sequence of graph jobs.
  14. Sometime in the future it may become the basis for a thread.
  15. */
  16. #include "config.h"
  17. #include <stdlib.h>
  18. #include "builddate.h"
  19. #include <common/render.h>
  20. #include <common/types.h>
  21. #include <gvc/gvplugin.h>
  22. #include <gvc/gvcjob.h>
  23. #include <gvc/gvcint.h>
  24. #include <gvc/gvcproc.h>
  25. #include <gvc/gvc.h>
  26. #include <util/alloc.h>
  27. /* from common/textspan.c */
  28. extern void textfont_dict_close(GVC_t *gvc);
  29. /* from common/globals.c */
  30. extern int graphviz_errors;
  31. static char *LibInfo[] = {
  32. "graphviz", /* Program */
  33. PACKAGE_VERSION, /* Version */
  34. BUILDDATE /* Build Date */
  35. };
  36. GVC_t *gvNEWcontext(const lt_symlist_t *builtins, int demand_loading)
  37. {
  38. GVC_t *gvc = gv_alloc(sizeof(GVC_t));
  39. gvc->common.info = LibInfo;
  40. gvc->common.errorfn = agerrorf;
  41. gvc->common.builtins = builtins;
  42. gvc->common.demand_loading = demand_loading;
  43. return gvc;
  44. }
  45. void gvFinalize(GVC_t * gvc)
  46. {
  47. if (gvc->active_jobs)
  48. gvrender_end_job(gvc->active_jobs);
  49. }
  50. int gvFreeContext(GVC_t * gvc)
  51. {
  52. GVG_t *gvg, *gvg_next;
  53. gvplugin_package_t *package, *package_next;
  54. gvplugin_available_t *api, *api_next;
  55. emit_once_reset();
  56. gvg_next = gvc->gvgs;
  57. while ((gvg = gvg_next)) {
  58. gvg_next = gvg->next;
  59. free(gvg);
  60. }
  61. package_next = gvc->packages;
  62. while ((package = package_next)) {
  63. package_next = package->next;
  64. free(package->path);
  65. free(package->name);
  66. free(package);
  67. }
  68. gvjobs_delete(gvc);
  69. free(gvc->config_path);
  70. free(gvc->input_filenames);
  71. textfont_dict_close(gvc);
  72. for (size_t i = 0; i < sizeof(gvc->apis) / sizeof(gvc->apis[0]); ++i) {
  73. for (api = gvc->apis[i]; api != NULL; api = api_next) {
  74. api_next = api->next;
  75. free(api->typestr);
  76. free(api);
  77. }
  78. }
  79. free(gvc);
  80. return (graphviz_errors + agerrors());
  81. }
  82. GVC_t* gvCloneGVC (GVC_t * gvc0)
  83. {
  84. GVC_t *gvc = gv_alloc(sizeof(GVC_t));
  85. gvc->common = gvc0->common;
  86. memcpy (&gvc->apis, &gvc0->apis, sizeof(gvc->apis));
  87. memcpy (&gvc->api, &gvc0->api, sizeof(gvc->api));
  88. gvc->packages = gvc0->packages;
  89. return gvc;
  90. }
  91. void gvFreeCloneGVC (GVC_t * gvc)
  92. {
  93. gvjobs_delete(gvc);
  94. free(gvc);
  95. }