]> granicus.if.org Git - graphviz/commitdiff
common: inline and remove 'printdouble'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 20 Apr 2022 02:36:42 +0000 (19:36 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 23 Apr 2022 23:50:15 +0000 (16:50 -0700)
With the `Agiodisc_t` output function now taking a format string, this code can
be written more readably and concisely. This also avoids the need for
intermediate buffering.

lib/common/output.c

index d24e61168a21b638f387bce7a32d2394ab3dafe3..6260f5e5500b39868d07060af16791a94451f97c 100644 (file)
@@ -37,20 +37,9 @@ static void agputc (int c, FILE* fp)
   print(fp, "%c", (char)c);
 }
 
-
-static void printdouble(FILE * f, char *prefix, double v)
-{
-    char buf[BUFSIZ];
-    
-    if (prefix) agputs(prefix, f);
-    snprintf(buf, sizeof(buf), "%.5g", v);
-    agputs(buf, f);
-}
-
 static void printpoint(FILE * f, pointf p)
 {
-    printdouble(f, " ", PS2INCH(p.x));
-    printdouble(f, " ", PS2INCH(YDIR(p.y)));
+  print(f, " %.5g %.5g", PS2INCH(p.x), PS2INCH(YDIR(p.y)));
 }
 
 /* setYInvert:
@@ -106,9 +95,9 @@ void write_plain(GVJ_t *job, graph_t *g, FILE *f, bool extend) {
 //    setup_graph(job, g);
     setYInvert(g);
     pt = GD_bb(g).UR;
-    printdouble(f, "graph ", job->zoom);
-    printdouble(f, " ", PS2INCH(pt.x));
-    printdouble(f, " ", PS2INCH(pt.y));
+    print(f, "graph %.5g", job->zoom);
+    print(f, " %.5g", PS2INCH(pt.x));
+    print(f, " %.5g", PS2INCH(pt.y));
     agputc('\n', f);
     for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
        if (IS_CLUST_NODE(n))
@@ -119,8 +108,8 @@ void write_plain(GVJ_t *job, graph_t *g, FILE *f, bool extend) {
            lbl = agcanonStr (agxget(n, N_label));
        else
            lbl = canon(agraphof(n),ND_label(n)->text);
-        printdouble(f, " ", ND_width(n));
-        printdouble(f, " ", ND_height(n));
+        print(f, " %.5g", ND_width(n));
+        print(f, " %.5g", ND_height(n));
         print(f, " %s", lbl);
        print(f, " %s", late_nnstring(n, N_style, "solid"));
        print(f, " %s", ND_shape(n)->name);