summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dimension/main.c7
-rw-r--r--dimension/progressbar.c27
-rw-r--r--dimension/progressbar.h5
-rw-r--r--dimension/utility.h8
4 files changed, 36 insertions, 11 deletions
diff --git a/dimension/main.c b/dimension/main.c
index fa7f5a6..cc140fd 100644
--- a/dimension/main.c
+++ b/dimension/main.c
@@ -196,7 +196,7 @@ main(int argc, char **argv) {
}
/* Realize the input */
- printf("Parsing scene ...\n");
+ printf("Parsing scene ...\n");
dmnsn_scene *scene = dmnsn_realize(input_file, symtable);
if (!scene) {
fprintf(stderr, "Error realizing input file!\n");
@@ -242,7 +242,8 @@ main(int argc, char **argv) {
return EXIT_FAILURE;
}
- dmnsn_progressbar("Rendering scene ", render_progress);
+ dmnsn_progressbar("Rendering scene with %u threads", render_progress,
+ scene->nthreads);
if (dmnsn_finish_progress(render_progress) != 0) {
dmnsn_delete_scene(scene);
@@ -259,7 +260,7 @@ main(int argc, char **argv) {
return EXIT_FAILURE;
}
- dmnsn_progressbar("Writing PNG ", output_progress);
+ dmnsn_progressbar("Writing PNG", output_progress);
if (dmnsn_finish_progress(output_progress) != 0) {
fclose(output_file);
diff --git a/dimension/progressbar.c b/dimension/progressbar.c
index fb26d4c..c366d4d 100644
--- a/dimension/progressbar.c
+++ b/dimension/progressbar.c
@@ -18,16 +18,35 @@
*************************************************************************/
#include "progressbar.h"
+#include <sys/ioctl.h>
+#include <stdarg.h>
#include <stdio.h>
+#include <unistd.h>
void
-dmnsn_progressbar(const char *str, const dmnsn_progress *progress)
+dmnsn_progressbar(const char *format, const dmnsn_progress *progress, ...)
{
- const unsigned int increments = 32;
- unsigned int i;
+ va_list ap;
+ va_start(ap, progress);
+
+ int len = vprintf(format, ap) + 1;
+ if (len < 1)
+ len = 1;
+ printf(" ");
+
+ va_end(ap);
+
+ unsigned int increments = 48;
+
+ /* Try to fill the terminal with the progress bar; this is non-portable */
+ struct winsize ws;
+ if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == 0) {
+ increments = ws.ws_col - (len % ws.ws_col);
+ }
- printf("%s", str);
fflush(stdout);
+
+ unsigned int i;
for (i = 0; i < increments; ++i) {
dmnsn_wait_progress(progress, ((double)(i + 1))/increments);
diff --git a/dimension/progressbar.h b/dimension/progressbar.h
index 9ee7d91..7f4948e 100644
--- a/dimension/progressbar.h
+++ b/dimension/progressbar.h
@@ -21,8 +21,11 @@
#define PROGRESSBAR_H
#include "../libdimension/dimension.h"
+#include "utility.h" /* For DMNSN_PRINTF_WARN */
/* Print a progress bar of the progress of `progress' */
-void dmnsn_progressbar(const char *str, const dmnsn_progress *progress);
+void dmnsn_progressbar(const char *format, const dmnsn_progress *progress,
+ ...)
+ DMNSN_PRINTF_WARN(1, 3);
#endif /* PROGRESSBAR_H */
diff --git a/dimension/utility.h b/dimension/utility.h
index d4ebda4..beb818e 100644
--- a/dimension/utility.h
+++ b/dimension/utility.h
@@ -17,11 +17,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
-#ifndef __GNUC__
- #define __attribute__(x)
+#if defined(__GNUC__) || defined(__attribute__)
+ #define DMNSN_PRINTF_WARN(f, a) __attribute__((format (printf, f, a)))
+#else
+ #define DMNSN_PRINTF_WARN(f, a)
#endif
/* Print a parsing diagnostic to stderr */
void dmnsn_diagnostic(const char *filename, int line, int col,
const char *format, ...)
- __attribute__ ((format (printf, 4, 5)));
+ DMNSN_PRINTF_WARN(4, 5);