Diffstat (limited to 'gammu/emb/common/misc/misc.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | gammu/emb/common/misc/misc.h | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/gammu/emb/common/misc/misc.h b/gammu/emb/common/misc/misc.h new file mode 100644 index 0000000..8b46170 --- a/dev/null +++ b/gammu/emb/common/misc/misc.h | |||
@@ -0,0 +1,137 @@ | |||
1 | /* (c) 2002-2004 by Marcin Wiacek */ | ||
2 | |||
3 | #ifndef __misc_h | ||
4 | #define __misc_h | ||
5 | |||
6 | #include <stdio.h> | ||
7 | #include <time.h> | ||
8 | #ifdef WIN32 | ||
9 | # include <windows.h> | ||
10 | #endif | ||
11 | |||
12 | #include "../config.h" | ||
13 | |||
14 | #ifndef __cplusplus | ||
15 | #ifndef false | ||
16 | # define false 0 | ||
17 | #endif | ||
18 | #ifndef true | ||
19 | # define true !0 | ||
20 | #endif | ||
21 | #ifndef bool | ||
22 | # define boolchar | ||
23 | #endif | ||
24 | #endif /* __cplusplus */ | ||
25 | |||
26 | #ifdef WIN32 | ||
27 | # define my_sleep(x) ((x)<1000 ? Sleep(1) : Sleep((x)/1000)) | ||
28 | #else | ||
29 | # define my_sleep(x) usleep(x) | ||
30 | #endif | ||
31 | |||
32 | #undef MAX | ||
33 | #define MAX(a,b) ((a)>(b) ? (a) : (b)) | ||
34 | #undef MIN | ||
35 | #define MIN(a,b) ((a)<(b) ? (a) : (b)) | ||
36 | |||
37 | /* ------------------------------------------------------------------------- */ | ||
38 | |||
39 | #define MAX_LINES 50 | ||
40 | |||
41 | int GetLine(FILE *File, char *Line, int count); | ||
42 | |||
43 | typedef struct { | ||
44 | int numbers[MAX_LINES*2]; | ||
45 | } GSM_Lines; | ||
46 | |||
47 | void SplitLines(unsigned char *message, int messagesize, GSM_Lines *lines, unsigned char *whitespaces, int spaceslen, bool eot); | ||
48 | char *GetLineString(unsigned char *message, GSM_Lines lines, int start); | ||
49 | void CopyLineString(unsigned char *dest, unsigned char *src, GSM_Lines lines, int start); | ||
50 | |||
51 | /* ------------------------------------------------------------------------- */ | ||
52 | |||
53 | typedef enum { | ||
54 | DL_BINARY = 1, /* Binary transmission dump */ | ||
55 | DL_TEXT, /* Text transmission dump*/ | ||
56 | DL_TEXTALL, /* Everything */ | ||
57 | DL_TEXTERROR, /* Only errors */ | ||
58 | DL_TEXTDATE, /* Text transmission dump*/ | ||
59 | DL_TEXTALLDATE, /* Everything */ | ||
60 | DL_TEXTERRORDATE /* Only errors */ | ||
61 | } Debug_Level; | ||
62 | |||
63 | typedef struct { | ||
64 | Debug_Leveldl; | ||
65 | FILE *df; | ||
66 | bool use_global; | ||
67 | char *coding; | ||
68 | } Debug_Info; | ||
69 | |||
70 | extern Debug_Infodi; | ||
71 | |||
72 | #ifdef DEBUG | ||
73 | #ifdef __GNUC__ | ||
74 | __attribute__((format(printf, 1, 2))) | ||
75 | #endif | ||
76 | int dbgprintf(const char *format, ...); | ||
77 | #else | ||
78 | # ifndef WIN32 | ||
79 | # define dbgprintf(a...) do { } while (0) | ||
80 | # else | ||
81 | # define dbgprintf | ||
82 | # endif | ||
83 | #endif | ||
84 | |||
85 | #ifdef __GNUC__ | ||
86 | __attribute__((format(printf, 3, 4))) | ||
87 | #endif | ||
88 | int smfprintf(FILE *f, Debug_Level dl, const char *format, ...); | ||
89 | |||
90 | void DumpMessage(FILE *df, Debug_Level dl, const unsigned char *message, int messagesize); | ||
91 | |||
92 | bool GSM_SetDebugLevel(char *info, Debug_Info *di); | ||
93 | |||
94 | /* ------------------------------------------------------------------------- */ | ||
95 | |||
96 | /** | ||
97 | * Structure used for saving date and time | ||
98 | */ | ||
99 | typedef struct { | ||
100 | /** | ||
101 | * The difference between local time and GMT in hours | ||
102 | */ | ||
103 | int Timezone; | ||
104 | |||
105 | unsigned int Second; | ||
106 | unsigned int Minute; | ||
107 | unsigned int Hour; | ||
108 | |||
109 | unsigned int Day; | ||
110 | /** | ||
111 | * January = 1, February = 2, etc. | ||
112 | */ | ||
113 | unsigned int Month; | ||
114 | /** | ||
115 | * Complete year number. Not 03, but 2003 | ||
116 | */ | ||
117 | unsigned int Year; | ||
118 | } GSM_DateTime; | ||
119 | |||
120 | void GSM_GetCurrentDateTime (GSM_DateTime *Date); | ||
121 | char *OSDateTime (GSM_DateTime dt, bool TimeZone); | ||
122 | char *OSDate (GSM_DateTime dt); | ||
123 | char *DayOfWeek (int year, int month, int day); | ||
124 | time_t Fill_Time_T (GSM_DateTime DT, int TZ); | ||
125 | void GetTimeDifference (unsigned long diff, GSM_DateTime *DT, bool Plus, int multi); | ||
126 | void Fill_GSM_DateTime (GSM_DateTime *Date, time_t timet); | ||
127 | bool CheckDate (GSM_DateTime *date); | ||
128 | bool CheckTime (GSM_DateTime *date); | ||
129 | |||
130 | char *GetCompiler(void); | ||
131 | char *GetOS(void); | ||
132 | |||
133 | #endif | ||
134 | |||
135 | /* How should editor hadle tabs in this file? Add editor commands here. | ||
136 | * vim: noexpandtab sw=8 ts=8 sts=8: | ||
137 | */ | ||