mtsm.h revision 151497
1151497Sru// -*- C++ -*- 2151497Sru/* Copyright (C) 2003, 2004 Free Software Foundation, Inc. 3151497Sru * 4151497Sru * mtsm.h 5151497Sru * 6151497Sru * written by Gaius Mulley (gaius@glam.ac.uk) 7151497Sru * 8151497Sru * provides a minimal troff state machine which is necessary to 9151497Sru * emit meta tags for the post-grohtml device driver. 10151497Sru */ 11151497Sru 12151497Sru/* 13151497SruThis file is part of groff. 14151497Sru 15151497Srugroff is free software; you can redistribute it and/or modify it under 16151497Sruthe terms of the GNU General Public License as published by the Free 17151497SruSoftware Foundation; either version 2, or (at your option) any later 18151497Sruversion. 19151497Sru 20151497Srugroff is distributed in the hope that it will be useful, but WITHOUT ANY 21151497SruWARRANTY; without even the implied warranty of MERCHANTABILITY or 22151497SruFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 23151497Srufor more details. 24151497Sru 25151497SruYou should have received a copy of the GNU General Public License along 26151497Sruwith groff; see the file COPYING. If not, write to the Free Software 27151497SruFoundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ 28151497Sru 29151497Srustruct int_value { 30151497Sru int value; 31151497Sru int is_known; 32151497Sru int_value(); 33151497Sru ~int_value(); 34151497Sru void diff(FILE *, const char *, int_value); 35151497Sru int differs(int_value); 36151497Sru void set(int); 37151497Sru void unset(); 38151497Sru void set_if_unknown(int); 39151497Sru}; 40151497Sru 41151497Srustruct bool_value : public int_value { 42151497Sru bool_value(); 43151497Sru ~bool_value(); 44151497Sru void diff(FILE *, const char *, bool_value); 45151497Sru}; 46151497Sru 47151497Srustruct units_value : public int_value { 48151497Sru units_value(); 49151497Sru ~units_value(); 50151497Sru void diff(FILE *, const char *, units_value); 51151497Sru int differs(units_value); 52151497Sru void set(hunits); 53151497Sru}; 54151497Sru 55151497Srustruct string_value { 56151497Sru string value; 57151497Sru int is_known; 58151497Sru string_value(); 59151497Sru ~string_value(); 60151497Sru void diff(FILE *, const char *, string_value); 61151497Sru int differs(string_value); 62151497Sru void set(string); 63151497Sru void unset(); 64151497Sru}; 65151497Sru 66151497Sruenum bool_value_state { 67151497Sru MTSM_EOL, 68151497Sru MTSM_BR, 69151497Sru LAST_BOOL 70151497Sru}; 71151497Sruenum int_value_state { 72151497Sru MTSM_FI, 73151497Sru MTSM_RJ, 74151497Sru MTSM_CE, 75151497Sru MTSM_SP, 76151497Sru LAST_INT 77151497Sru}; 78151497Sruenum units_value_state { 79151497Sru MTSM_IN, 80151497Sru MTSM_LL, 81151497Sru MTSM_PO, 82151497Sru MTSM_TI, 83151497Sru LAST_UNITS 84151497Sru}; 85151497Sruenum string_value_state { 86151497Sru MTSM_TA, 87151497Sru LAST_STRING 88151497Sru}; 89151497Sru 90151497Srustruct statem { 91151497Sru int issue_no; 92151497Sru bool_value bool_values[LAST_BOOL]; 93151497Sru int_value int_values[LAST_INT]; 94151497Sru units_value units_values[LAST_UNITS]; 95151497Sru string_value string_values[LAST_STRING]; 96151497Sru statem(); 97151497Sru statem(statem *); 98151497Sru ~statem(); 99151497Sru void flush(FILE *, statem *); 100151497Sru int changed(statem *); 101151497Sru void merge(statem *, statem *); 102151497Sru void add_tag(int_value_state, int); 103151497Sru void add_tag(bool_value_state); 104151497Sru void add_tag(units_value_state, hunits); 105151497Sru void add_tag(string_value_state, string); 106151497Sru void sub_tag_ce(); 107151497Sru void add_tag_if_unknown(int_value_state, int); 108151497Sru void add_tag_ta(); 109151497Sru void display_state(); 110151497Sru void update(statem *, statem *, int_value_state); 111151497Sru void update(statem *, statem *, bool_value_state); 112151497Sru void update(statem *, statem *, units_value_state); 113151497Sru void update(statem *, statem *, string_value_state); 114151497Sru}; 115151497Sru 116151497Srustruct stack { 117151497Sru stack *next; 118151497Sru statem *state; 119151497Sru stack(); 120151497Sru stack(statem *, stack *); 121151497Sru ~stack(); 122151497Sru}; 123151497Sru 124151497Sruclass mtsm { 125151497Sru statem *driver; 126151497Sru stack *sp; 127151497Sru int has_changed(int_value_state, statem *); 128151497Sru int has_changed(bool_value_state, statem *); 129151497Sru int has_changed(units_value_state, statem *); 130151497Sru int has_changed(string_value_state, statem *); 131151497Sru void inherit(statem *, int); 132151497Srupublic: 133151497Sru mtsm(); 134151497Sru ~mtsm(); 135151497Sru void push_state(statem *); 136151497Sru void pop_state(); 137151497Sru void flush(FILE *, statem *, string); 138151497Sru int changed(statem *); 139151497Sru void add_tag(FILE *, string); 140151497Sru}; 141151497Sru 142151497Sruclass state_set { 143151497Sru int boolset; 144151497Sru int intset; 145151497Sru int unitsset; 146151497Sru int stringset; 147151497Srupublic: 148151497Sru state_set(); 149151497Sru ~state_set(); 150151497Sru void incl(bool_value_state); 151151497Sru void incl(int_value_state); 152151497Sru void incl(units_value_state); 153151497Sru void incl(string_value_state); 154151497Sru void excl(bool_value_state); 155151497Sru void excl(int_value_state); 156151497Sru void excl(units_value_state); 157151497Sru void excl(string_value_state); 158151497Sru int is_in(bool_value_state); 159151497Sru int is_in(int_value_state); 160151497Sru int is_in(units_value_state); 161151497Sru int is_in(string_value_state); 162151497Sru void add(units_value_state, int); 163151497Sru units val(units_value_state); 164151497Sru}; 165