Commit 73f386c3 authored by Mathis Rosenhauer's avatar Mathis Rosenhauer

reformatting, option renaming and help

parent 98f41b09
...@@ -85,21 +85,20 @@ int main(int argc, char *argv[]) ...@@ -85,21 +85,20 @@ int main(int argc, char *argv[])
opterr = 0; opterr = 0;
while ((c = getopt (argc, argv, "d3Mscb:B:R:J:")) != -1) while ((c = getopt (argc, argv, "d3Mscb:B:R:J:")) != -1)
switch (c) switch (c) {
{
case 'd': case 'd':
dflag = 1; dflag = 1;
break; break;
case 'b': case 'b':
chunk = atoi(optarg); chunk = atoi(optarg);
break; break;
case 'B': case 'n':
strm.bits_per_sample = atoi(optarg); strm.bits_per_sample = atoi(optarg);
break; break;
case 'J': case 'j':
strm.block_size = atoi(optarg); strm.block_size = atoi(optarg);
break; break;
case 'R': case 'r':
strm.rsi = atoi(optarg); strm.rsi = atoi(optarg);
break; break;
case 'c': case 'c':
...@@ -108,7 +107,7 @@ int main(int argc, char *argv[]) ...@@ -108,7 +107,7 @@ int main(int argc, char *argv[])
case 's': case 's':
strm.flags |= AEC_DATA_SIGNED; strm.flags |= AEC_DATA_SIGNED;
break; break;
case 'M': case 'm':
strm.flags |= AEC_DATA_MSB; strm.flags |= AEC_DATA_MSB;
break; break;
case '3': case '3':
...@@ -128,25 +127,29 @@ int main(int argc, char *argv[]) ...@@ -128,25 +127,29 @@ int main(int argc, char *argv[])
abort (); abort ();
} }
if (optind < argc) if (optind < argc) {
{
infn = argv[optind]; infn = argv[optind];
} } else {
else fprintf(stderr, "Usage: %s [OPTION] SOURCE\n", argv[0]);
{ fprintf(stderr, "\nOPTIONS\n");
fprintf(stderr, "Usage: %s [ -c ] [ -b chunksize ] name\n", argv[0]); fprintf(stderr, "-3\n 24 bit samples are sored in 3 bytes\n");
fprintf(stderr, "-b\n internal buffer size\n");
fprintf(stderr, "-c\n write output on standard output\n");
fprintf(stderr, "-d\n decode SOURCE. If -d is not specified encode.\n");
fprintf(stderr, "-j\n block size in samples\n");
fprintf(stderr, "-m\n samples are MSB first. Default is LSB\n");
fprintf(stderr, "-n\n bits per sample\n");
fprintf(stderr, "-r\n reference sample interval in blocks\n");
fprintf(stderr, "-s\n samples are signed. Default is unsigned\n\n");
exit(-1); exit(-1);
} }
if (strm.bits_per_sample > 16) if (strm.bits_per_sample > 16) {
{
if (strm.bits_per_sample <= 24 && strm.flags & AEC_DATA_3BYTE) if (strm.bits_per_sample <= 24 && strm.flags & AEC_DATA_3BYTE)
chunk *= 3; chunk *= 3;
else else
chunk *= 4; chunk *= 4;
} } else if (strm.bits_per_sample > 8) {
else if (strm.bits_per_sample > 8)
{
chunk *= 2; chunk *= 2;
} }
...@@ -168,27 +171,20 @@ int main(int argc, char *argv[]) ...@@ -168,27 +171,20 @@ int main(int argc, char *argv[])
if ((infp = fopen(infn, "r")) == NULL) if ((infp = fopen(infn, "r")) == NULL)
exit(-1); exit(-1);
if (cflag) if (cflag) {
{
outfp = stdout; outfp = stdout;
} } else {
else
{
outfn = malloc(strlen(infn) + 4); outfn = malloc(strlen(infn) + 4);
if (outfn == NULL) if (outfn == NULL)
exit(-1); exit(-1);
if (dflag) if (dflag) {
{ if ((ext = strstr(infn, ".rz")) == NULL) {
if ((ext = strstr(infn, ".rz")) == NULL)
{
fprintf(stderr, "Error: input file needs to end with .rz\n"); fprintf(stderr, "Error: input file needs to end with .rz\n");
exit(-1); exit(-1);
} }
strncpy(outfn, infn, ext - infn); strncpy(outfn, infn, ext - infn);
} } else {
else
{
sprintf(outfn, "%s.rz", infn); sprintf(outfn, "%s.rz", infn);
} }
...@@ -196,21 +192,16 @@ int main(int argc, char *argv[]) ...@@ -196,21 +192,16 @@ int main(int argc, char *argv[])
exit(-1); exit(-1);
} }
if (dflag) if (dflag) {
{
if (aec_decode_init(&strm) != AEC_OK) if (aec_decode_init(&strm) != AEC_OK)
return 1; return 1;
} } else {
else
{
if (aec_encode_init(&strm) != AEC_OK) if (aec_encode_init(&strm) != AEC_OK)
return 1; return 1;
} }
while(input_avail || output_avail) while(input_avail || output_avail) {
{ if (strm.avail_in == 0 && input_avail) {
if (strm.avail_in == 0 && input_avail)
{
strm.avail_in = fread(in, 1, chunk, infp); strm.avail_in = fread(in, 1, chunk, infp);
if (strm.avail_in != chunk) if (strm.avail_in != chunk)
input_avail = 0; input_avail = 0;
...@@ -222,43 +213,33 @@ int main(int argc, char *argv[]) ...@@ -222,43 +213,33 @@ int main(int argc, char *argv[])
else else
status = aec_encode(&strm, AEC_NO_FLUSH); status = aec_encode(&strm, AEC_NO_FLUSH);
if (status != AEC_OK) if (status != AEC_OK) {
{
fprintf(stderr, "error is %i\n", status); fprintf(stderr, "error is %i\n", status);
return 1; return 1;
} }
if (strm.total_out - total_out > 0) if (strm.total_out - total_out > 0) {
{
fwrite(out, strm.total_out - total_out, 1, outfp); fwrite(out, strm.total_out - total_out, 1, outfp);
total_out = strm.total_out; total_out = strm.total_out;
output_avail = 1; output_avail = 1;
strm.next_out = out; strm.next_out = out;
strm.avail_out = chunk; strm.avail_out = chunk;
} } else {
else
{
output_avail = 0; output_avail = 0;
} }
} }
if (dflag) if (dflag) {
{
aec_decode_end(&strm); aec_decode_end(&strm);
} } else {
else if ((status = aec_encode(&strm, AEC_FLUSH)) != AEC_OK) {
{
if ((status = aec_encode(&strm, AEC_FLUSH)) != AEC_OK)
{
fprintf(stderr, "error is %i\n", status); fprintf(stderr, "error is %i\n", status);
return 1; return 1;
} }
if (strm.total_out - total_out > 0) if (strm.total_out - total_out > 0)
{
fwrite(out, strm.total_out - total_out, 1, outfp); fwrite(out, strm.total_out - total_out, 1, outfp);
}
aec_encode_end(&strm); aec_encode_end(&strm);
} }
...@@ -267,8 +248,7 @@ int main(int argc, char *argv[]) ...@@ -267,8 +248,7 @@ int main(int argc, char *argv[])
fclose(outfp); fclose(outfp);
free(in); free(in);
free(out); free(out);
if (!cflag) if (!cflag) {
{
unlink(infn); unlink(infn);
free(outfn); free(outfn);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment