-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
251 lines (213 loc) · 5.38 KB
/
main.c
File metadata and controls
251 lines (213 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/*
* Copyright (c) 1991, 1993, 1996, 1997
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Lawrence Berkeley Laboratory,
* Berkeley, CA. The name of the University may not be used to
* endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* This code is derived from the original X10 xgraph written by
* David Harrison University of California, Berkeley 1986, 1987
*
* Heavily hacked by Van Jacobson and Steven McCanne, UCB/LBL: added mouse
* functions to id points and compute slopes and distances. added keystroke
* commands to toggle most of the visual attributes of a window (grid, line,
* markers, etc.).
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "flags.h"
#include "dataset.h"
#ifndef lint
static char rcsid[] =
"@(#) $Header$ (LBL)";
#endif
/* VARARGS */
extern void error(char* cp, ...);
extern void xinit(char *dispname, struct plotflags *flags);
extern void xsetfont(char *name);
extern void setsetname(register char *name);
extern void ReadData(char *filename, int ulaw);
extern void xmain(struct plotflags *flags, int xlimits, int ylimits,
double loX, double loY, double hiX, double hiY);
char *progname;
void usage(void);
static char *
dispname(argc, argv)
int argc;
char **argv;
{
int i;
for (i = 1; i < argc - 1; ++i)
if (strcmp(argv[i], "-d") == 0)
return argv[i + 1];
return 0;
}
int
main(argc, argv)
int argc;
char *argv[];
{
int i, op;
int ulawflag = 0;
struct plotflags flags;
int xlim = 0, ylim = 0;
double loX, hiX, loY, hiY;
char *stripdir();
extern char *optarg;
extern int optind, opterr;
extern int bwFlag;
progname = stripdir(argv[0]);
memset(&flags, 0, sizeof(flags));
xinit(dispname(argc, argv), &flags);
/* Parse the argument list */
while ((op = getopt(argc, argv,
"x:y:cerRsS:tT:mMnN:oBpd:f:g:uDLl:v")) != -1) {
switch (op) {
default:
usage();
case 'c':
cflag = 1;
break;
case 'e':
flags.errorbar = 1;
break;
case 'r':
flags.rectangle = 1;
flags.nolines = 1;
break;
case 'R':
flags.rectangle = 2;
flags.nolines = 1;
break;
case 's':
flags.spline = 1;
break;
case 'S':
slope_scale = atof(optarg);
break;
case 't':
flags.tick = 1;
break;
case 'T':
graph_title = optarg;
break;
case 'm':
flags.mark = 1;
break;
case 'M':
bwFlag = 1;
break;
case 'n':
flags.nolines = 1;
break;
case 'N':
setsetname(optarg);
break;
case 'o':
flags.outline = 1;
break;
case 'B':
flags.bar = 1;
break;
case 'p':
flags.pixmarks = 1;
break;
case 'd':
break;
case 'f':
xsetfont(optarg);
break;
case 'g':
geometry = optarg;
break;
case 'u':
ulawflag = 1;
break;
case 'D':
dateXFlag = 1;
break;
case 'L':
dateXFlag = 1;
localTime = 1;
break;
case 'l':
if (*optarg == 'x')
logXFlag = 1;
else if (*optarg == 'y')
logYFlag = 1;
else
usage();
break;
case 'v':
usage();
break;
case 'x':
xlim = 1;
if (sscanf(optarg, "%lg,%lg", &loX, &hiX) != 2)
usage();
break;
case 'y':
ylim = 1;
if (sscanf(optarg, "%lg,%lg", &loY, &hiY) != 2)
usage();
break;
}
}
if (logXFlag && dateXFlag)
error("options -l x and -D or -L are incompatible");
/* Read the data into the data sets */
if (optind == argc)
ReadData((char *)0, ulawflag);
else
for (i = optind; i < argc; ++i)
ReadData(argv[i], ulawflag);
if (datasets == NULL)
error("no datapoints");
xmain(&flags, xlim, ylim, loX, loY, hiX, hiY);
exit(0);
}
void
usage(void)
{
static char use[] =
"\
usage: graf [-B] [-c] [-D] [-L] [-e] [-m] [-M] [-n] [-o] [-p] [-r] [-R] [-s]\n\
[-S] [-t] [-u] [-x x1,x2] [-y y1,y2] [-l x] [-l y] [-N label]\n\
[-T title] [-d host:display] [-f font] [-g geometry] [ file ... ]\n\
\n\
-B Draw bar graph\n\
-c Don't use off-screen pixmaps to enhance screen redraws\n\
-D Interpret X values as timestamps and label axis with date and time\n\
-e Draw error bars at each point\n\
-l x Logarithmic scale for X axis\n\
-l y Logarithmic scale for Y axis\n\
-L Show timestamps as local time not GMT, implies -D\n\
-m Mark each data point with large dot\n\
-M Forces black and white\n\
-n Don't draw lines (scatter plot)\n\
-N Dataset label (repeat for multiple datasets)\n\
-o Draws bounding box around data\n\
-p If -m, mark each point with a pixel instead\n\
-r Draw rectangle at each point (-R for filled)\n\
-s X Window System's notion of spline curves (not implemented)\n\
-S Set scale for slope display\n\
-t Draw tick marks instead of full grid\n\
-T Graph title\n\
-u Input files are ulaw encoded\n\
\n\
Type ?, F1 or Ctrl-H in the window for a list of mouse & keyboard functions.\n";
fputs(use, stderr);
exit(1);
}