Graphviz 16.1.1~dev.20261017.1520
Loading...
Searching...
No Matches
write.c File Reference

implements agwrite, agstrcanon, and agcanonStr More...

#include "config.h"
#include <assert.h>
#include <cdt/cdt.h>
#include <cgraph/agstrcanon.h>
#include <cgraph/cghdr.h>
#include <ctype.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <util/alloc.h>
#include <util/bitarray.h>
#include <util/gv_ctype.h>
#include <util/strcasecmp.h>
#include <util/unused.h>
Include dependency graph for write.c:

Go to the source code of this file.

Data Structures

struct  pending_edge_t
 an edge destined to be written out More...
 
struct  info_t
 

Macros

#define EMPTY(s)   (((s) == 0) || (s)[0] == '\0')
 
#define MAX_OUTPUTLINE   128
 
#define MIN_OUTPUTLINE   60
 

Typedefs

typedef void iochan_t
 

Functions

static int ioput (Agraph_t *g, iochan_t *ofile, char *str)
 
static int write_body (Agraph_t *g, iochan_t *ofile, info_t *info)
 
static info_t before_write (Agraph_t *)
 
static void after_write (info_t)
 
static int indent (Agraph_t *g, iochan_t *ofile, const info_t info)
 
static bool is_id_char (char c)
 
static bool is_escape (const char *str)
 
static char * agstrcanon_ (char *arg, char *buf)
 
static char * agcanonhtmlstr (const char *arg, char *buf)
 
char * agstrcanon (char *arg, char *buf)
 
static int write_canonstr_ (Agraph_t *g, iochan_t *ofile, char *str, bool chk)
 
static int write_canonstr (Agraph_t *g, iochan_t *ofile, char *str, bool known)
 
static int write_dict (Agraph_t *g, iochan_t *ofile, char *name, Dict_t *dict, bool top, info_t *info)
 
static int write_dicts (Agraph_t *g, iochan_t *ofile, bool top, info_t *info)
 
static int write_hdr (Agraph_t *g, iochan_t *ofile, bool top, info_t *info)
 
static int write_trl (Agraph_t *g, iochan_t *ofile, info_t *info)
 
static bool is_anonymous (Agraph_t *g)
 
static bool irrelevant_subgraph (Agraph_t *g)
 
static bool has_no_edges (Agraph_t *g, Agnode_t *n)
 
static bool not_default_attrs (Agraph_t *g, Agnode_t *n)
 
static int write_subgs (Agraph_t *g, iochan_t *ofile, info_t *info)
 
static int write_edge_name (Agedge_t *e, iochan_t *ofile, bool terminate, info_t *info)
 
static int write_nondefault_attrs (void *obj, iochan_t *ofile, Dict_t *defdict, info_t *info)
 
static int write_nodename (Agnode_t *n, iochan_t *ofile)
 
static int attrs_written (void *obj)
 
static int write_node (Agraph_t *subg, Agnode_t *n, iochan_t *ofile, Dict_t *d, info_t *info)
 
static bool write_node_test (Agraph_t *g, Agnode_t *n, info_t *info)
 
static int write_port (Agedge_t *e, iochan_t *ofile, Agsym_t *port)
 
static int write_edge (Agedge_t *e, iochan_t *ofile, Dict_t *d, info_t *info)
 
static int write_edges (iochan_t *ofile, Dict_t *d, info_t *info)
 
static void set_attrwf (Agraph_t *g, bool toplevel, bool value)
 
int agwrite (Agraph_t *g, void *ofile)
 Return 0 on success, EOF on failure.
 
static uint64_t subgdfs (Agraph_t *g, uint64_t ix, info_t *info)
 
static void * copy (void *p, Dtdisc_t *disc UNUSED)
 
static int cmp (void *a, void *b)
 

Variables

static int Max_outputline = MAX_OUTPUTLINE
 
static Agsym_t * Tailport
 
static Agsym_t * Headport
 
static Dtdisc_t edge_disc
 the “discipline” for info_t.edges_todo
 

Macro Definition Documentation

◆ EMPTY

#define EMPTY (   s)    (((s) == 0) || (s)[0] == '\0')

Definition at line 38 of file write.c.

◆ MAX_OUTPUTLINE

#define MAX_OUTPUTLINE   128

Definition at line 46 of file write.c.

◆ MIN_OUTPUTLINE

#define MIN_OUTPUTLINE   60

Definition at line 47 of file write.c.

Typedef Documentation

◆ iochan_t

typedef void iochan_t

Definition at line 40 of file write.c.

Function Documentation

◆ after_write()

static void after_write ( info_t  info)
static

Definition at line 816 of file write.c.

References bitarray_reset(), dtclose(), and free().

Referenced by agwrite().

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

◆ agcanonhtmlstr()

static char * agcanonhtmlstr ( const char *  arg,
char *  buf 
)
static

Canonicalize html strings.

Definition at line 217 of file write.c.

Referenced by agstrcanon().

Here is the caller graph for this function:

◆ agstrcanon_()

static char * agstrcanon_ ( char *  arg,
char *  buf 
)
static

Definition at line 126 of file write.c.

References cnt(), EMPTY, gv_isalnum(), gv_isdigit(), is_escape(), is_id_char(), Max_outputline, NULL, and tok().

Referenced by agstrcanon(), and write_canonstr_().

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

◆ attrs_written()

static int attrs_written ( void *  obj)
static

Definition at line 566 of file write.c.

References AGATTRWF.

Referenced by write_edge(), and write_node().

Here is the caller graph for this function:

◆ before_write()

static info_t before_write ( Agraph_t *  g)
static

Definition at line 803 of file write.c.

References AGEDGE, AGNODE, AGRAPH, bitarray_new(), Agraph_s::clos, dtopen(), Dtoset, edge_disc, gv_calloc(), Agclos_s::seq, set_attrwf(), and subgdfs().

Referenced by agwrite().

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

◆ cmp()

static int cmp ( void *  a,
void *  b 
)
static

Definition at line 781 of file write.c.

◆ copy()

static void * copy ( void *  p,
Dtdisc_t *disc  UNUSED 
)
static

Definition at line 773 of file write.c.

References pending_edge_t::edge, gv_alloc(), and pending_edge_t::seq.

Referenced by getval(), gv_strdup(), gv_strndup(), and prformat().

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

◆ has_no_edges()

static bool has_no_edges ( Agraph_t *  g,
Agnode_t *  n 
)
static

Definition at line 432 of file write.c.

References agfstin(), agfstout(), and NULL.

Referenced by write_node_test().

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

◆ indent()

static int indent ( Agraph_t *  g,
iochan_t *  ofile,
const info_t  info 
)
static

Definition at line 72 of file write.c.

References ioput().

Referenced by write_dict(), write_edge(), write_hdr(), write_node(), write_nondefault_attrs(), and write_trl().

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

◆ ioput()

static int ioput ( Agraph_t *  g,
iochan_t *  ofile,
char *  str 
)
static

Definition at line 42 of file write.c.

References AGDISC, and str.

Referenced by indent(), write_canonstr_(), write_dict(), write_edge(), write_edge_name(), write_hdr(), write_node(), write_nodename(), write_nondefault_attrs(), write_port(), and write_trl().

Here is the caller graph for this function:

◆ irrelevant_subgraph()

static bool irrelevant_subgraph ( Agraph_t *  g)
static

Definition at line 409 of file write.c.

References agattrrec(), agdatadict(), agparent(), agroot(), Agdatadict_s::dict, dtsize(), Agdatadict_s::e, is_anonymous(), Agdatadict_s::n, and Agattr_s::str.

Referenced by write_subgs().

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

◆ is_anonymous()

static bool is_anonymous ( Agraph_t *  g)
static

is this graph unnamed?

Parameters
gGraph to inspect
Returns
True if this graph was given no explicit name

Definition at line 392 of file write.c.

References AGDISC, AGID, AgIdDisc, agnameof(), LOCALNAMEPREFIX, and NULL.

Referenced by irrelevant_subgraph().

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

◆ is_escape()

static bool is_escape ( const char *  str)
static

Definition at line 88 of file write.c.

References NULL, and str.

Referenced by agstrcanon_().

Here is the caller graph for this function:

◆ is_id_char()

static bool is_id_char ( char  c)
static

Definition at line 82 of file write.c.

References gv_isalnum().

Referenced by agstrcanon_().

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

◆ not_default_attrs()

static bool not_default_attrs ( Agraph_t *  g,
Agnode_t *  n 
)
static

Definition at line 436 of file write.c.

References agattrrec(), Agsym_s::defval, Agattr_s::dict, dtfirst, dtnext, Agsym_s::id, and Agattr_s::str.

Referenced by write_node_test().

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

◆ set_attrwf()

static void set_attrwf ( Agraph_t *  g,
bool  toplevel,
bool  value 
)
static

Definition at line 717 of file write.c.

References AGATTRWF, agfstnode(), agfstout(), agfstsubg(), agnxtnode(), agnxtout(), agnxtsubg(), and set_attrwf().

Referenced by before_write(), and set_attrwf().

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

◆ subgdfs()

static uint64_t subgdfs ( Agraph_t *  g,
uint64_t  ix,
info_t *  info 
)
static

Definition at line 762 of file write.c.

References agfstsubg(), agnxtsubg(), AGSEQ, and subgdfs().

Referenced by before_write(), and subgdfs().

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

◆ write_body()

static int write_body ( Agraph_t *  g,
iochan_t *  ofile,
info_t *  info 
)
static

Definition at line 680 of file write.c.

References agdatadict(), agfstnode(), agfstout(), aghead, agnxtnode(), agnxtout(), AGSEQ, bitarray_get(), Agdatadict_s::dict, dtinsert, Agdatadict_s::e, Agdatadict_s::n, NULL, prev, pending_edge_t::seq, write_edges(), write_node(), write_node_test(), and write_subgs().

Referenced by agwrite(), and write_subgs().

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

◆ write_canonstr()

static int write_canonstr ( Agraph_t *  g,
iochan_t *  ofile,
char *  str,
bool  known 
)
static
Parameters
knownIs str already known to be a reference-counted string?

Definition at line 252 of file write.c.

References agstrdup(), agstrfree(), str, and write_canonstr_().

Referenced by write_dict(), write_edge_name(), write_hdr(), write_nodename(), write_nondefault_attrs(), and write_port().

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

◆ write_canonstr_()

static int write_canonstr_ ( Agraph_t *  g,
iochan_t *  ofile,
char *  str,
bool  chk 
)
static

Definition at line 233 of file write.c.

References agstrcanon(), agstrcanon_(), agstrcanon_bytes(), free(), ioput(), malloc(), NULL, and str.

Referenced by write_canonstr(), and write_port().

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

◆ write_dict()

static int write_dict ( Agraph_t *  g,
iochan_t *  ofile,
char *  name,
Dict_t *  dict,
bool  top,
info_t *  info 
)
static

Definition at line 268 of file write.c.

References cnt(), Agsym_s::defval, dtfirst, dtnext, dtsearch, dtview(), EMPTY, indent(), ioput(), Agsym_s::name, NULL, Agsym_s::print, top(), view, and write_canonstr().

Referenced by write_dicts().

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

◆ write_dicts()

static int write_dicts ( Agraph_t *  g,
iochan_t *  ofile,
bool  top,
info_t *  info 
)
static

Definition at line 317 of file write.c.

References agdatadict(), Agdatadict_s::dict, Agdatadict_s::e, Agdatadict_s::g, Agdatadict_s::n, top(), and write_dict().

Referenced by write_hdr().

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

◆ write_edge()

static int write_edge ( Agedge_t *  e,
iochan_t *  ofile,
Dict_t *  d,
info_t *  info 
)
static

Definition at line 636 of file write.c.

References AGHEAD, agisdirected(), agraphof(), AGTAIL, attrs_written(), Headport, indent(), ioput(), Tailport, write_edge_name(), write_nodename(), write_nondefault_attrs(), and write_port().

Referenced by write_edges().

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

◆ write_edge_name()

static int write_edge_name ( Agedge_t *  e,
iochan_t *  ofile,
bool  terminate,
info_t *  info 
)
static

Definition at line 467 of file write.c.

References agnameof(), agraphof(), EMPTY, ioput(), and write_canonstr().

Referenced by write_edge(), and write_nondefault_attrs().

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

◆ write_edges()

static int write_edges ( iochan_t *  ofile,
Dict_t *  d,
info_t *  info 
)
static

write out all the edges pending in info->edges_todo

Parameters
ofileChannel to write output to
dAttribute defaults
infoState for traversal
Returns
0 on success

Definition at line 668 of file write.c.

References bitarray_set(), dtclear, dtfirst, dtnext, NULL, and write_edge().

Referenced by write_body().

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

◆ write_hdr()

static int write_hdr ( Agraph_t *  g,
iochan_t *  ofile,
bool  top,
info_t *  info 
)
static

Definition at line 329 of file write.c.

References agattr_text(), AGATTRWF, AGEDGE, agisstrict(), agnameof(), agparent(), Agraph_s::desc, Agdesc_s::directed, Headport, HEADPORT_ID, indent(), ioput(), LOCALNAMEPREFIX, NULL, Tailport, TAILPORT_ID, top(), write_canonstr(), and write_dicts().

Referenced by agwrite(), and write_subgs().

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

◆ write_node()

static int write_node ( Agraph_t *  subg,
Agnode_t *  n,
iochan_t *  ofile,
Dict_t *  d,
info_t *  info 
)
static

Definition at line 568 of file write.c.

References agraphof(), AGSEQ, attrs_written(), indent(), ioput(), write_nodename(), and write_nondefault_attrs().

Referenced by write_body().

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

◆ write_node_test()

static bool write_node_test ( Agraph_t *  g,
Agnode_t *  n,
info_t *  info 
)
static

Definition at line 589 of file write.c.

References AGSEQ, has_no_edges(), and not_default_attrs().

Referenced by write_body().

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

◆ write_nodename()

static int write_nodename ( Agnode_t *  n,
iochan_t *  ofile 
)
static

Definition at line 545 of file write.c.

References AGID, agnameof(), agraphof(), ioput(), and write_canonstr().

Referenced by write_edge(), and write_node().

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

◆ write_nondefault_attrs()

static int write_nondefault_attrs ( void *  obj,
iochan_t *  ofile,
Dict_t *  defdict,
info_t *  info 
)
static

Definition at line 492 of file write.c.

References agattrrec(), AGATTRWF, AGINEDGE, AGOUTEDGE, agraphof(), AGTYPE, cnt(), Agsym_s::defval, dtfirst, dtnext, Headport, Agsym_s::id, indent(), ioput(), Agsym_s::name, Agattr_s::str, Tailport, write_canonstr(), and write_edge_name().

Referenced by write_edge(), and write_node().

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

◆ write_port()

static int write_port ( Agedge_t *  e,
iochan_t *  ofile,
Agsym_t *  port 
)
static

Definition at line 599 of file write.c.

References aghtmlstr(), agraphof(), agxget(), ioput(), write_canonstr(), and write_canonstr_().

Referenced by write_edge().

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

◆ write_subgs()

static int write_subgs ( Agraph_t *  g,
iochan_t *  ofile,
info_t *  info 
)
static

Definition at line 450 of file write.c.

References agfstsubg(), agnxtsubg(), irrelevant_subgraph(), write_body(), write_hdr(), write_subgs(), and write_trl().

Referenced by write_body(), and write_subgs().

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

◆ write_trl()

static int write_trl ( Agraph_t *  g,
iochan_t *  ofile,
info_t *  info 
)
static

Definition at line 380 of file write.c.

References indent(), and ioput().

Referenced by agwrite(), and write_subgs().

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

Variable Documentation

◆ edge_disc

Dtdisc_t edge_disc
static
Initial value:
= {
.key = offsetof(pending_edge_t, seq),
.size = sizeof(unsigned),
.link = offsetof(pending_edge_t, link),
.makef = copy,
.freef = free,
.comparf = cmp,
}
void free(void *)
an edge destined to be written out
Definition write.c:52
static int cmp(void *a, void *b)
Definition write.c:781
static void * copy(void *p, Dtdisc_t *disc UNUSED)
Definition write.c:773

Definition at line 794 of file write.c.

Referenced by before_write().

◆ Headport

Agsym_t * Headport
static

Definition at line 49 of file write.c.

Referenced by write_edge(), write_hdr(), and write_nondefault_attrs().

◆ Max_outputline

int Max_outputline = MAX_OUTPUTLINE
static

Definition at line 48 of file write.c.

Referenced by agstrcanon_(), and agwrite().

◆ Tailport

Agsym_t* Tailport
static

Definition at line 49 of file write.c.

Referenced by write_edge(), write_hdr(), and write_nondefault_attrs().