Graphviz 12.0.1~dev.20240716.0800
Loading...
Searching...
No Matches
ccomps.c File Reference

connected components filter for graphs More...

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <cgraph/agxbuf.h>
#include <cgraph/alloc.h>
#include <cgraph/cgraph.h>
#include <cgraph/gv_ctype.h>
#include <cgraph/ingraphs.h>
#include <cgraph/prisize_t.h>
#include <cgraph/stack.h>
#include <cgraph/unreachable.h>
#include <cgraph/exit.h>
#include <common/render.h>
#include <common/utils.h>
#include <getopt.h>
#include <string.h>
Include dependency graph for ccomps.c:

Go to the source code of this file.

Data Structures

struct  graphinfo_t
 
struct  nodeinfo_t
 

Macros

#define GD_cc_subg(g)   (((graphinfo_t*)(g->base.data))->cc_subg)
 
#define Node_mark(n)   (((nodeinfo_t*)(n->base.data))->mark)
 
#define ND_ptr(n)   (((nodeinfo_t*)(n->base.data))->ptr)
 
#define ND_dn(n)   ((Agnode_t*)ND_ptr(n))
 
#define Node_clust(n)   ((Agraph_t*)ND_ptr(n))
 
#define TAG_NODE   1
 
#define INTERNAL
 
#define EXTERNAL   1
 
#define SILENT   2
 
#define EXTRACT   3
 
#define BY_INDEX   1
 
#define BY_SIZE   2
 
#define PFX1   "%s_cc"
 
#define PFX2   "%s_cc_%ld"
 

Functions

static void usage (int v)
 
static void split (void)
 
static void init (int argc, char *argv[])
 
static void push (Agnode_t *np)
 
static Agnode_tpop (void)
 
static int dfs (Agraph_t *g, Agnode_t *n, Agraph_t *out)
 
static char * getName (void)
 
static void gwrite (Agraph_t *g)
 
static Agraph_tprojectG (Agraph_t *subg, Agraph_t *g, int inCluster)
 
static void subgInduce (Agraph_t *root, Agraph_t *g, int inCluster)
 
static void subGInduce (Agraph_t *g, Agraph_t *out)
 
static void deriveClusters (Agraph_t *dg, Agraph_t *g)
 
static Agraph_tderiveGraph (Agraph_t *g)
 
static void unionNodes (Agraph_t *dg, Agraph_t *g)
 
static int cmp (const void *x, const void *y)
 
static void printSorted (Agraph_t *root, int c_cnt)
 
static int processClusters (Agraph_t *g, char *graphName)
 
static void bindGraphinfo (Agraph_t *g)
 
static int process (Agraph_t *g, char *graphName)
 
static char * chkGraphName (Agraph_t *g)
 
int main (int argc, char *argv[])
 

Variables

static char * Cmd
 
static char ** Inputs
 
static int verbose
 
static int printMode = INTERNAL
 
static int useClusters = 0
 
static int doEdges = 1
 
static int doAll = 1
 
static char * suffix = 0
 
static char * outfile = 0
 
static char * rootpath = 0
 
static int sufcnt = 0
 
static int sorted = 0
 
static int sortIndex = 0
 
static int sortFinal
 
static int x_index = -1
 
static int x_final = -1
 
static int x_mode
 
static char * x_node
 
static char * useString
 
static gv_stack_t Stk
 

Macro Definition Documentation

◆ BY_INDEX

#define BY_INDEX   1

Definition at line 66 of file ccomps.c.

◆ BY_SIZE

#define BY_SIZE   2

Definition at line 67 of file ccomps.c.

◆ EXTERNAL

#define EXTERNAL   1

Definition at line 62 of file ccomps.c.

◆ EXTRACT

#define EXTRACT   3

Definition at line 64 of file ccomps.c.

◆ GD_cc_subg

#define GD_cc_subg (   g)    (((graphinfo_t*)(g->base.data))->cc_subg)

Definition at line 48 of file ccomps.c.

◆ INTERNAL

#define INTERNAL
Value:
0 /* Basically means all components need to be
* generated before output
*/

Definition at line 61 of file ccomps.c.

◆ ND_dn

#define ND_dn (   n)    ((Agnode_t*)ND_ptr(n))

Definition at line 51 of file ccomps.c.

◆ ND_ptr

#define ND_ptr (   n)    (((nodeinfo_t*)(n->base.data))->ptr)

Definition at line 50 of file ccomps.c.

◆ Node_clust

#define Node_clust (   n)    ((Agraph_t*)ND_ptr(n))

Definition at line 52 of file ccomps.c.

◆ Node_mark

#define Node_mark (   n)    (((nodeinfo_t*)(n->base.data))->mark)

Definition at line 49 of file ccomps.c.

◆ PFX1

#define PFX1   "%s_cc"

Definition at line 363 of file ccomps.c.

◆ PFX2

#define PFX2   "%s_cc_%ld"

Definition at line 364 of file ccomps.c.

◆ SILENT

#define SILENT   2

Definition at line 63 of file ccomps.c.

◆ TAG_NODE

#define TAG_NODE   1

Definition at line 59 of file ccomps.c.

Function Documentation

◆ bindGraphinfo()

static void bindGraphinfo ( Agraph_t g)
static

Definition at line 662 of file ccomps.c.

References agfstsubg(), aginit(), agnxtsubg(), AGRAPH, and bindGraphinfo().

Referenced by bindGraphinfo(), and process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ chkGraphName()

static char * chkGraphName ( Agraph_t g)
static

Definition at line 795 of file ccomps.c.

References agnameof(), agxbprint(), and agxbuse().

Here is the call graph for this function:

◆ cmp()

static int cmp ( const void *  x,
const void *  y 
)
static

Definition at line 458 of file ccomps.c.

Referenced by add_edges_in_G(), addVertex(), dttree(), dtvsearch(), printSorted(), strview_cmp(), SwigPyObject_Check(), and SwigPyPacked_Check().

Here is the caller graph for this function:

◆ deriveClusters()

static void deriveClusters ( Agraph_t dg,
Agraph_t g 
)
static

Definition at line 371 of file ccomps.c.

References agbindrec(), agfstnode(), agfstsubg(), agnameof(), agnode(), agnxtnode(), agnxtsubg(), deriveClusters(), is_a_cluster(), ND_dn, and ND_ptr.

Referenced by deriveClusters(), and deriveGraph().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deriveGraph()

static Agraph_t * deriveGraph ( Agraph_t g)
static

Definition at line 401 of file ccomps.c.

References agbindrec(), agedge(), agfstnode(), agfstout(), aghead, agnameof(), agnode(), agnxtnode(), agnxtout(), agopen(), Agstrictundirected, deriveClusters(), ND_dn, and ND_ptr.

Referenced by cccomps(), and processClusters().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dfs()

static int dfs ( Agraph_t g,
Agnode_t n,
Agraph_t out 
)
static

Definition at line 245 of file ccomps.c.

Referenced by cccomps(), ccomps(), isConnected(), pccomps(), process(), and processClusters().

Here is the caller graph for this function:

◆ getName()

static char * getName ( void  )
static

Definition at line 266 of file ccomps.c.

Referenced by gwrite().

Here is the caller graph for this function:

◆ gwrite()

static void gwrite ( Agraph_t g)
static

Definition at line 282 of file ccomps.c.

Referenced by printSorted(), process(), and processClusters().

Here is the caller graph for this function:

◆ init()

static void init ( int  argc,
char *  argv[] 
)
static

Definition at line 121 of file ccomps.c.

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 806 of file ccomps.c.

◆ pop()

static Agnode_t * pop ( void  )
static

Definition at line 237 of file ccomps.c.

Referenced by closesubg(), closesubg(), construct_graph(), dfs(), dfs(), freestack(), freestack(), genTree(), and search_component().

Here is the caller graph for this function:

◆ printSorted()

static void printSorted ( Agraph_t root,
int  c_cnt 
)
static

Definition at line 483 of file ccomps.c.

References agfstsubg(), agnameof(), agnnodes(), agnxtsubg(), BY_INDEX, BY_SIZE, cmp(), doAll, free(), GD_cc_subg, gv_calloc(), gwrite(), sortFinal, sortIndex, subGInduce(), and x_mode.

Referenced by process(), and processClusters().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process()

static int process ( Agraph_t g,
char *  graphName 
)
static

Definition at line 675 of file ccomps.c.

References agdelete(), agfindnode, agfstnode(), aginit(), agnameof(), agnedges(), agnnodes(), AGNODE, agnxtnode(), AGRAPH, agsubg(), agxbfree(), agxbprint(), agxbuse(), bindGraphinfo(), BY_INDEX, BY_SIZE, dfs(), doAll, doEdges, EXTERNAL, EXTRACT, GD_cc_subg, graphName, graphviz_node_induce(), gwrite(), INTERNAL, Node_mark, out(), PFX1, PFX2, printMode, printSorted(), PRISIZE_T, processClusters(), sorted, subGInduce(), useClusters, verbose, x_final, x_index, x_mode, and x_node.

Here is the call graph for this function:

◆ processClusters()

static int processClusters ( Agraph_t g,
char *  graphName 
)
static

Definition at line 544 of file ccomps.c.

References agclose(), agdelete(), agfindnode, agfstnode(), aginit(), agnameof(), agnedges(), agnnodes(), agnxtnode(), AGRAPH, agsubg(), agxbfree(), agxbprint(), agxbuse(), BY_INDEX, BY_SIZE, deriveGraph(), dfs(), doAll, doEdges, EXTERNAL, EXTRACT, GD_cc_subg, graphName, graphviz_node_induce(), gwrite(), INTERNAL, ND_dn, Node_mark, out(), PFX1, PFX2, printMode, printSorted(), PRISIZE_T, sorted, subGInduce(), unionNodes(), verbose, x_final, x_index, x_mode, and x_node.

Referenced by process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ projectG()

static Agraph_t * projectG ( Agraph_t subg,
Agraph_t g,
int  inCluster 
)
static

Definition at line 311 of file ccomps.c.

References agcopyattr(), agfindnode, agfstnode(), agnameof(), agnxtnode(), agsubg(), agsubnode(), doEdges, and graphviz_node_induce().

Referenced by subgInduce().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ push()

static void push ( Agnode_t np)
static

Definition at line 231 of file ccomps.c.

References Node_mark, stack_push(), and Stk.

Referenced by dfs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ split()

static void split ( void  )
static

Definition at line 108 of file ccomps.c.

Referenced by init(), and Block::splitBetween().

Here is the caller graph for this function:

◆ subGInduce()

static void subGInduce ( Agraph_t g,
Agraph_t out 
)
static

Definition at line 358 of file ccomps.c.

References out(), and subgInduce().

Referenced by cccomps(), printSorted(), process(), and processClusters().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ subgInduce()

static void subgInduce ( Agraph_t root,
Agraph_t g,
int  inCluster 
)
static

Definition at line 341 of file ccomps.c.

References agfstsubg(), agnxtsubg(), GD_cc_subg, is_a_cluster(), projectG(), subgInduce(), and useClusters.

Referenced by subGInduce(), and subgInduce().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unionNodes()

static void unionNodes ( Agraph_t dg,
Agraph_t g 
)
static

Definition at line 441 of file ccomps.c.

References agfstnode(), AGNODE, agnxtnode(), agsubnode(), AGTYPE, ND_dn, ND_ptr, and Node_clust.

Referenced by cccomps(), and processClusters().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ usage()

static void usage ( int  v)
static

Definition at line 102 of file ccomps.c.

References graphviz_exit(), and useString.

Here is the call graph for this function:

Variable Documentation

◆ Cmd

char* Cmd
static

Definition at line 69 of file ccomps.c.

◆ doAll

int doAll = 1
static

Definition at line 75 of file ccomps.c.

Referenced by newPos(), printSorted(), process(), processClusters(), and vAdjust().

◆ doEdges

int doEdges = 1
static

Definition at line 74 of file ccomps.c.

Referenced by neato_layout(), process(), processClusters(), and projectG().

◆ Inputs

char** Inputs
static

Definition at line 70 of file ccomps.c.

◆ outfile

char* outfile = 0
static

Definition at line 77 of file ccomps.c.

◆ printMode

int printMode = INTERNAL
static

Definition at line 72 of file ccomps.c.

Referenced by process(), and processClusters().

◆ rootpath

char* rootpath = 0
static

Definition at line 78 of file ccomps.c.

◆ sorted

int sorted = 0
static

Definition at line 80 of file ccomps.c.

Referenced by process(), and processClusters().

◆ sortFinal

int sortFinal
static

Definition at line 82 of file ccomps.c.

Referenced by printSorted().

◆ sortIndex

int sortIndex = 0
static

Definition at line 81 of file ccomps.c.

Referenced by printSorted().

◆ Stk

gv_stack_t Stk
static

Definition at line 229 of file ccomps.c.

Referenced by push().

◆ sufcnt

int sufcnt = 0
static

Definition at line 79 of file ccomps.c.

◆ suffix

char* suffix = 0
static

Definition at line 76 of file ccomps.c.

◆ useClusters

int useClusters = 0
static

Definition at line 73 of file ccomps.c.

Referenced by Import_coord_clusters_from_dot(), process(), and subgInduce().

◆ useString

char* useString
static
Initial value:
=
"Usage: ccomps [-svenCx?] [-X[#%]s[-f]] [-o<out template>] <files>\n\
-s - silent\n\
-x - external\n\
-X - extract component\n\
-C - use clusters\n\
-e - do not induce edges\n\
-n - do not induce subgraphs\n\
-v - verbose\n\
-o - output file template\n\
-z - sort by size, largest first\n\
-? - print usage\n\
If no files are specified, stdin is used\n"

Definition at line 88 of file ccomps.c.

Referenced by usage().

◆ verbose

int verbose
static

Definition at line 71 of file ccomps.c.

Referenced by process(), and processClusters().

◆ x_final

int x_final = -1
static

Definition at line 84 of file ccomps.c.

Referenced by process(), and processClusters().

◆ x_index

int x_index = -1
static

Definition at line 83 of file ccomps.c.

Referenced by process(), and processClusters().

◆ x_mode

int x_mode
static

Definition at line 85 of file ccomps.c.

Referenced by printSorted(), process(), and processClusters().

◆ x_node

char* x_node
static

Definition at line 86 of file ccomps.c.

Referenced by process(), and processClusters().