Imported Upstream version 1.22.4
[platform/upstream/groff.git] / src / roff / troff / div.h
1 // -*- C++ -*-
2 /* Copyright (C) 1989-2018 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 3 of the License, or
10 (at your option) any later 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
18 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
19
20 void do_divert(int append, int boxing);
21 void end_diversions();
22 void page_offset();
23
24 class diversion {
25   friend void do_divert(int append, int boxing);
26   friend void end_diversions();
27   diversion *prev;
28   node *saved_line;
29   hunits saved_width_total;
30   int saved_space_total;
31   hunits saved_saved_indent;
32   hunits saved_target_text_length;
33   int saved_prev_line_interrupted;
34 protected:
35   symbol nm;
36   vunits vertical_position;
37   vunits high_water_mark;
38 public:
39   int any_chars_added;
40   int no_space_mode;
41   int needs_push;
42   int saved_seen_break;
43   int saved_seen_space;
44   int saved_seen_eol;
45   int saved_suppress_next_eol;
46   state_set modified_tag;
47   vunits marked_place;
48   diversion(symbol s = NULL_SYMBOL);
49   virtual ~diversion();
50   virtual void output(node *nd, int retain_size, vunits vs, vunits post_vs,
51                       hunits width) = 0;
52   virtual void transparent_output(unsigned char) = 0;
53   virtual void transparent_output(node *) = 0;
54   virtual void space(vunits distance, int forced = 0) = 0;
55 #ifdef COLUMN
56   virtual void vjustify(symbol) = 0;
57 #endif /* COLUMN */
58   vunits get_vertical_position() { return vertical_position; }
59   vunits get_high_water_mark() { return high_water_mark; }
60   virtual vunits distance_to_next_trap() = 0;
61   void need(vunits);
62   const char *get_diversion_name() { return nm.contents(); }
63   virtual void set_diversion_trap(symbol, vunits) = 0;
64   virtual void clear_diversion_trap() = 0;
65   virtual void copy_file(const char *filename) = 0;
66   virtual int is_diversion() = 0;
67 };
68
69 class macro;
70
71 class macro_diversion : public diversion {
72   macro *mac;
73   hunits max_width;
74   symbol diversion_trap;
75   vunits diversion_trap_pos;
76 public:
77   macro_diversion(symbol, int);
78   ~macro_diversion();
79   void output(node *nd, int retain_size, vunits vs, vunits post_vs,
80               hunits width);
81   void transparent_output(unsigned char);
82   void transparent_output(node *);
83   void space(vunits distance, int forced = 0);
84 #ifdef COLUMN
85   void vjustify(symbol);
86 #endif /* COLUMN */
87   vunits distance_to_next_trap();
88   void set_diversion_trap(symbol, vunits);
89   void clear_diversion_trap();
90   void copy_file(const char *filename);
91   int is_diversion() { return 1; }
92 };
93
94 struct trap {
95   trap *next;
96   vunits position;
97   symbol nm;
98   trap(symbol, vunits, trap *);
99 };
100
101 class output_file;
102
103 class top_level_diversion : public diversion {
104   int page_number;
105   int page_count;
106   int last_page_count;
107   vunits page_length;
108   hunits prev_page_offset;
109   hunits page_offset;
110   trap *page_trap_list;
111   trap *find_next_trap(vunits *);
112   int have_next_page_number;
113   int next_page_number;
114   int ejecting_page;            // Is the current page being ejected?
115 public:
116   int before_first_page;
117   top_level_diversion();
118   void output(node *nd, int retain_size, vunits vs, vunits post_vs,
119               hunits width);
120   void transparent_output(unsigned char);
121   void transparent_output(node *);
122   void space(vunits distance, int forced = 0);
123 #ifdef COLUMN
124   void vjustify(symbol);
125 #endif /* COLUMN */
126   hunits get_page_offset() { return page_offset; }
127   vunits get_page_length() { return page_length; }
128   vunits distance_to_next_trap();
129   void add_trap(symbol nm, vunits pos);
130   void change_trap(symbol nm, vunits pos);
131   void remove_trap(symbol);
132   void remove_trap_at(vunits pos);
133   void print_traps();
134   int get_page_count() { return page_count; }
135   int get_page_number() { return page_number; }
136   int get_next_page_number();
137   void set_page_number(int n) { page_number = n; }
138   int begin_page(vunits = V0);
139   void set_next_page_number(int);
140   void set_page_length(vunits);
141   void copy_file(const char *filename);
142   int get_ejecting() { return ejecting_page; }
143   void set_ejecting() { ejecting_page = 1; }
144   friend void page_offset();
145   void set_diversion_trap(symbol, vunits);
146   void clear_diversion_trap();
147   void set_last_page() { last_page_count = page_count; }
148   int is_diversion() { return 0; }
149 };
150
151 extern top_level_diversion *topdiv;
152 extern diversion *curdiv;
153
154 extern int exit_started;
155 extern int done_end_macro;
156 extern int last_page_number;
157 extern int seen_last_page_ejector;
158
159 void spring_trap(symbol);       // implemented by input.c
160 extern int trap_sprung_flag;
161 void postpone_traps();
162 int unpostpone_traps();
163
164 void push_page_ejector();
165 void continue_page_eject();
166 void handle_first_page_transition();
167 void blank_line();
168 void begin_page();
169
170 extern void cleanup_and_exit(int);