~ubuntu-branches/ubuntu/wily/grass/wily

« back to all changes in this revision

Viewing changes to lib/db/dbmi_driver/d_error.c

Tags: 7.0.0~rc1+ds1-1~exp1
* New upstream release candidate.
* Repack upstream tarball, remove precompiled Python objects.
* Add upstream metadata.
* Update gbp.conf and Vcs-Git URL to use the experimental branch.
* Update watch file for GRASS 7.0.
* Drop build dependencies for Tcl/Tk, add build dependencies:
  python-numpy, libnetcdf-dev, netcdf-bin, libblas-dev, liblapack-dev
* Update Vcs-Browser URL to use cgit instead of gitweb.
* Update paths to use grass70.
* Add configure options: --with-netcdf, --with-blas, --with-lapack,
  remove --with-tcltk-includes.
* Update patches for GRASS 7.
* Update copyright file, changes:
  - Update copyright years
  - Group files by license
  - Remove unused license sections
* Add patches for various typos.
* Fix desktop file with patch instead of d/rules.
* Use minimal dh rules.
* Bump Standards-Version to 3.9.6, no changes.
* Use dpkg-maintscript-helper to replace directories with symlinks.
  (closes: #776349)
* Update my email to use @debian.org address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*!
 
2
  \file lib/db/dbmi_driver/d_error.c
 
3
  
 
4
  \brief DBMI Library (driver) - error reporting
 
5
  
 
6
  Taken from DB drivers.
 
7
  
 
8
  (C) 1999-2008, 2012 by the GRASS Development Team
 
9
  
 
10
  This program is free software under the GNU General Public
 
11
  License (>=v2). Read the file COPYING that comes with GRASS
 
12
  for details.
 
13
  
 
14
  \author Joel Jones (CERL/UIUC)
 
15
  \author Radim Blazek
 
16
  \author Adopted for DBMI by Martin Landa <landa.martin@gmail.com>
 
17
*/
 
18
 
 
19
#include <string.h>
 
20
#include <grass/dbmi.h>
 
21
#include <grass/glocale.h>
 
22
 
 
23
/* initialize the global struct */
 
24
struct error_state {
 
25
    char     *driver_name;
 
26
    dbString *errMsg;
 
27
};
 
28
 
 
29
static struct error_state state;
 
30
static struct error_state *st = &state;
 
31
 
 
32
static void init()
 
33
{
 
34
    db_set_string(st->errMsg, "");
 
35
    db_d_append_error(_("DBMI-%s driver error:"), st->driver_name);
 
36
    db_append_string(st->errMsg, "\n");
 
37
}
 
38
 
 
39
 
 
40
/*!
 
41
  \brief Init error message for DB driver
 
42
  
 
43
  Initialize prefix
 
44
 
 
45
  \param name driver name (eg. "SQLite"))
 
46
*/
 
47
void db_d_init_error(const char *name)
 
48
{
 
49
    if (!st->errMsg) {
 
50
        st->errMsg = (dbString *) G_malloc(sizeof(dbString));
 
51
        db_init_string(st->errMsg);
 
52
    }
 
53
    
 
54
    G_debug(1, "db_d_init_error(): %s", name);
 
55
    
 
56
    st->driver_name = G_malloc(strlen(name) + 1);
 
57
    strcpy(st->driver_name, name);
 
58
    init();
 
59
}
 
60
 
 
61
/*!
 
62
  \brief Append error message for DB driver
 
63
 
 
64
  \param fmt formatted message
 
65
*/
 
66
void db_d_append_error(const char *fmt, ...)
 
67
{
 
68
    FILE *fp = NULL;
 
69
    char *work = NULL;
 
70
    int count = 0;
 
71
    va_list ap;
 
72
 
 
73
    va_start(ap, fmt);
 
74
    if ((fp = tmpfile())) {
 
75
        count = vfprintf(fp, fmt, ap);
 
76
        if (count >= 0 && (work = G_calloc(count + 1, 1))) {
 
77
            rewind(fp);
 
78
            fread(work, 1, count, fp);
 
79
            db_append_string(st->errMsg, work);
 
80
            G_free(work);
 
81
        }
 
82
        fclose(fp);
 
83
    }
 
84
    va_end(ap);
 
85
}
 
86
 
 
87
/*!
 
88
  \brief Report error message for DB driver
 
89
*/
 
90
void db_d_report_error(void)
 
91
{
 
92
    db_append_string(st->errMsg, "\n");
 
93
    db_error(db_get_string(st->errMsg));
 
94
 
 
95
    init();
 
96
}