Go to the documentation of this file.00001
00017 #include <stdio.h>
00018 #include <grass/gis.h>
00019
00020
00021 static int prev = -1;
00022 static int first = 1;
00023
00024
00064 int G_percent(long n, long d, int s)
00065 {
00066 return (G_percent2(n, d, s, stderr));
00067 }
00068
00069
00084 int G_percent2(long n, long d, int s, FILE *out)
00085 {
00086 int x, format;
00087
00088 format = G_info_format();
00089
00090 x = (d <= 0 || s <= 0)
00091 ? 100 : (int)(100 * n / d);
00092
00093
00094 if (format == G_INFO_FORMAT_SILENT || G_verbose() < 1)
00095 return 0;
00096
00097 if (n <= 0 || n >= d || x > prev + s) {
00098 prev = x;
00099
00100 if (format == G_INFO_FORMAT_STANDARD) {
00101 if (out != NULL) {
00102 fprintf(out, "%4d%%\b\b\b\b\b", x);
00103 }
00104 }
00105 else {
00106 if (format == G_INFO_FORMAT_PLAIN) {
00107 if (out != NULL) {
00108 if (x == 100)
00109 fprintf(out, "%d\n", x);
00110 else
00111 fprintf(out, "%d..", x);
00112 }
00113 }
00114 else {
00115 if (out != NULL) {
00116 if (first) {
00117 fprintf(out, "\n");
00118 }
00119 fprintf(out, "GRASS_INFO_PERCENT: %d\n", x);
00120 fflush(out);
00121 }
00122 first = 0;
00123 }
00124 }
00125 }
00126
00127 if (x >= 100) {
00128 if (format == G_INFO_FORMAT_STANDARD) {
00129 if (out != NULL) {
00130 fprintf(out, "\n");
00131 }
00132 }
00133 prev = -1;
00134 first = 1;
00135 }
00136
00137 return 0;
00138 }
00139
00140
00147 int G_percent_reset(void)
00148 {
00149 prev = -1;
00150 first = 1;
00151
00152 return 0;
00153 }