nethercote | 5912c81 | 2004-02-15 15:38:08 +0000 | [diff] [blame] | 1 | /* 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 | |
nethercote | c9f3692 | 2004-02-14 16:40:02 +0000 | [diff] [blame] | 5 | #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 | |
| 23 | boolish pflag = 0; /* read auxiliary file */ |
| 24 | boolish eflag = 0; /* scaled EPSF */ |
| 25 | boolish dflag = 0; /* sort by standard deviation */ |
| 26 | int iflag = 0; /* sort by identifier (3-way flag) */ |
| 27 | boolish gflag = 0; /* output suitable for previewer */ |
| 28 | boolish yflag = 0; /* ignore marks */ |
| 29 | boolish bflag = 0; /* use a big title box */ |
| 30 | boolish sflag = 0; /* use a small title box */ |
| 31 | int mflag = 0; /* max no. of bands displayed (default 20) */ |
| 32 | boolish tflag = 0; /* ignored threshold specified */ |
| 33 | boolish cflag = 0; /* colour output */ |
| 34 | |
| 35 | boolish filter; /* true when running as a filter */ |
| 36 | |
| 37 | static floatish WidthInPoints PROTO((char *)); /* forward */ |
| 38 | static FILE *Fp PROTO((char *, char **, char *, char *)); /* forward */ |
| 39 | |
| 40 | char *hpfile; |
| 41 | char *psfile; |
| 42 | char *auxfile; |
| 43 | |
| 44 | char *programname; |
| 45 | |
| 46 | static char *pathName; |
| 47 | static char *baseName; /* "basename" is a std C library name (sigh) */ |
| 48 | |
| 49 | FILE* hpfp; |
| 50 | FILE* psfp; |
| 51 | FILE* auxfp; |
| 52 | |
| 53 | floatish xrange = 0.0; |
| 54 | floatish yrange = 0.0; |
| 55 | |
| 56 | floatish auxxrange = 0.0; |
| 57 | floatish auxyrange = 0.0; |
| 58 | |
| 59 | floatish epsfwidth; |
| 60 | floatish areabelow; |
| 61 | |
| 62 | intish nsamples; |
| 63 | intish nmarks; |
| 64 | intish nidents; |
| 65 | |
| 66 | floatish THRESHOLD_PERCENT = DEFAULT_THRESHOLD; |
| 67 | int TWENTY = DEFAULT_TWENTY; |
| 68 | |
| 69 | int main(argc, argv) |
| 70 | int argc; |
| 71 | char* 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 | } |
| 130 | nextarg: ; |
| 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 | |
| 188 | typedef enum {POINTS, INCHES, MILLIMETRES} pim; |
| 189 | |
| 190 | static pim Units PROTO((char *)); /* forward */ |
| 191 | |
| 192 | static floatish |
| 193 | WidthInPoints(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 | |
| 218 | static pim |
| 219 | Units(wstr) |
| 220 | char* wstr; |
| 221 | { |
| 222 | int 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 | |
| 237 | static FILE * |
| 238 | Fp(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 |
| 247 | void |
| 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 |