Graphviz 13.0.0~dev.20241220.2304
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 <stddef.h>
16#include <stdio.h>
17#include <cgraph/cghdr.h>
18#include <cgraph/rdr.h>
19
20static int iofread(void *chan, char *buf, int bufsize)
21{
22 if (fgets(buf, bufsize, chan))
23 return (int)strlen(buf);
24 else
25 return 0;
26}
27
28/* default IO methods */
29static int ioputstr(void *chan, const char *str)
30{
31 return fputs(str, chan);
32}
33
34static int ioflush(void *chan)
35{
36 return fflush(chan);
37}
38
40
41static int
42memiofread(void *chan, char *buf, int bufsize)
43{
44 const char *ptr;
45 char *optr;
46 char c;
47 int l;
48 rdr_t *s;
49
50 if (bufsize == 0) return 0;
51 s = chan;
52 if (s->cur >= s->len)
53 return 0;
54 l = 0;
55 ptr = s->data + s->cur;
56 optr = buf;
57 /* We know we have at least one character */
58 c = *ptr++;
59 do {
60 *optr++ = c;
61 l++;
62 /* continue if c is not newline, we have space in buffer,
63 * and next character is non-null (we are working with
64 * null-terminated strings.
65 */
66 } while (c != '\n' && l < bufsize && (c = *ptr++));
67 s->cur += (size_t)l;
68 return l;
69}
70
72
73static Agraph_t *agmemread0(Agraph_t *arg_g, const char *cp)
74{
75 Agraph_t* g;
76 rdr_t rdr;
78
81 rdr.data = cp;
82 rdr.len = strlen(cp);
83 rdr.cur = 0;
84
85 disc.id = &AgIdDisc;
86 disc.io = &memIoDisc;
87 if (arg_g) g = agconcat(arg_g, &rdr, &disc);
88 else g = agread (&rdr, &disc);
89 /* Null out filename and reset line number
90 * The name may have been set with a ppDirective, and
91 * we want to reset line_num.
92 */
94 return g;
95}
96
97Agraph_t *agmemread(const char *cp)
98{
99 return agmemread0(0, cp);
100}
101
102Agraph_t *agmemconcat(Agraph_t *g, const char *cp)
103{
104 return agmemread0(g, cp);
105}
cgraph.h additions
static Dtdisc_t disc
Definition exparse.y:209
node NULL
Definition grammar.y:163
Agiddisc_t AgIdDisc
Definition id.c:100
Agiodisc_t AgIoDisc
Definition io.c:39
Agraph_t * agmemconcat(Agraph_t *g, const char *cp)
Definition io.c:102
Agraph_t * agconcat(Agraph_t *g, void *chan, Agdisc_t *disc)
merges the file contents with a pre-existing graph
Definition grammar.c:2280
Agraph_t * agmemread(const char *cp)
reads a graph from the input string
Definition io.c:97
void agsetfile(const char *)
sets the current file name for subsequent error reporting
Definition scan.c:2415
Agraph_t * agread(void *chan, Agdisc_t *disc)
constructs a new graph
Definition grammar.c:2292
textitem scanner parser str
Definition htmlparse.y:224
static int iofread(void *chan, char *buf, int bufsize)
Definition io.c:20
static int memiofread(void *chan, char *buf, int bufsize)
Definition io.c:42
static Agraph_t * agmemread0(Agraph_t *arg_g, const char *cp)
Definition io.c:73
static int ioflush(void *chan)
Definition io.c:34
static Agiodisc_t memIoDisc
Definition io.c:71
static int ioputstr(void *chan, const char *str)
Definition io.c:29
user's discipline
Definition cgraph.h:337
IO services.
Definition cgraph.h:327
int(* flush)(void *chan)
Definition cgraph.h:330
int(* putstr)(void *chan, const char *str)
Definition cgraph.h:329
graph or subgraph
Definition cgraph.h:425
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:93