flush stdout during tests.
[rattatechess.git] / utils.h
blob776676775bf95fa2a4b662a31fbff24cb87286cd
1 /***************************************************************************
2 utils.h - some utility funtions
3 -------------------
4 begin : lun ott 24 2005
5 copyright : (C) 2005-2007 by Maurizio Monge
6 email : monge@linuz.sns.it
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 #ifndef __UTILS_H__
19 #define __UTILS_H__
21 #include <stdio.h>
22 #include <inttypes.h>
23 #include <errno.h>
24 #include "platform.h"
25 #include "compiler.h"
26 #include "array.h"
28 #define SWITCH(a, b) ({ typeof(a) tmp = b; b = a; a = tmp; })
29 #define MAX(a,b) ({ typeof(a) _a=(a); typeof(b) _b=(b); _a > _b ? _a : _b; })
30 #define MIN(a,b) ({ typeof(a) _a=(a); typeof(b) _b=(b); _a < _b ? _a : _b; })
31 #define ABS(a) ({ typeof(a) _a=(a); _a > 0 ? _a : -_a; })
33 #ifdef __x86_64__
34 #define U64F "%lu"
35 #else
36 #define U64F "%llu"
37 #endif
39 #define PROF(f,n) {uint64_t tmp = rdtsc(); f; prof_##n += rdtsc()-tmp; }
41 char **tokenize(const char *str, int* numtokens = NULL, bool accept_quotes = true);
42 char **tokenize(const char *str, const char *whitespaces, int* numtokens = NULL, bool accept_quotes = true);
44 char **get_tokenized(int* numtokens = NULL, bool accept_quotes = true);
45 char **get_tokenized(const char *whitespaces, int* numtokens = NULL, bool accept_quotes = true);
46 char **fget_tokenized(FILE* f, int* numtokens = NULL, bool accept_quotes = true);
47 char **fget_tokenized(FILE* f, const char *whitespaces, int* numtokens = NULL, bool accept_quotes = true);
49 #endif //__UTILS_H__