LaTeX for Xenix (14 of 14)
G Geers
glenn at extro.ucc.su.oz.au
Fri Feb 16 10:44:43 AEST 1990
---- Cut Here and unpack ----
#!/bin/sh
# this is part 14 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file token.c continued
#
CurArch=14
if test ! -r s2_seq_.tmp
then echo "Please unpack part 1 first!"
exit 1; fi
( read Scheck
if test "$Scheck" != $CurArch
then echo "Please unpack part $Scheck next!"
exit 1;
else exit 0; fi
) < s2_seq_.tmp || exit 1
echo "x - Continuing file token.c"
sed 's/^X//' << 'SHAR_EOF' >> token.c
X k = loc;
X cur_chr = buffer[k];
X cat = cat_code(cur_chr);
X incr(k);
X if (cat == LETTER)
X state = SKIP_BLANKS;
X else if (cat == SPACER)
X state = SKIP_BLANKS;
X else state = MID_LINE;
X if (cat == LETTER && k <= limit) {
X do {
X cur_chr = buffer[k];
X incr(k);
X cat = cat_code(cur_chr);
X } while (cat == LETTER && k <= limit);
X reduce_expanded_cc();
X if (cat != LETTER)
X decr(k);
X if (k > loc + 1) {
X cur_cs = id_lookup(loc, k - loc);
X loc = k;
X goto found;
X }
X } else reduce_expanded_cc();
X cur_cs = SINGLE_BASE + buffer[loc];
X incr(loc);
X }
X found:
X cur_cmd = eq_type(cur_cs);
X cur_chr = equiv(cur_cs);
X if (cur_cmd >= OUTER_CALL)
X check_outer_validity();
X break;
X
X any_state(ACTIVE_CHAR):
X cur_cs = cur_chr + ACTIVE_BASE;
X cur_cmd = eq_type(cur_cs);
X cur_chr = equiv(cur_cs);
X state = MID_LINE;
X if (cur_cmd >= OUTER_CALL)
X check_outer_validity();
X break;
X
X any_state(SUP_MARK):
X if (cur_chr == buffer[loc] && loc < limit) {
X if (buffer[loc + 1] < 0100)
X cur_chr = buffer[loc + 1] + 0100;
X else cur_chr = buffer[loc + 1] - 0100;
X loc += 2;
X goto reswitch;
X }
X state = MID_LINE;
X break;
X
X any_state(INVALID_CHAR):
X print_err("Text line contains an invalid character");
X help_funny();
X deletions_allowed = FALSE;
X error();
X deletions_allowed = TRUE;
X goto restart;
X break;
X
X mid_line(SPACER):
X state = SKIP_BLANKS;
X cur_chr = ' ';
X break;
X
X mid_line(CAR_RET):
X loc = limit + 1;
X cur_cmd = SPACER;
X cur_chr = ' ';
X break;
X
X skip_blanks(CAR_RET):
X any_state(COMMENT):
X loc = limit + 1;
X goto reread;
X break;
X
X new_line(CAR_RET):
X loc = limit + 1;
X cur_cs = par_loc;
X cur_cmd = eq_type(cur_cs);
X cur_chr = equiv(cur_cs);
X if (cur_cmd >= OUTER_CALL)
X check_outer_validity();
X break;
X
X mid_line(LEFT_BRACE):
X incr(align_state);
X break;
X
X skip_blanks(LEFT_BRACE):
X new_line(LEFT_BRACE):
X state = MID_LINE;
X incr(align_state);
X break;
X
X mid_line(RIGHT_BRACE):
X decr(align_state);
X break;
X
X skip_blanks(RIGHT_BRACE):
X new_line(RIGHT_BRACE):
X state = MID_LINE;
X decr(align_state);
X break;
X
X delims(SKIP_BLANKS):
X delims(NEW_LINE):
X state = MID_LINE;
X break;
X
X default:
X break;
X }
X } else {
X state = NEW_LINE;
X if (name > 17) {
X incr(line);
X first = start;
X if (!force_eof) {
X if (input_ln(cur_file, TRUE))
X firm_up_the_line();
X else force_eof = TRUE;
X }
X if (force_eof) {
X print_char(')');
X force_eof = FALSE;
X update_terminal();
X end_file_reading();
X check_outer_validity();
X goto restart;
X }
X if (end_line_char < 0 || end_line_char > 127)
X decr(limit);
X else buffer[limit] = end_line_char;
X first = limit + 1;
X loc = start;
X } else {
X if (!terminal_input) {
X cur_cmd = 0;
X cur_chr = 0;
X return;
X }
X if (input_ptr > 0) {
X end_file_reading();
X goto restart;
X }
X if (selector < LOG_ONLY)
X open_log_file();
X if (interaction > NONSTOP_MODE) {
X if (limit == start)
X print_nl("(Please type a command or say `\\end')");
X print_ln();
X first = start;
X prompt_input("*");
X limit = last;
X if (end_line_char < 0 || end_line_char > 127)
X decr(limit);
X else buffer[limit] = end_line_char;
X first = limit + 1;
X loc = start;
X } else
X fatal_error(
X "*** (job aborted, no legal \\end found)");
X }
X check_interrupt();
X goto reread;
X }
X } else {
X if (loc != NULL) {
X t = token(loc);
X loc = token_link(loc);
X if (t >= CS_TOKEN_FLAG) {
X cur_cs = t - CS_TOKEN_FLAG;
X cur_cmd = eq_type(cur_cs);
X cur_chr = equiv(cur_cs);
X if (cur_cmd >= OUTER_CALL) {
X if (cur_cmd == DONT_EXPAND) {
X cur_cs = token(loc) - CS_TOKEN_FLAG;
X loc = NULL;
X cur_cmd = eq_type(cur_cs);
X cur_chr = equiv(cur_cs);
X if (cur_cmd > MAX_COMMAND) {
X cur_cmd = RELAX;
X cur_chr = NO_EXPAND_FLAG;
X }
X } else check_outer_validity();
X }
X } else {
X cur_cmd = t / 0400;
X cur_chr = t % 0400;
X switch (cur_cmd)
X {
X case LEFT_BRACE:
X incr(align_state);
X break;
X
X case RIGHT_BRACE:
X decr(align_state);
X break;
X
X case OUT_PARAM:
X begin_token_list(
X param_stack[param_start + cur_chr - 1],
X PARAMETER);
X goto restart;
X break;
X
X default:
X break;
X }
X }
X } else {
X end_token_list();
X goto restart;
X }
X }
X if (cur_cmd <= CAR_RET &&
X cur_cmd >= TAB_MARK &&
X align_state == 0) {
X if (scanner_status == ALIGNING)
X fatal_error("(interwoven alignment preambles are not allowed)");
X cur_cmd = extra_info(cur_align);
X extra_info(cur_align) = cur_chr;
X if (cur_cmd == OMIT)
X begin_token_list(omit_template, (qword) V_TEMPLATE);
X else begin_token_list((ptr) v_part(cur_align), (qword) V_TEMPLATE);
X align_state = 1000000;
X goto restart;
X }
X}
X
Xcheck_outer_validity ()
X{
X ptr p;
X ptr q;
X
X if (scanner_status != NORMAL) {
X deletions_allowed = FALSE;
X if (cur_cs != 0) {
X if (state == TOKEN_LIST || name < 1 || name > 17) {
X p = new_token();
X token(p) = CS_TOKEN_FLAG + cur_cs;
X back_list(p);
X }
X cur_cmd = SPACER;
X cur_chr = ' ';
X }
X if (scanner_status > SKIPPING) {
X runaway();
X if (cur_cs == 0)
X print_err("File ended");
X else {
X cur_cs = 0;
X print_err("Forbidden control sequence found");
X }
X print(" while scanning ");
X p = new_token();
X switch (scanner_status)
X {
X case DEFINING:
X print("definition");
X token(p) = RIGHT_BRACE_TOKEN + '}';
X break;
X
X case MATCHING:
X print("use");
X token(p) = par_token;
X long_state = OUTER_CALL;
X break;
X
X case ALIGNING:
X print("preamble");
X token(p) = RIGHT_BRACE_TOKEN + '}';
X q = p;
X p = new_token();
X token_link(p) = q;
X token(p) = CS_TOKEN_FLAG + FROZEN_CR;
X align_state = -1000000;
X break;
X
X case ABSORBING:
X print("text");
X token(p) = RIGHT_BRACE_TOKEN + '}';
X break;
X }
X ins_list(p);
X print(" of ");
X sprint_cs(warning_index);
X help_scanner();
X error();
X } else {
X print_err("Incomplete ");
X print_cmd_chr(IF_TEST, cur_if);
X print("; all text was ignored after line ");
X print_val(skip_line);
X help_skif();
X if (cur_cs != 0)
X cur_cs = 0;
X else
X help_line[0] =
X "The file ended while I was skipping conditional text.";
X cur_tok = CS_TOKEN_FLAG + FROZEN_FI;
X ins_error();
X }
X deletions_allowed = TRUE;
X }
X}
X
Xfirm_up_the_line ()
X{
X int k;
X
X limit = last;
X if (pausing > 0 && interaction > NONSTOP_MODE) {
X wake_up_terminal();
X print_ln();
X if (start < limit) {
X for (k = start; k < limit; incr(k))
X print_char(buffer[k]);
X }
X first = limit;
X prompt_input("=>");
X if (last > first) {
X for (k = first; k < last; incr(k))
X buffer[k + start - first] = buffer[k];
X limit = start + last - first;
X }
X }
X}
X
Xptr
Xnew_token ()
X{
X ptr p;
X
X p = tok_head;
X if (p != NULL)
X tok_head = token_link(tok_head);
X else if (tok_end < TOK_MAX) {
X incr(tok_end);
X p = tok_end;
X } else {
X decr(tok_low);
X p = tok_low;
X if (tok_low <= TOK_MIN) {
X runaway();
X overflow("token memory size", TOK_MAX - TOK_MIN + 1);
X }
X }
X token_link(p) = NULL;
X#ifdef STAT
X incr(tok_used);
X#endif
X return p;
X}
X
Xinit_tok_mem()
X{
X int i;
X
X#ifdef INIT
X tok_head = NULL;
X tok_end = TOK_TOP;
X tok_low = tok_high;
X for (i = TOK_TOP; i > tok_low; decr(i)) {
X token(i) = 0;
X token_link(i) = NULL;
X }
X token(omit_template) = END_TEMPLATE_TOKEN;
X tok_used = tok_usage;
X#endif
X
X}
X
X/*
X * Help text
X */
X
Xhelp_scanner ()
X{
X help4("I suspect you have forgotten a `}', causing me",
X "to read past where you wanted me to stop.",
X "I'll try to recover; but if the error is serious,",
X "you'd better type `E' or `X' now and fix your file.");
X}
X
Xhelp_funny ()
X{
X help2("A funny symbol that I can't read has just been input.",
X "Continue, and I'll forget that it ever happened.");
X}
X
Xhelp_skif ()
X{
X help3("A forbidden control sequence occurred in skipped text.",
X "This kind of error happens when you say `\\if...' and forget",
X "the matching `\\fi'. I've inserted a `\\fi'; this might work.");
X}
SHAR_EOF
echo "File token.c is complete"
chmod 0444 token.c || echo "restore of token.c fails"
set `wc -c token.c`;Sum=$1
if test "$Sum" != "10484"
then echo original size 10484, current size $Sum;fi
echo "x - extracting token.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > token.h &&
X
X/*
X * Copyright 1986, 1987 Pat Joseph Monardo. All rights reserved.
X * Copying of this file is granted according to the provisions
X * specified in the file COPYING which must accompany this file.
X */
X
X
X/*
X * token.h
X */
X
Xglobal hword cur_tok;
Xglobal byte cur_cmd;
Xglobal hword cur_chr;
Xglobal ptr cur_cs;
X
X#define LEFT_BRACE_TOKEN 0400
X#define LEFT_BRACE_LIMIT 01000
X#define RIGHT_BRACE_TOKEN 01000
X#define RIGHT_BRACE_LIMIT 01400
X#define MATH_SHIFT_TOKEN 01400
X#define TAB_TOKEN 02000
X#define OUT_PARAM_TOKEN 02400
X#define SPACE_TOKEN 05040
X#define LETTER_TOKEN 05400
X#define OTHER_TOKEN 06000
X#define MATCH_TOKEN 06400
X#define END_MATCH_TOKEN 07000
X#define CS_TOKEN_FLAG 010000
X#define END_TEMPLATE_TOKEN CS_TOKEN_FLAG + FROZEN_END_TEMPLATE
X
X#define NO_EXPAND_FLAG 257
X
Xglobal ptr par_loc;
Xglobal hword par_token;
Xglobal bool force_eof;
X
X#define token(T) tok[T]
X#define token_link(T) tok_link[T]
X
Xglobal hword tok[];
Xglobal hword tok_link[];
Xglobal ptr tok_head;
Xglobal ptr tok_low;
Xglobal ptr tok_end;
Xglobal int tok_used;
X
X#define temp_toks TOK_TOP
X#define align_tokens (TOK_TOP - 1)
X#define omit_template (TOK_TOP - 2)
X#define null_list (TOK_TOP - 3)
X#define backup_tokens (TOK_TOP - 4)
X#define tok_high (TOK_TOP - 4)
X#define tok_usage 5
X
X#ifdef STAT
X#define fast_new_token(T) \
X {T = tok_head; \
X if (T == NULL) T = new_token(); \
X else {tok_head = token_link(T); token_link(T) = NULL; incr(tok_used);}}
X#else
X#define fast_new_token(T) \
X {T = tok_head; \
X if (T == NULL) T = new_token(); \
X else {tok_head = token_link(T); token_link(T) = NULL;}}
X#endif
X
Xint get_token();
Xint get_next();
Xptr new_token();
X
X#ifdef STAT
X#define free_token(T) \
X {token_link(T) = tok_head; tok_head = T; decr(tok_used);}
X#else
X#define free_token(T) \
X {token_link(T) = tok_head; tok_head = T;}
X#endif
X
Xint check_outer_validity();
Xint firm_up_the_line();
SHAR_EOF
chmod 0444 token.h || echo "restore of token.h fails"
set `wc -c token.h`;Sum=$1
if test "$Sum" != "1877"
then echo original size 1877, current size $Sum;fi
echo "x - extracting tokenlists.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > tokenlists.c &&
X
X/*
X * Copyright 1986, 1987 Pat Joseph Monardo. All rights reserved.
X * Copying of this file is granted according to the provisions
X * specified in the file COPYING which must accompany this file.
X */
X
X
X/*
X * tokenlists.c
X */
X
X#include "tex.h"
X#include "cmds.h"
X#include "heap.h"
X#include "eq.h"
X#include "hash.h"
X#include "str.h"
X#include "box.h"
X#include "token.h"
X#include "expand.h"
X#include "tokenstack.h"
X#include "io.h"
X#include "scan.h"
X#include "def.h"
X#include "file.h"
X#include "tfm.h"
X#include "print.h"
X#include "error.h"
X#include "tokenlists.h"
X
Xptr
Xstr_toks ()
X{
X int k;
X ptr p;
X ptr q;
X hword t;
X
X str_room(1);
X p = temp_toks;
X token_link(p) = NULL;
X k = str_start[str_ptr];
X while (k < pool_ptr) {
X t = str_pool[k];
X if (t == ' ')
X t = SPACE_TOKEN;
X else t += OTHER_TOKEN;
X fast_store_new_token(t);
X incr(k);
X }
X pool_ptr = str_start[str_ptr];
X return p;
X}
X
Xptr
Xthe_toks ()
X{
X ptr p;
X ptr q;
X ptr r;
X int old_setting;
X
X get_x_token();
X scan_something_internal(TOK_VAL, FALSE);
X if (cur_val_level >= IDENT_VAL) {
X p = temp_toks;
X token_link(p) = NULL;
X if (cur_val_level == IDENT_VAL)
X {store_new_token(CS_TOKEN_FLAG + cur_val);}
X else if (cur_val != NULL) {
X r = token_link(cur_val);
X while (r != NULL) {
X fast_store_new_token(token(r));
X r = token_link(r);
X }
X }
X return p;
X } else {
X old_setting = selector;
X selector = NEW_STRING;
X switch (cur_val_level)
X {
X case INT_VAL:
X print_val(cur_val);
X break;
X
X case DIMEN_VAL:
X print_scaled(cur_val);
X print("pt");
X break;
X
X case GLUE_VAL:
X print_spec((ptr) cur_val, "pt");
X delete_glue_ref((ptr) cur_val);
X break;
X
X case MU_VAL:
X print_spec((ptr) cur_val,"mu");
X delete_glue_ref((ptr) cur_val);
X break;
X }
X selector = old_setting;
X return (str_toks());
X }
X}
X
Xins_the_toks ()
X{
X the_toks();
X ins_list(token_link(temp_toks));
X}
X
Xconv_toks ()
X{
X int c;
X int old_setting;
X int save_scanner_status;
X
X c = cur_chr;
X switch (c)
X {
X case NUMBER_CODE:
X case ROMAN_NUMERAL_CODE:
X scan_int();
X break;
X
X case STRING_CODE:
X case MEANING_CODE:
X save_scanner_status = scanner_status;
X scanner_status = NORMAL;
X get_token();
X scanner_status = save_scanner_status;
X break;
X
X case FONT_NAME_CODE:
X scan_font_ident();
X break;
X
X case JOB_NAME_CODE:
X if (job_name == 0)
X open_log_file();
X break;
X }
X old_setting = selector;
X selector = NEW_STRING;
X switch (c)
X {
X case NUMBER_CODE:
X print_val(cur_val);
X break;
X
X case ROMAN_NUMERAL_CODE:
X print_roman_int(cur_val);
X break;
X
X case STRING_CODE:
X if (cur_cs != 0)
X sprint_cs(cur_cs);
X else print_char((ascii) cur_chr);
X break;
X
X case MEANING_CODE:
X print_meaning();
X break;
X
X case FONT_NAME_CODE:
X print_str(font_name[cur_val]);
X if (font_size[cur_val] != font_dsize[cur_val]) {
X print(" at ");
X print_scaled(font_size[cur_val]);
X print("pt");
X }
X break;
X
X case JOB_NAME_CODE:
X print_str(job_name);
X break;
X }
X selector = old_setting;
X str_toks();
X ins_list(token_link(temp_toks));
X}
X
Xptr
Xscan_toks (macro_def, xpand)
X bool macro_def;
X bool xpand;
X{
X ptr p;
X ptr q;
X hword s;
X hword t;
X int unbalance;
X hword hash_brace;
X
X if (macro_def)
X scanner_status = DEFINING;
X else scanner_status = ABSORBING;
X warning_index = cur_cs;
X def_ref = new_token();
X token_ref_count(def_ref) = NULL;
X p = def_ref;
X hash_brace = 0;
X t = ZERO_TOKEN;
X if (macro_def) {
X loop {
X get_token();
X if (cur_tok < RIGHT_BRACE_LIMIT)
X break;
X if (cur_cmd == MAC_PARAM) {
X s = MATCH_TOKEN + cur_chr;
X get_token();
X if (cur_cmd == LEFT_BRACE) {
X hash_brace = cur_tok;
X store_new_token(cur_tok);
X store_new_token(END_MATCH_TOKEN);
X goto done;
X }
X if (t == ZERO_TOKEN + 9) {
X print_err("You already have nine parameters");
X help_param_count();
X error();
X } else {
X incr(t);
X if (cur_tok != t) {
X print_err("Parameters must be numbered consecutively");
X help_param_num();
X back_error();
X }
X cur_tok = s;
X }
X }
X store_new_token(cur_tok);
X }
X store_new_token(END_MATCH_TOKEN);
X if (cur_cmd == RIGHT_BRACE) {
X print_err("Missing { inserted");
X incr(align_state);
X help_left_brace();
X error();
X goto found;
X }
X } else
X scan_left_brace();
X
Xdone:
X unbalance = 1;
X loop {
X if (xpand) {
X loop {
X get_next();
X if (cur_cmd <= MAX_COMMAND)
X break;
X if (cur_cmd != THE)
X expand();
X else {
X q = the_toks();
X if (token_link(temp_toks) != NULL) {
X token_link(p) = token_link(temp_toks);
X p = q;
X }
X }
X }
X x_token();
X } else get_token();
X if (cur_tok < RIGHT_BRACE_LIMIT) {
X if (cur_cmd < RIGHT_BRACE)
X incr(unbalance);
X else {
X decr(unbalance);
X if (unbalance == 0)
X break;
X }
X } else if (cur_cmd == MAC_PARAM && macro_def) {
X s = cur_tok;
X if (xpand)
X get_x_token();
X else get_token();
X if (cur_cmd != MAC_PARAM) {
X if (cur_tok <= ZERO_TOKEN || cur_tok > t) {
X print_err("Illegal parameter number in definition of ");
X sprint_cs(warning_index);
X help_param_use();
X back_error();
X cur_tok = s;
X } else
X cur_tok = OUT_PARAM_TOKEN + cur_chr - '0';
X }
X }
X store_new_token(cur_tok);
X }
X
Xfound:
X scanner_status = NORMAL;
X if (hash_brace != 0)
X store_new_token(hash_brace);
X return p;
X}
X
Xread_toks (n, r)
X int n;
X ptr r;
X{
X int m;
X ptr p;
X ptr q;
X val s;
X
X scanner_status = DEFINING;
X warning_index = r;
X def_ref = new_token();
X token_ref_count(def_ref) = NULL;
X p = def_ref;
X store_new_token(END_MATCH_TOKEN);
X if (n < 0 || n > 15)
X m = 16;
X else m = n;
X s = align_state;
X align_state = 1000000;
X do {
X begin_file_reading();
X name = m + 1;
X if (read_open[m] == CLOSED) {
X if (interaction > NONSTOP_MODE) {
X if (n < 0) {
X prompt_input("");
X } else {
X wake_up_terminal();
X print_ln();
X sprint_cs(r);
X prompt_input("=");
X n = -1;
X }
X } else
X fatal_error
X ("*** (cannot \\read from terminal in nonstop modes)");
X } else if (read_open[m] == JUST_OPENED) {
X if (input_ln(read_file[m], FALSE))
X read_open[m] = NORMAL;
X else {
X a_close(read_file[m]);
X read_open[m] = CLOSED;
X }
X } else {
X if (!input_ln(read_file[m], TRUE)) {
X a_close(read_file[m]);
X read_open[m] = CLOSED;
X if (align_state != 1000000) {
X runaway();
X print_err("File ended within ");
X print_esc("read");
X help_read();
X align_state = 1000000;
X error();
X }
X }
X }
X limit = last;
X if (end_line_char < 0 || end_line_char > 127)
X decr(limit);
X else buffer[limit] = end_line_char;
X first = limit + 1;
X loc = start;
X state = NEW_LINE;
X loop {
X get_token();
X if (cur_tok == 0)
X break;
X store_new_token(cur_tok);
X }
X end_file_reading();
X } while (align_state != 1000000);
X cur_val = def_ref;
X scanner_status = NORMAL;
X align_state = s;
X}
X
Xshow_token_list (p, q, l)
X ptr p;
X ptr q;
X val l;
X{
X hword c;
X hword m;
X ascii n;
X ascii match_chr;
X
X match_chr = '#';
X n = '0';
X for (tally = 0; p != NULL && tally < l; p = token_link(p)) {
X if (p == q)
X magic_c();
X if (p > tok_end) {
X print_esc("CLOBBERED.");
X return;
X }
X if (token(p) >= CS_TOKEN_FLAG)
X print_cs(token(p) - CS_TOKEN_FLAG);
X else {
X m = token(p) / 0400;
X c = token(p) % 0400;
X if (token(p) < 0 || c > 127)
X print_esc("BAD.");
X else {
X switch (m)
X {
X case LEFT_BRACE:
X case RIGHT_BRACE:
X case MATH_SHIFT:
X case TAB_MARK:
X case SUP_MARK:
X case SUB_MARK:
X case SPACER:
X case LETTER:
X case OTHER_CHAR:
X print_char(c);
X break;
X
X case MAC_PARAM:
X print_str(c);
X print_str(c);
X break;
X
X case OUT_PARAM:
X print_str(match_chr);
X if (c <= 9)
X print_char(c + '0');
X else {
X print_char('!');
X return;
X }
X break;
X
X case MATCH:
X match_chr = c;
X print_str(c);
X incr(n);
X print_char(n);
X if (n > '9')
X return;
X break;
X
X case END_MATCH:
X print("->");
X break;
X
X default:
X print_esc("BAD.");
X break;
X }
X }
X }
X }
X if (p != NULL)
X print_esc("ETC.");
X}
X
Xtoken_show (p)
X ptr p;
X{
X if (p == NULL)
X print("(null)");
X else show_token_list(token_link(p), NULL, 1000L);
X}
X
Xprint_meaning ()
X{
X print_cmd_chr(cur_cmd, cur_chr);
X if (cur_cmd >= CALL) {
X print_char(':');
X print_ln();
X token_show(cur_chr);
X } else if (cur_cmd == TOP_BOT_MARK) {
X print_char(':');
X print_ln();
X token_show(cur_mark[cur_chr]);
X }
X}
X
Xflush_list (p)
X ptr p;
X{
X ptr q;
X ptr r;
X
X if (p != NULL) {
X r = p;
X do {
X q = r;
X r = token_link(r);
X#ifdef STAT
X decr(tok_used);
X#endif
X } while (r != NULL);
X token_link(q) = tok_head;
X tok_head = p;
X }
X}
X
X/*
X * Help text
X */
X
Xhelp_param_num ()
X{
X help2("I've inserted the digit you should have used after the #.",
X "Type `1' to delete what you did use.");
X}
X
Xhelp_param_count ()
X{
X help1("I'm going to ignore the # sign you just used.");
X}
X
Xhelp_left_brace ()
X{
X help2("Where was the left brace? You said something like `\\def\\a}',",
X "which I'm going to interpret as `\\def\\a{}'.");
X}
X
Xhelp_param_use ()
X{
X help3("You meant to type ## instead of #, right?",
X "Or maybe a } was forgotten somewhere earlier, and things",
X "are all screwed up? I'm going to assume you meant ##.");
X}
X
Xhelp_read ()
X{
X help1("This \\read has unbalanced braces.");
X}
SHAR_EOF
chmod 0444 tokenlists.c || echo "restore of tokenlists.c fails"
set `wc -c tokenlists.c`;Sum=$1
if test "$Sum" != "9302"
then echo original size 9302, current size $Sum;fi
echo "x - extracting tokenlists.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > tokenlists.h &&
X
X/*
X * Copyright 1986, 1987 Pat Joseph Monardo. All rights reserved.
X * Copying of this file is granted according to the provisions
X * specified in the file COPYING which must accompany this file.
X */
X
X
X/*
X * tokenlists.h
X */
X
Xptr str_toks();
Xptr the_toks();
Xint conv_toks();
X
X#define NUMBER_CODE 0
X#define ROMAN_NUMERAL_CODE 1
X#define STRING_CODE 2
X#define MEANING_CODE 3
X#define FONT_NAME_CODE 4
X#define JOB_NAME_CODE 5
X
X#define token_ref_count(T) token(T)
X
Xptr scan_toks();
Xint read_toks();
Xint ins_the_toks();
Xint print_meaning();
X
Xint flush_list();
X
X#define add_token_ref(T) incr(token_ref_count(T))
X
X#define delete_token_ref(T) \
X {if (token_ref_count(T) == NULL) \
X flush_list(T); \
X else decr(token_ref_count(T));}
X
X#define store_new_token(T) \
X {q = new_token(); token_link(p) = q; token(q) = T; p = q;}
X
X#define fast_store_new_token(T) \
X {fast_new_token(q); token_link(p) = q; token(q) = T; p = q;}
X
Xint show_token_list();
Xint token_show();
SHAR_EOF
chmod 0444 tokenlists.h || echo "restore of tokenlists.h fails"
set `wc -c tokenlists.h`;Sum=$1
if test "$Sum" != "981"
then echo original size 981, current size $Sum;fi
echo "x - extracting tokenstack.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > tokenstack.c &&
X
X/*
X * Copyright 1986, 1987 Pat Joseph Monardo. All rights reserved.
X * Copying of this file is granted according to the provisions
X * specified in the file COPYING which must accompany this file.
X */
X
X
X/*
X * tokenstack.c
X */
X
X#include "tex.h"
X#include "cmds.h"
X#include "heap.h"
X#include "eq.h"
X#include "def.h"
X#include "char.h"
X#include "io.h"
X#include "token.h"
X#include "tokenlists.h"
X#include "box.h"
X#include "print.h"
X#include "error.h"
X#include "tokenstack.h"
X
Xinput cur_input;
Xinput input_stack[STACK_SIZE];
Xptr input_ptr;
Xptr max_in_stack;
X
Xalpha_file input_file[MAX_IN_OPEN];
X
Xval line;
Xval line_stack[MAX_IN_OPEN];
Xptr in_open;
X
Xptr param_stack[PARAM_SIZE];
Xptr param_ptr;
Xptr max_param_stack;
X
Xval align_state = 1000000;
Xptr base_ptr;
Xptr def_ref;
Xptr warning_index;
Xint scanner_status;
X
Xpush_input()
X{
X if (input_ptr > max_in_stack) {
X max_in_stack = input_ptr;
X if (input_ptr == STACK_SIZE)
X overflow("input stack size", STACK_SIZE);
X }
X input_stack[input_ptr] = cur_input;
X incr(input_ptr);
X}
X
Xpop_input()
X{
X decr(input_ptr);
X cur_input = input_stack[input_ptr];
X}
X
Xbegin_token_list (p, t)
X ptr p;
X qword t;
X{
X push_input();
X state = TOKEN_LIST;
X start = p;
X token_type = t;
X if (t >= MACRO) {
X add_token_ref(p);
X if (t == MACRO)
X param_start = param_ptr;
X else {
X loc = token_link(p);
X if (tracing_macros > 1) {
X begin_diagnostic();
X print_ln();
X switch (t)
X {
X case MARK_TEXT:
X print_esc("mark");
X break;
X
X case WRITE_TEXT:
X print_esc("write");
X break;
X
X default:
X print_cmd_chr (ASSIGN_TOKS,
X t - OUTPUT_TEXT + OUTPUT_ROUTINE_LOC);
X break;
X }
X print("->");
X token_show(p);
X end_diagnostic(FALSE);
X }
X }
X } else
X loc = p;
X}
X
Xend_token_list ()
X{
X if (token_type >= BACKED_UP) {
X if (token_type <= INSERTED)
X flush_list(start);
X else {
X delete_token_ref(start);
X if (token_type == MACRO) {
X while (param_ptr > param_start) {
X decr(param_ptr);
X flush_list(param_stack[param_ptr]);
X }
X }
X }
X } else if (token_type == U_TEMPLATE)
X align_state = 0;
X pop_input();
X check_interrupt();
X}
X
Xback_input ()
X{
X ptr p;
X
X while (state == TOKEN_LIST && loc == NULL)
X end_token_list();
X p = new_token();
X token(p) = cur_tok;
X if (cur_tok < RIGHT_BRACE_LIMIT)
X if (cur_tok < LEFT_BRACE_LIMIT)
X decr(align_state);
X else incr(align_state);
X push_input();
X state = TOKEN_LIST;
X start = p;
X token_type = BACKED_UP;
X loc = p;
X}
X
Xback_error ()
X{
X OK_to_interrupt = FALSE;
X back_input();
X OK_to_interrupt = TRUE;
X error();
X}
X
Xins_error ()
X{
X OK_to_interrupt = FALSE;
X back_input();
X token_type = INSERTED;
X OK_to_interrupt = TRUE;
X error();
X}
X
Xclear_for_error_prompt ()
X{
X while (state != TOKEN_LIST &&
X terminal_input &&
X input_ptr > 0 &&
X loc > limit)
X end_file_reading();
X print_ln();
X clear_terminal();
X}
X
Xbegin_file_reading ()
X{
X incr(in_open);
X if (in_open == MAX_IN_OPEN)
X overflow("text input levels", MAX_IN_OPEN);
X if (first == BUF_SIZE)
X overflow("buffer_size", BUF_SIZE);
X push_input();
X index = in_open;
X line_stack[index] = line;
X start = first;
X state = MID_LINE;
X name = 0;
X}
X
Xend_file_reading ()
X{
X first = start;
X line = line_stack[index];
X if (name > 17)
X a_close(cur_file);
X pop_input();
X decr(in_open);
X}
X
Xrunaway ()
X{
X ptr p;
X
X if (scanner_status > SKIPPING) {
X print_nl("Runaway ");
X switch (scanner_status)
X {
X case DEFINING:
X print("definition");
X p = def_ref;
X break;
X
X case MATCHING:
X print("argument");
X p = temp_toks;
X break;
X
X case ALIGNING:
X print("preamble");
X p = align_tokens;
X break;
X
X case ABSORBING:
X print("text");
X p = def_ref;
X break;
X }
X print_char('?');
X print_ln();
X show_token_list(token_link(p), NULL, (val) ERROR_LINE - 10);
X }
X}
X
X#define begin_pseudoprint() \
X {l = tally; \
X tally = 0; \
X selector = PSEUDO; \
X trick_count = 1000000;}
X
Xshow_context ()
X{
X int i;
X int j;
X val l;
X int m;
X int n;
X int p;
X int q;
X int old_setting;
X
X base_ptr = input_ptr;
X input_stack[base_ptr] = cur_input;
X loop {
X cur_input = input_stack[base_ptr];
X if (base_ptr == input_ptr ||
X state != TOKEN_LIST ||
X token_type != BACKED_UP ||
X loc != NULL) {
X tally = 0;
X old_setting = selector;
X if (state != TOKEN_LIST) {
X if (name <= 17) {
X if (terminal_input) {
X if (base_ptr == 0)
X print_nl("<*>");
X else print_nl("<insert> ");
X } else {
X print_nl("<read ");
X if (name == 17)
X print_char('*');
X else print_int(name - 1);
X print_char('>');
X }
X } else {
X print_nl("l.");
X print_val(line);
X }
X print_char(' ');
X begin_pseudoprint();
X if (buffer[limit] == CARRIAGE_RETURN)
X j = limit;
X else j = limit + 1;
X if (j > 0) {
X for (i = start; i < j; incr(i)) {
X if (i == loc)
X set_trick_count();
X print_str(buffer[i]);
X }
X }
X } else {
X switch (token_type)
X {
X case PARAMETER:
X print_nl("<argument> ");
X break;
X
X case U_TEMPLATE:
X case V_TEMPLATE:
X print_nl("<template> ");
X break;
X
X case BACKED_UP:
X if (loc == NULL)
X print_nl("<recently read> ");
X else print_nl("<to be read again> ");
X break;
X
X case INSERTED:
X print_nl("<inserted text> ");
X break;
X
X case MACRO:
X print_ln();
X print_cs(name);
X break;
X
X case OUTPUT_TEXT:
X print_nl("<output> ");
X break;
X
X case EVERY_PAR_TEXT:
X print_nl("<everypar> ");
X break;
X
X case EVERY_MATH_TEXT:
X print_nl("<everymath> ");
X break;
X
X case EVERY_DISPLAY_TEXT:
X print_nl("<everydisplay> ");
X break;
X
X case EVERY_HBOX_TEXT:
X print_nl("<everyhbox> ");
X break;
X
X case EVERY_VBOX_TEXT:
X print_nl("<everyvbox> ");
X break;
X
X case EVERY_JOB_TEXT:
X print_nl("<everyjob >");
X break;
X
X case EVERY_CR_TEXT:
X print_nl("<everycr> ");
X break;
X
X case MARK_TEXT:
X print_nl("<mark> ");
X break;
X
X case WRITE_TEXT:
X print_nl("<write> ");
X break;
X
X default:
X print_nl("? ");
X break;
X }
X begin_pseudoprint();
X if (token_type < MACRO)
X show_token_list(start, loc, 100000);
X else show_token_list(token_link(start), loc, 100000);
X }
X selector = old_setting;
X if (trick_count == 1000000)
X set_trick_count();
X if (tally < trick_count)
X m = tally - first_count;
X else m = trick_count - first_count;
X if (l + first_count <= HALF_ERROR_LINE) {
X p = 0;
X n = l + first_count;
X } else {
X print("...");
X p = l + first_count - HALF_ERROR_LINE + 3;
X n = HALF_ERROR_LINE;
X }
X for (q = p; q < first_count; incr(q))
X print_char(trick_buf[q % ERROR_LINE]);
X print_ln();
X for (q = 1; q <= n; incr(q))
X print_char(' ');
X if (m + n <= ERROR_LINE)
X p = first_count + m;
X else p = first_count + ERROR_LINE - n - 3;
X for (q = first_count; q < p; q++)
X print_char(trick_buf[q % ERROR_LINE]);
X if (m + n > ERROR_LINE)
X print("...");
X }
X if (state != TOKEN_LIST && name > 17 || base_ptr == 0)
X break;
X decr(base_ptr);
X }
X cur_input = input_stack[input_ptr];
X}
SHAR_EOF
chmod 0444 tokenstack.c || echo "restore of tokenstack.c fails"
set `wc -c tokenstack.c`;Sum=$1
if test "$Sum" != "7066"
then echo original size 7066, current size $Sum;fi
echo "x - extracting tokenstack.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > tokenstack.h &&
X
X/*
X * Copyright 1986, 1987 Pat Joseph Monardo. All rights reserved.
X * Copying of this file is granted according to the provisions
X * specified in the file COPYING which must accompany this file.
X */
X
X
X/*
X * tokensta.h
X */
X
Xtypedef struct
X{
X qword state_field;
X qword index_field;
X hword start_field;
X hword loc_field;
X hword limit_field;
X hword name_field;
X}
X input;
X
Xglobal input cur_input;
Xglobal input input_stack[];
Xglobal ptr input_ptr;
Xglobal ptr max_in_stack;
X
X#define state cur_input.state_field
X#define index cur_input.index_field
X#define start cur_input.start_field
X#define loc cur_input.loc_field
X#define limit cur_input.limit_field
X#define name cur_input.name_field
X
X#define MID_LINE 1
X#define SKIP_BLANKS (2 + MAX_CHAR_CODE)
X#define NEW_LINE (3 + MAX_CHAR_CODE + MAX_CHAR_CODE)
X
X#define terminal_input (name == 0)
X
Xglobal alpha_file input_file[];
X
Xglobal ptr in_open;
Xglobal val line;
Xglobal val line_stack[];
X
X#define cur_file input_file[index]
X
X#define TOKEN_LIST 0
X#define param_start limit
X#define token_type index
X
X#define PARAMETER 0
X#define U_TEMPLATE 1
X#define V_TEMPLATE 2
X#define BACKED_UP 3
X#define INSERTED 4
X#define MACRO 5
X#define OUTPUT_TEXT 6
X#define EVERY_PAR_TEXT 7
X#define EVERY_MATH_TEXT 8
X#define EVERY_DISPLAY_TEXT 9
X#define EVERY_HBOX_TEXT 10
X#define EVERY_VBOX_TEXT 11
X#define EVERY_JOB_TEXT 12
X#define EVERY_CR_TEXT 13
X#define MARK_TEXT 14
X#define WRITE_TEXT 15
X
Xglobal ptr param_ptr;
Xglobal ptr param_stack[];
Xglobal ptr max_param_stack;
X
Xint runaway();
Xint show_context();
X
Xglobal val align_state;
Xglobal ptr base_ptr;
Xglobal ptr def_ref;
Xglobal ptr warning_index;
Xglobal int scanner_status;
X
X#define SKIPPING 1
X#define DEFINING 2
X#define MATCHING 3
X#define ALIGNING 4
X#define ABSORBING 5
X
X#define set_trick_count() \
X {first_count = tally; \
X trick_count = tally + 1 + ERROR_LINE - HALF_ERROR_LINE; \
X if (trick_count < ERROR_LINE) \
X trick_count = ERROR_LINE;}
X
X#define magic_c() set_trick_count()
X
Xint push_input();
Xint pop_input();
X
Xint begin_token_list();
Xint end_token_list();
X
X#define back_list(L) begin_token_list(L, BACKED_UP)
X#define ins_list(L) begin_token_list(L, INSERTED)
X
Xint back_input();
Xint back_error();
X
Xint begin_file_reading();
Xint end_file_reading();
X
Xint clear_for_error_prompt();
SHAR_EOF
chmod 0444 tokenstack.h || echo "restore of tokenstack.h fails"
set `wc -c tokenstack.h`;Sum=$1
if test "$Sum" != "2325"
then echo original size 2325, current size $Sum;fi
rm -f s2_seq_.tmp
echo "You have unpacked the last part"
exit 0
More information about the Comp.unix.xenix
mailing list