00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 #include "plplotP.h"
00099 #include <ctype.h>
00100
00101
00102
00103 static int ParseOpt (int *, const char ***, int *, const char ***, PLOptionTable *);
00104 static int ProcessOpt (const char *, PLOptionTable *, int *, const char ***, int *);
00105 static int GetOptarg (const char **, int *, const char ***, int *);
00106 static void Help (void);
00107 static void Syntax (void);
00108
00109
00110
00111 static int opt_h (const char *, const char *, void *);
00112 static int opt_v (const char *, const char *, void *);
00113 static int opt_verbose (const char *, const char *, void *);
00114 static int opt_debug (const char *, const char *, void *);
00115 static int opt_hack (const char *, const char *, void *);
00116 static int opt_dev (const char *, const char *, void *);
00117 static int opt_o (const char *, const char *, void *);
00118 static int opt_geo (const char *, const char *, void *);
00119 static int opt_a (const char *, const char *, void *);
00120 static int opt_jx (const char *, const char *, void *);
00121 static int opt_jy (const char *, const char *, void *);
00122 static int opt_mar (const char *, const char *, void *);
00123 static int opt_ori (const char *, const char *, void *);
00124 static int opt_freeaspect (const char *, const char *, void *);
00125 static int opt_portrait (const char *, const char *, void *);
00126 static int opt_width (const char *, const char *, void *);
00127 static int opt_bg (const char *, const char *, void *);
00128 static int opt_ncol0 (const char *, const char *, void *);
00129 static int opt_ncol1 (const char *, const char *, void *);
00130 static int opt_fam (const char *, const char *, void *);
00131 static int opt_fsiz (const char *, const char *, void *);
00132 static int opt_fbeg (const char *, const char *, void *);
00133 static int opt_finc (const char *, const char *, void *);
00134 static int opt_fflen (const char *, const char *, void *);
00135 static int opt_bufmax (const char *, const char *, void *);
00136 static int opt_nopixmap (const char *, const char *, void *);
00137 static int opt_db (const char *, const char *, void *);
00138 static int opt_np (const char *, const char *, void *);
00139 static int opt_px (const char *, const char *, void *);
00140 static int opt_py (const char *, const char *, void *);
00141 static int opt_wplt (const char *, const char *, void *);
00142 static int opt_drvopt (const char *, const char *, void *);
00143
00144 static int opt_plserver (const char *, const char *, void *);
00145 static int opt_plwindow (const char *, const char *, void *);
00146 static int opt_tcl_cmd (const char *, const char *, void *);
00147 static int opt_auto_path (const char *, const char *, void *);
00148 static int opt_bufmax (const char *, const char *, void *);
00149 static int opt_server_name (const char *, const char *, void *);
00150 static int opt_tk_file (const char *, const char *, void *);
00151 static int opt_dpi (const char *, const char *, void *);
00152 static int opt_dev_compression (const char *, const char *, void *);
00153 static int opt_cmap0 (const char *, const char *, void *);
00154 static int opt_cmap1 (const char *, const char *, void *);
00155 static int opt_locale (const char *, const char *, void *);
00156
00157
00158
00159 static const char *program = NULL;
00160 static const char *usage = NULL;
00161
00162 static int mode_full;
00163 static int mode_quiet;
00164 static int mode_nodelete;
00165 static int mode_showall;
00166 static int mode_noprogram;
00167 static int mode_nodash;
00168 static int mode_skip;
00169
00170
00171
00172 #define OPTMAX 1024
00173 static char opttmp[OPTMAX];
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 static PLOptionTable ploption_table[] = {
00227 {
00228 "showall",
00229 NULL,
00230 NULL,
00231 &mode_showall,
00232 PL_OPT_BOOL | PL_OPT_INVISIBLE,
00233 "-showall",
00234 "Turns on invisible options" },
00235 {
00236 "h",
00237 opt_h,
00238 NULL,
00239 NULL,
00240 PL_OPT_FUNC,
00241 "-h",
00242 "Print out this message" },
00243 {
00244 "v",
00245 opt_v,
00246 NULL,
00247 NULL,
00248 PL_OPT_FUNC,
00249 "-v",
00250 "Print out the PLplot library version number" },
00251 {
00252 "verbose",
00253 opt_verbose,
00254 NULL,
00255 NULL,
00256 PL_OPT_FUNC,
00257 "-verbose",
00258 "Be more verbose than usual" },
00259 {
00260 "debug",
00261 opt_debug,
00262 NULL,
00263 NULL,
00264 PL_OPT_FUNC,
00265 "-debug",
00266 "Print debugging info (implies -verbose)" },
00267 {
00268 "hack",
00269 opt_hack,
00270 NULL,
00271 NULL,
00272 PL_OPT_FUNC | PL_OPT_INVISIBLE,
00273 "-hack",
00274 "Enable driver-specific hack(s)" },
00275 {
00276 "dev",
00277 opt_dev,
00278 NULL,
00279 NULL,
00280 PL_OPT_FUNC | PL_OPT_ARG,
00281 "-dev name",
00282 "Output device name" },
00283 {
00284 "o",
00285 opt_o,
00286 NULL,
00287 NULL,
00288 PL_OPT_FUNC | PL_OPT_ARG,
00289 "-o name",
00290 "Output filename" },
00291 {
00292 "display",
00293 opt_o,
00294 NULL,
00295 NULL,
00296 PL_OPT_FUNC | PL_OPT_ARG,
00297 "-display name",
00298 "X server to contact" },
00299 {
00300 "px",
00301 opt_px,
00302 NULL,
00303 NULL,
00304 PL_OPT_FUNC | PL_OPT_ARG,
00305 "-px number",
00306 "Plots per page in x" },
00307 {
00308 "py",
00309 opt_py,
00310 NULL,
00311 NULL,
00312 PL_OPT_FUNC | PL_OPT_ARG,
00313 "-py number",
00314 "Plots per page in y" },
00315 {
00316 "geometry",
00317 opt_geo,
00318 NULL,
00319 NULL,
00320 PL_OPT_FUNC | PL_OPT_ARG,
00321 "-geometry geom",
00322 "Window size (and optional position), in pixels (e.g. -geometry 400x300 or -geometry 400x300+100+200)" },
00323 {
00324 "geo",
00325 opt_geo,
00326 NULL,
00327 NULL,
00328 PL_OPT_FUNC | PL_OPT_ARG | PL_OPT_INVISIBLE,
00329 "-geo geom",
00330 "Window size, in pixels (e.g. -geo 400x300)" },
00331 {
00332 "wplt",
00333 opt_wplt,
00334 NULL,
00335 NULL,
00336 PL_OPT_FUNC | PL_OPT_ARG,
00337 "-wplt xl,yl,xr,yr",
00338 "Relative coordinates [0-1] of window into plot" },
00339 {
00340 "mar",
00341 opt_mar,
00342 NULL,
00343 NULL,
00344 PL_OPT_FUNC | PL_OPT_ARG,
00345 "-mar margin",
00346 "Margin space in relative coordinates (0 to 0.5, def 0)" },
00347 {
00348 "a",
00349 opt_a,
00350 NULL,
00351 NULL,
00352 PL_OPT_FUNC | PL_OPT_ARG,
00353 "-a aspect",
00354 "Page aspect ratio (def: same as output device)"},
00355 {
00356 "jx",
00357 opt_jx,
00358 NULL,
00359 NULL,
00360 PL_OPT_FUNC | PL_OPT_ARG,
00361 "-jx justx",
00362 "Page justification in x (-0.5 to 0.5, def 0)"},
00363 {
00364 "jy",
00365 opt_jy,
00366 NULL,
00367 NULL,
00368 PL_OPT_FUNC | PL_OPT_ARG,
00369 "-jy justy",
00370 "Page justification in y (-0.5 to 0.5, def 0)"},
00371 {
00372 "ori",
00373 opt_ori,
00374 NULL,
00375 NULL,
00376 PL_OPT_FUNC | PL_OPT_ARG,
00377 "-ori orient",
00378 "Plot orientation (0,1,2,3=landscape,portrait,seascape,upside-down)" },
00379 {
00380 "freeaspect",
00381 opt_freeaspect,
00382 NULL,
00383 NULL,
00384 PL_OPT_FUNC,
00385 "-freeaspect",
00386 "Allow aspect ratio to adjust to orientation swaps" },
00387 {
00388 "portrait",
00389 opt_portrait,
00390 NULL,
00391 NULL,
00392 PL_OPT_FUNC,
00393 "-portrait",
00394 "Sets portrait mode (both orientation and aspect ratio)" },
00395 {
00396 "width",
00397 opt_width,
00398 NULL,
00399 NULL,
00400 PL_OPT_FUNC | PL_OPT_ARG,
00401 "-width width",
00402 "Sets pen width (0 <= width)" },
00403 {
00404 "bg",
00405 opt_bg,
00406 NULL,
00407 NULL,
00408 PL_OPT_FUNC | PL_OPT_ARG,
00409 "-bg color",
00410 "Background color (FF0000=opaque red, 0000FF_0.1=blue with alpha of 0.1)" },
00411 {
00412 "ncol0",
00413 opt_ncol0,
00414 NULL,
00415 NULL,
00416 PL_OPT_FUNC | PL_OPT_ARG,
00417 "-ncol0 n",
00418 "Number of colors to allocate in cmap 0 (upper bound)" },
00419 {
00420 "ncol1",
00421 opt_ncol1,
00422 NULL,
00423 NULL,
00424 PL_OPT_FUNC | PL_OPT_ARG,
00425 "-ncol1 n",
00426 "Number of colors to allocate in cmap 1 (upper bound)" },
00427 {
00428 "fam",
00429 opt_fam,
00430 NULL,
00431 NULL,
00432 PL_OPT_FUNC,
00433 "-fam",
00434 "Create a family of output files" },
00435 {
00436 "fsiz",
00437 opt_fsiz,
00438 NULL,
00439 NULL,
00440 PL_OPT_FUNC | PL_OPT_ARG,
00441 "-fsiz size[kKmMgG]",
00442 "Output family file size (e.g. -fsiz 0.5G, def MB)" },
00443 {
00444 "fbeg",
00445 opt_fbeg,
00446 NULL,
00447 NULL,
00448 PL_OPT_FUNC | PL_OPT_ARG,
00449 "-fbeg number",
00450 "First family member number on output" },
00451 {
00452 "finc",
00453 opt_finc,
00454 NULL,
00455 NULL,
00456 PL_OPT_FUNC | PL_OPT_ARG,
00457 "-finc number",
00458 "Increment between family members" },
00459 {
00460 "fflen",
00461 opt_fflen,
00462 NULL,
00463 NULL,
00464 PL_OPT_FUNC | PL_OPT_ARG,
00465 "-fflen length",
00466 "Family member number minimum field width" },
00467 {
00468 "nopixmap",
00469 opt_nopixmap,
00470 NULL,
00471 NULL,
00472 PL_OPT_FUNC,
00473 "-nopixmap",
00474 "Don't use pixmaps in X-based drivers" },
00475 {
00476 "db",
00477 opt_db,
00478 NULL,
00479 NULL,
00480 PL_OPT_FUNC,
00481 "-db",
00482 "Double buffer X window output" },
00483 {
00484 "np",
00485 opt_np,
00486 NULL,
00487 NULL,
00488 PL_OPT_FUNC,
00489 "-np",
00490 "No pause between pages" },
00491 {
00492 "bufmax",
00493 opt_bufmax,
00494 NULL,
00495 NULL,
00496 PL_OPT_FUNC | PL_OPT_ARG | PL_OPT_INVISIBLE,
00497 "-bufmax",
00498 "bytes sent before flushing output" },
00499 {
00500 "server_name",
00501 opt_server_name,
00502 NULL,
00503 NULL,
00504 PL_OPT_FUNC | PL_OPT_ARG,
00505 "-server_name name",
00506 "Main window name of PLplot server (tk driver)" },
00507 {
00508 "plserver",
00509 opt_plserver,
00510 NULL,
00511 NULL,
00512 PL_OPT_FUNC | PL_OPT_ARG | PL_OPT_INVISIBLE,
00513 "-plserver name",
00514 "Invoked name of PLplot server (tk driver)" },
00515 {
00516 "plwindow",
00517 opt_plwindow,
00518 NULL,
00519 NULL,
00520 PL_OPT_FUNC | PL_OPT_ARG | PL_OPT_INVISIBLE,
00521 "-plwindow name",
00522 "Name of PLplot container window (tk driver)" },
00523 {
00524 "tcl_cmd",
00525 opt_tcl_cmd,
00526 NULL,
00527 NULL,
00528 PL_OPT_FUNC | PL_OPT_ARG | PL_OPT_INVISIBLE,
00529 "-tcl_cmd command",
00530 "Depreciated - use -drvopt tcl_cmd= instead" },
00531 {
00532 "auto_path",
00533 opt_auto_path,
00534 NULL,
00535 NULL,
00536 PL_OPT_FUNC | PL_OPT_ARG | PL_OPT_INVISIBLE,
00537 "-auto_path dir",
00538 "Additional directory(s) to autoload (tk driver)" },
00539 {
00540 "tk_file",
00541 opt_tk_file,
00542 NULL,
00543 NULL,
00544 PL_OPT_FUNC | PL_OPT_ARG | PL_OPT_INVISIBLE,
00545 "-tk_file file",
00546 "file for plserver (tk driver)" },
00547 {
00548 "dpi",
00549 opt_dpi,
00550 NULL,
00551 NULL,
00552 PL_OPT_FUNC | PL_OPT_ARG,
00553 "-dpi dpi",
00554 "Resolution, in dots per inch (e.g. -dpi 360x360)" },
00555 {
00556 "compression",
00557 opt_dev_compression,
00558 NULL,
00559 NULL,
00560 PL_OPT_FUNC | PL_OPT_ARG,
00561 "-compression num",
00562 "Sets compression level in supporting devices" },
00563 {
00564 "cmap0",
00565 opt_cmap0,
00566 NULL,
00567 NULL,
00568 PL_OPT_ARG | PL_OPT_FUNC,
00569 "-cmap0 file name",
00570 "Initializes color table 0 from a cmap0.pal format file in one of standard PLplot paths."},
00571 {
00572 "cmap1",
00573 opt_cmap1,
00574 NULL,
00575 NULL,
00576 PL_OPT_ARG | PL_OPT_FUNC,
00577 "-cmap1 file name",
00578 "Initializes color table 1 from a cmap1.pal format file in one of standard PLplot paths."},
00579 {
00580 "locale",
00581 opt_locale,
00582 NULL,
00583 NULL,
00584 PL_OPT_FUNC,
00585 "-locale",
00586 "Use locale environment (e.g., LC_ALL, LC_NUMERIC, or LANG) to set LC_NUMERIC locale (which affects decimal point separator)."},
00587 {
00588 "drvopt",
00589 opt_drvopt,
00590 NULL,
00591 NULL,
00592 PL_OPT_ARG | PL_OPT_FUNC,
00593 "-drvopt option[=value][,option[=value]]*",
00594 "Driver specific options" },
00595 {
00596 NULL,
00597 NULL,
00598 NULL,
00599 NULL,
00600 0,
00601 NULL,
00602 NULL }
00603 };
00604
00605 static const char *plplot_notes[] = {
00606 "All parameters must be white-space delimited. Some options are driver",
00607 "dependent. Please see the PLplot reference document for more detail.",
00608 NULL};
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624 typedef struct {
00625 PLOptionTable *options;
00626 const char *name;
00627 const char **notes;
00628 } PLOptionInfo;
00629
00630 PLOptionInfo ploption_info_default = {
00631 ploption_table,
00632 "PLplot options",
00633 plplot_notes
00634 };
00635
00636 #define PL_MAX_OPT_TABLES 10
00637 PLOptionInfo ploption_info[PL_MAX_OPT_TABLES] = {
00638 {
00639 ploption_table,
00640 "PLplot options",
00641 plplot_notes
00642 }
00643 };
00644
00645
00646
00647 typedef struct DrvOptCmd {
00648 char *option;
00649 char *value;
00650 struct DrvOptCmd *next;
00651 } DrvOptCmd;
00652
00653
00654 static DrvOptCmd drv_opt = { NULL, NULL, NULL };
00655
00656 static int tables = 1;
00657
00658
00659
00660
00661
00662
00663
00664
00665 int
00666 c_plsetopt(const char *opt, const char *optarg)
00667 {
00668 return(plSetOpt(opt, optarg));
00669 }
00670
00671 int
00672 plSetOpt(const char *opt, const char *optarg)
00673 {
00674 int mode = 0, argc = 2, status;
00675 const char *argv[3];
00676
00677 argv[0] = opt;
00678 argv[1] = optarg;
00679 argv[2] = NULL;
00680 mode =
00681 PL_PARSE_QUIET |
00682 PL_PARSE_NODELETE |
00683 PL_PARSE_NOPROGRAM |
00684 PL_PARSE_NODASH;
00685
00686 status = plparseopts(&argc, argv, mode);
00687 if (status) {
00688 fprintf( stderr, "plSetOpt: Unrecognized option %s\n", opt);
00689 }
00690 return status;
00691 }
00692
00693
00694
00695
00696
00697
00698
00699 int
00700 plMergeOpts(PLOptionTable *options, const char *name, const char **notes)
00701 {
00702 PLOptionTable *tab;
00703
00704 pllib_init();
00705
00706
00707
00708 for (tab = (PLOptionTable *) options; tab->opt; tab++)
00709 ;
00710
00711
00712
00713 if ((tab->handler != NULL) ||
00714 (tab->client_data != NULL) ||
00715 (tab->var != NULL) ||
00716 (tab->mode != 0) ||
00717 (tab->syntax != NULL) ||
00718 (tab->desc != NULL)) {
00719
00720 plabort("plMergeOpts: input table improperly terminated");
00721 return 1;
00722 }
00723
00724
00725
00726 if (tables++ >= PL_MAX_OPT_TABLES) {
00727 plabort("plMergeOpts: max tables limit exceeded, table not merged");
00728 return 1;
00729 }
00730
00731 ploption_info[tables-1].options = options;
00732 ploption_info[tables-1].name = name;
00733 ploption_info[tables-1].notes = notes;
00734
00735 return 0;
00736 }
00737
00738
00739
00740
00741
00742
00743
00744 void
00745 plClearOpts(void)
00746 {
00747 tables = 0;
00748 }
00749
00750
00751
00752
00753
00754
00755
00756 void
00757 plResetOpts(void)
00758 {
00759 ploption_info[0] = ploption_info_default;
00760 tables = 1;
00761 }
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771 int
00772 c_plparseopts(int *p_argc, const char **argv, PLINT mode)
00773 {
00774 const char **argsave, **argend;
00775 int i, myargc, status = 0;
00776
00777 pllib_init();
00778
00779
00780
00781 mode_full = mode & PL_PARSE_FULL;
00782 mode_quiet = mode & PL_PARSE_QUIET;
00783 mode_nodelete = mode & PL_PARSE_NODELETE;
00784 mode_showall = mode & PL_PARSE_SHOWALL;
00785 mode_noprogram = mode & PL_PARSE_NOPROGRAM;
00786 mode_nodash = mode & PL_PARSE_NODASH;
00787 mode_skip = mode & PL_PARSE_SKIP;
00788
00789 myargc = (*p_argc);
00790 argend = argv + myargc;
00791
00792
00793
00794 if ( ! mode_noprogram) {
00795 program = plstrdup(argv[0]);
00796 plsc->program = program;
00797 --myargc; ++argv;
00798 }
00799 if (myargc == 0)
00800 return 0;
00801
00802
00803
00804 argsave = argv;
00805 for (; myargc > 0; --myargc, ++argv) {
00806
00807
00808
00809 if (*argv == NULL || *argv[0] == '\0')
00810 continue;
00811
00812
00813
00814 for (i = tables-1; i >= 0; i--) {
00815
00816
00817
00818 status = ParseOpt(&myargc, &argv, p_argc, &argsave,
00819 ploption_info[i].options);
00820
00821 if ( ! status) break;
00822 }
00823
00824
00825
00826 if (status == -1) {
00827
00828
00829
00830
00831 if (mode_skip) {
00832 if ( ! mode_nodelete)
00833 *argsave++ = *argv;
00834 continue;
00835 }
00836 if ( ! mode_quiet && mode_full) {
00837 fprintf(stderr, "\nBad command line option \"%s\"\n", argv[0]);
00838 plOptUsage();
00839 }
00840 if (mode_full) exit(1);
00841
00842 status = 0;
00843 break;
00844
00845 } else if (status == 1) {
00846
00847
00848
00849 if ( ! mode_quiet) {
00850 fprintf(stderr, "\nBad command line option \"%s\"\n", argv[0]);
00851 plOptUsage();
00852 }
00853 if (mode_full) exit(1);
00854
00855 break;
00856
00857 } else if (status == 2) {
00858
00859
00860
00861 exit(0);
00862 }
00863 }
00864
00865
00866
00867 if ( ! mode_nodelete) {
00868 for (i = 0; i < myargc; i++)
00869 *argsave++ = *argv++;
00870
00871 if (argsave < argend)
00872 *argsave = NULL;
00873 }
00874
00875 return status;
00876 }
00877
00878
00879
00880
00881
00882
00883
00884 static int
00885 ParseOpt(int *p_myargc, const char ***p_argv, int *p_argc, const char ***p_argsave,
00886 PLOptionTable *option_table)
00887 {
00888 PLOptionTable *tab;
00889 const char *opt;
00890
00891
00892
00893 if ( mode_nodash || (*p_argv)[0][0] == '-') {
00894
00895 opt = (*p_argv)[0];
00896 if (*opt == '-')
00897 opt++;
00898
00899 for (tab = option_table; tab->opt; tab++) {
00900
00901
00902
00903 if (tab->mode & PL_OPT_DISABLED)
00904 continue;
00905
00906
00907
00908 if (*opt == *tab->opt && ! strcmp(opt, tab->opt)) {
00909
00910
00911
00912 if ( ! mode_nodelete) {
00913 if (tab->mode & PL_OPT_NODELETE)
00914 (*(*p_argsave)++) = (**p_argv);
00915 else
00916 --(*p_argc);
00917 }
00918
00919
00920
00921 return (ProcessOpt(opt, tab, p_myargc, p_argv, p_argc));
00922 }
00923 }
00924 }
00925
00926 return -1;
00927 }
00928
00929
00930
00931
00932
00933
00934
00935 static int
00936 ProcessOpt(const char *opt, PLOptionTable *tab, int *p_myargc, const char ***p_argv,
00937 int *p_argc)
00938 {
00939 int need_arg, res;
00940 const char *optarg = NULL;
00941
00942
00943
00944 need_arg = PL_OPT_ARG | PL_OPT_INT | PL_OPT_FLOAT | PL_OPT_STRING;
00945
00946 if (tab->mode & need_arg) {
00947 if (GetOptarg(&optarg, p_myargc, p_argv, p_argc))
00948 return 1;
00949 }
00950
00951
00952
00953 switch (tab->mode & 0xFF00) {
00954
00955 case PL_OPT_FUNC:
00956
00957
00958
00959 if (tab->handler == NULL) {
00960 fprintf(stderr,
00961 "ProcessOpt: no handler specified for option %s\n",
00962 tab->opt);
00963 return 1;
00964 }
00965
00966 if (mode_nodelete && optarg) {
00967
00968
00969 char *copy =
00970 (char *) malloc((size_t)(1+strlen(optarg))*sizeof(char));
00971 if (copy == NULL) {
00972 plabort("ProcessOpt: out of memory");
00973 return 1;
00974 }
00975 strcpy(copy, optarg);
00976 res = ((*tab->handler) (opt, copy, tab->client_data));
00977 free((void *) copy);
00978 return res;
00979 }
00980 else {
00981 return ((*tab->handler) (opt, optarg, tab->client_data));
00982 }
00983
00984 case PL_OPT_BOOL:
00985
00986
00987
00988 if (tab->var == NULL) {
00989 fprintf(stderr,
00990 "ProcessOpt: no variable specified for option %s\n",
00991 tab->opt);
00992 return 1;
00993 }
00994 *(int *)tab->var = 1;
00995 break;
00996
00997 case PL_OPT_INT:
00998
00999
01000
01001 if (tab->var == NULL) {
01002 fprintf(stderr,
01003 "ProcessOpt: no variable specified for option %s\n",
01004 tab->opt);
01005 return 1;
01006 }
01007 *(int *)tab->var = atoi(optarg);
01008 break;
01009
01010 case PL_OPT_FLOAT:
01011
01012
01013
01014 if (tab->var == NULL) {
01015 fprintf(stderr,
01016 "ProcessOpt: no variable specified for option %s\n",
01017 tab->opt);
01018 return 1;
01019 }
01020 *(PLFLT *)tab->var = atof(optarg);
01021 break;
01022
01023 case PL_OPT_STRING:
01024
01025
01026
01027 *(char **)tab->var = (char *)optarg;
01028 break;
01029
01030 default:
01031
01032
01033
01034 fprintf(stderr,
01035 "ProcessOpt: invalid processing mode for option %s\n",
01036 tab->opt);
01037 return 1;
01038 }
01039 return 0;
01040 }
01041
01042
01043
01044
01045
01046
01047
01048
01049 static int
01050 GetOptarg(const char **poptarg, int *p_myargc, const char ***p_argv, int *p_argc)
01051 {
01052 int result = 0;
01053
01054 --(*p_myargc);
01055
01056 if ((*p_myargc) <= 0)
01057 result = 1;
01058
01059 if ( ! result) {
01060 (*p_argv)++;
01061 if ((*p_argv)[0][0] == '-' && isalpha((*p_argv)[0][1])) {
01062
01063 (*p_argv)--;
01064 result = 1;
01065 }
01066 }
01067
01068 if ( ! result) {
01069 (*p_argc)--;
01070 *poptarg = (*p_argv)[0];
01071 }
01072 else {
01073 if ( ! mode_quiet) {
01074 fprintf(stderr, "Argument missing for %s option.\n", (*p_argv)[0]);
01075 plOptUsage();
01076 }
01077 }
01078 return result;
01079 }
01080
01081
01082
01083
01084
01085
01086
01087 void
01088 plSetUsage(const char *program_string, const char *usage_string)
01089 {
01090 if (program_string != NULL)
01091 program = program_string;
01092
01093 if (usage_string != NULL)
01094 usage = usage_string;
01095 }
01096
01097
01098
01099
01100
01101
01102
01103 void
01104 plOptUsage(void)
01105 {
01106 if (usage == NULL)
01107 fprintf(stderr, "\nUsage:\n %s [options]\n", program);
01108 else
01109 fputs(usage, stderr);
01110
01111 Syntax();
01112
01113 fprintf(stderr, "\n\nType %s -h for a full description.\n\n",
01114 program);
01115 }
01116
01117
01118
01119
01120
01121
01122
01123 static void
01124 Syntax(void)
01125 {
01126 PLOptionTable *tab;
01127 int i, col, len;
01128
01129
01130
01131 for (i = tables-1; i >= 0; i--) {
01132
01133
01134
01135 if (ploption_info[i].name)
01136 fprintf(stderr, "\n%s:", ploption_info[i].name);
01137 else
01138 fputs("\nUser options:", stderr);
01139
01140
01141
01142 col = 80;
01143 for (tab = ploption_info[i].options; tab->opt; tab++) {
01144 if (tab->mode & PL_OPT_DISABLED)
01145 continue;
01146
01147 if ( ! mode_showall && (tab->mode & PL_OPT_INVISIBLE))
01148 continue;
01149
01150 if (tab->syntax == NULL)
01151 continue;
01152
01153 len = 3 + strlen(tab->syntax);
01154 if (col + len > 79) {
01155 fprintf(stderr, "\n ");
01156 col = 3;
01157 }
01158 fprintf(stderr, " [%s]", tab->syntax);
01159 col += len;
01160 }
01161 fprintf(stderr, "\n");
01162 }
01163 }
01164
01165
01166
01167
01168
01169
01170
01171 static void
01172 Help(void)
01173 {
01174 PLOptionTable *tab;
01175 const char **note;
01176 int i;
01177 FILE *outfile = stderr;
01178
01179 #ifdef HAVE_POPEN
01180 FILE *pager = NULL;
01181 if (getenv("PAGER") != NULL)
01182 pager = (FILE *) popen("$PAGER", "w");
01183 if (pager == NULL)
01184 pager = (FILE *) popen("more", "w");
01185 if (pager != NULL)
01186 outfile = pager;
01187 #endif
01188
01189
01190
01191 if (usage == NULL)
01192 fprintf(outfile, "\nUsage:\n %s [options]\n", program);
01193 else
01194 fputs(usage, outfile);
01195
01196
01197
01198 for (i = tables-1; i >= 0; i--) {
01199
01200
01201
01202 if (ploption_info[i].name)
01203 fprintf(outfile, "\n%s:\n", ploption_info[i].name);
01204 else
01205 fputs("\nUser options:\n", outfile);
01206
01207
01208
01209 for (tab = ploption_info[i].options; tab->opt; tab++) {
01210 if (tab->mode & PL_OPT_DISABLED)
01211 continue;
01212
01213 if ( ! mode_showall && (tab->mode & PL_OPT_INVISIBLE))
01214 continue;
01215
01216 if (tab->desc == NULL)
01217 continue;
01218
01219 if (tab->mode & PL_OPT_INVISIBLE)
01220 fprintf(outfile, " * %-20s %s\n", tab->syntax, tab->desc);
01221 else
01222 fprintf(outfile, " %-20s %s\n", tab->syntax, tab->desc);
01223 }
01224
01225
01226
01227 if (ploption_info[i].notes) {
01228 putc('\n', outfile);
01229 for (note = ploption_info[i].notes; *note; note++) {
01230 fputs(*note, outfile);
01231 putc('\n', outfile);
01232 }
01233 }
01234 }
01235
01236 #ifdef HAVE_POPEN
01237 if (pager != NULL)
01238 pclose(pager);
01239 #endif
01240 }
01241
01242
01243
01244
01245
01246
01247
01248 int
01249 plParseDrvOpts(DrvOpt *acc_opt) {
01250 DrvOptCmd *drvp;
01251 DrvOpt *t;
01252 int fl;
01253 char msg[80];
01254 memset( msg, '\0', sizeof(msg) );
01255
01256 if (!drv_opt.option)
01257 return 1;
01258
01259 drvp = &drv_opt;
01260 do {
01261 t = acc_opt; fl = 0;
01262 while (t->opt) {
01263 if (strcmp(drvp->option, t->opt) == 0) {
01264 fl = 1;
01265 switch (t->type) {
01266
01267 case DRV_STR:
01268 *(char **)(t->var_ptr) = (drvp->value);
01269 #ifdef DEBUG
01270 fprintf(stderr,"plParseDrvOpts: %s %s\n", t->opt, *(char**)t->var_ptr);
01271 #endif
01272 break;
01273
01274 case DRV_INT:
01275 if (sscanf(drvp->value, "%d", (int *)t->var_ptr) != 1) {
01276 snprintf(msg, sizeof(msg)-1, "Incorrect argument to '%s' option", drvp->option);
01277 plexit(msg);
01278 }
01279 #ifdef DEBUG
01280 fprintf(stderr,"plParseDrvOpts: %s %d\n", t->opt, *(int *) t->var_ptr);
01281 #endif
01282 break;
01283
01284 case DRV_FLT:
01285 if (sscanf(drvp->value, "%f", (float *)t->var_ptr) != 1) {
01286 snprintf(msg, sizeof(msg)-1, "Incorrect argument to '%s' option", drvp->option);
01287 plexit(msg);
01288 }
01289 #ifdef DEBUG
01290 fprintf(stderr,"plParseDrvOpts: %s %f\n", t->opt, *(float *) t->var_ptr);
01291 #endif
01292 break;
01293 }
01294 }
01295 t++;
01296 }
01297
01298 if (!fl) {
01299 snprintf(msg, sizeof(msg)-1, "Option '%s' not recognized.\n\nRecognized options for this driver are:\n", drvp->option);
01300 plwarn(msg);
01301 plHelpDrvOpts(acc_opt);
01302 plexit("");
01303 }
01304 }
01305 while((drvp = drvp->next))
01306 ;
01307
01308 return 0;
01309 }
01310
01311
01312
01313
01314
01315
01316
01317 void
01318 plHelpDrvOpts(DrvOpt *acc_opt) {
01319 DrvOpt *t;
01320
01321 t = acc_opt;
01322 while(t->opt) {
01323 fprintf(stderr, "%s:\t%s\n", t->opt, t->hlp_msg);
01324 t++;
01325 }
01326 }
01327
01328
01329
01330
01331
01332
01333
01334 void
01335 plP_FreeDrvOpts() {
01336 DrvOptCmd *drvp, *drvpl;
01337
01338 drvp = &drv_opt;
01339 do {
01340 drvpl = drvp;
01341 drvp = drvpl->next;
01342
01343 free(drvpl->option);
01344 free(drvpl->value);
01345
01346
01347 if (drvpl != &drv_opt)
01348 free(drvpl);
01349
01350 } while(drvp != NULL);
01351
01352
01353 drv_opt.option=NULL;
01354 drv_opt.value=NULL;
01355 drv_opt.next=NULL;
01356 }
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370 static int
01371 opt_h(const char *opt, const char *optarg, void *client_data)
01372 {
01373 if ( ! mode_quiet)
01374 Help();
01375
01376 return 2;
01377 }
01378
01379
01380
01381
01382
01383
01384
01385
01386 static int
01387 opt_v(const char *opt, const char *optarg, void *client_data)
01388 {
01389 if ( ! mode_quiet)
01390 fprintf(stderr, "PLplot library version: %s\n", VERSION);
01391
01392 return 2;
01393 }
01394
01395
01396
01397
01398
01399
01400
01401
01402 static int
01403 opt_verbose(const char *opt, const char *optarg, void *client_data)
01404 {
01405 plsc->verbose = 1;
01406 return 0;
01407 }
01408
01409
01410
01411
01412
01413
01414
01415
01416 static int
01417 opt_debug(const char *opt, const char *optarg, void *client_data)
01418 {
01419 plsc->debug = 1;
01420 plsc->verbose = 1;
01421 return 0;
01422 }
01423
01424
01425
01426
01427
01428
01429
01430
01431 static int
01432 opt_hack(const char *opt, const char *optarg, void *client_data)
01433 {
01434 plsc->hack = 1;
01435 return 0;
01436 }
01437
01438
01439
01440
01441
01442
01443
01444
01445 static int
01446 opt_dev(const char *opt, const char *optarg, void *client_data)
01447 {
01448 plsdev(optarg);
01449 return 0;
01450 }
01451
01452
01453
01454
01455
01456
01457
01458
01459 static int
01460 opt_o(const char *opt, const char *optarg, void *client_data)
01461 {
01462 plsfnam(optarg);
01463 return 0;
01464 }
01465
01466
01467
01468
01469
01470
01471
01472
01473 static int
01474 opt_mar(const char *opt, const char *optarg, void *client_data)
01475 {
01476 plsdidev(atof(optarg), PL_NOTSET, PL_NOTSET, PL_NOTSET);
01477 return 0;
01478 }
01479
01480
01481
01482
01483
01484
01485
01486
01487 static int
01488 opt_a(const char *opt, const char *optarg, void *client_data)
01489 {
01490 plsdidev(PL_NOTSET, atof(optarg), PL_NOTSET, PL_NOTSET);
01491 return 0;
01492 }
01493
01494
01495
01496
01497
01498
01499
01500
01501 static int
01502 opt_jx(const char *opt, const char *optarg, void *client_data)
01503 {
01504 plsdidev(PL_NOTSET, PL_NOTSET, atof(optarg), PL_NOTSET);
01505 return 0;
01506 }
01507
01508
01509
01510
01511
01512
01513
01514
01515 static int
01516 opt_jy(const char *opt, const char *optarg, void *client_data)
01517 {
01518 plsdidev(PL_NOTSET, PL_NOTSET, PL_NOTSET, atof(optarg));
01519 return 0;
01520 }
01521
01522
01523
01524
01525
01526
01527
01528
01529 static int
01530 opt_ori(const char *opt, const char *optarg, void *client_data)
01531 {
01532 plsdiori(atof(optarg));
01533 return 0;
01534 }
01535
01536
01537
01538
01539
01540
01541
01542
01543 static int
01544 opt_freeaspect(const char *opt, const char *optarg, void *client_data)
01545 {
01546 plsc->freeaspect = 1;
01547 return 0;
01548 }
01549
01550
01551
01552
01553
01554
01555
01556
01557
01558
01559
01560
01561
01562
01563
01564
01565
01566
01567
01568
01569
01570
01571 static int
01572 opt_portrait(const char *opt, const char *optarg, void *client_data)
01573 {
01574 plsc->portrait = 1;
01575 return 0;
01576 }
01577
01578
01579
01580
01581
01582
01583
01584
01585 static int
01586 opt_width(const char *opt, const char *optarg, void *client_data)
01587 {
01588 int width;
01589
01590 width = atoi(optarg);
01591 if (width < 0) {
01592 fprintf(stderr, "?invalid width\n");
01593 return 1;
01594 }
01595 else {
01596 plwid(width);
01597 plsc->widthlock = 1;
01598 }
01599 return 0;
01600 }
01601
01602
01603
01604
01605
01606
01607
01608
01609
01610
01611
01612
01613 static int
01614 opt_bg(const char *opt, const char *optarg, void *client_data)
01615 {
01616 const char *rgb;
01617 char *color_field, *alpha_field;
01618 long bgcolor, r, g, b;
01619 PLFLT a;
01620
01621
01622
01623 if (*optarg == '#')
01624 rgb = optarg + 1;
01625 else
01626 rgb = optarg;
01627
01628 strncpy(opttmp, optarg, OPTMAX-1);
01629 opttmp[OPTMAX-1] = '\0';
01630
01631 if (strchr (opttmp, '_')) {
01632
01633 color_field = strtok (opttmp, "_");
01634 alpha_field = strtok (NULL, "_");
01635 } else {
01636 color_field = opttmp;
01637 alpha_field = NULL;
01638 }
01639
01640 bgcolor = strtol(color_field, NULL, 16);
01641
01642
01643
01644
01645 switch (strlen(color_field)) {
01646 case 3:
01647 r = (bgcolor & 0xF00) >> 8;
01648 g = (bgcolor & 0x0F0) >> 4;
01649 b = (bgcolor & 0x00F);
01650
01651 r = r | (r << 4);
01652 g = g | (g << 4);
01653 b = b | (b << 4);
01654 break;
01655
01656 case 6:
01657 r = (bgcolor & 0xFF0000) >> 16;
01658 g = (bgcolor & 0x00FF00) >> 8;
01659 b = (bgcolor & 0x0000FF);
01660 break;
01661
01662 default:
01663 fprintf(stderr, "Unrecognized background color value %s\n", color_field);
01664 return 1;
01665 }
01666
01667 if(alpha_field)
01668 a = atof(alpha_field);
01669 else
01670 a = 1.;
01671
01672 plscolbga(r, g, b, a);
01673
01674 return 0;
01675 }
01676
01677
01678
01679
01680
01681
01682
01683
01684 static int
01685 opt_ncol0(const char *opt, const char *optarg, void *client_data)
01686 {
01687 plsc->ncol0 = atoi(optarg);
01688 return 0;
01689 }
01690
01691
01692
01693
01694
01695
01696
01697
01698 static int
01699 opt_ncol1(const char *opt, const char *optarg, void *client_data)
01700 {
01701 plsc->ncol1 = atoi(optarg);
01702 return 0;
01703 }
01704
01705
01706
01707
01708
01709
01710
01711
01712 static int
01713 opt_wplt(const char *opt, const char *optarg, void *client_data)
01714 {
01715 char *field;
01716 PLFLT xl, yl, xr, yr;
01717
01718 strncpy(opttmp, optarg, OPTMAX-1);
01719 opttmp[OPTMAX-1] = '\0';
01720
01721 if ((field = strtok(opttmp, ",")) == NULL)
01722 return 1;
01723
01724 xl = atof(field);
01725
01726 if ((field = strtok(NULL, ",")) == NULL)
01727 return 1;
01728
01729 yl = atof(field);
01730
01731 if ((field = strtok(NULL, ",")) == NULL)
01732 return 1;
01733
01734 xr = atof(field);
01735
01736 if ((field = strtok(NULL, ",")) == NULL)
01737 return 1;
01738
01739 yr = atof(field);
01740
01741 plsdiplt(xl, yl, xr, yr);
01742 return 0;
01743 }
01744
01745
01746
01747
01748
01749
01750
01751
01752 static int
01753 opt_drvopt(const char *opt, const char *optarg, void *client_data)
01754 {
01755 char t, *tt, *option, *value;
01756 int fl = 0;
01757 DrvOptCmd *drvp;
01758
01759 option = (char *) malloc((size_t)(1+strlen(optarg))*sizeof(char));
01760 if (option == NULL)
01761 plexit("opt_drvopt: Out of memory!?");
01762
01763 value = (char *) malloc((size_t)(1+strlen(optarg))*sizeof(char));
01764 if (value == NULL)
01765 plexit("opt_drvopt: Out of memory!?");
01766
01767 drvp = &drv_opt;
01768 *option = *value = '\0';
01769 tt = option;
01770 while((t = *optarg++)) {
01771 switch (t) {
01772 case ',':
01773 if (fl)
01774 fl = 0;
01775 else {
01776 value[0] = '1';
01777 value[1] = '\0';
01778 }
01779
01780 *tt = '\0'; tt = option;
01781 drvp->option = plstrdup(option);
01782 drvp->value = plstrdup(value);
01783 drvp->next = (DrvOptCmd *) malloc(sizeof(DrvOptCmd));
01784 if (drvp->next == NULL)
01785 plexit("opt_drvopt: Out of memory!?\n");
01786
01787 drvp = drvp->next;
01788 break;
01789
01790 case '=':
01791 fl = 1;
01792 *tt = '\0'; tt = value;
01793 break;
01794
01795 default:
01796 *tt++ = t;
01797 }
01798 }
01799
01800 *tt = '\0';
01801 if (!fl) {
01802 value[0] = '1';
01803 value[1] = '\0';
01804 }
01805
01806 drvp->option = plstrdup(option);
01807 drvp->value = plstrdup(value);
01808 drvp->next = NULL;
01809
01810 #ifdef DEBUG
01811 fprintf(stderr, "\nopt_drvopt: -drvopt parsed options:\n");
01812 drvp = &drv_opt;
01813 do
01814 fprintf(stderr, "%s %s\n", drvp->option, drvp->value);
01815 while(drvp = drvp->next);
01816 fprintf(stderr, "\n");
01817 #endif
01818
01819 free(option); free(value);
01820
01821 return 0;
01822 }
01823
01824
01825
01826
01827
01828
01829
01830
01831 static int
01832 opt_fam(const char *opt, const char *optarg, void *client_data)
01833 {
01834 plsfam(1, -1, -1);
01835 return 0;
01836 }
01837
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853
01854 static int
01855 opt_fsiz(const char *opt, const char *optarg, void *client_data)
01856 {
01857 PLINT bytemax;
01858 int len = strlen(optarg);
01859 char lastchar = optarg[len-1];
01860 PLFLT multiplier = 1.0e6;
01861 char *spec = (char*)malloc(len+1);
01862
01863 if (spec==NULL)
01864 plexit("opt_fsiz: Insufficient memory");
01865
01866
01867
01868 switch (lastchar) {
01869 case 'k':
01870 case 'K':
01871 multiplier = 1.0e3; len--;
01872 break;
01873 case 'm':
01874 case 'M':
01875 multiplier = 1.0e6; len--;
01876 break;
01877 case 'g':
01878 case 'G':
01879 multiplier = 1.0e9; len--;
01880 break;
01881 }
01882 strncpy(spec, optarg, len);
01883 spec[len] = '\0';
01884
01885 bytemax = (PLINT)(multiplier * atof(spec));
01886 if (bytemax<=0) {
01887 fprintf(stderr, "?invalid file size %d. 2.14G is the maximum.\n", bytemax);
01888 return 1;
01889 }
01890 plsfam(1, -1, bytemax);
01891
01892 free(spec);
01893 return 0;
01894 }
01895
01896
01897
01898
01899
01900
01901
01902
01903 static int
01904 opt_fbeg(const char *opt, const char *optarg, void *client_data)
01905 {
01906 plsc->member = atoi(optarg);
01907
01908 return 0;
01909 }
01910
01911
01912
01913
01914
01915
01916
01917
01918 static int
01919 opt_finc(const char *opt, const char *optarg, void *client_data)
01920 {
01921 plsc->finc = atoi(optarg);
01922
01923 return 0;
01924 }
01925
01926
01927
01928
01929
01930
01931
01932
01933 static int
01934 opt_fflen(const char *opt, const char *optarg, void *client_data)
01935 {
01936 plsc->fflen = atoi(optarg);
01937
01938 return 0;
01939 }
01940
01941
01942
01943
01944
01945
01946
01947
01948 static int
01949 opt_np(const char *opt, const char *optarg, void *client_data)
01950 {
01951 plspause(0);
01952 return 0;
01953 }
01954
01955
01956
01957
01958
01959
01960
01961
01962 static int
01963 opt_nopixmap(const char *opt, const char *optarg, void *client_data)
01964 {
01965 plsc->nopixmap = 1;
01966 return 0;
01967 }
01968
01969
01970
01971
01972
01973
01974
01975
01976 static int
01977 opt_db(const char *opt, const char *optarg, void *client_data)
01978 {
01979 plsc->db = 1;
01980 return 0;
01981 }
01982
01983
01984
01985
01986
01987
01988
01989
01990 static int
01991 opt_bufmax(const char *opt, const char *optarg, void *client_data)
01992 {
01993 plsc->bufmax = atoi(optarg);
01994 return 0;
01995 }
01996
01997
01998
01999
02000
02001
02002
02003
02004 static int
02005 opt_server_name(const char *opt, const char *optarg, void *client_data)
02006 {
02007 plsc->server_name = plstrdup(optarg);
02008 return 0;
02009 }
02010
02011
02012
02013
02014
02015
02016
02017
02018 static int
02019 opt_plserver(const char *opt, const char *optarg, void *client_data)
02020 {
02021 plsc->plserver = plstrdup(optarg);
02022 return 0;
02023 }
02024
02025
02026
02027
02028
02029
02030
02031
02032 static int
02033 opt_plwindow(const char *opt, const char *optarg, void *client_data)
02034 {
02035 if ((plsc->plwindow = (char *) malloc((size_t)(1+strlen(optarg))*sizeof(char)))==NULL)
02036 {
02037 plexit("opt_plwindow: Insufficient memory");
02038 }
02039 strcpy (plsc->plwindow, optarg);
02040 return 0;
02041 }
02042
02043
02044
02045
02046
02047
02048
02049
02050
02051 static int
02052 opt_tcl_cmd(const char *opt, const char *optarg, void *client_data)
02053 {
02054 char *newcmd;
02055
02056 if ((newcmd = (char *) malloc((size_t)(strlen(optarg)+9)*sizeof(char)))==NULL)
02057 {
02058 plexit("opt_tcl_cmd: Insufficient memory");
02059 }
02060
02061 strcpy(newcmd,"tcl_cmd=");
02062 strcat(newcmd,optarg);
02063
02064 fprintf(stderr,"-tcl_cmd <cmd> is obsolete. Please use -drvopt tcl_cmd=<cmd> instead\n");
02065
02066 opt_drvopt("drvopt",newcmd,NULL);
02067 free(newcmd);
02068
02069 return 0;
02070 }
02071
02072
02073
02074
02075
02076
02077
02078
02079 static int
02080 opt_auto_path(const char *opt, const char *optarg, void *client_data)
02081 {
02082 plsc->auto_path = plstrdup(optarg);
02083 return 0;
02084 }
02085
02086
02087
02088
02089
02090
02091
02092
02093 static int
02094 opt_px(const char *opt, const char *optarg, void *client_data)
02095 {
02096 plssub(atoi(optarg), -1);
02097 return 0;
02098 }
02099
02100
02101
02102
02103
02104
02105
02106
02107 static int
02108 opt_py(const char *opt, const char *optarg, void *client_data)
02109 {
02110 plssub(-1, atoi(optarg));
02111 return 0;
02112 }
02113
02114
02115
02116
02117
02118
02119
02120
02121
02122
02123
02124 static int
02125 opt_geo(const char *opt, const char *optarg, void *client_data)
02126 {
02127 char *field;
02128 PLFLT xdpi = 0., ydpi = 0.;
02129 PLINT xwid = 0, ywid = 0, xoff = 0, yoff = 0;
02130
02131
02132
02133 if ((plsc->geometry = (char *) malloc((size_t)(1+strlen(optarg))*sizeof(char)))==NULL)
02134 {
02135 plexit("opt_geo: Insufficient memory");
02136 }
02137
02138 strcpy (plsc->geometry, optarg);
02139
02140
02141
02142 strncpy(opttmp, optarg, OPTMAX-1);
02143 opttmp[OPTMAX-1] = '\0';
02144 if (strchr (opttmp, 'x')) {
02145
02146
02147
02148 field = strtok (opttmp, "x");
02149 xwid = atoi (field);
02150 if (xwid == 0)
02151 fprintf (stderr, "?invalid xwid\n");
02152
02153 if ((field = strtok (NULL, "+")) == NULL)
02154 return 1;
02155
02156 ywid = atoi (field);
02157 if (ywid == 0)
02158 fprintf (stderr, "?invalid ywid\n");
02159
02160 field = strtok (NULL, "+");
02161 }
02162 else {
02163
02164
02165
02166 field = strtok (opttmp, "+");
02167 }
02168
02169 if (field != NULL) {
02170 xoff = atoi (field);
02171 if ((field = strtok (NULL, "+")) != NULL)
02172 yoff = atoi (field);
02173 }
02174
02175 plspage (xdpi, ydpi, xwid, ywid, xoff, yoff);
02176 return 0;
02177 }
02178
02179
02180
02181
02182
02183
02184
02185 static int
02186 opt_tk_file(const char *opt, const char *optarg, void *client_data)
02187 {
02188 if ((plsc->tk_file = (char *) malloc((size_t)(1+strlen(optarg))*sizeof(char)))==NULL)
02189 {
02190 plexit("opt_tk_file: Insufficient memory");
02191 }
02192
02193 strcpy (plsc->tk_file, optarg);
02194 return 0;
02195 }
02196
02197
02198
02199
02200
02201
02202
02203
02204
02205
02206
02207
02208 static int
02209 opt_dpi(const char *opt, const char *optarg, void *client_data)
02210 {
02211 char *field;
02212 PLFLT xdpi = 0., ydpi = 0.;
02213 PLINT xwid = 0, ywid = 0, xoff = 0, yoff = 0;
02214
02215 strncpy(opttmp, optarg, OPTMAX-1);
02216 opttmp[OPTMAX-1] = '\0';
02217 if (strchr (opttmp, 'x')) {
02218 field = strtok (opttmp, "x");
02219 xdpi = atof (field);
02220 if (xdpi == 0)
02221 fprintf (stderr, "?invalid xdpi\n");
02222
02223 if ((field = strtok (NULL, " ")) == NULL)
02224 return 1;
02225
02226 ydpi = atof (field);
02227 if (ydpi == 0)
02228 fprintf (stderr, "?invalid ydpi\n");
02229
02230 } else {
02231 xdpi = atof (opttmp);
02232 ydpi=xdpi;
02233 if (xdpi==0) return 1;
02234 }
02235
02236 plspage (xdpi, ydpi, xwid, ywid, xoff, yoff);
02237 return 0;
02238 }
02239
02240
02241
02242
02243
02244
02245
02246 static int
02247 opt_dev_compression(const char *opt, const char *optarg, void *client_data)
02248 {
02249 PLINT comp = 0;
02250
02251 comp = atoi(optarg);
02252 if (comp == 0) {
02253 fprintf(stderr, "?invalid compression\n");
02254 return 1;
02255 }
02256 plscompression (comp);
02257
02258 return 0;
02259 }
02260
02261
02262
02263
02264
02265
02266
02267 static int
02268 opt_cmap0(const char *opt, const char *optarg, void *client_data)
02269 {
02270 plspal0(optarg);
02271 return 0;
02272 }
02273
02274
02275
02276
02277
02278
02279
02280 static int
02281 opt_cmap1(const char *opt, const char *optarg, void *client_data)
02282 {
02283 plspal1(optarg, TRUE);
02284 return 0;
02285 }
02286
02287
02288
02289
02290
02291
02292
02293 static int
02294 opt_locale(const char *opt, const char *optarg, void *client_data)
02295 {
02296 char *locale;
02297 if(locale = setlocale(LC_NUMERIC, "")) {
02298 printf("LC_NUMERIC locale set to \"%s\"\n", locale);
02299 } else {
02300 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");
02301 if(!(locale = setlocale(LC_NUMERIC, "C"))) {
02302 plexit("Your platform is seriously broken. Not even a \"C\" locale could be set.");
02303 }
02304 }
02305 return 0;
02306 }
02307