/misc/src/release/graphviz-2.18-1/src/graphviz-2.18/cmd/dot/dot.c

Go to the documentation of this file.
00001 /* $Id: dot.c,v 1.29 2007/07/17 21:45:10 erg Exp $ $Revision: 1.29 $ */
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  * Written by Stephen North and Eleftherios Koutsofios.
00019  */
00020 
00021 #ifdef HAVE_CONFIG_H
00022 #include "config.h"
00023 #endif
00024 
00025 #include "builddate.h"
00026 #include "gvc.h"
00027 #ifdef GVDLL
00028 __declspec(dllimport) boolean MemTest;
00029 #else
00030 #include "globals.h"
00031 #endif
00032 
00033 #include <time.h>
00034 #ifdef HAVE_UNISTD_H
00035 #include <unistd.h>
00036 #endif
00037 
00038 #if defined(HAVE_FENV_H) && defined(HAVE_FEENABLEEXCEPT)
00039 /* _GNU_SOURCE is needed for feenableexcept to be defined in fenv.h on GNU
00040  * systems.   Presumably it will do no harm on other systems. */
00041 #ifndef _GNU_SOURCE
00042 #define _GNU_SOURCE
00043 #endif
00044 # include <fenv.h>
00045 #elif HAVE_FPU_CONTROL_H
00046 # include <fpu_control.h>
00047 #elif HAVE_SYS_FPU_H
00048 # include <sys/fpu.h>
00049 #endif
00050 
00051 char *Info[] = {
00052     "Graphviz",                 /* Program */
00053     VERSION,                    /* Version */
00054     BUILDDATE                   /* Build Date */
00055 };
00056 
00057 static GVC_t *Gvc;
00058 static graph_t * G;
00059 
00060 #ifndef WIN32
00061 static void intr(int s)
00062 {
00063     if (G)
00064         gvRenderJobs(Gvc, G);
00065     exit (gvFreeContext(Gvc));
00066 }
00067 
00068 #ifndef NO_FPERR
00069 static void fperr(int s)
00070 {
00071     fprintf(stderr, "caught SIGFPE %d\n", s);
00072     /* signal (s, SIG_DFL); raise (s); */
00073     exit(1);
00074 }
00075 
00076 static void fpinit(void)
00077 {
00078 #if defined(HAVE_FENV_H) && defined(HAVE_FEENABLEEXCEPT)
00079     int exc = 0;
00080 # ifdef FE_DIVBYZERO
00081     exc |= FE_DIVBYZERO;
00082 # endif
00083 # ifdef FE_OVERFLOW
00084     exc |= FE_OVERFLOW;
00085 # endif
00086 # ifdef FE_INVALID
00087     exc |= FE_INVALID;
00088 # endif
00089     feenableexcept(exc);
00090 
00091 #ifdef HAVE_FESETENV
00092 #ifdef FE_NONIEEE_ENV
00093     fesetenv (FE_NONIEEE_ENV);
00094 #endif
00095 #endif
00096 
00097 #elif  HAVE_FPU_CONTROL_H
00098     /* On s390-ibm-linux, the header exists, but the definitions
00099      * of the masks do not.  I assume this is temporary, but until
00100      * there's a real implementation, it's probably safest to not
00101      * adjust the FPU on this platform.
00102      */
00103 # if defined(_FPU_MASK_IM) && defined(_FPU_MASK_DM) && defined(_FPU_MASK_ZM) && defined(_FPU_GETCW)
00104     fpu_control_t fpe_flags = 0;
00105     _FPU_GETCW(fpe_flags);
00106     fpe_flags &= ~_FPU_MASK_IM; /* invalid operation */
00107     fpe_flags &= ~_FPU_MASK_DM; /* denormalized operand */
00108     fpe_flags &= ~_FPU_MASK_ZM; /* zero-divide */
00109     /*fpe_flags &= ~_FPU_MASK_OM;        overflow */
00110     /*fpe_flags &= ~_FPU_MASK_UM;        underflow */
00111     /*fpe_flags &= ~_FPU_MASK_PM;        precision (inexact result) */
00112     _FPU_SETCW(fpe_flags);
00113 # endif
00114 #endif
00115 }
00116 #endif
00117 #endif
00118 
00119 static graph_t *create_test_graph(void)
00120 {
00121 #define NUMNODES 5
00122 
00123     Agnode_t *node[NUMNODES];
00124     Agraph_t *g;
00125     int j, k;
00126     char name[10];
00127 
00128     /* Create a new graph */
00129     g = agopen("new_graph", AGDIGRAPH);
00130 
00131     /* Add nodes */
00132     for (j = 0; j < NUMNODES; j++) {
00133         sprintf(name, "%d", j);
00134         node[j] = agnode(g, name);
00135     }
00136 
00137     /* Connect nodes */
00138     for (j = 0; j < NUMNODES; j++) {
00139         for (k = j + 1; k < NUMNODES; k++) {
00140             agedge(g, node[j], node[k]);
00141         }
00142     }
00143     return g;
00144 }
00145 
00146 int main(int argc, char **argv)
00147 {
00148     graph_t *prev = NULL;
00149 
00150     Gvc = gvNEWcontext(Info, gvUsername());
00151     gvParseArgs(Gvc, argc, argv);
00152 
00153 #ifndef WIN32
00154     signal(SIGUSR1, gvToggle);
00155     signal(SIGINT, intr);
00156 #ifndef NO_FPERR
00157     fpinit();
00158     signal(SIGFPE, fperr);
00159 #endif
00160 #endif
00161 
00162     if (MemTest) {
00163         while (1) {
00164             /* Create a test graph */
00165             G = create_test_graph();
00166 
00167             /* Perform layout and cleanup */
00168             gvLayoutJobs(Gvc, G);  /* take layout engine from command line */
00169             gvFreeLayout(Gvc, G);
00170 
00171             /* Delete graph */
00172             agclose(G);
00173         }
00174     } else {
00175         while ((G = gvNextInputGraph(Gvc))) {
00176             if (prev) {
00177                 gvFreeLayout(Gvc, prev);
00178                 agclose(prev);
00179             }
00180             gvLayoutJobs(Gvc, G);  /* take layout engine from command line */
00181             gvRenderJobs(Gvc, G);
00182             prev = G;
00183         }
00184     }
00185     return (gvFreeContext(Gvc));
00186 }

Generated on Mon Mar 31 19:03:23 2008 for Graphviz by  doxygen 1.5.1