/contrib/groff/src/roff/troff/mtsm.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 164 lines · 128 code · 10 blank · 26 comment · 0 complexity · f60a62f16fc92d3ad597243ba2cd7c96 MD5 · raw file

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