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