~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to fdp/options.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
ImportĀ upstreamĀ versionĀ 1.7.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* options.c
 
2
 */
 
3
 
 
4
#include <stdio.h>
 
5
#include <stdlib.h>
 
6
#include <exprval.h>
 
7
#include <math.h>
 
8
#include "options.h"
 
9
/* #include "expr.h" */
 
10
#include "macros.h"
 
11
 
 
12
#ifdef DMALLOC
 
13
#include "dmalloc.h"
 
14
#endif
 
15
 
 
16
char**     Files;
 
17
FILE*      Output_file;
 
18
int        PS = 0;
 
19
int        UseComp = 0;
 
20
int        Verbose = 0;
 
21
int        UseGrid = 0;
 
22
int        DoArrow = 0;
 
23
double     ArrowScale = 1.0;
 
24
 
 
25
static int        SinterFlag = 0;
 
26
 
 
27
static char* trueStr = "true";
 
28
static char* falseStr = "false";
 
29
 
 
30
static char*
 
31
boolOf (int v)
 
32
{
 
33
    if (v) return trueStr;
 
34
    else return falseStr;
 
35
}
 
36
 
 
37
static FILE*
 
38
file_select (char *str)
 
39
{
 
40
    FILE    *rv;
 
41
 
 
42
    rv = fopen(str,"w");
 
43
    if (rv == NULL) { perror(str); exit(1); }
 
44
 
 
45
    return rv;
 
46
}
 
47
 
 
48
static char* useString = "nat [opts] files\n\
 
49
  -p         -- postscript output\n\
 
50
  -v[n]      -- verbose mode\n\
 
51
  -?         -- print usage\n\
 
52
  -C         -- use connected components\n\
 
53
  -S         -- sinter mode\n\
 
54
  -G         -- use grid\n\
 
55
  -A[s]      -- add arrows on digraphs, scaled by s\n\
 
56
  -h height       (%d)\n\
 
57
  -o outfile      (<stdout>)\n\
 
58
  -w width        (%d)\n\
 
59
  -x stretch\n\
 
60
  -k len\n\
 
61
  -n iterations   (%d)\n\
 
62
where d is distance between points and t is current iteration\n";
 
63
 
 
64
static void
 
65
usage ()
 
66
{
 
67
    printf (useString, DfltHeight, DfltWidth, DfltIters);
 
68
    exit (0);
 
69
}
 
70
 
 
71
void initialize(int argc, char** argv)
 
72
{
 
73
    char        *rest,c;
 
74
    int         i, nfiles;
 
75
    double      tmp;
 
76
 
 
77
    nfiles = 0;
 
78
    for (i = 1; i < argc; i++)
 
79
        if (argv[i][0] != '-') nfiles++;
 
80
    Files = (char**)malloc((nfiles + 1)*sizeof(char *));
 
81
    nfiles = 0;
 
82
    for (i = 1; i < argc; i++) {
 
83
        if (argv[i][0] == '-') {
 
84
            rest = &(argv[i][2]);
 
85
            switch (c = argv[i][1]) {
 
86
                case 'o':
 
87
                    Output_file = file_select(rest[0]?rest:argv[++i]);
 
88
                    break;
 
89
                case 'A':
 
90
                    DoArrow = 1;
 
91
                    if (rest[0]) ArrowScale = atof(rest);
 
92
                    break;
 
93
                case 'G':
 
94
                    UseGrid = 1;
 
95
                    break;
 
96
                case 'S':
 
97
                    SinterFlag = 1;
 
98
                    break;
 
99
                case 'C':
 
100
                    UseComp = 1;
 
101
                    break;
 
102
                case 'p':
 
103
                    PS = 1;
 
104
                    break;
 
105
                case 'v':
 
106
                    Verbose = rest[0]?atoi(rest):1;
 
107
                    break;
 
108
                case 'k':
 
109
                    UserK = atof(rest[0]?rest:argv[++i]);
 
110
                    break;
 
111
                case 'x':
 
112
                    tmp = atof(rest[0]?rest:argv[++i]);
 
113
                    if (tmp > 0.0) Stretch = tmp;
 
114
                    break;
 
115
                case 'w':
 
116
                    Width = atof(rest[0]?rest:argv[++i]);
 
117
                    break;
 
118
                case 'h':
 
119
                    Height = atof(rest[0]?rest:argv[++i]);
 
120
                    break;
 
121
                case 'n':
 
122
                    NumIters = atoi(rest[0]?rest:argv[++i]);
 
123
                    break;
 
124
                case '?':
 
125
                    usage ();
 
126
                    break;
 
127
                default:
 
128
                    fprintf(stderr,"nat: option -%c unrecognized\n",c);
 
129
            }
 
130
        }
 
131
        else
 
132
          Files[nfiles++] = argv[i];
 
133
    }
 
134
 
 
135
    if (Output_file == NULL) Output_file = stdout;
 
136
}
 
137
 
 
138
void   showOpts (FILE* outf)
 
139
{
 
140
    fprintf (outf, "Connected components (C) : %s\n", boolOf (UseComp));
 
141
    fprintf (outf, "Sinter mode (S) : %s\n", boolOf (SinterFlag));
 
142
    fprintf (outf, "Grid mode (G) : %s\n", boolOf (UseGrid));
 
143
    fprintf (outf, "Verbose level (v) : %d\n", Verbose);
 
144
    fprintf (outf, "Width (w) : %f, Height (h) : %f, Iterations (n) :%d\n", 
 
145
               Width, Height, NumIters);
 
146
}
 
147