Adapt src/troff (src/roff/troff)
[s-roff.git] / src / troff / token.h
blob44e00eee2397f147c96b5aea48ca1ce62f2c67cc
1 /*@
2 * Copyright (c) 2014 Steffen (Daode) Nurpmeso <sdaoden@users.sf.net>.
4 * Copyright (C) 1989 - 1992, 2000 - 2002, 2004
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 _TOKEN_H
23 #define _TOKEN_H
25 #include "config.h"
26 #include "troff-config.h"
28 class charinfo;
29 struct node;
30 class vunits;
32 class token
34 friend void process_input_stack();
36 symbol nm;
37 node *nd;
38 unsigned char c;
39 int val;
40 units dim;
41 enum token_type {
42 TOKEN_BACKSPACE,
43 TOKEN_BEGIN_TRAP,
44 TOKEN_CHAR, // a normal printing character
45 TOKEN_DUMMY, // \&
46 TOKEN_EMPTY, // this is the initial value
47 TOKEN_END_TRAP,
48 TOKEN_ESCAPE, // \e
49 TOKEN_HYPHEN_INDICATOR,
50 TOKEN_INTERRUPT, // \c
51 TOKEN_ITALIC_CORRECTION, // \/
52 TOKEN_LEADER, // ^A
53 TOKEN_LEFT_BRACE,
54 TOKEN_MARK_INPUT, // \k -- `nm' is the name of the register
55 TOKEN_NEWLINE, // newline
56 TOKEN_NODE,
57 TOKEN_NUMBERED_CHAR,
58 TOKEN_PAGE_EJECTOR,
59 TOKEN_REQUEST,
60 TOKEN_RIGHT_BRACE,
61 TOKEN_SPACE, // ` ' -- ordinary space
62 TOKEN_SPECIAL, // a special character -- \' \` \- \(xx \[xxx]
63 TOKEN_SPREAD, // \p -- break and spread output line
64 TOKEN_STRETCHABLE_SPACE, // \~
65 TOKEN_UNSTRETCHABLE_SPACE, // `\ '
66 TOKEN_TAB, // tab
67 TOKEN_TRANSPARENT, // \!
68 TOKEN_TRANSPARENT_DUMMY, // \)
69 TOKEN_ZERO_WIDTH_BREAK, // \:
70 TOKEN_EOF // end of file
71 } type;
73 public:
74 token();
75 ~token();
76 token(const token &);
77 void operator=(const token &);
78 void next();
79 void process();
80 void skip();
81 int eof();
82 int nspaces(); // 1 if space, 2 if double space, 0 otherwise
83 int space(); // is the current token a space?
84 int stretchable_space(); // is the current token a stretchable space?
85 int unstretchable_space(); // is the current token an unstretchable space?
86 int white_space(); // is the current token space or tab?
87 int special(); // is the current token a special character?
88 int newline(); // is the current token a newline?
89 int tab(); // is the current token a tab?
90 int leader();
91 int backspace();
92 int delimiter(int warn = 0); // is it suitable for use as a delimiter?
93 int dummy();
94 int transparent_dummy();
95 int transparent();
96 int left_brace();
97 int right_brace();
98 int page_ejector();
99 int hyphen_indicator();
100 int zero_width_break();
101 int operator==(const token &); // need this for delimiters, and for conditions
102 int operator!=(const token &); // ditto
103 unsigned char ch();
104 charinfo *get_char(int required = 0);
105 int add_to_node_list(node **);
106 int title();
107 void make_space();
108 void make_newline();
109 const char *description();
112 extern token tok; // the current token
114 extern symbol get_name(int required = 0);
115 extern symbol get_long_name(int required = 0);
116 extern charinfo *get_optional_char();
117 extern char *read_string();
118 extern void check_missing_character();
119 extern void skip_line();
120 extern void handle_initial_title();
122 enum char_mode {
123 CHAR_NORMAL,
124 CHAR_FALLBACK,
125 CHAR_FONT_SPECIAL,
126 CHAR_SPECIAL
129 extern void do_define_character(char_mode, const char * = 0);
131 class hunits;
132 extern void read_title_parts(node **part, hunits *part_width);
134 extern int get_number_rigidly(units *result, unsigned char si);
136 extern int get_number(units *result, unsigned char si);
137 extern int get_integer(int *result);
139 extern int get_number(units *result, unsigned char si, units prev_value);
140 extern int get_integer(int *result, int prev_value);
142 void interpolate_number_reg(symbol, int);
144 const char *asciify(int c);
146 inline int token::newline()
148 return type == TOKEN_NEWLINE;
151 inline int token::space()
153 return type == TOKEN_SPACE;
156 inline int token::stretchable_space()
158 return type == TOKEN_STRETCHABLE_SPACE;
161 inline int token::unstretchable_space()
163 return type == TOKEN_UNSTRETCHABLE_SPACE;
166 inline int token::special()
168 return type == TOKEN_SPECIAL;
171 inline int token::nspaces()
173 if (type == TOKEN_SPACE)
174 return 1;
175 else
176 return 0;
179 inline int token::white_space()
181 return type == TOKEN_SPACE || type == TOKEN_TAB;
184 inline int token::transparent()
186 return type == TOKEN_TRANSPARENT;
189 inline int token::page_ejector()
191 return type == TOKEN_PAGE_EJECTOR;
194 inline unsigned char token::ch()
196 return type == TOKEN_CHAR ? c : 0;
199 inline int token::eof()
201 return type == TOKEN_EOF;
204 inline int token::dummy()
206 return type == TOKEN_DUMMY;
209 inline int token::transparent_dummy()
211 return type == TOKEN_TRANSPARENT_DUMMY;
214 inline int token::left_brace()
216 return type == TOKEN_LEFT_BRACE;
219 inline int token::right_brace()
221 return type == TOKEN_RIGHT_BRACE;
224 inline int token::tab()
226 return type == TOKEN_TAB;
229 inline int token::leader()
231 return type == TOKEN_LEADER;
234 inline int token::backspace()
236 return type == TOKEN_BACKSPACE;
239 inline int token::hyphen_indicator()
241 return type == TOKEN_HYPHEN_INDICATOR;
244 inline int token::zero_width_break()
246 return type == TOKEN_ZERO_WIDTH_BREAK;
249 int has_arg();
251 #endif // _TOKEN_H
252 // s-it2-mode