00001 #ifndef MUTILS_UTIL_H
00002 #define MUTILS_UTIL_H
00003
00013 #include "mutils/platform.h"
00014
00015 #ifdef __cplusplus
00016 # include <cstdio>
00017 # include <cstdlib>
00018 # include <cstring>
00019 using std::FILE;
00020 using std::size_t;
00021 #else
00022 # include <stdio.h>
00023 # include <stdlib.h>
00024 # include <string.h>
00025 #endif
00026
00027 #ifdef mu_os_mswin
00028 #define strcasecmp stricmp
00029 #define strncasecmp strnicmp
00030 #elif !defined(__DECC)
00031 #include <strings.h>
00032 #endif
00033
00034 #ifndef mu_os_mswin
00035 #include <unistd.h>
00036 #endif
00037
00038 #define MU_VERMAX 32
00039 #define MU_DATEMAX 24
00040
00041 #ifdef __cplusplus
00042 extern "C" {
00043 namespace MUTILS {
00044 #endif
00045
00046 DLLSPEC extern void
00047 mu_cppdate(char str[ ], const char *date, const char *time),
00048 mu_error_action(int, const char *, const char *, int, int),
00049 mu_split_tag(char pre[], int *maj, int *min, int *clas, int *bug,
00050 int *y, int *m, int *d, const char *tag);
00051
00052 DLLSPEC extern char
00053 *mu_fgetline(char *, long int, FILE *);
00054
00055 DLLSPEC extern const char
00056 *mu_platform(void),
00057 *mu_version(void),
00058 *mu_verstr(char verstr[ ], const char *pre,
00059 int maj, int min, int clas, int bug);
00060
00061 DLLSPEC extern int
00062 mu_ppmtext(char *, char *, int, int, int),
00063 mu_vernum(const char *name, const char *cvs);
00064
00065 #define MU_iferr_abort(err, func) do { \
00066 if (err) mu_error_action(-1, func, __FILE__, __LINE__, -1); } while (0)
00067
00068 #define MU_iferr_warn(err, func) do { \
00069 if (err) mu_error_action(-1, func, __FILE__, __LINE__, 0); } while (0)
00070
00071 #define MU_iferr(err, func) do { \
00072 if (err) mu_error_action(-1, func, __FILE__, __LINE__, 1); } while (0)
00073
00074 #define MU_iferrn_abort(err, func) do { \
00075 int errn=(err); \
00076 if (errn) mu_error_action(errn, func, __FILE__, __LINE__, -1); } while (0)
00077
00078 #define MU_iferrn_warn(err, func) do { \
00079 int errn=(err); \
00080 if (errn) mu_error_action(errn, func, __FILE__, __LINE__, 0); } while (0)
00081
00082 #define MU_iferrn(err, func) do { \
00083 int errn=(err); \
00084 if (errn) mu_error_action(errn, func, __FILE__, __LINE__, 1); } while (0)
00085
00086 #define mu_alloc(s) mu_alloc_r(NULL, s)
00087 #define mu_realloc(p, s) mu_realloc_r(NULL, p, s)
00088 #define mu_free(p) mu_free_r(NULL, p)
00089 #define mu_freeall() mu_freeall_r(NULL)
00090
00091 DLLSPEC extern int mu_free_r(void **, void *);
00092 DLLSPEC extern void
00093 mu_freeall_r(void *), *mu_alloc_r(void **, size_t),
00094 *mu_realloc_r(void **, void *, size_t);
00095
00096
00097 DLLSPEC extern int mu_clock_Hz(void);
00098 DLLSPEC extern void mu_wait_time(double);
00099 DLLSPEC extern double
00100 mu_clock_time(void), mu_cpu_time(void),
00101 mu_system_time(void), mu_user_time(void);
00102
00103
00104 DLLSPEC extern char *mu_optarg;
00105 DLLSPEC extern int
00106 mu_opterr, mu_optind, mu_optopt,
00107 mu_getopt(int argc, char * const argv[], const char *opts);
00108
00109 DLLSPEC extern double
00110 mu_time_unary(double (*fn)(double), double x1, double x2, double tmin),
00111 mu_time_binary(double (*fn)(double, double), double x1,
00112 double x2, double y1, double y2, double tmin);
00113
00114 #ifdef __cplusplus
00115 }
00116 }
00117 #endif
00118
00119 #endif