HNBody  Version 1.2.1
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 # if !defined(strcasecmp)
29 # define strcasecmp stricmp
30 # define strncasecmp strnicmp
31 # endif
32 #elif !defined(__DECC)
33 # include <strings.h>
34 #endif
35 
36 #ifndef mu_os_mswin
37 # include <unistd.h>
38 #endif
39 
40 #define MU_VERMAX 32 /* Max length of version string. */
41 #define MU_DATEMAX 24 /* Max length of cppdate string. */
42 
43 #ifdef __cplusplus
44 extern "C" {
45 namespace MUTILS {
46 #endif
47 
48 DLLSPEC extern void
49  mu_cppdate(char str[ /*MU_DATEMAX*/ ], const char *date, const char *time),
50  mu_error_action(int, const char *, const char *, int, int),
51  mu_split_tag(char pre[], int *maj, int *min, int *clas, int *bug,
52  int *y, int *m, int *d, const char *tag);
53 
54 DLLSPEC extern char
55  *mu_utoa9(char *str, unsigned i, int strip),
56  *mu_fgetline(char *, long int, FILE *);
57 
58 DLLSPEC extern const char
59  *mu_platform(void),
60  *mu_version(void),
61  *mu_verstr(char verstr[ /*MU_VERMAX*/ ], const char *pre,
62  int maj, int min, int clas, int bug);
63 
64 DLLSPEC extern int
65  mu_ppmtext(char *, char *, int, int, int),
66  mu_vernum(const char *name, const char *cvs);
67 
68 #define MU_iferr_abort(err, func) do { \
69  if (err) mu_error_action(-1, func, __FILE__, __LINE__, -1); } while (0)
70 
71 #define MU_iferr_warn(err, func) do { \
72  if (err) mu_error_action(-1, func, __FILE__, __LINE__, 0); } while (0)
73 
74 #define MU_iferr(err, func) do { \
75  if (err) mu_error_action(-1, func, __FILE__, __LINE__, 1); } while (0)
76 
77 #define MU_iferrn_abort(err, func) do { \
78  int errn=(err); \
79  if (errn) mu_error_action(errn, func, __FILE__, __LINE__, -1); } while (0)
80 
81 #define MU_iferrn_warn(err, func) do { \
82  int errn=(err); \
83  if (errn) mu_error_action(errn, func, __FILE__, __LINE__, 0); } while (0)
84 
85 #define MU_iferrn(err, func) do { \
86  int errn=(err); \
87  if (errn) mu_error_action(errn, func, __FILE__, __LINE__, 1); } while (0)
88 
89 #define mu_alloc(s) mu_alloc_r(NULL, s)
90 #define mu_realloc(p, s) mu_realloc_r(NULL, p, s)
91 #define mu_free(p) mu_free_r(NULL, p)
92 #define mu_freeall() mu_freeall_r(NULL)
93 
94 DLLSPEC extern int mu_free_r(void **, void *);
95 DLLSPEC extern void
96  mu_freeall_r(void *), *mu_alloc_r(void **, size_t),
97  *mu_realloc_r(void **, void *, size_t);
98 
99 
100 DLLSPEC extern int mu_clock_Hz(void);
101 DLLSPEC extern void mu_wait_time(double);
102 DLLSPEC extern double
103  mu_clock_time(void), mu_cpu_time(void),
104  mu_system_time(void), mu_user_time(void);
105 
106 
107 DLLSPEC extern char *mu_optarg;
108 DLLSPEC extern int
109  mu_opterr, mu_optind, mu_optopt,
110  mu_getopt(int argc, char * const argv[], const char *opts);
111 
112 DLLSPEC extern double
113  mu_time_unary(double (*fn)(double), double x1, double x2, double tmin);
114 
115 DLLSPEC extern double
116  mu_time_binary(double (*fn)(double, double), double x1,
117  double x2, double y1, double y2, double tmin);
118 
119 DLLSPEC extern double
120  mu_time_trinary(double (*fn)(double, double, double), double x1,
121  double x2, double y1, double y2, double z1, double z2,
122  double tmin);
123 
124 #ifdef __cplusplus
125 } // namespace MUTILS
126 } // extern "C"
127 #endif
128 
129 #endif /* MUTILS_UTIL_H */
MathUtils platform identification macros.