00001
00002
00003
00004
00005 #include "plDevs.h"
00006
00007 #if defined ( PLD_xterm ) || \
00008 defined ( PLD_tek4010 ) || \
00009 defined ( PLD_tek4010f ) || \
00010 defined ( PLD_tek4107 ) || \
00011 defined ( PLD_tek4107f ) || \
00012 defined ( PLD_mskermit ) || \
00013 defined ( PLD_versaterm ) || \
00014 defined ( PLD_vlt ) || \
00015 defined ( PLD_conex ) // conex emulator 4010/4014/4105
00016
00017 #define NEED_PLDEBUG
00018 #include "plplotP.h"
00019 #include "drivers.h"
00020 #include "plevent.h"
00021
00022 #include <ctype.h>
00023
00024
00025
00026 PLDLLIMPEXP_DRIVER const char* plD_DEVICE_INFO_tek =
00027 #if defined ( PLD_conex )
00028 "conex:Conex vt320/tek emulator:1:tek:24:conex\n"
00029 #endif
00030 #if defined ( PLD_mskermit )
00031 "mskermit:MS-Kermit emulator:1:tek:21:mskermit\n"
00032 #endif
00033 #if defined ( PLD_tek4107t )
00034 "tek4107t:Tektronix Terminal (4105/4107):1:tek:20:tek4107t\n"
00035 #endif
00036 #if defined ( PLD_tek4107f )
00037 "tek4107f:Tektronix File (4105/4107):0:tek:28:tek4107f\n"
00038 #endif
00039 #if defined ( PLD_tekt )
00040 "tekt:Tektronix Terminal (4010):1:tek:19:tekt\n"
00041 #endif
00042 #if defined ( PLD_tekf )
00043 "tekf:Tektronix File (4010):0:tek:27:tekf\n"
00044 #endif
00045 #if defined ( PLD_versaterm )
00046 "versaterm:Versaterm vt100/tek emulator:1:tek:22:versaterm\n"
00047 #endif
00048 #if defined ( PLD_vlt )
00049 "vlt:VLT vt100/tek emulator:1:tek:23:vlt\n"
00050 #endif
00051 #if defined ( PLD_xterm )
00052 "xterm:Xterm Window:1:tek:18:xterm\n"
00053 #endif
00054 ;
00055
00056
00057
00058
00059 void plD_init_xterm( PLStream * );
00060 void plD_init_tekt( PLStream * );
00061 void plD_init_tekf( PLStream * );
00062 void plD_init_tek4107t( PLStream * );
00063 void plD_init_tek4107f( PLStream * );
00064 void plD_init_mskermit( PLStream * );
00065 void plD_init_versaterm( PLStream * );
00066 void plD_init_vlt( PLStream * );
00067 void plD_init_conex( PLStream * );
00068
00069
00070
00071 void plD_line_tek( PLStream *, short, short, short, short );
00072 void plD_polyline_tek( PLStream *, short *, short *, PLINT );
00073 void plD_eop_tek( PLStream * );
00074 void plD_bop_tek( PLStream * );
00075 void plD_tidy_tek( PLStream * );
00076 void plD_state_tek( PLStream *, PLINT );
00077 void plD_esc_tek( PLStream *, PLINT, void * );
00078
00079
00080
00081 static void WaitForPage( PLStream *pls );
00082 static void tek_init( PLStream *pls );
00083 static void tek_text( PLStream *pls );
00084 static void tek_graph( PLStream *pls );
00085 static void fill_polygon( PLStream *pls );
00086 static void GetCursor( PLStream *pls, PLGraphicsIn *ptr );
00087 static void encode_int( char *c, int i );
00088 static void encode_vector( char *c, int x, int y );
00089 static void decode_gin( char *c, PLGraphicsIn *gin );
00090 static void tek_vector( PLStream *pls, int x, int y );
00091 static void scolor( PLStream *pls, int icol, int r, int g, int b );
00092 static void setcmap( PLStream *pls );
00093
00094 static void LookupEvent( PLStream *pls );
00095 static void InputEH( PLStream *pls );
00096 static void LocateEH( PLStream *pls );
00097
00098
00099
00100 #ifdef HAVE_TERMIOS_H
00101 #include <termios.h>
00102 #include <unistd.h>
00103 static struct termios termios_cbreak, termios_reset;
00104 static enum { RESET, CBREAK } ttystate = RESET;
00105 static void tty_setup( void );
00106 static int tty_cbreak( void );
00107 static int tty_reset( void );
00108 static void tty_atexit( void );
00109 #else
00110 static void tty_setup( void )
00111 {
00112 }
00113 static int tty_cbreak( void )
00114 {
00115 return 0;
00116 }
00117 static int tty_reset( void )
00118 {
00119 return 0;
00120 }
00121 static void tty_atexit( void )
00122 {
00123 }
00124 #endif
00125
00126
00127
00128 #define TEKX 1023
00129 #define TEKY 779
00130
00131
00132
00133 #define RING_BELL "\007" // ^G = 7
00134 #define CLEAR_VIEW "\033\f" // clear the view = ESC FF
00135
00136 #define ALPHA_MODE "\037" // Enter Alpha mode: US
00137 #define VECTOR_MODE "\035" // Enter Vector mode: GS
00138 #define GIN_MODE "\033\032" // Enter GIN mode: ESC SUB
00139 #define BYPASS_MODE "\033\030" // Enter Bypass mode: ESC CAN
00140 #define XTERM_VTMODE "\033\003" // End xterm-Tek mode: ESC ETX
00141 #define CANCEL "\033KC" // Cancel
00142
00143
00144
00145 enum { tek4010, tek4105, tek4107, xterm, mskermit, vlt, versaterm };
00146
00147
00148
00149 typedef struct
00150 {
00151 PLINT xold, yold;
00152 int exit_eventloop;
00153 int locate_mode;
00154 int curcolor;
00155 PLGraphicsIn gin;
00156 } TekDev;
00157
00158
00159
00160
00161
00162
00163 #ifdef PLD_mskermit
00164 static char *kermit_color[15] = {
00165 "0;30", "0;37",
00166 "0;32", "0;36","0;31", "0;35",
00167 "1;34", "1;33","1;31", "1;37",
00168 "1;35", "1;32","1;36", "0;34",
00169 "0;33"
00170 };
00171 #endif
00172
00173 static void tek_dispatch_init_helper( PLDispatchTable *pdt,
00174 char *menustr, char *devnam,
00175 int type, int seq, plD_init_fp init )
00176 {
00177 #ifndef ENABLE_DYNDRIVERS
00178 pdt->pl_MenuStr = menustr;
00179 pdt->pl_DevName = devnam;
00180 #endif
00181 pdt->pl_type = type;
00182 pdt->pl_seq = seq;
00183 pdt->pl_init = init;
00184 pdt->pl_line = (plD_line_fp) plD_line_tek;
00185 pdt->pl_polyline = (plD_polyline_fp) plD_polyline_tek;
00186 pdt->pl_eop = (plD_eop_fp) plD_eop_tek;
00187 pdt->pl_bop = (plD_bop_fp) plD_bop_tek;
00188 pdt->pl_tidy = (plD_tidy_fp) plD_tidy_tek;
00189 pdt->pl_state = (plD_state_fp) plD_state_tek;
00190 pdt->pl_esc = (plD_esc_fp) plD_esc_tek;
00191 }
00192
00193 void plD_dispatch_init_xterm( PLDispatchTable *pdt )
00194 {
00195 tek_dispatch_init_helper( pdt,
00196 "Xterm Window", "xterm",
00197 plDevType_Interactive, 18,
00198 (plD_init_fp) plD_init_xterm );
00199 }
00200
00201 void plD_dispatch_init_tekt( PLDispatchTable *pdt )
00202 {
00203 tek_dispatch_init_helper( pdt,
00204 "Tektronix Terminal (4010)", "tekt",
00205 plDevType_Interactive, 19,
00206 (plD_init_fp) plD_init_tekt );
00207 }
00208
00209 void plD_dispatch_init_tek4107t( PLDispatchTable *pdt )
00210 {
00211 tek_dispatch_init_helper( pdt,
00212 "Tektronix Terminal (4105/4107)", "tek4107t",
00213 plDevType_Interactive, 20,
00214 (plD_init_fp) plD_init_tek4107t );
00215 }
00216
00217 void plD_dispatch_init_mskermit( PLDispatchTable *pdt )
00218 {
00219 tek_dispatch_init_helper( pdt,
00220 "MS-Kermit emulator", "mskermit",
00221 plDevType_Interactive, 21,
00222 (plD_init_fp) plD_init_mskermit );
00223 }
00224
00225 void plD_dispatch_init_versaterm( PLDispatchTable *pdt )
00226 {
00227 tek_dispatch_init_helper( pdt,
00228 "Versaterm vt100/tek emulator", "versaterm",
00229 plDevType_Interactive, 22,
00230 (plD_init_fp) plD_init_versaterm );
00231 }
00232
00233 void plD_dispatch_init_vlt( PLDispatchTable *pdt )
00234 {
00235 tek_dispatch_init_helper( pdt,
00236 "VLT vt100/tek emulator", "vlt",
00237 plDevType_Interactive, 23,
00238 (plD_init_fp) plD_init_vlt );
00239 }
00240
00241 void plD_dispatch_init_conex( PLDispatchTable *pdt )
00242 {
00243 tek_dispatch_init_helper( pdt,
00244 "Conex vt320/tek emulator", "conex",
00245 plDevType_Interactive, 24,
00246 (plD_init_fp) plD_init_conex );
00247 }
00248
00249 void plD_dispatch_init_tekf( PLDispatchTable *pdt )
00250 {
00251 tek_dispatch_init_helper( pdt,
00252 "Tektronix File (4010)", "tekf",
00253 plDevType_FileOriented, 27,
00254 (plD_init_fp) plD_init_tekf );
00255 }
00256
00257 void plD_dispatch_init_tek4107f( PLDispatchTable *pdt )
00258 {
00259 tek_dispatch_init_helper( pdt,
00260 "Tektronix File (4105/4107)", "tek4107f",
00261 plDevType_FileOriented, 28,
00262 (plD_init_fp) plD_init_tek4107f );
00263 }
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285 void
00286 plD_init_xterm( PLStream *pls )
00287 {
00288 pls->dev_minor = xterm;
00289 pls->termin = 1;
00290 tek_init( pls );
00291 }
00292
00293 void
00294 plD_init_tekt( PLStream *pls )
00295 {
00296 pls->termin = 1;
00297 plD_init_tekf( pls );
00298 }
00299
00300 void
00301 plD_init_tekf( PLStream *pls )
00302 {
00303 pls->dev_minor = tek4010;
00304 tek_init( pls );
00305 }
00306
00307 void
00308 plD_init_tek4107t( PLStream *pls )
00309 {
00310 pls->termin = 1;
00311 plD_init_tek4107f( pls );
00312 }
00313
00314 void
00315 plD_init_tek4107f( PLStream *pls )
00316 {
00317 pls->dev_minor = tek4107;
00318 pls->color = 1;
00319 pls->dev_fill0 = 1;
00320 tek_init( pls );
00321 }
00322
00323 void
00324 plD_init_mskermit( PLStream *pls )
00325 {
00326 pls->dev_minor = mskermit;
00327 pls->termin = 1;
00328 pls->color = 1;
00329 pls->dev_fill0 = 1;
00330 tek_init( pls );
00331 }
00332
00333 void
00334 plD_init_vlt( PLStream *pls )
00335 {
00336 pls->dev_minor = vlt;
00337 pls->termin = 1;
00338 pls->color = 1;
00339 pls->dev_fill0 = 1;
00340 tek_init( pls );
00341 }
00342
00343 void
00344 plD_init_versaterm( PLStream *pls )
00345 {
00346 pls->dev_minor = versaterm;
00347 pls->termin = 1;
00348 pls->color = 1;
00349 pls->dev_fill0 = 1;
00350 tek_init( pls );
00351 }
00352
00353 void
00354 plD_init_conex( PLStream *pls )
00355 {
00356 pls->dev_minor = xterm;
00357 pls->termin = 1;
00358 pls->color = 2;
00359 tek_init( pls );
00360 }
00361
00362
00363
00364
00365
00366
00367
00368 static void
00369 tek_init( PLStream *pls )
00370 {
00371 TekDev *dev;
00372 int xmin = 0;
00373 int xmax = TEKX;
00374 int ymin = 0;
00375 int ymax = TEKY;
00376
00377 PLFLT pxlx = 4.771;
00378 PLFLT pxly = 4.653;
00379
00380 pls->graphx = TEXT_MODE;
00381
00382
00383
00384 pls->dev = calloc( 1, (size_t) sizeof ( TekDev ) );
00385 if ( pls->dev == NULL )
00386 plexit( "tek_init: Out of memory." );
00387
00388 dev = (TekDev *) pls->dev;
00389
00390 dev->curcolor = 1;
00391 dev->xold = PL_UNDEFINED;
00392 dev->yold = PL_UNDEFINED;
00393
00394 plP_setpxl( pxlx, pxly );
00395 plP_setphy( xmin, xmax, ymin, ymax );
00396
00397
00398
00399 if ( pls->termin )
00400 {
00401 pls->OutFile = stdout;
00402 tty_setup();
00403 }
00404 else
00405 {
00406 plFamInit( pls );
00407 plOpenFile( pls );
00408 }
00409
00410 switch ( pls->dev_minor )
00411 {
00412 #ifdef PLD_tek4107
00413 case tek4107:
00414 pls->graphx = GRAPHICS_MODE;
00415 fprintf( pls->OutFile, "\033%%!0" );
00416 fprintf( pls->OutFile, "\033KN1" );
00417 fprintf( pls->OutFile, "\033LZ" );
00418 fprintf( pls->OutFile, "\033ML1" );
00419 break;
00420 #endif // PLD_tek4107
00421
00422
00423
00424
00425
00426
00427 #ifdef PLD_vlt
00428 case vlt: {
00429 char fillcol[4];
00430 tek_graph( pls );
00431 encode_int( fillcol, 0 );
00432 fprintf( pls->OutFile, "\033MP%s\033LE", fillcol );
00433 break;
00434 }
00435 #endif // PLD_vlt
00436
00437 default:
00438 tek_graph( pls );
00439 }
00440
00441
00442
00443 if ( pls->color & 0x01 )
00444 {
00445 printf( "\033TM111" );
00446 setcmap( pls );
00447 }
00448
00449
00450
00451 fprintf( pls->OutFile, VECTOR_MODE );
00452 if ( pls->termin )
00453 fprintf( pls->OutFile, CLEAR_VIEW );
00454
00455 fflush( pls->OutFile );
00456 }
00457
00458
00459
00460
00461
00462
00463
00464 void
00465 plD_line_tek( PLStream *pls, short x1, short y1, short x2, short y2 )
00466 {
00467 TekDev *dev = (TekDev *) pls->dev;
00468
00469 tek_graph( pls );
00470
00471
00472
00473 if ( x1 != dev->xold || y1 != dev->yold )
00474 {
00475 pls->bytecnt += fprintf( pls->OutFile, VECTOR_MODE );
00476 tek_vector( pls, x1, y1 );
00477 }
00478
00479
00480
00481 tek_vector( pls, x2, y2 );
00482
00483 dev->xold = x2;
00484 dev->yold = y2;
00485 }
00486
00487
00488
00489
00490
00491
00492
00493 void
00494 plD_polyline_tek( PLStream *pls, short *xa, short *ya, PLINT npts )
00495 {
00496 PLINT i;
00497 TekDev *dev = (TekDev *) pls->dev;
00498 short x = xa[0], y = ya[0];
00499
00500 tek_graph( pls );
00501
00502
00503
00504 if ( x != dev->xold || y != dev->yold )
00505 {
00506 pls->bytecnt += fprintf( pls->OutFile, VECTOR_MODE );
00507 tek_vector( pls, x, y );
00508 }
00509
00510
00511
00512 for ( i = 1; i < npts; i++ )
00513 tek_vector( pls, xa[i], ya[i] );
00514
00515 dev->xold = xa[npts - 1];
00516 dev->yold = ya[npts - 1];
00517 }
00518
00519
00520
00521
00522
00523
00524
00525 void
00526 plD_eop_tek( PLStream *pls )
00527 {
00528 tek_graph( pls );
00529
00530 if ( pls->termin )
00531 {
00532 if ( !pls->nopause )
00533 WaitForPage( pls );
00534 }
00535 fprintf( pls->OutFile, CLEAR_VIEW );
00536 }
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546 void
00547 plD_bop_tek( PLStream *pls )
00548 {
00549 TekDev *dev = (TekDev *) pls->dev;
00550
00551 dev->xold = PL_UNDEFINED;
00552 dev->yold = PL_UNDEFINED;
00553
00554 if ( pls->termin )
00555 {
00556 switch ( pls->dev_minor )
00557 {
00558 case mskermit:
00559 fprintf( pls->OutFile, CLEAR_VIEW );
00560 break;
00561 }
00562 }
00563 else
00564 {
00565 plGetFam( pls );
00566 }
00567 pls->page++;
00568
00569
00570
00571 if ( pls->color & 0x01 )
00572 setcmap( pls );
00573 }
00574
00575
00576
00577
00578
00579
00580
00581 void
00582 plD_tidy_tek( PLStream *pls )
00583 {
00584 if ( !pls->termin )
00585 {
00586 plCloseFile( pls );
00587 }
00588 else
00589 {
00590 tek_text( pls );
00591 fflush( pls->OutFile );
00592 }
00593 }
00594
00595
00596
00597
00598
00599
00600
00601 static void
00602 tek_color( PLStream *pls, int icol )
00603 {
00604 switch ( pls->dev_minor )
00605 {
00606 #ifdef PLD_mskermit // Is this really necessary?
00607 case mskermit:
00608 printf( "\033[%sm", kermit_color[icol % 14] );
00609 break;
00610 #endif
00611 default:
00612 pls->bytecnt += fprintf( pls->OutFile, "\033ML%c", icol + '0' );
00613 }
00614 }
00615
00616
00617
00618
00619
00620
00621
00622
00623 void
00624 plD_state_tek( PLStream *pls, PLINT op )
00625 {
00626 TekDev *dev = (TekDev *) pls->dev;
00627
00628 switch ( op )
00629 {
00630 case PLSTATE_WIDTH:
00631 break;
00632
00633 case PLSTATE_COLOR0:
00634 if ( pls->color )
00635 {
00636 int icol0 = pls->icol0;
00637 tek_graph( pls );
00638 if ( icol0 != PL_RGB_COLOR )
00639 {
00640 dev->curcolor = icol0;
00641 tek_color( pls, icol0 );
00642 }
00643 }
00644 break;
00645
00646 case PLSTATE_COLOR1:
00647 if ( pls->color )
00648 {
00649 int icol1, ncol1;
00650 tek_graph( pls );
00651 if ( ( ncol1 = MIN( 16 - pls->ncol0, pls->ncol1 ) ) < 1 )
00652 break;
00653
00654 icol1 = pls->ncol0 + ( pls->icol1 * ( ncol1 - 1 ) ) / ( pls->ncol1 - 1 );
00655 dev->curcolor = icol1;
00656 tek_color( pls, icol1 );
00657 }
00658 break;
00659
00660 case PLSTATE_CMAP0:
00661 case PLSTATE_CMAP1:
00662 if ( pls->color & 0x01 )
00663 setcmap( pls );
00664
00665 break;
00666 }
00667 }
00668
00669
00670
00671
00672
00673
00674
00675 void
00676 plD_esc_tek( PLStream *pls, PLINT op, void *ptr )
00677 {
00678 switch ( op )
00679 {
00680 case PLESC_TEXT:
00681 tek_text( pls );
00682 break;
00683
00684 case PLESC_GRAPH:
00685 tek_graph( pls );
00686 break;
00687
00688 case PLESC_FILL:
00689 fill_polygon( pls );
00690 break;
00691
00692 case PLESC_GETC:
00693 GetCursor( pls, (PLGraphicsIn *) ptr );
00694 break;
00695 }
00696 }
00697
00698
00699
00700
00701
00702
00703
00704
00705 static void
00706 GetCursor( PLStream *pls, PLGraphicsIn *ptr )
00707 {
00708 #define MAX_GIN 10
00709 char input_string[MAX_GIN];
00710 int i = 0;
00711
00712 plGinInit( ptr );
00713
00714 if ( pls->termin && pls->dev_minor != xterm )
00715 {
00716 tek_graph( pls );
00717
00718
00719
00720 printf( GIN_MODE );
00721 fflush( stdout );
00722
00723
00724
00725 while ( ++i < MAX_GIN && ( input_string[i - 1] = getchar() ) != '\n' )
00726 ;
00727
00728 input_string[i - 1] = '\0';
00729 ptr->keysym = input_string[0];
00730 decode_gin( &input_string[1], ptr );
00731
00732
00733
00734 printf( VECTOR_MODE );
00735 }
00736 }
00737
00738
00739
00740
00741
00742
00743
00744 static void
00745 fill_polygon( PLStream *pls )
00746 {
00747 TekDev *dev = (TekDev *) pls->dev;
00748 int i;
00749 char fillcol[4], firstpoint[5];
00750
00751 if ( pls->dev_npts < 1 )
00752 return;
00753
00754 tek_graph( pls );
00755
00756 encode_int( fillcol, -dev->curcolor );
00757 encode_vector( firstpoint, pls->dev_x[0], pls->dev_y[0] );
00758
00759
00760
00761 pls->bytecnt += fprintf( pls->OutFile, "\033MP%s", fillcol );
00762
00763
00764
00765
00766 if ( pls->debug )
00767 pls->bytecnt += fprintf( pls->OutFile, "\033LP%s1", firstpoint );
00768 else
00769 pls->bytecnt += fprintf( pls->OutFile, "\033LP%s0", firstpoint );
00770
00771
00772
00773 pls->bytecnt += fprintf( pls->OutFile, VECTOR_MODE );
00774 for ( i = 1; i < pls->dev_npts; i++ )
00775 tek_vector( pls, pls->dev_x[i], pls->dev_y[i] );
00776
00777
00778
00779 pls->bytecnt += fprintf( pls->OutFile, "\033LE" );
00780 }
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800 static void
00801 tek_text( PLStream *pls )
00802 {
00803 if ( pls->termin && ( pls->graphx == GRAPHICS_MODE ) )
00804 {
00805 tty_reset();
00806 pls->graphx = TEXT_MODE;
00807 switch ( pls->dev_minor )
00808 {
00809 case xterm:
00810 printf( "\033\003" );
00811 break;
00812
00813 case mskermit:
00814 case vlt:
00815 printf( "\033[?38l" );
00816 break;
00817
00818 case versaterm:
00819 printf( "\033%%!2" );
00820 break;
00821
00822 case tek4107:
00823 printf( "\033LV1" );
00824 printf( "\033%%!1" );
00825 break;
00826
00827 default:
00828 printf( ALPHA_MODE );
00829 }
00830 fflush( stdout );
00831 }
00832 }
00833
00834
00835
00836
00837
00838
00839
00840
00841 static void
00842 tek_graph( PLStream *pls )
00843 {
00844 if ( pls->termin && ( pls->graphx == TEXT_MODE ) )
00845 {
00846 tty_cbreak();
00847 pls->graphx = GRAPHICS_MODE;
00848 switch ( pls->dev_minor )
00849 {
00850 case xterm:
00851 case mskermit:
00852 case vlt:
00853 printf( "\033[?38h" );
00854 break;
00855
00856 case versaterm:
00857 printf( "\033%%!0" );
00858 break;
00859
00860 case tek4107:
00861 printf( "\033%%!0" );
00862 printf( CLEAR_VIEW );
00863 printf( "\033LV0" );
00864 break;
00865 }
00866 }
00867 }
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877 static void
00878 encode_int( char *c, int i )
00879 {
00880 int negative = 0;
00881
00882 if ( i > 0 )
00883 {
00884 if ( i & 0x7C00 )
00885 *c++ = ( ( i >> 10 ) & 0x1F ) | 0x40;
00886 if ( i & 0x03F0 )
00887 *c++ = ( ( i >> 4 ) & 0x3F ) | 0x40;
00888 }
00889 else
00890 {
00891 i = -i;
00892 negative = 1;
00893 }
00894
00895 if ( i & 0x000F )
00896 *c = ( i & 0x0F ) | 0x20;
00897 else
00898 *c = 0x20;
00899
00900 if ( !negative )
00901 *c |= 0x10;
00902
00903 c++; *c = '\0';
00904 return;
00905 }
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920 static void
00921 decode_gin( char *c, PLGraphicsIn *gin )
00922 {
00923 int x, y, lc = strlen( c );
00924
00925 if ( lc == 4 )
00926 {
00927 x = ( ( c[0] & 0x1f ) << 5 ) +
00928 ( ( c[1] & 0x1f ) );
00929
00930 y = ( ( c[2] & 0x1f ) << 5 ) +
00931 ( ( c[3] & 0x1f ) );
00932
00933 gin->pX = x;
00934 gin->pY = y;
00935 gin->dX = x / (double) TEKX;
00936 gin->dY = y / (double) TEKY;
00937 }
00938 else if ( lc == 5 )
00939 {
00940 y = ( ( c[0] & 0x1f ) << 7 ) +
00941 ( ( c[2] & 0x1f ) << 2 ) +
00942 ( ( c[1] & 0x06 ) >> 2 );
00943
00944 x = ( ( c[3] & 0x1f ) << 7 ) +
00945 ( ( c[4] & 0x1f ) << 2 ) +
00946 ( ( c[1] & 0x03 ) );
00947
00948 gin->pX = x;
00949 gin->pY = y;
00950 gin->dX = x / (double) ( TEKX << 2 );
00951 gin->dY = y / (double) ( TEKY << 2 );
00952 }
00953 else
00954 {
00955 gin->pX = 0;
00956 gin->pY = 0;
00957 gin->dY = 0;
00958 gin->dX = 0;
00959 }
00960 }
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970 static void
00971 encode_vector( char *c, int x, int y )
00972 {
00973 c[0] = ( y >> 5 ) + 0x20;
00974 c[1] = ( y & 0x1f ) + 0x60;
00975 c[2] = ( x >> 5 ) + 0x20;
00976 c[3] = ( x & 0x1f ) + 0x40;
00977 c[4] = '\0';
00978 }
00979
00980
00981
00982
00983
00984
00985
00986
00987 static void
00988 tek_vector( PLStream *pls, int x, int y )
00989 {
00990 char c[5];
00991
00992 encode_vector( c, x, y );
00993 pls->bytecnt += fprintf( pls->OutFile, "%s", c );
00994 }
00995
00996
00997
00998
00999
01000
01001
01002
01003 static void
01004 scolor( PLStream *pls, int icol, int r, int g, int b )
01005 {
01006 char tek_col[4], tek_r[4], tek_g[4], tek_b[4];
01007
01008 encode_int( tek_col, icol );
01009 encode_int( tek_r, ( 100 * r ) / 255 );
01010 encode_int( tek_g, ( 100 * g ) / 255 );
01011 encode_int( tek_b, ( 100 * b ) / 255 );
01012
01013 pls->bytecnt += fprintf( pls->OutFile, "\033TG14%s%s%s%s",
01014 tek_col, tek_r, tek_g, tek_b );
01015 }
01016
01017
01018
01019
01020
01021
01022
01023 static void
01024 setcmap( PLStream *pls )
01025 {
01026 int i, ncol1 = MIN( 16 - pls->ncol0, pls->ncol1 );
01027 PLColor cmap1col;
01028
01029 tek_graph( pls );
01030
01031
01032
01033 for ( i = 0; i < pls->ncol0; i++ )
01034 scolor( pls, i, pls->cmap0[i].r, pls->cmap0[i].g, pls->cmap0[i].b );
01035
01036
01037
01038 for ( i = 0; i < ncol1; i++ )
01039 {
01040 plcol_interp( pls, &cmap1col, i, ncol1 );
01041 scolor( pls, i + pls->ncol0, cmap1col.r, cmap1col.g, cmap1col.b );
01042 }
01043 }
01044
01045
01046
01047
01048
01049
01050
01051
01052 static void
01053 WaitForPage( PLStream *pls )
01054 {
01055 TekDev *dev = (TekDev *) pls->dev;
01056
01057 printf( ALPHA_MODE );
01058 printf( RING_BELL );
01059 printf( VECTOR_MODE );
01060 fflush( stdout );
01061
01062 while ( !dev->exit_eventloop )
01063 {
01064 LookupEvent( pls );
01065 if ( dev->locate_mode )
01066 LocateEH( pls );
01067 else
01068 InputEH( pls );
01069 }
01070 dev->exit_eventloop = FALSE;
01071 }
01072
01073
01074
01075
01076
01077
01078
01079 static void
01080 LookupEvent( PLStream *pls )
01081 {
01082 TekDev *dev = (TekDev *) pls->dev;
01083 PLGraphicsIn *gin = &( dev->gin );
01084
01085 if ( dev->locate_mode )
01086 {
01087 GetCursor( pls, gin );
01088 }
01089 else
01090 {
01091 plGinInit( gin );
01092 gin->keysym = getchar();
01093 }
01094
01095 if ( isprint( gin->keysym ) )
01096 {
01097 gin->string[0] = gin->keysym;
01098 gin->string[1] = '\0';
01099 }
01100 else
01101 {
01102 gin->string[0] = '\0';
01103 }
01104
01105 pldebug( "LookupEvent",
01106 "Keycode %x, string: %s\n", gin->keysym, gin->string );
01107 }
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138 static void
01139 LocateEH( PLStream *pls )
01140 {
01141 TekDev *dev = (TekDev *) pls->dev;
01142 PLGraphicsIn *gin = &( dev->gin );
01143
01144
01145
01146 if ( gin->keysym == PLK_Escape )
01147 {
01148 dev->locate_mode = 0;
01149 return;
01150 }
01151
01152
01153
01154 if ( pls->LocateEH != NULL )
01155 ( *pls->LocateEH )( gin, pls->LocateEH_data, &dev->locate_mode );
01156
01157
01158
01159 else
01160 {
01161
01162
01163 if ( plTranslateCursor( gin ) )
01164 {
01165
01166
01167 pltext();
01168 if ( isprint( gin->keysym ) )
01169 printf( "%f %f %c\n", gin->wX, gin->wY, gin->keysym );
01170 else
01171 printf( "%f %f\n", gin->wX, gin->wY );
01172
01173 plgra();
01174 }
01175 else
01176 {
01177
01178
01179 dev->locate_mode = 0;
01180 }
01181 }
01182 }
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196 static void
01197 InputEH( PLStream *pls )
01198 {
01199 TekDev *dev = (TekDev *) pls->dev;
01200 PLGraphicsIn *gin = &( dev->gin );
01201
01202
01203
01204
01205
01206 if ( pls->KeyEH != NULL )
01207 ( *pls->KeyEH )( gin, pls->KeyEH_data, &dev->exit_eventloop );
01208
01209
01210
01211 switch ( gin->keysym )
01212 {
01213 case PLK_Linefeed:
01214
01215 dev->exit_eventloop = TRUE;
01216 break;
01217
01218 case 'Q':
01219
01220 pls->nopause = TRUE;
01221 plexit( "" );
01222 break;
01223
01224 case 'L':
01225
01226 dev->locate_mode = 1;
01227 break;
01228 }
01229 }
01230
01231
01232
01233
01234
01235
01236
01237
01238 #ifdef HAVE_TERMIOS_H
01239
01240 static void
01241 tty_setup( void )
01242 {
01243 if ( tcgetattr( STDIN_FILENO, &termios_reset ) < 0 )
01244 {
01245 fprintf( stderr, "Unable to set up cbreak mode.\n" );
01246 return;
01247 }
01248
01249 termios_cbreak = termios_reset;
01250
01251 termios_cbreak.c_lflag &= ~( ICANON );
01252 termios_cbreak.c_cc[VMIN] = 1;
01253 termios_cbreak.c_cc[VTIME] = 0;
01254
01255 #ifdef STDC_HEADERS
01256 if ( atexit( tty_atexit ) )
01257 fprintf( stderr, "Unable to set up atexit handler.\n" );
01258 #endif
01259 return;
01260 }
01261
01262 static int
01263 tty_cbreak( void )
01264 {
01265 if ( ttystate != CBREAK )
01266 {
01267 if ( tcsetattr( STDIN_FILENO, TCSAFLUSH, &termios_cbreak ) < 0 )
01268 return -1;
01269
01270 ttystate = CBREAK;
01271 }
01272 return 0;
01273 }
01274
01275 static int
01276 tty_reset( void )
01277 {
01278 if ( ttystate != RESET )
01279 {
01280 if ( tcsetattr( STDIN_FILENO, TCSAFLUSH, &termios_reset ) < 0 )
01281 return -1;
01282
01283 ttystate = RESET;
01284 }
01285 return 0;
01286 }
01287
01288 static void
01289 tty_atexit( void )
01290 {
01291 tty_reset();
01292 }
01293
01294 #endif // HAVE_TERMIOS_H
01295
01296 #else
01297 int pldummy_tek()
01298 {
01299 return 0;
01300 }
01301
01302 #endif // defined(PLD_xterm) || ...