Initial import from FreeBSD RELENG_4:
[dragonfly.git] / contrib / groff / src / roff / troff / token.h
1 // -*- C++ -*-
2 /* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002
3    Free Software Foundation, Inc.
4      Written by James Clark (jjc@jclark.com)
5
6 This file is part of groff.
7
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.
12
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.
17
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21
22
23 struct charinfo;
24 struct node;
25 struct vunits;
26
27 class token {
28   symbol nm;
29   node *nd;
30   unsigned char c;
31   int val;
32   units dim;
33   enum token_type {
34     TOKEN_BACKSPACE,
35     TOKEN_BEGIN_TRAP,
36     TOKEN_CHAR,                 // a normal printing character
37     TOKEN_DUMMY,                // \&
38     TOKEN_EMPTY,                // this is the initial value
39     TOKEN_END_TRAP,
40     TOKEN_ESCAPE,               // \e
41     TOKEN_HYPHEN_INDICATOR,
42     TOKEN_INTERRUPT,            // \c
43     TOKEN_ITALIC_CORRECTION,    // \/
44     TOKEN_LEADER,               // ^A
45     TOKEN_LEFT_BRACE,
46     TOKEN_MARK_INPUT,           // \k -- `nm' is the name of the register
47     TOKEN_NEWLINE,              // newline
48     TOKEN_NODE,
49     TOKEN_NUMBERED_CHAR,
50     TOKEN_PAGE_EJECTOR,
51     TOKEN_REQUEST,
52     TOKEN_RIGHT_BRACE,
53     TOKEN_SPACE,                // ` ' -- ordinary space
54     TOKEN_SPECIAL,              // a special character -- \' \` \- \(xx \[xxx]
55     TOKEN_SPREAD,               // \p -- break and spread output line 
56     TOKEN_STRETCHABLE_SPACE,    // \~
57     TOKEN_UNSTRETCHABLE_SPACE,  // `\ '
58     TOKEN_TAB,                  // tab
59     TOKEN_TRANSPARENT,          // \!
60     TOKEN_TRANSPARENT_DUMMY,    // \)
61     TOKEN_ZERO_WIDTH_BREAK,     // \:
62     TOKEN_EOF                   // end of file
63   } type;
64 public:
65   token();
66   ~token();
67   token(const token &);
68   void operator=(const token &);
69   void next();
70   void process();
71   void skip();
72   int eof();
73   int nspaces();                // 1 if space, 2 if double space, 0 otherwise
74   int space();                  // is the current token a space?
75   int stretchable_space();      // is the current token a stretchable space?
76   int unstretchable_space();    // is the current token an unstretchable space?
77   int white_space();            // is the current token space or tab?
78   int special();                // is the current token a special character?
79   int newline();                // is the current token a newline?
80   int tab();                    // is the current token a tab?
81   int leader();
82   int backspace();
83   int delimiter(int warn = 0);  // is it suitable for use as a delimiter?
84   int dummy();
85   int transparent_dummy();
86   int transparent();
87   int left_brace();
88   int right_brace();
89   int page_ejector();
90   int hyphen_indicator();
91   int zero_width_break();
92   int operator==(const token &); // need this for delimiters, and for conditions
93   int operator!=(const token &); // ditto
94   unsigned char ch();
95   charinfo *get_char(int required = 0);
96   int add_to_node_list(node **);
97   int title();
98   void make_space();
99   void make_newline();
100   const char *description();
101
102   friend void process_input_stack();
103 };
104
105 extern token tok;               // the current token
106
107 extern symbol get_name(int required = 0);
108 extern symbol get_long_name(int required = 0);
109 extern charinfo *get_optional_char();
110 extern char *read_string();
111 extern void check_missing_character();
112 extern void skip_line();
113 extern void handle_initial_title();
114
115 struct hunits;
116 extern void read_title_parts(node **part, hunits *part_width);
117
118 extern int get_number_rigidly(units *result, unsigned char si);
119
120 extern int get_number(units *result, unsigned char si);
121 extern int get_integer(int *result);
122
123 extern int get_number(units *result, unsigned char si, units prev_value);
124 extern int get_integer(int *result, int prev_value);
125
126 void interpolate_number_reg(symbol, int);
127
128 const char *asciify(int c);
129
130 inline int token::newline()
131
132   return type == TOKEN_NEWLINE; 
133 }
134
135 inline int token::space()
136
137   return type == TOKEN_SPACE;
138 }
139
140 inline int token::stretchable_space()
141 {
142   return type == TOKEN_STRETCHABLE_SPACE;
143 }
144
145 inline int token::unstretchable_space()
146 {
147   return type == TOKEN_UNSTRETCHABLE_SPACE;
148 }
149
150 inline int token::special()
151
152   return type == TOKEN_SPECIAL;
153 }
154
155 inline int token::nspaces()
156 {
157   if (type == TOKEN_SPACE)
158     return 1;
159   else
160     return 0;
161 }
162
163 inline int token::white_space()
164 {
165   return type == TOKEN_SPACE || type == TOKEN_TAB;
166 }
167
168 inline int token::transparent()
169 {
170   return type == TOKEN_TRANSPARENT;
171 }
172
173 inline int token::page_ejector()
174 {
175   return type == TOKEN_PAGE_EJECTOR;
176 }
177
178 inline unsigned char token::ch()
179 {
180   return type == TOKEN_CHAR ? c : 0;
181
182
183 inline int token::eof()
184 {
185   return type == TOKEN_EOF;
186 }
187
188 inline int token::dummy()
189 {
190   return type == TOKEN_DUMMY;
191 }
192
193 inline int token::transparent_dummy()
194 {
195   return type == TOKEN_TRANSPARENT_DUMMY;
196 }
197
198 inline int token::left_brace()
199 {
200   return type == TOKEN_LEFT_BRACE;
201 }
202
203 inline int token::right_brace()
204 {
205   return type == TOKEN_RIGHT_BRACE;
206 }
207
208 inline int token::tab()
209 {
210   return type == TOKEN_TAB;
211 }
212
213 inline int token::leader()
214 {
215   return type == TOKEN_LEADER;
216 }
217
218 inline int token::backspace()
219 {
220   return type == TOKEN_BACKSPACE;
221 }
222
223 inline int token::hyphen_indicator()
224 {
225   return type == TOKEN_HYPHEN_INDICATOR;
226 }
227
228 inline int token::zero_width_break()
229 {
230   return type == TOKEN_ZERO_WIDTH_BREAK;
231 }
232
233 int has_arg();