Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / DtSearch / dtsrdbrec.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /*
24  *   COMPONENT_NAME: austext
25  *
26  *   FUNCTIONS: main
27  *              print_dbrec
28  *
29  *   ORIGINS: 27
30  *
31  *
32  *   (C) COPYRIGHT International Business Machines Corp. 1994,1995
33  *   All Rights Reserved
34  *   Licensed Materials - Property of IBM
35  *   US Government Users Restricted Rights - Use, duplication or
36  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
37  */
38 /************************* DTSRDBREC.C **************************
39  * $XConsortium: dtsrdbrec.c /main/8 1996/11/21 19:49:44 drk $
40  * January 1994.
41  * Prints out data in a dbrec system record in human readable form.
42  *
43  * $Log$
44  * Revision 2.4  1996/02/01  18:18:18  miker
45  * Added DtSrLaJPN2.  Deleted BETA definition.
46  *
47  * Revision 2.3  1995/10/25  19:49:12  miker
48  * Renamed from dbrec.c.  Added prolog.c.
49  *
50  * Log: dbrec.c,v
51  * Revision 2.2  1995/10/19  20:31:07  miker
52  * No longer necessary to rename d00 file.
53  * Database files may be read-only.
54  *
55  * Revision 2.1  1995/09/22  19:34:56  miker
56  * Freeze DtSearch 0.1, AusText 2.1.8
57  *
58  * Revision 1.12  1995/09/19  21:51:43  miker
59  * ifdef DTSEARCH, use DtSrVERSION instead of AUSAPI_VERSION in banner.
60  *
61  * Revision 1.11  1995/08/31  22:24:50  miker
62  * Added report of or_language and other minor changes for DtSearch.
63  * DtSearch executable (without semantic report) renamed dtsrdbrec.
64  */
65 #include "SearchP.h"
66
67 #define XOS_USE_NO_LOCKING
68 #define X_INCLUDE_TIME_H
69 #include <X11/Xos_r.h>
70
71 #define PROGNAME        "DTSRDBREC"
72 #define MS_misc         1
73 #define MS_dbrec        23
74
75 /**#define MAIN_PROGRAM ***/
76
77 /************************************************/
78 /*                                              */
79 /*                language_name                 */
80 /*                                              */
81 /************************************************/
82 static char    *language_name (int language_number)
83 {
84     switch (language_number) {
85         case DtSrLaENG:         return "ENGLISH (ASCII)";
86         case DtSrLaENG2:        return "ENGLISH (ISO Latin-1)";
87         case DtSrLaESP:         return "SPANISH";
88         case DtSrLaFRA:         return "FRENCH";
89         case DtSrLaITA:         return "ITALIAN";
90         case DtSrLaDEU:         return "GERMAN";
91         case DtSrLaJPN:         return "JAPANESE (AUTO COMPOUNDS)";
92         case DtSrLaJPN2:        return "JAPANESE (COMPOUNDS FROM LIST)";
93         default:                return "USER DEFINED LANGUAGE";
94     }
95 }
96
97 /************************************************/
98 /*                                              */
99 /*                 print_dbrec                  */
100 /*                                              */
101 /************************************************/
102 void            print_dbrec (char *dbname, struct or_dbrec * dbrec)
103 {
104     int             i;
105     char           *cptr;
106     int             blobs_are_possible = FALSE;
107
108     printf (catgets (dtsearch_catd, MS_dbrec, 1,
109             "---------- System Values for Database '%s' ----------\n"),
110         dbname);
111     printf (catgets (dtsearch_catd, MS_dbrec, 2,
112             "Schema version number (version) is '%s'.\n"),
113         dbrec->or_version);
114
115     printf (catgets (dtsearch_catd, MS_dbrec, 3,
116             "Maximum object key size (sizeof(objkey)) is %ld bytes.\n"),
117         DtSrMAX_DB_KEYSIZE);
118     if (ORD_USEHUGEKEYS & dbrec->or_dbflags)
119         printf (catgets (dtsearch_catd, MS_dbrec, 4,
120                 "Optional 'Huge' keys enabled.\n"));
121
122     printf (catgets (dtsearch_catd, MS_dbrec, 12,
123             "Maximum length of an abstract string (abstrsz) is %d.\n"),
124         dbrec->or_abstrsz);
125     if (dbrec->or_abstrsz == 0)
126         puts (catgets (dtsearch_catd, MS_dbrec, 14,
127                 "  (Abstracts are not used in this database)."));
128     else {
129         /*
130          * if they CAN be compressed, say whether or not they
131          * actually are 
132          */
133         if (dbrec->or_hufid != 0L)
134             printf (catgets (dtsearch_catd, MS_dbrec, 20,
135                     "Abstracts are %scompressed.\n"),
136                 (ORC_COMPABSTR & dbrec->or_compflags) ? "" : "not ");
137     }
138
139     printf (catgets (dtsearch_catd, MS_dbrec, 22,
140             "Parsing language is number %d, %s.\n"),
141         dbrec->or_language, language_name(dbrec->or_language));
142
143     printf (catgets (dtsearch_catd, MS_dbrec, 24,
144             "Minimum word length (minwordsz) is %d.\n"),
145         dbrec->or_minwordsz);
146
147     printf (catgets (dtsearch_catd, MS_dbrec, 26,
148             "Maximum word length (maxwordsz) is %d.\n"),
149         dbrec->or_maxwordsz);
150
151     printf (catgets (dtsearch_catd, MS_dbrec, 30,
152             "Number of .d00 slots per object (recslots) is %d.\n"),
153         dbrec->or_recslots);
154
155     printf (catgets (dtsearch_catd, MS_dbrec, 36,
156             "  (Maximum number of database objects is %ld).\n"),
157         0xffffffL / (long) dbrec->or_recslots);
158
159     printf (catgets (dtsearch_catd, MS_dbrec, 40,
160             "Huffman compression table id (hufid) is %ld.\n"),
161         dbrec->or_hufid);
162     if (dbrec->or_hufid == 0L)
163         puts (catgets (dtsearch_catd, MS_dbrec, 42,
164                 "  (Compression is disabled in this database)."));
165     if (dbrec->or_hufid == -1L)
166         puts (catgets (dtsearch_catd, MS_dbrec, 44,
167                 "  (Specific compression table is not yet determined)."));
168
169     blobs_are_possible = FALSE;
170     switch (dbrec->or_dbaccess) {
171         case ORA_VARIES:
172             puts (catgets (dtsearch_catd, MS_dbrec, 50,
173                 "Engine accessibility to data may vary from object to object."));
174             blobs_are_possible = TRUE;
175             break;
176         case ORA_NOTAVAIL:
177             puts (catgets (dtsearch_catd, MS_dbrec, 54,
178                 "Data objects are not directly accessible from the engine."));
179             break;
180         case ORA_BLOB:
181             puts (catgets (dtsearch_catd, MS_dbrec, 56,
182                 "Data objects are stored internally as blobs."));
183             blobs_are_possible = TRUE;
184             break;
185         case ORA_REFBLOB:
186             puts (catgets (dtsearch_catd, MS_dbrec, 60,
187                 "Only server file references to objects are stored in the blobs."));
188             break;
189         case ORA_CREFBLOB:
190             puts (catgets (dtsearch_catd, MS_dbrec, 64,
191                 "Only client file references to objects are stored in the blobs."));
192             break;
193         case ORA_REFKEY:
194             puts (catgets (dtsearch_catd, MS_dbrec, 68,
195                 "Object keys are server file references to the objects."));
196             break;
197         case ORA_CREFKEY:
198             puts (catgets (dtsearch_catd, MS_dbrec, 72,
199                 "Object keys are client file references to the objects."));
200             break;
201         case ORA_REFHUGEKEY:
202             puts (catgets (dtsearch_catd, MS_dbrec, 74,
203                 "Server file references to objects are "
204                 "stored in the 'huge' keys."));
205             break;
206         case ORA_REFABSTR:
207             puts (catgets (dtsearch_catd, MS_dbrec, 80,
208                 "Server file references to objects are stored in the abstracts."));
209             break;
210         case ORA_CREFABSTR:
211             puts (catgets (dtsearch_catd, MS_dbrec, 86,
212                 "Client file references to objects are stored in the abstracts."));
213             break;
214         default:
215             printf (catgets (dtsearch_catd, MS_dbrec, 90,
216                 "Error: meaning of or_dbaccess value (%hd) is unknown.\n"),
217                 dbrec->or_dbaccess);
218             blobs_are_possible = TRUE;
219             break;
220     }   /* end or_dbaccess switch */
221
222     if (blobs_are_possible) {
223         /*
224          * if they CAN be compressed, say whether or not they
225          * actually are 
226          */
227         if (dbrec->or_hufid != 0L)
228             printf (catgets (dtsearch_catd, MS_dbrec, 100,
229                     "Repository blobs are %scompressed.\n"),
230                 (ORC_COMPBLOB & dbrec->or_compflags) ? "" : "not ");
231     }
232     else
233         puts (catgets (dtsearch_catd, MS_dbrec, 110,
234                 "Repository blobs are not used in this database."));
235
236     printf (catgets (dtsearch_catd, MS_dbrec, 120,
237             "Database switches (dbflags) are 0x%lx:\n"),
238         dbrec->or_dbflags);
239
240     printf (catgets (dtsearch_catd, MS_dbrec, 130,
241             "  Inverted index %s words exactly as parsed.\n"),
242         (ORD_XWORDS & dbrec->or_dbflags) ?
243         catgets (dtsearch_catd, MS_dbrec, 124, "INCLUDES") :
244         catgets (dtsearch_catd, MS_dbrec, 125, "EXCLUDES"));
245
246     printf (catgets (dtsearch_catd, MS_dbrec, 140,
247             "  Inverted index %s word stems.\n"),
248         (ORD_XSTEMS & dbrec->or_dbflags) ?
249         catgets (dtsearch_catd, MS_dbrec, 124, "INCLUDES") :
250         catgets (dtsearch_catd, MS_dbrec, 125, "EXCLUDES"));
251
252     printf (catgets (dtsearch_catd, MS_dbrec, 160,
253             "  Use of optional 'huge' keys is %s.\n"),
254         (ORD_USEHUGEKEYS & dbrec->or_dbflags) ?
255         catgets (dtsearch_catd, MS_dbrec, 126, "ENABLED") :
256         catgets (dtsearch_catd, MS_dbrec, 127, "DISABLED"));
257
258     printf (catgets (dtsearch_catd, MS_dbrec, 162,
259             "  Mark-for-deletion is %s.\n"),
260         (ORD_NOMARKDEL & dbrec->or_dbflags) ?
261         catgets (dtsearch_catd, MS_dbrec, 127, "DISABLED") :
262         catgets (dtsearch_catd, MS_dbrec, 126, "ENABLED"));
263
264     printf (catgets (dtsearch_catd, MS_dbrec, 164,
265             "  Appendable user notes are %s.\n"),
266         (ORD_NONOTES & dbrec->or_dbflags) ?
267         catgets (dtsearch_catd, MS_dbrec, 127, "DISABLED") :
268         catgets (dtsearch_catd, MS_dbrec, 126, "ENABLED"));
269
270     printf (catgets (dtsearch_catd, MS_dbrec, 170,
271             "  Text characters are %s wide.\n"),
272         (ORD_WIDECHAR & dbrec->or_dbflags) ?
273         catgets (dtsearch_catd, MS_dbrec, 172, "MULTIPLE bytes") :
274         catgets (dtsearch_catd, MS_dbrec, 174, "a SINGLE byte"));
275
276     printf (catgets (dtsearch_catd, MS_dbrec, 200,
277             "Current number of database objects (reccount) is %ld.\n"),
278         dbrec->or_reccount);
279
280     printf (catgets (dtsearch_catd, MS_dbrec, 210,
281             "Last currently used slot number (maxdba) is %ld.\n"),
282         dbrec->or_maxdba);
283
284     for (i = 58; i > 0; i--)
285         putchar ('-');
286     putchar ('\n');
287     return;
288 }  /* print_dbrec() */
289
290
291 #ifdef MAIN_PROGRAM
292 #include <locale.h>
293 #include <fcntl.h>
294 #include "vista.h"
295 /************************************************/
296 /*                                              */
297 /*                    main                      */
298 /*                                              */
299 /************************************************/
300 int     main (int argc, char *argv[])
301 {
302     struct or_dbrec dbrec;
303     char            renamebuf[256];
304     time_t          now;
305     struct tm       *time_ptr;
306     _Xltimeparams   localtime_buf;
307
308     aa_argv0 = argv[0];
309     setlocale (LC_ALL, "");
310     dtsearch_catd = catopen (FNAME_DTSRCAT, 0);
311     austools_catd = catopen (FNAME_AUSCAT, 0);
312
313     time (&now);
314     time_ptr = _XLocaltime(&now, localtime_buf);
315     strftime (renamebuf, sizeof (renamebuf),
316         catgets (dtsearch_catd, MS_misc, 22, "%A, %b %d %Y, %I:%M %p"),
317         time_ptr);
318     printf (catgets (dtsearch_catd, MS_misc, 23,
319         "%s: Version %s.  Run %s.\n"),
320         aa_argv0,
321         DtSrVERSION,
322         renamebuf);
323
324     if (argc < 2) {
325         printf (catgets (dtsearch_catd, MS_dbrec, 310,
326                 "USAGE: %s <dbname>\n"), aa_argv0);
327         return 2;
328     }
329     sprintf (renamebuf, "%s.d00", argv[1]);
330     db_oflag = O_RDONLY;        /* db files may be read-only */
331     d_open (argv[1], "o");
332     if (db_status != S_OKAY) {
333         printf (catgets (dtsearch_catd, MS_dbrec, 330,
334                 "Could not open '%s' database.\n%s\n"),
335                 argv[1], vista_msg(PROGNAME"293"));
336         return 3;
337     }
338     d_recfrst (OR_DBREC, 0);
339     if (db_status != S_OKAY) {
340         printf (catgets (dtsearch_catd, MS_dbrec, 340,
341                 "No dbrec record in database '%s'.\n"),
342                 argv[1]);
343         return 4;
344     }
345     d_recread (&dbrec, 0);
346     if (db_status != S_OKAY) {
347         printf (catgets (dtsearch_catd, MS_dbrec, 350,
348                 "Can't read dbrec record in database '%s'.\n%s\n"),
349                 argv[1], vista_msg(PROGNAME"306"));
350         return 5;
351     }
352     swab_dbrec (&dbrec, NTOH);
353     print_dbrec (argv[1], &dbrec);
354     return 0;
355 }  /* main() */
356
357 #endif
358
359 /************************* DTSRDBREC.C **************************/