Pass lua_State arg to l_quvi_object_opts_croak_if_error
[libquvi.git] / src / api / errmsg.c
blobf59895a7254aaf896d09522f382a84b695560de9
1 /* libquvi
2 * Copyright (C) 2012-2013 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of libquvi <http://quvi.sourceforge.net/>.
6 * This library is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public
8 * License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General
17 * Public License along with this library. If not, see
18 * <http://www.gnu.org/licenses/>.
21 /** @file errmsg.c */
23 #include "config.h"
25 #include <glib/gi18n-lib.h>
26 #include <glib.h>
28 #include "quvi.h"
29 /* -- */
30 #include "_quvi_s.h"
32 static const gchar *msg[] =
34 N_("Not an error"),
35 N_("Operation aborted by a callback"),
36 N_("Could not find any subtitle export scripts in the path"),
37 N_("Could not find any subtitle scripts in the path"),
38 N_("Could not find any playlist scripts in the path"),
39 N_("Could not find any media scripts in the path"),
40 N_("Could not find any scan scripts in the path"),
41 N_("Could not find any the utility scripts in the path"),
42 N_("Operation aborted by the \"croak\" keyword"),
43 N_("An invalid argument to the function"),
44 N_("libgcrypt version mismatch"),
45 N_("Initialization of libproxy failed"),
46 N_("Initialization of libcurl failed"),
47 N_("Initialization of liblua failed")
50 static const gchar *inv_code_msg = N_("An invalid error code");
52 /** @return NULL-terminated error string
53 @note Do not attempt to free the returned string
54 @sa @ref getting_started
55 @ingroup convenience
57 const char *quvi_errmsg(quvi_t handle)
59 const gchar *s;
60 QuviError c;
61 _quvi_t q;
62 gint i;
64 if (handle == NULL)
65 return (g_dgettext(GETTEXT_PACKAGE, msg[QUVI_ERROR_INVALID_ARG]));
67 q = (_quvi_t) handle;
68 c = q->status.rc;
70 for (i=1; msg[i] != NULL; ++i);
72 s = msg[0];
74 if ( (gint) c<0 || c>i)
76 if (q->status.errmsg->len >0)
77 s = q->status.errmsg->str;
78 else
79 s = inv_code_msg;
81 else
82 s = msg[c];
84 return (g_dgettext(GETTEXT_PACKAGE, s));
87 /* vim: set ts=2 sw=2 tw=72 expandtab: */