aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--miragextract.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/miragextract.c b/miragextract.c
index e67964f..3719f2a 100644
--- a/miragextract.c
+++ b/miragextract.c
@@ -53,6 +53,21 @@ const guint8 *apply_s_opt(const guint8 *buf, gint len) {
return (const guint8 *)newbuf;
}
+void print_progress(void) {
+ static char spinner[] = "-/|\\";
+ static int count = 0;
+ putchar(spinner[count++]);
+ putchar('\b');
+ fflush(stdout);
+ if(count == 4) count = 0;
+}
+
+char *human_mb(int bytes) {
+ static char buf[10];
+ sprintf(buf, "%2.1f", (float)bytes / 1048576.0);
+ return buf;
+}
+
void extract_track(int t, int extract) {
MirageTrack *track;
MirageSector *sector;
@@ -134,6 +149,7 @@ void extract_track(int t, int extract) {
} else {
fwrite(buf, len, 1, out);
}
+ if(isatty(1) && !(sec % 100)) print_progress();
}
g_object_unref(sector);
}
@@ -141,7 +157,7 @@ void extract_track(int t, int extract) {
if(sfout) sf_close(sfout);
if(out) fclose(out);
- printf("%d bytes (%d sectors)\n", bytes, sec);
+ printf("%d bytes (%sMB, %d sectors)\n", bytes, human_mb(bytes), sec);
if(extract) printf(" Extracted to %s\n", outfile);
total_bytes += bytes;
@@ -247,6 +263,7 @@ int main(int argc, char **argv) {
gchar *fn[2];
int s, t;
+ /* get rid of any path elements in our executable name */
self = argv[0];
for(p = self; *p; p++)
if(p[0] == '/' && p[1]) self = p + 1;
@@ -259,6 +276,7 @@ int main(int argc, char **argv) {
if(!mirage_initialize(NULL))
die("couldn't initialize libmirage");
+ /* TODO: find out what image formats require multiple filenames, if any */
fn[0] = imagefile;
fn[1] = NULL;
@@ -275,7 +293,6 @@ int main(int argc, char **argv) {
int extract = 0;
output_track_number++;
- // printf("session %d, track %d\n", s + 1, t + 1);
if(want_track == 0 || want_track == output_track_number)
extract = 1;
@@ -284,6 +301,6 @@ int main(int argc, char **argv) {
}
mirage_shutdown(NULL);
- printf("Total size: %d bytes\n", total_bytes);
+ printf("Total size: %d bytes (%sMB)\n", total_bytes, human_mb(total_bytes));
return 0;
}