Copyright 2017
[s-roff.git] / src / troff / mtsm.h
blobe2ad08961cc67712dfdbec6a352252af0b2feff5
1 /*@ Provides a minimal troff state machine which is necessary to
2 *@ emit meta tags for the post-grohtml device driver.
4 * Copyright (c) 2014 - 2017 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>.
6 * Copyright (C) 2003, 2004 Free Software Foundation, Inc.
7 * written by Gaius Mulley (gaius@glam.ac.uk)
9 * This is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2, or (at your option) any later
12 * version.
14 * This is distributed in the hope that it will be useful, but WITHOUT ANY
15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 * for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with groff; see the file COPYING. If not, write to the Free Software
21 * Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA.
23 #ifndef _MTSM_H
24 #define _MTSM_H
26 #include "config.h"
27 #include "troff-config.h"
29 class int_value
31 public:
32 int value;
33 int is_known;
35 int_value();
36 ~int_value();
37 void diff(FILE *, const char *, int_value);
38 int differs(int_value);
39 void set(int);
40 void unset();
41 void set_if_unknown(int);
44 class bool_value
45 : public int_value
47 public:
48 bool_value();
49 ~bool_value();
50 void diff(FILE *, const char *, bool_value);
53 class units_value
54 : public int_value
56 public:
57 units_value();
58 ~units_value();
59 void diff(FILE *, const char *, units_value);
60 int differs(units_value);
61 void set(hunits);
64 class string_value
66 public:
67 string value;
68 int is_known;
70 string_value();
71 ~string_value();
72 void diff(FILE *, const char *, string_value);
73 int differs(string_value);
74 void set(string);
75 void unset();
78 enum bool_value_state {
79 MTSM_EOL,
80 MTSM_BR,
81 LAST_BOOL
84 enum int_value_state {
85 MTSM_FI,
86 MTSM_RJ,
87 MTSM_CE,
88 MTSM_SP,
89 LAST_INT
92 enum units_value_state {
93 MTSM_IN,
94 MTSM_LL,
95 MTSM_PO,
96 MTSM_TI,
97 LAST_UNITS
100 enum string_value_state {
101 MTSM_TA,
102 LAST_STRING
105 class statem
107 int issue_no;
108 bool_value bool_values[LAST_BOOL];
109 int_value int_values[LAST_INT];
110 units_value units_values[LAST_UNITS];
111 string_value string_values[LAST_STRING];
113 public:
114 statem();
115 statem(statem *);
116 ~statem();
117 void flush(FILE *, statem *);
118 int changed(statem *);
119 void merge(statem *, statem *);
120 void add_tag(int_value_state, int);
121 void add_tag(bool_value_state);
122 void add_tag(units_value_state, hunits);
123 void add_tag(string_value_state, string);
124 void sub_tag_ce();
125 void add_tag_if_unknown(int_value_state, int);
126 void add_tag_ta();
127 void display_state();
128 void update(statem *, statem *, int_value_state);
129 void update(statem *, statem *, bool_value_state);
130 void update(statem *, statem *, units_value_state);
131 void update(statem *, statem *, string_value_state);
134 class stack
136 public:
137 stack *next;
138 statem *state;
140 stack();
141 stack(statem *, stack *);
142 ~stack();
145 class mtsm
147 statem *driver;
148 stack *sp;
150 int has_changed(int_value_state, statem *);
151 int has_changed(bool_value_state, statem *);
152 int has_changed(units_value_state, statem *);
153 int has_changed(string_value_state, statem *);
154 void inherit(statem *, int);
156 public:
157 mtsm();
158 ~mtsm();
159 void push_state(statem *);
160 void pop_state();
161 void flush(FILE *, statem *, string);
162 int changed(statem *);
163 void add_tag(FILE *, string);
166 class state_set
168 int boolset;
169 int intset;
170 int unitsset;
171 int stringset;
173 public:
174 state_set();
175 ~state_set();
176 void incl(bool_value_state);
177 void incl(int_value_state);
178 void incl(units_value_state);
179 void incl(string_value_state);
180 void excl(bool_value_state);
181 void excl(int_value_state);
182 void excl(units_value_state);
183 void excl(string_value_state);
184 int is_in(bool_value_state);
185 int is_in(int_value_state);
186 int is_in(units_value_state);
187 int is_in(string_value_state);
188 void add(units_value_state, int);
189 units val(units_value_state);
192 #endif // _MTSM_H
193 // s-it2-mode