Link with C++ linker
[oweals/cde.git] / cde / programs / dtsr / 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/6 1996/08/12 12:18:12 cde-ibm $
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 PROGNAME        "DTSRDBREC"
68 #define MS_misc         1
69 #define MS_dbrec        23
70
71 /**#define MAIN_PROGRAM ***/
72
73 /************************************************/
74 /*                                              */
75 /*                language_name                 */
76 /*                                              */
77 /************************************************/
78 static char    *language_name (int language_number)
79 {
80     switch (language_number) {
81         case DtSrLaENG:         return "ENGLISH (ASCII)";
82         case DtSrLaENG2:        return "ENGLISH (ISO Latin-1)";
83         case DtSrLaESP:         return "SPANISH";
84         case DtSrLaFRA:         return "FRENCH";
85         case DtSrLaITA:         return "ITALIAN";
86         case DtSrLaDEU:         return "GERMAN";
87         case DtSrLaJPN:         return "JAPANESE (AUTO COMPOUNDS)";
88         case DtSrLaJPN2:        return "JAPANESE (COMPOUNDS FROM LIST)";
89         default:                return "USER DEFINED LANGUAGE";
90     }
91 }
92
93 /************************************************/
94 /*                                              */
95 /*                 print_dbrec                  */
96 /*                                              */
97 /************************************************/
98 void            print_dbrec (char *dbname, struct or_dbrec * dbrec)
99 {
100     int             i;
101     char           *cptr;
102     int             blobs_are_possible = FALSE;
103
104     printf (catgets (dtsearch_catd, MS_dbrec, 1,
105             "---------- System Values for Database '%s' ----------\n"),
106         dbname);
107     printf (catgets (dtsearch_catd, MS_dbrec, 2,
108             "Schema version number (version) is '%s'.\n"),
109         dbrec->or_version);
110
111     printf (catgets (dtsearch_catd, MS_dbrec, 3,
112             "Maximum object key size (sizeof(objkey)) is %ld bytes.\n"),
113         DtSrMAX_DB_KEYSIZE);
114     if (ORD_USEHUGEKEYS & dbrec->or_dbflags)
115         printf (catgets (dtsearch_catd, MS_dbrec, 4,
116                 "Optional 'Huge' keys enabled.\n"));
117
118     printf (catgets (dtsearch_catd, MS_dbrec, 12,
119             "Maximum length of an abstract string (abstrsz) is %d.\n"),
120         dbrec->or_abstrsz);
121     if (dbrec->or_abstrsz == 0)
122         puts (catgets (dtsearch_catd, MS_dbrec, 14,
123                 "  (Abstracts are not used in this database)."));
124     else {
125         /*
126          * if they CAN be compressed, say whether or not they
127          * actually are 
128          */
129         if (dbrec->or_hufid != 0L)
130             printf (catgets (dtsearch_catd, MS_dbrec, 20,
131                     "Abstracts are %scompressed.\n"),
132                 (ORC_COMPABSTR & dbrec->or_compflags) ? "" : "not ");
133     }
134
135     printf (catgets (dtsearch_catd, MS_dbrec, 22,
136             "Parsing language is number %d, %s.\n"),
137         dbrec->or_language, language_name(dbrec->or_language));
138
139     printf (catgets (dtsearch_catd, MS_dbrec, 24,
140             "Minimum word length (minwordsz) is %d.\n"),
141         dbrec->or_minwordsz);
142
143     printf (catgets (dtsearch_catd, MS_dbrec, 26,
144             "Maximum word length (maxwordsz) is %d.\n"),
145         dbrec->or_maxwordsz);
146
147     printf (catgets (dtsearch_catd, MS_dbrec, 30,
148             "Number of .d00 slots per object (recslots) is %d.\n"),
149         dbrec->or_recslots);
150
151     printf (catgets (dtsearch_catd, MS_dbrec, 36,
152             "  (Maximum number of database objects is %ld).\n"),
153         0xffffffL / (long) dbrec->or_recslots);
154
155     printf (catgets (dtsearch_catd, MS_dbrec, 40,
156             "Huffman compression table id (hufid) is %ld.\n"),
157         dbrec->or_hufid);
158     if (dbrec->or_hufid == 0L)
159         puts (catgets (dtsearch_catd, MS_dbrec, 42,
160                 "  (Compression is disabled in this database)."));
161     if (dbrec->or_hufid == -1L)
162         puts (catgets (dtsearch_catd, MS_dbrec, 44,
163                 "  (Specific compression table is not yet determined)."));
164
165     blobs_are_possible = FALSE;
166     switch (dbrec->or_dbaccess) {
167         case ORA_VARIES:
168             puts (catgets (dtsearch_catd, MS_dbrec, 50,
169                 "Engine accessibility to data may vary from object to object."));
170             blobs_are_possible = TRUE;
171             break;
172         case ORA_NOTAVAIL:
173             puts (catgets (dtsearch_catd, MS_dbrec, 54,
174                 "Data objects are not directly accessible from the engine."));
175             break;
176         case ORA_BLOB:
177             puts (catgets (dtsearch_catd, MS_dbrec, 56,
178                 "Data objects are stored internally as blobs."));
179             blobs_are_possible = TRUE;
180             break;
181         case ORA_REFBLOB:
182             puts (catgets (dtsearch_catd, MS_dbrec, 60,
183                 "Only server file references to objects are stored in the blobs."));
184             break;
185         case ORA_CREFBLOB:
186             puts (catgets (dtsearch_catd, MS_dbrec, 64,
187                 "Only client file references to objects are stored in the blobs."));
188             break;
189         case ORA_REFKEY:
190             puts (catgets (dtsearch_catd, MS_dbrec, 68,
191                 "Object keys are server file references to the objects."));
192             break;
193         case ORA_CREFKEY:
194             puts (catgets (dtsearch_catd, MS_dbrec, 72,
195                 "Object keys are client file references to the objects."));
196             break;
197         case ORA_REFHUGEKEY:
198             puts (catgets (dtsearch_catd, MS_dbrec, 74,
199                 "Server file references to objects are "
200                 "stored in the 'huge' keys."));
201             break;
202         case ORA_REFABSTR:
203             puts (catgets (dtsearch_catd, MS_dbrec, 80,
204                 "Server file references to objects are stored in the abstracts."));
205             break;
206         case ORA_CREFABSTR:
207             puts (catgets (dtsearch_catd, MS_dbrec, 86,
208                 "Client file references to objects are stored in the abstracts."));
209             break;
210         default:
211             printf (catgets (dtsearch_catd, MS_dbrec, 90,
212                 "Error: meaning of or_dbaccess value (%hd) is unknown.\n"),
213                 dbrec->or_dbaccess);
214             blobs_are_possible = TRUE;
215             break;
216     }   /* end or_dbaccess switch */
217
218     if (blobs_are_possible) {
219         /*
220          * if they CAN be compressed, say whether or not they
221          * actually are 
222          */
223         if (dbrec->or_hufid != 0L)
224             printf (catgets (dtsearch_catd, MS_dbrec, 100,
225                     "Repository blobs are %scompressed.\n"),
226                 (ORC_COMPBLOB & dbrec->or_compflags) ? "" : "not ");
227     }
228     else
229         puts (catgets (dtsearch_catd, MS_dbrec, 110,
230                 "Repository blobs are not used in this database."));
231
232     printf (catgets (dtsearch_catd, MS_dbrec, 120,
233             "Database switches (dbflags) are 0x%lx:\n"),
234         dbrec->or_dbflags);
235
236     printf (catgets (dtsearch_catd, MS_dbrec, 130,
237             "  Inverted index %s words exactly as parsed.\n"),
238         (ORD_XWORDS & dbrec->or_dbflags) ?
239         catgets (dtsearch_catd, MS_dbrec, 124, "INCLUDES") :
240         catgets (dtsearch_catd, MS_dbrec, 125, "EXCLUDES"));
241
242     printf (catgets (dtsearch_catd, MS_dbrec, 140,
243             "  Inverted index %s word stems.\n"),
244         (ORD_XSTEMS & dbrec->or_dbflags) ?
245         catgets (dtsearch_catd, MS_dbrec, 124, "INCLUDES") :
246         catgets (dtsearch_catd, MS_dbrec, 125, "EXCLUDES"));
247
248     printf (catgets (dtsearch_catd, MS_dbrec, 160,
249             "  Use of optional 'huge' keys is %s.\n"),
250         (ORD_USEHUGEKEYS & dbrec->or_dbflags) ?
251         catgets (dtsearch_catd, MS_dbrec, 126, "ENABLED") :
252         catgets (dtsearch_catd, MS_dbrec, 127, "DISABLED"));
253
254     printf (catgets (dtsearch_catd, MS_dbrec, 162,
255             "  Mark-for-deletion is %s.\n"),
256         (ORD_NOMARKDEL & dbrec->or_dbflags) ?
257         catgets (dtsearch_catd, MS_dbrec, 127, "DISABLED") :
258         catgets (dtsearch_catd, MS_dbrec, 126, "ENABLED"));
259
260     printf (catgets (dtsearch_catd, MS_dbrec, 164,
261             "  Appendable user notes are %s.\n"),
262         (ORD_NONOTES & dbrec->or_dbflags) ?
263         catgets (dtsearch_catd, MS_dbrec, 127, "DISABLED") :
264         catgets (dtsearch_catd, MS_dbrec, 126, "ENABLED"));
265
266     printf (catgets (dtsearch_catd, MS_dbrec, 170,
267             "  Text characters are %s wide.\n"),
268         (ORD_WIDECHAR & dbrec->or_dbflags) ?
269         catgets (dtsearch_catd, MS_dbrec, 172, "MULTIPLE bytes") :
270         catgets (dtsearch_catd, MS_dbrec, 174, "a SINGLE byte"));
271
272     printf (catgets (dtsearch_catd, MS_dbrec, 200,
273             "Current number of database objects (reccount) is %ld.\n"),
274         dbrec->or_reccount);
275
276     printf (catgets (dtsearch_catd, MS_dbrec, 210,
277             "Last currently used slot number (maxdba) is %ld.\n"),
278         dbrec->or_maxdba);
279
280     for (i = 58; i > 0; i--)
281         putchar ('-');
282     putchar ('\n');
283     return;
284 }  /* print_dbrec() */
285
286
287 #ifdef MAIN_PROGRAM
288 #include <locale.h>
289 #include <fcntl.h>
290 #include "vista.h"
291 /************************************************/
292 /*                                              */
293 /*                    main                      */
294 /*                                              */
295 /************************************************/
296 int     main (int argc, char *argv[])
297 {
298     struct or_dbrec dbrec;
299     char            renamebuf[256];
300     time_t          now;
301
302     aa_argv0 = argv[0];
303     setlocale (LC_ALL, "");
304     dtsearch_catd = catopen (FNAME_DTSRCAT, 0);
305     austools_catd = catopen (FNAME_AUSCAT, 0);
306
307     time (&now);
308     strftime (renamebuf, sizeof (renamebuf),
309         catgets (dtsearch_catd, MS_misc, 22, "%A, %b %d %Y, %I:%M %p"),
310         localtime (&now));
311     printf (catgets (dtsearch_catd, MS_misc, 23,
312         "%s: Version %s.  Run %s.\n"),
313         aa_argv0,
314         DtSrVERSION,
315         renamebuf);
316
317     if (argc < 2) {
318         printf (catgets (dtsearch_catd, MS_dbrec, 310,
319                 "USAGE: %s <dbname>\n"), aa_argv0);
320         return 2;
321     }
322     sprintf (renamebuf, "%s.d00", argv[1]);
323     db_oflag = O_RDONLY;        /* db files may be read-only */
324     d_open (argv[1], "o");
325     if (db_status != S_OKAY) {
326         printf (catgets (dtsearch_catd, MS_dbrec, 330,
327                 "Could not open '%s' database.\n%s\n"),
328                 argv[1], vista_msg(PROGNAME"293"));
329         return 3;
330     }
331     d_recfrst (OR_DBREC, 0);
332     if (db_status != S_OKAY) {
333         printf (catgets (dtsearch_catd, MS_dbrec, 340,
334                 "No dbrec record in database '%s'.\n"),
335                 argv[1]);
336         return 4;
337     }
338     d_recread (&dbrec, 0);
339     if (db_status != S_OKAY) {
340         printf (catgets (dtsearch_catd, MS_dbrec, 350,
341                 "Can't read dbrec record in database '%s'.\n%s\n"),
342                 argv[1], vista_msg(PROGNAME"306"));
343         return 5;
344     }
345     swab_dbrec (&dbrec, NTOH);
346     print_dbrec (argv[1], &dbrec);
347     return 0;
348 }  /* main() */
349
350 #endif
351
352 /************************* DTSRDBREC.C **************************/