Graphviz  2.31.20130524.0447
lib/gvc/gvcontext.c
Go to the documentation of this file.
00001 /* $Id$ $Revision$ */
00002 /* vim:set shiftwidth=4 ts=8: */
00003 
00004 /*************************************************************************
00005  * Copyright (c) 2011 AT&T Intellectual Property 
00006  * All rights reserved. This program and the accompanying materials
00007  * are made available under the terms of the Eclipse Public License v1.0
00008  * which accompanies this distribution, and is available at
00009  * http://www.eclipse.org/legal/epl-v10.html
00010  *
00011  * Contributors: See CVS logs. Details at http://www.graphviz.org/
00012  *************************************************************************/
00013 
00014 /*
00015     A gvcontext is a single instance of a GVC_t data structure providing
00016     for a set of plugins for processing one graph at a time, and a job
00017     description provividing for a sequence of graph jobs.
00018 
00019     Sometime in the future it may become the basis for a thread.
00020  */
00021 
00022 #ifdef HAVE_CONFIG_H
00023 #include "config.h"
00024 #endif
00025 
00026 #include <stdlib.h>
00027 
00028 #include "builddate.h"
00029 #include "types.h"
00030 #include "gvplugin.h"
00031 #include "gvcjob.h"
00032 #include "gvcint.h"
00033 #include "gvcproc.h"
00034 #include "gvc.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 static char *LibInfo[] = {
00046     "graphviz",         /* Program */
00047     VERSION,            /* Version */
00048     BUILDDATE           /* Build Date */
00049 };
00050 
00051 GVC_t *gvNEWcontext(const lt_symlist_t *builtins, int demand_loading)
00052 {
00053     GVC_t *gvc = zmalloc(sizeof(GVC_t));
00054 
00055     if (gvc) {
00056         gvc->common.info = LibInfo;
00057         gvc->common.errorfn = agerrorf;
00058         gvc->common.builtins = builtins;
00059         gvc->common.demand_loading = demand_loading;
00060     }
00061     return gvc;
00062 }
00063 
00064 void gvFinalize(GVC_t * gvc)
00065 {
00066     if (gvc->active_jobs)
00067         gvrender_end_job(gvc->active_jobs);
00068 }
00069 
00070 
00071 int gvFreeContext(GVC_t * gvc)
00072 {
00073     GVG_t *gvg, *gvg_next;
00074     gvplugin_package_t *package, *package_next;
00075 
00076     emit_once_reset();
00077     gvg_next = gvc->gvgs;
00078     while ((gvg = gvg_next)) {
00079         gvg_next = gvg->next;
00080         free(gvg);
00081     }
00082     package_next = gvc->packages;
00083     while ((package = package_next)) {
00084         package_next = package->next;
00085         free(package->path);
00086         free(package->name);
00087         free(package);
00088     }
00089     gvjobs_delete(gvc);
00090     if (gvc->config_path)
00091         free(gvc->config_path);
00092     if (gvc->input_filenames)
00093         free(gvc->input_filenames);
00094     free(gvc);
00095     return (graphviz_errors + agerrors());
00096 }