Graphviz 14.1.3~dev.20260129.0812
Loading...
Searching...
No Matches
io.c
Go to the documentation of this file.
1
5/*************************************************************************
6 * Copyright (c) 2011 AT&T Intellectual Property
7 * All rights reserved. This program and the accompanying materials
8 * are made available under the terms of the Eclipse Public License v1.0
9 * which accompanies this distribution, and is available at
10 * https://www.eclipse.org/legal/epl-v10.html
11 *
12 * Contributors: Details at https://graphviz.org
13 *************************************************************************/
14
15#include "config.h"
16
17#include <stddef.h>
18#include <stdio.h>
19#include <cgraph/cghdr.h>
20#include <cgraph/rdr.h>
21
22static int iofread(void *chan, char *buf, int bufsize)
23{
24 if (fgets(buf, bufsize, chan))
25 return (int)strlen(buf);
26 else
27 return 0;
28}
29
30/* default IO methods */
31static int ioputstr(void *chan, const char *str)
32{
33 return fputs(str, chan);
34}
35
36static int ioflush(void *chan)
37{
38 return fflush(chan);
39}
40
42
43static int
44memiofread(void *chan, char *buf, int bufsize)
45{
46 const char *ptr;
47 char *optr;
48 char c;
49 int l;
50 rdr_t *s;
51
52 if (bufsize == 0) return 0;
53 s = chan;
54 if (s->cur >= s->len)
55 return 0;
56 l = 0;
57 ptr = s->data + s->cur;
58 optr = buf;
59 /* We know we have at least one character */
60 c = *ptr++;
61 do {
62 *optr++ = c;
63 l++;
64 /* continue if c is not newline, we have space in buffer,
65 * and next character is non-null (we are working with
66 * null-terminated strings.
67 */
68 } while (c != '\n' && l < bufsize && (c = *ptr++));
69 s->cur += (size_t)l;
70 return l;
71}
72
74
75static Agraph_t *agmemread0(Agraph_t *arg_g, const char *cp)
76{
77 rdr_t rdr;
79
82 rdr.data = cp;
83 rdr.len = strlen(cp);
84 rdr.cur = 0;
85
86 disc.id = &AgIdDisc;
87 disc.io = &memIoDisc;
88 if (arg_g) return agconcat(arg_g, NULL, &rdr, &disc);
89 return agread(&rdr, &disc);
90}
91
92Agraph_t *agmemread(const char *cp)
93{
94 return agmemread0(0, cp);
95}
96
97Agraph_t *agmemconcat(Agraph_t *g, const char *cp)
98{
99 return agmemread0(g, cp);
100}
cgraph.h additions
static Dtdisc_t disc
Definition exparse.y:209
node NULL
Definition grammar.y:181
Agiddisc_t AgIdDisc
Definition id.c:93
Agiodisc_t AgIoDisc
Definition io.c:41
Agraph_t * agconcat(Agraph_t *g, const char *filename, void *chan, Agdisc_t *disc)
merges the file contents with a pre-existing graph
Definition grammar.c:2030
Agraph_t * agmemconcat(Agraph_t *g, const char *cp)
Definition io.c:97
Agraph_t * agmemread(const char *cp)
reads a graph from the input string
Definition io.c:92
Agraph_t * agread(void *chan, Agdisc_t *disc)
constructs a new graph
Definition grammar.c:2052
textitem scanner parser str
Definition htmlparse.y:218
static int iofread(void *chan, char *buf, int bufsize)
Definition io.c:22
static int memiofread(void *chan, char *buf, int bufsize)
Definition io.c:44
static Agraph_t * agmemread0(Agraph_t *arg_g, const char *cp)
Definition io.c:75
static int ioflush(void *chan)
Definition io.c:36
static Agiodisc_t memIoDisc
Definition io.c:73
static int ioputstr(void *chan, const char *str)
Definition io.c:31
user's discipline
Definition cgraph.h:336
IO services.
Definition cgraph.h:326
int(* flush)(void *chan)
Definition cgraph.h:329
int(* putstr)(void *chan, const char *str)
Definition cgraph.h:328
graph or subgraph
Definition cgraph.h:424
Definition rdr.h:10
size_t cur
Definition rdr.h:13
const char * data
Definition rdr.h:11
size_t len
Definition rdr.h:12
Definition grammar.c:90