Adapt src/troff (src/roff/troff)
[s-roff.git] / src / troff / div.h
blobe19fee892630c00b2996221e01a7a5612f8891ae
1 /*@
2 * Copyright (c) 2014 Steffen (Daode) Nurpmeso <sdaoden@users.sf.net>.
4 * Copyright (C) 1989 - 1992, 2001, 2002, 2004, 2005
5 * Free Software Foundation, Inc.
6 * Written by James Clark (jjc@jclark.com)
8 * groff is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2, or (at your option) any later
11 * version.
13 * groff is distributed in the hope that it will be useful, but WITHOUT ANY
14 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with groff; see the file COPYING. If not, write to the Free Software
20 * Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA.
22 #ifndef _DIV_H
23 #define _DIV_H
25 #include "config.h"
26 #include "troff-config.h"
28 void do_divert(int append, int boxing);
29 void end_diversions();
30 void page_offset();
32 class diversion
34 friend void do_divert(int append, int boxing);
35 friend void end_diversions();
37 diversion *prev;
38 node *saved_line;
39 hunits saved_width_total;
40 int saved_space_total;
41 hunits saved_saved_indent;
42 hunits saved_target_text_length;
43 int saved_prev_line_interrupted;
45 protected:
46 symbol nm;
47 vunits vertical_position;
48 vunits high_water_mark;
50 public:
51 int any_chars_added;
52 int no_space_mode;
53 int needs_push;
54 int saved_seen_break;
55 int saved_seen_space;
56 int saved_seen_eol;
57 int saved_suppress_next_eol;
58 state_set modified_tag;
59 vunits marked_place;
61 diversion(symbol s = NULL_SYMBOL);
62 virtual ~diversion();
63 virtual void output(node *nd, int retain_size, vunits vs, vunits post_vs,
64 hunits width) = 0;
65 virtual void transparent_output(unsigned char) = 0;
66 virtual void transparent_output(node *) = 0;
67 virtual void space(vunits distance, int forced = 0) = 0;
68 #ifdef COLUMN
69 virtual void vjustify(symbol) = 0;
70 #endif /* COLUMN */
71 vunits get_vertical_position() { return vertical_position; }
72 vunits get_high_water_mark() { return high_water_mark; }
73 virtual vunits distance_to_next_trap() = 0;
74 void need(vunits);
75 const char *get_diversion_name() { return nm.contents(); }
76 virtual void set_diversion_trap(symbol, vunits) = 0;
77 virtual void clear_diversion_trap() = 0;
78 virtual void copy_file(const char *filename) = 0;
79 virtual int is_diversion() = 0;
82 class macro;
84 class macro_diversion
85 : public diversion
87 macro *mac;
88 hunits max_width;
89 symbol diversion_trap;
90 vunits diversion_trap_pos;
92 public:
93 macro_diversion(symbol, int);
94 ~macro_diversion();
95 void output(node *nd, int retain_size, vunits vs, vunits post_vs,
96 hunits width);
97 void transparent_output(unsigned char);
98 void transparent_output(node *);
99 void space(vunits distance, int forced = 0);
100 #ifdef COLUMN
101 void vjustify(symbol);
102 #endif
103 vunits distance_to_next_trap();
104 void set_diversion_trap(symbol, vunits);
105 void clear_diversion_trap();
106 void copy_file(const char *filename);
107 int is_diversion() { return 1; }
110 class trap
112 public:
113 trap *next;
114 vunits position;
115 symbol nm;
117 trap(symbol, vunits, trap *);
120 class output_file;
122 class top_level_diversion
123 : public diversion
125 int page_number;
126 int page_count;
127 int last_page_count;
128 vunits page_length;
129 hunits prev_page_offset;
130 hunits page_offset;
131 trap *page_trap_list;
132 int have_next_page_number;
133 int next_page_number;
134 int ejecting_page; // Is the current page being ejected?
136 trap *find_next_trap(vunits *);
138 public:
139 int before_first_page;
140 top_level_diversion();
142 void output(node *nd, int retain_size, vunits vs, vunits post_vs,
143 hunits width);
144 void transparent_output(unsigned char);
145 void transparent_output(node *);
146 void space(vunits distance, int forced = 0);
147 #ifdef COLUMN
148 void vjustify(symbol);
149 #endif /* COLUMN */
150 hunits get_page_offset() { return page_offset; }
151 vunits get_page_length() { return page_length; }
152 vunits distance_to_next_trap();
153 void add_trap(symbol nm, vunits pos);
154 void change_trap(symbol nm, vunits pos);
155 void remove_trap(symbol);
156 void remove_trap_at(vunits pos);
157 void print_traps();
158 int get_page_count() { return page_count; }
159 int get_page_number() { return page_number; }
160 int get_next_page_number();
161 void set_page_number(int n) { page_number = n; }
162 int begin_page(vunits = V0);
163 void set_next_page_number(int);
164 void set_page_length(vunits);
165 void copy_file(const char *filename);
166 int get_ejecting() { return ejecting_page; }
167 void set_ejecting() { ejecting_page = 1; }
168 friend void page_offset();
169 void set_diversion_trap(symbol, vunits);
170 void clear_diversion_trap();
171 void set_last_page() { last_page_count = page_count; }
172 int is_diversion() { return 0; }
175 extern top_level_diversion *topdiv;
176 extern diversion *curdiv;
178 extern int exit_started;
179 extern int done_end_macro;
180 extern int last_page_number;
181 extern int seen_last_page_ejector;
183 void spring_trap(symbol); // implemented by input.c
184 extern int trap_sprung_flag;
185 void postpone_traps();
186 int unpostpone_traps();
188 void push_page_ejector();
189 void continue_page_eject();
190 void handle_first_page_transition();
191 void blank_line();
192 void begin_page();
194 extern void cleanup_and_exit(int);
196 #endif // _DIV_H
197 // s-it2-mode