Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / DtSvc / DtUtil1 / DtsMM.h
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 /* $XConsortium: DtsMM.h /main/8 1996/08/28 14:27:26 rswiston $ */
24 /*
25  *
26  *      RESTRICTED CONFIDENTIAL INFORMATION:
27  *      
28  *
29  *      Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
30  *
31  *+ENOTICE
32  */
33 #ifndef DT_DTS_MM_H
34 #define DT_DTS_MM_H
35
36 #include <stdio.h>
37 #include <Dt/DtShmDb.h>
38 #include <X11/Intrinsic.h>
39 #include "Dt/DbReader.h"
40
41 #define DTDTSDB_TMPDATABASENAME "%s/.dt/.tmp_dt_db_cache.%s\0"
42 #define DTDTSDB_DATABASENAME    "%s/.dt/.dt_db_cache.%s\0"
43 #define _DTDTSMMTEMPFILE        "dtdbcache_"
44
45 /*
46  * NOTE: _DTDTSMMTEMPDIR affects the location of the dtdbcache
47  * file, and therefore affects the Xsession.src, Xreset.src, and
48  * Xstartup.src scripts in dtlogin/config.
49  */
50 #ifdef __osf__
51 # define _DTDTSMMTEMPDIR        "/var/tmp"
52 #else
53 # define _DTDTSMMTEMPDIR        "/tmp"
54 #endif
55
56 typedef int     DtDtsMMSeqNo;           /* the order it occures in db */
57 typedef int     DtDtsMMFieldCount;      /* number of fields in record */
58 typedef int     DtDtsMMRecordCount;     /* number of records in field */
59 typedef int     DtDtsMMDataBaseCount;   /* how many databases */
60 typedef int     DtDtsMMFieldStart;      /* index in table where field list starts */
61 typedef int     DtDtsMMRecordStart;     /* index in table where record list starts */
62 typedef int     DtDtsMMDataBaseStart;   /* index in table where database list starts */
63 typedef int     DtDtsMMIndexOffset;
64 typedef int     DtDtsMMNameIndex;
65 typedef int     DtDtsMMPathHash;
66
67 typedef struct
68 {
69         DtDtsMMPathHash         pathhash;       /* hash of dir. we visit */
70         DtDtsMMDataBaseCount    num_db;         /* number of databases */
71         DtDtsMMDataBaseStart    db_offset;      /* index to databases */
72         DtDtsMMNameIndex        name_list_offset;       /* index to name list */
73         DtDtsMMNameIndex        no_name_offset;         /* index to nonunique names */
74         DtDtsMMNameIndex        buffer_start_index;     /* index to list of buffers */
75         DtDtsMMIndexOffset      str_tbl_offset;         /* index to table of strings */
76         DtDtsMMIndexOffset      files_count;            /* number of loaded files */
77         DtDtsMMIndexOffset      files_offset;           /* index to list of loaded files */
78         DtDtsMMIndexOffset      mtimes_offset;  /* index to modified times of files */
79 } DtDtsMMHeader;
80
81 /* one set of attribute/pair */
82 typedef struct
83 {
84         DtShmBoson              fieldName;      /* name of attribute */
85         DtShmBoson              fieldValue;     /* value of attribute */
86 } DtDtsMMField;
87
88 /* typedefs for casting comparison functions if needed */
89 typedef int     (*_DtDtsMMFieldCompare)(DtDtsMMField *fld1, DtDtsMMField *fld2);
90
91 /* entry of a list of attribute/pairs */
92 typedef struct
93 {
94         DtShmBoson              recordName;     /* name of this entry */
95         DtShmBoson              pathId;         /* file entry is located in */
96         DtDtsMMSeqNo            seq;            /* sequence this got loaded */
97         DtDtsMMFieldCount       fieldCount;     /* number of fields in record */
98         DtDtsMMFieldStart       fieldList;      /* index to field table */
99 } DtDtsMMRecord;
100
101 /* typedefs for casting record comparison functions if needed */
102 typedef int     (*_DtDtsMMRecordCompare)(DtDtsMMRecord *rec1, DtDtsMMRecord *rec2);
103
104 /* a "database" of a collection of entrys (i.e. OBJECT-TYPE, ACTION, FILE-TYPE 
105         This is a private Structure to the DtDtsMM component.
106 */
107 typedef struct
108 {
109         DtShmBoson              databaseName;   /* name of database */
110         DtDtsMMIndexOffset      nameIndex;      /* index for DataCriteria quick find */
111         DtDtsMMRecordCount      recordCount;    /* number of records */
112         DtDtsMMRecordStart      recordList;     /* index to records table */
113 } DtDtsMMDatabase;
114
115
116 /* Db Internal pointers */
117 int *                   _DtDtsMMGetDCNameIndex(int *size);
118 int *                   _DtDtsMMGetBufferIndex(int *size);
119 int *                   _DtDtsMMGetNoNameIndex(int *size);
120 void *                  _DtDtsMMGetPtr(int index);
121 DtShmInttab             _DtDtsMMGetFileList(void);
122 int                     _DtDtsMMGetPtrSize(int index);
123 int                     _DtDtsMMInit(int);
124 void                    _DtDtsMMPrint(FILE *org_fd);
125 int                     _DtDtsMMCreateDb(DtDirPaths *dirs, const char *CacheFile, int override);
126 int                     _DtDtsMMCreateFile(DtDirPaths *dirs, const char *CacheFile);
127 char *                  _DtDtsMMCacheName(int);
128 int                     _DtDtsMMapDB(const char *CacheFile);
129
130 const char *            _DtDtsMMBosonToString(DtShmBoson boson);
131 DtShmBoson              _DtDtsMMStringToBoson(const char *string);
132
133 extern  int     use_in_memory_db;
134
135
136 /* returns the handle for the database where name is the Database name */
137 extern  DtDtsMMDatabase         *_DtDtsMMGet(const char *name);
138 extern  char                    **_DtDtsMMListDb(void);
139
140 /* Name Comparison functions:
141  * These routines can be passed in to the corresponding sort function to
142  * sort by name.
143  *
144  */
145 extern int _DtDtsMMCompareRecordNames(DtDtsMMRecord *entry1, DtDtsMMRecord *entry2);
146 extern int _DtDtsMMCompareFieldNames(DtDtsMMField *entry1, DtDtsMMField *entry2);
147
148 /* retrieves the Record that matches the specified entry from the record */
149 extern  DtDtsMMField    *_DtDtsMMGetField(DtDtsMMRecord *record,
150                                         const char *value);
151 extern const char *_DtDtsMMGetFieldByName(DtDtsMMRecord *rec, const char *name);
152
153 /* retrieves the entry of the specified entry from the specified database */
154 extern  DtDtsMMRecord   *_DtDtsMMGetRecord(DtDtsMMDatabase *database,
155                                         DtDtsMMRecord *value);
156 extern  DtDtsMMRecord   *_DtDtsMMGetRecordByName(DtDtsMMDatabase *database,
157                                         const char *value);
158
159 /* Get By Name functions:
160  * retrieves the entry of the specified name from the specified database
161  * ** IF ** the _DtDtsMM*Sort routine has been called with the corresponding
162  * _DtDtsMMCompare*Name comparison function. Otherwise use the standard
163  * _DtDtsMMGet* functions. 
164 */
165
166
167 char *  _DtDtsMMExpandValue(const char *value);
168 void    _DtDtsMMSafeFree(char *value);
169 int     _DtDtsMMIsMemory(const char *value);
170
171 extern  DtShmBoson      _DtDtsMMNameStringToBoson(const char *string);
172
173
174 #endif /* DT_DTS_MM_H */