lishka@uwslh.slh.wisc.edu (Chris Lishka (hang loose...) ) (07/10/90)
Posting-number: Volume 13, Issue 121 Submitted-by: lishka@uwslh.slh.wisc.edu (Chris Lishka (hang loose...) ) Archive-name: lj2ps-1.2/part13 ---- Cut Here and unpack ---- #!/bin/sh # this is lj2ps.13 (part 13 of a multipart archive) # do not concatenate these parts, unpack them in order with /bin/sh # file scan.c continued # if touch 2>&1 | fgrep '[-amc]' > /dev/null then TOUCH=touch else TOUCH=true fi if test ! -r @shar_seq_.tmp; then echo "Please unpack part 1 first!" exit 1 fi (read Scheck if test "$Scheck" != 13; then echo "Please unpack part $Scheck next!" exit 1 else exit 0 fi ) < @shar_seq_.tmp || exit 1 echo "x - Continuing file scan.c" sed 's/^X//' << 'SHAR_EOF' >> scan.c && X /* 78 */ CSP_LW, CSP_LW, CSP_LW, CSP_US, CSP_US, CSP_US, CSP_US, CSP___, X X /* 80 */ CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, X /* 88 */ CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, X /* 90 */ CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, X /* 98 */ CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, X /* a0 */ CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, X /* a8 */ CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, X /* b0 */ CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, X /* b8 */ CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, X /* c0 */ CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, X /* c8 */ CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, X /* d0 */ CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, X /* d8 */ CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, X /* e0 */ CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, X /* e8 */ CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, X /* f0 */ CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, X /* f8 */ CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___, CSP___ X}; X X X /* Local macro definitions X */ X X /* Local function list X */ Xstatic void parse_argument(); X X /* Function bodies X */ X X /* scan() is the front_end to the scanner. It runs the proper scanner, X ** based on the value of scan_state. It returns a token number if the X ** scan was successful, or zero if the end-of-file was reached. X */ Xint Xscan() X{ X register int prev_state; /* The previous state */ X register int curr_state; /* The current state */ X X rescan: X X curr_token.storage[0] = '\0'; curr_token.length = 0; X curr_state = START; X X do{ /* Main scanning loop */ X X prev_state = curr_state; X X /* Get the next character */ X if( input.length > 0 ){ X curr_char = input.storage[--input.length]; X } X else{ X if( (curr_char = getc(in_file)) == EOF) X end_of_file = 1; X else X end_of_file = 0; X } X X#ifdef DEBUG X if( debug == 2 ) fputc(curr_char, stderr); X#endif X X if( !end_of_file ){ X X#ifdef DEBUG X if( debug == 3 ){ X switch( scan_state ){ X case SS_TEXT: X fprintf(stderr, X "TEXT curr % 3.3d (prev % 3.3d) char %c (0x%2.2x) class % 3.3d -> % 3.3d\n", X curr_state, prev_state, X curr_char, (int) curr_char, st_classes[curr_char], X st_states[curr_state][st_classes[curr_char]] X ); X break; X case SS_PARAM: X fprintf(stderr, X "TEXT curr % 3.3d (prev % 3.3d) char %c (0x%2.2x) class % 3.3d -> % 3.3d\n", X curr_state, prev_state, X curr_char, (int) curr_char, sp_classes[curr_char], X sp_states[curr_state][sp_classes[curr_char]] X ); X break; X default: X internal_error("illegal scan state in scan()", ""); X } /* switch( ... ) */ X } /* if( debug ... ) */ X#endif X X switch( scan_state ){ X case SS_TEXT: X if( (curr_state = st_states[curr_state][st_classes[curr_char]]) X == END ){ X X /* Put back character */ X if( input.length == MAX_BUFFER ){ X internal_error("you blew the put-back buffer!", ""); X } X else{ X input.storage[input.length] = curr_char; X input.length++; X } X X } X else{ X X /* Accept character */ X if( curr_token.length == MAX_BUFFER ){ X internal_error("current token is too large", ""); X } X else{ X curr_token.storage[curr_token.length] = curr_char; X curr_token.length++; X } X X } X break; X case SS_PARAM: X if( (curr_state = sp_states[curr_state][sp_classes[curr_char]]) X == END ){ X X /* Put back character */ X if( input.length == MAX_BUFFER ){ X internal_error("you blew the put-back buffer!", ""); X } X else{ X input.storage[input.length] = curr_char; X input.length++; X } X X } X else{ X X /* Accept character */ X if( curr_token.length == MAX_BUFFER ){ X internal_error("current token is too large", ""); X } X else{ X curr_token.storage[curr_token.length] = curr_char; X curr_token.length++; X } X X } X break; X default: X internal_error("illegal scan state in scan()", ""); X } /* switch(...) */ X X } /* if( !eof ) */ X else{ X X switch( scan_state ){ X case SS_TEXT: X if( (curr_state = st_states[curr_state][CST_EF]) X != END ){ X X fatal_error("end-of-file found in a command", ""); X X } X break; X case SS_PARAM: X if( (curr_state = sp_states[curr_state][CSP_EF]) X != END ){ X X fatal_error("end-of-file found in a command", ""); X X } X break; X default: X internal_error("illegal scan state in scan()", ""); X } /* switch(...) */ X X } /* else( !eof ) */ X X } while( curr_state != END ); X X /* If this point is reached, then an entire token has been scanned. X ** The token must be properly saved, and then the appropriate token X ** action must be performed. The switch() and embedded switch()'s X ** perform the necessary token actions for each state. X */ X curr_token.storage[curr_token.length] = '\0'; X switch( scan_state ){ X case SS_TEXT: X switch( prev_state ){ X case ST_TLP: scan_state = SS_TEXT; curr_token.code = TEXT_lp; break; X case ST_TRP: scan_state = SS_TEXT; curr_token.code = TEXT_rp; break; X case ST_TBS: scan_state = SS_TEXT; curr_token.code = TEXT_bslash; break; X case ST_TNL: scan_state = SS_TEXT; curr_token.code = TEXT_NEWLINE; break; X case ST_TFF: scan_state = SS_TEXT; curr_token.code = TEXT_FORMFEED;break; X case ST_UNK: X warning("LaserJet command not supported", curr_token.storage); X scan_state = SS_TEXT; goto rescan; X case ST_CEQ: scan_state = SS_TEXT; curr_token.code = CMD_eq; break; X case ST_C9 : scan_state = SS_TEXT; curr_token.code = CMD_9; break; X case ST_CZ : scan_state = SS_TEXT; curr_token.code = CMD_Z; break; X case ST_CY : scan_state = SS_TEXT; curr_token.code = CMD_Y; break; X case ST_CE : scan_state = SS_TEXT; curr_token.code = CMD_E; break; X case ST_CAa: scan_state = SS_PARAM; curr_token.code = CMD_amp_a; break; X case ST_CAd: scan_state = SS_PARAM; curr_token.code = CMD_amp_d; break; X case ST_CAf: scan_state = SS_PARAM; curr_token.code = CMD_amp_f; break; X case ST_CAk: scan_state = SS_PARAM; curr_token.code = CMD_amp_k; break; X case ST_CAl: scan_state = SS_PARAM; curr_token.code = CMD_amp_l; break; X case ST_CAp: scan_state = SS_PARAM; curr_token.code = CMD_amp_p; break; X case ST_CAs: scan_state = SS_PARAM; curr_token.code = CMD_amp_s; break; X case ST_CSt: scan_state = SS_PARAM; curr_token.code = CMD_star_t; break; X case ST_CSr: scan_state = SS_PARAM; curr_token.code = CMD_star_r; break; X case ST_CSp: scan_state = SS_PARAM; curr_token.code = CMD_star_p; break; X case ST_CSc: scan_state = SS_PARAM; curr_token.code = CMD_star_c; break; X case ST_CSb: scan_state = SS_PARAM; curr_token.code = CMD_star_b; break; X case ST_CLs: scan_state = SS_PARAM; curr_token.code = CMD_lp_s; break; X case ST_CRs: scan_state = SS_PARAM; curr_token.code = CMD_rp_s; break; X case ST_CLP: scan_state = SS_PARAM; curr_token.code = CMD_lp; break; X case ST_CRP: scan_state = SS_PARAM; curr_token.code = CMD_rp; break; X case ST_TXT: scan_state = SS_TEXT; curr_token.code = TEXT_CHAR; break; X case ST_NUL: scan_state = SS_TEXT; curr_token.code = TEXT_NULL; break; X case ST_TTB: scan_state = SS_TEXT; curr_token.code = TEXT_TAB; break; X case ST_TSI: scan_state = SS_TEXT; curr_token.code = TEXT_SH_IN; break; X case ST_TSO: scan_state = SS_TEXT; curr_token.code = TEXT_SH_OUT; break; X case ST____: X case ST_STT: X case ST_CMD: X case ST_CMA: X case ST_CMS: X default: X if( !end_of_file ){ X internal_error("illegal state in text scanner token actions", ""); X } X } /* switch( text scanner ) */ X break; X case SS_PARAM: X switch( prev_state ){ X case SP_PE : X scan_state = SS_TEXT; X curr_token.code = PARAM_END; X parse_argument(); X break; X case SP_PC : X scan_state = SS_PARAM; X curr_token.code = PARAM_CONTINUE; X parse_argument(); X break; X case SP_PEO: X scan_state = SS_TEXT; X curr_token.code = PARAM_END; X parse_argument(); X break; X case SP_UNK: X warning("illegal character in command parameter", curr_token.storage); X scan_state = SS_TEXT; goto rescan; X case SP____: X case SP_PRM: X case SP_INT: X case SP_FLP: X default: X internal_error("illegal state in parameter scanner token actions", ""); X } /* switch( parameter scanner ) */ X break; X default: X internal_error("illegal scan state in token actions", ""); X } /* switch( scan_state ) */ X X return( !end_of_file ); X} /* scan() */ X X X X /* scan_init() initializes the scanner to a new input stream. This is X ** accomplished by reseting the scan_state, clearing the put-back buffer, X ** and various other minor tasks. X */ Xvoid Xscan_init(file) X FILE *file; X{ X X /* Initialize the scan state */ X scan_state = SS_TEXT; X X /* Save the handle to the file */ X in_file = file; X end_of_file = 0; X X /* Reset the buffer */ X input.length = 0; X X /* Miscellaneous */ X text = curr_token.storage; X command = curr_token.storage; X X} /* scan_init() */ X X X X Xstatic void Xparse_argument() X{ X X /* Determine whether or not the command has a numeric argument */ X if( curr_token.length == 1 ){ /* No numeric argument */ X number[0] = '0'; /* Set number = "0" */ X number[1] = '\0'; X pos_code = POS_ABSOLUTE; /* Set to a constant value */ X } X else{ /* Numeric argument present */ X /* Check if it is a relative offset */ X if( !isdigit(curr_token.storage[0]) ){ X if( curr_token.storage[0] == '+' ) pos_code = POS_REL_POSITIVE; X else if( curr_token.storage[0] == '-' ) pos_code = POS_REL_NEGATIVE; X else internal_error("illegal relative offset", curr_token.storage); X } X else{ X pos_code = POS_ABSOLUTE; X } X /* Record the scalar value */ X if( pos_code == POS_ABSOLUTE ){ X (void) strncpy(number, curr_token.storage, curr_token.length - 1); X number[curr_token.length - 1] = '\0'; X } X else{ X (void) strncpy(number, &(curr_token.storage)[1], curr_token.length - 2); X number[curr_token.length - 2] = '\0'; X } X } X X /* Finally, record the command as an *upper-case* single digit string */ X variable[0] = curr_token.storage[curr_token.length - 1]; X variable[1] = '\0'; X if( islower(variable[0]) ) variable[0] = toupper(variable[0]); X X} /* parse_argument() */ SHAR_EOF echo "File scan.c is complete" && $TOUCH -am 0707112690 scan.c && chmod 0644 scan.c || echo "restore of scan.c failed" set `wc -c scan.c`;Wc_c=$1 if test "$Wc_c" != "32557"; then echo original size 32557, current size $Wc_c fi # ============= scan.h ============== echo "x - extracting scan.h (Text)" sed 's/^X//' << 'SHAR_EOF' > scan.h && X/* X** Project: lj2ps X** File: scan.h X** X** Author: Christopher Lishka X** Organization: Wisconsin State Laboratory of Hygiene X** Data Processing Dept. X** X** Copyright (C) 1990 by Christopher Lishka. X** X** This program is free software; you can redistribute it and/or modify X** it under the terms of the GNU General Public License as published by X** the Free Software Foundation; either version 1, or (at your option) X** any later version. X** X** This program is distributed in the hope that it will be useful, X** but WITHOUT ANY WARRANTY; without even the implied warranty of X** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X** GNU General Public License for more details. X** X** You should have received a copy of the GNU General Public License X** along with this program; if not, write to the Free Software X** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X*/ X X /* Global constants X */ X#define MAX_BUFFER 1024 /* The maximum size of the token buffer */ X /* Persistent scanner states */ X#define SS_TEXT 1 X#define SS_PARAM 2 X /* Tokens returned */ X#define TEXT_lp 201 /* Normal text tokens */ X#define TEXT_rp 202 X#define TEXT_bslash 203 X#define TEXT_NEWLINE 204 X#define TEXT_FORMFEED 205 X#define TEXT_NULL 206 X#define TEXT_CHAR 207 X#define TEXT_TAB 208 X#define TEXT_SH_IN 209 X#define TEXT_SH_OUT 210 X#define CMD_UNDEF 300 /* Command tokens */ X#define CMD_E 301 X#define CMD_Y 302 X#define CMD_Z 303 X#define CMD_9 304 X#define CMD_eq 305 X#define CMD_lp 306 X#define CMD_rp 307 X#define CMD_lp_s 308 X#define CMD_rp_s 309 X#define CMD_amp_a 310 X#define CMD_amp_d 311 X#define CMD_amp_f 312 X#define CMD_amp_k 313 X#define CMD_amp_l 314 X#define CMD_amp_p 315 X#define CMD_amp_s 316 X#define CMD_star_b 317 X#define CMD_star_c 318 X#define CMD_star_p 319 X#define CMD_star_r 320 X#define CMD_star_t 321 X#define PARAM_CONTINUE 401 /* Parameter tokens */ X#define PARAM_END 402 X#define PARAM_UNDEF 403 X /* Position codes */ X#define POS_ABSOLUTE 501 X#define POS_REL_POSITIVE 502 X#define POS_REL_NEGATIVE 503 X X /* Global structure and type definitions X */ Xtypedef struct { /* Input buffer */ X int code; /* The token code */ X int length; /* Number of characters put back */ X char storage[MAX_BUFFER]; /* Storage for characters in the buffer */ X} token; X X /* Global variables X */ Xextern int scan_state; /* Controls which scanner is being used */ Xextern char *text; /* Text read in for text tokens */ Xextern char *command; /* Command read in */ Xextern char variable[]; /* Command parameter */ Xextern char number[]; /* Command numeric argument */ Xextern int pos_code; /* Command numeric position code */ Xextern token curr_token; /* Where to hold the scanned token */ X X /* Global macro definitions X */ X X /* Global functions X */ Xextern int scan(); /* The entry into the scanners */ Xextern void scan_init(); /* Reset the input for the scanner */ SHAR_EOF $TOUCH -am 0707112690 scan.h && chmod 0644 scan.h || echo "restore of scan.h failed" set `wc -c scan.h`;Wc_c=$1 if test "$Wc_c" != "3044"; then echo original size 3044, current size $Wc_c fi # ============= trans.c ============== echo "x - extracting trans.c (Text)" sed 's/^X//' << 'SHAR_EOF' > trans.c && X/* Program: lj2ps X** File: transform.c X** X** Author: Christopher Lishka X** Organization: Wisconsin State Laboratory of Hygiene X** Data Processing Dept. X** X** Copyright (C) 1990 by Christopher Lishka. X** X** This program is free software; you can redistribute it and/or modify X** it under the terms of the GNU General Public License as published by X** the Free Software Foundation; either version 1, or (at your option) X** any later version. X** X** This program is distributed in the hope that it will be useful, X** but WITHOUT ANY WARRANTY; without even the implied warranty of X** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X** GNU General Public License for more details. X** X** You should have received a copy of the GNU General Public License X** along with this program; if not, write to the Free Software X** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X*/ X Xstatic char * ModuleID = "Module transform: v1.0.1.2, production"; X X /* Include files X */ X#include <stdio.h> X#include "trans.h" X#include "scan.h" X#include "lj2ps.h" X#include "lj.h" X X /* External definitions X */ X X /* Global variables X */ X X /* Global function list X */ Xextern void transform(); X X /* Local constants X */ X X /* Local structures and types X */ X X /* Local variables X */ X X /* Local macro definitions X */ X#define report(x) fprintf(output_file, "%s", x); X X /* Local function list X */ X X /* Function bodies X */ X X /* transform() reads text mixed with laserjet commands from its input X ** and "magically" changes it to postscript on its output. The magic X ** is performed in a tight while-loop which acts as a simple decision X ** table: for each token type (command, text, parameter) the appropriate X ** action is done (which usually involves writing to stdout or calling X ** an emulation function). X */ Xvoid Xtransform(input_file, output_file) X FILE *input_file, *output_file; X{ X X /* Reset the scanner to read from the input */ X scan_init(input_file); X X /* While the input stream still has tokens, handle each token through X ** the switch() jump table. X */ X scan_state = SS_TEXT; /* Set the initial scan state */ X while( scan() ){ X#ifdef DEBUG X if( debug ) fprintf(stderr, "{TOKEN:%d}", curr_token.code); X#endif X switch( curr_token.code ){ X case TEXT_CHAR: X if( (page_height - current_y) > (text_height + margin_top + LJ_ERROR) ){ X lj_page_end(output_file); X lj_page_begin(output_file); X } X lj_text_add(output_file, text); X break; X case TEXT_NULL: /* Ignore nulls */ X warning("encountered a null; ignoring", ""); X break; X case TEXT_lp: X lj_text_add(output_file, "\\("); X break; X case TEXT_rp: X lj_text_add(output_file, "\\)"); X break; X case TEXT_bslash: X lj_text_add(output_file, "\\\\"); X break; X case TEXT_NEWLINE: X if( (page_height - current_y) > (text_height + margin_top + LJ_ERROR) ){ X lj_page_end(output_file); X lj_page_begin(output_file); X } X lj_nl(output_file); /* Write out a newline */ X current_line++; X break; X case TEXT_FORMFEED: X lj_page_end(output_file); X /* XXX insert page counting mechanism here! */ X lj_page_begin(output_file); X break; X case TEXT_TAB: X /* XXX This should check for either font_p or font_s, and not assume X ** font_p automatically! X */ X if( font_p.spacing == LJ_SP_PROPORTIONAL ) X warning("a tab is being used with a proportional font!", ""); X lj_text_end(output_file); X fputs("TAB ", output_file); X lj_text_begin(); X break; X case TEXT_SH_IN: X warning("shift-in is not yet supported -- ignoring", ""); X break; X case TEXT_SH_OUT: X warning("shift-out is not yet supported -- ignoring", ""); X break; X case CMD_UNDEF: ljcmd_undefined(input_file, output_file); break; X case CMD_E: ljcmd_E(output_file); break; X case CMD_Y: ljcmd_Y(output_file); break; X case CMD_Z: ljcmd_Z(output_file); break; X case CMD_9: ljcmd_9(output_file); break; X case CMD_eq: ljcmd_eq(output_file); break; X case CMD_lp: ljcmd_lp(input_file, output_file); break; X case CMD_rp: ljcmd_rp(input_file, output_file); break; X case CMD_lp_s: ljcmd_lp_s(input_file, output_file); break; X case CMD_rp_s: ljcmd_rp_s(input_file, output_file); break; X case CMD_amp_a: ljcmd_amp_a(input_file, output_file); break; X case CMD_amp_d: ljcmd_amp_d(input_file, output_file); break; X case CMD_amp_f: ljcmd_amp_f(input_file, output_file); break; X case CMD_amp_k: ljcmd_amp_k(input_file, output_file); break; X case CMD_amp_l: ljcmd_amp_l(input_file, output_file); break; X case CMD_amp_p: ljcmd_amp_p(input_file, output_file); break; X case CMD_amp_s: ljcmd_amp_s(input_file, output_file); break; X case CMD_star_b: ljcmd_star_b(input_file, output_file); break; X case CMD_star_c: ljcmd_star_c(input_file, output_file); break; X case CMD_star_p: ljcmd_star_p(input_file, output_file); break; X case CMD_star_r: ljcmd_star_r(input_file, output_file); break; X case CMD_star_t: ljcmd_star_t(input_file, output_file); break; X case PARAM_CONTINUE: X case PARAM_END: X internal_error("(end)parameter found in transform()", variable); X break; X default: X internal_error("illegal token encountered in transform()", ""); X } /* switch(...) */ X } /* while(...) */ X X} /* transform() */ X X X SHAR_EOF $TOUCH -am 0707112690 trans.c && chmod 0644 trans.c || echo "restore of trans.c failed" set `wc -c trans.c`;Wc_c=$1 if test "$Wc_c" != "5585"; then echo original size 5585, current size $Wc_c fi # ============= trans.h ============== echo "x - extracting trans.h (Text)" sed 's/^X//' << 'SHAR_EOF' > trans.h && X/* X** Project: lj2ps X** File: trans.h X** X** Author: Christopher Lishka X** Organization: Wisconsin State Laboratory of Hygiene X** Data Processing Dept. X** X** Copyright (C) 1990 by Christopher Lishka. X** X** This program is free software; you can redistribute it and/or modify X** it under the terms of the GNU General Public License as published by X** the Free Software Foundation; either version 1, or (at your option) X** any later version. X** X** This program is distributed in the hope that it will be useful, X** but WITHOUT ANY WARRANTY; without even the implied warranty of X** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X** GNU General Public License for more details. X** X** You should have received a copy of the GNU General Public License X** along with this program; if not, write to the Free Software X** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X*/ X X /* Global constants X */ X X /* Global structure and type definitions X */ X X /* Global variables X */ X X /* Global macro definitions X */ X X /* Global functions X */ Xextern void transform(); SHAR_EOF $TOUCH -am 0707112690 trans.h && chmod 0644 trans.h || echo "restore of trans.h failed" set `wc -c trans.h`;Wc_c=$1 if test "$Wc_c" != "1087"; then echo original size 1087, current size $Wc_c fi rm -f @shar_seq_.tmp echo "You have unpacked the last part" exit 0