xref: /NextBSD/contrib/groff/src/roff/troff/charinfo.h (revision eb1a5f8de9f7ea602c373a710f531abbf81141c4)
1 // -*- C++ -*-
2 /* Copyright (C) 1989, 1990, 1991, 1992, 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
21 
22 class macro;
23 
24 class charinfo {
25   static int next_index;
26   charinfo *translation;
27   int index;
28   int number;
29   macro *mac;
30   unsigned char special_translation;
31   unsigned char hyphenation_code;
32   unsigned char flags;
33   unsigned char ascii_code;
34   unsigned char asciify_code;
35   char not_found;
36   char transparent_translate;	// non-zero means translation applies
37 				// to transparent throughput
38   char translate_input;		// non-zero means that asciify_code is
39 				// active for .asciify (set by .trin)
40   char_mode mode;
41 public:
42   enum {
43     ENDS_SENTENCE = 1,
44     BREAK_BEFORE = 2,
45     BREAK_AFTER = 4,
46     OVERLAPS_HORIZONTALLY = 8,
47     OVERLAPS_VERTICALLY = 16,
48     TRANSPARENT = 32,
49     NUMBERED = 64
50   };
51   enum {
52     TRANSLATE_NONE,
53     TRANSLATE_SPACE,
54     TRANSLATE_DUMMY,
55     TRANSLATE_STRETCHABLE_SPACE,
56     TRANSLATE_HYPHEN_INDICATOR
57   };
58   symbol nm;
59   charinfo(symbol s);
60   int get_index();
61   int ends_sentence();
62   int overlaps_vertically();
63   int overlaps_horizontally();
64   int can_break_before();
65   int can_break_after();
66   int transparent();
67   unsigned char get_hyphenation_code();
68   unsigned char get_ascii_code();
69   unsigned char get_asciify_code();
70   void set_hyphenation_code(unsigned char);
71   void set_ascii_code(unsigned char);
72   void set_asciify_code(unsigned char);
73   void set_translation_input();
74   int get_translation_input();
75   charinfo *get_translation(int = 0);
76   void set_translation(charinfo *, int, int);
77   void set_flags(unsigned char);
78   void set_special_translation(int, int);
79   int get_special_translation(int = 0);
80   macro *set_macro(macro *);
81   macro *setx_macro(macro *, char_mode);
82   macro *get_macro();
83   int first_time_not_found();
84   void set_number(int);
85   int get_number();
86   int numbered();
87   int is_normal();
88   int is_fallback();
89   int is_special();
90   symbol *get_symbol();
91 };
92 
93 charinfo *get_charinfo(symbol);
94 extern charinfo *charset_table[];
95 charinfo *get_charinfo_by_number(int);
96 
overlaps_horizontally()97 inline int charinfo::overlaps_horizontally()
98 {
99   return flags & OVERLAPS_HORIZONTALLY;
100 }
101 
overlaps_vertically()102 inline int charinfo::overlaps_vertically()
103 {
104   return flags & OVERLAPS_VERTICALLY;
105 }
106 
can_break_before()107 inline int charinfo::can_break_before()
108 {
109   return flags & BREAK_BEFORE;
110 }
111 
can_break_after()112 inline int charinfo::can_break_after()
113 {
114   return flags & BREAK_AFTER;
115 }
116 
ends_sentence()117 inline int charinfo::ends_sentence()
118 {
119   return flags & ENDS_SENTENCE;
120 }
121 
transparent()122 inline int charinfo::transparent()
123 {
124   return flags & TRANSPARENT;
125 }
126 
numbered()127 inline int charinfo::numbered()
128 {
129   return flags & NUMBERED;
130 }
131 
is_normal()132 inline int charinfo::is_normal()
133 {
134   return mode == CHAR_NORMAL;
135 }
136 
is_fallback()137 inline int charinfo::is_fallback()
138 {
139   return mode == CHAR_FALLBACK;
140 }
141 
is_special()142 inline int charinfo::is_special()
143 {
144   return mode == CHAR_SPECIAL;
145 }
146 
get_translation(int transparent_throughput)147 inline charinfo *charinfo::get_translation(int transparent_throughput)
148 {
149   return (transparent_throughput && !transparent_translate
150 	  ? 0
151 	  : translation);
152 }
153 
get_hyphenation_code()154 inline unsigned char charinfo::get_hyphenation_code()
155 {
156   return hyphenation_code;
157 }
158 
get_ascii_code()159 inline unsigned char charinfo::get_ascii_code()
160 {
161   return ascii_code;
162 }
163 
get_asciify_code()164 inline unsigned char charinfo::get_asciify_code()
165 {
166   return (translate_input ? asciify_code : 0);
167 }
168 
set_flags(unsigned char c)169 inline void charinfo::set_flags(unsigned char c)
170 {
171   flags = c;
172 }
173 
get_index()174 inline int charinfo::get_index()
175 {
176   return index;
177 }
178 
set_translation_input()179 inline void charinfo::set_translation_input()
180 {
181   translate_input = 1;
182 }
183 
get_translation_input()184 inline int charinfo::get_translation_input()
185 {
186   return translate_input;
187 }
188 
get_special_translation(int transparent_throughput)189 inline int charinfo::get_special_translation(int transparent_throughput)
190 {
191   return (transparent_throughput && !transparent_translate
192 	  ? int(TRANSLATE_NONE)
193 	  : special_translation);
194 }
195 
get_macro()196 inline macro *charinfo::get_macro()
197 {
198   return mac;
199 }
200 
first_time_not_found()201 inline int charinfo::first_time_not_found()
202 {
203   if (not_found)
204     return 0;
205   else {
206     not_found = 1;
207     return 1;
208   }
209 }
210 
get_symbol()211 inline symbol *charinfo::get_symbol()
212 {
213   return( &nm );
214 }
215