Graphviz  2.41.20171026.1811
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 #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 
88 {
89  return (gvc->job = gvc->jobs);
90 }
91 
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 
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 
120 {
121  if (list->argv)
122  free(list->argv);
123  list->argv = NULL;
124  list->alloc = 0;
125  list->argc = 0;
126 }
127 
129 {
130  if (list->argv)
131  free(list->argv);
132  free(list);
133 }
134 
136 {
137  GVJ_t *job, *j;
138 
139  job = gvc->jobs;
140  while ((j = job)) {
141  job = job->next;
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 }
void * zmalloc(size_t nbytes)
Definition: memory.c:20
void * grealloc(void *ptr, size_t size)
Definition: memory.c:54
Definition: utils.c:981
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:262
GVJ_t * gvjobs_first(GVC_t *gvc)
Definition: gvjobs.c:87
Definition: gvcjob.h:271
GVJ_t * next
Definition: gvcjob.h:273
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
Definition: gvcint.h:70
GVJ_t * active_jobs
Definition: gvcint.h:112
void gv_argvlist_free(gv_argvlist_t *list)
Definition: gvjobs.c:128
GVJ_t * jobs
Definition: gvcint.h:103
gv_argvlist_t * gvNEWargvlist(void)
Definition: gvjobs.c:105
GVC_t * gvc
Definition: gvcjob.h:272
#define NULL
Definition: logic.h:39
void gv_argvlist_reset(gv_argvlist_t *list)
Definition: gvjobs.c:119
gv_argvlist_t selected_obj_attributes
Definition: gvcjob.h:362
GVC_t * gvc
Definition: htmlparse.c:87
struct item_s item
boolean gvjobs_output_langname(GVC_t *gvc, const char *name)
Definition: gvjobs.c:64
void gvjobs_output_filename(GVC_t *gvc, const char *name)
Definition: gvjobs.c:45
GVCOMMON_t common
Definition: gvcint.h:71
void gvjobs_delete(GVC_t *gvc)
Definition: gvjobs.c:135
GVJ_t * gvjobs_next(GVC_t *gvc)
Definition: gvjobs.c:92
GVJ_t * job
Definition: gvcint.h:104
#define FALSE
Definition: cgraph.h:35
void gv_argvlist_set_item(gv_argvlist_t *list, int index, char *item)
Definition: gvjobs.c:110
const char * output_langname
Definition: gvcjob.h:291
char ** argv
Definition: gvcjob.h:151
#define TRUE
Definition: cgraph.h:38