summaryrefslogtreecommitdiff
path: root/src/roff/troff
diff options
context:
space:
mode:
Diffstat (limited to 'src/roff/troff')
-rw-r--r--src/roff/troff/TODO6
-rw-r--r--src/roff/troff/env.cc5
-rw-r--r--src/roff/troff/env.h2
-rw-r--r--src/roff/troff/input.cc41
-rw-r--r--src/roff/troff/node.cc10
-rw-r--r--src/roff/troff/node.h2
-rw-r--r--src/roff/troff/token.h11
-rw-r--r--src/roff/troff/troff.man87
8 files changed, 128 insertions, 36 deletions
diff --git a/src/roff/troff/TODO b/src/roff/troff/TODO
index 6fd50ff3..79d84e29 100644
--- a/src/roff/troff/TODO
+++ b/src/roff/troff/TODO
@@ -24,7 +24,7 @@ decision of where to break the line.
Provide a mechanism to control the shape of the rag in non-justified
text.
-Add a discretionary break escape sequence. \B'...'...'...' like TeX.
+Add a discretionary break escape sequence. \='...'...'...' like TeX.
Think about kerning between characters and spaces. (Need to implement
get_breakpoints and split methods for kern_pair_node class.)
@@ -40,8 +40,6 @@ and has a non-zero hyphen-type. Then we ought to be able to hyphenate,
but we won't be able to because we will look for the hyphen only in
font S and not in font R.
-Variant of tm which doesn't write a newline.
-
Perhaps the current input level should be accessible in a number register.
Should \w deal with a newline like \X?
@@ -124,8 +122,6 @@ decrement when it's at the same input level as the request.
Don't ever change a charinfo. Create new variants instead and chain
them together.
-Make it possible to tr characters onto \~.
-
Unix troff appears to read the first character of a request name in
copy mode. Should we do the same?
diff --git a/src/roff/troff/env.cc b/src/roff/troff/env.cc
index 378cfffd..b65742d3 100644
--- a/src/roff/troff/env.cc
+++ b/src/roff/troff/env.cc
@@ -260,6 +260,7 @@ void leader_character()
void environment::add_char(charinfo *ci)
{
+ int s;
if (interrupted)
;
// don't allow fields in dummy environments
@@ -275,7 +276,7 @@ void environment::add_char(charinfo *ci)
if (tab_contents == 0)
tab_contents = new line_start_node;
if (ci != hyphen_indicator_char)
- tab_contents = tab_contents->add_char(ci, this, &tab_width);
+ tab_contents = tab_contents->add_char(ci, this, &tab_width, &s);
else
tab_contents = tab_contents->add_discretionary_hyphen();
}
@@ -283,7 +284,7 @@ void environment::add_char(charinfo *ci)
if (line == 0)
start_line();
if (ci != hyphen_indicator_char)
- line = line->add_char(ci, this, &width_total);
+ line = line->add_char(ci, this, &width_total, &space_total);
else
line = line->add_discretionary_hyphen();
}
diff --git a/src/roff/troff/env.h b/src/roff/troff/env.h
index 6792ea63..74f23cae 100644
--- a/src/roff/troff/env.h
+++ b/src/roff/troff/env.h
@@ -189,7 +189,6 @@ class environment {
#ifdef WIDOW_CONTROL
void mark_last_line();
#endif /* WIDOW_CONTROL */
- void possibly_break_line(int forced = 0);
breakpoint *choose_breakpoint();
void hyphenate_line();
void start_field();
@@ -268,6 +267,7 @@ public:
void set_input_line_position(hunits); // used by \n(hp
void interrupt();
void spread() { spread_flag = 1; }
+ void possibly_break_line(int forced = 0);
void do_break(); // .br
void final_break();
void add_html_tag (const char *name);
diff --git a/src/roff/troff/input.cc b/src/roff/troff/input.cc
index c0661913..f11b5a98 100644
--- a/src/roff/troff/input.cc
+++ b/src/roff/troff/input.cc
@@ -172,6 +172,7 @@ const int VJUSTIFY_REQUEST = 0203;
const int ESCAPE_E = 0204;
const int LAST_PAGE_EJECTOR = 0205;
const int ESCAPE_RIGHT_PARENTHESIS = 0206;
+const int ESCAPE_TILDE = 0207;
#else /* IS_EBCDIC_HOST */
@@ -204,6 +205,7 @@ const int VJUSTIFY_REQUEST = 063;
const int ESCAPE_E = 064;
const int LAST_PAGE_EJECTOR = 065;
const int ESCAPE_RIGHT_PARENTHESIS = 066;
+const int ESCAPE_TILDE = 067;
#endif /* IS_EBCDIC_HOST */
@@ -909,6 +911,9 @@ static int get_copy(node **nd, int defining)
case ' ':
(void)input_stack::get(NULL);
return ESCAPE_SPACE;
+ case '~':
+ (void)input_stack::get(NULL);
+ return ESCAPE_TILDE;
case '|':
(void)input_stack::get(NULL);
return ESCAPE_BAR;
@@ -1315,6 +1320,11 @@ void token::next()
type = TOKEN_NODE;
nd = new space_char_hmotion_node(curenv->get_space_width());
return;
+ case ESCAPE_TILDE:
+ ESCAPE_TILDE:
+ type = TOKEN_STRETCHABLE_SPACE;
+ nd = new unbreakable_space_node(curenv->get_space_width());
+ return;
case ESCAPE_e:
ESCAPE_e:
type = TOKEN_ESCAPE;
@@ -1469,9 +1479,7 @@ void token::next()
case '?':
goto ESCAPE_QUESTION;
case '~':
- nd = new unbreakable_space_node(curenv->get_space_width());
- type = TOKEN_NODE;
- return;
+ goto ESCAPE_TILDE;
case '"':
while ((cc = input_stack::get(NULL)) != '\n' && cc != EOF)
;
@@ -1786,6 +1794,7 @@ int token::delimiter(int err)
}
case TOKEN_NODE:
case TOKEN_SPACE:
+ case TOKEN_STRETCHABLE_SPACE:
case TOKEN_TAB:
case TOKEN_NEWLINE:
if (err)
@@ -1834,6 +1843,8 @@ const char *token::description()
return "`\\}'";
case TOKEN_SPACE:
return "a space";
+ case TOKEN_STRETCHABLE_SPACE:
+ return "`\\~'";
case TOKEN_SPECIAL:
return "a special character";
case TOKEN_SPREAD:
@@ -2059,6 +2070,8 @@ static int transparent_translate(int cc)
switch (ci->get_special_translation(1)) {
case charinfo::TRANSLATE_SPACE:
return ' ';
+ case charinfo::TRANSLATE_STRETCHABLE_SPACE:
+ return ESCAPE_TILDE;
case charinfo::TRANSLATE_DUMMY:
return ESCAPE_AMPERSAND;
case charinfo::TRANSLATE_HYPHEN_INDICATOR:
@@ -2281,6 +2294,7 @@ void process_input_stack()
case token::TOKEN_EOF:
return;
case token::TOKEN_NODE:
+ case token::TOKEN_STRETCHABLE_SPACE:
{
if (possibly_handle_first_page_transition())
;
@@ -2292,6 +2306,7 @@ void process_input_stack()
curenv->add_node(tok.nd);
tok.nd = 0;
bol = 0;
+ curenv->possibly_break_line();
}
break;
}
@@ -4798,6 +4813,9 @@ const char *asciify(int c)
case ESCAPE_SPACE:
buf[1] = ' ';
break;
+ case ESCAPE_TILDE:
+ buf[1] = '~';
+ break;
default:
if (illegal_input_char(c))
buf[0] = '\0';
@@ -5036,8 +5054,7 @@ static void init_charset_table()
page_character = charset_table['%'];
}
-static
-void do_translate(int translate_transparent)
+static void do_translate(int translate_transparent)
{
tok.skip();
while (!tok.newline() && !tok.eof()) {
@@ -5062,6 +5079,9 @@ void do_translate(int translate_transparent)
if (tok.space())
ci1->set_special_translation(charinfo::TRANSLATE_SPACE,
translate_transparent);
+ else if (tok.stretchable_space())
+ ci1->set_special_translation(charinfo::TRANSLATE_STRETCHABLE_SPACE,
+ translate_transparent);
else if (tok.dummy())
ci1->set_special_translation(charinfo::TRANSLATE_DUMMY,
translate_transparent);
@@ -5182,17 +5202,18 @@ void check_missing_character()
int token::add_to_node_list(node **pp)
{
hunits w;
+ int s;
node *n = 0;
switch (type) {
case TOKEN_CHAR:
- *pp = (*pp)->add_char(charset_table[c], curenv, &w);
+ *pp = (*pp)->add_char(charset_table[c], curenv, &w, &s);
break;
case TOKEN_DUMMY:
n = new dummy_node;
break;
case TOKEN_ESCAPE:
if (escape_char != 0)
- *pp = (*pp)->add_char(charset_table[escape_char], curenv, &w);
+ *pp = (*pp)->add_char(charset_table[escape_char], curenv, &w, &s);
break;
case TOKEN_HYPHEN_INDICATOR:
*pp = (*pp)->add_discretionary_hyphen();
@@ -5206,11 +5227,12 @@ int token::add_to_node_list(node **pp)
set_number_reg(nm, curenv->get_input_line_position().to_units());
break;
case TOKEN_NODE:
+ case TOKEN_STRETCHABLE_SPACE:
n = nd;
nd = 0;
break;
case TOKEN_NUMBERED_CHAR:
- *pp = (*pp)->add_char(get_charinfo_by_number(val), curenv, &w);
+ *pp = (*pp)->add_char(get_charinfo_by_number(val), curenv, &w, &s);
break;
case TOKEN_RIGHT_BRACE:
break;
@@ -5218,7 +5240,7 @@ int token::add_to_node_list(node **pp)
n = new hmotion_node(curenv->get_space_width());
break;
case TOKEN_SPECIAL:
- *pp = (*pp)->add_char(get_charinfo(nm), curenv, &w);
+ *pp = (*pp)->add_char(get_charinfo(nm), curenv, &w, &s);
break;
default:
return 0;
@@ -5280,6 +5302,7 @@ void token::process()
curenv->newline();
break;
case TOKEN_NODE:
+ case TOKEN_STRETCHABLE_SPACE:
curenv->add_node(nd);
nd = 0;
break;
diff --git a/src/roff/troff/node.cc b/src/roff/troff/node.cc
index f5585512..580785ab 100644
--- a/src/roff/troff/node.cc
+++ b/src/roff/troff/node.cc
@@ -3877,6 +3877,8 @@ node *make_node(charinfo *ci, environment *env)
switch (ci->get_special_translation()) {
case charinfo::TRANSLATE_SPACE:
return new space_char_hmotion_node(env->get_space_width());
+ case charinfo::TRANSLATE_STRETCHABLE_SPACE:
+ return new unbreakable_space_node(env->get_space_width());
case charinfo::TRANSLATE_DUMMY:
return new dummy_node;
case charinfo::TRANSLATE_HYPHEN_INDICATOR:
@@ -3910,7 +3912,8 @@ int character_exists(charinfo *ci, environment *env)
return 0;
}
-node *node::add_char(charinfo *ci, environment *env, hunits *widthp)
+node *node::add_char(charinfo *ci, environment *env,
+ hunits *widthp, int *spacep)
{
node *res;
switch (ci->get_special_translation()) {
@@ -3918,6 +3921,11 @@ node *node::add_char(charinfo *ci, environment *env, hunits *widthp)
res = new space_char_hmotion_node(env->get_space_width(), this);
*widthp += res->width();
return res;
+ case charinfo::TRANSLATE_STRETCHABLE_SPACE:
+ res = new unbreakable_space_node(env->get_space_width(), this);
+ *widthp += res->width();
+ *spacep += res->nspaces();
+ return res;
case charinfo::TRANSLATE_DUMMY:
return new dummy_node(this);
case charinfo::TRANSLATE_HYPHEN_INDICATOR:
diff --git a/src/roff/troff/node.h b/src/roff/troff/node.h
index 6a602dc3..9dc05308 100644
--- a/src/roff/troff/node.h
+++ b/src/roff/troff/node.h
@@ -52,7 +52,7 @@ struct node {
node *last;
node();
node(node *n);
- node *add_char(charinfo *c, environment *, hunits *widthp);
+ node *add_char(charinfo *c, environment *, hunits *widthp, int *spacep);
virtual ~node();
virtual node *copy() = 0;
diff --git a/src/roff/troff/token.h b/src/roff/troff/token.h
index f6707f2a..0bcb72c7 100644
--- a/src/roff/troff/token.h
+++ b/src/roff/troff/token.h
@@ -1,5 +1,5 @@
// -*- C++ -*-
-/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
+/* Copyright (C) 1989, 1990, 1991, 1992, 2000 Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
This file is part of groff.
@@ -50,6 +50,7 @@ class token {
TOKEN_REQUEST,
TOKEN_RIGHT_BRACE,
TOKEN_SPACE, // ` ' -- ordinary space
+ TOKEN_STRETCHABLE_SPACE, // \~
TOKEN_SPECIAL, // a special character -- \' \` \- \(xx
TOKEN_SPREAD, // \p -- break and spread output line
TOKEN_TAB, // tab
@@ -66,7 +67,8 @@ public:
void skip();
int eof();
int nspaces(); // 1 if space, 2 if double space, 0 otherwise
- int space(); // is it a space or double space?
+ int space(); // is the current token a space?
+ int stretchable_space(); // is the current token a stretchable space?
int white_space(); // is the current token space or tab?
int special(); // is the current token a special character?
int newline(); // is the current token a newline?
@@ -125,6 +127,11 @@ inline int token::space()
return type == TOKEN_SPACE;
}
+inline int token::stretchable_space()
+{
+ return type == TOKEN_STRETCHABLE_SPACE;
+}
+
inline int token::special()
{
return type == TOKEN_SPECIAL;
diff --git a/src/roff/troff/troff.man b/src/roff/troff/troff.man
index d266317b..6a20049b 100644
--- a/src/roff/troff/troff.man
+++ b/src/roff/troff/troff.man
@@ -34,9 +34,17 @@ the original English.
.\" so use \(ts instead of ".
.tr \(ts"
.TH @G@TROFF @MAN1EXT@ "@MDATE@" "Groff Version @VERSION@"
+.
+.
.SH NAME
+.
+.
@g@troff \- format documents
+.
+.
.SH SYNOPSIS
+.
+.
.nr a \n(.j
.ad l
.nr i \n(.i
@@ -65,15 +73,23 @@ the original English.
.PP
It is possible to have whitespace between a command line option and its
parameter.
+.
+.
.SH DESCRIPTION
+.
+.
This manual page describes the GNU version of
.BR troff ,
which is part of the groff document formatting system.
-It is highly compatible with Unix troff.
+It is highly compatible with UNIX troff.
Usually it should be invoked using the groff command, which will
also run preprocessors and postprocessors in the appropriate
order and with the appropriate options.
+.
+.
.SH OPTIONS
+.
+.
.TP \w'\-dname=s'u+2n
.B \-a
Generate an
@@ -236,9 +252,15 @@ Search directory (or directory path)
.I dir
for macro files.
This is scanned before all other macro directories.
+.
+.
.SH USAGE
-Only the features not in Unix troff are described here.
+.
+.
+Only the features not in UNIX troff are described here.
+.
.SS Long names
+.
The names of number registers, fonts, strings/macros/diversions,
special characters can be of any length. In escape sequences, where
you can use
@@ -262,7 +284,9 @@ Interpolate string
.BI \en[ xxx ]
Interpolate number register
.IR xxx .
+.
.SS Fractional pointsizes
+.
A
.I
scaled point
@@ -345,7 +369,9 @@ Be sure not to confuse the
and
.B z
scale indicators.
+.
.SS Numeric expressions
+.
.LP
Spaces are permitted in a number expression within parentheses.
.LP
@@ -374,7 +400,9 @@ If
.I c
is missing, ignore scaling indicators in the evaluation of
.IR e .
+.
.SS New escape sequences
+.
.TP
.BI \eA' anything '
This expands to
@@ -528,7 +556,7 @@ to have been defined as a macro and thus contain newlines
(it is not permitted for the argument to
.B \eX
to contain newlines).
-The inclusion of newlines requires an extension to the Unix troff output
+The inclusion of newlines requires an extension to the UNIX troff output
format, and will confuse drivers that do not know about this
extension.
.TP
@@ -559,7 +587,7 @@ In a macro, this gives the
or
.IR nnn -th
argument.
-Macros can have a unlimited number of arguments.
+Macros can have an unlimited number of arguments.
.TP
.BI \e? anything \e?
When used in a diversion, this will transparently embed
@@ -659,7 +687,9 @@ This is like
except that
.B \e"
does not ignore the terminating newline.
+.
.SS New requests
+.
.TP
.BI .aln\ xx\ yy
Create an alias
@@ -1422,7 +1452,7 @@ transparently throughput into a diversion with
.BR \e! .
For example,
.RS
-.LP
+.IP
.nf
.ft B
\&.tr ab
@@ -1521,14 +1551,16 @@ is read in copy mode;
a leading
.B \(ts
will be stripped.
+.
.SS Extended requests
+.
.TP
.BI .cf\ filename
When used in a diversion, this will embed in the diversion an object which,
when reread, will cause the contents of
.I filename
to be transparently copied through to the output.
-In Unix troff, the
+In UNIX troff, the
contents of
.I filename
is immediately copied through to the output regardless of whether
@@ -1574,11 +1606,11 @@ if the end of a sentence occurs at the end of a line in fill mode, then
both an inter-word space and a sentence space will be added;
if two spaces follow the end of a sentence in the middle of a line,
then the second space will be a sentence space.
-Note that the behaviour of Unix troff will be exactly
+Note that the behaviour of UNIX troff will be exactly
that exhibited by GNU troff if a second argument is never given to the
.B ss
request.
-In GNU troff, as in Unix troff, you should always
+In GNU troff, as in UNIX troff, you should always
follow a sentence with either a newline or two spaces.
.TP
.BI .ta\ n1\ n2\|.\|.\|.nn \ T\ r1\ r2\|.\|.\|.\|rn
@@ -1603,7 +1635,9 @@ For example,
.LP
will set tabs every half an inch.
.RE
+.
.SS New number registers
+.
The following read-only registers are available:
.TP
.B \en[.C]
@@ -1840,7 +1874,9 @@ Note that the traditional
number register
.B \en(yr
is the current year minus 1900.
+.
.SS Miscellaneous
+.
.B @g@troff
predefines a single (read/write) string-based register,
.BR \e*(.T ,
@@ -1857,7 +1893,7 @@ which is defined to be\ 1 if
is called with the
.B -T
command line option, and zero otherwise. This behaviour is different to
-Unix troff.
+UNIX troff.
.LP
Fonts not listed in the
.SM DESC
@@ -1947,7 +1983,14 @@ the condition will also be true if
has been defined by the
.B char
request.
+.LP
+The
+.B tr
+request can now map characters onto
+.BR \e~ .
+.
.SS Warnings
+.
The warnings that can be given by
.B troff
are divided into the following categories.
@@ -2073,10 +2116,12 @@ that are useful with traditional macro packages.
.TP
.B w
All warnings.
+.
.SS Incompatibilities
+.
.LP
Long names cause some incompatibilities.
-Unix troff will interpret
+UNIX troff will interpret
.IP
.B
\&.dsabcd
@@ -2087,7 +2132,7 @@ with contents
.BR cd .
Normally, GNU troff will interpret this as a call of a macro named
.BR dsabcd .
-Also Unix troff will interpret
+Also UNIX troff will interpret
.B \e*[
or
.B \en[
@@ -2112,14 +2157,14 @@ GNU troff
does not allow the use of the escape sequences
.BR \\e\e|\e^\e&\e}\e{\e (space) \e'\e`\e-\e_\e!\e%\ec
in names of strings, macros, diversions, number registers,
-fonts or environments; Unix troff does.
+fonts or environments; UNIX troff does.
The
.B \eA
escape sequence may be helpful in avoiding use of these
escape sequences in names.
.LP
Fractional pointsizes cause one noteworthy incompatibility.
-In Unix troff the
+In UNIX troff the
.B ps
request ignores scale indicators and so
.IP
@@ -2173,7 +2218,7 @@ is turned into one output
and the resulting output
.BR \e s
are not interpreted as escape characters when they are reread.
-Unix troff would interpret them as escape characters
+UNIX troff would interpret them as escape characters
when they were reread and would end up printing one
.BR \e .
The correct way to obtain a printable
@@ -2182,7 +2227,7 @@ is to use the
.B \ee
escape sequence: this will always print a single instance of the
current escape character, regardless of whether or not it is used in a
-diversion; it will also work in both GNU troff and Unix troff.
+diversion; it will also work in both GNU troff and UNIX troff.
If you wish for some reason to store in a diversion an escape
sequence that will be interpreted when the diversion is reread,
you can either use the traditional
@@ -2190,7 +2235,11 @@ you can either use the traditional
transparent output facility, or, if this is unsuitable, the new
.B \e?
escape sequence.
+.
+.
.SH ENVIRONMENT
+.
+.
.TP
.SM
.B GROFF_TMAC_PATH
@@ -2222,7 +2271,11 @@ will scan directories given in the
option before these, and in standard directories
.RB ( @FONTPATH@ )
after these.
+.
+.
.SH FILES
+.
+.
.Tp \w'@FONTDIR@/devname/DESC'u+3n
.B @MACRODIR@/troffrc
Initialization file (called before any other macro package).
@@ -2259,7 +2312,11 @@ command line option or the
.B GROFF_MACRO_PATH
environment variable to add these directories to the search path if
necessary.
+.
+.
.SH "SEE ALSO"
+.
+.
.BR groff (@MAN1EXT@),
.BR @g@tbl (@MAN1EXT@),
.BR @g@pic (@MAN1EXT@),