mtsm.h revision 256281
1239313Sdim// -*- C++ -*-
2239313Sdim/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
3239313Sdim *
4239313Sdim *  mtsm.h
5239313Sdim *
6239313Sdim *    written by Gaius Mulley (gaius@glam.ac.uk)
7239313Sdim *
8239313Sdim *  provides a minimal troff state machine which is necessary to
9239313Sdim *  emit meta tags for the post-grohtml device driver.
10239313Sdim */
11239313Sdim
12239313Sdim/*
13239313SdimThis file is part of groff.
14239313Sdim
15239313Sdimgroff is free software; you can redistribute it and/or modify it under
16239313Sdimthe terms of the GNU General Public License as published by the Free
17239313SdimSoftware Foundation; either version 2, or (at your option) any later
18239313Sdimversion.
19239313Sdim
20239313Sdimgroff is distributed in the hope that it will be useful, but WITHOUT ANY
21239313SdimWARRANTY; without even the implied warranty of MERCHANTABILITY or
22239313SdimFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23239313Sdimfor more details.
24239313Sdim
25239313SdimYou should have received a copy of the GNU General Public License along
26239313Sdimwith groff; see the file COPYING.  If not, write to the Free Software
27239313SdimFoundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
28239313Sdim
29239313Sdimstruct int_value {
30239313Sdim  int value;
31239313Sdim  int is_known;
32239313Sdim  int_value();
33239313Sdim  ~int_value();
34239313Sdim  void diff(FILE *, const char *, int_value);
35239313Sdim  int differs(int_value);
36239313Sdim  void set(int);
37239313Sdim  void unset();
38239313Sdim  void set_if_unknown(int);
39249423Sdim};
40239313Sdim
41239313Sdimstruct bool_value : public int_value {
42239313Sdim  bool_value();
43239313Sdim  ~bool_value();
44239313Sdim  void diff(FILE *, const char *, bool_value);
45239313Sdim};
46239313Sdim
47239313Sdimstruct units_value : public int_value {
48239313Sdim  units_value();
49263508Sdim  ~units_value();
50239313Sdim  void diff(FILE *, const char *, units_value);
51239313Sdim  int differs(units_value);
52239313Sdim  void set(hunits);
53239313Sdim};
54239313Sdim
55239313Sdimstruct string_value {
56239313Sdim  string value;
57239313Sdim  int is_known;
58239313Sdim  string_value();
59239313Sdim  ~string_value();
60239313Sdim  void diff(FILE *, const char *, string_value);
61239313Sdim  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