From d0fc345d05ecbbac8aeb5c408aad08c243b4c011 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 24 Nov 2011 10:22:18 +0100 Subject: uniso: use progress callback --- uniso.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'uniso.c') diff --git a/uniso.c b/uniso.c index f8d4427..f84efcd 100644 --- a/uniso.c +++ b/uniso.c @@ -1,7 +1,50 @@ +/* uniso.c - Unpack ISO9660 File System from a stream + * + * Copyright (C) 2011 Natanael Copa + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. See http://www.gnu.org/ for details. + */ + +#include +#include +#include #include #include +struct progress_context { + const char *filename; +}; + +static void update_progress_cb(size_t current, size_t total, const char *filename, + void *userdata) +{ + struct progress_context *ctx = (struct progress_context *)userdata; + double percent; + + if (ctx->filename == filename) + return; + + percent = (double)current * 100 / (double)total; + printf("(%5.1f%%) %s\n", percent, filename?filename:""); + ctx->filename = filename; +} + int main(int argc, char *argv[]) { - return uniso(STDIN_FILENO, NULL, NULL); + int opt; + void (*callback)(size_t, size_t, const char*, void*) = NULL; + struct progress_context ctx = { NULL }; + + while ((opt = getopt(argc, argv, "v")) != -1) { + switch (opt) { + case 'v': + callback = &update_progress_cb; + break; + } + } + + return uniso(STDIN_FILENO, callback, &ctx); } -- cgit v1.2.3