| 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 | /* |
| 15 | A gvcontext is a single instance of a GVC_t data structure providing |
| 16 | for a set of plugins for processing one graph at a time, and a job |
| 17 | description provividing for a sequence of graph jobs. |
| 18 | |
| 19 | Sometime in the future it may become the basis for a thread. |
| 20 | */ |
| 21 | |
| 22 | #include "config.h" |
| 23 | |
| 24 | #include <stdlib.h> |
| 25 | |
| 26 | #include "builddate.h" |
| 27 | #include "types.h" |
| 28 | #include "gvplugin.h" |
| 29 | #include "gvcjob.h" |
| 30 | #include "gvcint.h" |
| 31 | #include "gvcproc.h" |
| 32 | #include "gvc.h" |
| 33 | |
| 34 | /* from common/utils.c */ |
| 35 | extern void *zmalloc(size_t); |
| 36 | |
| 37 | /* from common/textspan.c */ |
| 38 | extern void textfont_dict_close(GVC_t *gvc); |
| 39 | |
| 40 | /* from common/emit.c */ |
| 41 | extern void emit_once_reset(void); |
| 42 | |
| 43 | /* from common/globals.c */ |
| 44 | extern int graphviz_errors; |
| 45 | |
| 46 | static char *LibInfo[] = { |
| 47 | "graphviz" , /* Program */ |
| 48 | PACKAGE_VERSION, /* Version */ |
| 49 | BUILDDATE /* Build Date */ |
| 50 | }; |
| 51 | |
| 52 | GVC_t *gvNEWcontext(const lt_symlist_t *builtins, int demand_loading) |
| 53 | { |
| 54 | GVC_t *gvc = zmalloc(sizeof(GVC_t)); |
| 55 | |
| 56 | if (gvc) { |
| 57 | gvc->common.info = LibInfo; |
| 58 | gvc->common.errorfn = agerrorf; |
| 59 | gvc->common.builtins = builtins; |
| 60 | gvc->common.demand_loading = demand_loading; |
| 61 | } |
| 62 | return gvc; |
| 63 | } |
| 64 | |
| 65 | void gvFinalize(GVC_t * gvc) |
| 66 | { |
| 67 | if (gvc->active_jobs) |
| 68 | gvrender_end_job(gvc->active_jobs); |
| 69 | } |
| 70 | |
| 71 | |
| 72 | int gvFreeContext(GVC_t * gvc) |
| 73 | { |
| 74 | GVG_t *gvg, *gvg_next; |
| 75 | gvplugin_package_t *package, *package_next; |
| 76 | gvplugin_available_t *api, *api_next; |
| 77 | |
| 78 | #define ELEM(x) +1 |
| 79 | /* See gvcext.h for APIS and gvcint.h for an example usage of "+1" |
| 80 | to get the number of APIs. */ |
| 81 | unsigned int num_apis = APIS, i; |
| 82 | #undef ELEM |
| 83 | |
| 84 | emit_once_reset(); |
| 85 | gvg_next = gvc->gvgs; |
| 86 | while ((gvg = gvg_next)) { |
| 87 | gvg_next = gvg->next; |
| 88 | free(gvg); |
| 89 | } |
| 90 | package_next = gvc->packages; |
| 91 | while ((package = package_next)) { |
| 92 | package_next = package->next; |
| 93 | free(package->path); |
| 94 | free(package->name); |
| 95 | free(package); |
| 96 | } |
| 97 | gvjobs_delete(gvc); |
| 98 | if (gvc->config_path) |
| 99 | free(gvc->config_path); |
| 100 | if (gvc->input_filenames) |
| 101 | free(gvc->input_filenames); |
| 102 | textfont_dict_close(gvc); |
| 103 | for (i = 0; i != num_apis; ++i) { |
| 104 | for (api = gvc->apis[i]; api != NULL; api = api_next) { |
| 105 | api_next = api->next; |
| 106 | free(api); |
| 107 | } |
| 108 | } |
| 109 | free(gvc); |
| 110 | return (graphviz_errors + agerrors()); |
| 111 | } |
| 112 | |
| 113 | GVC_t* gvCloneGVC (GVC_t * gvc0) |
| 114 | { |
| 115 | GVC_t *gvc = zmalloc(sizeof(GVC_t)); |
| 116 | |
| 117 | gvc->common = gvc0->common; |
| 118 | memcpy (&gvc->apis, &gvc0->apis, sizeof(gvc->apis)); |
| 119 | memcpy (&gvc->api, &gvc0->api, sizeof(gvc->api)); |
| 120 | gvc->packages = gvc0->packages; |
| 121 | |
| 122 | return gvc; |
| 123 | } |
| 124 | |
| 125 | void gvFreeCloneGVC (GVC_t * gvc) |
| 126 | { |
| 127 | gvjobs_delete(gvc); |
| 128 | free(gvc); |
| 129 | } |
| 130 | |
| 131 | |