aboutsummaryrefslogtreecommitdiffstats
path: root/dl_item_ok.c
blob: ef919f6e9cf352a03dfe043423ea2e3ff8f034e7 (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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/* 
 * Copyright 1996-2002 - Karl R. Hakimian and David Fries
 *
 * This file is part of datalink.
 *
 * Datalink is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Datalink is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with datalink (see COPYING); if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include "datalink.h"
#include "datalink_private.h"


int dl_item_ok(WatchInfoPtr wi, ItemPtr ip)
{
	char buf[1024];

	switch (ip->type)
	{
	case DL_TIME_TYPE:

		if (ip->data.time.tz_num < 1
		    || ip->data.time.tz_num > wi->max_tz)
		{
			sprintf(buf, "Bad time zone number #%d",
				ip->data.time.tz_num);
			(*dl_error_proc) (buf);
			return (0);
		}

		if (ip->data.time.hours > 23)
		{
			sprintf(buf, "Bad hour in time #%d",
				ip->data.time.tz_num);
			(*dl_error_proc) (buf);
			return (0);
		}

		if (ip->data.time.minutes > 59)
		{
			sprintf(buf, "Bad minute in time #%d",
				ip->data.time.tz_num);
			(*dl_error_proc) (buf);
			return (0);
		}

		if (ip->data.time.month < 1 || ip->data.time.month > 12)
		{
			sprintf(buf, "Bad month in time #%d",
				ip->data.time.tz_num);
			(*dl_error_proc) (buf);
			return (0);
		}

		if (ip->data.time.day < 1 || ip->data.time.day > 31)
		{
			sprintf(buf, "Bad day in time #%d",
				ip->data.time.tz_num);
			(*dl_error_proc) (buf);
			return (0);
		}

		if (!dl_string_ok(ip->data.time.label, wi->max_str))
		{
			sprintf(buf, "Bad characters in label in time #%d",
				ip->data.time.tz_num);
			(*dl_warn_proc) (buf);
		}

		break;
	case DL_ALARM_TYPE:

		if (ip->data.alarm.alarm_num < 1 ||
		    ip->data.alarm.alarm_num > wi->max_alarms)
		{
			sprintf(buf, "Bad alarm number #%d",
				ip->data.alarm.alarm_num);
			(*dl_error_proc) (buf);
			return (0);
		}

		if (ip->data.alarm.hours > 23)
		{
			sprintf(buf, "Bad hour in alarm #%d",
				ip->data.alarm.alarm_num);
			(*dl_error_proc) (buf);
			return (0);
		}

		if (ip->data.alarm.minutes > 59)
		{
			sprintf(buf, "Bad minute in alarm #%d",
				ip->data.alarm.alarm_num);
			(*dl_error_proc) (buf);
			return (0);
		}

		if (ip->data.alarm.month > 12)
		{
			sprintf(buf, "Bad month in alarm #%d",
				ip->data.alarm.alarm_num);
			(*dl_error_proc) (buf);
			return (0);
		}

		if (ip->data.alarm.day > 31)
		{
			sprintf(buf, "Bad day in alarm #%d",
				ip->data.alarm.alarm_num);
			(*dl_error_proc) (buf);
			return (0);
		}

		if (!dl_string_ok(ip->data.alarm.label, wi->max_alarm_str))
		{
			sprintf(buf, "Bad string in alarm #%d",
				ip->data.alarm.alarm_num);
			(*dl_warn_proc) (buf);
		}

		break;
	case DL_TIMER_TYPE:

		if (ip->data.timer.timer_num < 1 ||
		    ip->data.timer.timer_num > wi->max_timers)
		{
			sprintf(buf, "Bad timer number #%d",
				ip->data.timer.timer_num);
			(*dl_error_proc) (buf);
			return (0);
		}

		if (ip->data.timer.hours > 99)
		{
			sprintf(buf, "Bad hour in timer #%d",
				ip->data.timer.timer_num);
			(*dl_error_proc) (buf);
			return (0);
		}

		if (ip->data.timer.minutes > 59)
		{
			sprintf(buf, "Bad minute in timer #%d",
				ip->data.timer.timer_num);
			(*dl_error_proc) (buf);
			return (0);
		}

		if (ip->data.timer.second > 59)
		{
			sprintf(buf, "Bad second in timer #%d",
				ip->data.timer.timer_num);
			(*dl_error_proc) (buf);
			return (0);
		}

		if (ip->data.timer.repeat != 0
		    && ip->data.timer.repeat != 1)
		{
			sprintf(buf, "Bad repeat in timer #%d",
				ip->data.timer.timer_num);
			(*dl_error_proc) (buf);
			return (0);
		}

		if (ip->data.timer.chron != 0 && ip->data.timer.chron != 1)
		{
			sprintf(buf, "Bad chron in timer #%d",
				ip->data.timer.timer_num);
			(*dl_error_proc) (buf);
			return (0);
		}

		if (ip->data.timer.chron && ip->data.timer.repeat)
		{
			sprintf(buf,
				"Can't do repeat and chron at the end of a timer, in timer #%d",
				ip->data.timer.timer_num);
			(*dl_error_proc) (buf);
			return (0);
		}

		if (!dl_string_ok(ip->data.timer.label, wi->max_timer_str))
		{
			sprintf(buf, "Bad string in timer #%d",
				ip->data.timer.timer_num);
			(*dl_warn_proc) (buf);
		}

		break;
	case DL_APP_TYPE:

		if (ip->data.app.month < 1 || ip->data.app.month > 12)
		{
			sprintf(buf, "Bad month in appointment.");
			(*dl_error_proc) (buf);
			return (0);
		}

		if (ip->data.app.day < 1 || ip->data.app.day > 31)
		{
			sprintf(buf, "Bad day in appointment.");
			(*dl_error_proc) (buf);
			return (0);
		}

		if (ip->data.app.time > 0x7f)
		{
			sprintf(buf, "Bad time in appointment.");
			(*dl_error_proc) (buf);
			return (0);
		}

		if (!dl_string_ok(ip->data.app.label, wi->max_str))
		{
			sprintf(buf,
				"Bad characters in label in appointment.");
			(*dl_warn_proc) (buf);
		}

		break;
	case DL_CHRON_TYPE:

		if (!dl_string_ok(ip->data.chron.label, wi->max_chron_str))
		{
			sprintf(buf, "Bad characters in label in chron.");
			(*dl_warn_proc) (buf);
		}

		break;
	case DL_PHONE_TYPE:

		if (!dl_string_ok
		    (ip->data.phone.number, wi->max_phone_str))
		{
			sprintf(buf, "Bad characters in phone number.");
			(*dl_warn_proc) (buf);
		}

		if (!dl_string_ok(ip->data.phone.label, wi->max_str))
		{
			sprintf(buf, "Bad characters in label in phone.");
			(*dl_warn_proc) (buf);
		}

		break;
	case DL_TODO_TYPE:

		if (!dl_string_ok(ip->data.todo.label, wi->max_str))
		{
			sprintf(buf, "Bad characters in label in todo.");
			(*dl_warn_proc) (buf);
		}

		break;
	case DL_ANNIV_TYPE:

		if (ip->data.anniv.month < 1 || ip->data.anniv.month > 12)
		{
			sprintf(buf, "Bad month in anniversary.");
			(*dl_error_proc) (buf);
			return (0);
		}

		if (ip->data.anniv.day < 1 || ip->data.anniv.day > 31)
		{
			sprintf(buf, "Bad day in anniversary.");
			(*dl_error_proc) (buf);
			return (0);
		}

		if (!dl_string_ok(ip->data.anniv.label, wi->max_str))
		{
			sprintf(buf,
				"Bad characters in label in anniversary.");
			(*dl_warn_proc) (buf);
		}

		break;
	case DL_SYSTEM_TYPE:
		break;
	case DL_WRISTAPP_TYPE:
		break;
	case DL_MELODY_TYPE:
		break;
	default:
		(*dl_error_proc) ("Unknown type");
		return (0);
	}

	return (1);
}