Neale Pickett
·
2020-12-22
freq.c
1#include <stdio.h>
2#include <stdbool.h>
3#include <unistd.h>
4#include "glyphs.h"
5
6int counts[256] = {0};
7
8int main(int argc, char *argv[]) {
9 int c;
10 bool all = false;
11
12 while ((c = getopt(argc, argv, "a")) != -1) {
13 switch (c) {
14 case -1:
15 break;
16 case 'a':
17 all = true;
18 break;
19 default:
20 fprintf(stderr, "Usage: %s [-a]\n", argv[0]);
21 fprintf(stderr, "\n");
22 fprintf(stderr, "-a Output all octets, even if count == 0\n");
23 return 1;
24 }
25 }
26
27 for (;;) {
28 c = getchar();
29 if (EOF == c) {
30 break;
31 }
32 counts[c] += 1;
33 }
34
35 for (c=0; c<256; ++c) {
36 if (all || counts[c]) {
37 printf("%d %02x %s\n", counts[c], c, fluffyglyphs[c]);
38 }
39 }
40 return 0;
41}