Commit 1944269d authored by Vivien Kraus's avatar Vivien Kraus
Browse files

Introduce the function =tarot_set_datadir=

I don't want to break the API, so I won't touch =tarot_init=.  The
trick for the new function is that it should not make a difference if
you don't use newer API functions, so you can always link against
newer libtarot's.
parent 0ffab32d
......@@ -51,6 +51,7 @@ include git-check.am
AM_CPPFLAGS += \
-DLOCALEDIR="\"$(localedir)\"" \
-DSYSCONFDIR="\"$(sysconfdir)\"" \
-DDATADIR="\"$(datadir)\"" \
-DABS_TOP_SRCDIR="\"$(abs_top_srcdir)\"" \
-I. -I$(srcdir) \
-Ilib -I$(srcdir)/lib \
......
......@@ -690,6 +690,7 @@ int
main ()
{
/* The installation directories below are just an example. */
tarot_set_datadir ("/usr/local/share");
if (tarot_init ("/usr/local/share/locale") != 0)
{
fprintf (stderr, "Error: could not initialize libtarot.\n");
......@@ -702,10 +703,20 @@ main ()
}
#+END_SRC
#+attr_texinfo: :options {void} tarot_set_datadir (const char *@var{datadir})
#+begin_deftypefun
Define the directory where the libtarot will look up
architecture-independent data. This function should be called before
=tarot_init=, otherwise you will not be able to call functions that
were introduced after this function.
#+end_deftypefun
#+attr_texinfo: :options {int} tarot_init (const char *@var{localedir})
#+begin_deftypefun
Initialize libtarot. The localization will use the /localedir/
directory. Return 0 on success, or an error code.
directory. Return 0 on success, or an error code. This function
should be called before any other libtarot function, except the
functions to set up the installation directories.
#+end_deftypefun
#+attr_texinfo: :options {void} tarot_quit (void)
......
......@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: tarot 0.4.2.83-ebdc-dirty\n"
"Report-Msgid-Bugs-To: vivien@planete-kraus.eu\n"
"POT-Creation-Date: 2019-08-29 01:24+0200\n"
"POT-Creation-Date: 2019-09-01 19:10+0200\n"
"PO-Revision-Date: 2019-08-29 01:26+0200\n"
"Last-Translator: Vivien Kraus <vivien@planete-kraus.eu>\n"
"Language-Team: French\n"
......@@ -26,7 +26,7 @@ msgstr ""
"ERREUR : la variable d'environnement '%s' n'est pas définie. Essayez de "
"réinstaller le programme.\n"
#: src/tarot-app/main.vala:69 src/tarot-app/program_commons.c:47
#: src/tarot-app/main.vala:69 src/tarot-app/program_commons.c:48
#, c-format
msgid "ERROR: could not initialize libtarot.\n"
msgstr "ERREUR : impossible d'initialiser libtarot.\n"
......@@ -1237,19 +1237,19 @@ msgstr "- %s\n"
msgid "Error: invalid game.\n"
msgstr "Erreur : partie invalide.\n"
#: src/tarot-app/program_commons.c:157
#: src/tarot-app/program_commons.c:158
msgid "GiB"
msgstr "GiB"
#: src/tarot-app/program_commons.c:163
#: src/tarot-app/program_commons.c:164
msgid "MiB"
msgstr "MiB"
#: src/tarot-app/program_commons.c:169
#: src/tarot-app/program_commons.c:170
msgid "KiB"
msgstr "KiB"
#: src/tarot-app/program_commons.c:175
#: src/tarot-app/program_commons.c:176
msgid "B"
msgstr "B"
......
......@@ -28,11 +28,36 @@ static int libtarot_initialized = 0;
char *tarot_libtarot_program_name = PACKAGE_NAME;
static char *libtarot_localedir = NULL;
static char *libtarot_datadir = NULL;
static char *libtarot_pkgdatadir = NULL;
static void
tarot_set_localedir (const char *localedir)
{
free (libtarot_localedir);
libtarot_localedir = strdup (localedir);
}
void
tarot_set_datadir (const char *datadir)
{
free (libtarot_datadir);
free (libtarot_pkgdatadir);
libtarot_datadir = strdup (datadir);
libtarot_pkgdatadir = xmalloc (strlen (libtarot_datadir)
+ strlen ("/") + strlen (PACKAGE) + 1);
strcpy (libtarot_pkgdatadir, libtarot_datadir);
strcat (libtarot_pkgdatadir, "/");
strcat (libtarot_pkgdatadir, PACKAGE);
}
int
tarot_init (const char *localedir)
{
assert (libtarot_initialized == 0);
bindtextdomain (PACKAGE, localedir);
tarot_set_localedir (localedir);
bindtextdomain (PACKAGE, libtarot_localedir);
libtarot_initialized = 1;
return 0;
}
......
......@@ -40,6 +40,8 @@ extern "C"
{
#endif /* __cplusplus */
void tarot_set_datadir (const char *datadir);
int tarot_init (const char *localedir);
void tarot_quit (void);
......
......@@ -42,6 +42,7 @@ tarot_program_setup (void)
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
tarot_set_datadir (DATADIR);
if (tarot_init (LOCALEDIR) != 0)
{
fprintf (stderr, _ ("ERROR: could not initialize libtarot.\n"));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment