summaryrefslogtreecommitdiff
path: root/src/roff/troff
diff options
context:
space:
mode:
authorwl <wl>2009-02-14 17:21:35 +0000
committerwl <wl>2009-02-14 17:21:35 +0000
commit71ea99d4c8b847766e48883219b38aa3bca74367 (patch)
treeba6ca3699ca9c6ede2ff0d162b65e8cbff931eb4 /src/roff/troff
parent3e5365fb2c256a2d2273d970a54f434305e34371 (diff)
downloadgroff-71ea99d4c8b847766e48883219b38aa3bca74367.tar.gz
Implement a leading spaces macro request, `lsm', in analogy to
`blm'. Implement two new number registers, \n[lsn] and \n[lss], which hold the number of spaces and the horizontal space, respectively, which would be inserted if the macro registered by `lsm' wasn't called. * src/roff/troff/input.cpp (leading_spaces_macro_name, leading_spaces_number, leading_spaces_space): New global variables. (leading_spaces_macro): New function. (process_input_stack) <token::TOKEN_SPACE>: Handle `lsm'. (init_input_requests): Register `lsm', \n[lsn], and \n[lss]. * NEWS, man/groff_diff.man, man/groff.man, doc/groff.texinfo (Leading Spaces Traps): Document new requests and registers.
Diffstat (limited to 'src/roff/troff')
-rw-r--r--src/roff/troff/input.cpp32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 8038f70f..b3243f5a 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -101,6 +101,7 @@ static void disable_warning(const char *);
static int escape_char = '\\';
static symbol end_macro_name;
static symbol blank_line_macro_name;
+static symbol leading_spaces_macro_name;
static int compatible_flag = 0;
int ascii_output_flag = 0;
int suppress_output_flag = 0;
@@ -120,7 +121,7 @@ double spread_limit = -3.0 - 1.0; // negative means deactivated
double warn_scale;
char warn_scaling_indicator;
-int debug_state = 0; // turns on debugging of the html troff state
+int debug_state = 0; // turns on debugging of the html troff state
search_path *mac_path = &safer_macro_path;
@@ -2608,6 +2609,12 @@ void blank_line_macro()
skip_line();
}
+void leading_spaces_macro()
+{
+ leading_spaces_macro_name = get_name();
+ skip_line();
+}
+
static void trapping_blank_line()
{
if (!blank_line_macro_name.is_null())
@@ -2773,6 +2780,9 @@ int hmotion_node::reread(int *)
return 0;
}
+static int leading_spaces_number = 0;
+static int leading_spaces_space = 0;
+
void process_input_stack()
{
int_stack trap_bol_stack;
@@ -2853,11 +2863,12 @@ void process_input_stack()
do {
node *n;
cc = get_copy(&n);
- if (cc != EOF)
+ if (cc != EOF) {
if (cc != '\0')
curdiv->transparent_output(transparent_translate(cc));
else
curdiv->transparent_output(n);
+ }
} while (cc != '\n' && cc != EOF);
if (cc == EOF)
curdiv->transparent_output('\n');
@@ -2919,9 +2930,15 @@ void process_input_stack()
trapping_blank_line();
else {
push_token(tok);
- curenv->do_break();
- curenv->add_node(new hmotion_node(space_width * nspaces,
- curenv->get_fill_color()));
+ leading_spaces_number = nspaces;
+ leading_spaces_space = space_width.to_units() * nspaces;
+ if (!leading_spaces_macro_name.is_null())
+ spring_trap(leading_spaces_macro_name);
+ else {
+ curenv->do_break();
+ curenv->add_node(new hmotion_node(space_width * nspaces,
+ curenv->get_fill_color()));
+ }
bol = 0;
}
}
@@ -4080,7 +4097,7 @@ void spring_trap(symbol nm)
postponed_trap = nm;
return;
}
- static char buf[2] = { BEGIN_TRAP, 0 };
+ static char buf[2] = { BEGIN_TRAP, '\0' };
static char buf2[2] = { END_TRAP, '\0' };
input_stack::push(make_temp_iterator(buf2));
request_or_macro *p = lookup_request(nm);
@@ -7812,6 +7829,7 @@ void init_input_requests()
init_request("ig", ignore);
init_request("length", length_request);
init_request("lf", line_file);
+ init_request("lsm", leading_spaces_macro);
init_request("mso", macro_source);
init_request("nop", nop_request);
init_request("nroff", nroff_request);
@@ -7879,6 +7897,8 @@ void init_input_requests()
number_reg_dictionary.define("c.", new writable_lineno_reg);
number_reg_dictionary.define("llx", new variable_reg(&llx_reg_contents));
number_reg_dictionary.define("lly", new variable_reg(&lly_reg_contents));
+ number_reg_dictionary.define("lsn", new variable_reg(&leading_spaces_number));
+ number_reg_dictionary.define("lss", new variable_reg(&leading_spaces_space));
number_reg_dictionary.define("opmaxx",
new variable_reg(&output_reg_maxx_contents));
number_reg_dictionary.define("opmaxy",