aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--miragextract.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/miragextract.c b/miragextract.c
index 6861aef..e67964f 100644
--- a/miragextract.c
+++ b/miragextract.c
@@ -2,19 +2,21 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
+#include <limits.h>
#include <sndfile.h>
#include <mirage/mirage.h>
#define VERSION "0.0.1"
-const char *self;
+#ifndef PATH_MAX
+# define PATH_MAX 1024
+#endif
-static MirageContext *mirage = NULL;
-static MirageDisc *disc = NULL;
-static MirageSession *session = NULL;
-static int output_track_number = 0;
-int total_bytes = 0;
+/* This should be big enough to hold any CD sector */
+#define BUF_SIZE 4096
+
+const char *self;
char *imagefile = NULL;
char *outfilebase = "track";
@@ -26,6 +28,12 @@ int autoname = 0;
int want_data = 1;
int want_audio = 1;
+MirageContext *mirage = NULL;
+MirageDisc *disc = NULL;
+MirageSession *session = NULL;
+int output_track_number = 0;
+int total_bytes = 0;
+
void die(char *msg) {
fprintf(stderr, "%s: %s\n", self, msg);
exit(1);
@@ -33,7 +41,7 @@ void die(char *msg) {
const guint8 *apply_s_opt(const guint8 *buf, gint len) {
int i;
- static guint8 newbuf[4096];
+ static guint8 newbuf[BUF_SIZE];
if(!swap_bytes) return buf;
@@ -52,7 +60,7 @@ void extract_track(int t, int extract) {
gint len;
const guint8 *buf;
char *ext;
- char outfile[4096];
+ char outfile[PATH_MAX + 1];
FILE *out = NULL;
SNDFILE *sfout = NULL;
struct SF_INFO sfi;
@@ -141,7 +149,7 @@ void extract_track(int t, int extract) {
}
void set_auto_name(void) {
- static char autoname[4096];
+ static char autoname[PATH_MAX + 1];
char *p;
strcpy(autoname, imagefile);
@@ -155,7 +163,8 @@ void set_auto_name(void) {
void usage(int exit_code) {
fprintf(exit_code ? stderr : stdout,
"miragextract v" VERSION " by B. Watson, WTFPL\n"
- "Usage: %s [-l] [-s] [-n] [-a] [-d] [-t track] [-b base] [-f fmt ] [-q quality ] image-file\n"
+ "Usage: %s [-l] [-s] [-n] [-a] [-d] [-t track] [-b base]\n"
+ " [-f fmt ] [-q quality ] image-file\n"
"See man page for details\n", self);
exit(exit_code);
}
@@ -234,10 +243,14 @@ void parse_args(int argc, char **argv) {
}
int main(int argc, char **argv) {
- self = argv[0];
+ const char *p;
gchar *fn[2];
int s, t;
+ self = argv[0];
+ for(p = self; *p; p++)
+ if(p[0] == '/' && p[1]) self = p + 1;
+
parse_args(argc, argv);
if(!((mirage = g_object_new(MIRAGE_TYPE_CONTEXT, NULL))))