1 | /* $Id$ $Revision$ */ |
2 | /* vim:set shiftwidth=4 ts=8: */ |
3 | |
4 | /************************************************************************* |
5 | * Copyright (c) 2011 AT&T Intellectual Property |
6 | * All rights reserved. This program and the accompanying materials |
7 | * are made available under the terms of the Eclipse Public License v1.0 |
8 | * which accompanies this distribution, and is available at |
9 | * http://www.eclipse.org/legal/epl-v10.html |
10 | * |
11 | * Contributors: See CVS logs. Details at http://www.graphviz.org/ |
12 | *************************************************************************/ |
13 | |
14 | #include "config.h" |
15 | |
16 | #include "memory.h" |
17 | #include "types.h" |
18 | #include "gvplugin.h" |
19 | #include "gvcjob.h" |
20 | #include "gvcint.h" |
21 | #include "gvcproc.h" |
22 | |
23 | static GVJ_t *output_filename_job; |
24 | static GVJ_t *output_langname_job; |
25 | |
26 | /* |
27 | * -T and -o can be specified in any order relative to the other, e.g. |
28 | * -T -T -o -o |
29 | * -T -o -o -T |
30 | * The first -T is paired with the first -o, the second with the second, and so on. |
31 | * |
32 | * If there are more -T than -o, then the last -o is repeated for the remaining -T |
33 | * and vice-versa |
34 | * |
35 | * If there are no -T or -o then a single job is instantiated. |
36 | * |
37 | * If there is no -T on the first job, then "dot" is used. |
38 | * |
39 | * As many -R as are specified before a completed -T -o pair (according to the above rules) |
40 | * are used as renderer-specific switches for just that one job. -R must be restated for |
41 | * each job. |
42 | */ |
43 | |
44 | /* -o switches */ |
45 | void gvjobs_output_filename(GVC_t * gvc, const char *name) |
46 | { |
47 | if (!gvc->jobs) { |
48 | output_filename_job = gvc->job = gvc->jobs = zmalloc(sizeof(GVJ_t)); |
49 | } else { |
50 | if (!output_filename_job) { |
51 | output_filename_job = gvc->jobs; |
52 | } else { |
53 | if (!output_filename_job->next) { |
54 | output_filename_job->next = zmalloc(sizeof(GVJ_t)); |
55 | } |
56 | output_filename_job = output_filename_job->next; |
57 | } |
58 | } |
59 | output_filename_job->output_filename = name; |
60 | output_filename_job->gvc = gvc; |
61 | } |
62 | |
63 | /* -T switches */ |
64 | boolean gvjobs_output_langname(GVC_t * gvc, const char *name) |
65 | { |
66 | if (!gvc->jobs) { |
67 | output_langname_job = gvc->job = gvc->jobs = zmalloc(sizeof(GVJ_t)); |
68 | } else { |
69 | if (!output_langname_job) { |
70 | output_langname_job = gvc->jobs; |
71 | } else { |
72 | if (!output_langname_job->next) { |
73 | output_langname_job->next = zmalloc(sizeof(GVJ_t)); |
74 | } |
75 | output_langname_job = output_langname_job->next; |
76 | } |
77 | } |
78 | output_langname_job->output_langname = name; |
79 | output_langname_job->gvc = gvc; |
80 | |
81 | /* load it now to check that it exists */ |
82 | if (gvplugin_load(gvc, API_device, name)) |
83 | return TRUE; |
84 | return FALSE; |
85 | } |
86 | |
87 | GVJ_t *gvjobs_first(GVC_t * gvc) |
88 | { |
89 | return (gvc->job = gvc->jobs); |
90 | } |
91 | |
92 | GVJ_t *gvjobs_next(GVC_t * gvc) |
93 | { |
94 | GVJ_t *job = gvc->job->next; |
95 | |
96 | if (job) { |
97 | /* if langname not specified, then repeat previous value */ |
98 | if (!job->output_langname) |
99 | job->output_langname = gvc->job->output_langname; |
100 | /* if filename not specified, then leave NULL to indicate stdout */ |
101 | } |
102 | return (gvc->job = job); |
103 | } |
104 | |
105 | gv_argvlist_t *gvNEWargvlist(void) |
106 | { |
107 | return (gv_argvlist_t*)zmalloc(sizeof(gv_argvlist_t)); |
108 | } |
109 | |
110 | void gv_argvlist_set_item(gv_argvlist_t *list, int index, char *item) |
111 | { |
112 | if (index >= list->alloc) { |
113 | list->alloc = index + 10; |
114 | list->argv = grealloc(list->argv, (list->alloc)*(sizeof(char*))); |
115 | } |
116 | list->argv[index] = item; |
117 | } |
118 | |
119 | void gv_argvlist_reset(gv_argvlist_t *list) |
120 | { |
121 | if (list->argv) |
122 | free(list->argv); |
123 | list->argv = NULL; |
124 | list->alloc = 0; |
125 | list->argc = 0; |
126 | } |
127 | |
128 | void gv_argvlist_free(gv_argvlist_t *list) |
129 | { |
130 | if (list->argv) |
131 | free(list->argv); |
132 | free(list); |
133 | } |
134 | |
135 | void gvjobs_delete(GVC_t * gvc) |
136 | { |
137 | GVJ_t *job, *j; |
138 | |
139 | job = gvc->jobs; |
140 | while ((j = job)) { |
141 | job = job->next; |
142 | gv_argvlist_reset(&(j->selected_obj_attributes)); |
143 | gv_argvlist_reset(&(j->selected_obj_type_name)); |
144 | if (j->active_tooltip) |
145 | free(j->active_tooltip); |
146 | if (j->selected_href) |
147 | free(j->selected_href); |
148 | free(j); |
149 | } |
150 | gvc->jobs = gvc->job = gvc->active_jobs = output_filename_job = output_langname_job = |
151 | NULL; |
152 | gvc->common.viewNum = 0; |
153 | } |
154 | |