015ccc7cef0fc95b1998f84c253feffc165d1c54
[m17n/libotf.git] / src / otferror.c
1 /* otferror.c -- Error handling.
2
3 Copyright (C) 2003, 2004
4   National Institute of Advanced Industrial Science and Technology (AIST)
5   Registration Number H15PRO167
6
7 This file is part of libotf.
8
9 Libotf is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published
11 by the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
13
14 Libotf is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
17 License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library, in a file named COPYING; if not,
21 write to the Free Software Foundation, Inc., 59 Temple Place, Suite
22 330, Boston, MA 02111-1307, USA.  */
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <config.h>
28
29 #include "otf.h"
30
31 static char error_message[1024];
32 int OTF_error;
33
34 static char *error_string[] =
35   {
36     "No error",
37     "Memory shortage",
38     "File error",
39     "Invalid table",
40     "CMAP drive",
41     "GDEF drive",
42     "GSUB drive",
43     "GPOS drive"
44   };
45
46 int
47 otf__error (int err, const char *fmt, const void *arg)
48 {
49   sprintf (error_message, "OTF-Error (%s): ", error_string[err]);
50   sprintf (error_message + strlen (error_message), fmt, arg);
51   OTF_error = err;
52   return 0;
53 }
54
55 void
56 OTF_perror (const char *prefix)
57 {
58   if (OTF_error == 0)
59     sprintf (error_message, "%s", error_string[0]);
60   if (prefix)
61     fprintf (stderr, "%s: %s\n", prefix, error_message);
62   else
63     fprintf (stderr, "%s\n", error_message);
64 }