]> granicus.if.org Git - graphviz/commitdiff
No value in making gvprintnum() generally accessible. Merge into gvdevice.c
authorellson <devnull@localhost>
Fri, 21 Dec 2007 01:48:33 +0000 (01:48 +0000)
committerellson <devnull@localhost>
Fri, 21 Dec 2007 01:48:33 +0000 (01:48 +0000)
and make static.

lib/gvc/gvcproc.h
lib/gvc/gvdevice.c
lib/gvc/gvprintnum.c [deleted file]

index b8c93f6e47355a0e347f4ebdbe99d3ab300307c2..3599d1b6767f3e98129790df6e6b4fd79f763bcb 100644 (file)
@@ -77,7 +77,6 @@ extern "C" {
     extern void gvdevice_format(GVJ_t * job);
     extern void gvdevice_finalize(GVJ_t * job);
 
-    extern unsigned char * gvprintnum(int *len, double num);
     extern void gvdevice_printnum(GVJ_t * job, double num);
     extern void gvdevice_printpointf(GVJ_t * job, pointf p);
     extern void gvdevice_printpointflist(GVJ_t * job, pointf *p, int n);
index 1cf0d98cc1fd689cd341610eecf1164ab208106e..fe2caf78721f0aee8cf6ac93d6cb77aaa77e74b2 100644 (file)
@@ -104,6 +104,104 @@ void gvdevice_printf(GVJ_t * job, const char *format, ...)
     gvdevice_write(job, buf, len);
 }
 
+
+/* Test with:
+ *     cc -DGVPRINTNUM_TEST gvprintnum.c -o gvprintnum
+ */
+
+#define DECPLACES 2
+#define DECPLACES_SCALE 100
+
+/* use macro so maxnegnum is stated just once for both double and string versions */
+#define val_str(n, x) static double n = x; static unsigned char n##str[] = #x;
+val_str(maxnegnum, -999999999999999.99)
+
+/* Note.  Returned string is only good until the next call to gvprintnum */
+static unsigned char * gvprintnum (int *len, double number)
+{
+    static unsigned char tmpbuf[sizeof(maxnegnumstr)];   /* buffer big enough for worst case */
+    unsigned char *result = tmpbuf+sizeof(maxnegnumstr); /* init result to end of tmpbuf */
+    long int N;
+    bool showzeros, negative;
+    int digit, i;
+
+    /*
+        number limited to a working range: maxnegnum >= n >= -maxnegnum
+       N = number * DECPLACES_SCALE rounded towards zero,
+       printing to buffer in reverse direction,
+       printing "." after DECPLACES
+       suppressing trailing "0" and "."
+     */
+
+    if (number < maxnegnum) {          /* -ve limit */
+       *len = sizeof(maxnegnumstr)-1;  /* len doesn't include terminator */
+       return maxnegnumstr;;
+    }
+    if (number > -maxnegnum) {         /* +ve limit */
+       *len = sizeof(maxnegnumstr)-2;  /* len doesn't include terminator or sign */
+       return maxnegnumstr+1;          /* +1 to skip the '-' sign */
+    }
+    number *= DECPLACES_SCALE;         /* scale by DECPLACES_SCALE */
+    if (number < 0.0)                  /* round towards zero */
+        N = number - 0.5;
+    else
+        N = number + 0.5;
+    if (N == 0) {                      /* special case for exactly 0 */
+       *len = 1;
+       return (unsigned char *)"0";
+    }
+    if ((negative = (N < 0)))          /* avoid "-0" by testing rounded int */
+        N = -N;                                /* make number +ve */
+    *--result = '\0';                  /* terminate the result string */
+    showzeros = false;                 /* don't print trailing zeros */
+    for (i = DECPLACES; N || i > 0; i--) {  /* non zero remainder,
+                                               or still in fractional part */
+        digit = N % 10;                        /* next least-significant digit */
+        N /= 10;
+        if (digit || showzeros) {      /* if digit is non-zero,
+                                               or if we are printing zeros */
+            *--result = digit | '0';   /* convert digit to ascii */
+            showzeros = true;          /* from now on we must print zeros */
+        }
+        if (i == 1) {                  /* if completed fractional part */
+            if (showzeros)             /* if there was a non-zero fraction */
+                *--result = '.';       /* print decimal point */
+            showzeros = true;          /* print all digits in int part */
+        }
+    }
+    if (negative)                      /* print "-" if needed */
+        *--result = '-';
+    *len = tmpbuf+sizeof(maxnegnumstr)-1 - result;
+    return result;                             
+}
+
+
+#ifdef GVPRINTNUM_TEST
+int main (int argc, char *argv[])
+{
+    unsigned char *buf;
+    int len;
+
+    double test[] = {
+       -maxnegnum*1.1, -maxnegnum*.9,
+       1e8, 10.008, 10, 1, .1, .01,
+       .006, .005, .004, .001, 1e-8, 
+       0, -0,
+       -1e-8, -.001, -.004, -.005, -.006,
+       -.01, -.1, -1, -10, -10.008, -1e8,
+       maxnegnum*.9, maxnegnum*1.1
+    };
+    int i = sizeof(test) / sizeof(test[0]);
+
+    while (i--) {
+       buf = gvprintnum(&len, test[i]);
+        fprintf (stdout, "%g = %s %d\n", test[i], buf, len);
+    }
+
+    return 0;
+}
+#endif
+
 void gvdevice_printnum(GVJ_t * job, double num)
 {
     unsigned char *buf;
diff --git a/lib/gvc/gvprintnum.c b/lib/gvc/gvprintnum.c
deleted file mode 100644 (file)
index 4087fa0..0000000
+++ /dev/null
@@ -1,116 +0,0 @@
-/* $Id$ $Revision$ */
-/* vim:set shiftwidth=4 ts=8: */
-
-/***********************************************************
- *      This software is part of the graphviz package      *
- *                http://www.graphviz.org/                 *
- *                                                         *
- *            Copyright (c) 1994-2004 AT&T Corp.           *
- *                and is licensed under the                *
- *            Common Public License, Version 1.0           *
- *                      by AT&T Corp.                      *
- *                                                         *
- *        Information and Software Systems Research        *
- *              AT&T Research, Florham Park NJ             *
- ***********************************************************/
-
-/* Test with:
- *     cc -DGVPRINTNUM_TEST gvprintnum.c -o gvprintnum
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <stdbool.h>
-
-#define DECPLACES 2
-#define DECPLACES_SCALE 100
-
-/* use macro so maxnegnum is stated just once for both double and string versions */
-#define val_str(n, x) static double n = x; static unsigned char n##str[] = #x;
-val_str(maxnegnum, -999999999999999.99)
-
-/* Note.  Returned string is only good until the next call to gvprintnum */
-unsigned char * gvprintnum (int *len, double number)
-{
-    static unsigned char tmpbuf[sizeof(maxnegnumstr)];   /* buffer big enough for worst case */
-    unsigned char *result = tmpbuf+sizeof(maxnegnumstr); /* init result to end of tmpbuf */
-    long int N;
-    bool showzeros, negative;
-    int digit, i;
-
-    /*
-        number limited to a working range: maxnegnum >= n >= -maxnegnum
-       N = number * DECPLACES_SCALE rounded towards zero,
-       printing to buffer in reverse direction,
-       printing "." after DECPLACES
-       suppressing trailing "0" and "."
-     */
-
-    if (number < maxnegnum) {          /* -ve limit */
-       *len = sizeof(maxnegnumstr)-1;  /* len doesn't include terminator */
-       return maxnegnumstr;;
-    }
-    if (number > -maxnegnum) {         /* +ve limit */
-       *len = sizeof(maxnegnumstr)-2;  /* len doesn't include terminator or sign */
-       return maxnegnumstr+1;          /* +1 to skip the '-' sign */
-    }
-    number *= DECPLACES_SCALE;         /* scale by DECPLACES_SCALE */
-    if (number < 0.0)                  /* round towards zero */
-        N = number - 0.5;
-    else
-        N = number + 0.5;
-    if (N == 0) {                      /* special case for exactly 0 */
-       *len = 1;
-       return (unsigned char *)"0";
-    }
-    if ((negative = (N < 0)))          /* avoid "-0" by testing rounded int */
-        N = -N;                                /* make number +ve */
-    *--result = '\0';                  /* terminate the result string */
-    showzeros = false;                 /* don't print trailing zeros */
-    for (i = DECPLACES; N || i > 0; i--) {  /* non zero remainder,
-                                               or still in fractional part */
-        digit = N % 10;                        /* next least-significant digit */
-        N /= 10;
-        if (digit || showzeros) {      /* if digit is non-zero,
-                                               or if we are printing zeros */
-            *--result = digit | '0';   /* convert digit to ascii */
-            showzeros = true;          /* from now on we must print zeros */
-        }
-        if (i == 1) {                  /* if completed fractional part */
-            if (showzeros)             /* if there was a non-zero fraction */
-                *--result = '.';       /* print decimal point */
-            showzeros = true;          /* print all digits in int part */
-        }
-    }
-    if (negative)                      /* print "-" if needed */
-        *--result = '-';
-    *len = tmpbuf+sizeof(maxnegnumstr)-1 - result;
-    return result;                             
-}
-
-
-#ifdef GVPRINTNUM_TEST
-int main (int argc, char *argv[])
-{
-    unsigned char *buf;
-    int len;
-
-    double test[] = {
-       -maxnegnum*1.1, -maxnegnum*.9,
-       1e8, 10.008, 10, 1, .1, .01,
-       .006, .005, .004, .001, 1e-8, 
-       0, -0,
-       -1e-8, -.001, -.004, -.005, -.006,
-       -.01, -.1, -1, -10, -10.008, -1e8,
-       maxnegnum*.9, maxnegnum*1.1
-    };
-    int i = sizeof(test) / sizeof(test[0]);
-
-    while (i--) {
-       buf = gvprintnum(&len, test[i]);
-        fprintf (stdout, "%g = %s %d\n", test[i], buf, len);
-    }
-
-    return 0;
-}
-#endif