home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / groff / troff / token.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-30  |  4.8 KB  |  219 lines

  1. // -*- C++ -*-
  2. /* Copyright (C) 1989, 1990 Free Software Foundation, Inc.
  3.      Written by James Clark (jjc@jclark.uucp)
  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 1, 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 LICENSE.  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. // See ARM p251.
  27. static void process_input_stack();
  28.  
  29. class token {
  30.   symbol nm;
  31.   node *nd;
  32.   unsigned char c;
  33.   int val;
  34.   units dim;
  35.   enum token_type {
  36.     TOKEN_BACKSPACE,
  37.     TOKEN_BEGIN_TRAP,
  38.     TOKEN_CHAR,            // a normal printing character
  39.     TOKEN_CHAR_HEIGHT,        // \H
  40.     TOKEN_CHAR_SLANT,        // \S
  41.     TOKEN_DUMMY,
  42.     TOKEN_EMPTY,        // this is the initial value
  43.     TOKEN_END_TRAP,
  44.     TOKEN_ESCAPE,        // \e
  45.     TOKEN_FONT_NAME,        // \f followed by a name
  46.     TOKEN_FONT_POSITION,    // \f followed by a digit
  47.     TOKEN_HYPHEN_INDICATOR,
  48.     TOKEN_INTERRUPT,        // \c
  49.     TOKEN_ITALIC_CORRECTION,    // \/
  50.     TOKEN_LEADER,        // ^A
  51.     TOKEN_LEFT_BRACE,
  52.     TOKEN_MARK_INPUT,        // \k -- `nm' is the name of the register
  53.     TOKEN_NEWLINE,        // newline
  54.     TOKEN_NODE,
  55.     TOKEN_NUMBERED_CHAR,
  56.     TOKEN_PAGE_EJECTOR,
  57.     TOKEN_REQUEST,
  58.     TOKEN_RIGHT_BRACE,
  59.     TOKEN_SIZE,            // \s
  60.     TOKEN_SPACE,        // ` ' -- ordinary space
  61.     TOKEN_SPECIAL,        // a special character -- \' \` \- \(xx
  62.     TOKEN_SPREAD,        // \p -- break and spread output line 
  63.     TOKEN_TAB,            // tab
  64.     TOKEN_TRANSPARENT,        // \!
  65.     TOKEN_EOF            // end of file
  66.     } type;
  67. public:
  68.   token();
  69.   ~token();
  70.   token(const token &);
  71.   void operator=(const token &);
  72.   void next();
  73.   void process();
  74.   void skip();
  75.   int eof();
  76.   int nspaces();        // 1 if space, 2 if double space, 0 otherwise
  77.   int space();            // is it a space or double space?
  78.   int white_space();        // is the current token space or tab?
  79.   int newline();        // is the current token a newline?
  80.   int tab();            // is the current token a tab?
  81.   int leader();
  82.   int backspace();
  83.   int delimiter(int warn = 0);    // is it suitable for use as a delimiter?
  84.   symbol special();
  85.   int dummy();
  86.   int transparent();
  87.   int left_brace();
  88.   int right_brace();
  89.   int page_ejector();
  90.   int operator==(const token &); // need this for delimiters, and for conditions
  91.   int operator!=(const token &); // ditto
  92.   unsigned char ch();
  93.   charinfo *get_char(int required = 0);
  94.   int add_to_node_list(node **);
  95.   int changes_env();
  96.   int is_size();
  97.   int title();
  98.   void make_space();
  99.   void make_newline();
  100.   const char *description();
  101.  
  102.   friend void process_input_stack();
  103. };
  104.  
  105. extern token tok;        // the current token
  106.  
  107. extern symbol get_name(int required = 0);
  108. extern symbol get_long_name(int required = 0);
  109. extern charinfo *get_optional_char();
  110. extern void skip_line();
  111. extern void handle_initial_title();
  112.  
  113. struct hunits;
  114. extern void read_title_parts(node **part, hunits *part_width);
  115.  
  116. extern int get_number(units *result, unsigned char si);
  117. extern int get_integer(int *result);
  118.  
  119. extern int get_number(units *result, unsigned char si, units prev_value);
  120. extern int get_integer(int *result, int prev_value);
  121.  
  122. void interpolate_number_reg(symbol, int);
  123.  
  124. const char *asciify(int c);
  125.  
  126. inline int token::newline()
  127.   return type == TOKEN_NEWLINE; 
  128. }
  129.  
  130. inline int token::space()
  131.   return type == TOKEN_SPACE;
  132. }
  133.  
  134. inline int token::nspaces()
  135. {
  136.   if (type == TOKEN_SPACE)
  137.     return 1;
  138.   else
  139.     return 0;
  140. }
  141.  
  142. inline int token::white_space()
  143. {
  144.   return type == TOKEN_SPACE || type == TOKEN_TAB;
  145. }
  146.  
  147. inline int token::transparent()
  148. {
  149.   return type == TOKEN_TRANSPARENT;
  150. }
  151.  
  152. inline int token::page_ejector()
  153. {
  154.   return type == TOKEN_PAGE_EJECTOR;
  155. }
  156.  
  157. inline unsigned char token::ch()
  158. {
  159.   return type == TOKEN_CHAR ? c : 0;
  160.  
  161. inline int token::eof()
  162. {
  163.   return type == TOKEN_EOF;
  164. }
  165.  
  166. inline symbol token::special()
  167. {
  168.   return type == TOKEN_SPECIAL ? nm : symbol();
  169. }
  170.  
  171. inline int token::dummy()
  172. {
  173.   return type == TOKEN_DUMMY;
  174. }
  175.  
  176. inline int token::is_size()
  177. {
  178.   return type == TOKEN_SIZE;
  179. }
  180.  
  181. inline int token::left_brace()
  182. {
  183.   return type == TOKEN_LEFT_BRACE;
  184. }
  185.  
  186. inline int token::right_brace()
  187. {
  188.   return type == TOKEN_RIGHT_BRACE;
  189. }
  190.  
  191. inline int token::changes_env()
  192. {
  193.   return (type == TOKEN_CHAR_HEIGHT
  194.       || type == TOKEN_CHAR_SLANT
  195.       || type == TOKEN_FONT_NAME
  196.       || type == TOKEN_FONT_POSITION
  197.       || type == TOKEN_SIZE);
  198. }
  199.  
  200. inline int token::tab()
  201. {
  202.   return type == TOKEN_TAB;
  203. }
  204.  
  205. inline int token::leader()
  206. {
  207.   return type == TOKEN_LEADER;
  208. }
  209.  
  210. inline int token::backspace()
  211. {
  212.   return type == TOKEN_BACKSPACE;
  213. }
  214.  
  215. int has_arg();
  216.