00001 /* $Id: gvcontext.c,v 1.20 2007/11/02 20:30:28 ellson Exp $ $Revision: 1.20 $ */ 00002 /* vim:set shiftwidth=4 ts=8: */ 00003 00004 /********************************************************** 00005 * This software is part of the graphviz package * 00006 * http://www.graphviz.org/ * 00007 * * 00008 * Copyright (c) 1994-2004 AT&T Corp. * 00009 * and is licensed under the * 00010 * Common Public License, Version 1.0 * 00011 * by AT&T Corp. * 00012 * * 00013 * Information and Software Systems Research * 00014 * AT&T Research, Florham Park NJ * 00015 **********************************************************/ 00016 00017 /* 00018 A gvcontext is a single instance of a GVC_t data structure providing 00019 for a set of plugins for processing one graph at a time, and a job 00020 description provividing for a sequence of graph jobs. 00021 00022 Sometime in the future it may become the basis for a thread. 00023 */ 00024 00025 #ifdef HAVE_CONFIG_H 00026 #include "config.h" 00027 #endif 00028 00029 #include "types.h" 00030 #include "graph.h" 00031 #include "gvplugin.h" 00032 #include "gvcjob.h" 00033 #include "gvcint.h" 00034 #include "gvcproc.h" 00035 00036 /* from common/utils.c */ 00037 extern void *zmalloc(size_t); 00038 00039 /* from common/emit.c */ 00040 extern void emit_once_reset(void); 00041 00042 /* from common/globals.c */ 00043 extern int graphviz_errors; 00044 00045 GVC_t *gvNEWcontext(char **info, char *user) 00046 { 00047 GVC_t *gvc = zmalloc(sizeof(GVC_t)); 00048 00049 if (gvc) { 00050 gvc->common.info = info; 00051 gvc->common.user = user; 00052 gvc->common.errorfn = agerrorf; 00053 } 00054 return gvc; 00055 } 00056 00057 int gvFreeContext(GVC_t * gvc) 00058 { 00059 GVG_t *gvg, *gvg_next; 00060 00061 if (gvc->active_jobs) 00062 gvrender_end_job(gvc->active_jobs); 00063 emit_once_reset(); 00064 gvg_next = gvc->gvgs; 00065 while ((gvg = gvg_next)) { 00066 gvg_next = gvg->next; 00067 free(gvg); 00068 } 00069 gvjobs_delete(gvc); 00070 if (gvc->config_path) 00071 free(gvc->config_path); 00072 if (gvc->input_filenames) 00073 free(gvc->input_filenames); 00074 free(gvc); 00075 return (graphviz_errors + agerrors()); 00076 }