1 /* $Id$ $Revision$ */
2 /* vim:set shiftwidth=4 ts=8: */
3 
4 /*************************************************************************
5  * Copyright (c) 2011 AT&T Intellectual Property
6  * All rights reserved. This program and the accompanying materials
7  * are made available under the terms of the Eclipse Public License v1.0
8  * which accompanies this distribution, and is available at
9  * http://www.eclipse.org/legal/epl-v10.html
10  *
11  * Contributors: See CVS logs. Details at http://www.graphviz.org/
12  *************************************************************************/
13 
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include "gvc.h"
17 #include "gvplugin.h"
18 #include "gvcjob.h"
19 #include "gvcint.h"
20 
21 typedef struct {
22     char* data;
23     int sz;       /* buffer size */
24     int len;      /* length of array */
25 } BA;
26 
gv_string_writer(GVJ_t * job,const char * s,size_t len)27 static size_t gv_string_writer(GVJ_t *job, const char *s, size_t len)
28 {
29     BA* bap = (BA*)(job->output_file);
30 /* fprintf (stderr, "newlen %ld data %p sz %d len %d\n", len, bap->data,bap->sz, bap->len); */
31     int newlen = bap->len + len;
32     if (newlen > bap->sz) {
33 	bap->sz *= 2;
34 	if (newlen > bap->sz)
35 	    bap->sz = 2*newlen;
36         bap->data = (char*)realloc(bap->data, bap->sz);
37     }
38     memcpy (bap->data+bap->len, s, len);
39     bap->len = newlen;
40     return len;
41 }
42 
gv_string_writer_init(GVC_t * gvc)43 void gv_string_writer_init(GVC_t *gvc)
44 {
45     gvc->write_fn = gv_string_writer;
46 }
47 
gv_channel_writer(GVJ_t * job,const char * s,size_t len)48 static size_t gv_channel_writer(GVJ_t *job, const char *s, size_t len)
49 {
50     return len;
51 }
52 
gv_channel_writer_init(GVC_t * gvc)53 void gv_channel_writer_init(GVC_t *gvc)
54 {
55     gvc->write_fn = gv_channel_writer;
56 }
57 
gv_writer_reset(GVC_t * gvc)58 void gv_writer_reset (GVC_t *gvc) {gvc->write_fn = NULL;}
59