Compare commits

...

2 Commits

Author SHA1 Message Date
Neale Pickett c66c6aea95 Make should make printy. Also docs. 2023-11-15 14:09:28 -07:00
Neale Pickett fb2cc4c44d New printy command 2023-11-15 13:13:47 -07:00
3 changed files with 37 additions and 0 deletions

View File

@ -16,6 +16,7 @@ TARGETS += hex
TARGETS += entropy
TARGETS += freq
TARGETS += histogram
TARGETS += printy
SCRIPTS += octets

View File

@ -232,6 +232,19 @@ Displays the Shannon entropy of the input.
0.865857
## printy: show density of printable octets
Displays the number of printable octets
divided by the total number of octets.
$ echo -n abcd | ./printy
1.000000
$ echo abcd | ./printy # Newline is not printable
0.800000
$ echo 00 41 | ./unhex | ./printy
0.500000
## pyesc: python escape input
Escapes input octets for pasting into a python "print" statement.

23
printy.c Normal file
View File

@ -0,0 +1,23 @@
#include <stdio.h>
#include <ctype.h>
int main(int argc, char *argv[]) {
int c;
unsigned int count = 0;
unsigned int printy = 0;
for (;;) {
c = getchar();
if (EOF == c) {
break;
}
if (isprint(c)) {
printy += 1;
}
count += 1;
}
printf("%f\n", printy/(float)count);
return 0;
}