Imported gammu 0.90.7
[gammu.git] / common / misc / misc.h
blob9dae75a215145d428b00694ec98e35c7ff5cefdd
2 #ifndef __misc_h
3 #define __misc_h
5 #include <stdio.h>
6 #include <time.h>
7 #ifdef WIN32
8 # include <windows.h>
9 #endif
11 #include "../config.h"
13 #ifndef false
14 # define false (0)
15 #endif
17 #ifndef true
18 # define true (!false)
19 #endif
21 #ifndef bool
22 # define bool int
23 #endif
25 #ifdef WIN32
26 # define my_sleep(x) Sleep(((x) < 1000) ? 1 : ((x) / 1000))
27 #else
28 # define my_sleep(x) usleep(x)
29 #endif
31 #undef MAX
32 #define MAX(a,b) ((a)>(b)?(a):(b))
33 #undef MIN
34 #define MIN(a,b) ((a)<(b)?(a):(b))
36 /* ------------------------------------------------------------------------- */
38 #define MAX_LINES 50
40 int GetLine(FILE *File, char *Line, int count);
42 typedef struct {
43 int numbers[MAX_LINES*2];
44 } GSM_Lines;
46 void SplitLines(unsigned char *message, int messagesize, GSM_Lines *lines, unsigned char *whitespaces, int spaceslen, bool eot);
47 char *GetLineString(unsigned char *message, GSM_Lines lines, int start);
48 void CopyLineString(unsigned char *dest, unsigned char *src, GSM_Lines lines, int start);
50 /* ------------------------------------------------------------------------- */
52 typedef enum {
53 DL_BINARY = 1, /* Binary transmission dump */
54 DL_TEXT, /* Text transmission dump */
55 DL_TEXTALL, /* Everything */
56 DL_TEXTERROR, /* Only errors */
57 DL_TEXTDATE, /* Text transmission dump */
58 DL_TEXTALLDATE, /* Everything */
59 DL_TEXTERRORDATE /* Only errors */
60 } Debug_Level;
62 typedef struct {
63 Debug_Level dl;
64 FILE *df;
65 bool use_global;
66 char *coding;
67 } Debug_Info;
69 extern Debug_Info di;
71 #ifdef DEBUG
72 int dbgprintf(const char *format, ...);
73 #else
74 # ifndef WIN32
75 # define dbgprintf(a...) do { } while (0)
76 # else
77 # define dbgprintf
78 # endif
79 #endif
81 int smfprintf(FILE *f, const char *format, ...);
83 void DumpMessage(FILE *df, const unsigned char *message, int messagesize);
85 bool GSM_SetDebugLevel(char *info, Debug_Info *di);
87 /* ------------------------------------------------------------------------- */
89 /**
90 * Structure used for saving date and time
92 typedef struct {
93 /* Complete year number */
94 unsigned int Year;
95 /* January = 1 */
96 unsigned int Month;
97 unsigned int Day;
98 unsigned int Hour;
99 unsigned int Minute;
100 unsigned int Second;
101 /* The difference between local time and GMT */
102 int Timezone;
103 } GSM_DateTime;
105 void GSM_GetCurrentDateTime (GSM_DateTime *Date);
106 char *OSDateTime (GSM_DateTime dt, bool TimeZone);
107 char *OSDate (GSM_DateTime dt);
108 char *DayOfWeek (int year, int month, int day);
109 time_t Fill_Time_T (GSM_DateTime DT, int TZ);
110 void GetTimeDifference (unsigned long diff, GSM_DateTime *DT, bool Plus, int multi);
111 void Fill_GSM_DateTime (GSM_DateTime *Date, time_t timet);
112 bool CheckDate (GSM_DateTime *date);
113 bool CheckTime (GSM_DateTime *date);
115 #endif
117 /* How should editor hadle tabs in this file? Add editor commands here.
118 * vim: noexpandtab sw=8 ts=8 sts=8: