diff options
author | bapt <bapt@FreeBSD.org> | 2015-05-01 23:54:09 +0000 |
---|---|---|
committer | bapt <bapt@FreeBSD.org> | 2015-05-01 23:54:09 +0000 |
commit | aeb0d2a45d79b0b3df20c20610021ce84ece4a3e (patch) | |
tree | a2a37edde27fec7cb2958544f4a5cdafb1a1f0e4 /usr.bin/soelim | |
parent | ffdc60a5eab3ccd8c50433db90fadab8d3568cd8 (diff) | |
download | FreeBSD-src-aeb0d2a45d79b0b3df20c20610021ce84ece4a3e.zip FreeBSD-src-aeb0d2a45d79b0b3df20c20610021ce84ece4a3e.tar.gz |
Improve compatibility groff's soelim
While here implement -C from GNU groff
Reported by: delphij
Diffstat (limited to 'usr.bin/soelim')
-rw-r--r-- | usr.bin/soelim/soelim.1 | 6 | ||||
-rw-r--r-- | usr.bin/soelim/soelim.c | 33 |
2 files changed, 29 insertions, 10 deletions
diff --git a/usr.bin/soelim/soelim.1 b/usr.bin/soelim/soelim.1 index af6e7f7..b6ec13c 100644 --- a/usr.bin/soelim/soelim.1 +++ b/usr.bin/soelim/soelim.1 @@ -48,9 +48,9 @@ it replace the line by processing Otherwise the line is printed to stdout. .Bl -tag -width "-I dir" .It Fl C -Compatibility with GNU groff's -.Xr soelim 1 -(does nothing). +Recognise +.Em .so +when not followed by a space character. .It Fl r Compatibility with GNU groff's .Xr soelim 1 diff --git a/usr.bin/soelim/soelim.c b/usr.bin/soelim/soelim.c index 26f85d6..700ae57 100644 --- a/usr.bin/soelim/soelim.c +++ b/usr.bin/soelim/soelim.c @@ -39,6 +39,8 @@ __FBSDID("$FreeBSD$"); #include <err.h> #include <ctype.h> +#define C_OPTION 0x1 + static StringList *includes; static void @@ -81,10 +83,10 @@ soelim_fopen(const char *name) } static int -soelim_file(FILE *f) +soelim_file(FILE *f, int flag) { char *line = NULL; - char *walk; + char *walk, *cp; size_t linecap = 0; ssize_t linelen; @@ -96,13 +98,27 @@ soelim_file(FILE *f) printf("%s", line); continue; } + walk = line + 3; + if (!isspace(*walk) && ((flag & C_OPTION) == 0)) { + printf("%s", line); + continue; + } + while (isspace(*walk)) walk++; - while (isspace(walk[strlen(walk) - 1])) - walk[strlen(walk) - 1] = '\0'; - if (soelim_file(soelim_fopen(walk)) == 1) { + cp = walk + strlen(walk) - 1; + while (cp > walk && isspace(*cp)) { + *cp = 0; + cp--; + } + + if (*walk == '\0') { + printf("%s", line); + continue; + } + if (soelim_file(soelim_fopen(walk), flag) == 1) { free(line); return (1); } @@ -119,6 +135,7 @@ main(int argc, char **argv) { int ch, i; int ret = 0; + int flags = 0; includes = sl_init(); if (includes == NULL) @@ -127,6 +144,8 @@ main(int argc, char **argv) while ((ch = getopt(argc, argv, "CrtvI:")) != -1) { switch (ch) { case 'C': + flags |= C_OPTION; + break; case 'r': case 'v': case 't': @@ -145,10 +164,10 @@ main(int argc, char **argv) argv += optind; if (argc == 0) - ret = soelim_file(stdin); + ret = soelim_file(stdin, flags); for (i = 0; i < argc; i++) - ret = soelim_file(soelim_fopen(argv[i])); + ret = soelim_file(soelim_fopen(argv[i]), flags); sl_free(includes, 0); |