~ubuntu-branches/ubuntu/jaunty/plotutils/jaunty

« back to all changes in this revision

Viewing changes to pic2plot/main.cc

  • Committer: Bazaar Package Importer
  • Author(s): Floris Bruynooghe
  • Date: 2007-05-10 19:48:54 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070510194854-mrr3lgwzpxd8hovo
Tags: 2.5-2
Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the GNU plotutils package.  Copyright (C) 1995,
 
2
   1996, 1997, 1998, 1999, 2000, 2005, Free Software Foundation, Inc.
 
3
 
 
4
   The GNU plotutils package is free software.  You may redistribute it
 
5
   and/or modify it under the terms of the GNU General Public License as
 
6
   published by the Free Software foundation; either version 2, or (at your
 
7
   option) any later version.
 
8
 
 
9
   The GNU plotutils package is distributed in the hope that it will be
 
10
   useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
   General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU General Public License along
 
15
   with the GNU plotutils package; see the file COPYING.  If not, write to
 
16
   the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
 
17
   Boston, MA 02110-1301, USA. */
 
18
 
1
19
#include "pic.h"
2
20
#include "output.h"
 
21
#include "common.h"
 
22
 
 
23
#include "libcommon.h"
3
24
#include "getopt.h"
 
25
#include "fontlist.h"
4
26
#include "plot.h"               // libplot header file
5
27
 
6
28
const char *progname = "pic2plot"; // name of this program
 
29
const char *written = "Written by Robert S. Maier.";
 
30
const char *copyright = "Copyright (C) 2005 Free Software Foundation, Inc.";
7
31
 
8
32
const char *usage_appendage = " FILE...\n";
9
33
 
16
40
// is derived from the output class.  Any instance of the plot_output
17
41
// class looks at the following global variables, which the user
18
42
// can set on the command line.
19
 
char *display_type = (char *)"meta"; // libplot output format
 
43
char *output_format = (char *)"meta"; // libplot output format
20
44
char *font_name = NULL; // initial font name (if set)
21
45
char *pen_color_name = NULL; // initial pen color (if set)
22
46
double font_size = 10.0/(8.0*72.); // font size as width of graphics display
43
67
static int had_parse_error = 0; // parse error?
44
68
static int lf_flag = 1;         // non-zero -> try to parse `.lf' lines
45
69
 
46
 
/* Long options we recognize */
 
70
// options
47
71
 
48
72
#define ARG_NONE        0
49
73
#define ARG_REQUIRED    1
50
74
#define ARG_OPTIONAL    2
51
75
 
 
76
const char *optstring = "T:OndF:f:W:";
 
77
 
52
78
struct option long_options[] = 
53
79
{
54
 
  /* The most important option */
55
 
  { "display-type",     ARG_REQUIRED,   NULL, 'T'},
 
80
  /* The most important option ("--display-type" is an obsolete variant) */
 
81
  { "output-format",    ARG_REQUIRED,   NULL, 'T'},
 
82
  { "display-type",     ARG_REQUIRED,   NULL, 'T' << 8 }, /* hidden */
56
83
  /* Long options, most with no equivalent short option alias */
57
84
  { "bg-color",         ARG_REQUIRED,   NULL, 'q' << 8 },
58
85
  { "bitmap-size",      ARG_REQUIRED,   NULL, 'B' << 8 },
76
103
  { NULL,               0,              NULL,  0}
77
104
};
78
105
    
79
 
/* null-terminated list of options that we don't show to the user */
80
 
int hidden_options[] = { 0 };
 
106
/* null-terminated list of options, such as obsolete-but-still-maintained
 
107
   options or undocumented options, which we don't show to the user */
 
108
const int hidden_options[] = { (int)('T' << 8), 0 };
81
109
 
82
110
// forward references
83
111
void do_file (const char *filename);
84
112
void do_picture (FILE *fp);
85
113
 
86
 
/* from libcommon */
87
 
extern "C" int display_fonts (const char *display_type, const char *progname);
88
 
extern "C" int list_fonts (const char *display_type, const char *progname);
89
 
extern "C" void display_usage (const char *progname, const int *omit_vals, const char *appendage, bool fonts);
90
 
extern "C" void display_version (const char *progname); 
91
 
extern "C" voidptr_t xcalloc (size_t nmemb, size_t size);
92
 
extern "C" voidptr_t xmalloc (size_t size);
93
 
extern "C" voidptr_t xrealloc (voidptr_t p, size_t length);
94
 
extern "C" char *xstrdup (const char *s);
95
 
 
96
114
//////////////////////////////////////////////////////////////////////
97
115
// TOP_INPUT class.
98
116
//////////////////////////////////////////////////////////////////////
328
346
#endif
329
347
 
330
348
  plotter_params = pl_newplparams ();
331
 
  while ((option = getopt_long (argc, argv, "T:OndF:f:W:", long_options, &opt_index)) != EOF)
 
349
  while ((option = getopt_long (argc, argv, optstring, long_options, &opt_index)) != EOF)
332
350
    {
333
351
      if (option == 0)
334
352
        option = long_options[opt_index].val;
335
353
      
336
354
      switch (option) 
337
355
        {
338
 
        case 'T':               /* Display type, ARG REQUIRED      */
339
 
          display_type = (char *)xmalloc (strlen (optarg) + 1);
340
 
          strcpy (display_type, optarg);
 
356
        case 'T':               /* Output format, ARG REQUIRED      */
 
357
        case 'T' << 8:
 
358
          output_format = (char *)xmalloc (strlen (optarg) + 1);
 
359
          strcpy (output_format, optarg);
341
360
          break;
342
361
        case 'O':               /* Ascii output */
343
 
          pl_setplparam (plotter_params, "META_PORTABLE", (voidptr_t)"yes");
 
362
          pl_setplparam (plotter_params, "META_PORTABLE", (void *)"yes");
344
363
          break;
345
364
        case 'n':               /* No centering */
346
365
          no_centering_flag = 1;
409
428
            break;
410
429
          }
411
430
        case 'e' << 8:          /* Emulate color via grayscale */
412
 
          pl_setplparam (plotter_params, "EMULATE_COLOR", (voidptr_t)optarg);
 
431
          pl_setplparam (plotter_params, "EMULATE_COLOR", (void *)optarg);
413
432
          break;
414
433
        case 'C' << 8:          /* set the initial pen color */
415
434
          pen_color_name = (char *)xmalloc (strlen (optarg) + 1);
416
435
          strcpy (pen_color_name, optarg);
417
436
          break;
418
437
        case 'q' << 8:          /* set the initial background color */
419
 
          pl_setplparam (plotter_params, "BG_COLOR", (voidptr_t)optarg);
 
438
          pl_setplparam (plotter_params, "BG_COLOR", (void *)optarg);
420
439
          break;
421
440
        case 'B' << 8:          /* Bitmap size */
422
 
          pl_setplparam (plotter_params, "BITMAPSIZE", (voidptr_t)optarg);
 
441
          pl_setplparam (plotter_params, "BITMAPSIZE", (void *)optarg);
423
442
          break;
424
443
        case 'M' << 8:          /* Max line length */
425
 
          pl_setplparam (plotter_params, "MAX_LINE_LENGTH", (voidptr_t)optarg);
 
444
          pl_setplparam (plotter_params, "MAX_LINE_LENGTH", (void *)optarg);
426
445
          break;
427
446
        case 'P' << 8:          /* Page size */
428
 
          pl_setplparam (plotter_params, "PAGESIZE", (voidptr_t)optarg);
 
447
          pl_setplparam (plotter_params, "PAGESIZE", (void *)optarg);
429
448
          break;
430
449
        case 'r' << 8:          /* Rotation angle */
431
 
          pl_setplparam (plotter_params, "ROTATION", (voidptr_t)optarg);
 
450
          pl_setplparam (plotter_params, "ROTATION", (void *)optarg);
432
451
          break;
433
452
        case 'V' << 8:          /* Version */
434
453
          show_version = true;
456
475
    }
457
476
  if (show_version)
458
477
    {
459
 
      display_version (progname);
 
478
      display_version (progname, written, copyright);
460
479
      return EXIT_SUCCESS;
461
480
    }
462
481
  if (do_list_fonts)
463
482
    {
464
483
      int success = true;
465
484
 
466
 
      success = list_fonts (display_type, progname);
 
485
      success = list_fonts (output_format, progname);
467
486
      if (success)
468
487
        return EXIT_SUCCESS;
469
488
      else
473
492
    {
474
493
      int success = true;
475
494
 
476
 
      success = display_fonts (display_type, progname);
 
495
      success = display_fonts (output_format, progname);
477
496
      if (success)
478
497
        return EXIT_SUCCESS;
479
498
      else