home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / CMTEX330 / SOURCE / TOK.H < prev    next >
C/C++ Source or Header  |  1992-02-19  |  4KB  |  187 lines

  1.  
  2. /*
  3.  * %Y%:%M%:%I%:%Q%
  4.  *
  5.  * Copyright 1987,1988,1991 Pat J Monardo
  6.  *
  7.  * Redistribution of this file is permitted through
  8.  * the specifications in the file COPYING.
  9.  *
  10.  *
  11.  */
  12.  
  13. #define token_link(T)    link(T)
  14. #define token(T)    info(T)
  15.  
  16. #define LEFT_BRACE_TOKEN    0400
  17. #define LEFT_BRACE_LIMIT    01000
  18. #define RIGHT_BRACE_TOKEN    01000
  19. #define RIGHT_BRACE_LIMIT    01400
  20. #define MATH_SHIFT_TOKEN    01400
  21. #define TAB_TOKEN        02000
  22. #define OUT_PARAM_TOKEN        02400
  23. #define SPACE_TOKEN        05040
  24. #define LETTER_TOKEN        05400
  25. #define OTHER_TOKEN        06000
  26. #define MATCH_TOKEN        06400
  27. #define END_MATCH_TOKEN        07000
  28. #define CS_TOKEN_FLAG        010000
  29. #define is_sym(TOK)        ((TOK) >= CS_TOKEN_FLAG)
  30. #define sym2tok(SYM)        ((tok) (CS_TOKEN_FLAG + (char *) (SYM)))
  31. #define tok2sym(TOK)        ((sym) ((TOK) - CS_TOKEN_FLAG))
  32. #define END_TEMPLATE_TOKEN    sym2tok(FROZEN_END_TEMPLATE)
  33.  
  34. #define NO_EXPAND_FLAG        257
  35.  
  36. #define null_tok ((tok) 0)
  37.  
  38. global    tok    cur_tok;
  39. global    tok    par_tok;
  40.  
  41. global    int    cur_cmd;
  42. global    int    cur_chr;
  43.  
  44. void    get_token();
  45. void    get_next();
  46. void    get_cs();
  47. void    check_outer_validity();
  48. void    firm_up_the_line();
  49.  
  50. #define end_line_char_active    (end_line_char >= 0 && end_line_char <= 255)
  51.  
  52. global    bool    force_eof;
  53. global    int    open_parens;
  54. global    int    align_state;
  55. global    int    scanner_status;
  56.  
  57. #define SKIPPING    1
  58. #define DEFINING    2
  59. #define MATCHING    3
  60. #define ALIGNING    4
  61. #define ABSORBING    5
  62.  
  63. global    ptr    null_list;
  64. global    ptr    def_ref;
  65. global    ptr    match_toks;
  66. global    ptr    align_toks;
  67. global    ptr    omit_template;
  68.  
  69. struct input {
  70.     short    state_field;
  71.     short    type_field;
  72.     union {
  73.         struct {
  74.             sym    in_cs_field;
  75.             ptr    start_field;
  76.             ptr    loc_field;
  77.             ptr    *param_field;
  78.         } t;
  79.         struct {
  80.             ptr    in_open_field;
  81.             byte    *buf_field;
  82.             byte    *next_field;
  83.             byte    *limit_field;
  84.         } f;
  85.     } obj_field;
  86. };
  87. typedef struct input input;
  88.  
  89. global    input    cur_input;
  90. global    input    *input_stack;
  91. global    input    *input_end;
  92. global    input    *input_ptr;
  93. global    input    *base_ptr;
  94. global    input    *max_in_stack;
  95.  
  96. #define state        cur_input.state_field
  97.  
  98. #define MID_LINE    1
  99. #define SKIP_BLANKS    (2 + MAX_CHAR_CODE)
  100. #define NEW_LINE    (3 + MAX_CHAR_CODE + MAX_CHAR_CODE)
  101.  
  102. #define file_state    (state != TOKEN_LIST)
  103.  
  104. #define index        cur_input.type_field
  105. #define in_file        cur_input.obj_field.f.in_open_field
  106. #define buffer        cur_input.obj_field.f.buf_field
  107. #define next        cur_input.obj_field.f.next_field
  108. #define limit        cur_input.obj_field.f.limit_field
  109.  
  110. #define BUF_SIZE        4096
  111.  
  112. #define terminal_input    (index == 0)
  113.  
  114. struct infile {
  115.     file    file_field;
  116.     str    name_field;
  117.     int    line_field;
  118. };
  119. typedef struct infile infile;
  120.  
  121. #define cur_file    ((infile *) in_file)->file_field
  122. #define file_name    ((infile *) in_file)->name_field
  123. #define file_line    ((infile *) in_file)->line_field
  124.  
  125. global    str    name;
  126. global    int    line;
  127.  
  128. global    infile    *file_stack;
  129. global    infile    *file_end;
  130. global    infile    *file_ptr;
  131. global    infile    *max_file_stack;
  132.  
  133. #define TOKEN_LIST    0
  134.  
  135. #define token_type    cur_input.type_field
  136. #define in_cs        cur_input.obj_field.t.in_cs_field
  137. #define start        cur_input.obj_field.t.start_field
  138. #define loc        cur_input.obj_field.t.loc_field
  139. #define param_start    cur_input.obj_field.t.param_field
  140.  
  141. #define cs_name        text(in_cs)
  142.  
  143. #define PARAMETER        0
  144. #define U_TEMPLATE        1
  145. #define V_TEMPLATE        2
  146. #define BACKED_UP        3
  147. #define INSERTED        4
  148. #define MACRO            5
  149. #define OUTPUT_TEXT        6
  150. #define EVERY_PAR_TEXT        7
  151. #define EVERY_MATH_TEXT        8
  152. #define EVERY_DISPLAY_TEXT    9
  153. #define EVERY_HBOX_TEXT        10
  154. #define EVERY_VBOX_TEXT        11
  155. #define EVERY_JOB_TEXT        12
  156. #define EVERY_CR_TEXT        13
  157. #define MARK_TEXT        14
  158. #define WRITE_TEXT        15
  159.  
  160. global    int    nparams;
  161. global    ptr    *param_stack;
  162. global    ptr    *param_end;
  163. global    ptr    *param_ptr;
  164. global    ptr    *max_param_stack;
  165.  
  166. void    push_input();
  167. void    pop_input();
  168. void    begin_token_list();
  169. void    end_token_list();
  170. void    begin_file_reading();
  171. void    end_file_reading();
  172. void    back_input();
  173. void    back_error();
  174. void    ins_error();
  175. void    runaway();
  176. void    show_context();
  177. void    clear_for_error_prompt();
  178.  
  179. #define new_token    new_avail
  180. #define free_token    free_avail
  181.  
  182. #define back_list(L)    begin_token_list(L, BACKED_UP)
  183. #define ins_list(L)    begin_token_list(L, INSERTED)
  184.  
  185. void    _tok_init();
  186. void    _tok_init_once();
  187.