summaryrefslogtreecommitdiff
path: root/libgammu/misc/misc.h
blob: f702589d333826c5f24cf86b061dbcc2190fead9 (plain)
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
/* (c) 2002-2004 by Marcin Wiacek */

#ifndef __misc_h
#define __misc_h

#if defined(_MSC_VER) && defined(__cplusplus)
    extern "C" {
#endif

#define GAMMU_URL "<http://www.gammu.org>"
#define BACKUP_MAIN_HEADER "; This file format was designed for Gammu and is compatible with Gammu+"
#define BACKUP_INFO_HEADER "; See " GAMMU_URL " for more info"

#include <stdio.h>
#include <time.h>

#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#endif

#include <gammu-config.h>
#include <gammu-types.h>
#include <gammu-datetime.h>
#include <gammu-misc.h>
#include <gammu-debug.h>

/* ------------------------------------------------------------------------- */

/**
 * Listing of cut points for text lines.
 */
typedef struct {
	/**
	 * Cut points.
	 */
	int *numbers;
	/**
	 * Number of currently allocated entries.
	 */
	int allocated;
	/**
	 * Storage for return value.
	 */
	char *retval;
} GSM_CutLines;

/**
 * Calculates string cut points to split it to lines.
 */
void SplitLines(const char *message, const int messagesize, GSM_CutLines *lines, const char *whitespaces, const int spaceslen, const char *quotes, const int quoteslen, const gboolean eot);

/**
 * Returns pointer to static buffer containing line.
 *
 * @param message Parsed message.
 * @param lines Parsed lines information.
 * @param start Which line we want.
 */
const char *GetLineString(const char *message, GSM_CutLines *lines, int start);

/**
 * Returns line length.
 * @param message Parsed message.
 * @param lines Parsed lines information.
 * @param start Which line we want.
 */
int GetLineLength(const char *message, const GSM_CutLines * lines, int start);

/**
 * Initializes line cut structure.
 */
void InitLines(GSM_CutLines *lines);

/**
 * Frees line cut structure.
 */
void FreeLines(GSM_CutLines *lines);

/**
 * Copies line to variable.
 */
void CopyLineString(char *dest, const char *src, const GSM_CutLines * lines, int start);

void GetTimeDifference(unsigned long diff, GSM_DateTime * DT, gboolean Plus,
		       int multi);

GSM_DateTime GSM_AddTime(GSM_DateTime DT, GSM_DeltaTime delta);

/**
 *
 * \ingroup DateTime
 */
int GetDayOfYear(unsigned int year, unsigned int month, unsigned int day);

/**
 *
 * \ingroup DateTime
 */
int GetWeekOfMonth(unsigned int year, unsigned int month, unsigned int day);

/**
 *
 * \ingroup DateTime
 */
int GetDayOfWeek(unsigned int year, unsigned int month, unsigned int day);


#ifdef WIN32
typedef SOCKET socket_type;
#define socket_invalid (INVALID_SOCKET)
#else
typedef int socket_type;
#define socket_invalid (-1)
#endif

/**
 * Strips spaces from string.
 *
 * \param[in,out] buff String where to strip buffers.
 */
void StripSpaces(char *buff);

#if defined(_MSC_VER) && defined(__cplusplus)

    }
#endif

#endif

/* How should editor hadle tabs in this file? Add editor commands here.
 * vim: noexpandtab sw=8 ts=8 sts=8:
 */