1 /***********************************************************************/
2 /* Open Visualization Data Explorer                                    */
3 /* (C) Copyright IBM Corp. 1989,1999                                   */
4 /* ALL RIGHTS RESERVED                                                 */
5 /* This code licensed under the                                        */
6 /*    "IBM PUBLIC LICENSE - Open Visualization Data Explorer"          */
7 /***********************************************************************/
8 
9 #include <dxconfig.h>
10 
11 
12 #include <dx/dx.h>
13 #include "utils.h"
14 
15 #if 0
16 char *strsaven (char *old, int n)
17 {
18     char	*new;
19 
20     new = DXAllocate (n + 1);
21     if (new)
22     {
23 	memcpy (new, old, n);
24 	new[n] = NULL;
25     }
26     return (new);
27 }
28 #endif
29 
30 #if 0
31 char *lstrsaven (char *old, int n)
32 {
33     char	*new;
34 
35     new = DXAllocateLocal (n + 1);
36     if (new)
37     {
38 	memcpy (new, old, n);
39 	new[n] = NULL;
40     }
41     return (new);
42 }
43 #endif
44 
_dxf_ExStrSave(char * old)45 char *_dxf_ExStrSave (char *old)
46 {
47     char	*new;
48     int		n;
49 
50     n   = strlen (old);
51     new = DXAllocate (n + 1);
52     if (new)
53     {
54 	memcpy (new, old, n);
55 	new[n] = '\0';
56     }
57     return (new);
58 }
59 
60 #if 0
61 char *lstrsave (char *old)
62 {
63     char	*new;
64     int		n;
65 
66     n   = strlen (old);
67     new = DXAllocateLocal (n + 1);
68     if (new)
69     {
70 	memcpy (new, old, n);
71 	new[n] = NULL;
72     }
73     return (new);
74 }
75 #endif
76 
77 /*
78  * Adjusts a pointer value such that it falls on an n byte aligned boundary.
79  *
80  * WARNING:	Only works if n is a power of 2.
81  */
82 
_dxf_ExAlignBoundary(long n,Pointer p)83 Pointer _dxf_ExAlignBoundary	(long n, Pointer p)
84 {
85     long	mask;
86 
87     if (n == 0 || n == 1)
88 	return (p);
89 
90     mask = n - 1;
91 
92     return ((mask & (long) p)
93 		? (Pointer) (((long) p + n) & ~mask)
94 		: p);
95 }
96 
97 
_dxf_ExCopyStringN(char * old,int len)98 char *_dxf_ExCopyStringN (char *old, int len)
99 {
100     char        *new;
101 
102     if (old == NULL)
103 	return (NULL);
104 
105     new = (char *) DXAllocate (len + 1);
106 
107     if (! new)
108     {
109         DXResetError ();
110         return (NULL);
111     }
112 
113     strncpy (new, old, len);
114     new[len] = '\0';
115 
116     return (new);
117 }
118 
119 
120 
_dxf_ExCopyString(char * old)121 char *_dxf_ExCopyString (char *old)
122 {
123     char	*new;
124 
125     if (old == NULL)
126 	return (NULL);
127 
128     new = (char *) DXAllocate (strlen (old) + 1);
129 
130     if (! new)
131     {
132 	DXResetError ();
133 	return (NULL);
134     }
135 
136     strcpy (new, old);
137 
138     return (new);
139 }
140 
141 
_dxf_ExCopyStringLocal(char * old)142 char *_dxf_ExCopyStringLocal (char *old)
143 {
144     char		*new;
145     int			size;
146 
147     size = strlen (old) + 1;
148 
149     new = (char *) DXAllocateLocal (size);
150 
151     if (! new)
152     {
153 	DXResetError ();
154 	return (NULL);
155     }
156 
157     strcpy (new, old);
158 
159     return (new);
160 }
161 
_dxf_ExNextPowerOf2(int n)162 int _dxf_ExNextPowerOf2 (int n)
163 {
164     int		i;
165     int		v;
166 
167     for (i = 0, v = 1; i < 31; i++, v <<= 1)
168 	if (v >= n)
169 	    return (v);
170     return 0;
171 }
172 
_dxfExNewInteger(int n)173 Array _dxfExNewInteger (int n)
174 {
175     return DXAddArrayData (DXNewArray (TYPE_INT, CATEGORY_REAL, 0),
176 			0, 1, (Pointer) &n);
177 }
178 
179