FreeBASIC
0.91.0
Main Page
Data Structures
Files
File List
Globals
time_timeset.c
Go to the documentation of this file.
1
/* settime function */
2
3
#include "
fb.h
"
4
#include <ctype.h>
5
6
/*:::::*/
7
FBCALL
int
fb_SetTime
(
FBSTRING
*time )
8
{
9
10
/* valid formats:
11
hh
12
hh:mm
13
hh:mm:ss
14
*/
15
if
( (time !=
NULL
) && (time->
data
!=
NULL
) )
16
{
17
18
char
*t, c;
19
int
i, h, m = 0, s = 0;
20
21
/* get hours */
22
h = 0;
23
for
( i = 0, t = time->
data
; (c = *t) && isdigit(c); t++, i += 10 )
24
{
25
h = h * i + c -
'0'
;
26
}
27
28
if
( (h > 23) || (c !=
'\0'
&& c !=
':'
) )
29
{
30
return
fb_ErrorSetNum
(
FB_RTERROR_ILLEGALFUNCTIONCALL
);
31
}
32
33
if
( c !=
'\0'
)
34
{
35
/* get minutes */
36
m = 0;
37
for
( i = 0, t++; (c = *t) && isdigit(c); t++, i += 10 )
38
{
39
m = m * i + c -
'0'
;
40
}
41
42
if
( (m > 59) || (c !=
'\0'
&& c !=
':'
) )
43
{
44
return
fb_ErrorSetNum
(
FB_RTERROR_ILLEGALFUNCTIONCALL
);
45
}
46
47
if
( c !=
'\0'
)
48
{
49
/* get seconds */
50
s = 0;
51
for
(i = 0, t++; (c = *t) && isdigit(c); t++, i += 10)
52
s = s * i + c -
'0'
;
53
}
54
}
55
56
if
( (s > 59) || (c !=
'\0'
) )
57
{
58
return
fb_ErrorSetNum
(
FB_RTERROR_ILLEGALFUNCTIONCALL
);
59
}
60
61
62
if
(
fb_hSetTime
( h, m, s ) )
63
{
64
return
fb_ErrorSetNum
(
FB_RTERROR_ILLEGALFUNCTIONCALL
);
65
}
66
}
67
68
/* del if temp */
69
fb_hStrDelTemp
( time );
70
71
return
fb_ErrorSetNum
(
FB_RTERROR_OK
);
72
}
73
rtlib
time_timeset.c
Generated on Thu Jan 23 2014 19:40:14 for FreeBASIC by
1.8.4