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
8This file is part of groff.
9
10groff is free software; you can redistribute it and/or modify it under
11the terms of the GNU General Public License as published by the Free
12Software Foundation; either version 2, or (at your option) any later
13version.
14
15groff is distributed in the hope that it will be useful, but WITHOUT ANY
16WARRANTY; without even the implied warranty of MERCHANTABILITY or
17FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
18for more details.
19
20You should have received a copy of the GNU General Public License along
21with groff; see the file COPYING.  If not, write to the Free Software
22Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
23
24
25class charinfo;
26struct node;
27class vunits;
28
29class 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;
66public:
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
107extern token tok;		// the current token
108
109extern symbol get_name(int required = 0);
110extern symbol get_long_name(int required = 0);
111extern charinfo *get_optional_char();
112extern char *read_string();
113extern void check_missing_character();
114extern void skip_line();
115extern void handle_initial_title();
116
117enum char_mode {
118  CHAR_NORMAL,
119  CHAR_FALLBACK,
120  CHAR_FONT_SPECIAL,
121  CHAR_SPECIAL
122};
123
124extern void do_define_character(char_mode, const char * = 0);
125
126class hunits;
127extern void read_title_parts(node **part, hunits *part_width);
128
129extern int get_number_rigidly(units *result, unsigned char si);
130
131extern int get_number(units *result, unsigned char si);
132extern int get_integer(int *result);
133
134extern int get_number(units *result, unsigned char si, units prev_value);
135extern int get_integer(int *result, int prev_value);
136
137void interpolate_number_reg(symbol, int);
138
139const char *asciify(int c);
140
141inline int token::newline()
142{
143  return type == TOKEN_NEWLINE;
144}
145
146inline int token::space()
147{
148  return type == TOKEN_SPACE;
149}
150
151inline int token::stretchable_space()
152{
153  return type == TOKEN_STRETCHABLE_SPACE;
154}
155
156inline int token::unstretchable_space()
157{
158  return type == TOKEN_UNSTRETCHABLE_SPACE;
159}
160
161inline int token::special()
162{
163  return type == TOKEN_SPECIAL;
164}
165
166inline int token::nspaces()
167{
168  if (type == TOKEN_SPACE)
169    return 1;
170  else
171    return 0;
172}
173
174inline int token::white_space()
175{
176  return type == TOKEN_SPACE || type == TOKEN_TAB;
177}
178
179inline int token::transparent()
180{
181  return type == TOKEN_TRANSPARENT;
182}
183
184inline int token::page_ejector()
185{
186  return type == TOKEN_PAGE_EJECTOR;
187}
188
189inline unsigned char token::ch()
190{
191  return type == TOKEN_CHAR ? c : 0;
192}
193
194inline int token::eof()
195{
196  return type == TOKEN_EOF;
197}
198
199inline int token::dummy()
200{
201  return type == TOKEN_DUMMY;
202}
203
204inline int token::transparent_dummy()
205{
206  return type == TOKEN_TRANSPARENT_DUMMY;
207}
208
209inline int token::left_brace()
210{
211  return type == TOKEN_LEFT_BRACE;
212}
213
214inline int token::right_brace()
215{
216  return type == TOKEN_RIGHT_BRACE;
217}
218
219inline int token::tab()
220{
221  return type == TOKEN_TAB;
222}
223
224inline int token::leader()
225{
226  return type == TOKEN_LEADER;
227}
228
229inline int token::backspace()
230{
231  return type == TOKEN_BACKSPACE;
232}
233
234inline int token::hyphen_indicator()
235{
236  return type == TOKEN_HYPHEN_INDICATOR;
237}
238
239inline int token::zero_width_break()
240{
241  return type == TOKEN_ZERO_WIDTH_BREAK;
242}
243
244int has_arg();
245