Update gnulib files.
[shishi.git] / db / setup.c
blob313930ff1c74b6900be0d53f114ebb2f65b3338e
1 /* init.c --- Initialization functions for the Shisa library.
2 * Copyright (C) 2002, 2003, 2006, 2007 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * Shishi is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Shishi; if not, see http://www.gnu.org/licenses or write
18 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
19 * Floor, Boston, MA 02110-1301, USA
23 #include "info.h"
25 /**
26 * shisa:
28 * Initializes the Shisa library. If this function fails, it may
29 * print diagnostic errors to stderr.
31 * Return value: Returns Shisa library handle, or %NULL on error.
32 **/
33 Shisa *
34 shisa (void)
36 Shisa *dbh;
38 dbh = xcalloc (1, sizeof (*dbh));
40 bindtextdomain (PACKAGE, LOCALEDIR);
41 textdomain (PACKAGE);
43 return dbh;
46 /**
47 * shisa_done:
48 * @handle: shisa handle as allocated by shisa().
50 * Deallocates the shisa library handle. The handle must not be used
51 * in any calls to shisa functions after this.
52 **/
53 void
54 shisa_done (Shisa * dbh)
56 _Shisa_db *db;
57 size_t i;
59 for (i = 0, db = dbh->dbs; i < dbh->ndbs; i++, db++)
60 db->backend->done (dbh, db->state);
62 if (dbh->dbs)
63 free (dbh->dbs);
65 free (dbh);
68 /**
69 * shisa_init:
70 * @dbh: pointer to library handle to be created.
72 * Create a Shisa library handle, using shisa(), and read the system
73 * configuration file from their default locations. The paths to the
74 * default system configuration file is decided at compile time
75 * ($sysconfdir/shisa.conf).
77 * The handle is allocated regardless of return values, except for
78 * SHISA_INIT_ERROR which indicates a problem allocating the handle.
79 * (The other error conditions comes from reading the files.)
81 * Return value: Returns %SHISA_OK iff successful.
82 **/
83 int
84 shisa_init (Shisa ** dbh)
86 return shisa_init_with_paths (dbh, NULL);
89 /**
90 * shisa_init_with_paths:
91 * @dbh: pointer to library handle to be created.
92 * @file: Filename of system configuration, or NULL.
94 * Create a Shisa library handle, using shisa(), and read the system
95 * configuration file indicated location (or the default location, if
96 * %NULL). The paths to the default system configuration file is
97 * decided at compile time ($sysconfdir/shisa.conf).
99 * The handle is allocated regardless of return values, except for
100 * SHISA_INIT_ERROR which indicates a problem allocating the handle.
101 * (The other error conditions comes from reading the files.)
103 * Return value: Returns %SHISA_OK iff successful.
106 shisa_init_with_paths (Shisa ** dbh, const char *file)
108 int rc;
110 if (!dbh || !(*dbh = shisa ()))
111 return SHISA_INIT_ERROR;
113 if (!file)
114 file = shisa_cfg_default_systemfile (*dbh);
116 rc = shisa_cfg_from_file (*dbh, file);
117 if (rc != SHISA_OK && rc != SHISA_CFG_NO_FILE)
118 return rc;
120 if ((*dbh)->ndbs == 0)
122 rc = shisa_cfg (*dbh, "db file " DEFAULTDBPATH);
123 if (rc != SHISA_OK)
124 return rc;
127 return SHISA_OK;