1 /* $NetBSD: token.h,v 1.1.1.1 2016/01/13 18:41:48 christos Exp $ */
2
3 // -*- C++ -*-
4 /* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2004
5 Free Software Foundation, Inc.
6 Written by James Clark (jjc@jclark.com)
7
8 This file is part of groff.
9
10 groff is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
13 version.
14
15 groff is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 for more details.
19
20 You should have received a copy of the GNU General Public License along
21 with groff; see the file COPYING. If not, write to the Free Software
22 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
23
24
25 class charinfo;
26 struct node;
27 class vunits;
28
29 class token {
30 symbol nm;
31 node *nd;
32 unsigned char c;
33 int val;
34 units dim;
35 enum token_type {
36 TOKEN_BACKSPACE,
37 TOKEN_BEGIN_TRAP,
38 TOKEN_CHAR, // a normal printing character
39 TOKEN_DUMMY, // \&
40 TOKEN_EMPTY, // this is the initial value
41 TOKEN_END_TRAP,
42 TOKEN_ESCAPE, // \e
43 TOKEN_HYPHEN_INDICATOR,
44 TOKEN_INTERRUPT, // \c
45 TOKEN_ITALIC_CORRECTION, // \/
46 TOKEN_LEADER, // ^A
47 TOKEN_LEFT_BRACE,
48 TOKEN_MARK_INPUT, // \k -- `nm' is the name of the register
49 TOKEN_NEWLINE, // newline
50 TOKEN_NODE,
51 TOKEN_NUMBERED_CHAR,
52 TOKEN_PAGE_EJECTOR,
53 TOKEN_REQUEST,
54 TOKEN_RIGHT_BRACE,
55 TOKEN_SPACE, // ` ' -- ordinary space
56 TOKEN_SPECIAL, // a special character -- \' \` \- \(xx \[xxx]
57 TOKEN_SPREAD, // \p -- break and spread output line
58 TOKEN_STRETCHABLE_SPACE, // \~
59 TOKEN_UNSTRETCHABLE_SPACE, // `\ '
60 TOKEN_TAB, // tab
61 TOKEN_TRANSPARENT, // \!
62 TOKEN_TRANSPARENT_DUMMY, // \)
63 TOKEN_ZERO_WIDTH_BREAK, // \:
64 TOKEN_EOF // end of file
65 } type;
66 public:
67 token();
68 ~token();
69 token(const token &);
70 void operator=(const token &);
71 void next();
72 void process();
73 void skip();
74 int eof();
75 int nspaces(); // 1 if space, 2 if double space, 0 otherwise
76 int space(); // is the current token a space?
77 int stretchable_space(); // is the current token a stretchable space?
78 int unstretchable_space(); // is the current token an unstretchable space?
79 int white_space(); // is the current token space or tab?
80 int special(); // is the current token a special character?
81 int newline(); // is the current token a newline?
82 int tab(); // is the current token a tab?
83 int leader();
84 int backspace();
85 int delimiter(int warn = 0); // is it suitable for use as a delimiter?
86 int dummy();
87 int transparent_dummy();
88 int transparent();
89 int left_brace();
90 int right_brace();
91 int page_ejector();
92 int hyphen_indicator();
93 int zero_width_break();
94 int operator==(const token &); // need this for delimiters, and for conditions
95 int operator!=(const token &); // ditto
96 unsigned char ch();
97 charinfo *get_char(int required = 0);
98 int add_to_node_list(node **);
99 int title();
100 void make_space();
101 void make_newline();
102 const char *description();
103
104 friend void process_input_stack();
105 };
106
107 extern token tok; // the current token
108
109 extern symbol get_name(int required = 0);
110 extern symbol get_long_name(int required = 0);
111 extern charinfo *get_optional_char();
112 extern char *read_string();
113 extern void check_missing_character();
114 extern void skip_line();
115 extern void handle_initial_title();
116
117 enum char_mode {
118 CHAR_NORMAL,
119 CHAR_FALLBACK,
120 CHAR_FONT_SPECIAL,
121 CHAR_SPECIAL
122 };
123
124 extern void do_define_character(char_mode, const char * = 0);
125
126 class hunits;
127 extern void read_title_parts(node **part, hunits *part_width);
128
129 extern int get_number_rigidly(units *result, unsigned char si);
130
131 extern int get_number(units *result, unsigned char si);
132 extern int get_integer(int *result);
133
134 extern int get_number(units *result, unsigned char si, units prev_value);
135 extern int get_integer(int *result, int prev_value);
136
137 void interpolate_number_reg(symbol, int);
138
139 const char *asciify(int c);
140
newline()141 inline int token::newline()
142 {
143 return type == TOKEN_NEWLINE;
144 }
145
space()146 inline int token::space()
147 {
148 return type == TOKEN_SPACE;
149 }
150
stretchable_space()151 inline int token::stretchable_space()
152 {
153 return type == TOKEN_STRETCHABLE_SPACE;
154 }
155
unstretchable_space()156 inline int token::unstretchable_space()
157 {
158 return type == TOKEN_UNSTRETCHABLE_SPACE;
159 }
160
special()161 inline int token::special()
162 {
163 return type == TOKEN_SPECIAL;
164 }
165
nspaces()166 inline int token::nspaces()
167 {
168 if (type == TOKEN_SPACE)
169 return 1;
170 else
171 return 0;
172 }
173
white_space()174 inline int token::white_space()
175 {
176 return type == TOKEN_SPACE || type == TOKEN_TAB;
177 }
178
transparent()179 inline int token::transparent()
180 {
181 return type == TOKEN_TRANSPARENT;
182 }
183
page_ejector()184 inline int token::page_ejector()
185 {
186 return type == TOKEN_PAGE_EJECTOR;
187 }
188
ch()189 inline unsigned char token::ch()
190 {
191 return type == TOKEN_CHAR ? c : 0;
192 }
193
eof()194 inline int token::eof()
195 {
196 return type == TOKEN_EOF;
197 }
198
dummy()199 inline int token::dummy()
200 {
201 return type == TOKEN_DUMMY;
202 }
203
transparent_dummy()204 inline int token::transparent_dummy()
205 {
206 return type == TOKEN_TRANSPARENT_DUMMY;
207 }
208
left_brace()209 inline int token::left_brace()
210 {
211 return type == TOKEN_LEFT_BRACE;
212 }
213
right_brace()214 inline int token::right_brace()
215 {
216 return type == TOKEN_RIGHT_BRACE;
217 }
218
tab()219 inline int token::tab()
220 {
221 return type == TOKEN_TAB;
222 }
223
leader()224 inline int token::leader()
225 {
226 return type == TOKEN_LEADER;
227 }
228
backspace()229 inline int token::backspace()
230 {
231 return type == TOKEN_BACKSPACE;
232 }
233
hyphen_indicator()234 inline int token::hyphen_indicator()
235 {
236 return type == TOKEN_HYPHEN_INDICATOR;
237 }
238
zero_width_break()239 inline int token::zero_width_break()
240 {
241 return type == TOKEN_ZERO_WIDTH_BREAK;
242 }
243
244 int has_arg();
245