]> granicus.if.org Git - graphviz/commitdiff
some input-filter hook code, disabled
authorellson <devnull@localhost>
Thu, 25 May 2006 15:02:28 +0000 (15:02 +0000)
committerellson <devnull@localhost>
Thu, 25 May 2006 15:02:28 +0000 (15:02 +0000)
lib/common/input.c

index 8d35d789c8d2da24719aac8fbb229e447d1af91e..0ddfe016fac2759170cf9d04ec785052be4b11b8 100644 (file)
@@ -359,6 +359,57 @@ void getdouble(graph_t * g, char *name, double *result)
     }
 }
 
+#ifdef EXPERIMENTAL_MYFGETS
+/*
+ * Potential input filter - e.g. for iconv 
+ */
+
+/*
+ * myfgets - same api as fgets
+ * 
+ * gets n chars at a time
+ *
+ * returns pointer to user buffer,
+ * or returns NULL on eof or error.
+ */
+static char *myfgets(char * ubuf, int n, FILE * fp)
+{
+    static char *buf;
+    static int bufsz, pos, len;
+    int cnt;
+
+    if (!n) {                   /* a call with n==0 (from aglexinit) resets */
+        ubuf[0] = '\0';
+        pos = len = 0;
+        return NULL;
+    }
+
+    if (!len) {
+       if (n > bufsz) {
+           bufsz = n;
+           buf = realloc(buf, bufsz);
+       }
+       if (!(fgets(buf, bufsz, fp))) {
+            ubuf[0] = '\0';
+            return NULL;
+        }
+       len = strlen(buf);
+       pos = 0;
+    }
+
+    cnt = n - 1;
+    if (len < cnt)
+       cnt = len;
+
+    memcpy(ubuf, buf + pos, cnt);
+    pos += cnt;
+    len -= cnt;
+    ubuf[cnt] = '\0';
+
+    return ubuf;
+}
+#endif
+
 graph_t *gvNextInputGraph(GVC_t *gvc)
 {
     graph_t *g = NULL;
@@ -383,7 +434,12 @@ graph_t *gvNextInputGraph(GVC_t *gvc)
        if (fp == NULL)
            break;
        agsetfile(fn ? fn : "<stdin>");
-       if ((g = agread(fp))) {
+#ifdef EXPERIMENTAL_MYFGETS
+       g = agread_usergets(fp, myfgets);
+#else
+       g = agread(fp);
+#endif
+       if (g) {
            gvg = zmalloc(sizeof(GVG_t));
            if (!gvc->gvgs) 
                gvc->gvgs = gvg;
@@ -401,6 +457,7 @@ graph_t *gvNextInputGraph(GVC_t *gvc)
     }
     return g;
 }
+
 /* findCharset:
  * Check if the charset attribute is defined for the graph and, if
  * so, return the corresponding internal value. If undefined, return