Clustal Omega 1.2.4
util.h
Go to the documentation of this file.
1/*********************************************************************
2 * Clustal Omega - Multiple sequence alignment
3 *
4 * Copyright (C) 2010 University College Dublin
5 *
6 * Clustal-Omega is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 *
11 * This file is part of Clustal-Omega.
12 *
13 ********************************************************************/
14
15/*
16 * RCS $Id: util.h 230 2011-04-09 15:37:50Z andreas $
17 */
18
19#include <limits.h>
20#include <string.h>
21#include <strings.h>
22#include <stdarg.h>
23#include <stdbool.h>
24
25#ifndef CLUSTALO_UTIL_H
26#define CLUSTALO_UTIL_H
27
28
29#define CKMALLOC(b) CkMalloc((b), __FUNCTION__, __LINE__)
30#define CKCALLOC(c, s) CkCalloc((c), (s), __FUNCTION__, __LINE__)
31#define CKREALLOC(p, b) CkRealloc((p), (b), __FUNCTION__, __LINE__)
32#define CKFREE(b) ((b)=CkFree((b), __FUNCTION__, __LINE__))
33
34#ifndef MAX
35#define MAX(a,b) ((a)>(b)?(a):(b))
36#endif
37#ifndef MIN
38#define MIN(a,b) ((a)<(b)?(a):(b))
39#endif
40
41/* STR_EQ: strings are equal, case sensitive */
42#define STR_EQ(a,b) (strcmp((a),(b)) == 0)
43/* STR_NC_EQ: strings are equal, ignoring case */
44#define STR_NC_EQ(a,b) (strcasecmp((a),(b)) == 0)
45
46
47/* type boolean and false and true defined in stdbool.h */
48#ifndef TRUE
49#define TRUE true
50#endif
51#ifndef FALSE
52#define FALSE false
53#endif
54
55/* clashes with hhalign
56#define FAIL -1
57#define OK 0
58*/
59
60
61
62/* don't use the following directly; use macros provided above instead
63 */
64void *CkMalloc(size_t size, const char *function, const int line);
65void *CkCalloc(size_t count, size_t size, const char *function, const int line);
66void *CkRealloc(void *ptr, size_t bytes, const char *function, const int line);
67void *CkFree(void *ptr, const char *function, const int line);
68char *CkStrdup(const char *s);
69void PermutationArray(int **array, const int len);
70void RandomUniqueIntArray(int *array, const int array_len, const int max_value);
71int IntCmp(const void *a, const void *b);
72bool FileIsWritable(char *pcFileName);
73void QSortAndTrackIndex(int *piSortedIndices, int *piArrayToSort,
74 const int uArrayLen, const char cOrder, const bool bOverwriteArrayToSort);
75
76#endif
void * CkFree(void *ptr, const char *function, const int line)
Frees memory.
Definition util.c:180
void PermutationArray(int **array, const int len)
Creates an int array of size len with len-1 random but unique integers with values 0–len-1....
Definition util.c:237
char * CkStrdup(const char *s)
safe version of strdup
Definition util.c:207
void * CkMalloc(size_t size, const char *function, const int line)
Allocates memory (malloc)
Definition util.c:79
int IntCmp(const void *a, const void *b)
int comparison function for qsort
Definition util.c:329
void QSortAndTrackIndex(int *piSortedIndices, int *piArrayToSort, const int uArrayLen, const char cOrder, const bool bOverwriteArrayToSort)
Sort a given int array in ascending or descending order, while keeping track of the element order.
Definition util.c:403
bool FileIsWritable(char *pcFileName)
Test if file is writable. File may or may not exist.
Definition util.c:466
void RandomUniqueIntArray(int *array, const int array_len, const int max_value)
Creates an array filled with random, but unique ints of given range. Implementation of the Floyd algo...
Definition util.c:293
void * CkCalloc(size_t count, size_t size, const char *function, const int line)
Allocates memory (calloc). Memory will be set to zero.
Definition util.c:114
void * CkRealloc(void *ptr, size_t bytes, const char *function, const int line)
Reallocates memory.
Definition util.c:148