101 #ifdef HAVE_CRT_EXTERNS_H
105 #include <crt_externs.h>
112 static int GetOptarg(
const char **,
int *,
const char ***,
int * );
113 static void Help(
void );
114 static void Syntax(
void );
118 static int opt_h(
const char *,
const char *,
void * );
119 static int opt_v(
const char *,
const char *,
void * );
120 static int opt_verbose(
const char *,
const char *,
void * );
121 static int opt_debug(
const char *,
const char *,
void * );
122 static int opt_hack(
const char *,
const char *,
void * );
123 static int opt_dev(
const char *,
const char *,
void * );
124 static int opt_o(
const char *,
const char *,
void * );
125 static int opt_geo(
const char *,
const char *,
void * );
126 static int opt_a(
const char *,
const char *,
void * );
127 static int opt_jx(
const char *,
const char *,
void * );
128 static int opt_jy(
const char *,
const char *,
void * );
129 static int opt_mar(
const char *,
const char *,
void * );
130 static int opt_ori(
const char *,
const char *,
void * );
132 static int opt_portrait(
const char *,
const char *,
void * );
133 static int opt_width(
const char *,
const char *,
void * );
134 static int opt_bg(
const char *,
const char *,
void * );
135 static int opt_ncol0(
const char *,
const char *,
void * );
136 static int opt_ncol1(
const char *,
const char *,
void * );
137 static int opt_fam(
const char *,
const char *,
void * );
138 static int opt_fsiz(
const char *,
const char *,
void * );
139 static int opt_fbeg(
const char *,
const char *,
void * );
140 static int opt_finc(
const char *,
const char *,
void * );
141 static int opt_fflen(
const char *,
const char *,
void * );
142 static int opt_bufmax(
const char *,
const char *,
void * );
143 static int opt_nopixmap(
const char *,
const char *,
void * );
144 static int opt_db(
const char *,
const char *,
void * );
145 static int opt_np(
const char *,
const char *,
void * );
146 static int opt_px(
const char *,
const char *,
void * );
147 static int opt_py(
const char *,
const char *,
void * );
148 static int opt_wplt(
const char *,
const char *,
void * );
149 static int opt_drvopt(
const char *,
const char *,
void * );
151 static int opt_plserver(
const char *,
const char *,
void * );
152 static int opt_plwindow(
const char *,
const char *,
void * );
153 static int opt_auto_path(
const char *,
const char *,
void * );
154 static int opt_bufmax(
const char *,
const char *,
void * );
156 static int opt_tk_file(
const char *,
const char *,
void * );
157 static int opt_dpi(
const char *,
const char *,
void * );
159 static int opt_cmap0(
const char *,
const char *,
void * );
160 static int opt_cmap1(
const char *,
const char *,
void * );
161 static int opt_locale(
const char *,
const char *,
void * );
162 static int opt_eofill(
const char *,
const char *,
void * );
164 static int opt_mfo(
const char *,
const char *,
void * );
165 static int opt_mfi(
const char *,
const char *,
void * );
245 "Turns on invisible options"
254 "Print out this message"
263 "Print out the PLplot library version number"
272 "Be more verbose than usual"
281 "Print debugging info (implies -verbose)"
290 "Enable driver-specific hack(s)"
317 "X server to contact"
326 "Plots per page in x"
335 "Plots per page in y"
344 "Window size/position specified as in X, e.g., 400x300, 400x300-100+200, +100-200, etc."
353 "Window size/position specified as in X, e.g., 400x300, 400x300-100+200, +100-200, etc."
362 "Relative coordinates [0-1] of window into plot"
371 "Margin space in relative coordinates (0 to 0.5, def 0)"
380 "Page aspect ratio (def: same as output device)"
389 "Page justification in x (-0.5 to 0.5, def 0)"
398 "Page justification in y (-0.5 to 0.5, def 0)"
407 "Plot orientation (0,1,2,3=landscape,portrait,seascape,upside-down)"
416 "Allow aspect ratio to adjust to orientation swaps"
425 "Sets portrait mode (both orientation and aspect ratio)"
434 "Sets pen width (0 <= width)"
443 "Background color (FF0000=opaque red, 0000FF_0.1=blue with alpha of 0.1)"
452 "Number of colors to allocate in cmap 0 (upper bound)"
461 "Number of colors to allocate in cmap 1 (upper bound)"
470 "Create a family of output files"
478 "-fsiz size[kKmMgG]",
479 "Output family file size (e.g. -fsiz 0.5G, def MB)"
488 "First family member number on output"
497 "Increment between family members"
506 "Family member number minimum field width"
515 "Don't use pixmaps in X-based drivers"
524 "Double buffer X window output"
533 "No pause between pages"
542 "bytes sent before flushing output"
551 "Main window name of PLplot server (tk driver)"
560 "Invoked name of PLplot server (tk driver)"
569 "Name of PLplot container window (tk driver)"
578 "Additional directory(s) to autoload (tk driver)"
587 "file for plserver (tk driver)"
596 "Resolution, in dots per inch (e.g. -dpi 360x360)"
605 "Sets compression level in supporting devices"
614 "Initializes color table 0 from a cmap0.pal format file in one of standard PLplot paths."
623 "Initializes color table 1 from a cmap1.pal format file in one of standard PLplot paths."
632 "Use locale environment (e.g., LC_ALL, LC_NUMERIC, or LANG) to set LC_NUMERIC locale (which affects decimal point separator)."
641 "For the case where the boundary of the filled region is self-intersecting, use the even-odd fill rule rather than the default nonzero fill rule."
649 "-drvopt option[=value][,option[=value]]*",
650 "Driver specific options"
658 "-mfo PLplot metafile name",
659 "Write the plot to the specified PLplot metafile"
667 "-mfi PLplot metafile name",
668 "Read the specified PLplot metafile"
682 "All parameters must be white-space delimited. Some options are driver",
683 "dependent. Please see the PLplot reference document for more detail.",
716 #define PL_MAX_OPT_TABLES 10
754 plSetOpt(
const char * opt,
const char *opt_arg )
758 #endif //#ifdef PL_DEPRECATED
763 int mode = 0,
argc = 2, status;
778 fprintf( stderr,
"plSetOpt: Unrecognized option %s\n", opt );
808 if ( ( tab->
handler != NULL ) ||
810 ( tab->
var != NULL ) ||
811 ( tab->
mode != 0 ) ||
812 ( tab->
syntax != NULL ) ||
813 ( tab->
desc != NULL ) )
815 plabort(
"plMergeOpts: input table improperly terminated" );
823 plabort(
"plMergeOpts: max tables limit exceeded, table not merged" );
879 const char **argsave, **argend;
880 int i, myargc, status = 0;
894 myargc = ( *p_argc );
895 argend = argv + myargc;
901 plsc->program =
plstrdup( argv[0] );
902 program = (
const char *) plsc->program;
911 for (; myargc > 0; --myargc, ++
argv )
915 if ( *argv == NULL || *argv[0] ==
'\0' )
920 for ( i =
tables - 1; i >= 0; i-- )
924 status =
ParseOpt( &myargc, &argv, p_argc, &argsave,
948 fprintf( stderr,
"\nBad command line option \"%s\"\n", argv[0] );
956 else if ( status == 1 )
962 fprintf( stderr,
"\nBad command line option \"%s\"\n", argv[0] );
970 else if ( status == 2 )
982 for ( i = 0; i < myargc; i++ )
983 *argsave++ = *argv++;
985 if ( argsave < argend )
988 #ifdef HAVE_NSGETARGC
996 *_NSGetArgc() = *p_argc;
1020 ParseOpt(
int *p_myargc,
const char ***p_argv,
int *p_argc,
const char ***p_argsave,
1030 opt = ( *p_argv )[0];
1034 for ( tab = option_table; tab->
opt; tab++ )
1043 if ( *opt == *tab->
opt && !strcmp( opt, tab->
opt ) )
1050 ( *( *p_argsave )++ ) = ( **p_argv );
1057 return (
ProcessOpt( opt, tab, p_myargc, p_argv, p_argc ) );
1084 const char *opt_arg = NULL;
1090 if ( tab->
mode & need_arg )
1092 if (
GetOptarg( &opt_arg, p_myargc, p_argv, p_argc ) )
1098 switch ( tab->
mode & 0xFF00 )
1107 "ProcessOpt: no handler specified for option %s\n",
1116 (
char *) malloc( (
size_t) ( 1 + strlen( opt_arg ) ) *
sizeof (
char ) );
1119 plabort(
"ProcessOpt: out of memory" );
1122 strcpy( copy, opt_arg );
1124 free( (
void *) copy );
1136 if ( tab->
var == NULL )
1139 "ProcessOpt: no variable specified for option %s\n",
1143 *(
int *) tab->
var = 1;
1150 if ( tab->
var == NULL )
1153 "ProcessOpt: no variable specified for option %s\n",
1157 *(
int *) tab->
var = atoi( opt_arg );
1164 if ( tab->
var == NULL )
1167 "ProcessOpt: no variable specified for option %s\n",
1171 *(
PLFLT *) tab->
var = atof( opt_arg );
1178 *(
const char **) tab->
var = opt_arg;
1186 "ProcessOpt: invalid processing mode for option %s\n",
1209 GetOptarg(
const char **popt_arg,
int *p_myargc,
const char ***p_argv,
int *p_argc )
1215 if ( ( *p_myargc ) <= 0 )
1221 if ( ( *p_argv )[0][0] ==
'-' && isalpha( ( *p_argv )[0][1] ) )
1231 *popt_arg = ( *p_argv )[0];
1237 fprintf( stderr,
"Argument missing for %s option.\n", ( *p_argv )[0] );
1255 plSetUsage(
const char *program_string,
const char *usage_string )
1257 if ( program_string != NULL )
1260 if ( usage_string != NULL )
1261 usage = usage_string;
1274 if (
usage == NULL )
1275 fprintf( stderr,
"\nUsage:\n %s [options]\n",
program );
1277 fputs(
usage, stderr );
1281 fprintf( stderr,
"\n\nType %s -h for a full description.\n\n",
1300 for ( i =
tables - 1; i >= 0; i-- )
1304 if ( ploption_info[i].
name )
1305 fprintf( stderr,
"\n%s:", ploption_info[i].name );
1307 fputs(
"\nUser options:", stderr );
1312 for ( tab = ploption_info[i].
options; tab->
opt; tab++ )
1320 if ( tab->
syntax == NULL )
1323 len = 3 + (int) strlen( tab->
syntax );
1324 if ( col + len > 79 )
1326 fprintf( stderr,
"\n " );
1329 fprintf( stderr,
" [%s]", tab->
syntax );
1332 fprintf( stderr,
"\n" );
1349 FILE *outfile = stderr;
1353 if ( getenv(
"PAGER" ) != NULL )
1354 pager = (FILE *) popen(
"$PAGER",
"w" );
1355 if ( pager == NULL )
1356 pager = (FILE *) popen(
"more",
"w" );
1357 if ( pager != NULL )
1363 if (
usage == NULL )
1364 fprintf( outfile,
"\nUsage:\n %s [options]\n",
program );
1366 fputs(
usage, outfile );
1370 for ( i =
tables - 1; i >= 0; i-- )
1374 if ( ploption_info[i].
name )
1375 fprintf( outfile,
"\n%s:\n", ploption_info[i].name );
1377 fputs(
"\nUser options:\n", outfile );
1381 for ( tab = ploption_info[i].
options; tab->
opt; tab++ )
1389 if ( tab->
desc == NULL )
1393 fprintf( outfile,
" * %-20s %s\n", tab->
syntax, tab->
desc );
1395 fprintf( outfile,
" %-20s %s\n", tab->
syntax, tab->
desc );
1400 if ( ploption_info[i].notes )
1402 putc(
'\n', outfile );
1403 for ( note = ploption_info[i].notes; *note; note++ )
1405 fputs( *note, outfile );
1406 putc(
'\n', outfile );
1412 if ( pager != NULL )
1435 memset( msg,
'\0',
sizeof ( msg ) );
1443 t = acc_opt; fl = 0;
1446 if ( strcmp( drvp->
option, t->
opt ) == 0 )
1454 fprintf( stderr,
"plParseDrvOpts: %s %s\n", t->
opt, *(
char **) t->
var_ptr );
1459 if ( sscanf( drvp->
value,
"%d", (
int *) t->
var_ptr ) != 1 )
1461 snprintf( msg,
sizeof ( msg ) - 1,
"Incorrect argument to '%s' option", drvp->
option );
1465 fprintf( stderr,
"plParseDrvOpts: %s %d\n", t->
opt, *(
int *) t->
var_ptr );
1470 if ( sscanf( drvp->
value,
"%f", (
float *) t->
var_ptr ) != 1 )
1472 snprintf( msg,
sizeof ( msg ) - 1,
"Incorrect argument to '%s' option", drvp->
option );
1476 fprintf( stderr,
"plParseDrvOpts: %s %f\n", t->
opt, *(
float *) t->
var_ptr );
1486 snprintf( msg,
sizeof ( msg ) - 1,
"Option '%s' not recognized.\n\nRecognized options for this driver are:\n", drvp->
option );
1492 while ( ( drvp = drvp->
next ) )
1515 fprintf( stderr,
"%s:\t%s\n", t->
opt, t->
hlp_msg );
1539 free( drvpl->
value );
1542 if ( drvpl != &drv_opt )
1544 }
while ( drvp != NULL );
1548 drv_opt.
value = NULL;
1549 drv_opt.
next = NULL;
1598 fprintf( stderr,
"PLplot library version: %s\n",
PLPLOT_VERSION );
1831 plsc->freeaspect = 1;
1889 width = atof( opt_arg );
1892 fprintf( stderr,
"?invalid width\n" );
1898 plsc->widthlock = 1;
1925 char *color_field, *alpha_field;
1932 if ( *opt_arg ==
'#' )
1940 if ( strchr(
opttmp,
'_' ) )
1943 color_field = strtok(
opttmp,
"_" );
1944 alpha_field = strtok( NULL,
"_" );
1952 bgcolor = strtol( color_field, NULL, 16 );
1957 switch ( strlen( color_field ) )
1960 r = (
PLINT) ( ( bgcolor & 0xF00 ) >> 8 );
1961 g = (
PLINT) ( ( bgcolor & 0x0F0 ) >> 4 );
1962 b = (
PLINT) ( bgcolor & 0x00F );
1970 r = (
PLINT) ( ( bgcolor & 0xFF0000 ) >> 16 );
1971 g = (
PLINT) ( ( bgcolor & 0x00FF00 ) >> 8 );
1972 b = (
PLINT) ( bgcolor & 0x0000FF );
1976 fprintf( stderr,
"Unrecognized background color value %s\n", color_field );
1981 a = atof( alpha_field );
2007 plsc->ncol0 = atoi( opt_arg );
2028 plsc->ncol1 = atoi( opt_arg );
2055 if ( ( field = strtok(
opttmp,
"," ) ) == NULL )
2060 if ( ( field = strtok( NULL,
"," ) ) == NULL )
2065 if ( ( field = strtok( NULL,
"," ) ) == NULL )
2070 if ( ( field = strtok( NULL,
"," ) ) == NULL )
2100 option = (
char *) malloc( (
size_t) ( 1 + strlen( opt_arg ) ) *
sizeof (
char ) );
2101 if ( option == NULL )
2102 plexit(
"opt_drvopt: Out of memory!?" );
2104 value = (
char *) malloc( (
size_t) ( 1 + strlen( opt_arg ) ) *
sizeof (
char ) );
2105 if ( value == NULL )
2106 plexit(
"opt_drvopt: Out of memory!?" );
2109 *option = *value =
'\0';
2111 while ( ( t = *opt_arg++ ) )
2128 if ( drvp->
next == NULL )
2129 plexit(
"opt_drvopt: Out of memory!?\n" );
2136 *tt =
'\0'; tt =
value;
2156 fprintf( stderr,
"\nopt_drvopt: -drvopt parsed options:\n" );
2159 fprintf( stderr,
"%s %s\n", drvp->
option, drvp->
value );
2160 while ( drvp = drvp->
next );
2161 fprintf( stderr,
"\n" );
2164 free( option ); free( value );
2217 size_t len = strlen( opt_arg );
2218 char lastchar = opt_arg[len - 1];
2219 PLFLT multiplier = 1.0e6;
2220 char *spec = (
char *) malloc( len + 1 );
2223 plexit(
"opt_fsiz: Insufficient memory" );
2231 multiplier = 1.0e3; len--;
2235 multiplier = 1.0e6; len--;
2239 multiplier = 1.0e9; len--;
2242 strncpy( spec, opt_arg, len );
2245 bytemax = (
PLINT) ( multiplier * atof( spec ) );
2248 fprintf( stderr,
"?invalid file size %d. 2.14G is the maximum.\n", bytemax );
2251 plsfam( 1, -1, bytemax );
2274 plsc->member = atoi( opt_arg );
2296 plsc->finc = atoi( opt_arg );
2318 plsc->fflen = atoi( opt_arg );
2403 plsc->bufmax = atoi( opt_arg );
2424 plsc->server_name =
plstrdup( opt_arg );
2445 plsc->plserver =
plstrdup( opt_arg );
2466 if ( ( plsc->plwindow = (
char *) malloc( (
size_t) ( 1 + strlen( opt_arg ) ) *
sizeof (
char ) ) ) == NULL )
2468 plexit(
"opt_plwindow: Insufficient memory" );
2470 strcpy( plsc->plwindow, opt_arg );
2491 plsc->auto_path =
plstrdup( opt_arg );
2512 plssub( atoi( opt_arg ), -1 );
2533 plssub( -1, atoi( opt_arg ) );
2559 PLFLT xdpi = 0., ydpi = 0.;
2560 PLINT xwid, ywid, xoff, yoff;
2564 if ( ( plsc->geometry = (
char *) malloc( (
size_t) ( 1 + strlen( opt_arg ) ) *
sizeof (
char ) ) ) == NULL )
2566 plexit(
"opt_geo: Insufficient memory" );
2569 strcpy( plsc->geometry, opt_arg );
2571 numargs = sscanf( opt_arg,
"%dx%d%d%d", &xwid, &ywid, &xoff, &yoff );
2577 fprintf( stderr,
"?invalid xwid in -geometry %s\n", opt_arg );
2579 fprintf( stderr,
"?invalid ywid in -geometry %s\n", opt_arg );
2582 fprintf( stderr,
"?invalid xwid in -geometry %s\n", opt_arg );
2587 fprintf( stderr,
"?invalid ywid in -geometry %s\n", opt_arg );
2591 else if ( numargs == 4 )
2594 fprintf( stderr,
"?invalid xwid in -geometry %s\n", opt_arg );
2596 fprintf( stderr,
"?invalid ywid in -geometry %s\n", opt_arg );
2599 fprintf( stderr,
"?invalid xwid in -geometry %s\n", opt_arg );
2604 fprintf( stderr,
"?invalid ywid in -geometry %s\n", opt_arg );
2607 if ( abs( xoff ) == 0 )
2608 fprintf( stderr,
"?invalid xoff in -geometry %s\n", opt_arg );
2609 if ( abs( yoff ) == 0 )
2610 fprintf( stderr,
"?invalid yoff in -geometry %s\n", opt_arg );
2614 numargs = sscanf( opt_arg,
"%d%d", &xoff, &yoff );
2619 if ( abs( xoff ) == 0 )
2620 fprintf( stderr,
"?invalid xoff in -geometry %s\n", opt_arg );
2621 if ( abs( yoff ) == 0 )
2622 fprintf( stderr,
"?invalid yoff in -geometry %s\n", opt_arg );
2626 fprintf( stderr,
"?invalid -geometry %s\n", opt_arg );
2631 plspage( xdpi, ydpi, xwid, ywid, xoff, yoff );
2651 if ( ( plsc->tk_file = (
char *) malloc( (
size_t) ( 1 + strlen( opt_arg ) ) *
sizeof (
char ) ) ) == NULL )
2653 plexit(
"opt_tk_file: Insufficient memory" );
2656 strcpy( plsc->tk_file, opt_arg );
2682 PLFLT xdpi = 0., ydpi = 0.;
2683 PLINT xwid = 0, ywid = 0, xoff = 0, yoff = 0;
2687 if ( strchr(
opttmp,
'x' ) )
2689 field = strtok(
opttmp,
"x" );
2690 xdpi = atof( field );
2692 fprintf( stderr,
"?invalid xdpi\n" );
2694 if ( ( field = strtok( NULL,
" " ) ) == NULL )
2697 ydpi = atof( field );
2699 fprintf( stderr,
"?invalid ydpi\n" );
2709 plspage( xdpi, ydpi, xwid, ywid, xoff, yoff );
2731 comp = atoi( opt_arg );
2734 fprintf( stderr,
"?invalid compression\n" );
2799 if ( ( locale = setlocale( LC_NUMERIC,
"" ) ) )
2801 printf(
"LC_NUMERIC locale set to \"%s\"\n", locale );
2805 plwarn(
"Could not use invalid environment (e.g., LC_ALL, LC_NUMERIC, or LANG) to set LC_NUMERIC locale. Falling back to LC_NUMERIC \"C\" locale instead.\n" );
2806 if ( !( locale = setlocale( LC_NUMERIC,
"C" ) ) )
2808 plexit(
"Your platform is seriously broken. Not even a \"C\" locale could be set." );
2832 plsc->dev_eofill = 1;
2852 if ( ( plsc->mf_outfile = (
char *) malloc( (
size_t) ( 1 + strlen( opt_arg ) ) *
sizeof (
char ) ) ) == NULL )
2854 plexit(
"opt_mfo: Insufficient memory" );
2857 strcpy( plsc->mf_outfile, opt_arg );
2877 if ( ( plsc->mf_infile = (
char *) malloc( (
size_t) ( 1 + strlen( opt_arg ) ) *
sizeof (
char ) ) ) == NULL )
2879 plexit(
"opt_mfi: Insufficient memory" );
2882 strcpy( plsc->mf_infile, opt_arg );