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