blob: 86621a92f5669913a38af3292cec9b62330fd138 [file] [log] [blame]
nethercote5912c812004-02-15 15:38:08 +00001/* This file is part of hp2ps, a graph drawer for memory profiles.
2 Copyright (C) 2002 The University Court of the University of Glasgow.
3 This program is governed by the license contained in the file LICENSE. */
4
nethercotec9f36922004-02-14 16:40:02 +00005#include <stdio.h>
6#include <string.h>
7#include <stdlib.h>
8#include "Main.h"
9#include "Defines.h"
10#include "AuxFile.h"
11#include "AreaBelow.h"
12#include "Dimensions.h"
13#include "HpFile.h"
14#include "PsFile.h"
15#include "Reorder.h"
16#include "Scale.h"
17#include "TopTwenty.h"
18#include "TraceElement.h"
19#include "Deviation.h"
20#include "Error.h"
21#include "Utilities.h"
22
23boolish pflag = 0; /* read auxiliary file */
24boolish eflag = 0; /* scaled EPSF */
25boolish dflag = 0; /* sort by standard deviation */
26int iflag = 0; /* sort by identifier (3-way flag) */
27boolish gflag = 0; /* output suitable for previewer */
28boolish yflag = 0; /* ignore marks */
29boolish bflag = 0; /* use a big title box */
30boolish sflag = 0; /* use a small title box */
31int mflag = 0; /* max no. of bands displayed (default 20) */
32boolish tflag = 0; /* ignored threshold specified */
33boolish cflag = 0; /* colour output */
34
35boolish filter; /* true when running as a filter */
36
37static floatish WidthInPoints PROTO((char *)); /* forward */
38static FILE *Fp PROTO((char *, char **, char *, char *)); /* forward */
39
40char *hpfile;
41char *psfile;
42char *auxfile;
43
44char *programname;
45
46static char *pathName;
47static char *baseName; /* "basename" is a std C library name (sigh) */
48
49FILE* hpfp;
50FILE* psfp;
51FILE* auxfp;
52
53floatish xrange = 0.0;
54floatish yrange = 0.0;
55
56floatish auxxrange = 0.0;
57floatish auxyrange = 0.0;
58
59floatish epsfwidth;
60floatish areabelow;
61
62intish nsamples;
63intish nmarks;
64intish nidents;
65
66floatish THRESHOLD_PERCENT = DEFAULT_THRESHOLD;
67int TWENTY = DEFAULT_TWENTY;
68
69int main(argc, argv)
70int argc;
71char* argv[];
72{
73
74 programname = copystring(Basename(argv[0]));
75
76 argc--, argv++;
77 while (argc && argv[0][0] == '-') {
78 while (*++*argv)
79 switch(**argv) {
80 case 'p':
81 pflag++;
82 break;
83 case 'e':
84 eflag++;
85 epsfwidth = WidthInPoints(*argv + 1);
86 goto nextarg;
87 case 'd':
88 dflag++;
89 goto nextarg;
90 case 'i':
91 switch( *(*argv + 1) ) {
92 case '-':
93 iflag = -1;
94 case '+':
95 default:
96 iflag = 1;
97 }
98 goto nextarg;
99 case 'g':
100 gflag++;
101 goto nextarg;
102 case 'y':
103 yflag++;
104 goto nextarg;
105 case 'b':
106 bflag++;
107 goto nextarg;
108 case 's':
109 sflag++;
110 goto nextarg;
111 case 'm':
112 mflag++;
113 TWENTY = atoi(*argv + 1);
114 if (TWENTY > DEFAULT_TWENTY)
115 Usage(*argv-1);
116 goto nextarg;
117 case 't':
118 tflag++;
119 THRESHOLD_PERCENT = (floatish) atof(*argv + 1);
120 if (THRESHOLD_PERCENT < 0 || THRESHOLD_PERCENT > 5)
121 Usage(*argv-1);
122 goto nextarg;
123 case 'c':
124 cflag++;
125 goto nextarg;
126 case '?':
127 default:
128 Usage(*argv-1);
129 }
130nextarg: ;
131 argc--, argv++;
132 }
133
134 hpfile = "stdin";
135 psfile = "stdout";
136
137 hpfp = stdin;
138 psfp = stdout;
139
140 filter = argc < 1;
141
142
143
144 if (!filter) {
145 pathName = copystring(argv[0]);
146 DropSuffix(pathName, ".hp");
147 baseName = copystring(Basename(pathName));
148
149 hpfp = Fp(pathName, &hpfile, ".hp", "r");
150 psfp = Fp(baseName, &psfile, ".ps", "w");
151
152 if (pflag) auxfp = Fp(baseName, &auxfile, ".aux", "r");
153 }
154
155 GetHpFile(hpfp);
156
157 if (!filter && pflag) GetAuxFile(auxfp);
158
159
160 TraceElement(); /* Orders on total, Removes trace elements (tflag) */
161
162 if (dflag) Deviation(); /* ReOrders on deviation */
163
164 if (iflag) Identorder(iflag); /* ReOrders on identifier */
165
166 if (pflag) Reorder(); /* ReOrders on aux file */
167
168 if (TWENTY) TopTwenty(); /* Selects top twenty (mflag) */
169
170 Dimensions();
171
172 areabelow = AreaBelow();
173
174 Scale();
175
176 PutPsFile();
177
178 if (!filter) {
179 auxfp = Fp(baseName, &auxfile, ".aux", "w");
180 PutAuxFile(auxfp);
181 }
182
183 return(0);
184}
185
186
187
188typedef enum {POINTS, INCHES, MILLIMETRES} pim;
189
190static pim Units PROTO((char *)); /* forward */
191
192static floatish
193WidthInPoints(wstr)
194 char *wstr;
195{
196 floatish result;
197
198 result = (floatish) atof(wstr);
199
200 switch (Units(wstr)) {
201 case INCHES:
202 result *= 72.0;
203 break;
204 case MILLIMETRES:
205 result *= 2.834646;
206 break;
207 case POINTS:
208 default: ;
209 }
210
211 if (result <= 144) /* Minimum of 2in wide ! */
212 Usage(wstr);
213
214 return result;
215}
216
217
218static pim
219Units(wstr)
220 char* wstr;
221{
222int i;
223
224 i = strlen(wstr) - 2;
225
226 if (wstr[i] == 'p' && wstr[i+1] == 't') {
227 return POINTS;
228 } else if (wstr[i] == 'i' && wstr[i+1] == 'n') {
229 return INCHES;
230 } else if (wstr[i] == 'm' && wstr[i+1] == 'm') {
231 return MILLIMETRES;
232 } else {
233 return POINTS;
234 }
235}
236
237static FILE *
238Fp(rootname, filename, suffix, mode)
239 char* rootname; char** filename; char* suffix; char* mode;
240{
241 *filename = copystring2(rootname, suffix);
242
243 return(OpenFile(*filename, mode));
244}
245
246#ifdef DEBUG
247void
248_stgAssert (filename, linenum)
249 char *filename;
250 unsigned int linenum;
251{
252 fflush(stdout);
253 fprintf(stderr, "ASSERTION FAILED: file %s, line %u\n", filename, linenum);
254 fflush(stderr);
255 abort();
256}
257#endif