37 #ifdef ENABLE_DYNDRIVERS
49 # ifdef NEED_SYS_TYPE_H
50 # include <sys/types.h>
53 # define NAMLEN( dirent ) strlen( ( dirent )->d_name )
55 # if defined ( _MSC_VER )
58 # define dirent direct
59 # define NAMLEN( dirent ) ( dirent )->d_namlen
61 # include <sys/ndir.h>
78 #if defined ( _MSC_VER )
80 # define getcwd _getcwd
84 #define BUFFER_SIZE 80
85 #define BUFFER2_SIZE 300
86 #define DRVSPEC_SIZE 400
94 text2fci(
const char *text,
unsigned char *hexdigit,
unsigned char *hexpower );
140 plsc->page_status =
AT_EOP;
141 plsc->stream_closed =
FALSE;
144 ( *plsc->dispatch_table->pl_init )( (
struct PLStream_struct *) plsc );
147 if ( plsc->plbuf_write )
158 int skip_driver_eop = 0;
160 if ( plsc->page_status ==
AT_EOP )
163 plsc->page_status =
AT_EOP;
165 if ( plsc->plbuf_write )
170 if ( plsc->eop_handler != NULL )
171 ( *plsc->eop_handler )( plsc->eop_data, &skip_driver_eop );
173 if ( !skip_driver_eop )
176 if ( !plsc->stream_closed )
178 ( *plsc->dispatch_table->pl_eop )( (
struct PLStream_struct *) plsc );
192 int skip_driver_bop = 0;
195 if ( plsc->page_status ==
AT_BOP )
198 plsc->page_status =
AT_BOP;
203 if ( plsc->bop_handler != NULL )
204 ( *plsc->bop_handler )( plsc->bop_data, &skip_driver_bop );
206 if ( !skip_driver_bop )
209 if ( !plsc->stream_closed )
211 ( *plsc->dispatch_table->pl_bop )( (
struct PLStream_struct *) plsc );
216 if ( plsc->plbuf_write )
228 ( *plsc->tidy )( plsc->tidy_data );
230 plsc->tidy_data = NULL;
234 ( *plsc->dispatch_table->pl_tidy )( (
struct PLStream_struct *) plsc );
237 if ( plsc->plbuf_write )
242 plsc->OutFile = NULL;
251 if ( plsc->plbuf_write )
255 if ( !plsc->stream_closed )
257 ( *plsc->dispatch_table->pl_state )( (
struct PLStream_struct *) plsc, op );
268 PLINT clpxmi, clpxma, clpymi, clpyma;
272 if ( plsc->plbuf_write )
283 difilt( &( args->
x ), &( args->
y ), 1, &clpxmi, &clpxma, &clpymi, &clpyma );
288 if ( !plsc->stream_closed )
290 ( *plsc->dispatch_table->pl_esc )( (
struct PLStream_struct *) plsc, op, ptr );
303 PLINT clpxmi, clpxma, clpymi, clpyma;
307 if ( plsc->plbuf_write )
340 if ( plsc->dev_swin )
343 if ( !plsc->stream_closed )
345 ( *plsc->dispatch_table->pl_esc )( (
struct PLStream_struct *) plsc,
361 if ( !plsc->nopause && *plsc->dispatch_table->pl_wait != NULL )
364 if ( !plsc->stream_closed )
366 ( *plsc->dispatch_table->pl_wait )( (
struct PLStream_struct *) plsc );
382 PLINT i, npts = 2, clpxmi, clpxma, clpymi, clpyma;
386 if ( plsc->plbuf_write )
391 for ( i = 0; i < npts; i++ )
411 PLINT i, clpxmi, clpxma, clpymi, clpyma;
415 if ( plsc->plbuf_write )
420 for ( i = 0; i < npts; i++ )
445 PLINT i, clpxmi, clpxma, clpymi, clpyma;
449 if ( plsc->plbuf_write )
451 plsc->dev_npts = npts;
459 if ( plsc->patt == 0 && !plsc->dev_fill0 )
463 plwarn(
"Driver does not support hardware solid fills, switching to software fill.\n" );
469 if ( plsc->dev_fill1 )
471 plsc->patt = -
ABS( plsc->patt );
479 if ( plsc->patt > 0 )
486 for ( i = 0; i < npts; i++ )
510 PLINT i, clpxmi, clpxma, clpymi, clpyma;
514 if ( plsc->plbuf_write )
516 plsc->dev_npts = npts;
525 for ( i = 0; i < npts; i++ )
563 *num = (
PLUNICODE) strtoul( text, &endptr, 0 );
565 if ( end != endptr[0] )
567 snprintf( msgbuf,
BUFFER_SIZE,
"text2num: invalid control string detected - %c expected", end );
571 return (
int) ( endptr - text );
592 int text2fci(
const char *text,
unsigned char *hexdigit,
unsigned char *hexpower )
597 unsigned char hexdigit;
598 unsigned char hexpower;
604 #define N_TextLookupTable 10
620 length = (int) strlen( lookup[i].ptext );
621 if ( !strncmp( text, lookup[i].ptext, (
size_t) length ) )
623 *hexdigit = lookup[i].hexdigit;
624 *hexpower = lookup[i].hexpower;
638 unsigned char hexdigit, hexpower;
649 len = strlen(
string );
666 for ( i = 0; i < len; i++ )
670 if (
string[i] == esc )
672 switch (
string[i + 1] )
675 i += 2 +
text2num( &
string[i + 2],
')', &code );
685 i += 2 +
text2num( &
string[i + 2],
']', &code );
692 if (
'0' <=
string[i + 2] &&
string[i + 2] <=
'9' )
694 i += 2 +
text2num( &
string[i + 2],
'>', &code );
726 i +=
text2fci( &
string[i + 1], &hexdigit, &hexpower );
748 if (
string[i + 2] ==
'n' )
753 else if (
string[i + 2] ==
'r' )
758 else if (
string[i + 2] ==
'i' )
764 else if (
string[i + 2] ==
's' )
801 else if ( ig == 634 )
803 else if ( ig == 647 )
865 #ifdef HAVE_LIBUNICODE
866 const char * ptr = unicode_get_utf8(
string + i, &unichar );
868 const char * ptr =
utf8_to_ucs4(
string + i, &unichar );
874 strncpy( tmpstring,
string, 30 );
875 tmpstring[30] =
'\0';
877 tmpstring, strlen(
string ) > 30 ?
"[...]" :
"" );
881 i += (int) ( ptr - (
string + i ) - 1 );
886 if (
string[i] == esc &&
string[i + 1] == esc )
910 unsigned char hexdigit, hexpower;
922 len = strlen(
string );
944 for ( j = i = 0; i < len; i++ )
948 if (
string[i] == esc )
952 switch (
string[i + 1] )
955 i += ( 2 +
text2num( &
string[i + 2],
')', &code ) );
974 i += ( 2 +
text2num( &
string[i + 2],
']', &code ) );
991 if (
'0' <=
string[i + 2] &&
string[i + 2] <=
'9' )
993 i += 2 +
text2num( &
string[i + 2],
'>', &code );
1019 i +=
text2fci( &
string[i + 1], &hexdigit, &hexpower );
1038 if (
string[i + 2] ==
'n' )
1043 else if (
string[i + 2] ==
'r' )
1048 else if (
string[i + 2] ==
'i' )
1054 else if (
string[i + 2] ==
's' )
1089 else if ( ig == 634 )
1091 else if ( ig == 647 )
1117 #ifdef HAVE_LIBUNICODE
1118 const char * ptr = unicode_get_utf8(
string + i, &unichar );
1120 const char * ptr =
utf8_to_ucs4(
string + i, &unichar );
1126 strncpy( tmpstring,
string, 30 );
1127 tmpstring[30] =
'\0';
1129 tmpstring, strlen(
string ) > 30 ?
"[...]" :
"" );
1134 i += (int) ( ptr - (
string + i ) - 1 );
1140 &&
string[i + 1] == esc )
1164 if (
string == NULL )
1167 if ( plsc->dev_text )
1186 if ( plsc->dev_unicode )
1188 if ( plsc->alt_unicode )
1213 len = strlen(
string );
1225 plstr( base, xform, refx, refy,
string );
1245 if ( (
unsigned char) ( tmp & 0x80 ) == 0x00 )
1247 *unichar = (
unsigned int) tmp & 0x7F;
1250 else if ( (
unsigned char) ( tmp & 0xE0 ) == 0xC0 )
1252 *unichar = (
unsigned int) tmp & 0x1F;
1255 else if ( (
unsigned char) ( tmp & 0xF0 ) == 0xE0 )
1257 *unichar = (
unsigned char) tmp & 0x0F;
1260 else if ( (
unsigned char) ( tmp & 0xF8 ) == 0xF0 )
1262 *unichar = (
unsigned char) tmp & 0x07;
1265 else if ( (
unsigned char) ( tmp & 0xFC ) == 0xF8 )
1267 *unichar = (
unsigned char) tmp & 0x03;
1270 else if ( (
unsigned char) ( tmp & 0xFE ) == 0xFC )
1272 *unichar = (
unsigned char) tmp & 0x01;
1283 if ( (
unsigned char) ( tmp & 0xC0 ) == 0x80 )
1285 *unichar = ( *unichar << 6 ) | ( (
unsigned int) tmp & 0x3F );
1294 }
while ( cnt > 0 );
1305 tmp = (
unsigned char *) ptr;
1307 if ( ( unichar & 0xffff80 ) == 0 )
1309 *tmp = (
unsigned char) unichar;
1313 else if ( ( unichar & 0xfff800 ) == 0 )
1315 *tmp = (
unsigned char) 0xc0 | (
unsigned char) ( unichar >> 6 );
1317 *tmp = (
unsigned char) ( 0x80 | (
unsigned char) ( unichar & (
PLUINT) 0x3f ) );
1321 else if ( ( unichar & 0xff0000 ) == 0 )
1323 *tmp = (
unsigned char) 0xe0 | (
unsigned char) ( unichar >> 12 );
1325 *tmp = (
unsigned char) ( 0x80 | (
unsigned char) ( ( unichar >> 6 ) & 0x3f ) );
1327 *tmp = (
unsigned char) ( 0x80 | ( (
unsigned char) unichar & 0x3f ) );
1331 else if ( ( unichar & 0xe0000 ) == 0 )
1333 *tmp = (
unsigned char) 0xf0 | (
unsigned char) ( unichar >> 18 );
1335 *tmp = (
unsigned char) ( 0x80 | (
unsigned char) ( ( unichar >> 12 ) & 0x3f ) );
1337 *tmp = (
unsigned char) ( 0x80 | (
unsigned char) ( ( unichar >> 6 ) & 0x3f ) );
1339 *tmp = (
unsigned char) ( 0x80 | (
unsigned char) ( unichar & 0x3f ) );
1356 if ( !plsc->stream_closed )
1358 ( *plsc->dispatch_table->pl_line )( (
struct PLStream_struct *) plsc,
1359 x[0], y[0], x[1], y[1] );
1368 if ( !plsc->stream_closed )
1370 ( *plsc->dispatch_table->pl_polyline )( (
struct PLStream_struct *) plsc,
1380 plsc->dev_npts = npts;
1385 if ( !plsc->stream_closed )
1387 ( *plsc->dispatch_table->pl_esc )( (
struct PLStream_struct *) plsc,
1397 plsc->dev_npts = npts;
1402 if ( !plsc->stream_closed )
1404 ( *plsc->dispatch_table->pl_esc )( (
struct PLStream_struct *) plsc,
1440 for ( i = 0; i < npts; i++ )
1442 xsc[i] = (
PLINT) ( plsc->dimxax * xsc[i] + plsc->dimxb );
1443 ysc[i] = (
PLINT) ( plsc->dimyay * ysc[i] + plsc->dimyb );
1451 for ( i = 0; i < npts; i++ )
1453 x = (
PLINT) ( plsc->dioxax * xsc[i] + plsc->dioxay * ysc[i] + plsc->dioxb );
1454 y = (
PLINT) ( plsc->dioyax * xsc[i] + plsc->dioyay * ysc[i] + plsc->dioyb );
1464 for ( i = 0; i < npts; i++ )
1466 xsc[i] = (
PLINT) ( plsc->dipxax * xsc[i] + plsc->dipxb );
1467 ysc[i] = (
PLINT) ( plsc->dipyay * ysc[i] + plsc->dipyb );
1476 for ( i = 0; i < npts; i++ )
1478 xsc[i] = (
PLINT) ( plsc->didxax * xsc[i] + plsc->didxb );
1479 ysc[i] = (
PLINT) ( plsc->didyay * ysc[i] + plsc->didyb );
1481 *clpxmi = plsc->diclpxmi;
1482 *clpxma = plsc->diclpxma;
1483 *clpymi = plsc->diclpymi;
1484 *clpyma = plsc->diclpyma;
1488 *clpxmi = plsc->phyxmi;
1489 *clpxma = plsc->phyxma;
1490 *clpymi = plsc->phyymi;
1491 *clpyma = plsc->phyyma;
1576 PLINT x1c, x2c, y1c, y2c;
1590 difilt( x_coords, y_coords, 4, &x1c, &x2c, &y1c, &y2c );
1604 plsc->dipxmin = 0.0;
1605 plsc->dipxmax = 1.0;
1606 plsc->dipymin = 0.0;
1607 plsc->dipymax = 1.0;
1628 if ( plsc->level >= 1 )
1630 if ( plsc->plbuf_write )
1664 PLFLT pxmin, pymin, pxmax, pymax;
1665 PLFLT sxmin, symin, sxmax, symax;
1666 PLFLT rxmin, rymin, rxmax, rymax;
1670 pldebug(
"pldid2pc",
1671 "Relative device coordinates (in): %f, %f, %f, %f\n",
1672 *xmin, *ymin, *xmax, *ymax );
1679 sxmin = ( pxmin - plsc->didxb ) / plsc->didxax;
1680 symin = ( pymin - plsc->didyb ) / plsc->didyay;
1681 sxmax = ( pxmax - plsc->didxb ) / plsc->didxax;
1682 symax = ( pymax - plsc->didyb ) / plsc->didyay;
1689 *xmin = ( rxmin < 0 ) ? 0 : rxmin;
1690 *xmax = ( rxmax > 1 ) ? 1 : rxmax;
1691 *ymin = ( rymin < 0 ) ? 0 : rymin;
1692 *ymax = ( rymax > 1 ) ? 1 : rymax;
1694 pldebug(
"pldid2pc",
1695 "Relative plot coordinates (out): %f, %f, %f, %f\n",
1696 rxmin, rymin, rxmax, rymax );
1710 PLFLT pxmin, pymin, pxmax, pymax;
1711 PLFLT sxmin, symin, sxmax, symax;
1712 PLFLT rxmin, rymin, rxmax, rymax;
1716 pldebug(
"pldip2pc",
1717 "Relative plot coordinates (in): %f, %f, %f, %f\n",
1718 *xmin, *ymin, *xmax, *ymax );
1725 sxmin = pxmin * plsc->didxax + plsc->didxb;
1726 symin = pymin * plsc->didyay + plsc->didyb;
1727 sxmax = pxmax * plsc->didxax + plsc->didxb;
1728 symax = pymax * plsc->didyay + plsc->didyb;
1735 *xmin = ( rxmin < 0 ) ? 0 : rxmin;
1736 *xmax = ( rxmax > 1 ) ? 1 : rxmax;
1737 *ymin = ( rymin < 0 ) ? 0 : rymin;
1738 *ymax = ( rymax > 1 ) ? 1 : rymax;
1740 pldebug(
"pldip2pc",
1741 "Relative device coordinates (out): %f, %f, %f, %f\n",
1742 rxmin, rymin, rxmax, rymax );
1755 plsc->dipxmin = ( xmin <
xmax ) ? xmin : xmax;
1756 plsc->dipxmax = ( xmin <
xmax ) ? xmax : xmin;
1757 plsc->dipymin = ( ymin <
ymax ) ? ymin : ymax;
1758 plsc->dipymax = ( ymin <
ymax ) ? ymax : ymin;
1760 if ( xmin == 0. && xmax == 1. && ymin == 0. && ymax == 1. )
1781 xmin = plsc->dipxmin + ( plsc->dipxmax - plsc->dipxmin ) * xmin;
1782 ymin = plsc->dipymin + ( plsc->dipymax - plsc->dipymin ) * ymin;
1783 xmax = plsc->dipxmin + ( plsc->dipxmax - plsc->dipxmin ) * xmax;
1784 ymax = plsc->dipymin + ( plsc->dipymax - plsc->dipymin ) * ymax;
1787 plsdiplt( xmin, ymin, xmax, ymax );
1804 PLINT pxmin, pxmax, pymin, pymax, pxlen, pylen;
1809 if ( !plsc->stream_closed )
1811 ( *plsc->dispatch_table->pl_esc )( (
struct PLStream_struct *) plsc,
1817 if ( !( plsc->difilt &
PLDI_PLT ) )
1825 pxlen = pxmax - pxmin;
1826 pylen = pymax - pymin;
1827 pxlen =
MAX( 1, pxlen );
1828 pylen =
MAX( 1, pylen );
1830 plsc->dipxax = plsc->phyxlen / (double) pxlen;
1831 plsc->dipyay = plsc->phyylen / (double) pylen;
1832 plsc->dipxb = plsc->phyxmi - plsc->dipxax * pxmin;
1833 plsc->dipyb = plsc->phyymi - plsc->dipyay * pymin;
1845 *p_xmin = plsc->dipxmin;
1846 *p_xmax = plsc->dipxmax;
1847 *p_ymin = plsc->dipymin;
1848 *p_ymax = plsc->dipymax;
1870 if ( mar == 0. && aspect == 0. && jx == 0. && jy == 0. &&
1891 PLFLT lx, ly, aspect, aspdev;
1893 PLINT pxmin, pxmax, pymin, pymax, pxlen, pylen;
1898 if ( !plsc->stream_closed )
1900 ( *plsc->dispatch_table->pl_esc )( (
struct PLStream_struct *) plsc,
1906 if ( !( plsc->difilt &
PLDI_DEV ) )
1911 lx = plsc->phyxlen / plsc->xpmm;
1912 ly = plsc->phyylen / plsc->ypmm;
1916 aspect = plsc->aspori;
1918 aspect = plsc->aspect;
1921 aspect = plsc->aspdev;
1925 plsc->mar = ( plsc->mar > 0.5 ) ? 0.5 : plsc->mar;
1926 plsc->mar = ( plsc->mar < 0.0 ) ? 0.0 : plsc->mar;
1927 plsc->jx = ( plsc->jx > 0.5 ) ? 0.5 : plsc->jx;
1928 plsc->jx = ( plsc->jx < -0.5 ) ? -0.5 : plsc->jx;
1929 plsc->jy = ( plsc->jy > 0.5 ) ? 0.5 : plsc->jy;
1930 plsc->jy = ( plsc->jy < -0.5 ) ? -0.5 : plsc->jy;
1934 xlen = ( aspect < aspdev ) ? ( aspect / aspdev ) : 1.0;
1935 ylen = ( aspect < aspdev ) ? 1.0 : ( aspdev / aspect );
1937 xlen *= ( 1.0 - 2. * plsc->mar );
1938 ylen *= ( 1.0 - 2. * plsc->mar );
1940 xmin = ( 1. - xlen ) * ( 0.5 + plsc->jx );
1943 ymin = ( 1. - ylen ) * ( 0.5 + plsc->jy );
1953 pxlen = pxmax - pxmin;
1954 pylen = pymax - pymin;
1955 pxlen =
MAX( 1, pxlen );
1956 pylen =
MAX( 1, pylen );
1958 plsc->didxax = pxlen / (double) plsc->phyxlen;
1959 plsc->didyay = pylen / (
double) plsc->phyylen;
1960 plsc->didxb = pxmin - plsc->didxax * plsc->phyxmi;
1961 plsc->didyb = pymin - plsc->didyay * plsc->phyymi;
1965 plsc->diclpxmi = (
PLINT) ( plsc->didxax * plsc->phyxmi + plsc->didxb );
1966 plsc->diclpxma = (
PLINT) ( plsc->didxax * plsc->phyxma + plsc->didxb );
1967 plsc->diclpymi = (
PLINT) ( plsc->didyay * plsc->phyymi + plsc->didyb );
1968 plsc->diclpyma = (
PLINT) ( plsc->didyay * plsc->phyyma + plsc->didyb );
1981 *p_aspect = plsc->aspect;
2018 PLFLT x0, y0, lx, ly, aspect;
2024 if ( !plsc->stream_closed )
2026 ( *plsc->dispatch_table->pl_esc )( (
struct PLStream_struct *) plsc,
2032 if ( !( plsc->difilt &
PLDI_ORI ) )
2037 x0 = ( plsc->phyxma + plsc->phyxmi ) / 2.;
2038 y0 = ( plsc->phyyma + plsc->phyymi ) / 2.;
2042 cost =
ABS( cos( plsc->diorot *
PI / 2. ) );
2043 sint =
ABS( sin( plsc->diorot *
PI / 2. ) );
2047 aspect = plsc->aspect;
2049 aspect = plsc->aspdev;
2051 if ( plsc->freeaspect )
2052 plsc->aspori = aspect;
2054 plsc->aspori = ( aspect * cost + sint ) / ( aspect * sint + cost );
2056 if ( !( plsc->difilt &
PLDI_DEV ) )
2101 plsc->dioxax = affine_result[0];
2102 plsc->dioxay = affine_result[2];
2103 plsc->dioxb = affine_result[4];
2104 plsc->dioyax = affine_result[1];
2105 plsc->dioyay = affine_result[3];
2106 plsc->dioyb = affine_result[5];
2118 *p_rot = plsc->diorot;
2134 plsetvar( plsc->dimxmin, dimxmin );
2135 plsetvar( plsc->dimxmax, dimxmax );
2136 plsetvar( plsc->dimymin, dimymin );
2137 plsetvar( plsc->dimymax, dimymax );
2138 plsetvar( plsc->dimxpmm, dimxpmm );
2139 plsetvar( plsc->dimypmm, dimypmm );
2158 PLINT pxmin, pxmax, pymin, pymax;
2159 PLFLT dimxlen, dimylen, pxlen, pylen;
2161 if ( ( plsc->dimxmin == plsc->phyxmi ) && ( plsc->dimxmax == plsc->phyxma ) &&
2162 ( plsc->dimymin == plsc->phyymi ) && ( plsc->dimymax == plsc->phyyma ) &&
2163 ( plsc->dimxpmm == plsc->xpmm ) && ( plsc->dimypmm == plsc->ypmm ) )
2171 lx = ( plsc->dimxmax - plsc->dimxmin + 1 ) / plsc->dimxpmm;
2172 ly = ( plsc->dimymax - plsc->dimymin + 1 ) / plsc->dimypmm;
2174 plsc->aspdev = lx / ly;
2178 dimxlen = plsc->dimxmax - plsc->dimxmin;
2179 dimylen = plsc->dimymax - plsc->dimymin;
2181 pxmin = plsc->phyxmi;
2182 pxmax = plsc->phyxma;
2183 pymin = plsc->phyymi;
2184 pymax = plsc->phyyma;
2185 pxlen = pxmax - pxmin;
2186 pylen = pymax - pymin;
2188 plsc->dimxax = pxlen / dimxlen;
2189 plsc->dimyay = pylen / dimylen;
2190 plsc->dimxb = pxmin - pxlen * plsc->dimxmin / dimxlen;
2191 plsc->dimyb = pymin - pylen * plsc->dimymin / dimylen;
2203 if ( plsc->dev_flush )
2206 if ( !plsc->stream_closed )
2208 ( *plsc->dispatch_table->pl_esc )( (
struct PLStream_struct *) plsc,
2215 if ( plsc->OutFile != NULL )
2216 fflush( plsc->OutFile );
2239 #ifdef ENABLE_DYNDRIVERS
2261 if ( plsc->level != 0 )
2280 if ( plsc->level != 0 )
2298 PLFLT lx, ly, xpmm_loc, ypmm_loc, aspect_old, aspect_new;
2302 if ( plsc->level != 0 )
2318 if ( plsc->plwindow == NULL )
2320 if ( plsc->program )
2322 if ( ( plsc->plwindow = (
char *) malloc( (
size_t) ( 1 + strlen( plsc->program ) ) * sizeof (
char ) ) ) == NULL )
2324 plexit(
"plinit: Insufficient memory" );
2326 strcpy( plsc->plwindow, plsc->program );
2330 if ( ( plsc->plwindow = (
char *) malloc( (
size_t) 7 *
sizeof (
char ) ) ) == NULL )
2332 plexit(
"plinit: Insufficient memory" );
2334 strcpy( plsc->plwindow,
"PLplot" );
2361 if ( plsc->aspect > 0. )
2363 lx = plsc->phyxlen / plsc->xpmm;
2364 ly = plsc->phyylen / plsc->ypmm;
2365 aspect_old = lx / ly;
2366 aspect_new = plsc->aspect;
2367 plsc->caspfactor = sqrt( aspect_old / aspect_new );
2371 else if ( plsc->freeaspect &&
ABS( cos( plsc->diorot *
PI / 2. ) ) <= 1.e-5 )
2373 lx = plsc->phyxlen / plsc->xpmm;
2374 ly = plsc->phyylen / plsc->ypmm;
2375 aspect_old = lx / ly;
2376 aspect_new = ly / lx;
2377 plsc->caspfactor = sqrt( aspect_old / aspect_new );
2381 plsc->caspfactor = 1.;
2395 if ( plsc->xdigmax == 0 )
2398 if ( plsc->ydigmax == 0 )
2401 if ( plsc->zdigmax == 0 )
2404 if ( plsc->timefmt == NULL )
2410 if ( plsc->qsasconfig == NULL )
2411 c_plconfigtime( 0., 0., 0., 0x0, 0, 0, 0, 0, 0, 0, 0. );
2426 plsc->clpxmi = plsc->phyxmi;
2427 plsc->clpxma = plsc->phyxma;
2428 plsc->clpymi = plsc->phyymi;
2429 plsc->clpyma = plsc->phyyma;
2433 lx = plsc->phyxlen / plsc->xpmm;
2434 ly = plsc->phyylen / plsc->ypmm;
2435 plsc->aspdev = lx / ly;
2448 plP_setpxl( xpmm_loc * plsc->caspfactor, ypmm_loc / plsc->caspfactor );
2467 if (
pls[i] != NULL )
2474 #ifdef ENABLE_DYNDRIVERS
2480 free_mem( loadable_device_list[i].devnam );
2481 free_mem( loadable_device_list[i].description );
2482 free_mem( loadable_device_list[i].drvnam );
2483 free_mem( loadable_device_list[i].tag );
2486 for ( i = 0; i < nloadabledrivers; i++ )
2488 free_mem( loadable_driver_list[i].drvnam );
2518 if ( plsc->level > 0 )
2526 if ( plsc->FileName )
2539 if ( plsc->program )
2541 if ( plsc->server_name )
2543 if ( plsc->server_host )
2545 if ( plsc->server_port )
2549 if ( plsc->plserver )
2551 if ( plsc->auto_path )
2554 if ( plsc->arrow_x )
2556 if ( plsc->arrow_y )
2559 if ( plsc->timefmt )
2568 if ( plsc->mf_infile )
2570 if ( plsc->mf_outfile )
2600 "plsstrm: Illegal stream number %d, must be in [0, %d]\n",
2610 plexit(
"plsstrm: Out of memory." );
2651 if (
pls[i] == NULL )
2655 if ( i == PL_NSTREAMS )
2657 fprintf( stderr,
"plmkstrm: Cannot create new stream\n" );
2687 if ( !plsc->initialized )
2689 plsc->initialized = 1;
2691 if ( plsc->cmap0 == NULL )
2694 if ( plsc->cmap1 == NULL )
2698 plsc->cmap1_min = 0.0;
2699 plsc->cmap1_max = 1.0;
2743 fprintf( stderr,
"plcpstrm: stream %d not in use\n", (
int) iplsr );
2749 plsc->debug = plsr->
debug;
2757 if ( ( plsc->plbuf_buffer = malloc( plsc->plbuf_buffer_size ) ) == NULL )
2758 plexit(
"plcpstrm: Error allocating plot buffer." );
2775 if ( !( flags & 0x01 ) )
2777 pldebug(
"plcpstrm",
"mapping parameters: %d %d %d %d %f %f\n",
2790 plsc->icol0 = plsr->
icol0;
2791 plsc->ncol0 = plsr->
ncol0;
2792 if ( plsc->cmap0 != NULL )
2793 free( (
void *) plsc->cmap0 );
2795 if ( ( plsc->cmap0 = (
PLColor *) calloc( 1, (
size_t) plsc->ncol0 * sizeof (
PLColor ) ) ) == NULL )
2797 plexit(
"c_plcpstrm: Insufficient memory" );
2800 for ( i = 0; i < plsc->ncol0; i++ )
2805 plsc->icol1 = plsr->
icol1;
2806 plsc->ncol1 = plsr->
ncol1;
2809 if ( plsc->cmap1 != NULL )
2810 free( (
void *) plsc->cmap1 );
2812 if ( ( plsc->cmap1 = (
PLColor *) calloc( 1, (
size_t) plsc->ncol1 * sizeof (
PLColor ) ) ) == NULL )
2814 plexit(
"c_plcpstrm: Insufficient memory" );
2817 for ( i = 0; i < plsc->ncol1; i++ )
2822 if ( plsc->level == 0 )
2850 if ( plsc->dev_initialized )
2852 plsc->dev_initialized = 1;
2864 static int inited = 0;
2865 static int inBuildTree = 0;
2869 int len_currdir, len_builddir;
2876 pldebug(
"plInBuildTree():",
"Not enough buffer space" );
2880 pldebug(
"plInBuildTree(): ",
"current directory >%s<\n", currdir );
2881 pldebug(
"plInBuildTree(): ",
"build directory >%s<\n",
BUILD_DIR );
2889 pldebug(
"plInBuildTree():",
"Not enough buffer space" );
2893 len_currdir = strlen( currdir );
2894 len_builddir = strlen( builddir );
2895 #if defined ( IGNORECASE )
2896 pldebug(
"plInBuildTree(): ",
"comparing ignoring case\n" );
2899 for (; *pcurrdir; ++pcurrdir )
2901 *pcurrdir = tolower( *pcurrdir );
2902 if ( *pcurrdir ==
'\\' )
2907 for (; *pbuilddir; ++pbuilddir )
2909 *pbuilddir = tolower( *pbuilddir );
2910 if ( *pbuilddir ==
'\\' )
2923 if ( strncmp( builddir, currdir, len_builddir ) == 0 &&
2924 ( len_currdir == len_builddir || currdir[len_builddir] ==
'\\' || currdir[len_builddir] ==
'/' ) )
2926 pldebug(
"plInBuildTree(): ",
"comparing respecting case\n" );
2927 if ( strncmp( builddir, currdir, len_builddir ) == 0 &&
2928 ( len_currdir == len_builddir || currdir[len_builddir] ==
'/' ) )
2934 if ( chdir( currdir ) != 0 )
2935 pldebug(
"plInBuildTree():",
"Unable to chdir to current directory" );
2943 #ifdef ENABLE_DYNDRIVERS
2957 pldebug(
"plGetDrvDir",
"Using %s as the driver directory.\n", drvdir );
2961 pldebug(
"plGetDrvDir",
"Trying to read env var PLPLOT_DRV_DIR\n" );
2962 drvdir = getenv(
"PLPLOT_DRV_DIR" );
2964 if ( drvdir == NULL )
2966 pldebug(
"plGetDrvDir",
2967 "Will use drivers dir: " DRV_DIR "\n" );
3000 #ifdef ENABLE_DYNDRIVERS
3002 const char * drvdir;
3003 char *devnam, *devdesc, *devtype, *driver, *tag, *seqstr;
3005 int i, j, driver_found, done = 0;
3006 FILE *fp_drvdb = NULL;
3007 DIR * dp_drvdir = NULL;
3013 nloadabledrivers = 0;
3018 if ( fp_drvdb == NULL )
3020 plabort(
"plInitDispatchTable: Could not open temporary file" );
3025 drvdir = plGetDrvDir();
3026 dp_drvdir =
opendir( drvdir );
3027 if ( dp_drvdir == NULL )
3030 plabort(
"plInitDispatchTable: Could not open drivers directory" );
3036 pldebug(
"plInitDispatchTable",
"Scanning dyndrivers dir\n" );
3037 while ( ( entry =
readdir( dp_drvdir ) ) != NULL )
3041 size_t len = strlen( name ) - 12;
3043 pldebug(
"plInitDispatchTable",
3044 "Consider file %s\n", name );
3047 if ( ( len > 0 ) && ( strcmp( name + len,
".driver_info" ) == 0 ) )
3054 fd = fopen( path,
"r" );
3060 "plInitDispatchTable: Could not open driver info file %s\n",
3070 pldebug(
"plInitDispatchTable",
3071 "Opened driver info file %s\n", name );
3074 fprintf( fp_drvdb,
"%s", buf );
3075 if ( buf [strlen( buf ) - 1] !=
'\n' )
3076 fprintf( fp_drvdb,
"\n" );
3094 #ifdef ENABLE_DYNDRIVERS
3097 plexit(
"plInitDispatchTable: Insufficient memory" );
3109 #ifdef ENABLE_DYNDRIVERS
3112 plexit(
"plInitDispatchTable: Insufficient memory" );
3124 #ifdef ENABLE_DYNDRIVERS
3129 if ( ( ( loadable_device_list = malloc( (
size_t)
npldynamicdevices *
sizeof ( PLLoadableDevice ) ) ) == NULL ) ||
3130 ( ( loadable_driver_list = malloc( (
size_t)
npldynamicdevices *
sizeof ( PLLoadableDriver ) ) ) == NULL ) )
3133 plexit(
"plInitDispatchTable: Insufficient memory" );
3150 devnam = strtok( buf,
":" );
3151 devdesc = strtok( 0,
":" );
3152 devtype = strtok( 0,
":" );
3153 driver = strtok( 0,
":" );
3154 seqstr = strtok( 0,
":" );
3155 tag = strtok( 0,
"\n" );
3157 if ( devnam == NULL || devdesc == NULL || devtype == NULL || driver == NULL ||
3158 seqstr == NULL || tag == NULL )
3163 seq = atoi( seqstr );
3170 plexit(
"plInitDispatchTable: Insufficient memory" );
3185 loadable_device_list[i].devnam =
plstrdup( devnam );
3186 loadable_device_list[i].description =
plstrdup( devdesc );
3187 loadable_device_list[i].drvnam =
plstrdup( driver );
3188 loadable_device_list[i].tag =
plstrdup( tag );
3193 for ( j = 0; j < nloadabledrivers; j++ )
3194 if ( strcmp( driver, loadable_driver_list[j].drvnam ) == 0 )
3200 if ( !driver_found )
3202 loadable_driver_list[nloadabledrivers].drvnam =
plstrdup( driver );
3203 loadable_driver_list[nloadabledrivers].dlhand = 0;
3207 loadable_device_list[i].drvidx = j;
3221 plexit(
"No device drivers found - please check the environment variable PLPLOT_DRV_DIR" );
3252 if ( plsc->DevName[0] ==
'\0' )
3254 devname_env = getenv(
"PLPLOT_DEV" );
3257 strncpy( plsc->DevName, devname_env, sizeof ( plsc->DevName ) - 1 );
3258 plsc->DevName[
sizeof ( plsc->DevName ) - 1] =
'\0';
3264 if ( *( plsc->DevName ) !=
'\0' && *( plsc->DevName ) !=
'?' )
3266 length = strlen( plsc->DevName );
3270 ( strncmp( plsc->DevName,
3274 if ( i < npldrivers )
3276 plsc->device = i + 1;
3281 fprintf( stderr,
"Requested device %s not available\n",
3296 fprintf( stdout,
"\nPlotting Options:\n" );
3299 fprintf( stdout,
" <%2d> %-10s %s\n", i + 1,
3304 fprintf( stdout,
"\nEnter device number or keyword: " );
3306 fprintf( stdout,
"\nEnter device number or keyword (stream %d): ",
3309 plio_fgets( response,
sizeof ( response ), stdin );
3314 length = strlen( response );
3315 if ( *( response - 1 + length ) ==
'\n' )
3321 (
unsigned int) length ) )
3324 if ( i < npldrivers )
3330 if ( ( dev = atoi( response ) ) < 1 )
3332 fprintf( stdout,
"\nInvalid device: %s", response );
3337 plexit(
"plSelectDev: Too many tries." );
3354 #ifdef ENABLE_DYNDRIVERS
3359 int n = plsc->device - 1;
3361 PLLoadableDriver *driver = 0;
3369 pldebug(
"plLoadDriver",
"Device not loaded!\n" );
3374 if ( strcmp( dev->
pl_DevName, loadable_device_list[i].devnam ) == 0 )
3380 if ( i == npldynamicdevices )
3382 fprintf( stderr,
"No such device: %s.\n", dev->
pl_DevName );
3383 plexit(
"plLoadDriver detected device logic screwup" );
3389 tag = loadable_device_list[i].tag;
3390 drvidx = loadable_device_list[i].drvidx;
3392 pldebug(
"plLoadDriver",
"tag=%s, drvidx=%d\n", tag, drvidx );
3394 driver = &loadable_driver_list[drvidx];
3397 if ( !driver->dlhand )
3400 #if defined ( LTDL_WIN32 ) || defined ( __CYGWIN__ )
3404 #endif // LTDL_WIN32
3406 pldebug(
"plLoadDriver",
"Trying to load %s on %s\n",
3407 driver->drvnam, drvspec );
3418 if ( !( strcmp( driver->drvnam,
"mem" ) == 0 ||
3419 strcmp( driver->drvnam,
"null" ) == 0 ||
3420 strcmp( driver->drvnam,
"plmeta" ) == 0 ||
3421 strcmp( driver->drvnam,
"ps" ) == 0 ||
3422 strcmp( driver->drvnam,
"svg" ) == 0 ||
3423 strcmp( driver->drvnam,
"xfig" ) == 0 ) )
3428 if ( !driver->dlhand )
3430 pldebug(
"plLoadDriver",
"lt_dlopenext failed because of "
3431 "the following reason:\n%s\n",
lt_dlerror() );
3432 fprintf( stderr,
"Unable to load driver: %s.\n", driver->drvnam );
3433 plexit(
"Unable to load driver" );
3442 if ( !dispatch_init )
3445 "Unable to locate dispatch table initialization function for driver: %s.\n",
3450 ( *dispatch_init )( dev );
3467 if ( plsc->level > 0 )
3482 if ( plsc->plbuf_buffer != NULL )
3488 plwarn(
"plreplot: plot buffer not available" );
3504 plgFileDevs(
const char ***p_menustr,
const char ***p_devname,
int *p_ndev )
3506 plgdevlst( *p_menustr, *p_devname, p_ndev, 0 );
3516 plgDevs(
const char ***p_menustr,
const char ***p_devname,
int *p_ndev )
3518 plgdevlst( *p_menustr, *p_devname, p_ndev, -1 );
3522 plgdevlst(
const char **p_menustr,
const char **p_devname,
int *p_ndev,
int type )
3534 if ( ++j + 1 >= *p_ndev )
3536 plwarn(
"plgdevlst: too many devices" );
3541 p_menustr[j] = NULL;
3542 p_devname[j] = NULL;
3558 *p_xleng = plsc->xlength;
3559 *p_yleng = plsc->ylength;
3560 *p_xoff = plsc->xoffset;
3561 *p_yoff = plsc->yoffset;
3569 if ( plsc->level > 0 )
3570 plwarn(
"calling plspage() after plinit() may give unpredictable results" );
3578 plsc->xlength = xleng;
3580 plsc->ylength = yleng;
3583 plsc->xoffset = xoff;
3585 plsc->yoffset = yoff;
3602 if ( plsc->level > 0 )
3609 if ( plsc->plbuf_write )
3618 if ( plsc->level > 0 )
3620 plwarn(
"plsdev: Must be called before plinit." );
3623 if ( devname != NULL )
3625 strncpy( plsc->DevName, devname, sizeof ( plsc->DevName ) - 1 );
3626 plsc->DevName[
sizeof ( plsc->DevName ) - 1] =
'\0';
3636 strcpy( p_dev, plsc->DevName );
3651 plsc->dev = plotmem;
3652 plsc->dev_mem_alpha = 0;
3661 plsc->dev = plotmem;
3662 plsc->dev_mem_alpha = 1;
3685 *p_level = plsc->level;
3694 plsc->KeyEH = KeyEH;
3695 plsc->KeyEH_data = KeyEH_data;
3702 void *ButtonEH_data )
3704 plsc->ButtonEH = ButtonEH;
3705 plsc->ButtonEH_data = ButtonEH_data;
3711 plsbopH(
void ( *handler )(
void *,
int * ),
void *handler_data )
3713 plsc->bop_handler = handler;
3714 plsc->bop_data = handler_data;
3720 plseopH(
void ( *handler )(
void *,
int * ),
void *handler_data )
3722 plsc->eop_handler = handler;
3723 plsc->eop_data = handler_data;
3731 if ( errcode != NULL )
3732 plsc->errcode = errcode;
3734 if ( errmsg != NULL )
3755 if ( width != plsc->width && width >= 0. )
3757 plsc->width = width;
3759 if ( plsc->level > 0 )
3761 if ( !plsc->widthlock )
3772 *p_file = plsc->OutFile;
3780 plsc->OutFile = file;
3791 plabort(
"filename string must be preallocated to >=80 bytes" );
3796 if ( plsc->FileName != NULL )
3798 strncpy( fnam, plsc->FileName, 79 );
3822 plsc->dev_data =
data;
3838 plsc->setpre = setp;
3839 plsc->precis = prec;
3847 *p_setp = plsc->setpre;
3848 *p_prec = plsc->precis;
3854 return (
const char *) plsc->timefmt;
3883 plwarn(
"plsesc: Invalid escape character, ignoring." );
3892 if ( plsc->esc ==
'\0' )
3926 *pfci = *pfci & mask;
3928 *pfci = *pfci | mask;
3939 *phexdigit = (
unsigned char) ( ( fci & mask ) >>
3956 plsc->window_id = window_id;
3973 *p_fam = plsc->family;
3974 *p_num = plsc->member;
3975 *p_bmax = plsc->bytemax;
3983 if ( plsc->level > 0 )
3984 plwarn(
"plsfam: Must be called before plinit." );
3991 plsc->bytemax = bmax;
4012 *p_digmax = plsc->xdigmax;
4013 *p_digits = plsc->xdigits;
4021 plsc->xdigmax = digmax;
4022 plsc->xdigits = digits;
4030 *p_digmax = plsc->ydigmax;
4031 *p_digits = plsc->ydigits;
4039 plsc->ydigmax = digmax;
4040 plsc->ydigits = digits;
4048 *p_digmax = plsc->zdigmax;
4049 *p_digits = plsc->zdigits;
4057 plsc->zdigmax = digmax;
4058 plsc->zdigits = digits;
4066 *p_def = plsc->chrdef;
4067 *p_ht = plsc->chrht;
4075 *p_xmin = plsc->vpdxmi;
4076 *p_xmax = plsc->vpdxma;
4077 *p_ymin = plsc->vpdymi;
4078 *p_ymax = plsc->vpdyma;
4086 *p_xmin = plsc->vpwxmi;
4087 *p_xmax = plsc->vpwxma;
4088 *p_ymin = plsc->vpwymi;
4089 *p_ymax = plsc->vpwyma;
4098 dx = ( plsc->vpwxma - plsc->vpwxmi ) * 1.0e-5;
4099 dy = ( plsc->vpwyma - plsc->vpwymi ) * 1.0e-5;
4104 *p_xmin = plsc->vpwxmi -
dx;
4105 *p_xmax = plsc->vpwxma +
dx;
4106 *p_ymin = plsc->vpwymi -
dy;
4107 *p_ymax = plsc->vpwyma +
dy;
4119 *p_xmin = plsc->domxmi;
4120 *p_xmax = plsc->domxma;
4121 *p_ymin = plsc->domymi;
4122 *p_ymax = plsc->domyma;
4130 *p_zscl = plsc->zzscl;
4131 *p_zmin = plsc->ranmi;
4132 *p_zmax = plsc->ranma;
4152 *p_ixmin = plsc->clpxmi;
4153 *p_ixmax = plsc->clpxma;
4154 *p_iymin = plsc->clpymi;
4155 *p_iymax = plsc->clpyma;
4163 plsc->clpxmi = ixmin;
4164 plsc->clpxma = ixmax;
4165 plsc->clpymi = iymin;
4166 plsc->clpyma = iymax;
4167 if ( plsc->plbuf_write )
4176 *p_ixmin = plsc->phyxmi;
4177 *p_ixmax = plsc->phyxma;
4178 *p_iymin = plsc->phyymi;
4179 *p_iymax = plsc->phyyma;
4187 *p_nx = plsc->nsubx;
4188 *p_ny = plsc->nsuby;
4189 *p_cs = plsc->cursub;
4218 plsc->umx = (
PLINT) ( 1000.0 / plsc->xpmm );
4219 plsc->umy = (
PLINT) ( 1000.0 / plsc->ypmm );
4227 if ( xmin > xmax || ymin > ymax )
4228 plexit(
"plP_setphy: device minima must not exceed maxima" );
4230 plsc->phyxmi =
xmin;
4231 plsc->phyxma =
xmax;
4232 plsc->phyymi =
ymin;
4233 plsc->phyyma =
ymax;
4234 plsc->phyxlen = xmax -
xmin;
4235 plsc->phyylen = ymax -
ymin;
4248 if ( plsc->level <= 0 )
4250 plsc->dev_compression = compression;
4263 *compression = plsc->dev_compression;
4284 if (
pls[i] != NULL )
4287 strcpy( names,
pls[i]->DevName );
4290 strcat( names,
" " );
4291 strcat( names,
pls[i]->DevName );
4314 buff = (
char *) malloc( (
size_t)
PL_NSTREAMS * 8 );
4322 for ( tok = strtok( buff,
" ," );
4323 tok; tok = strtok( 0,
" ," ) )
4325 if ( strstr( names, tok ) != NULL )
4367 #if 0 // BEGIN dev_fastimg COMMENT
4374 if ( plsc->dev_fastimg == 0 )
4377 xmin, ymin, dx, dy, zmin, zmax );
4381 if ( plsc->plbuf_write )
4393 plsc->dev_nptsX = nx;
4394 plsc->dev_nptsY = ny;
4395 plsc->dev_zmin = zmin;
4396 plsc->dev_zmax = zmax;
4402 plbuf_write = plsc->plbuf_write;
4403 plsc->plbuf_write = 0;
4408 PLINT clpxmi, clpxma, clpymi, clpyma;
4410 if ( ( ( xscl = (
short *) malloc( nx * ny *
sizeof (
short ) ) ) == NULL ) ||
4411 ( ( yscl = (
short *) malloc( nx * ny *
sizeof (
short ) ) ) == NULL ) )
4413 plexit(
"plP_image: Insufficient memory" );
4416 for ( i = 0; i < npts; i++ )
4421 sdifilt( xscl, yscl, npts, &clpxmi, &clpxma, &clpymi, &clpyma );
4422 plsc->imclxmin = clpxmi;
4423 plsc->imclymin = clpymi;
4424 plsc->imclxmax = clpxma;
4425 plsc->imclymax = clpyma;
4426 grimage( xscl, yscl, z, nx, ny );
4432 plsc->imclxmin = plsc->phyxmi;
4433 plsc->imclymin = plsc->phyymi;
4434 plsc->imclxmax = plsc->phyxma;
4435 plsc->imclymax = plsc->phyyma;
4439 #endif // END dev_fastimg COMMENT
4451 plsc->coordinate_transform = coordinate_transform;
4452 plsc->coordinate_transform_data = coordinate_transform_data;