[GRASS-SVN] r35951 - in grass/trunk: include lib/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Feb 19 12:27:42 EST 2009
Author: martinl
Date: 2009-02-19 12:27:41 -0500 (Thu, 19 Feb 2009)
New Revision: 35951
Modified:
grass/trunk/include/gisdefs.h
grass/trunk/lib/gis/percent.c
Log:
libgis: G_set_percent_routine() and G_unset_percent_routine() added
Modified: grass/trunk/include/gisdefs.h
===================================================================
--- grass/trunk/include/gisdefs.h 2009-02-19 17:24:49 UTC (rev 35950)
+++ grass/trunk/include/gisdefs.h 2009-02-19 17:27:41 UTC (rev 35951)
@@ -870,6 +870,8 @@
/* percent.c */
void G_percent(long, long, int);
void G_percent_reset(void);
+void G_set_percent_routine(int (*) (int));
+void G_unset_percent_routine(void);
/* plot.c */
void G_setup_plot(double, double, double, double, int (*)(int, int),
Modified: grass/trunk/lib/gis/percent.c
===================================================================
--- grass/trunk/lib/gis/percent.c 2009-02-19 17:24:49 UTC (rev 35950)
+++ grass/trunk/lib/gis/percent.c 2009-02-19 17:27:41 UTC (rev 35951)
@@ -1,17 +1,15 @@
/**
- * \file percent.c
+ * \file gis/percent.c
*
* \brief GIS Library - percentage progress functions.
*
- * (C) 2001-2008 by the GRASS Development Team
+ * (C) 2001-2009 by the GRASS Development Team
*
* This program is free software under the GNU General Public License
* (>=v2). Read the file COPYING that comes with GRASS for details.
*
* \author GRASS GIS Development Team
- *
- * \date 1999-2008
*/
#include <stdio.h>
@@ -23,6 +21,7 @@
} state = {-1, 1};
static struct state *st = &state;
+static int (*ext_percent) (int);
/**
* \brief Print percent complete messages.
@@ -79,29 +78,37 @@
if (n <= 0 || n >= d || x > st->prev + s) {
st->prev = x;
- if (format == G_INFO_FORMAT_STANDARD) {
- fprintf(stderr, "%4d%%\b\b\b\b\b", x);
+ if (ext_percent) {
+ ext_percent(x);
}
else {
- if (format == G_INFO_FORMAT_PLAIN) {
- if (x == 100)
- fprintf(stderr, "%d\n", x);
- else
- fprintf(stderr, "%d..", x);
+ if (format == G_INFO_FORMAT_STANDARD) {
+ fprintf(stderr, "%4d%%\b\b\b\b\b", x);
}
- else { /* GUI */
- if (st->first) {
- fprintf(stderr, "\n");
+ else {
+ if (format == G_INFO_FORMAT_PLAIN) {
+ if (x == 100)
+ fprintf(stderr, "%d\n", x);
+ else
+ fprintf(stderr, "%d..", x);
}
- fprintf(stderr, "GRASS_INFO_PERCENT: %d\n", x);
- fflush(stderr);
- st->first = 0;
+ else { /* GUI */
+ if (st->first) {
+ fprintf(stderr, "\n");
+ }
+ fprintf(stderr, "GRASS_INFO_PERCENT: %d\n", x);
+ fflush(stderr);
+ st->first = 0;
+ }
}
}
}
if (x >= 100) {
- if (format == G_INFO_FORMAT_STANDARD) {
+ if (ext_percent) {
+ ext_percent(100);
+ }
+ else if (format == G_INFO_FORMAT_STANDARD) {
fprintf(stderr, "\n");
}
st->prev = -1;
@@ -121,3 +128,25 @@
st->prev = -1;
st->first = 1;
}
+
+/**
+ * \brief Establishes percent_routine as the routine that will handle
+ * the printing of percentage progress messages.
+ *
+ * \param percent_routine routine will be called like this: percent_routine(x)
+ */
+void G_set_percent_routine(int (*percent_routine) (int))
+{
+ ext_percent = percent_routine;
+}
+
+/**
+ * \brief After this call subsequent percentage progress messages will
+ * be handled in the default method.
+ *
+ * Percentage progress messages are printed directly to stderr.
+ */
+void G_unset_percent_routine(void)
+{
+ ext_percent = NULL;
+}
More information about the grass-commit
mailing list