]> granicus.if.org Git - graphviz/commitdiff
Add basename function to graphviz
authorerg <devnull@localhost>
Thu, 20 Jan 2005 23:36:34 +0000 (23:36 +0000)
committererg <devnull@localhost>
Thu, 20 Jan 2005 23:36:34 +0000 (23:36 +0000)
lib/common/input.c

index 453bdb2a20f44877eded73c3fab938d56274dbaf..131181f4f8c114b2748f21856d0d1cb9c7d855a3 100644 (file)
@@ -15,7 +15,6 @@
 **********************************************************/
 
 #include       <ctype.h>
-#include       <libgen.h>
 
 #include       "render.h"
 #include       "htmltable.h"
@@ -121,6 +120,26 @@ static char *getFlagOpt(int argc, char **argv, int *idx)
     return 0;
 }
 
+/* basename:
+ * Partial implementation of real basename.
+ * Skip over any trailing slashes or backslashes; then
+ * find next (back)slash moving left; return string to the right.
+ * If no next slash is found, return the whole string.
+ */
+static char* basename (char* path)
+{
+    char* s = path;
+    if (*s == '\0') return path; /* empty string */
+    while (*s) s++; s--;
+    /* skip over trailing slashes, nulling out as we go */
+    while ((s > path) && ((*s == '/') || (*s == '\\')))
+       *s-- = '\0';
+    if (s == path) return path;
+    while ((s > path) && ((*s != '/') && (*s != '\\'))) s--;
+    if ((*s == '/') || (*s == '\\')) return (s+1);
+    else return path;
+}
+
 void dotneato_initialize(GVC_t * gvc, int argc, char **argv)
 {
     char *rest, c, *val;