Initial import from FreeBSD RELENG_4:
[dragonfly.git] / contrib / groff / src / roff / troff / div.h
1 // -*- C++ -*-
2 /* Copyright (C) 1989, 1990, 1991, 1992, 2001 Free Software Foundation, Inc.
3      Written by James Clark (jjc@jclark.com)
4
5 This file is part of groff.
6
7 groff is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 groff is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License along
18 with groff; see the file COPYING.  If not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 class diversion {
22   friend void do_divert(int append, int boxing);
23   friend void end_diversions();
24   diversion *prev;
25   node *saved_line;
26   hunits saved_width_total;
27   int saved_space_total;
28   hunits saved_saved_indent;
29   hunits saved_target_text_length;
30   int saved_prev_line_interrupted;
31 protected:
32   symbol nm;
33   vunits vertical_position;
34   vunits high_water_mark;
35 public:
36   int no_space_mode;
37   vunits marked_place;
38   diversion(symbol s = NULL_SYMBOL);
39   virtual ~diversion();
40   virtual void output(node *nd, int retain_size, vunits vs, vunits post_vs,
41                       hunits width) = 0;
42   virtual void transparent_output(unsigned char) = 0;
43   virtual void transparent_output(node *) = 0;
44   virtual void space(vunits distance, int forced = 0) = 0;
45 #ifdef COLUMN
46   virtual void vjustify(symbol) = 0;
47 #endif /* COLUMN */
48   vunits get_vertical_position() { return vertical_position; }
49   vunits get_high_water_mark() { return high_water_mark; }
50   virtual vunits distance_to_next_trap() = 0;
51   void need(vunits);
52   const char *get_diversion_name() { return nm.contents(); }
53   virtual void set_diversion_trap(symbol, vunits) = 0;
54   virtual void clear_diversion_trap() = 0;
55   virtual void copy_file(const char *filename) = 0;
56 };
57
58 class macro;
59
60 class macro_diversion : public diversion {
61   macro *mac;
62   hunits max_width;
63   symbol diversion_trap;
64   vunits diversion_trap_pos;
65 public:
66   macro_diversion(symbol, int);
67   ~macro_diversion();
68   void output(node *nd, int retain_size, vunits vs, vunits post_vs,
69               hunits width);
70   void transparent_output(unsigned char);
71   void transparent_output(node *);
72   void space(vunits distance, int forced = 0);
73 #ifdef COLUMN
74   void vjustify(symbol);
75 #endif /* COLUMN */
76   vunits distance_to_next_trap();
77   void set_diversion_trap(symbol, vunits);
78   void clear_diversion_trap();
79   void copy_file(const char *filename);
80 };
81
82 struct trap {
83   trap *next;
84   vunits position;
85   symbol nm;
86   trap(symbol, vunits, trap *);
87 };
88
89 struct output_file;
90
91 class top_level_diversion : public diversion {
92   int page_number;
93   int page_count;
94   int last_page_count;
95   vunits page_length;
96   hunits prev_page_offset;
97   hunits page_offset;
98   trap *page_trap_list;
99   trap *find_next_trap(vunits *);
100   int have_next_page_number;
101   int next_page_number;
102   int ejecting_page;            // Is the current page being ejected?
103 public:
104   int before_first_page;
105   top_level_diversion();
106   void output(node *nd, int retain_size, vunits vs, vunits post_vs,
107               hunits width);
108   void transparent_output(unsigned char);
109   void transparent_output(node *);
110   void space(vunits distance, int forced = 0);
111 #ifdef COLUMN
112   void vjustify(symbol);
113 #endif /* COLUMN */
114   hunits get_page_offset() { return page_offset; }
115   vunits get_page_length() { return page_length; }
116   vunits distance_to_next_trap();
117   void add_trap(symbol nm, vunits pos);
118   void change_trap(symbol nm, vunits pos);
119   void remove_trap(symbol);
120   void remove_trap_at(vunits pos);
121   void print_traps();
122   int get_page_count() { return page_count; }
123   int get_page_number() { return page_number; }
124   int get_next_page_number();
125   void set_page_number(int n) { page_number = n; }
126   int begin_page();
127   void set_next_page_number(int);
128   void set_page_length(vunits);
129   void copy_file(const char *filename);
130   int get_ejecting() { return ejecting_page; }
131   void set_ejecting() { ejecting_page = 1; }
132   friend void page_offset();
133   void set_diversion_trap(symbol, vunits);
134   void clear_diversion_trap();
135   void set_last_page() { last_page_count = page_count; }
136 };
137
138 extern top_level_diversion *topdiv;
139 extern diversion *curdiv;
140
141 extern int exit_started;
142 extern int done_end_macro;
143 extern int last_page_number;
144 extern int seen_last_page_ejector;
145
146 void spring_trap(symbol);       // implemented by input.c
147 extern int trap_sprung_flag;
148 void postpone_traps();
149 int unpostpone_traps();
150
151 void push_page_ejector();
152 void continue_page_eject();
153 void handle_first_page_transition();
154 void blank_line();
155 void begin_page();
156 void end_diversions();
157
158 extern void cleanup_and_exit(int);