/* bpbcounts.c - character code frequencies. * filter counting the occurrences of opening and closing brace, parenthesis, * and bracket characters. cf BE, 250707 NG. * usage: bpbcounts < file.{inc,pov} */ #define _GNU_SOURCE #include #include #include #include #include #define MAXV 256 int main(void) { int c; unsigned long v[MAXV] = {0L}; /* value counts array */ unsigned long nv = 0L; /* total */ /* drop privileges */ setregid(getgid(), getgid()); /* while there are characters on input stream */ while (EOF != (c = fgetc(stdin))) { ++v[(size_t)c]; ++nv; } /* output counts */ if (0 < nv) { printf("counts of paired characters:\n"); printf(" parentheses '%c' %3lu '%c' %3lu\n", 40, v[40], 41, v[41]); printf(" angle brackets '%c' %3lu '%c' %3lu\n", 60, v[60], 62, v[62]); printf("square brackets '%c' %3lu '%c' %3lu\n", 91, v[91], 93, v[93]); printf(" braces '%c' %3lu '%c' %3lu\n", 123, v[123], 125, v[125]); } exit(EXIT_SUCCESS); }