groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Groff] Reliably identifying a running Roff processor


From: John Gardner
Subject: [Groff] Reliably identifying a running Roff processor
Date: Fri, 8 Sep 2017 00:42:53 +1000

The other week, I had an itch to write a Roff snippet to report the name of
a running Troff implementation. While this is *not* meant for serious use,
it *does* work well to distinguish mandoc(1), groff(1) and Heirloom:


.\" Identify the formatter processing the document.
.\" The program's name is stored in the `T?` string.
.if !\n(T? \{
. nf
. nr A \n(.d
\v'2m'
. nr B \n(.d
\v'-2m'
. ie '\nA'\nB' .ds T? mandoc
. el \{
. ie 0<>1 .ds T? heirloom
. el \{
. nr A 1
. do if \n[A]=1 .ds T? groff
. \}
. \}
. rr A
. rr B
. if 'T?'' .ds T? unknown
.\}
\fBInterpreter\fP: \*(T?

*Output:*

$ mandoc which.roff

Interpreter: mandoc


> $ groff -Tutf8 which.roff

Interpreter: groff


> $ /usr/local/ucb/nroff which.roff

Interpreter: heirloom



$ /usr/local/ucb/nroff -x0 which.roff

Interpreter:


That last example demonstrates how it's of no use when running Heirloom
with extensions disabled. I haven't tested with older versions of each
interpreter, either, but I doubt the results should differ. So far, it's
already been more helpful than Groff's \n[.g] register (which we know other
modern implementations will spoof).

Feedback is warmly welcomed! I'm sure the output can be cleaned up too,
there're excess newlines everywhere... :\

- John

Attachment: which.roff
Description: Troff document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]