bernd@actisb.UUCP (Bernd-Gunter Nitzler) (04/24/88)
N E C - P 5 to P o s t s c r i p t (TM) F i l t e r
Version 0.5 (not completely tested)
This is a filter to translate the ESC- and FS-sequences
of the NEC P5 Series printer (and since this is a superset
of the EPSON printer commands also EPSON and compatible
printers) to Postscript.
It is based very loosely on the IBM Graphics printer to
postscript translator posted a couple of weeks before to the
net. That version was copyrighted by Jonathan Greenblatt and
changed by Mark Alexander. Since I started from scratch and
used only about 5% of the original code I include my own
copyright notice.
Copyright (c) 1988, Bernd-Gunter Nitzler,
pyramid!actisb!bernd
unido!tub!actisb!bernd
A similar program was copyrighted before:
Copyright (c) 1988, Jonathan Greenblatt,
<jonnyg@rover.umd.edu> (128.8.2.73)
<jonnyg@umd5.umd.edu> (128.8.10.5)
<pcproj@gymble.umd.edu> (128.8.128.16)
and changed by:
Mark Alexander <uunet!amdahl!drivax!alexande@umd5.UMD.EDU>
I post this version only as a beta test version, not as a final
release because I am out of town until 15th of June 1988 and I
look forward to receive bug fixes and enhancements until then.
About half of the control sequences I implemented were only
roughly tested, the graphics sequences were only tested in the
8-pin part sinc I have no graphics program which can handle
24-pin graphics.
Please mail any bug fixes and enhancements or comments to me
because our news system has an expire period of 4 to 7 days only
and all news messages will be deleted when I come back to the
office.
#--- cut --- cut --- cut --- cut --- cut --- cut --- cut --- cut
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
# README
# defaults.h
# necp5.c
# This archive created: Sun Apr 24 00:00:38 1988
export PATH; PATH=/bin:$PATH
echo shar: extracting "'README'" '(1859 characters)'
if test -f 'README'
then
echo shar: will not over-write existing file "'README'"
else
sed 's/^X//' << \SHAR_EOF > 'README'
X N E C - P 5 to P o s t s c r i p t (TM)
X
XVersion 0.5 (not completely tested)
X
XThis is a filter to translate the ESC- and FS-sequences
Xof the NEC P5 Series printer (and since this is a superset
Xof the EPSON printer commands also EPSON and compatible
Xprinters) to Postscript.
X
XIt is based very loosely on the IBM Graphics printer to
Xpostscript translator posted a couple of weeks before to the
Xnet. That version was copyrighted by Jonathan Greenblatt and
Xchanged by Mark Alexander. Since I started from scratch and
Xused only about 5% of the original code I include my own
Xcopyright notice.
X
XCopyright (c) 1988, Bernd-Gunter Nitzler,
X pyramid!actisb!bernd
X unido!tub!actisb!bernd
X
X A similar program was copyrighted before:
XCopyright (c) 1988, Jonathan Greenblatt,
X <jonnyg@rover.umd.edu> (128.8.2.73)
X <jonnyg@umd5.umd.edu> (128.8.10.5)
X <pcproj@gymble.umd.edu> (128.8.128.16)
X
X and changed by:
XMark Alexander <uunet!amdahl!drivax!alexande@umd5.UMD.EDU>
X
XThis program may be redistributed in source form,
Xprovided no fee is charged and this copyright notices are preserved.
X
XThis filter translates most of the control sequences of the
XNEC P5 printer and all graphics modes as well as the international
Xlanguage character sets and a part of the IBM character set.
X
XI post this version only as a beta test version, not as a final
Xrelease because I am out of town until 15th of June 1988 and I
Xlook forward to receive bug fixes and enhancements until then.
XAbout half of the control sequences I implemented were only
Xroughly tested, the graphics sequences were only tested in the
X8-pin part sinc I have no graphics program which can handle
X24-pin graphics.
X
XPlease mail any bug fixes and enhancements or comments to me
Xbecause our news system has an expire period of 4 to 7 days only
Xand all news messages will be deleted when I come back to the
Xoffice.
SHAR_EOF
if test 1859 -ne "`wc -c < 'README'`"
then
echo shar: error transmitting "'README'" '(should have been 1859 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'defaults.h'" '(797 characters)'
if test -f 'defaults.h'
then
echo shar: will not over-write existing file "'defaults.h'"
else
sed 's/^X//' << \SHAR_EOF > 'defaults.h'
X#define CR 0
X#define CRLF 1
X#define LF 2
X
X /* Printer switch settings */
X
X#define LINESPACING 6 /* Line spacing default 6/8 */
X#define PERFSKIP 0 /* 1-Inch perforation skip 0/1 */
X#define FFLENGTH 72 /* Form feed length default 66/72 */
X#define AUTOLF 1 /* Auto line feed when buffer full 0/1 */
X#define LINEFEED CRLF /* Linefeed CRLF/LF */
X#define CARRIAGE CR /* Carriage return CR/CRLF */
X#define SHAPE0 0 /* Shape of the default 0 0/1 */
X#define LEFTMARGIN 1 /* Left Margin for sheet feeder 1/35 */
X#define COUNTRY 0 /* USA=0/France=1/Germany=2/England=3/
X Denmark I=4/Sweden=5/Italy=6/Spain=7/
X Japan=8/Norway=9/Denmark II=10/
X Netherlands=11 */
X#define CHARSET 0 /* Character set default Italic/IBM 0/1 */
X
X /* Additional settings */
X
X#define RIGHTMARGIN 78
SHAR_EOF
if test 797 -ne "`wc -c < 'defaults.h'`"
then
echo shar: error transmitting "'defaults.h'" '(should have been 797 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'necp5.c'" '(18839 characters)'
if test -f 'necp5.c'
then
echo shar: will not over-write existing file "'necp5.c'"
else
sed 's/^X//' << \SHAR_EOF > 'necp5.c'
X/*
X * N E C - P 5 to P o s t s c r i p t (TM)
X *
X * Version 0.5 (not completely tested)
X *
X * This is a filter to translate the ESC- and FS-sequences
X * of the NEC P5 Series printer (and since this is a superset
X * of the EPSON printer commands also EPSON and compatible
X * printers) to Postscript.
X *
X * It is very loosely based on the IBM Graphics printer to
X * postscript translator posted a couple of weeks before to the
X * net. That version was copyrighted by Jonathan Greenblatt and
X * changed by Mark Alexander. Since I started from scratch and
X * used only about 5% of the original code I include my own
X * copyright notice.
X *
X * Copyright (c) 1988, Bernd-Gunter Nitzler,
X * pyramid!actisb!bernd
X * unido!tub!actisb!bernd
X *
X * A similar program was copyrighted before:
X * Copyright (c) 1988, Jonathan Greenblatt,
X * <jonnyg@rover.umd.edu> (128.8.2.73)
X * <jonnyg@umd5.umd.edu> (128.8.10.5)
X * <pcproj@gymble.umd.edu> (128.8.128.16)
X *
X * and changed by:
X * Mark Alexander <uunet!amdahl!drivax!alexande@umd5.UMD.EDU>
X *
X * This program may be redistributed in source form,
X * provided no fee is charged and this copyright notices are preserved.
X *
X * This filter translates most of the control sequences of the
X * NEC P5 printer and all graphics modes as well as the international
X * language character sets and a part of the IBM character set.
X *
X */
X
X#include <stdio.h>
X#include "defaults.h"
X
X#define MAXX 2880 /* X scaled to 360 points per inch */
X#define MAXY 3960 /* Y scaled to 360 points per inch */
X
X#define YANFANG point_sizey
X#define YENDE MAXY
X
X#define get_pointx(cpi) (360/(cpi))
X#define get_pointy(lpi) (360/(lpi))
X#define H_ENLARGE(x) ((x)*(horz_enlarge + 1))
X#define V_ENLARGE(x) ((x)*(vert_enlarge + 1))
X
XFILE *file;
Xchar *filename;
X
Xint eof = 0;
X
X#define NUM_TABS 32
Xint tabs[NUM_TABS+1];
Xint tabindex;
X
X#define NUM_VTABS 16
Xint vtabs[NUM_VTABS+1];
Xint vtabindex;
X
X#define SPC 1000
X
X /* Language Character Sets and Paranthesis */
X
Xchar *language[12][14] = {
X
X /* 0x23, 0x24, 0x28, 0x29, 0x40, 0x5b, 0x5c, 0x5d,
X 0x5e, 0x60, 0x7b, 0x7c, 0x7d, 0x7e */
X
X { "#", "$", "\\(", "\\)", "@", "[", "\\\\", "]",
X "^", "`", "{", "|", "}", "~"},
X
X { "#", "$", "\\(", "\\)","\\326","\\312","\\300","\\247",
X "^", "`","\\323","\\324","\\332","\\310"},
X
X { "#", "$", "\\(", "\\)","\\247","\\276","\\311","\\321",
X "^", "`","\\325","\\327","\\333","\\373"},
X
X {"\\243", "$", "\\(", "\\)", "@", "[", "\\\\", "]",
X "^", "`", "{", "|", "}", "~"},
X
X { "#", "$", "\\(", "\\)", "@","\\341","\\351","\\322",
X "^", "`","\\361","\\371","\\334", "~"},
X
X { "#","\\250", "\\(", "\\)","\\265","\\276","\\311","\\322",
X "\\321","\\323","\\325","\\327","\\334","\\333"},
X
X { "#", "$", "\\(", "\\)", "@","\\312", "\\\\","\\323",
X "^","\\324","\\260","\\330","\\332","\\241"},
X
X { "#", "$", "\\(", "\\)", "@","\\241","\\314","\\277",
X "^", "`","\\310","\\331", "}", "~"},
X
X { "#", "$", "\\(", "\\)", "@", "[","\\245", "]",
X "^", "`", "{", "|", "}", "~"},
X
X { "#","\\250", "\\(", "\\)","\\265","\\341","\\351","\\322",
X "\\321","\\323","\\361","\\371","\\334","\\333"},
X
X { "#", "$", "\\(", "\\)","\\265","\\341","\\351","\\322",
X "\\321","\\323","\\361","\\371","\\334","\\333"},
X
X {"\\243", "$", "\\(", "\\)", "@", "[", "\\\\", "]",
X "^", "`", "{", "|", "}", "~"}};
X
Xint charset[256] = {
X 0, 0, 0, 0, 0, 0, 0, 0,
X 0, 0, 0, 0, 0, 0, 0, 0,
X 0, 0, 0, 0, 0,'\247', 0, 0,
X 0, 0, 0, 0, 0, 0, 0, 0,
X ' ', '!', '\"', SPC+0, SPC+1, '%', '&', '\'',
X SPC+2, SPC+3, '*', '+', ',', '-', '.', '/',
X '0', '1', '2', '3', '4', '5', '6', '7',
X '8', '9', ':', ';', '<', '=', '>', '?',
X SPC+4, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
X 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
X 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
X 'X', 'Y', 'Z', SPC+5, SPC+6, SPC+7, SPC+8, '_',
X SPC+9, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
X 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
X 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
X 'x', 'y', 'z',SPC+10,SPC+11,SPC+12,SPC+13, 0,
X '\335','\333','\323','\336','\325','\260','\334','\300',
X '\337','\340','\332','\342','\344','\345','\276','\322',
X '\265','\361','\341','\346','\327','\330','\347','\324',
X '\354','\311','\321','\242','\243','\245', 'P','\246',
X '\355','\356','\357','\360','\331','\314','\343','\353',
X '\277', ' ', ' ', ' ', ' ','\241','\253','\273',
X ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
X ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
X ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
X ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
X ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
X ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
X ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
X ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
X ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
X ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '};
X
Xint graphic_dpi[32] = { 60, 120, 120, 240, 80, 0, 90, 180 };
X
Xint gmodeK = 0;
Xint gmodeL = 1;
Xint gmodeY = 2;
Xint gmodeZ = 3;
X
Xshort repeatbuf[2048];
X
Xenum {normal,bold,doublenorm,doublebold,
X italicnorm,italicbold,doubleinorm,doubleibold} font_type;
X
Xstruct font {
X char *odescr;
X char *descr;
X char *name;
X int pointx;
X int pointy;
X } fonts[] = {
X {"Courier", "LCourier", "normal", 10, 6},
X {"Courier-Bold", "LCourier-B", "bold", 10, 6},
X {"Courier", "LCourier", "doublenorm", 5, 6},
X {"Courier-Bold", "LCourier-B", "doublebold", 5, 6},
X {"Courier-Oblique", "LCourier-O", "italicnorm", 10, 6},
X {"Courier-BoldOblique", "LCourier-BO", "italicbold", 10, 6},
X {"Courier-Oblique", "LCourier-O", "doubleinorm", 5, 6},
X {"Courier-BoldOblique", "LCourier-BO", "doubleibold", 5, 6}
X};
X
Xint cx;
Xint cy;
Xint point_sizex;
Xint point_sizey;
Xint ulpositionx;
X
Xint line_space = LINESPACING;
Xint vert_enlarge = 0;
Xint horz_enlarge = 0;
Xint intext = 0;
Xint underline = 0;
Xint subscript = 0;
Xint doublewidth = 0;
Xint highlight = 0;
Xint emphasize = 0;
Xint italic = 0;
Xint italic_char = 0;
Xint linefeed = 0;
Xint curlang = COUNTRY;
Xint lftype = LINEFEED;
Xint crtype = CARRIAGE;
Xint left_margin = LEFTMARGIN-1;
Xint right_margin = RIGHTMARGIN-1;
Xint page = 0;
Xint repeatsw = 0;
Xint repeatcnt = 0;
Xint repeatidx = 0;
Xint repeatmax = 0;
Xint control8 = 0;
Xint bit8 = 0;
Xint italic_ibm = CHARSET;
X
Xdefine_font(f,def)
Xstruct font *f;
Xint def;
X{
X int s;
X
X s = get_pointx(f->pointx)*10;
X if (def)
X printf("/%s /%s langvec Lang\n",f->odescr,f->descr);
X printf("/%s {/%s findfont [%d 0 0 -%d 0 -8] makefont setfont} def\n",
X f->name,f->descr,s/6,get_pointy(f->pointy));
X}
X
Xnew_page()
X{
X cx = H_ENLARGE(left_margin * point_sizex);
X cy = YANFANG;
X page++;
X printf("%%%%Page: %d %d\n",page,page);
X printf("gsave\n");
X}
X
Xset_font()
X{
X int boldface;
X
X boldface = highlight || emphasize;
X if (doublewidth) {
X if (italic || italic_char)
X font_type = boldface ? doubleibold : doubleinorm;
X else
X font_type = boldface ? doublebold : doublenorm;
X } else {
X if (italic || italic_char)
X font_type = boldface ? italicbold : italicnorm;
X else
X font_type = boldface ? bold: normal;
X }
X point_sizex = get_pointx(fonts[(int)font_type].pointx);
X point_sizey = get_pointy(fonts[(int)font_type].pointy);
X printf("%s\n",fonts[(int)font_type].name);
X}
X
Xeject_page()
X{
X printf("showpage grestore\n");
X new_page();
X}
X
Xcheck_page()
X{
X int oldcy;
X
X if (cy > YENDE) {
X/* oldcy = cy; */
X eject_page();
X/* cy = oldcy - YENDE; */
X } else if (cy < YANFANG)
X cy = YANFANG;
X
X}
X
Xinit_printer()
X{
X line_space = get_pointy(fonts[(int)normal].pointy);
X printf("%%!PS-Adobe-1.0\n");
X printf("%%%%DocumentFonts: (atend)\n");
X printf("%%%%Title: %s\n",filename);
X printf("%%%%Creator: %s\n",getenv("USER"));
X printf("%%%%Pages: (atend)\n");
X printf("%%%%EndComments\n");
X printf("/m {moveto} def\n");
X printf("/s {show} def\n");
X printf("/ul {1 index m lineto stroke} def\n");
X printf("/langdict 12 dict def\n");
X printf("/Lang {langdict begin /codes exch def /newfont exch def /basefont exch def\n");
X printf(" /basedict basefont findfont def /newdict basedict maxlength dict def\n");
X printf(" basedict {exch dup /FID ne {dup /Encoding eq {exch dup length array copy\n");
X printf(" newdict 3 1 roll put} {exch newdict 3 1 roll put} ifelse} {pop pop}\n");
X printf(" ifelse} forall newdict /FontName newfont put codes aload pop\n");
X printf(" codes length 2 idiv {newdict /Encoding get 3 1 roll put} repeat\n");
X printf(" newfont newdict definefont pop end} def\n");
X printf("/langvec [8#260 /agrave 8#265 /Eacute 8#276 /Adieresis 8#300 /ccedilla\n");
X printf(" 8#311 /Odieresis 8#314 /Ntilde 8#321 /Udieresis 8#322 /Aring 8#323 /eacute\n");
X printf(" 8#324 /ugrave 8#325 /adieresis 8#326 /agrave 8#327 /odieresis 8#330 /ograve\n");
X printf(" 8#331 /ntilde 8#332 /egrave 8#333 /udieresis 8#334 /aring\n");
X printf(" 8#335 /Ccedilla 8#336 /acircumflex 8#337 /ecircumflex 8#340 /edieresis\n");
X printf(" 8#342 /idieresis 8#344 /icircumflex 8#345 /igrave 8#346 /ocircumflex\n");
X printf(" 8#347 /ucircumflex 8#354 /ydieresis 8#355 /aacute 8#356 /iacute\n");
X printf(" 8#357 /oacute 8#360 /uacute] def\n");
X printf("clippath pathbbox exch pop exch pop translate\n");
X printf("0.2 -0.2 scale\n");
X printf("1 setlinejoin 1 setlinecap 1 setlinewidth\n");
X printf("newpath\n");
X
X /* Define the normal-width fonts. */
X define_font(&fonts[(int)normal],1);
X define_font(&fonts[(int)bold],1);
X define_font(&fonts[(int)italicnorm],1);
X define_font(&fonts[(int)italicbold],1);
X
X /* Define the double-width fonts. */
X define_font(&fonts[(int)doublenorm],0);
X define_font(&fonts[(int)doublebold],0);
X define_font(&fonts[(int)doubleinorm],0);
X define_font(&fonts[(int)doubleibold],0);
X font_type = normal;
X set_font();
X printf("%%%%EndProlog\n");
X new_page();
X}
X
Xnewline()
X{
X if (linefeed)
X cy -= V_ENLARGE(line_space);
X else
X cy += V_ENLARGE(line_space);
X check_page();
X}
X
Xstop_underline()
X{
X if (underline)
X printf("%d %d %d ul\n",cx-1,cy+8,ulpositionx);
X}
X
Xend_underline()
X{
X stop_underline();
X underline = 0;
X}
X
Xend_text()
X{
X if (intext) {
X if (subscript || vert_enlarge || horz_enlarge)
X printf(") s grestore\n");
X else
X printf(") s\n");
X intext = 0;
X }
X}
X
Xint eofgetc()
X{
X int c;
X
X if (repeatsw == 2) { /* Do repeat */
X do {
X if (repeatidx < repeatmax)
X return(repeatbuf[repeatidx++]);
X repeatidx = 0;
X } while (--repeatcnt);
X repeatsw = 0;
X }
X if (eof || (c = getc(file)) == EOF) {
X eof = 1;
X c = '\0';
X }
X if (control8)
X c = c & 0x7f | bit8;
X if (repeatsw == 1 && repeatmax < sizeof(repeatbuf))
X repeatbuf[repeatmax++] = c;
X return(c);
X}
X
Xdographic(mode)
Xint mode;
X{
X int n1, n2, c;
X int px, pins;
X
X end_underline();
X if (mode < 32) { /* For 24 Pin Printers */
X pins = 8;
X px = graphic_dpi[mode];
X } else {
X pins = 24;
X if (mode < 60) {
X mode -= 32;
X px = graphic_dpi[mode];
X } else
X px = mode;
X }
X if (px == 0)
X fprintf(stderr,"Unknown graphic mode: %d\n",mode);
X n1 = eofgetc();
X n2 = eofgetc();
X n1 = n2 * 256 + n1;
X#ifdef TRACE
Xfprintf(stderr,"Graphic: mode=%d n=%d\n",mode,n1);
X#endif
X if (n1) {
X printf("gsave %d %d translate %d %d scale\n",
X cx,cy,get_pointx(px)*8,48);
X printf("%d %d true [ 0 %d %d 0 %d 0 ] { <\n",pins,n1,
X pins,pins,pins);
X if (pins == 24)
X n1 *= 3;
X n2 = 0;
X while (n1-- && !eof)
X printf("%02x%c",eofgetc(),++n2 & 15 ? ' ' : '\n');
X printf("> } imagemask grestore\n");
X }
X}
X
Xdoescape()
X{
X int c;
X int mode;
X
X c = eofgetc();
X#ifdef TRACE
Xfprintf(stderr,"Escape: %c\n",c);
X#endif
X switch (c) {
X case '#':
X control8 = 0;
X break;
X case '*':
X mode = eofgetc();
X if (!eof)
X dographic(mode);
X break;
X case '-':
X c = eofgetc();
X if (c == '\0' && underline) {
X end_underline();
X underline = 0;
X } else if (c == '\1') {
X underline = 1;
X ulpositionx = cx;
X }
X break;
X case '0': /* set line spacing to 1/8 inch */
X line_space = get_pointy(8);
X break;
X case '1':
X c = eofgetc();
X if (H_ENLARGE(c * point_sizex) < MAXX)
X left_margin = c;
X break;
X case '2': /* set line spacing to 1/6 inch */
X line_space = get_pointy(6);
X break;
X case '3':
X c = eofgetc();
X line_space = c*2;
X break;
X case '4':
X italic = 1;
X italic_char = 0;
X set_font();
X break;
X case '5':
X italic = 0;
X italic_char = 0;
X set_font();
X break;
X case '<': /* Print Head to Left Margin */
X break;
X case '=':
X control8 = 1;
X bit8 = 0x00;
X break;
X case '>':
X control8 = 1;
X bit8 = 0x80;
X break;
X case '?':
X c = eofgetc();
X mode = eofgetc();
X switch (c) {
X case 'K':
X gmodeK = mode;
X break;
X case 'L':
X gmodeL = mode;
X break;
X case 'Y':
X gmodeY = mode;
X break;
X case 'Z':
X gmodeZ = mode;
X break;
X default:
X fprintf(stderr,"Unknown Graphic Control: 0x%02x\n",c);
X break;
X }
X break;
X case 'A':
X c = eofgetc();
X line_space = c*5;
X break;
X case 'B':
X vtabindex = 0;
X while (c = eofgetc())
X if (vtabindex < NUM_TABS)
X vtabs[vtabindex++] = c;
X vtabs[vtabindex] = 0;
X break;
X case 'D':
X tabindex = 0;
X while (c = eofgetc())
X if (tabindex < NUM_TABS)
X tabs[tabindex++] = c;
X tabs[tabindex] = 0;
X break;
X case 'E':
X emphasize = 1;
X set_font();
X break;
X case 'F':
X emphasize = 0;
X set_font();
X break;
X case 'G':
X highlight = 1;
X set_font();
X break;
X case 'H':
X highlight = 0;
X set_font();
X break;
X case 'J':
X stop_underline();
X c = eofgetc();
X cy += c*2;
X check_page();
X ulpositionx = cx;
X break;
X case 'K':
X dographic(gmodeK);
X break;
X case 'L':
X dographic(gmodeL);
X break;
X case 'M':
X point_sizex = get_pointx(12);
X break;
X case 'P':
X point_sizex = get_pointx(10);
X break;
X case 'Q':
X c = eofgetc();
X if (H_ENLARGE(c * point_sizex) < MAXX)
X right_margin = c;
X break;
X case 'R':
X c = eofgetc();
X if (c < 12) curlang = c;
X break;
X case 'S':
X c = eofgetc();
X if (c == '\0') subscript = 2;
X else if (c == '\1') subscript = 1;
X break;
X case 'T':
X subscript = 0;
X break;
X case 'U': /* Uni/Bidirectional printing */
X c = eofgetc();
X break;
X case 'V':
X c = eofgetc();
X if (c) {
X repeatsw = 1;
X repeatcnt = c;
X repeatmax = 0;
X } else if (--repeatcnt) {
X repeatsw = 2;
X repeatidx = 0;
X repeatmax -= 3; /* forget repeat end */
X } else
X repeatsw = 0;
X break;
X case 'W':
X c = eofgetc();
X if (c == '\0') doublewidth = 0;
X else if (c == '\1') doublewidth = 1;
X set_font();
X break;
X case 'Y':
X dographic(gmodeY);
X break;
X case 'Z':
X dographic(gmodeZ);
X break;
X case 'f':
X stop_underline();
X c = eofgetc();
X if (c == 0) { /* Print head move */
X c = eofgetc();
X cx += H_ENLARGE(get_pointx(c));
X } else { /* Paper advance */
X c = eofgetc();
X cy += get_pointy(c);
X check_page();
X }
X ulpositionx = cx;
X break;
X case 'j':
X stop_underline();
X c = eofgetc();
X cy -= c*2;
X check_page();
X ulpositionx = cx;
X break;
X case 's': /* Half Speed Printing */
X c = eofgetc();
X break;
X default:
X end_underline();
X fprintf(stderr,"Unknown sequence: ESC 0x%x\n",c);
X break;
X }
X}
X
Xdoformsep()
X{
X int c;
X
X c = eofgetc();
X#ifdef TRACE
Xfprintf(stderr,"Form Sep: %c\n",c);
X#endif
X switch (c) {
X case '3':
X c = eofgetc();
X line_space = c;
X break;
X case 'E':
X c = eofgetc();
X horz_enlarge = c;
X break;
X case 'F':
X linefeed = 0; /* forward */
X break;
X case 'I':
X c = eofgetc();
X italic_ibm = c;
X break;
X case 'R':
X linefeed = 1; /* reverse */
X break;
X case 'V':
X c = eofgetc();
X vert_enlarge = c;
X break;
X case 'Z':
X dographic(360);
X break;
X default:
X end_underline();
X fprintf(stderr,"Unknown sequence: FS 0x%x\n",c);
X break;
X }
X}
X
Xdochar()
X{
X int c;
X
X c = eofgetc();
X#ifdef TRACE
Xfprintf(stderr,"Character: 0x%02x\n",c);
X#endif
X if (!italic_ibm &&
X (italic_char && (c & 0x80) == 0 || !italic_char && (c & 0x80))) {
X end_text();
X italic_char = !italic_char;
X set_font();
X } else if (charset[c] == 0)
X end_text();
X if (italic_char)
X c &= 0x7f;
X switch (c) {
X case '\000':
X case '\032':
X case '\177':
X break;
X case '\010':
X if (cx > H_ENLARGE(left_margin * point_sizex))
X cx -= H_ENLARGE(point_sizex);
X break;
X case '\011':
X {
X int i,l;
X
X l = cx / H_ENLARGE(point_sizex);
X for (i = 0; i < NUM_TABS && tabs[i] && tabs[i] <= l; i++) ;
X cx = H_ENLARGE(tabs[i] * point_sizex);
X }
X break;
X case '\014':
X stop_underline();
X eject_page();
X ulpositionx = cx;
X break;
X case '\033':
X doescape();
X break;
X case '\034':
X doformsep();
X break;
X case '\n':
X stop_underline();
X newline();
X if (lftype == CRLF)
X cx = H_ENLARGE(left_margin * point_sizex);
X ulpositionx = cx;
X break;
X case '\r':
X stop_underline();
X cx = H_ENLARGE(left_margin * point_sizex);
X if (crtype == CRLF)
X newline();
X ulpositionx = cx;
X break;
X default:
X if (cx > MAXX || cx > H_ENLARGE((right_margin - 1) * point_sizex)) {
X end_text();
X cx = H_ENLARGE(left_margin * point_sizex);
X newline();
X }
X if (!intext) {
X switch (subscript) {
X case 0:
X if (vert_enlarge || horz_enlarge)
X printf("%d %d m gsave %d %d scale (",
X cx,cy+point_sizey*vert_enlarge,
X horz_enlarge+1,vert_enlarge+1);
X else
X printf("%d %d m (",cx,cy);
X break;
X case 1: /* Subscript */
X printf("%d %d m gsave %d %f scale (",
X cx,cy+point_sizey*vert_enlarge,
X horz_enlarge+1,(double)((vert_enlarge+1)*0.5));
X break;
X case 2: /* Superscript */
X printf("%d %d m gsave %d %f scale (",
X cx,cy-point_sizey/2+point_sizey*vert_enlarge,
X horz_enlarge+1,(double)((vert_enlarge+1)*0.5));
X break;
X }
X intext = 1;
X }
X if (c >= ' ' && c <= 255) {
X c = charset[c];
X if (c >= SPC)
X printf(language[curlang][c-SPC]);
X else if (c) {
X if (c & 0x80)
X printf("\\%3o",c & 0xff);
X else
X putchar(c);
X } else
X putchar(' ');
X } else
X fprintf(stderr,"Unknown control: 0x%02x\n",c);
X cx += H_ENLARGE(point_sizex);
X break;
X }
X}
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X int i;
X
X if (argc > 2) {
X fprintf(stderr,"Usage: %s [file]\n",argv[0]);
X exit(1);
X }
X if (argc == 2) {
X if ((file = fopen(argv[1],"r")) == NULL) {
X fprintf(stderr,"%s: Unable to open %s\n",argv[0],argv[1]);
X exit(2);
X }
X filename = argv[1];
X } else {
X file = stdin;
X filename = "(STDIN)";
X }
X init_printer();
X do {
X dochar();
X } while (!eof);
X end_text();
X if (cx > H_ENLARGE(left_margin * point_sizex) || cy > YANFANG)
X printf("showpage grestore\n");
X printf("%%%%Trailer\n");
X printf("%%%%DocumentFonts: ");
X for (i = 2;i < 6;i++)
X printf("%s ",fonts[i].odescr);
X printf("\n%%%%Pages: %d\n",page);
X exit(0);
X}
SHAR_EOF
if test 18839 -ne "`wc -c < 'necp5.c'`"
then
echo shar: error transmitting "'necp5.c'" '(should have been 18839 characters)'
fi
fi # end of overwriting check
# End of shell archive
exit 0
--
Bernd-Gunter Nitzler VoiceNet: 49 / (30) 88 43 01-31
ACTIS in Berlin GmbH UUCP: mcvax!unido!tub!actisb!bernd
Kurfuerstendamm 65 uunet/ /
D-1000 Berlin 15 pyramid/
W. Germany