/***************************************************************************/ /* */ /* Bitstat - generate bit-wise [and byte-wise] statistics of a file */ /* */ /* Usage: bitstat [-v] file (normal usage) */ /* or: bitstat [-v] < file */ /* or: type file | bitstat [-v] */ /* or: bitstat [-v] (keyboard input (terminate with ^Z)) */ /* */ /* Version: 1.0 */ /* Platform: DOS (easily transportable) */ /* Compiler: gcc */ /* Date: 07/09/96 */ /* License: Freeware */ /* Author: Winston Rayburn */ /* */ /***************************************************************************/ #include #include #include #include #define INPUT_BUFFER_SIZE 1024 /* in bytes */ #define TRUE (1==1) #define FALSE (1==0) #define USAGE printf("%s: Usage: %s [-v] file\n", argv[0], argv[0]); \ exit(1) /***************************************************************************/ main (argc, argv) int argc; char *argv[]; { float set_ratio, deviance_from_unity; float bit_percentage[8], byte_percentage[256]; float average_byte_count, average_byte_percentage; float ones_bit_percentage, zeros_bit_percentage; unsigned int bytes = 0, ones = 0, zeros; unsigned int i, got; unsigned char uc; int in; unsigned int byte_count[256] = {0}; unsigned int bit_count[8] = {0}; unsigned int bits; char *p; char verbose = FALSE; char c[INPUT_BUFFER_SIZE]; /***************************************************************************/ for (i=1; i 1) && (*p != '-')) { //--> in = open(argv[argc-1], O_RDONLY|O_BINARY); in = open(argv[argc-1], "rb"); if (in < 0) { printf("%s: Error opening %s\n", argv[0], argv[argc-1]); USAGE; } } else in = 0; while ((got = read(in, c, INPUT_BUFFER_SIZE)) > 0) { bytes += got; for(i=0; i