40static const unsigned char z_file_header[] =
41 {0x1f, 0x8b, Z_DEFLATED, 0 , 0,0,0,0 , 0 , OS_CODE};
43static z_stream z_strm;
44static unsigned char *df;
45static unsigned int dfallocated;
97 const char *src_end = src + strlen(src);
98 for (
const char *q = src_end; ; --q) {
100 agxbprint(&buf,
"%.*s.", (
int)(src_end - q - 1), q + 1);
104 agxbprint(&buf,
"%.*s", (
int)(src_end - src), src);
133 job->
common->
errorfn(
"Could not open \"%s\" for writing : %s\n",
156 z_stream *
z = &z_strm;
165 crc = crc32(0
L, Z_NULL, 0);
167 if (deflateInit2(
z, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY) != Z_OK) {
171 gvwrite_no_z(job, z_file_header,
sizeof(z_file_header));
189 z_streamp
z = &z_strm;
191 size_t dflen = deflateBound(
z,
len);
192 if (dfallocated < dflen) {
193 dfallocated = dflen > UINT_MAX - 1 ? UINT_MAX : (unsigned)dflen + 1;
194 df = realloc(df, dfallocated);
201#if ZLIB_VERNUM >= 0x1290
202 crc = crc32_z(crc, (
const unsigned char*)
s,
len);
204 crc = crc32(crc, (
const unsigned char*)
s,
len);
210#pragma GCC diagnostic push
211#pragma GCC diagnostic ignored "-Wcast-qual"
213 z->next_in = (
unsigned char *)
s +
offset;
215#pragma GCC diagnostic pop
217 const unsigned chunk =
len -
offset > UINT_MAX
221 z->avail_out = dfallocated;
222 int r = deflate(
z, Z_NO_FLUSH);
228 if ((olen = (
size_t)(
z->next_out - df))) {
266 size_t len = strlen(
s);
280 for (; *
s !=
'\0'; ++
s) {
283 }
else if (isascii((
int)*
s)) {
293 const char cc = (char)c;
295 if (
gvwrite (job, &cc, 1) != 1) {
337 bool finalized_p =
false;
341 z_streamp
z = &z_strm;
342 unsigned char out[8] =
"";
349 z->avail_out = dfallocated;
350 while ((ret = deflate (
z, Z_FINISH)) == Z_OK && (
cnt++ <= 100)) {
353 z->avail_out = dfallocated;
355 if (ret != Z_STREAM_END) {
366 out[0] = (
unsigned char)crc;
367 out[1] = (
unsigned char)(crc >> 8);
368 out[2] = (
unsigned char)(crc >> 16);
369 out[3] = (
unsigned char)(crc >> 24);
370 out[4] = (
unsigned char)
z->total_in;
371 out[5] = (
unsigned char)(
z->total_in >> 8);
372 out[6] = (
unsigned char)(
z->total_in >> 16);
373 out[7] = (
unsigned char)(
z->total_in >> 24);
404 agerrorf(
"gvprintf: %s\n", strerror(errno));
419#define val_str(n, x) static double n = x; static char n##str[] = #x;
432 if (
number > -maxnegnum) {
444 memmove(staging, &staging[1], strlen(staging));
446 memmove(&staging[1], &staging[2], strlen(&staging[1]));
454#ifdef GVPRINTNUM_TEST
455int main (
int argc,
char *argv[])
462 -maxnegnum*1.1, -maxnegnum*.9,
463 1e8, 10.008, 10, 1, .1, .01,
464 .006, .005, .004, .001, 1e-8,
466 -1e-8, -.001, -.004, -.005, -.006,
467 -.01, -.1, -1, -10, -10.008, -1e8,
468 maxnegnum*.9, maxnegnum*1.1
470 int i =
sizeof(test) /
sizeof(test[0]);
473 gvprintnum(&xb, test[i]);
475 fprintf (stdout,
"%g = %s %d\n", test[i], buf,
len);
488 char *dotp = strchr(buf,
'.');
494 assert(isdigit((
int)dotp[1]) && isdigit((
int)dotp[2]) && dotp[3] ==
'\0');
496 if (dotp[2] ==
'0') {
497 if (dotp[1] ==
'0') {
498 return (
size_t)(dotp - buf);
500 return (
size_t)(dotp - buf) + 2;
510 if (num > -0.005 && num < 0.005)
518 snprintf(buf, 50,
"%.02f", num);
528 gvprintnum(&xb, p.
x);
529 const char *buf =
agxbuse(&xb);
530 gvwrite(job, buf, strlen(buf));
532 gvprintnum(&xb, p.
y);
534 gvwrite(job, buf, strlen(buf));
539 const char *separator =
"";
540 for (
size_t i = 0; i < n; ++i) {
static void out(agerrlevel_t level, const char *fmt, va_list args)
Report messages using a user-supplied or default write function.
static void agxbfree(agxbuf *xb)
free any malloced resources
static int agxbprint(agxbuf *xb, const char *fmt,...)
Printf-style output to an agxbuf.
static int vagxbprint(agxbuf *xb, const char *fmt, va_list ap)
vprintf-style output to an agxbuf
static WUR char * agxbuse(agxbuf *xb)
static int agxbputc(agxbuf *xb, char c)
add character to buffer
static char * agxbdisown(agxbuf *xb)
static NORETURN void graphviz_exit(int status)
static double len(glCompPoint p)
static int cnt(Dict_t *d, Dtlink_t **set)
void agerrorf(const char *fmt,...)
FILE * gv_fopen(const char *filename, const char *mode)
wrapper around fopen for internal library usage
swig_ptr_object_handlers offset
#define GVDEVICE_COMPRESSED_FORMAT
#define GVDEVICE_BINARY_FORMAT
size_t gvwrite(GVJ_t *job, const char *s, size_t len)
int gvputc(GVJ_t *job, int c)
static void auto_output_filename(GVJ_t *job)
void gvdevice_finalize(GVJ_t *job)
static void gvdevice_close(GVJ_t *job)
void gvputs_nonascii(GVJ_t *job, const char *s)
static size_t gvwrite_no_z(GVJ_t *job, const void *s, size_t len)
int gvputs_xml(GVJ_t *job, const char *s)
int gvferror(FILE *stream)
int gvdevice_initialize(GVJ_t *job)
int gvputs(GVJ_t *job, const char *s)
void gvdevice_format(GVJ_t *job)
void gvprintpointflist(GVJ_t *job, pointf *p, size_t n)
void gvprintpointf(GVJ_t *job, pointf p)
static size_t gv_trim_zeros(const char *buf)
void gvprintf(GVJ_t *job, const char *format,...)
void gvprintdouble(GVJ_t *job, double num)
GVIO_API const char * format
static bool startswith(const char *s, const char *prefix)
does the string s begin with the string prefix?
void(* errorfn)(const char *fmt,...)
size_t(* write_fn)(GVJ_t *job, const char *s, size_t len)
size_t output_data_allocated
size_t output_data_position
const char * output_filename
gvplugin_active_device_t device
const char * output_langname
void(* format)(GVJ_t *firstjob)
void(* finalize)(GVJ_t *firstjob)
void(* initialize)(GVJ_t *firstjob)
gvdevice_engine_t * engine
int xml_escape(const char *s, xml_flags_t flags, int(*cb)(void *state, const char *s), void *state)