Disable all code related to libXp
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / utility / funcs.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 /*
24  * $XConsortium: funcs.h /main/12 1996/09/13 20:48:55 cde-hal $
25  *
26  * Copyright (c) 1993 HAL Computer Systems International, Ltd.
27  * All rights reserved.  Unpublished -- rights reserved under
28  * the Copyright Laws of the United States.  USE OF A COPYRIGHT
29  * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
30  * OR DISCLOSURE.
31  * 
32  * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
33  * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.  USE,
34  * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
35  * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
36  * INTERNATIONAL, LTD.
37  * 
38  *                         RESTRICTED RIGHTS LEGEND
39  * Use, duplication, or disclosure by the Government is subject
40  * to the restrictions as set forth in subparagraph (c)(l)(ii)
41  * of the Rights in Technical Data and Computer Software clause
42  * at DFARS 252.227-7013.
43  *
44  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
45  *                  1315 Dell Avenue
46  *                  Campbell, CA  95008
47  * 
48  */
49
50
51
52 #ifndef _funcs_h
53 #define _funcs_h 1
54
55 #if !defined(USL) && !defined(__osf__) && !defined(linux) && \
56     !defined(CSRG_BASED) && !defined(sun)
57 #include <libc.h>
58 #endif
59 #if defined(hpux) || defined(sgi) || defined(USL) ||defined(__osf__) || \
60     defined(linux) || defined(CSRG_BASED) || defined(sun)
61 #include <unistd.h>
62 #else
63 #include <sysent.h>
64 #endif
65 #include <time.h>
66 #include <errno.h>
67 #include <string.h>
68 #include <sys/types.h>
69 #include <sys/stat.h>
70
71 #ifdef C_API
72 #include "utility/c_stream.h"
73 #include "utility/c_fstream.h"
74 #include "utility/c_stringstream.h"
75 #else
76 #include <assert.h>
77 #include <iostream>
78 #include <fstream>
79 #include <sstream>
80 using namespace std;
81 #endif
82
83 #include <math.h>
84
85 #ifdef __CENTERLINE__
86 // centerline does not define these
87 #define S_ISDIR(m)      (((m)&S_IFMT) == S_IFDIR)
88 #define S_ISREG(m)      (((m)&S_IFMT) == S_IFREG)
89
90 #endif
91
92 #include "utility/debug.h"
93 #include "utility/types.h"
94 #include "utility/const.h"
95 #include "utility/macro.h"
96 #include "utility/mmdb_exception.h"
97
98 #ifdef USL
99 int _DtMmdbStrcasecmp(const char *s1, const char *s2);
100 int _DtMmdbStrncasecmp(const char *s1, const char *s2, int n);
101 #define strcasecmp(s1,s2) _DtMmdbStrcasecmp(s1,s2)
102 #define strncasecmp(s1,s2,n) _DtMmdbStrncasecmp(s1,s2,n)
103 #endif
104 #ifdef _IBMR2
105 /* no C++ version of <strings.h>, C version causes conflicts */
106 extern "C" {
107 extern int  strcasecmp(const char *, const char *);
108 extern int  strncasecmp(const char *, const char *, size_t);
109 }
110 #endif
111 #ifdef mips
112 int gethostname(char* name, int namelen);
113 #endif
114
115 int compare_stream(ostringstream& x, ostringstream& y);
116
117 char * cuserid(char *s);
118
119
120 inline float flog2(unsigned int x) {
121    return (float)(log((double)x) / log((double)2));
122 #if defined(__osf__)
123 }     // return log_2(x) 
124 #else
125 };     // return log_2(x) 
126 #endif /* (__osf__) */
127
128 inline float flog2(const float x) {
129    return (float)log((double)x) / (float)log((float)2);
130 #if defined(__osf__)
131 }
132 #else
133 };
134 #endif /* (__osf__) */
135
136 inline int pow2(const int x) {
137    return (int)pow((double)2, (double)x);
138 #if defined(__osf__)
139 }     // x's power of 2
140 #else
141 };     // x's power of 2
142 #endif /* (__osf__) */
143
144 inline int pow2(const float x) {
145    return (int)pow((double)2, (double)x);
146 #if defined(__osf__)
147 }    // x's power of 2
148 #else
149 };    // x's power of 2
150 #endif /* (__osf__) */
151
152 int pos_of_LSB(const unsigned int x); // position of the MSB
153
154 int ceiling(const float);    // ceiling of x
155 unsigned getbits(unsigned, unsigned, unsigned);
156
157 inline void char_swap(char& c1, char& c2) {
158    char tmp = c1; c1 = c2; c2 = tmp;
159 #if defined(__osf__)
160 }  // switch two chars
161 #else
162 };  // switch two chars
163 #endif /* (__osf__) */
164
165 inline void short_swap(short& s1, short& s2) {
166    short tmp = s1; s1 = s2; s2 = tmp;
167 #if defined(__osf__)
168 }// switch two shorts
169 #else
170 };// switch two shorts
171 #endif /* (__osf__) */
172
173 inline void int_swap(int& i1, int& i2) {
174    int tmp = i1; i1 = i2; i2 = tmp;
175 #if defined(__osf__)
176 }     // switch two ints
177 #else
178 };     // switch two ints
179 #endif /* (__osf__) */
180
181 // file functions
182
183 int del_file(const char* file_nm, const char* path_nm = 0);
184
185 Boolean copy_file(const char* source, const char* sink);
186 Boolean copy_file(const char* path, const char* filenm,
187                   const char* source_ext, const char* target_ext);
188
189 Boolean exist_file(const char* name, const char* path = 0);
190 Boolean cat_file(const char* source1, const char* source2, 
191                     const char* target);
192 int check_file(istream&, const char* msg = "");
193
194 Boolean exist_dir(const char* path);
195 Boolean check_and_create_dir(const char* path);
196
197 int open_file_prot();
198 int open_dir_prot();
199
200
201 Boolean cc_is_digit(istream&); // "cc" stands for current char
202
203 unsigned long disk_space(const char* path);
204 char* access_info( char* request );
205
206 Boolean int_eq(void*, void*);
207 Boolean int_ls(void*, void*);
208
209 // return an lease largest int of x, the returned value is 
210 // also a multiple of sizeof(void*)
211 int ll4(int x);
212
213 /*
214 enum lock_t { SHARED, EXCLUSIVE };
215
216 Boolean fcntl_lock( int fd, lock_t lt );
217 Boolean fcntl_unlock( int fd );
218
219 Boolean timed_lock( int fd, lock_t lt, int seconds = 5);
220 Boolean timed_unlock( int fd, int seconds = 5);
221
222 void onalarm(int);
223 */
224
225 #ifdef C_API
226 int bytes(int fd);
227 int bytes(fstream&);
228 #else
229 int bytes(fstream*);
230 #endif
231 int bytes(char* file_name);
232
233 char*  form(const char* ...);
234
235 // lsb is considered as the 0th bit
236 void lsb_putbits(unsigned& target, unsigned position_from_lsb, 
237              unsigned bits, unsigned source);
238 unsigned lsb_getbits(unsigned source, unsigned position_from_lsb, unsigned bits);
239
240 Boolean writeToTmpFile(char* unique_nm, char* str, int size);
241
242 #endif
243