2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * COMPONENT_NAME: austext
26 * FUNCTIONS: austext_dopen
31 * (C) COPYRIGHT International Business Machines Corp. 1994,1995
33 * Licensed Materials - Property of IBM
34 * US Government Users Restricted Rights - Use, duplication or
35 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
37 /*************************** AUSDOPEN.C **************************
38 * $XConsortium: ausdopen.c /main/6 1996/08/12 13:17:32 cde-ibm $
40 * Austext_dopen() performs vista d_open() for an AusText database.
41 * Optionally sets vista page cache size, renames the files,
42 * opens the database, and optionally reads the dbrec.
43 * Intended to be used by offline programs like cravel, cborodin,
44 * and various utilities. Similar to opendblk.c.
47 * Revision 2.3 1995/10/25 22:22:45 miker
50 * Revision 2.2 1995/10/19 20:20:51 miker
51 * Deleted all RENFILE calls--database files no longer have to be renamed.
53 * Revision 2.1 1995/09/22 19:04:52 miker
54 * Freeze DtSearch 0.1, AusText 2.1.8
56 * Revision 1.5 1995/08/31 21:53:28 miker
57 * Minor changes for DtSearch.
59 * Revision 1.4 1995/05/30 18:19:21 miker
60 * write all err msgs to aa_stderr (write_msg) rather than stdout.
65 #define PROGNAME "AUSDOPEN"
68 /****************************************/
72 /****************************************/
73 /* dbname: 1 - 8 char database name.
74 * path: Optional path prefix for .dbd file.
75 * If NULL is passed, default is vista
76 * default (current working directory).
77 * d2xpath: Used only for mrclean; should be NULL for all other callers.
78 * Specifies path prefix for rename of d2x files only.
79 * cache: Optional vista paging size.
80 * If zero is passed, default is global CACHE_SIZE.
81 * If < 16 specified, silently adjusted up to minimum 16.
82 * If cache specified is not a power of 2,
83 * cache adjusted upward to nearest power of 2.
84 * dbrec: If NULL is passed, dbrec is not read. Otherwise
85 * database's dbrec is read into passed buffer.
87 * RETURNS: TRUE if all went well.
88 * FALSE and writes error msg to ausapi_msglist if could not open.
89 * (vista abort prints out its own error messages).
101 char sprintbuf[2048];
102 char *d2xptr, *ptr, *src;
105 if (dbname == NULL) {
107 sprintf (sprintbuf, catgets (dtsearch_catd, 13, 348,
108 "%s Invalid database name '%s'."),
109 PROGNAME"348", NULLORSTR(dbname));
110 DtSearchAddMessage (sprintbuf);
117 /* Test cache, silently rounding up to nearest power of 2.
118 * 2^4 = 16 = minimum cache. 2^12 = 4096 = maximum cache.
123 for (i = 4; i < 12; i++)
129 /* If mrclean needs special d2x renames, build them now.
130 * (d2xptr is where the ".d2x" extensions will be copied.)
134 for (i = 0; i < sizeof (d2xbuf) - 14; i++) {
137 *d2xptr++ = d2xpath[i];
139 if (i > 0 && *(d2xptr - 1) != LOCAL_SLASH)
140 *d2xptr++ = LOCAL_SLASH;
146 /* Copy path, if any, to name buffer leaving room for the slash
147 * which the caller may not have originally specified,
148 * the 8 char database name, the 3 char file name extensions,
149 * and the terminating \0. Then set 'ptr' to the place
150 * where the dbdname should be appended.
154 for (i = 0; i < sizeof (dbdbuf) - 14; i++) {
159 if (i > 0 && *(ptr - 1) != LOCAL_SLASH)
160 *ptr++ = LOCAL_SLASH;
163 /* Now concatenate the dbname and set ptr to where
164 * the file name extensions should go.
170 /* Specify the cache size and open the database.
171 * I use the original d_open() call so I can print
172 * a good error msg if it fails.
174 *ptr = 0; /* no extension used for .dbd file in OPEN */
175 SETPAGES (PROGNAME "283", cache, 4);
176 d_open (dbdbuf, "o");
177 if (db_status != S_OKAY) {
178 sprintf (sprintbuf, catgets (dtsearch_catd, 13, 379,
179 "%s Could not open database '%s':\n %s."),
180 PROGNAME"379", dbdbuf, vista_msg (PROGNAME"379"));
181 DtSearchAddMessage (sprintbuf);
185 /* From here on, emergency exits MUST close the database. */
186 austext_exit_dbms = (void (*) (int)) d_close;
188 /* If requested, read the dbrec into caller's buffer. */
190 RECFRST (PROGNAME "285", OR_DBREC, 0); /* seqtl retrieval */
191 if (db_status != S_OKAY) {
194 PROGNAME "289 Database '%s' has not been initialized.",
196 DtSearchAddMessage (sprintbuf);
199 RECREAD (PROGNAME "302", dbrec, 0);
200 if (db_status != S_OKAY)
202 swab_dbrec (dbrec, NTOH);
206 } /* austext_dopen() */
208 /*************************** AUSDOPEN.C **************************/