~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/errmsg_stderr/errmsg_stderr.cc

  • Committer: Monty Taylor
  • Date: 2008-08-01 22:33:44 UTC
  • mto: (236.1.42 codestyle)
  • mto: This revision was merged to the branch mainline in revision 261.
  • Revision ID: monty@inaugust.com-20080801223344-vzhlflfmtijp1imv
First pass at gettexizing the error messages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Mark Atwood
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
 
#include <config.h>
21
 
#include <drizzled/plugin/error_message.h>
22
 
#include <drizzled/gettext.h>
23
 
#include <drizzled/plugin.h>
24
 
 
25
 
#include <stdio.h>  /* for vsnprintf */
26
 
#include <stdarg.h>  /* for va_list */
27
 
#include <unistd.h>  /* for write(2) */
28
 
 
29
 
using namespace drizzled;
30
 
 
31
 
/* todo, make this dynamic as needed */
32
 
#define MAX_MSG_LEN 8192
33
 
 
34
 
class Error_message_stderr : public plugin::ErrorMessage
35
 
{
36
 
public:
37
 
  Error_message_stderr()
38
 
   : plugin::ErrorMessage("Error_message_stderr") {}
39
 
  virtual bool errmsg(error::level_t , const char *format, va_list ap)
40
 
  {
41
 
    char msgbuf[MAX_MSG_LEN];
42
 
    int prv, wrv;
43
 
 
44
 
    prv= vsnprintf(msgbuf, MAX_MSG_LEN, format, ap);
45
 
    if (prv < 0) return true;
46
 
 
47
 
    /* a single write has a OS level thread lock
48
 
       so there is no need to have mutexes guarding this write,
49
 
    */
50
 
    wrv= write(fileno(stderr), msgbuf, prv);
51
 
    fputc('\n', stderr);
52
 
    if ((wrv < 0) || (wrv != prv))
53
 
      return true;
54
 
 
55
 
    return false;
56
 
  }
57
 
};
58
 
 
59
 
static Error_message_stderr *handler= NULL;
60
 
static int errmsg_stderr_plugin_init(module::Context &context)
61
 
{
62
 
  handler= new Error_message_stderr();
63
 
  context.add(handler);
64
 
 
65
 
  return 0;
66
 
}
67
 
 
68
 
DRIZZLE_DECLARE_PLUGIN
69
 
{
70
 
  DRIZZLE_VERSION_ID,
71
 
  "errmsg_stderr",
72
 
  "0.1",
73
 
  "Mark Atwood <mark@fallenpegasus.com>",
74
 
  N_("Error Messages to stderr"),
75
 
  PLUGIN_LICENSE_GPL,
76
 
  errmsg_stderr_plugin_init,
77
 
  NULL, /* depends */
78
 
  NULL
79
 
}
80
 
DRIZZLE_DECLARE_PLUGIN_END;