home *** CD-ROM | disk | FTP | other *** search
/ Aminet 10 / aminetcdnumber101996.iso / Aminet / util / gnu / groff_src.lha / groff-1.10src / troff / token.h < prev    next >
C/C++ Source or Header  |  1995-06-22  |  5KB  |  196 lines

  1. // -*- C++ -*-
  2. /* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
  3.      Written by James Clark (jjc@jclark.com)
  4.  
  5. This file is part of groff.
  6.  
  7. groff is free software; you can redistribute it and/or modify it under
  8. the terms of the GNU General Public License as published by the Free
  9. Software Foundation; either version 2, or (at your option) any later
  10. version.
  11.  
  12. groff is distributed in the hope that it will be useful, but WITHOUT ANY
  13. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License along
  18. with groff; see the file COPYING.  If not, write to the Free Software
  19. Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  20.  
  21.  
  22. struct charinfo;
  23. struct node;
  24. struct vunits;
  25.  
  26. class token {
  27.   symbol nm;
  28.   node *nd;
  29.   unsigned char c;
  30.   int val;
  31.   units dim;
  32.   enum token_type {
  33.     TOKEN_BACKSPACE,
  34.     TOKEN_BEGIN_TRAP,
  35.     TOKEN_CHAR,            // a normal printing character
  36.     TOKEN_DUMMY,
  37.     TOKEN_EMPTY,        // this is the initial value
  38.     TOKEN_END_TRAP,
  39.     TOKEN_ESCAPE,        // \e
  40.     TOKEN_HYPHEN_INDICATOR,
  41.     TOKEN_INTERRUPT,        // \c
  42.     TOKEN_ITALIC_CORRECTION,    // \/
  43.     TOKEN_LEADER,        // ^A
  44.     TOKEN_LEFT_BRACE,
  45.     TOKEN_MARK_INPUT,        // \k -- `nm' is the name of the register
  46.     TOKEN_NEWLINE,        // newline
  47.     TOKEN_NODE,
  48.     TOKEN_NUMBERED_CHAR,
  49.     TOKEN_PAGE_EJECTOR,
  50.     TOKEN_REQUEST,
  51.     TOKEN_RIGHT_BRACE,
  52.     TOKEN_SPACE,        // ` ' -- ordinary space
  53.     TOKEN_SPECIAL,        // a special character -- \' \` \- \(xx
  54.     TOKEN_SPREAD,        // \p -- break and spread output line 
  55.     TOKEN_TAB,            // tab
  56.     TOKEN_TRANSPARENT,        // \!
  57.     TOKEN_EOF            // end of file
  58.     } type;
  59. public:
  60.   token();
  61.   ~token();
  62.   token(const token &);
  63.   void operator=(const token &);
  64.   void next();
  65.   void process();
  66.   void skip();
  67.   int eof();
  68.   int nspaces();        // 1 if space, 2 if double space, 0 otherwise
  69.   int space();            // is it a space or double space?
  70.   int white_space();        // is the current token space or tab?
  71.   int newline();        // is the current token a newline?
  72.   int tab();            // is the current token a tab?
  73.   int leader();
  74.   int backspace();
  75.   int delimiter(int warn = 0);    // is it suitable for use as a delimiter?
  76.   int dummy();
  77.   int transparent();
  78.   int left_brace();
  79.   int right_brace();
  80.   int page_ejector();
  81.   int hyphen_indicator();
  82.   int operator==(const token &); // need this for delimiters, and for conditions
  83.   int operator!=(const token &); // ditto
  84.   unsigned char ch();
  85.   charinfo *get_char(int required = 0);
  86.   int add_to_node_list(node **);
  87.   int title();
  88.   void make_space();
  89.   void make_newline();
  90.   const char *description();
  91.  
  92.   friend void process_input_stack();
  93. };
  94.  
  95. extern token tok;        // the current token
  96.  
  97. extern symbol get_name(int required = 0);
  98. extern symbol get_long_name(int required = 0);
  99. extern charinfo *get_optional_char();
  100. extern void check_missing_character();
  101. extern void skip_line();
  102. extern void handle_initial_title();
  103.  
  104. struct hunits;
  105. extern void read_title_parts(node **part, hunits *part_width);
  106.  
  107. extern int get_number(units *result, unsigned char si);
  108. extern int get_integer(int *result);
  109.  
  110. extern int get_number(units *result, unsigned char si, units prev_value);
  111. extern int get_integer(int *result, int prev_value);
  112.  
  113. void interpolate_number_reg(symbol, int);
  114.  
  115. const char *asciify(int c);
  116.  
  117. inline int token::newline()
  118.   return type == TOKEN_NEWLINE; 
  119. }
  120.  
  121. inline int token::space()
  122.   return type == TOKEN_SPACE;
  123. }
  124.  
  125. inline int token::nspaces()
  126. {
  127.   if (type == TOKEN_SPACE)
  128.     return 1;
  129.   else
  130.     return 0;
  131. }
  132.  
  133. inline int token::white_space()
  134. {
  135.   return type == TOKEN_SPACE || type == TOKEN_TAB;
  136. }
  137.  
  138. inline int token::transparent()
  139. {
  140.   return type == TOKEN_TRANSPARENT;
  141. }
  142.  
  143. inline int token::page_ejector()
  144. {
  145.   return type == TOKEN_PAGE_EJECTOR;
  146. }
  147.  
  148. inline unsigned char token::ch()
  149. {
  150.   return type == TOKEN_CHAR ? c : 0;
  151.  
  152. inline int token::eof()
  153. {
  154.   return type == TOKEN_EOF;
  155. }
  156.  
  157. inline int token::dummy()
  158. {
  159.   return type == TOKEN_DUMMY;
  160. }
  161.  
  162. inline int token::left_brace()
  163. {
  164.   return type == TOKEN_LEFT_BRACE;
  165. }
  166.  
  167. inline int token::right_brace()
  168. {
  169.   return type == TOKEN_RIGHT_BRACE;
  170. }
  171.  
  172. inline int token::tab()
  173. {
  174.   return type == TOKEN_TAB;
  175. }
  176.  
  177. inline int token::leader()
  178. {
  179.   return type == TOKEN_LEADER;
  180. }
  181.  
  182. inline int token::backspace()
  183. {
  184.   return type == TOKEN_BACKSPACE;
  185. }
  186.  
  187. inline int token::hyphen_indicator()
  188. {
  189.   return type == TOKEN_HYPHEN_INDICATOR;
  190. }
  191.  
  192. int has_arg();
  193.