summaryrefslogtreecommitdiffstats
path: root/src/roff/troff/input.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/roff/troff/input.cpp')
-rw-r--r--src/roff/troff/input.cpp70
1 files changed, 36 insertions, 34 deletions
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index a2bb11d4e..d3d700c0c 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -5571,14 +5571,19 @@ static node *do_non_interpreted()
return new non_interpreted_node(mac);
}
+// In troff output, we translate the escape character to '\', but it is
+// up to the postprocessor to interpret it as such. (This mostly
+// matters for device control commands.)
static void encode_char_for_troff_output(macro *mac, const char c)
{
+ bool is_char_valid = true;
+ const char *sc = 0 /* nullptr */;
if ('\0' == c) {
- if (tok.is_stretchable_space()
- || tok.is_unstretchable_space())
+ if (tok.is_space()
+ || tok.is_stretchable_space()
+ || tok.is_unstretchable_space())
mac->append(' ');
else if (tok.is_special()) {
- const char *sc;
if (font::use_charnames_in_special) {
charinfo *ci = tok.get_char(true /* required */);
sc = ci->get_symbol()->contents();
@@ -5612,29 +5617,32 @@ static void encode_char_for_troff_output(macro *mac, const char c)
mac->append(']');
}
else
- error("special character '%1' cannot be used within a"
- " device control escape sequence", sc);
+ is_char_valid = false;
}
else
- error("special character '%1' cannot be used within a device"
- " control escape sequence", sc);
+ is_char_valid = false;
}
}
else if (!(tok.is_hyphen_indicator()
|| tok.is_dummy()
|| tok.is_transparent_dummy()
|| tok.is_zero_width_break()))
- error("%1 is invalid within device control escape sequence",
- tok.description());
+ is_char_valid = false;
+ if (!is_char_valid) {
+ if (sc != 0 /* nullptr */)
+ error("special character '%1' is invalid within a device"
+ " control command", sc);
+ else
+ error("%1 is invalid within a device control command",
+ tok.description());
+ }
}
else {
- if ((font::use_charnames_in_special) && ('\\' == c)) {
- /*
- * add escape escape sequence
- */
- mac->append(c);
+ if (c == escape_char) {
+ mac->append('\\');
}
- mac->append(c);
+ else
+ mac->append(c);
}
}
@@ -5678,34 +5686,28 @@ static node *do_special()
static void device_request()
{
- // We can't use `has_arg()` here because we want to read in copy mode.
- int c;
- for (;;) {
- c = input_stack::peek();
- if (' ' == c)
- (void) get_copy(0 /* nullptr */);
- else
- break;
+ if (!has_arg()) {
+ warning(WARN_MISSING, "device request expects arguments");
+ skip_line();
+ return;
}
- if (('\n' == c) || (EOF == c)) {
- warning(WARN_MISSING, "device control request expects arguments");
+ if (tok.is_newline() || tok.is_eof()) {
+ warning(WARN_MISSING, "device request expects arguments");
skip_line();
return;
}
+ if ('"' == tok.ch()) {
+ tok.next();
+ }
macro mac;
for (;;) {
- c = get_copy(0 /* nullptr */);
- if ('"' == c) {
- c = get_copy(0 /* nullptr */);
- break;
- }
- if (c != ' ' && c != '\t')
+ if (tok.is_newline() || tok.is_eof())
break;
+ encode_char_for_troff_output(&mac, tok.ch());
+ tok.next();
}
- for (; c != '\n' && c != EOF; c = get_copy(0 /* nullptr */))
- mac.append(c);
curenv->add_node(new special_node(mac));
- tok.next();
+ skip_line();
}
static void device_macro_request()