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