home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / bbs / gnu / groff-1.09-src.lha / src / amiga / groff-1.09 / troff / token.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-28  |  4.3 KB  |  195 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, 675 Mass Ave, Cambridge, MA 02139, 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 skip_line();
  101. extern void handle_initial_title();
  102.  
  103. struct hunits;
  104. extern void read_title_parts(node **part, hunits *part_width);
  105.  
  106. extern int get_number(units *result, unsigned char si);
  107. extern int get_integer(int *result);
  108.  
  109. extern int get_number(units *result, unsigned char si, units prev_value);
  110. extern int get_integer(int *result, int prev_value);
  111.  
  112. void interpolate_number_reg(symbol, int);
  113.  
  114. const char *asciify(int c);
  115.  
  116. inline int token::newline()
  117.   return type == TOKEN_NEWLINE; 
  118. }
  119.  
  120. inline int token::space()
  121.   return type == TOKEN_SPACE;
  122. }
  123.  
  124. inline int token::nspaces()
  125. {
  126.   if (type == TOKEN_SPACE)
  127.     return 1;
  128.   else
  129.     return 0;
  130. }
  131.  
  132. inline int token::white_space()
  133. {
  134.   return type == TOKEN_SPACE || type == TOKEN_TAB;
  135. }
  136.  
  137. inline int token::transparent()
  138. {
  139.   return type == TOKEN_TRANSPARENT;
  140. }
  141.  
  142. inline int token::page_ejector()
  143. {
  144.   return type == TOKEN_PAGE_EJECTOR;
  145. }
  146.  
  147. inline unsigned char token::ch()
  148. {
  149.   return type == TOKEN_CHAR ? c : 0;
  150.  
  151. inline int token::eof()
  152. {
  153.   return type == TOKEN_EOF;
  154. }
  155.  
  156. inline int token::dummy()
  157. {
  158.   return type == TOKEN_DUMMY;
  159. }
  160.  
  161. inline int token::left_brace()
  162. {
  163.   return type == TOKEN_LEFT_BRACE;
  164. }
  165.  
  166. inline int token::right_brace()
  167. {
  168.   return type == TOKEN_RIGHT_BRACE;
  169. }
  170.  
  171. inline int token::tab()
  172. {
  173.   return type == TOKEN_TAB;
  174. }
  175.  
  176. inline int token::leader()
  177. {
  178.   return type == TOKEN_LEADER;
  179. }
  180.  
  181. inline int token::backspace()
  182. {
  183.   return type == TOKEN_BACKSPACE;
  184. }
  185.  
  186. inline int token::hyphen_indicator()
  187. {
  188.   return type == TOKEN_HYPHEN_INDICATOR;
  189. }
  190.  
  191. int has_arg();
  192.