#include #include #include #include "click-finder.h" #include "version.h" // #include static int verbose_flag; static long long int bytes_per_sample = 3; static long long int channels = 1; int main(int argc, char **argv) { int c; int samples_read; while (1) { static struct option long_options[] = { {"help", no_argument, 0, 0}, {"version", no_argument, 0, 0}, {"verbose", no_argument, &verbose_flag, 1}, {"brief", no_argument, &verbose_flag, 0}, {"bitspersample", required_argument, 0, 'b'}, {"channels", required_argument, 0, 'c'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; c = getopt_long (argc, argv, "b:hv", long_options, &option_index); /* Detect the end of the options. */ if (c == -1) break; switch (c) { case 0: /* If this option set a flag, do nothing else now. */ if (long_options[option_index].flag != 0) break; switch (option_index) { case 0: printf("Print help here.\n"); exit(0); case 1: printf("This is %s, version %s\n", progname, VERSION); exit(0); default: fprintf (stderr, "unknown option %s", long_options[option_index].name); if (optarg) fprintf (stderr, " with arg %s", optarg); fprintf (stderr, "\n"); exit(1); } break; case 'b': if (atoi(optarg) % 8 != 0) { fprintf(stderr, "%s: bits per sample (%d) is no multiple of 8", progname, atoi(optarg)); exit(1); } bytes_per_sample = atoi(optarg)/8; break; case 'c': channels = atoi(optarg); break; case 'v': verbose_flag=1; break; case '?': /* getopt_long already printed an error message. */ exit(1); default: exit(1); } } if (optind != argc) { fprintf(stderr, "%s: spurious option '%s'\n", progname, argv[optind]); exit(1); } if (verbose_flag) { fprintf(stderr, "bps: %d\n", bytes_per_sample*8); fprintf(stderr, "channels: %d\n", channels); } int8_t *content = malloc(sizeof(int8_t) * bytes_per_sample * channels * BUF_SIZE); long long int content_length = 0; // in bytes if (content == NULL) { fprintf(stderr, "%s: Failed to allocate content", progname); exit(1); } while (samples_read = fread(content + content_length, bytes_per_sample * channels, BUF_SIZE, stdin)) { content_length += samples_read * bytes_per_sample * channels; content = realloc(content, content_length + sizeof(int8_t) * bytes_per_sample * channels * BUF_SIZE); } if(ferror(stdin)) { free(content); fprintf(stderr, "%s: Error reading from stdin.", progname); exit(1); } fprintf(stderr, "%d", content_length); free(content); if (verbose_flag) fprintf(stderr, "success\n"); return 0; }