ref: 8a095062fb0581494c9ded643663bebeb898de7c
parent: f709b9219a3029d875e7e48040757d6008c67184
author: Ali Gholami Rudi <ali@rudi.ir>
date: Sat Aug 30 18:38:39 EDT 2014
reg: \n(.D is the directory containing current file Also \*(.P, which used to point to macros directory, is removed.
--- a/reg.c
+++ b/reg.c
@@ -50,6 +50,19 @@
return &nregs[id];
}
+static char *directory(char *path)
+{
+ static char dst[PATHLEN];
+ char *s = strrchr(path, '/');
+ if (!s)
+ return ".";
+ if (path == s)
+ return "/";
+ memcpy(dst, path, s - path);
+ dst[s - path] = '\0';
+ return dst;
+}
+
static int num_fmt(char *s, int n, int fmt);
/* the contents of a number register (returns a static buffer) */
@@ -84,6 +97,9 @@
return numbuf;
case 'F':
sprintf(numbuf, "%s", in_filename());
+ return numbuf;
+ case 'D':
+ sprintf(numbuf, "%s", directory(in_filename()));
return numbuf;
case '$':
sprintf(numbuf, "%d", in_nargs());
--- a/roff.c
+++ b/roff.c
@@ -98,7 +98,6 @@
in_queue(NULL); /* reading from standard input */
for (; i < argc; i++)
in_queue(!strcmp("-", argv[i]) ? NULL : argv[i]);
- str_set(map(".P"), macrodir);
out("s%d\n", n_s);
out("f%d\n", n_f);
ret = render();