Improve compatibility groff's soelim

While here implement -C from GNU groff

Reported by:	delphij
This commit is contained in:
Baptiste Daroussin 2015-05-01 23:54:09 +00:00
parent 6f32f49c02
commit b4a0618c44
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=282330
2 changed files with 29 additions and 10 deletions

View File

@ -48,9 +48,9 @@ it replace the line by processing
Otherwise the line is printed to stdout. Otherwise the line is printed to stdout.
.Bl -tag -width "-I dir" .Bl -tag -width "-I dir"
.It Fl C .It Fl C
Compatibility with GNU groff's Recognise
.Xr soelim 1 .Em .so
(does nothing). when not followed by a space character.
.It Fl r .It Fl r
Compatibility with GNU groff's Compatibility with GNU groff's
.Xr soelim 1 .Xr soelim 1

View File

@ -39,6 +39,8 @@ __FBSDID("$FreeBSD$");
#include <err.h> #include <err.h>
#include <ctype.h> #include <ctype.h>
#define C_OPTION 0x1
static StringList *includes; static StringList *includes;
static void static void
@ -81,10 +83,10 @@ soelim_fopen(const char *name)
} }
static int static int
soelim_file(FILE *f) soelim_file(FILE *f, int flag)
{ {
char *line = NULL; char *line = NULL;
char *walk; char *walk, *cp;
size_t linecap = 0; size_t linecap = 0;
ssize_t linelen; ssize_t linelen;
@ -96,13 +98,27 @@ soelim_file(FILE *f)
printf("%s", line); printf("%s", line);
continue; continue;
} }
walk = line + 3; walk = line + 3;
if (!isspace(*walk) && ((flag & C_OPTION) == 0)) {
printf("%s", line);
continue;
}
while (isspace(*walk)) while (isspace(*walk))
walk++; walk++;
while (isspace(walk[strlen(walk) - 1])) cp = walk + strlen(walk) - 1;
walk[strlen(walk) - 1] = '\0'; while (cp > walk && isspace(*cp)) {
if (soelim_file(soelim_fopen(walk)) == 1) { *cp = 0;
cp--;
}
if (*walk == '\0') {
printf("%s", line);
continue;
}
if (soelim_file(soelim_fopen(walk), flag) == 1) {
free(line); free(line);
return (1); return (1);
} }
@ -119,6 +135,7 @@ main(int argc, char **argv)
{ {
int ch, i; int ch, i;
int ret = 0; int ret = 0;
int flags = 0;
includes = sl_init(); includes = sl_init();
if (includes == NULL) if (includes == NULL)
@ -127,6 +144,8 @@ main(int argc, char **argv)
while ((ch = getopt(argc, argv, "CrtvI:")) != -1) { while ((ch = getopt(argc, argv, "CrtvI:")) != -1) {
switch (ch) { switch (ch) {
case 'C': case 'C':
flags |= C_OPTION;
break;
case 'r': case 'r':
case 'v': case 'v':
case 't': case 't':
@ -145,10 +164,10 @@ main(int argc, char **argv)
argv += optind; argv += optind;
if (argc == 0) if (argc == 0)
ret = soelim_file(stdin); ret = soelim_file(stdin, flags);
for (i = 0; i < argc; i++) 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); sl_free(includes, 0);