From beb59d9076fcc95c9a0093b513e39b02fd9db134 Mon Sep 17 00:00:00 2001 From: mj Date: Mon, 19 Dec 2005 13:01:29 +0000 Subject: [PATCH] Bug fixes. --- Makefile | 7 +++++-- vorbiscut.c | 29 +++++++++++++++++++---------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index bd4ba4e..99fa239 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,15 @@ CC=gcc-4.0 LD=gcc-4.0 -CFLAGS=-O2 -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Wundef -Wredundant-decls -std=gnu99 +#CFLAGS=-O2 -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Wundef -Wredundant-decls -std=gnu99 +CFLAGS=-O0 -g -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Wundef -Wredundant-decls -std=gnu99 all: vorbiscut oggtest: LDFLAGS+=-logg vorbistest: LDFLAGS+=-lvorbisfile -logg -lvorbis -vorbiscut: LDFLAGS+=-L/opt/lib -lvorbisfile -logg -lvorbis -lasound -lsndfile +#vorbiscut: LDFLAGS+=-L/opt/lib -static -lvorbisfile -dynamic -logg -lvorbis -lasound -lsndfile +vorbiscut: vorbiscut.o /tmp/libvorbis-1.0rc3/lib/.libs/libvorbisfile.a /tmp/libvorbis-1.0rc3/lib/.libs/libvorbis.a +vorbiscut: LDFLAGS+=-L/opt/lib -logg -lasound -lsndfile vorbiscut.o: CFLAGS+=-I/opt/include clean: diff --git a/vorbiscut.c b/vorbiscut.c index 9fa51e5..be2e0f6 100644 --- a/vorbiscut.c +++ b/vorbiscut.c @@ -9,12 +9,15 @@ #include #include +static void key_cleanup(void); + static void __attribute__((noreturn)) die(char *msg, ...) { va_list args; va_start(args, msg); vfprintf(stderr, msg, args); fputc('\n', stderr); + key_cleanup(); exit(1); } @@ -25,6 +28,7 @@ typedef short s16; #define TRIPLE(pos) (int)(((pos)/rate)/60), (int)(((pos)/rate)%60), (int)((pos)%rate) static struct termios tios, tios_old; +static int tios_inited; static void key_init(void) { @@ -38,11 +42,16 @@ static void key_init(void) if (tcsetattr(0, 0, &tios) < 0) die("tcsetattr failed: %m"); fcntl(0, F_SETFL, O_NONBLOCK); + tios_inited = 1; } static void key_cleanup(void) { - tcsetattr(0, 0, &tios_old); + if (tios_inited) + { + tcsetattr(0, 0, &tios_old); + tios_inited = 0; + } } static int key_get(void) @@ -157,7 +166,7 @@ static void scan_streams(void) if (start_pos < 0) { if (find_title) - printf("WARNING: Title not found, marking whole file"); + printf("WARNING: Title not found, marking whole file\n"); start_pos = 0; end_pos = total_samples; } @@ -196,7 +205,7 @@ static void in_open(char *name) SF_INFO si; bzero(&si, sizeof(si)); lseek(fileno(infile), 0, SEEK_SET); - sndf = sf_open_fd(fileno(infile), O_RDONLY, &si, 0); + sndf = sf_open_fd(fileno(infile), SFM_READ, &si, 0); if (!sndf) die("sf_open_fd() failed: %s", sf_strerror(NULL)); total_samples = si.frames; @@ -236,10 +245,10 @@ static int in_read(s16 *buf, s64 pos, int nsamp) { if (ov_pcm_tell(&vf) != pos) { - printf("!!! CONFUSED POSITION\n"); - ov_pcm_seek(&vf, pos); - if (ov_pcm_tell(&vf) != pos) - printf(">>> unable to correct :(\n"); + printf("\n!!! CONFUSED POSITION\n"); + //ov_pcm_seek(&vf, pos); + //if (ov_pcm_tell(&vf) != pos) + //printf(">>> unable to correct :(\n"); } for (;;) { @@ -542,7 +551,7 @@ static void editor(void) else *f = MAX(*f - fst, 0); recalc_faders(); - if (mode == 1) + if (mode == M_PRE) go = start_pos; else go = CLAMP(end_pos - lback); @@ -585,7 +594,7 @@ static void editor(void) else { nsamp = sizeof(buf)/4; - if (pos + nsamp > pos) + if (pos + nsamp > end) nsamp = end - pos; nsamp = cooked_read(buf, pos, nsamp, (mode == M_PRE), (mode == M_POST)); nread = nsamp; @@ -713,7 +722,7 @@ static void render(char *name) for (;;) { int n = sizeof(buf) / 4; - if (pos + n > end_pos) + if (end_pos - pos < n) n = end_pos - pos; if (!n) break; -- 2.39.2