1 /* Implementation of the messaging API to applications.
2 Copyright (C) 2001 The Genes Development Team
3 This file is part of the Gedcom parser library.
4 Contributed by Peter Verthez <Peter.Verthez@advalvas.be>, 2001.
6 The Gedcom parser library is free software; you can redistribute it
7 and/or modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The Gedcom parser library is distributed in the hope that it will be
12 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the Gedcom parser library; if not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 #include "gedcom_internal.h"
27 #define INITIAL_BUF_SIZE 256
28 char *mess_buffer = NULL;
31 Gedcom_msg_handler msg_handler = NULL;
33 void gedcom_set_message_handler(Gedcom_msg_handler func)
38 void reset_mess_buffer()
40 if (mess_buffer != NULL)
41 mess_buffer[0] = '\0';
44 void init_mess_buffer()
46 if (mess_buffer == NULL) {
47 mess_buffer = (char *)malloc(INITIAL_BUF_SIZE);
48 mess_buffer[0] = '\0';
49 bufsize = INITIAL_BUF_SIZE;
53 int safe_buf_vappend(char *s, va_list ap)
58 len = strlen(mess_buffer);
60 char *buf_ptr = mess_buffer + len;
61 int rest_size = bufsize - len;
63 res = vsnprintf(buf_ptr, rest_size, s, ap);
65 if (res > -1 && res < rest_size) {
70 mess_buffer = realloc(mess_buffer, bufsize);
76 int safe_buf_append(char *s, ...)
82 res = safe_buf_vappend(s, ap);
88 int gedcom_message(char* s, ...)
95 res = safe_buf_vappend(s, ap);
98 (*msg_handler)(MESSAGE, mess_buffer);
102 int gedcom_warning(char* s, ...)
108 safe_buf_append(_("Warning on line %d: "), line_no);
110 res = safe_buf_vappend(s, ap);
113 (*msg_handler)(WARNING, mess_buffer);
118 int gedcom_error(char* s, ...)
124 safe_buf_append(_("Error on line %d: "), line_no);
126 res = safe_buf_vappend(s, ap);
129 (*msg_handler)(ERROR, mess_buffer);