Graphviz  2.39.20141221.0545
gvjobs.c
Go to the documentation of this file.
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 #ifdef HAVE_CONFIG_H
15 #include "config.h"
16 #endif
17 
18 #include "memory.h"
19 #include "types.h"
20 #include "gvplugin.h"
21 #include "gvcjob.h"
22 #include "gvcint.h"
23 #include "gvcproc.h"
24 
25 static GVJ_t *output_filename_job;
26 static GVJ_t *output_langname_job;
27 
28 /*
29  * -T and -o can be specified in any order relative to the other, e.g.
30  * -T -T -o -o
31  * -T -o -o -T
32  * The first -T is paired with the first -o, the second with the second, and so on.
33  *
34  * If there are more -T than -o, then the last -o is repeated for the remaining -T
35  * and vice-versa
36  *
37  * If there are no -T or -o then a single job is instantiated.
38  *
39  * If there is no -T on the first job, then "dot" is used.
40  *
41  * As many -R as are specified before a completed -T -o pair (according to the above rules)
42  * are used as renderer-specific switches for just that one job. -R must be restated for
43  * each job.
44  */
45 
46 /* -o switches */
47 void gvjobs_output_filename(GVC_t * gvc, const char *name)
48 {
49  if (!gvc->jobs) {
50  output_filename_job = gvc->job = gvc->jobs = zmalloc(sizeof(GVJ_t));
51  } else {
52  if (!output_filename_job) {
53  output_filename_job = gvc->jobs;
54  } else {
55  if (!output_filename_job->next) {
56  output_filename_job->next = zmalloc(sizeof(GVJ_t));
57  }
58  output_filename_job = output_filename_job->next;
59  }
60  }
61  output_filename_job->output_filename = name;
62  output_filename_job->gvc = gvc;
63 }
64 
65 /* -T switches */
66 boolean gvjobs_output_langname(GVC_t * gvc, const char *name)
67 {
68  if (!gvc->jobs) {
69  output_langname_job = gvc->job = gvc->jobs = zmalloc(sizeof(GVJ_t));
70  } else {
71  if (!output_langname_job) {
72  output_langname_job = gvc->jobs;
73  } else {
74  if (!output_langname_job->next) {
75  output_langname_job->next = zmalloc(sizeof(GVJ_t));
76  }
77  output_langname_job = output_langname_job->next;
78  }
79  }
80  output_langname_job->output_langname = name;
81  output_langname_job->gvc = gvc;
82 
83  /* load it now to check that it exists */
84  if (gvplugin_load(gvc, API_device, name))
85  return TRUE;
86  return FALSE;
87 }
88 
90 {
91  return (gvc->job = gvc->jobs);
92 }
93 
95 {
96  GVJ_t *job = gvc->job->next;
97 
98  if (job) {
99  /* if langname not specified, then repeat previous value */
100  if (!job->output_langname)
101  job->output_langname = gvc->job->output_langname;
102  /* if filename not specified, then leave NULL to indicate stdout */
103  }
104  return (gvc->job = job);
105 }
106 
108 {
109  return (gv_argvlist_t*)zmalloc(sizeof(gv_argvlist_t));
110 }
111 
112 void gv_argvlist_set_item(gv_argvlist_t *list, int index, char *item)
113 {
114  if (index >= list->alloc) {
115  list->alloc = index + 10;
116  list->argv = grealloc(list->argv, (list->alloc)*(sizeof(char*)));
117  }
118  list->argv[index] = item;
119 }
120 
122 {
123  if (list->argv)
124  free(list->argv);
125  list->argv = NULL;
126  list->alloc = 0;
127  list->argc = 0;
128 }
129 
131 {
132  if (list->argv)
133  free(list->argv);
134  free(list);
135 }
136 
138 {
139  GVJ_t *job, *j;
140 
141  job = gvc->jobs;
142  while ((j = job)) {
143  job = job->next;
146  if (j->active_tooltip)
147  free(j->active_tooltip);
148  if (j->selected_href)
149  free(j->selected_href);
150  free(j);
151  }
152  gvc->jobs = gvc->job = gvc->active_jobs = output_filename_job = output_langname_job =
153  NULL;
154  gvc->common.viewNum = 0;
155 }
void * zmalloc(size_t nbytes)
Definition: memory.c:22
void * grealloc(void *ptr, size_t size)
Definition: memory.c:56
Definition: utils.c:978
void gvjobs_output_filename(GVC_t *gvc, const char *name)
Definition: gvjobs.c:47
gv_argvlist_t * gvNEWargvlist(void)
Definition: gvjobs.c:107
GVJ_t * gvjobs_first(GVC_t *gvc)
Definition: gvjobs.c:89
void gv_argvlist_free(gv_argvlist_t *list)
Definition: gvjobs.c:130
const char * output_filename
Definition: gvcjob.h:285
gvplugin_available_t * gvplugin_load(GVC_t *gvc, api_t api, const char *type)
Definition: gvplugin.c:250
Definition: gvcjob.h:271
void gv_argvlist_set_item(gv_argvlist_t *list, int index, char *item)
Definition: gvjobs.c:112
GVJ_t * next
Definition: gvcjob.h:273
void gv_argvlist_reset(gv_argvlist_t *list)
Definition: gvjobs.c:121
char * active_tooltip
Definition: gvcjob.h:359
gv_argvlist_t selected_obj_type_name
Definition: gvcjob.h:361
char * selected_href
Definition: gvcjob.h:360
int viewNum
Definition: gvcommon.h:31
void free()
Definition: gvcint.h:70
GVJ_t * active_jobs
Definition: gvcint.h:112
GVJ_t * jobs
Definition: gvcint.h:103
GVC_t * gvc
Definition: gvcjob.h:272
GVJ_t * gvjobs_next(GVC_t *gvc)
Definition: gvjobs.c:94
#define NULL
Definition: logic.h:50
gv_argvlist_t selected_obj_attributes
Definition: gvcjob.h:362
GVC_t * gvc
Definition: htmlparse.c:87
void gvjobs_delete(GVC_t *gvc)
Definition: gvjobs.c:137
struct item_s item
GVCOMMON_t common
Definition: gvcint.h:71
boolean gvjobs_output_langname(GVC_t *gvc, const char *name)
Definition: gvjobs.c:66
GVJ_t * job
Definition: gvcint.h:104
#define FALSE
Definition: cgraph.h:24
const char * output_langname
Definition: gvcjob.h:291
char ** argv
Definition: gvcjob.h:151
#define TRUE
Definition: cgraph.h:27