Initial import from FreeBSD RELENG_4:
[dragonfly.git] / contrib / groff / src / roff / troff / charinfo.h
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 fallback;
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 *, int = 0);
81   macro *get_macro();
82   int first_time_not_found();
83   void set_number(int);
84   int get_number();
85   int numbered();
86   int is_fallback();
87   symbol *get_symbol();
88 };
89
90 charinfo *get_charinfo(symbol);
91 extern charinfo *charset_table[];
92 charinfo *get_charinfo_by_number(int);
93
94 inline int charinfo::overlaps_horizontally()
95 {
96   return flags & OVERLAPS_HORIZONTALLY;
97 }
98
99 inline int charinfo::overlaps_vertically()
100 {
101   return flags & OVERLAPS_VERTICALLY;
102 }
103
104 inline int charinfo::can_break_before()
105 {
106   return flags & BREAK_BEFORE;
107 }
108
109 inline int charinfo::can_break_after()
110 {
111   return flags & BREAK_AFTER;
112 }
113
114 inline int charinfo::ends_sentence()
115 {
116   return flags & ENDS_SENTENCE;
117 }
118
119 inline int charinfo::transparent()
120 {
121   return flags & TRANSPARENT;
122 }
123
124 inline int charinfo::numbered()
125 {
126   return flags & NUMBERED;
127 }
128
129 inline int charinfo::is_fallback()
130 {
131   return fallback;
132 }
133
134 inline charinfo *charinfo::get_translation(int transparent_throughput)
135 {
136   return (transparent_throughput && !transparent_translate
137           ? 0
138           : translation);
139 }
140
141 inline unsigned char charinfo::get_hyphenation_code()
142 {
143   return hyphenation_code;
144 }
145
146 inline unsigned char charinfo::get_ascii_code()
147 {
148   return ascii_code;
149 }
150
151 inline unsigned char charinfo::get_asciify_code()
152 {
153   return (translate_input ? asciify_code : 0);
154 }
155
156 inline void charinfo::set_flags(unsigned char c)
157 {
158   flags = c;
159 }
160
161 inline int charinfo::get_index()
162 {
163   return index;
164 }
165
166 inline void charinfo::set_translation_input()
167 {
168   translate_input = 1;
169 }
170
171 inline int charinfo::get_translation_input()
172 {
173   return translate_input;
174 }
175
176 inline int charinfo::get_special_translation(int transparent_throughput)
177 {
178   return (transparent_throughput && !transparent_translate
179           ? int(TRANSLATE_NONE)
180           : special_translation);
181 }
182
183 inline macro *charinfo::get_macro()
184 {
185   return mac;
186 }
187
188 inline int charinfo::first_time_not_found()
189 {
190   if (not_found)
191     return 0;
192   else {
193     not_found = 1;
194     return 1;
195   }
196 }
197
198 inline symbol *charinfo::get_symbol()
199 {
200   return( &nm );
201 }