xref: /netbsd-src/external/gpl2/groff/dist/src/roff/troff/mtsm.h (revision 89a07cf815a29524268025a1139fac4c5190f765)
1 /*	$NetBSD: mtsm.h,v 1.1.1.1 2016/01/13 18:41:48 christos Exp $	*/
2 
3 // -*- C++ -*-
4 /* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
5  *
6  *  mtsm.h
7  *
8  *    written by Gaius Mulley (gaius@glam.ac.uk)
9  *
10  *  provides a minimal troff state machine which is necessary to
11  *  emit meta tags for the post-grohtml device driver.
12  */
13 
14 /*
15 This file is part of groff.
16 
17 groff is free software; you can redistribute it and/or modify it under
18 the terms of the GNU General Public License as published by the Free
19 Software Foundation; either version 2, or (at your option) any later
20 version.
21 
22 groff is distributed in the hope that it will be useful, but WITHOUT ANY
23 WARRANTY; without even the implied warranty of MERCHANTABILITY or
24 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
25 for more details.
26 
27 You should have received a copy of the GNU General Public License along
28 with groff; see the file COPYING.  If not, write to the Free Software
29 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
30 
31 struct int_value {
32   int value;
33   int is_known;
34   int_value();
35   ~int_value();
36   void diff(FILE *, const char *, int_value);
37   int differs(int_value);
38   void set(int);
39   void unset();
40   void set_if_unknown(int);
41 };
42 
43 struct bool_value : public int_value {
44   bool_value();
45   ~bool_value();
46   void diff(FILE *, const char *, bool_value);
47 };
48 
49 struct units_value : public int_value {
50   units_value();
51   ~units_value();
52   void diff(FILE *, const char *, units_value);
53   int differs(units_value);
54   void set(hunits);
55 };
56 
57 struct string_value {
58   string value;
59   int is_known;
60   string_value();
61   ~string_value();
62   void diff(FILE *, const char *, string_value);
63   int differs(string_value);
64   void set(string);
65   void unset();
66 };
67 
68 enum bool_value_state {
69   MTSM_EOL,
70   MTSM_BR,
71   LAST_BOOL
72 };
73 enum int_value_state {
74   MTSM_FI,
75   MTSM_RJ,
76   MTSM_CE,
77   MTSM_SP,
78   LAST_INT
79 };
80 enum units_value_state {
81   MTSM_IN,
82   MTSM_LL,
83   MTSM_PO,
84   MTSM_TI,
85   LAST_UNITS
86 };
87 enum string_value_state {
88   MTSM_TA,
89   LAST_STRING
90 };
91 
92 struct statem {
93   int issue_no;
94   bool_value bool_values[LAST_BOOL];
95   int_value int_values[LAST_INT];
96   units_value units_values[LAST_UNITS];
97   string_value string_values[LAST_STRING];
98   statem();
99   statem(statem *);
100   ~statem();
101   void flush(FILE *, statem *);
102   int changed(statem *);
103   void merge(statem *, statem *);
104   void add_tag(int_value_state, int);
105   void add_tag(bool_value_state);
106   void add_tag(units_value_state, hunits);
107   void add_tag(string_value_state, string);
108   void sub_tag_ce();
109   void add_tag_if_unknown(int_value_state, int);
110   void add_tag_ta();
111   void display_state();
112   void update(statem *, statem *, int_value_state);
113   void update(statem *, statem *, bool_value_state);
114   void update(statem *, statem *, units_value_state);
115   void update(statem *, statem *, string_value_state);
116 };
117 
118 struct stack {
119   stack *next;
120   statem *state;
121   stack();
122   stack(statem *, stack *);
123   ~stack();
124 };
125 
126 class mtsm {
127   statem *driver;
128   stack *sp;
129   int has_changed(int_value_state, statem *);
130   int has_changed(bool_value_state, statem *);
131   int has_changed(units_value_state, statem *);
132   int has_changed(string_value_state, statem *);
133   void inherit(statem *, int);
134 public:
135   mtsm();
136   ~mtsm();
137   void push_state(statem *);
138   void pop_state();
139   void flush(FILE *, statem *, string);
140   int changed(statem *);
141   void add_tag(FILE *, string);
142 };
143 
144 class state_set {
145   int boolset;
146   int intset;
147   int unitsset;
148   int stringset;
149 public:
150   state_set();
151   ~state_set();
152   void incl(bool_value_state);
153   void incl(int_value_state);
154   void incl(units_value_state);
155   void incl(string_value_state);
156   void excl(bool_value_state);
157   void excl(int_value_state);
158   void excl(units_value_state);
159   void excl(string_value_state);
160   int is_in(bool_value_state);
161   int is_in(int_value_state);
162   int is_in(units_value_state);
163   int is_in(string_value_state);
164   void add(units_value_state, int);
165   units val(units_value_state);
166 };
167