gvjobs.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #include "config.h"
  11. #include <common/types.h>
  12. #include <gvc/gvplugin.h>
  13. #include <gvc/gvcjob.h>
  14. #include <gvc/gvcint.h>
  15. #include <gvc/gvcproc.h>
  16. #include <stdbool.h>
  17. #include <stddef.h>
  18. #include <util/alloc.h>
  19. static GVJ_t *output_filename_job;
  20. static GVJ_t *output_langname_job;
  21. /*
  22. * -T and -o can be specified in any order relative to the other, e.g.
  23. * -T -T -o -o
  24. * -T -o -o -T
  25. * The first -T is paired with the first -o, the second with the second, and so on.
  26. *
  27. * If there are more -T than -o, then the last -o is repeated for the remaining -T
  28. * and vice-versa
  29. *
  30. * If there are no -T or -o then a single job is instantiated.
  31. *
  32. * If there is no -T on the first job, then "dot" is used.
  33. *
  34. * As many -R as are specified before a completed -T -o pair (according to the above rules)
  35. * are used as renderer-specific switches for just that one job. -R must be restated for
  36. * each job.
  37. */
  38. /* -o switches */
  39. void gvjobs_output_filename(GVC_t * gvc, const char *name)
  40. {
  41. if (!gvc->jobs) {
  42. output_filename_job = gvc->job = gvc->jobs = gv_alloc(sizeof(GVJ_t));
  43. } else {
  44. if (!output_filename_job) {
  45. output_filename_job = gvc->jobs;
  46. } else {
  47. if (!output_filename_job->next) {
  48. output_filename_job->next = gv_alloc(sizeof(GVJ_t));
  49. }
  50. output_filename_job = output_filename_job->next;
  51. }
  52. }
  53. output_filename_job->output_filename = name;
  54. output_filename_job->gvc = gvc;
  55. }
  56. /* -T switches */
  57. bool gvjobs_output_langname(GVC_t * gvc, const char *name)
  58. {
  59. if (!gvc->jobs) {
  60. output_langname_job = gvc->job = gvc->jobs = gv_alloc(sizeof(GVJ_t));
  61. } else {
  62. if (!output_langname_job) {
  63. output_langname_job = gvc->jobs;
  64. } else {
  65. if (!output_langname_job->next) {
  66. output_langname_job->next = gv_alloc(sizeof(GVJ_t));
  67. }
  68. output_langname_job = output_langname_job->next;
  69. }
  70. }
  71. output_langname_job->output_langname = name;
  72. output_langname_job->gvc = gvc;
  73. /* load it now to check that it exists */
  74. if (gvplugin_load(gvc, API_device, name, NULL))
  75. return true;
  76. return false;
  77. }
  78. GVJ_t *gvjobs_first(GVC_t * gvc)
  79. {
  80. return (gvc->job = gvc->jobs);
  81. }
  82. GVJ_t *gvjobs_next(GVC_t * gvc)
  83. {
  84. GVJ_t *job = gvc->job->next;
  85. if (job) {
  86. /* if langname not specified, then repeat previous value */
  87. if (!job->output_langname)
  88. job->output_langname = gvc->job->output_langname;
  89. /* if filename not specified, then leave NULL to indicate stdout */
  90. }
  91. return (gvc->job = job);
  92. }
  93. void gvjobs_delete(GVC_t * gvc)
  94. {
  95. GVJ_t *job, *j;
  96. job = gvc->jobs;
  97. while ((j = job)) {
  98. job = job->next;
  99. free(j->active_tooltip);
  100. free(j->selected_href);
  101. free(j);
  102. }
  103. gvc->jobs = gvc->job = gvc->active_jobs = output_filename_job = output_langname_job =
  104. NULL;
  105. gvc->common.viewNum = 0;
  106. }