[GRASS-SVN] r43014 - in grass/branches/develbranch_6: include
lib/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Aug 7 15:19:01 EDT 2010
Author: martinl
Date: 2010-08-07 19:19:01 +0000 (Sat, 07 Aug 2010)
New Revision: 43014
Modified:
grass/branches/develbranch_6/include/gisdefs.h
grass/branches/develbranch_6/lib/gis/error.c
grass/branches/develbranch_6/lib/gis/percent.c
Log:
backport G_set/unset_percent_routine() from trunk (used by wxnviz)
Modified: grass/branches/develbranch_6/include/gisdefs.h
===================================================================
--- grass/branches/develbranch_6/include/gisdefs.h 2010-08-07 19:17:15 UTC (rev 43013)
+++ grass/branches/develbranch_6/include/gisdefs.h 2010-08-07 19:19:01 UTC (rev 43014)
@@ -904,6 +904,8 @@
int G_percent(long, long, int);
int G_percent2(long, long, int, FILE *);
int G_percent_reset(void);
+void G_set_percent_routine(int (*) (int));
+void G_unset_percent_routine(void);
/* plot.c */
int G_setup_plot(double, double, double, double, int (*)(int, int),
Modified: grass/branches/develbranch_6/lib/gis/error.c
===================================================================
--- grass/branches/develbranch_6/lib/gis/error.c 2010-08-07 19:17:15 UTC (rev 43013)
+++ grass/branches/develbranch_6/lib/gis/error.c 2010-08-07 19:19:01 UTC (rev 43014)
@@ -263,7 +263,7 @@
else /* WARN */
fatal = FALSE;
- if ((type == WARN || type == ERR) && ext_error) { /* Function defined by application */
+ if ((type == MSG || type == WARN || type == ERR) && ext_error) { /* Function defined by application */
ext_error(msg, fatal);
}
else {
Modified: grass/branches/develbranch_6/lib/gis/percent.c
===================================================================
--- grass/branches/develbranch_6/lib/gis/percent.c 2010-08-07 19:17:15 UTC (rev 43013)
+++ grass/branches/develbranch_6/lib/gis/percent.c 2010-08-07 19:19:01 UTC (rev 43014)
@@ -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-2008, 2010 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>
@@ -21,6 +19,7 @@
static int prev = -1;
static int first = 1;
+static int (*ext_percent) (int);
/**
* \brief Print percent complete messages.
@@ -97,35 +96,42 @@
if (n <= 0 || n >= d || x > prev + s) {
prev = x;
- if (format == G_INFO_FORMAT_STANDARD) {
- if (out != NULL) {
- fprintf(out, "%4d%%\b\b\b\b\b", x);
- }
+ if (ext_percent) {
+ ext_percent(x);
}
else {
- if (format == G_INFO_FORMAT_PLAIN) {
+ if (format == G_INFO_FORMAT_STANDARD) {
if (out != NULL) {
- if (x == 100)
- fprintf(out, "%d\n", x);
- else
- fprintf(out, "%d..", x);
+ fprintf(out, "%4d%%\b\b\b\b\b", x);
}
}
- else { /* GUI */
- if (out != NULL) {
- if (first) {
- fprintf(out, "\n");
+ else {
+ if (format == G_INFO_FORMAT_PLAIN) {
+ if (out != NULL) {
+ if (x == 100)
+ fprintf(out, "%d\n", x);
+ else
+ fprintf(out, "%d..", x);
}
- fprintf(out, "GRASS_INFO_PERCENT: %d\n", x);
- fflush(out);
}
- first = 0;
+ else { /* GUI */
+ if (out != NULL) {
+ if (first) {
+ fprintf(out, "\n");
+ }
+ fprintf(out, "GRASS_INFO_PERCENT: %d\n", x);
+ fflush(out);
+ }
+ first = 0;
+ }
}
}
}
-
if (x >= 100) {
- if (format == G_INFO_FORMAT_STANDARD) {
+ if (ext_percent) {
+ ext_percent(100);
+ }
+ else if (format == G_INFO_FORMAT_STANDARD) {
if (out != NULL) {
fprintf(out, "\n");
}
@@ -137,7 +143,6 @@
return 0;
}
-
/**
* \brief Reset G_percent() to 0%; do not add newline.
*
@@ -151,3 +156,25 @@
return 0;
}
+
+/**
+ * \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