summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-03-14 12:35:02 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-03-14 12:35:02 +0000
commitff2d2efac021b47be5131aeb11372e2fa6c73f0f (patch)
tree1f39ca4e4068ff7b4589e4259eb1997fb02e067f
parentf24d8846442dca61e961b029eb67ce69c086dc41 (diff)
downloadmandoc-ff2d2efac021b47be5131aeb11372e2fa6c73f0f.tar.gz
mandoc-ff2d2efac021b47be5131aeb11372e2fa6c73f0f.tar.zst
mandoc-ff2d2efac021b47be5131aeb11372e2fa6c73f0f.zip
Added colour styles (not being used) to struct termp.
Added nroff style-escape encoding. Removed ANSI schema string tables (there's only ANSI and nroff/backspace). Pushed styling directly into pword (simpler).
-rw-r--r--Makefile2
-rw-r--r--mdocterm.145
-rw-r--r--mdocterm.c152
-rw-r--r--term.c22
-rw-r--r--term.h39
5 files changed, 152 insertions, 108 deletions
diff --git a/Makefile b/Makefile
index dae5bf57..bbc0be5a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
.SUFFIXES: .html .sgml
-VERSION = 1.4.15
+VERSION = 1.4.16
VDATE = 14 March 2009
BINDIR = $(PREFIX)/bin
diff --git a/mdocterm.1 b/mdocterm.1
index 96ecd2d5..796fb8de 100644
--- a/mdocterm.1
+++ b/mdocterm.1
@@ -1,4 +1,4 @@
-.\" $Id: mdocterm.1,v 1.19 2009/03/13 07:46:10 kristaps Exp $
+.\" $Id: mdocterm.1,v 1.20 2009/03/14 12:35:02 kristaps Exp $
.\"
.\" Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
.\"
@@ -16,7 +16,7 @@
.\" TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
.\" PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: March 13 2009 $
+.Dd $Mdocdate: March 14 2009 $
.Dt mdocterm 1
.Os
.\" SECTION
@@ -28,6 +28,7 @@
.Nm mdocmterm
.Op Fl vV
.Op Fl f Ns Ar option...
+.Op Fl O Ns Ar option...
.Op Fl W Ns Ar err...
.Op Ar infile
.\" SECTION
@@ -50,6 +51,15 @@ Override default compiler behaviour. See
.Sx Compiler Options
for details.
.\" ITEM
+.It Fl O Ns Ar option...
+Terminal-encoding options. May be set to
+.Fl O Ns Ar ansi
+for ANSI/VT100-encoded output (the default) or
+.Fl O Ns Ar nroff
+for nroff-encoded
+.Qq backspace
+output.
+.\" ITEM
.It Fl W Ns Ar err...
Print warning messages. May be set to
.Fl W Ns Ar all
@@ -119,30 +129,11 @@ options may be grouped and delimited with a comma. Using
.Fl f Ns Ar ign-scope,ign-escape ,
for example, will try to ignore scope and character-escape errors.
.\" SUB-SECTION
-.Ss Input Encoding
-The
-.Nm
-utility expects its input to be 7-bit ASCII as defined in
-.Xr ascii 7 .
-The only non-graphing characters accepted are spaces,
-.Sq \ ,
-and tabs,
-.Sq \et .
-Tabs are only accepted in literal block-displays and as column
-delimiters.
-.Pp
-Only Unix-style newlines (\en) are accepted; if the newline is escaped,
-the line is concatenated with the next.
-.\" SUB-SECTION
.Ss Character Escapes
-This section documents the character-escapes accepted by
-.Xr mdocterm 1 .
-Note that the \\x, \\(xx and \\[n] forms are described here; the \\*(xx,
-\\*[n] and \\*x forms described in
-.Xr mdoc.samples 7
-are deprecated, but still rendered. All one- and two-character
-sequences may be used in the n-character sequence \\[n].
-.Pp
+The following table shows all
+.Xr mdoc 7
+character escapes rendered by
+.Nm .
Note that the
.Em Output
column will render differently whether executed with
@@ -266,7 +257,7 @@ Special symbols:
the more general syntax.
.\" SECTION
.Sh EXAMPLES
-To display this manual page:
+To display this manual page on ANSI-capable terminal:
.\" PARAGRAPH
.Pp
.D1 % mdocmterm \-Wall,error mdocmterm.1
@@ -274,7 +265,7 @@ To display this manual page:
.Pp
To pipe a manual page to the pager:
.Pp
-.D1 % mdocterm mdocterm.1 2>&1 | less \-R
+.D1 % mdocterm -Onroff mdocterm.1 | less
.\" SECTION
.Sh SEE ALSO
.Xr mdoctree 1 ,
diff --git a/mdocterm.c b/mdocterm.c
index 644bbe35..5308d449 100644
--- a/mdocterm.c
+++ b/mdocterm.c
@@ -1,4 +1,4 @@
-/* $Id: mdocterm.c,v 1.41 2009/03/14 05:36:07 kristaps Exp $ */
+/* $Id: mdocterm.c,v 1.42 2009/03/14 12:35:02 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -29,11 +29,12 @@
#include "mmain.h"
#include "term.h"
-struct termenc {
+struct termseq {
const char *enc;
int sym;
};
+static int option(void *, int, const char *);
static void body(struct termp *,
struct termpair *,
const struct mdoc_meta *,
@@ -53,14 +54,13 @@ static void stringa(struct termp *,
const char *, size_t);
static void symbola(struct termp *, enum tsym);
static void sanity(const struct mdoc_node *);
-static void stylea(struct termp *, enum tstyle);
#ifdef __linux__
extern size_t strlcat(char *, const char *, size_t);
extern size_t strlcpy(char *, const char *, size_t);
#endif
-static struct termenc termenc1[] = {
+static struct termseq termenc1[] = {
{ "\\", TERMSYM_SLASH },
{ "\'", TERMSYM_RSQUOTE },
{ "`", TERMSYM_LSQUOTE },
@@ -74,7 +74,7 @@ static struct termenc termenc1[] = {
{ NULL, 0 }
};
-static struct termenc termenc2[] = {
+static struct termseq termenc2[] = {
{ "rC", TERMSYM_RBRACE },
{ "lC", TERMSYM_LBRACE },
{ "rB", TERMSYM_RBRACK },
@@ -126,7 +126,7 @@ static struct termenc termenc2[] = {
{ NULL, 0 }
};
-static struct termsym termsym_ansi[TERMSYM_MAX] = {
+static struct termsym termsym_ascii[TERMSYM_MAX] = {
{ "]", 1 }, /* TERMSYM_RBRACK */
{ "[", 1 }, /* TERMSYM_LBRACK */
{ "<-", 2 }, /* TERMSYM_LARROW */
@@ -170,16 +170,6 @@ static struct termsym termsym_ansi[TERMSYM_MAX] = {
{ "}", 1 }, /* TERMSYM_RBRACE */
};
-static const char ansi_clear[] = { 27, '[', '0', 'm' };
-static const char ansi_bold[] = { 27, '[', '1', 'm' };
-static const char ansi_under[] = { 27, '[', '4', 'm' };
-
-static struct termsym termstyle_ansi[] = {
- { ansi_clear, 4 },
- { ansi_bold, 4 },
- { ansi_under, 4 }
-};
-
int
main(int argc, char *argv[])
@@ -189,22 +179,25 @@ main(int argc, char *argv[])
const struct mdoc *mdoc;
struct termp termp;
+ (void)memset(&termp, 0, sizeof(struct termp));
+
+ termp.maxrmargin = termp.rmargin = 78; /* XXX */
+ termp.maxcols = 1024;
+ termp.offset = termp.col = 0;
+ termp.flags = TERMP_NOSPACE;
+ termp.symtab = termsym_ascii;
+ termp.enc = TERMENC_ANSI;
+
p = mmain_alloc();
+ c = mmain_getopt(p, argc, argv, "[-Ooption...]",
+ "O:", &termp, option);
- c = mmain_getopt(p, argc, argv, NULL, NULL, NULL, NULL);
if (1 != c)
mmain_exit(p, -1 == c ? 1 : 0);
if (NULL == (mdoc = mmain_mdoc(p)))
mmain_exit(p, 1);
- termp.maxrmargin = termp.rmargin = 78; /* XXX */
- termp.maxcols = 1024;
- termp.offset = termp.col = 0;
- termp.flags = TERMP_NOSPACE;
- termp.symtab = termsym_ansi;
- termp.styletab = termstyle_ansi;
-
if (NULL == (termp.buf = malloc(termp.maxcols)))
err(1, "malloc");
@@ -219,6 +212,26 @@ main(int argc, char *argv[])
}
+int
+option(void *ptr, int c, const char *arg)
+{
+ struct termp *p;
+
+ p = (struct termp *)ptr;
+
+ if (0 == strcmp(arg, "nroff")) {
+ p->enc = TERMENC_NROFF;
+ return(1);
+ } else if (0 == strcmp(arg, "ansi")) {
+ p->enc = TERMENC_ANSI;
+ return(1);
+ }
+
+ warnx("unknown option: -O%s", arg);
+ return(0);
+}
+
+
/*
* Flush a line of text. A "line" is loosely defined as being something
* that should be followed by a newline, regardless of whether it's
@@ -288,15 +301,18 @@ flushln(struct termp *p)
* space is printed according to regular spacing rules).
*/
- /* FIXME: make non-ANSI friendly. */
-
/* LINTED */
for (j = i, vsz = 0; j < p->col; j++) {
- if (isspace((u_char)p->buf[j]))
+ if (isspace((u_char)p->buf[j])) {
break;
- else if (27 == p->buf[j]) {
- assert(j + 4 <= p->col);
- j += 3;
+ } else if (27 == p->buf[j]) {
+ assert(TERMENC_ANSI == p->enc);
+ assert(j + 5 <= p->col);
+ j += 4;
+ } else if (8 == p->buf[j]) {
+ assert(TERMENC_NROFF == p->enc);
+ assert(j + 2 <= p->col);
+ j += 1;
} else
vsz++;
}
@@ -656,7 +672,7 @@ header(struct termp *p, const struct mdoc_meta *meta)
static void
nescape(struct termp *p, const char *word, size_t len)
{
- struct termenc *enc;
+ struct termseq *enc;
switch (len) {
case (1):
@@ -763,26 +779,70 @@ pword(struct termp *p, const char *word, size_t len)
p->flags &= ~TERMP_NOSPACE;
/*
- * XXX - if literal and underlining, this will underline the
- * spaces between literal words.
+ * If ANSI (word-length styling), then apply our style now,
+ * before the word.
*/
- if (p->flags & TERMP_BOLD)
- stylea(p, TERMSTYLE_BOLD);
- if (p->flags & TERMP_UNDERLINE)
- stylea(p, TERMSTYLE_UNDER);
+ if (TERMENC_ANSI == p->enc && TERMP_STYLE & p->flags) {
+ if (TERMP_BOLD & p->flags) {
+ chara(p, 27);
+ stringa(p, "[01m", 4);
+ }
+ if (TERMP_UNDER & p->flags) {
+ chara(p, 27);
+ stringa(p, "[04m", 4);
+ }
+ if (TERMP_RED & p->flags) {
+ chara(p, 27);
+ stringa(p, "[31m", 4);
+ }
+ if (TERMP_GREEN & p->flags) {
+ chara(p, 27);
+ stringa(p, "[32m", 4);
+ }
+ if (TERMP_YELLOW & p->flags) {
+ chara(p, 27);
+ stringa(p, "[33m", 4);
+ }
+ if (TERMP_BLUE & p->flags) {
+ chara(p, 27);
+ stringa(p, "[34m", 4);
+ }
+ if (TERMP_MAGENTA & p->flags) {
+ chara(p, 27);
+ stringa(p, "[35m", 4);
+ }
+ if (TERMP_CYAN & p->flags) {
+ chara(p, 27);
+ stringa(p, "[36m", 4);
+ }
+ }
for (i = 0; i < len; i++) {
if ('\\' == word[i]) {
pescape(p, word, &i, len);
continue;
}
+
+ if (TERMENC_NROFF == p->enc &&
+ TERMP_STYLE & p->flags) {
+ if (TERMP_BOLD & p->flags) {
+ chara(p, word[i]);
+ chara(p, 8);
+ }
+ if (TERMP_UNDER & p->flags) {
+ chara(p, '_');
+ chara(p, 8);
+ }
+ }
+
chara(p, word[i]);
}
- if (p->flags & TERMP_BOLD ||
- p->flags & TERMP_UNDERLINE)
- stylea(p, TERMSTYLE_CLEAR);
+ if (TERMENC_ANSI == p->enc && TERMP_STYLE & p->flags) {
+ chara(p, 27);
+ stringa(p, "[00m", 4);
+ }
}
@@ -799,18 +859,6 @@ symbola(struct termp *p, enum tsym sym)
/*
- * Add a style to the output line buffer.
- */
-static void
-stylea(struct termp *p, enum tstyle style)
-{
-
- assert(p->styletab[style].sym);
- stringa(p, p->styletab[style].sym, p->styletab[style].sz);
-}
-
-
-/*
* Like chara() but for arbitrary-length buffers. Resize the buffer by
* a factor of two (if the buffer is less than that) or the buffer's
* size.
diff --git a/term.c b/term.c
index 4ba00b1b..06d4bc3f 100644
--- a/term.c
+++ b/term.c
@@ -1,4 +1,4 @@
-/* $Id: term.c,v 1.58 2009/03/13 07:46:10 kristaps Exp $ */
+/* $Id: term.c,v 1.59 2009/03/14 12:35:02 kristaps Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -67,28 +67,28 @@
/* TODO: abstract this into mdocterm.c. */
const int ttypes[TTYPE_NMAX] = {
- TERMP_BOLD, /* TTYPE_PROG */
+ TERMP_BOLD, /* TTYPE_PROG */
TERMP_BOLD, /* TTYPE_CMD_FLAG */
- TERMP_UNDERLINE, /* TTYPE_CMD_ARG */
+ TERMP_UNDER, /* TTYPE_CMD_ARG */
TERMP_BOLD, /* TTYPE_SECTION */
TERMP_BOLD, /* TTYPE_FUNC_DECL */
- TERMP_UNDERLINE, /* TTYPE_VAR_DECL */
- TERMP_UNDERLINE, /* TTYPE_FUNC_TYPE */
+ TERMP_UNDER, /* TTYPE_VAR_DECL */
+ TERMP_UNDER, /* TTYPE_FUNC_TYPE */
TERMP_BOLD, /* TTYPE_FUNC_NAME */
- TERMP_UNDERLINE, /* TTYPE_FUNC_ARG */
- TERMP_UNDERLINE, /* TTYPE_LINK */
+ TERMP_UNDER, /* TTYPE_FUNC_ARG */
+ TERMP_UNDER, /* TTYPE_LINK */
TERMP_BOLD, /* TTYPE_SSECTION */
- TERMP_UNDERLINE, /* TTYPE_FILE */
- TERMP_UNDERLINE, /* TTYPE_EMPH */
+ TERMP_UNDER, /* TTYPE_FILE */
+ TERMP_UNDER, /* TTYPE_EMPH */
TERMP_BOLD, /* TTYPE_CONFIG */
TERMP_BOLD, /* TTYPE_CMD */
TERMP_BOLD, /* TTYPE_INCLUDE */
TERMP_BOLD, /* TTYPE_SYMB */
TERMP_BOLD, /* TTYPE_SYMBOL */
TERMP_BOLD, /* TTYPE_DIAG */
- TERMP_UNDERLINE, /* TTYPE_LINK_ANCHOR */
+ TERMP_UNDER, /* TTYPE_LINK_ANCHOR */
TERMP_BOLD, /* TTYPE_LINK_TEXT */
- TERMP_UNDERLINE /* TTYPE_REF_TITLE */
+ TERMP_UNDER /* TTYPE_REF_TITLE */
};
static int arg_hasattr(int, const struct mdoc_node *);
diff --git a/term.h b/term.h
index 4e1c557a..db35ed70 100644
--- a/term.h
+++ b/term.h
@@ -1,4 +1,4 @@
-/* $Id: term.h,v 1.21 2009/03/14 05:36:07 kristaps Exp $ */
+/* $Id: term.h,v 1.22 2009/03/14 12:35:02 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -70,12 +70,9 @@ enum tsym {
TERMSYM_MAX = 41
};
-
-enum tstyle {
- TERMSTYLE_CLEAR = 0,
- TERMSTYLE_BOLD = 1,
- TERMSTYLE_UNDER = 2,
- TERMSTYLE_MAX = 3
+enum termenc {
+ TERMENC_ANSI,
+ TERMENC_NROFF
};
struct termsym {
@@ -90,18 +87,26 @@ struct termp {
size_t offset;
size_t col;
int flags;
-#define TERMP_BOLD (1 << 0) /* Embolden words. */
-#define TERMP_UNDERLINE (1 << 1) /* Underline words. */
-#define TERMP_NOSPACE (1 << 2) /* No space before words. */
-#define TERMP_NOLPAD (1 << 3) /* No leftpad before flush. */
-#define TERMP_NOBREAK (1 << 4) /* No break after flush. */
-#define TERMP_LITERAL (1 << 5) /* Literal words. */
-#define TERMP_IGNDELIM (1 << 6) /* Delims like regulars. */
-#define TERMP_NONOSPACE (1 << 7) /* No space (no autounset). */
-#define TERMP_NONOBREAK (1 << 8)
+#define TERMP_NOSPACE (1 << 0) /* No space before words. */
+#define TERMP_NOLPAD (1 << 1) /* No leftpad before flush. */
+#define TERMP_NOBREAK (1 << 2) /* No break after flush. */
+#define TERMP_LITERAL (1 << 3) /* Literal words. */
+#define TERMP_IGNDELIM (1 << 4) /* Delims like regulars. */
+#define TERMP_NONOSPACE (1 << 5) /* No space (no autounset). */
+#define TERMP_NONOBREAK (1 << 7) /* Don't newln NOBREAK. */
+
+#define TERMP_STYLE 0xff00 /* Style mask. */
+#define TERMP_BOLD (1 << 8) /* Styles... */
+#define TERMP_UNDER (1 << 9)
+#define TERMP_BLUE (1 << 10)
+#define TERMP_RED (1 << 11)
+#define TERMP_YELLOW (1 << 12)
+#define TERMP_MAGENTA (1 << 13)
+#define TERMP_CYAN (1 << 14)
+#define TERMP_GREEN (1 << 15)
char *buf;
struct termsym *symtab; /* Special-symbol table. */
- struct termsym *styletab; /* Style table. */
+ enum termenc enc; /* Encoding. */
};
struct termpair {