9 |
|
|
10 |
|
#include <stdio.h> |
11 |
|
#include <stdlib.h> |
12 |
+ |
#include <string.h> |
13 |
|
#include <math.h> |
14 |
|
#include <ctype.h> |
15 |
|
|
29 |
|
int ncols; |
30 |
|
|
31 |
|
|
32 |
< |
main(argc, argv) |
33 |
< |
int argc; |
33 |
< |
char *argv[]; |
32 |
> |
static void |
33 |
> |
readinp(void) /* gather statistics on input */ |
34 |
|
{ |
35 |
– |
progname = argv[0]; |
36 |
– |
if (argc > 1 && !strcmp(argv[1], "-c")) { |
37 |
– |
cumulative++; |
38 |
– |
argc--; argv++; |
39 |
– |
} |
40 |
– |
if (argc < 3) |
41 |
– |
goto userr; |
42 |
– |
minv = atof(argv[1]); |
43 |
– |
maxv = atof(argv[2]); |
44 |
– |
if (argc == 4) |
45 |
– |
ndiv = atoi(argv[3]); |
46 |
– |
else { |
47 |
– |
if (argc > 4 || !isint(minv) || !isint(maxv)) |
48 |
– |
goto userr; |
49 |
– |
maxv += 0.5; |
50 |
– |
minv -= 0.5; |
51 |
– |
ndiv = maxv - minv + 0.5; |
52 |
– |
} |
53 |
– |
if (minv >= maxv | ndiv <= 0) |
54 |
– |
goto userr; |
55 |
– |
if (ndiv > MAXDIV) { |
56 |
– |
fprintf(stderr, "%s: maximum number of divisions: %d\n", |
57 |
– |
progname, MAXDIV); |
58 |
– |
goto userr; |
59 |
– |
} |
60 |
– |
readinp(); |
61 |
– |
if (cumulative) |
62 |
– |
printcumul(); |
63 |
– |
else |
64 |
– |
printhisto(); |
65 |
– |
exit(0); |
66 |
– |
userr: |
67 |
– |
fprintf(stderr, "Usage: %s [-c] min max n\n", progname); |
68 |
– |
fprintf(stderr, " Or: %s [-c] imin imax\n", progname); |
69 |
– |
exit(1); |
70 |
– |
} |
71 |
– |
|
72 |
– |
|
73 |
– |
readinp() /* gather statistics on input */ |
74 |
– |
{ |
35 |
|
char buf[16*MAXCOL]; |
36 |
|
double d; |
37 |
|
register int c; |
55 |
|
} |
56 |
|
|
57 |
|
|
58 |
< |
printcumul() /* print cumulative histogram results */ |
58 |
> |
static void |
59 |
> |
printcumul(void) /* print cumulative histogram results */ |
60 |
|
{ |
61 |
|
long ctot[MAXCOL]; |
62 |
|
register int i, c; |
75 |
|
} |
76 |
|
|
77 |
|
|
78 |
< |
printhisto() /* print histogram results */ |
78 |
> |
static void |
79 |
> |
printhisto(void) /* print histogram results */ |
80 |
|
{ |
81 |
|
register int i, c; |
82 |
|
|
87 |
|
putchar('\n'); |
88 |
|
} |
89 |
|
} |
90 |
+ |
|
91 |
+ |
|
92 |
+ |
int |
93 |
+ |
main( |
94 |
+ |
int argc, |
95 |
+ |
char *argv[] |
96 |
+ |
) |
97 |
+ |
{ |
98 |
+ |
progname = argv[0]; |
99 |
+ |
if (argc > 1 && !strcmp(argv[1], "-c")) { |
100 |
+ |
cumulative++; |
101 |
+ |
argc--; argv++; |
102 |
+ |
} |
103 |
+ |
if (argc < 3) |
104 |
+ |
goto userr; |
105 |
+ |
minv = atof(argv[1]); |
106 |
+ |
maxv = atof(argv[2]); |
107 |
+ |
if (argc == 4) |
108 |
+ |
ndiv = atoi(argv[3]); |
109 |
+ |
else { |
110 |
+ |
if (argc > 4 || !isint(minv) || !isint(maxv)) |
111 |
+ |
goto userr; |
112 |
+ |
maxv += 0.5; |
113 |
+ |
minv -= 0.5; |
114 |
+ |
ndiv = maxv - minv + 0.5; |
115 |
+ |
} |
116 |
+ |
if (minv >= maxv | ndiv <= 0) |
117 |
+ |
goto userr; |
118 |
+ |
if (ndiv > MAXDIV) { |
119 |
+ |
fprintf(stderr, "%s: maximum number of divisions: %d\n", |
120 |
+ |
progname, MAXDIV); |
121 |
+ |
goto userr; |
122 |
+ |
} |
123 |
+ |
readinp(); |
124 |
+ |
if (cumulative) |
125 |
+ |
printcumul(); |
126 |
+ |
else |
127 |
+ |
printhisto(); |
128 |
+ |
exit(0); |
129 |
+ |
userr: |
130 |
+ |
fprintf(stderr, "Usage: %s [-c] min max n\n", progname); |
131 |
+ |
fprintf(stderr, " Or: %s [-c] imin imax\n", progname); |
132 |
+ |
exit(1); |
133 |
+ |
} |
134 |
+ |
|
135 |
+ |
|