Debian Codegraph @

lib/gvc/gvjobs.c

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