/* ********************************************************* * * * TekPS - Version 2.0 * * September, 1988 * * * * (c) 1988 by Arlindo da Silva * * * * This program takes as input Tektronix * * instructions and produces the corresponding Post * * Script code. Notice that: * * * * - the Tektronix alpha mode instructions * * are ignored; use it only for graphics. * * * ********************************************************* */ #include #include /*................................................................*/ FILE *tek_file; FILE *ps_file; int x1, y1, x0, y0, ps_counter; int xoff[4], yoff[4], inext=0; char delimiter, linecap, linewidth, linejoin, nplotsfrm; char first_instruction, frame_flag, c1; char infile[80], outfile[80]; char ESC=27, FF=12, US=31, GS=29; /* Global Variables: tek_file - Tektronix input file ps_file - Post Script output file frame_flag - whether or not frame has anything in it ps_counter - holds counter of Post Script points plotted first_instruction - whether or not first instruction of the frame. inext - controls position of plot on the frame */ /*...................................................................*/ main ( argc, argv ) int argc; char *argv[]; { Setup ( argc, argv ); Initialization(); Scan_Tektronix_File(); Finalization(); Close_Files(); } Usage_Note() { fprintf ( stderr, "Usage: tekps [-options] [infile [outfile]\n"); fprintf ( stderr, "Options:\n" ); fprintf ( stderr, " -h displays this message\n" ); fprintf ( stderr, " -d n specifies character n as delimiter"); fprintf ( stderr," (default=%d)\n", delimiter ); fprintf ( stderr, " -f n specifies n plots per frame; n can only\n"); fprintf ( stderr, " be 1, 2 or 4" ); fprintf ( stderr," (default=%d)\n", nplotsfrm ); fprintf ( stderr, " -c n specifies line cap as n"); fprintf ( stderr," (default=%d)\n", linecap ); fprintf ( stderr, " -w n specifies line width as n"); fprintf ( stderr," (default=%d)\n", linewidth ); fprintf ( stderr, " -j n specifies line join as n"); fprintf ( stderr," (default=%d)\n", linejoin ); } Setup ( argc, argv ) int argc; char *argv[]; { int i; char *fin=NULL; char *fout=NULL; /*---- defaults for internal parameters ---*/ delimiter = '%'; nplotsfrm = 1; linecap = 1; /* change this only if you know what you are doing */ linewidth = 2; linejoin = 1; i=1; while (i= 32 ) && ( OneByte <= 63 ) ) { if ( after_low_y ) hx = OneByte - 32; else hy = OneByte - 32; after_low_y = 0; } /* Set low x */ else if ( ( OneByte >= 64 ) && ( OneByte <= 95 ) ) { lx = OneByte - 64; x0 = hx * 128 + lx * 4 + ( lxy & 3 ); y0 = hy * 128 + ly * 4 + ( lxy >> 2 ); if ( pen_down ) Plot ( x0, y0, 'L' ); else { Plot ( x0, y0, 'M' ); pen_down = 1; } after_low_y = 0; } /* Set low y / extra byte */ else if ( ( OneByte >= 96 ) && ( OneByte <= 127 ) ) { if ( after_low_y ) lxy = ( ly & 15 ); ly = OneByte - 96; after_low_y = 1; } } } if ( inext != 0 ) { inext = 999; /* to force end of page */ frame_flag = 1; } End_Page(); } Initialization() { if ( delimiter != '%' ) fputc ( delimiter, ps_file ); fputs ( "%!\n", ps_file ); fputs ( "% TekPS Prologue, ver 2.0, (c) 1988 Arlindo da Silva\n", ps_file ); fputs ( "% RCSID: $Ident$\n", ps_file ); fputs ( "% definitions:\n", ps_file ); fputs ( "save /TekPSsave exch def\n", ps_file ); fputs ( "/M /moveto load def\n", ps_file ); fputs ( "/L /lineto load def\n", ps_file ); fputs ( "% scale the coordinate space:\n", ps_file ); fputs ( "initmatrix 0.18 dup scale\n", ps_file ); fputs ( "%ps line parameters:\n", ps_file ); fprintf ( ps_file, "%d setlinecap %d setlinewidth %d setlinejoin\n", linecap, linewidth, linejoin ); fputs ( "erasepage\n", ps_file ); fputs ( "% ((( end of TekPS prologue )))\n", ps_file ); } New_Page() { fprintf ( ps_file, "0 0 M \n" ); } Plot ( XA, YA, com ) int XA, YA; char com; /* This procedure plots or move the pen depending on the value of com: xa, ya -- Tektronix coordinates - range: [0,4095] com -- command: "M" - move to position xa, xb "L" - draw line from previous position to xa, ya NOTE: The ps_counter is related to the size of the printer buffer. The value used (500) is ok for many printers (like Apple, NEC, TI, etc...) */ { int xa, ya; switch ( nplotsfrm ) /* transform coordinates according to the number of plots per frame */ { case 2: xa = xoff[inext] + 0.64 * XA ; ya = yoff[inext] + 0.64 * YA ; break; case 4: xa = xoff[inext] + 0.5 * ( YA ); ya = yoff[inext] + 0.5 * ( 4096 - XA ); break; case 7: xa = xoff[inext] + 1.024 * ( YA - 1600) + 800.; ya = yoff[inext] + 0.8 * ( 2048 - XA) + 1024.; break; case 8: xa = xoff[inext] + 1.28 * ( YA - 1600) + 800.; ya = yoff[inext] + 1. * ( 2048 - XA) + 1024.; break; case 9: xa = xoff[inext] + 1.6 * ( YA - 1600) + 800.; ya = yoff[inext] + 1.25 * ( 2048 - XA) + 1024.; break; default: xa = 160 + YA; ya = 160 + 4096 - XA; break; } if ( ! frame_flag ) { if ( first_instruction ) /* consider only frames with more than 1 instruction */ { x1 = xa; y1 = ya; c1 = com; first_instruction = 0; } else { New_Page(); fprintf ( ps_file, "%d %d %c\n", x1, y1, c1 ); fprintf ( ps_file, "%d %d %c\n", xa, ya, com ); frame_flag = 1; } } else { if ( ps_counter > 500 ) { fprintf ( ps_file, "%d %d %c\n", xa, ya, com ); fputs ( "stroke\n", ps_file ); fprintf ( ps_file, "%d %d %c\n", xa, ya, 'M' ); ps_counter = 0; } else { fprintf ( ps_file, "%d %d %c\n", xa, ya, com ); ps_counter++; } } } End_Page() { if ( frame_flag ) { inext++; if ( inext >= nplotsfrm ) { fputs ( "stroke gsave showpage grestore\n", ps_file ); inext = 0; } } } Finalization() { fputs ( "%%Trailer\n", ps_file ); fputs ( "grestore\n", ps_file ); fputs ( "TekPSsave restore\n", ps_file ); }