-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocal.h
executable file
·177 lines (137 loc) · 3.98 KB
/
local.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#ifndef _LOCAL_H_
#define _LOCAL_H_
/*
* String Handling
*/
#ifndef __KERNEL__
#include <string.h>
#endif
#define STREQ( s1, s2 ) (strcmp( s1, s2 ) == 0)
#define STREQN( s1, s2, n ) (strncmp( s1, s2, n ) == 0)
#define STREQNL( s1, s2 ) (strncmp( s1, s2, strlen(s2) ) == 0)
/*
* Range Checking and simple math
*/
#define IN_RANGE(xx,ll,rr) ((xx)>=(ll)&&(xx)<=(rr))
#define CLAMP(xx,ll,rr) ((xx) = (xx)<(ll)? (ll): (xx)>(rr)? (rr): (xx))
#define SWAP(aa,bb,tt) ( tt = aa, aa = bb, bb = tt )
#define MAX(aa,bb) ((aa)>=(bb)?(aa):(bb))
#define MIN(aa,bb) ((aa)<=(bb)?(aa):(bb))
#define ABS(aa) ((aa)>0?(aa):-(aa))
#define SQR(aa) ((aa)*(aa))
#define SIGN(aa) ((aa)>=0? 1: -1)
/*
* boolean values
*/
#ifndef OK
#define OK 0
#endif
#ifndef ERR
#define ERR -1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef ON
#define ON 1
#endif
#ifndef OFF
#define OFF 0
#endif
#define __U32__
typedef unsigned u32;
typedef unsigned short u16;
typedef unsigned char u8;
#if defined __cplusplus
extern "C" {
#endif
extern int acq200_debug;
#if defined __cplusplus
};
#endif
#ifndef FN
#define FN __FUNCTION__
#endif
#include <sys/syslog.h>
#ifndef PROCLOGNAME
#define PROCLOGNAME "acq200control"
#endif
#define ACQ200_SYSLOG_SCREEN 1
#define ACQ200_SYSLOG_SYSLOG 2
#ifndef ACQ200_SYSLOG_MODE
#define ACQ200_SYSLOG_MODE (ACQ200_SYSLOG_SCREEN|ACQ200_SYSLOG_SYSLOG)
#endif
#if ((ACQ200_SYSLOG_MODE & ACQ200_SYSLOG_SCREEN) != 0)
#define _ACQ200_SYSLOG_SCREEN(pri, fmt, args...) fprintf(stderr, fmt, ##args)
#else
#define _ACQ200_SYSLOG_SCREEN(pri, fmt, args...)
#endif
#if ((ACQ200_SYSLOG_MODE & ACQ200_SYSLOG_SYSLOG) != 0)
#define _ACQ200_SYSLOG_SYSLOG(pri, fmt, args...)\
do { \
openlog(PROCLOGNAME, 0, LOG_USER); \
syslog(pri, fmt, ## args); \
closelog(); \
} while (0)
#else
#define _ACQ200_SYSLOG_SYSLOG(pri, fmt, args...)
#endif
#define ACQ200_SYSLOG(pri, fmt, args...) \
do { \
_ACQ200_SYSLOG_SCREEN(pri, fmt, ## args); \
_ACQ200_SYSLOG_SYSLOG(pri, fmt, ## args); \
}while(0)
//#define info(fmt, arg...) printf("%s:" fmt "\n", FN, ## arg)
#define info(format, arg...) \
ACQ200_SYSLOG(LOG_INFO, "%s " format "\n", FN, ## arg )
#define err(format, arg...) \
ACQ200_SYSLOG(LOG_ERR, "%s ERROR:" format "\n", FN, ## arg )
#define dbg(lvl, format, arg...) \
do { \
if(acq200_debug>=lvl ){ \
if (lvl <= 1){ \
ACQ200_SYSLOG( LOG_DEBUG, \
"%s " format "\n", \
FN, ## arg ); \
}else{ \
fprintf(stderr, \
"deb(%d) %s " format "\n", \
lvl, FN, ## arg ); \
} \
} \
} while(0)
static inline char* chomp(char *src) {
char *plast = src + strlen(src) - 1;
while(*plast == '\n' || *plast == '\r'){
*plast-- = '\0';
if (plast == src){
break;
}
}
return src;
}
static inline char* tr(char *src, char c1, char c2){
int ii = 0;
int i2 = strlen(src);
for (ii = 0; ii < i2; ii++){
if (src[ii] == c1){
src[ii] = c2;
}
}
return src;
}
#define dbgnl(lvl, format, arg...) \
do { \
if(acq200_debug>=lvl ){ \
if (lvl <= 1) \
ACQ200_SYSLOG( LOG_DEBUG, "%s " format, \
FN, ## arg ); \
fprintf(stderr, \
"deb(%d) %s " format, \
lvl, FN, ## arg ); \
} \
} while(0)
#endif