summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwlemb <wlemb>2001-03-09 00:18:20 +0000
committerwlemb <wlemb>2001-03-09 00:18:20 +0000
commitb0e4f58b4afa4e924818766dd78f3c8a804295c4 (patch)
tree5f6e48fb6b1f9d4a007054dbe262af14580e9b95
parent5c15ebdf9477000c401785690b95997713e8aec8 (diff)
downloadgroff-b0e4f58b4afa4e924818766dd78f3c8a804295c4.tar.gz
Added the `return' request to end a macro immediately. It simply
pops iterators from the input stack until a macro iterator is found. * src/roff/troff/input.cc (input_iterator::is_macro, macro_iterator::is_macro): New member. (input_return_boundary): New class to signal an immediate return to while_request(). (input_stack::add_return_boundary, input_stack::is_return_boundary): New functions. (input_stack::clear): Use it. (input_stack::pop_macro): New function. (while_request): Use `is_return_boundary()'. (return_macro_request): New function. (init_input_requests): Use it. * src/roff/troff/TODO: Updated. * NEWS, src/roff/troff/troff.man, man/groff.man: Document it. * src/roff/troff/input.cc (input_iterator::is_boundary): Minor cleanup.
-rw-r--r--ChangeLog25
-rw-r--r--NEWS4
-rw-r--r--man/groff.man3
-rw-r--r--src/roff/troff/TODO3
-rw-r--r--src/roff/troff/input.cc58
-rw-r--r--src/roff/troff/troff.man4
6 files changed, 85 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index c8ffe15e..e67e7a62 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2001-03-09 Werner LEMBERG <wl@gnu.org>
+
+ Added the `return' request to end a macro immediately. It simply
+ pops iterators from the input stack until a macro iterator is found.
+
+ * src/roff/troff/input.cc (input_iterator::is_macro,
+ macro_iterator::is_macro): New member.
+ (input_return_boundary): New class to signal an immediate return
+ to while_request().
+ (input_stack::add_return_boundary, input_stack::is_return_boundary):
+ New functions.
+ (input_stack::clear): Use it.
+ (input_stack::pop_macro): New function.
+ (while_request): Use `is_return_boundary()'.
+ (return_macro_request): New function.
+ (init_input_requests): Use it.
+
+ * src/roff/troff/TODO: Updated.
+ * NEWS, src/roff/troff/troff.man, man/groff.man: Document it.
+
+2001-03-08 Werner LEMBERG <wl@gnu.org>
+
+ * src/roff/troff/input.cc (input_iterator::is_boundary): Minor
+ cleanup.
+
2001-03-07 Werner LEMBERG <wl@gnu.org>
Make `\B' more rigid.
diff --git a/NEWS b/NEWS
index 61f02633..8f41b4f6 100644
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,8 @@ o A new command line option for the `man' macros (similar to the `mdoc'
produce one single, very long page instead of multiple pages. `-rcR=0'
will deactivate it.
+o The `return' request has been added to return immediately from a macro.
+
o A new request `nop' (no operation) has been added which is similar to
`if 1'. For example,
@@ -50,7 +52,7 @@ o The `asciify' request has been extended to `unformat' space characters
o The new `unformat' request is similar to `asciify' but only handles space
characters and tabs specially if the diversion is reread, retaining font
- information. This makes it possible to reformat diversions; for example
+ information. This makes it possible to reformat diversions; for example
the following
.ll 3i
diff --git a/man/groff.man b/man/groff.man
index 7b23cba4..0d7d3935 100644
--- a/man/groff.man
+++ b/man/groff.man
@@ -1500,6 +1500,9 @@ Remove the definitions of characters
.REQ .rd prompt
Read insertion.
.
+.REQ .return
+Return from a macro.
+.
.REQ .rj n
Right justify the next
.argument n
diff --git a/src/roff/troff/TODO b/src/roff/troff/TODO
index 79d84e29..66605973 100644
--- a/src/roff/troff/TODO
+++ b/src/roff/troff/TODO
@@ -132,6 +132,3 @@ More thorough range checking.
Provide syntax for octal and hexadecimal numeric constants. Perhaps
o#100 and x#7f as per Scheme. Or perhaps PostScript 16#7f. Ambiguity
between whether `c' is treated as digit or scaling indicator.
-
-Request to return from a macro (ie ignore the rest of the current
-input level).
diff --git a/src/roff/troff/input.cc b/src/roff/troff/input.cc
index acfaed24..bcbdb2a1 100644
--- a/src/roff/troff/input.cc
+++ b/src/roff/troff/input.cc
@@ -203,9 +203,10 @@ private:
{ return 0; }
virtual int next_file(FILE *, const char *) { return 0; }
virtual void shift(int) {}
- virtual int is_boundary();
+ virtual int is_boundary() { return 0; }
virtual int internal_level() { return 0; }
virtual int is_file() { return 0; }
+ virtual int is_macro() { return 0; }
};
input_iterator::input_iterator()
@@ -227,11 +228,6 @@ int input_iterator::peek()
return EOF;
}
-int input_iterator::is_boundary()
-{
- return 0;
-}
-
inline int input_iterator::get(node **p)
{
return ptr < eptr ? *ptr++ : fill(p);
@@ -242,6 +238,11 @@ public:
int is_boundary() { return 1; }
};
+class input_return_boundary : public input_iterator {
+public:
+ int is_boundary() { return 2; }
+};
+
class file_iterator : public input_iterator {
FILE *fp;
int lineno;
@@ -400,9 +401,12 @@ public:
static void end_file();
static void shift(int n);
static void add_boundary();
+ static void add_return_boundary();
+ static int is_return_boundary();
static void remove_boundary();
static int get_level();
static void clear();
+ static void pop_macro();
static int limit;
private:
@@ -475,6 +479,16 @@ void input_stack::add_boundary()
push(new input_boundary);
}
+void input_stack::add_return_boundary()
+{
+ push(new input_return_boundary);
+}
+
+int input_stack::is_return_boundary()
+{
+ return top->is_boundary() == 2;
+}
+
void input_stack::remove_boundary()
{
assert(top->is_boundary());
@@ -590,7 +604,27 @@ void input_stack::clear()
}
// Keep while_request happy.
for (; nboundaries > 0; --nboundaries)
- add_boundary();
+ add_return_boundary();
+}
+
+void input_stack::pop_macro()
+{
+ int nboundaries = 0;
+ int is_macro = 0;
+ do {
+ if (top->next == &nil_iterator)
+ break;
+ if (top->is_boundary())
+ nboundaries++;
+ is_macro = top->is_macro();
+ input_iterator *tem = top;
+ top = top->next;
+ level--;
+ delete tem;
+ } while (!is_macro);
+ // Keep while_request happy.
+ for (; nboundaries > 0; --nboundaries)
+ add_return_boundary();
}
void backtrace_request()
@@ -1988,6 +2022,12 @@ void exit_request()
exit_troff();
}
+void return_macro_request()
+{
+ input_stack::pop_macro();
+ tok.next();
+}
+
void end_macro()
{
end_macro_name = get_name();
@@ -2903,6 +2943,7 @@ public:
int nargs() { return argc; }
void add_arg(const macro &m);
void shift(int n);
+ int is_macro() { return 1; }
};
input_iterator *macro_iterator::get_arg(int i)
@@ -4589,7 +4630,7 @@ void while_request()
break;
}
process_input_stack();
- if (while_break_flag) {
+ if (while_break_flag || input_stack::is_return_boundary()) {
while_break_flag = 0;
break;
}
@@ -6301,6 +6342,7 @@ void init_input_requests()
init_request("tm1", terminal1);
init_request("tmc", terminal_continue);
init_request("ex", exit_request);
+ init_request("return", return_macro_request);
init_request("em", end_macro);
init_request("blm", blank_line_macro);
init_request("tr", translate);
diff --git a/src/roff/troff/troff.man b/src/roff/troff/troff.man
index 7b57ee08..5f54e42a 100644
--- a/src/roff/troff/troff.man
+++ b/src/roff/troff/troff.man
@@ -1317,6 +1317,10 @@ This undoes the effect of a
.B char
request.
.TP
+.B .return
+Within a macro, return immediately.
+No effect otherwise.
+.TP
.B .rj
.TQ
.BI .rj\ n