Changeset 51466


Ignore:
Timestamp:
Apr 17, 2012 2:34:57 PM (4 years ago)
Author:
martinl
Message:

libgis: new verbosity level

GRASS_VERBOSE=-1 also discards error and warning messages
doxygen documentation for verbose.c updated

Location:
grass/trunk/lib/gis
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • grass/trunk/lib/gis/error.c

    r45826 r51466  
    4444/* static int (*error)() = 0; */
    4545static int (*ext_error) (const char *, int);    /* Roger Bivand 17 June 2000 */
    46 static int no_warn = 0;
    47 static int no_sleep = 1;
     46static int no_warn  = FALSE;
     47static int no_sleep = TRUE;
    4848
    4949static int grass_info_format;
     
    154154    busy = 1;
    155155
    156     va_start(ap, msg);
    157     vfprint_error(ERR, msg, ap);
    158     va_end(ap);
     156    if (G_verbose() > -1) {
     157        va_start(ap, msg);
     158        vfprint_error(ERR, msg, ap);
     159        va_end(ap);
     160    }
    159161
    160162    G__call_error_handlers();
     
    186188    va_list ap;
    187189
    188     if (no_warn)
     190    if (no_warn || G_verbose() < 0)
    189191        return;
    190192
  • grass/trunk/lib/gis/parser.c

    r51132 r51466  
    555555   
    556556    if (st->n_errors > 0) {
    557         if (G_verbose() > G_verbose_min())
    558             G_usage();
    559         fprintf(stderr, "\n");
    560         for (i = 0; i < st->n_errors; i++) {
    561             fprintf(stderr, "%s: %s\n", _("ERROR"), st->error[i]);
    562         }
     557        if (G_verbose() > -1) {
     558            if (G_verbose() > G_verbose_min())
     559                G_usage();
     560            fprintf(stderr, "\n");
     561            for (i = 0; i < st->n_errors; i++) {
     562                fprintf(stderr, "%s: %s\n", _("ERROR"), st->error[i]);
     563            }
     564        }
    563565        return -1;
    564566    }
     
    13311333                    if (found) {        /* found */
    13321334                        if (!st->overwrite && !over) {
    1333                             if (G_info_format() != G_INFO_FORMAT_GUI) {
    1334                                 fprintf(stderr,
    1335                                         _("ERROR: option <%s>: <%s> exists.\n"),
    1336                                         opt->key, opt->answers[i]);
    1337                             }
    1338                             else {
    1339                                 fprintf(stderr,
    1340                                         "GRASS_INFO_ERROR(%d,1): option <%s>: <%s> exists.\n",
    1341                                         getpid(), opt->key, opt->answers[i]);
    1342                                 fprintf(stderr, "GRASS_INFO_END(%d,1)\n",
    1343                                         getpid());
    1344                             }
    1345 
     1335                            if (G_verbose() > -1) {
     1336                                if (G_info_format() != G_INFO_FORMAT_GUI) {
     1337                                    fprintf(stderr,
     1338                                            _("ERROR: option <%s>: <%s> exists.\n"),
     1339                                            opt->key, opt->answers[i]);
     1340                                }
     1341                                else {
     1342                                    fprintf(stderr,
     1343                                            "GRASS_INFO_ERROR(%d,1): option <%s>: <%s> exists.\n",
     1344                                            getpid(), opt->key, opt->answers[i]);
     1345                                    fprintf(stderr, "GRASS_INFO_END(%d,1)\n",
     1346                                            getpid());
     1347                                }
     1348                            }
    13461349                            error = 1;
    13471350                        }
  • grass/trunk/lib/gis/verbose.c

    r34486 r51466  
    1 
    2 /**
    3  * \file verbose.c
     1/*!
     2 * \file lib/gis/verbose.c
    43 *
    5  * \brief GIS Library - Functions to check for GRASS_VERBOSE environment variable.
     4 * \brief GIS Library - Subroutines to manage verbosity level
     5 * (GRASS_VERBOSE environment variable)
    66 *
    7  * see also:
     7 * See also:
    88 *  - G_percent()
     9 *  - G_important_message()
    910 *  - G_message()
     11 *  - G_verbose_message()
    1012 *  - G_warning()
     13 *  - G_fatal_error()
    1114 *
    12  * (C) 2001-2008 by the GRASS Development Team
     15 * (C) 2001-2008, 2012 by the GRASS Development Team
    1316 *
    1417 * This program is free software under the GNU General Public License
     
    1619 *
    1720 * \author Jachym Cepicky - jachym.cepicky at gmail.com
    18  *
    19  * \date 2006-2008
    2021 */
    2122
     
    2425#include <grass/gis.h>
    2526
    26 #define MAXLEVEL 3
     27#define MAXLEVEL 3 /* verbose */
    2728#define STDLEVEL 2
    28 #define MINLEVEL 0
     29#define MINLEVEL 0 /* quiet */
    2930
    30 static int initialized;
    31 static int verbose;     /* current verbosity level */
     31static struct state {
     32    int initialized;
     33    int verbose;       /* current verbosity level */
     34} state;
    3235
     36static struct state *st = &state;
    3337
    34 /**
     38/*!
    3539 * \brief Get current verbosity level.
    3640 *
    37  * Currently, there are 4 levels of verbosity.
     41 * Currently, there are 5 levels of verbosity (see return codes)
    3842 *
    39  * \return 0 - module should print nothing but errors and warnings
    40  *              (G_fatal_error, G_warning). Triggered by "--q" or "--quiet".
    41  * \return 1 - module will print progress information (G_percent)
    42  * \return 2 - module will print all messages (G_message)
    43  * \return 3 - module will be very verbose. Triggered by "--v" or "--verbose".
     43 * \return -1 - nothing will be printed (also errors and warnings will be also discarded)
     44 * \return  0 - nothing will be printed except of errors and warnings
     45 *              (G_fatal_error(), G_warning()). Triggered by "--q" or "--quiet".
     46 * \return  1 - only progress information (G_percent()) and important messages (G_important_message()) will be printed
     47 * \return  2 - all messages (G_message() and G_important_message()) will be printed
     48 * \return  3 - also verbose messages (G_verbose_message()) will be printed. Triggered by "--v" or "--verbose".
    4449 */
    45 
    4650int G_verbose(void)
    4751{
    48     const char *verstr;         /* string for GRASS_VERBOSE content */
     52    const char *verstr;         /* string for GRASS_VERBOSE content */
    4953
    50     if (G_is_initialized(&initialized))
    51         return verbose;
     54    if (G_is_initialized(&(st->initialized)))
     55        return st->verbose;
    5256
    5357    /* verbose not defined -> get it from env. */
    5458    verstr = getenv("GRASS_VERBOSE");
    55     verbose = verstr ? atoi(verstr) : STDLEVEL;
     59    st->verbose = verstr ? atoi(verstr) : STDLEVEL;
    5660
    57     G_initialize_done(&initialized);
     61    G_initialize_done(&(st->initialized));
    5862
    59     return verbose;
     63    return st->verbose;
    6064}
    6165
    62 
    63 /**
     66/*!
    6467 * \brief Get max verbosity level.
    6568 *
    6669 * \return max verbosity level
    6770 */
    68 
    6971int G_verbose_max(void)
    7072{
     
    7274}
    7375
    74 
    75 /**
     76/*!
    7677 * \brief Get standard verbosity level.
    7778 *
    7879 * \return standard verbosity level
    7980 */
    80 
    8181int G_verbose_std(void)
    8282{
     
    8484}
    8585
    86 
    87 /**
     86/*!
    8887 * \brief Get min verbosity level.
    8988 *
    9089 * \return min verbosity level
    9190 */
    92 
    9391int G_verbose_min(void)
    9492{
     
    9694}
    9795
    98 /**
     96/*!
    9997 * \brief Set verbosity level.
    10098 *
    101  * \param level: new verbosity level
     99 * - -1 - nothing will be printed (also errors and warnings will be also discarded)
     100 * -  0 - nothing will be printed except of errors and warnings
     101 *              (G_fatal_error(), G_warning()). Triggered by "--q" or "--quiet".
     102 * -  1 - only progress information (G_percent()) and important messages (G_important_message()) will be printed
     103 * -  2 - all messages (G_message() and G_important_message()) will be printed
     104 * -  3 - also verbose messages (G_verbose_message()) will be printed. Triggered by "--v" or "--verbose".
    102105 *
    103  * \return 0 - failed (verbosity level untouched)
    104  * \return 1 - success
     106 * \param level new verbosity level (-1,0,1,2,3)
     107 *
     108 * \return 0 on invalid verbosity level (verbosity level untouched)
     109 * \return 1 on success
    105110 */
    106 
    107111int G_set_verbose(int level)
    108112{
    109     if (level >= MINLEVEL && level <= MAXLEVEL) {
    110         verbose = level;
    111         return 1;
     113    if (level == -1 || (level >= MINLEVEL && level <= MAXLEVEL)) {
     114        st->verbose = level;
     115        return 1;
    112116    }
    113117
Note: See TracChangeset for help on using the changeset viewer.