summaryrefslogtreecommitdiffabout
path: root/gammu/emb/common/misc/misc.h
Unidiff
Diffstat (limited to 'gammu/emb/common/misc/misc.h') (more/less context) (show whitespace changes)
-rw-r--r--gammu/emb/common/misc/misc.h137
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
41int GetLine(FILE *File, char *Line, int count);
42
43typedef struct {
44 int numbers[MAX_LINES*2];
45} GSM_Lines;
46
47void SplitLines(unsigned char *message, int messagesize, GSM_Lines *lines, unsigned char *whitespaces, int spaceslen, bool eot);
48char *GetLineString(unsigned char *message, GSM_Lines lines, int start);
49void CopyLineString(unsigned char *dest, unsigned char *src, GSM_Lines lines, int start);
50
51/* ------------------------------------------------------------------------- */
52
53typedef 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
63typedef 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
76int 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
88int smfprintf(FILE *f, Debug_Level dl, const char *format, ...);
89
90void DumpMessage(FILE *df, Debug_Level dl, const unsigned char *message, int messagesize);
91
92bool GSM_SetDebugLevel(char *info, Debug_Info *di);
93
94/* ------------------------------------------------------------------------- */
95
96/**
97 * Structure used for saving date and time
98 */
99typedef 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 */