[GRASS-SVN] r50441 - in grass/trunk: include/defs lib/db/dbmi_driver

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jan 25 09:02:21 EST 2012


Author: martinl
Date: 2012-01-25 06:02:21 -0800 (Wed, 25 Jan 2012)
New Revision: 50441

Added:
   grass/trunk/lib/db/dbmi_driver/d_error.c
Modified:
   grass/trunk/include/defs/dbmi.h
Log:
DBMI (driver): implement db_d_init/append/report_error (taken from DB drivers)


Modified: grass/trunk/include/defs/dbmi.h
===================================================================
--- grass/trunk/include/defs/dbmi.h	2012-01-25 12:05:53 UTC (rev 50440)
+++ grass/trunk/include/defs/dbmi.h	2012-01-25 14:02:21 UTC (rev 50441)
@@ -104,6 +104,9 @@
 int db_d_get_num_rows(void);
 int db_d_grant_on_table(void);
 int db_d_insert(void);
+void db_d_init_error(const char *);
+void db_d_append_error(const char *, ...);
+void db_d_report_error(void);
 dbDirent *db_dirent(const char *, int *);
 int db_d_list_databases(void);
 int db_d_list_indexes(void);

Added: grass/trunk/lib/db/dbmi_driver/d_error.c
===================================================================
--- grass/trunk/lib/db/dbmi_driver/d_error.c	                        (rev 0)
+++ grass/trunk/lib/db/dbmi_driver/d_error.c	2012-01-25 14:02:21 UTC (rev 50441)
@@ -0,0 +1,95 @@
+/*!
+  \file lib/db/dbmi_driver/d_error.c
+  
+  \brief DBMI Library (driver) - error reporting
+  
+  Taken from DB drivers.
+  
+  (C) 1999-2008, 2012 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 Joel Jones (CERL/UIUC)
+  \author Radim Blazek
+  \author Adopted for DBMI by Martin Landa <landa.martin at gmail.com>
+*/
+
+#include <string.h>
+#include <grass/dbmi.h>
+#include <grass/glocale.h>
+
+/* initialize the global struct */
+struct state {
+    char     *driver_name;
+    dbString *errMsg;
+} state;
+
+struct state *st = &state;
+
+static void init();
+
+/*!
+  \brief Init error message for DB driver
+  
+  Initialize prefix
+
+  \param name driver name (eg. "SQLite"))
+*/
+void db_d_init_error(const char *name)
+{
+    if (!st->errMsg) {
+	st->errMsg = (dbString *) G_malloc(sizeof(dbString));
+	db_init_string(st->errMsg);
+    }
+    
+    G_debug(1, "db_d_init_error(): %s", name);
+    
+    st->driver_name = G_malloc(strlen(name) + 1);
+    strcpy(st->driver_name, name);
+    init();
+}
+
+void init()
+{
+    db_set_string(st->errMsg, "");
+    db_d_append_error(_("DBMI-%s driver error:"), st->driver_name);
+    db_append_string(st->errMsg, "\n");
+}
+/*!
+  \brief Append error message for DB driver
+
+  \param frmt formatted message
+*/
+void db_d_append_error(const char *fmt, ...)
+{
+    FILE *fp = NULL;
+    char *work = NULL;
+    int count = 0;
+    va_list ap;
+
+    va_start(ap, fmt);
+    if ((fp = tmpfile())) {
+	count = vfprintf(fp, fmt, ap);
+	if (count >= 0 && (work = G_calloc(count + 1, 1))) {
+	    rewind(fp);
+	    fread(work, 1, count, fp);
+	    db_append_string(st->errMsg, work);
+	    G_free(work);
+	}
+	fclose(fp);
+    }
+    va_end(ap);
+}
+
+/*!
+  \brief Report error message for DB driver
+*/
+void db_d_report_error(void)
+{
+    db_append_string(st->errMsg, "\n");
+    db_error(db_get_string(st->errMsg));
+
+    init();
+}


Property changes on: grass/trunk/lib/db/dbmi_driver/d_error.c
___________________________________________________________________
Added: svn:mime-type
   + text/x-csrc
Added: svn:eol-style
   + native



More information about the grass-commit mailing list