HNBody  Version 1.0.10
util.h
Go to the documentation of this file.
1 #ifndef MUTILS_UTIL_H
2 #define MUTILS_UTIL_H
3 
13 #include "mutils/platform.h"
14 
15 #ifdef __cplusplus
16 # include <cstdio>
17 # include <cstdlib>
18 # include <cstring>
19  using std::FILE;
20  using std::size_t;
21 #else
22 # include <stdio.h>
23 # include <stdlib.h>
24 # include <string.h>
25 #endif
26 
27 #ifdef mu_os_mswin
28 #define strcasecmp stricmp
29 #define strncasecmp strnicmp
30 #elif !defined(__DECC)
31 #include <strings.h>
32 #endif
33 
34 #ifndef mu_os_mswin
35 #include <unistd.h>
36 #endif
37 
38 #define MU_VERMAX 32 /* Max length of version string. */
39 #define MU_DATEMAX 24 /* Max length of cppdate string. */
40 
41 #ifdef __cplusplus
42 extern "C" {
43 namespace MUTILS {
44 #endif
45 
46 DLLSPEC extern void
47  mu_cppdate(char str[ /*MU_DATEMAX*/ ], const char *date, const char *time),
48  mu_error_action(int, const char *, const char *, int, int),
49  mu_split_tag(char pre[], int *maj, int *min, int *clas, int *bug,
50  int *y, int *m, int *d, const char *tag);
51 
52 DLLSPEC extern char
53  *mu_fgetline(char *, long int, FILE *);
54 
55 DLLSPEC extern const char
56  *mu_platform(void),
57  *mu_version(void),
58  *mu_verstr(char verstr[ /*MU_VERMAX*/ ], const char *pre,
59  int maj, int min, int clas, int bug);
60 
61 DLLSPEC extern int
62  mu_ppmtext(char *, char *, int, int, int),
63  mu_vernum(const char *name, const char *cvs);
64 
65 #define MU_iferr_abort(err, func) do { \
66  if (err) mu_error_action(-1, func, __FILE__, __LINE__, -1); } while (0)
67 
68 #define MU_iferr_warn(err, func) do { \
69  if (err) mu_error_action(-1, func, __FILE__, __LINE__, 0); } while (0)
70 
71 #define MU_iferr(err, func) do { \
72  if (err) mu_error_action(-1, func, __FILE__, __LINE__, 1); } while (0)
73 
74 #define MU_iferrn_abort(err, func) do { \
75  int errn=(err); \
76  if (errn) mu_error_action(errn, func, __FILE__, __LINE__, -1); } while (0)
77 
78 #define MU_iferrn_warn(err, func) do { \
79  int errn=(err); \
80  if (errn) mu_error_action(errn, func, __FILE__, __LINE__, 0); } while (0)
81 
82 #define MU_iferrn(err, func) do { \
83  int errn=(err); \
84  if (errn) mu_error_action(errn, func, __FILE__, __LINE__, 1); } while (0)
85 
86 #define mu_alloc(s) mu_alloc_r(NULL, s)
87 #define mu_realloc(p, s) mu_realloc_r(NULL, p, s)
88 #define mu_free(p) mu_free_r(NULL, p)
89 #define mu_freeall() mu_freeall_r(NULL)
90 
91 DLLSPEC extern int mu_free_r(void **, void *);
92 DLLSPEC extern void
93  mu_freeall_r(void *), *mu_alloc_r(void **, size_t),
94  *mu_realloc_r(void **, void *, size_t);
95 
96 
97 DLLSPEC extern int mu_clock_Hz(void);
98 DLLSPEC extern void mu_wait_time(double);
99 DLLSPEC extern double
100  mu_clock_time(void), mu_cpu_time(void),
101  mu_system_time(void), mu_user_time(void);
102 
103 
104 DLLSPEC extern char *mu_optarg;
105 DLLSPEC extern int
106  mu_opterr, mu_optind, mu_optopt,
107  mu_getopt(int argc, char * const argv[], const char *opts);
108 
109 DLLSPEC extern double
110  mu_time_unary(double (*fn)(double), double x1, double x2, double tmin),
111  mu_time_binary(double (*fn)(double, double), double x1,
112  double x2, double y1, double y2, double tmin);
113 
114 #ifdef __cplusplus
115 } // namespace MUTILS
116 } // extern "C"
117 #endif
118 
119 #endif /* MUTILS_UTIL_H */
MathUtils platform identification macros.