1 /*
2   Copyright (c) 2003 by Stefan Kurtz and The Institute for
3   Genomic Research.  This is OSI Certified Open Source Software.
4   Please see the file LICENSE for licensing information and
5   the file ACKNOWLEDGEMENTS for names of contributors to the
6   code base.
7 */
8 
9 //\IgnoreLatex{
10 
11 #ifndef TYPES_H
12 #define TYPES_H
13 #include <sys/types.h>
14 #include <limits.h>
15 #include <stdlib.h>
16 #include <stdio.h>
17 
18 #ifdef MSWINDOWS
19 typedef void * caddr_t;
20 #endif
21 
22 /*
23   Some rules about types:
24   - do not use Ulong, these are not portable.
25   - do not use the constants, UINT_MAX, INT_MAX and INT_MIN
26   The following are the assumptions about the types:
27   - size(Uint) >= 4
28   - size(Sint) >= 4
29   - size(Ushort) = 2
30   - size(Sshort) = 2
31   No other assumptions are to be made.
32 */
33 
34 //}
35 
36 /*
37   This file contains some basic type definition.
38 */
39 
40 typedef unsigned char  Uchar;         // \Typedef{Uchar}
41 typedef unsigned short Ushort;        // \Typedef{Ushort}
42 
43 /*
44   The following is the central case distinction to accomodate
45   code for 32 bit integers and 64 bit integers.
46 */
47 
48 #ifdef SIXTYFOURBITS
49 
50 typedef unsigned long  Uint;          // \Typedef{Uint}
51 typedef signed   long  Sint;          // \Typedef{Sint}
52 #define LOGWORDSIZE    6              // base 2 logarithm of wordsize
53 #define UintConst(N)   (N##UL)        // unsigned integer constant
54 
55 #else
56 
57 typedef unsigned int  Uint;          // \Typedef{Uint}
58 typedef signed   int  Sint;          // \Typedef{Sint}
59 #define LOGWORDSIZE    5             // base 2 logarithm of wordsize
60 #define UintConst(N)   (N##U)        // unsigned integer constant
61 
62 #endif
63 
64 /*
65   Type of unsigned integer in \texttt{printf}.
66 */
67 
68 typedef unsigned long Showuint;     // \Typedef{Showuint}
69 
70 /*
71   Type of signed integer in \texttt{printf}.
72 */
73 
74 typedef signed long Showsint;       // \Typedef{Showsint}
75 
76 /*
77   Type of integer in \texttt{scanf}.
78 */
79 
80 typedef signed long Scaninteger;    // \Typedef{Scaninteger}
81 
82 /*
83   Argument of a function from \texttt{ctype.h}.
84 */
85 
86 typedef int Ctypeargumenttype;      // \Typedef{Ctypeargumenttype}
87 
88 /*
89   Return type of \texttt{fgetc} and \texttt{getc}.
90 */
91 
92 typedef int Fgetcreturntype;        // \Typedef{Fgetcreturntype}
93 
94 /*
95   Type of first argument of \texttt{fputc}.
96 */
97 
98 typedef int Fputcfirstargtype;      // \Typedef{Fputsfirstargtype}
99 
100 /*
101   Return type of \texttt{strcmp}.
102 */
103 
104 typedef int Strcmpreturntype;       // \Typedef{Strcmpreturntype}
105 
106 /*
107   Type of a file descriptor.
108 */
109 
110 typedef int Filedesctype;           // \Typedef{Filedesctype}
111 
112 /*
113   Return type of \texttt{qsort} function.
114 */
115 
116 typedef int Qsortcomparereturntype; // \Typedef{Qsortcomparefunction}
117 
118 /*
119   Return type of \texttt{sprintf} function.
120 */
121 
122 typedef int Sprintfreturntype;     // \Typedef{Sprintfreturntype}
123 
124 /*
125   Type of fieldwidth in \texttt{printf} format string.
126 */
127 
128 typedef int Fieldwidthtype;         // \Typedef{Fieldwidthtype}
129 
130 /*
131   Type of \texttt{argc}-parameter in main.
132 */
133 
134 typedef int Argctype;               // \Typedef{Argctype}
135 
136 /*
137   Return type of \texttt{getrlimit}
138 */
139 
140 typedef int Getrlimitreturntype;    // \Typedef{Getrlimitreturntype}
141 
142 #ifdef WITHSYSCONF
143 typedef int Sysconfargtype;         // \Typedef{Sysconfargtype}
144 #endif
145 
146 /*
147   The following macros define some basic division, multiplication,
148   and modulo operations on unsigned integers.
149 */
150 
151 #define DIV2(N)      ((N) >> 1)
152 #define DIV4(N)      ((N) >> 2)
153 #define DIV8(N)      ((N) >> 3)
154 #define MULT2(N)     ((N) << 1)
155 #define MULT4(N)     ((N) << 2)
156 #define MULT8(N)     ((N) << 3)
157 #define MOD2(N)      ((N) & 1)
158 #define MOD4(N)      ((N) & 3)
159 #define MOD8(N)      ((N) & 7)
160 
161 //\IgnoreLatex{
162 
163 #define CHECKTYPESIZE(T,OP,S)\
164         if(sizeof(T) OP (S))\
165         {\
166           DEBUG4(1,"# sizeof(%s) %s (%ld bytes,%ld bits) as epected\n",\
167                   #T,#OP,(Showsint) sizeof(T),\
168                          (Showsint) (CHAR_BIT * sizeof(T)));\
169         } else\
170         {\
171           fprintf(stderr,"typesize constraint\n");\
172           fprintf(stderr,"  sizeof(%s) = (%ld bytes,%ld bits) %s %lu bytes\n",\
173                   #T,\
174                   (Showsint) sizeof(T),\
175                   (Showsint) (CHAR_BIT * sizeof(T)),\
176                   #OP,\
177                   (Showuint) (S));\
178           fprintf(stderr,"does not hold\n");\
179           exit(EXIT_FAILURE);\
180         }
181 
182 /*
183   The following function checks some type constraints
184 */
185 
186 #define CHECKALLTYPESIZES\
187         CHECKTYPESIZE(char,==,(size_t) 1)\
188         CHECKTYPESIZE(short,==,(size_t) 2)\
189         CHECKTYPESIZE(int,==,(size_t) 4)\
190         CHECKTYPESIZE(long,>=,(size_t) 4)\
191         CHECKTYPESIZE(void *,>=,(size_t) 4)
192 
193 //}
194 
195 /*
196   Here is a prototype for the main function.
197 */
198 
199 #define MAINFUNCTION int main(Argctype argc,char *argv[])
200 
201 //\IgnoreLatex{
202 
203 #ifndef __cplusplus
204 int mkstemp(char *);
205 #endif
206 
207 //}
208 
209 /*
210   A type for boolean values defined as a constant to allow
211   checking if it has been defined previously.
212 */
213 
214 #ifndef BOOL
215 #define BOOL unsigned char
216 #endif
217 
218 #ifndef False
219 #define False ((BOOL) 0)
220 #endif
221 
222 #ifndef True
223 #define True ((BOOL) 1)
224 #endif
225 
226 /*
227   Show a boolean value as a string or as a character 0 or 1.
228 */
229 
230 #define SHOWBOOL(B) ((B) ? "True" : "False")
231 #define SHOWBIT(B)  ((B) ? '1' : '0')
232 
233 /*
234   Pairs, triples, and quadruples of unsigned integers.
235 */
236 
237 typedef struct
238 {
239   Uint uint0, uint1;
240 } PairUint;                // \Typedef{PairUint}
241 
242 typedef struct
243 {
244   Uint uint0, uint1, uint2;
245 } ThreeUint;               // \Typedef{ThreeUint}
246 
247 typedef struct
248 {
249   Uint uint0, uint1, uint2, uint3;
250 } FourUint;                // \Typedef{FourUint}
251 
252 //\IgnoreLatex{
253 
254 /*
255   A list is stored with its start position in some space block
256   and its length.
257 */
258 
259 typedef struct
260 {
261   Uint start, length;
262 } Listtype;                // \Typedef{Listtype}
263 
264 /*
265   A string is just a list.
266 */
267 
268 typedef Listtype Stringtype;    // \Typedef{Stringtype}
269 
270 /*
271   The default type for length-values is unsigned int.
272 */
273 
274 #ifndef LENGTHTYPE
275 #define LENGTHTYPE Uint
276 #endif
277 
278 /*
279   The default number of bytes in a bitvector used for dynamic programming
280   is 4.
281 */
282 
283 #ifndef DPBYTESINWORD
284 #define DPBYTESINWORD 4
285 #endif
286 
287 /*
288   The number of bytes in a dynamic programming bitvector determines the type
289   of integers, the dp-bits are stored in.
290 */
291 
292 #if DPBYTESINWORD == 1
293 typedef unsigned char DPbitvector;          // \Typedef{DPbitvector}
294 #else
295 #if DPBYTESINWORD == 2
296 typedef unsigned short DPbitvector;
297 #else
298 #if DPBYTESINWORD == 4
299 typedef unsigned int DPbitvector;
300 #else
301 #if DPBYTESINWORD == 8
302 typedef unsigned long long DPbitvector;
303 #endif
304 #endif
305 #endif
306 #endif
307 
308 typedef unsigned int DPbitvector4;          // \Typedef{DPbitvector4}
309 
310 #if (LOGWORDSIZE==6)
311 typedef unsigned long DPbitvector8;         // \Typedef{DPbitvector8}
312 #endif
313 
314 //}
315 
316 /*
317   The following type stores filenames and the length of the corresponding
318   files.
319 */
320 
321 typedef struct
322 {
323   char *filenamebuf;    // pointer to a copy of a filename
324   Uint filelength;      // the length of the corresponding file
325 } Fileinfo;             // \Typedef{Fileinfo}
326 
327 /*
328   The following is the type of the comparison function
329   to be provided to the function \texttt{qsort}.
330 */
331 
332 typedef int (*Qsortcomparefunction)(const void *,const void *);
333 
334 //\IgnoreLatex{
335 
336 #endif
337 
338 //}
339