mess822x
1.24
mess822x
Loading...
Searching...
No Matches
mess822x-1.24
src
822date.c
Go to the documentation of this file.
1
#include <sys/types.h>
2
#include <time.h>
3
#include "buffer.h"
4
#include "logmsg.h"
5
#include "getln.h"
6
#include "
mess822.h
"
7
#include "exit.h"
8
#include "
leapsecs.h
"
9
#include "
caltime.h
"
10
#include "tai.h"
11
12
#define WHO "822date"
13
14
static
void
nomem
()
15
{
16
logmsg(
WHO
,111,FATAL,
"out of memory"
);
17
}
18
19
mess822_time
t
;
20
struct
tai
sec
;
21
unsigned
char
secpack
[TAI_PACK];
22
time_t
secunix
;
23
24
mess822_header
h
=
MESS822_HEADER
;
25
mess822_action
a
[] = {
26
{
"date"
, 0, 0, 0, 0, &
t
, 0 }
27
, { 0, 0, 0, 0, 0, 0, 0 }
28
} ;
29
30
stralloc
line
= {0};
31
int
match
;
32
33
int
main
(
int
argc,
char
**argv)
34
{
35
if
(
leapsecs_init
() == -1)
36
logmsg(
WHO
,111,FATAL,
"unable to init leapsecs: "
);
37
38
if
(argv[1])
39
a
[0].name = argv[1];
40
41
if
(!
mess822_begin
(&
h
,
a
))
nomem
();
42
for
(;;) {
43
if
(getln(buffer_0,&
line
,&
match
,
'\n'
) == -1)
44
logmsg(
WHO
,111,FATAL,
"unable to read input: "
);
45
if
(!
mess822_ok
(&
line
))
break
;
46
if
(!
mess822_line
(&
h
,&
line
))
nomem
();
47
if
(!
match
)
break
;
48
}
49
if
(!
mess822_end
(&
h
))
nomem
();
50
51
if
(!
t
.known) _exit(100);
52
53
if
(!stralloc_ready(&
line
,
caltime_fmt
((
char
*) 0,&
t
.ct)))
nomem
();
54
buffer_put(buffer_1,
line
.s,
caltime_fmt
(
line
.s,&
t
.ct));
55
buffer_put(buffer_1,
"\n"
,1);
56
57
caltime_tai
(&
t
.ct,&
sec
);
58
59
caltime_utc
(&
t
.ct,&
sec
,(
int
*) 0,(
int
*) 0);
60
if
(!stralloc_ready(&
line
,
caltime_fmt
((
char
*) 0,&
t
.ct)))
nomem
();
61
buffer_put(buffer_1,
line
.s,
caltime_fmt
(
line
.s,&
t
.ct));
62
buffer_put(buffer_1,
"\n"
,1);
63
64
tai_pack((
char
*)
secpack
,&
sec
);
65
secunix
=
secpack
[0] - 64;
66
secunix
= (
secunix
<< 8) +
secpack
[1];
67
secunix
= (
secunix
<< 8) +
secpack
[2];
68
secunix
= (
secunix
<< 8) +
secpack
[3];
69
secunix
= (
secunix
<< 8) +
secpack
[4];
70
secunix
= (
secunix
<< 8) +
secpack
[5];
71
secunix
= (
secunix
<< 8) +
secpack
[6];
72
secunix
= (
secunix
<< 8) +
secpack
[7];
73
secunix
-= 10;
74
buffer_puts(buffer_1,ctime(&
secunix
));
75
76
buffer_flush(buffer_1);
77
_exit(0);
78
}
mess822.h
mess822_line
int mess822_line(mess822_header *, stralloc *)
Definition
mess822_line.c:107
mess822_end
int mess822_end(mess822_header *)
Definition
mess822_line.c:26
mess822_ok
int mess822_ok(stralloc *)
Definition
mess822_ok.c:4
MESS822_HEADER
#define MESS822_HEADER
Definition
mess822.h:48
mess822_begin
int mess822_begin(mess822_header *, mess822_action *)
Definition
mess822_line.c:5
leapsecs.h
leapsecs_init
int leapsecs_init(void)
Definition
leapsecs_init.c:5
caltime.h
line
stralloc line
Definition
822body.c:9
match
int match
Definition
822body.c:10
WHO
#define WHO
Definition
822body.c:7
caltime_fmt
unsigned int caltime_fmt(char *s, struct caltime *ct)
Definition
caltime_fmt.c:4
nomem
void nomem()
Definition
quote.c:8
caltime_tai
void caltime_tai(struct caltime *ct, struct tai *t)
Definition
caltime_tai.c:8
a
mess822_action a[]
Definition
822date.c:25
sec
struct tai sec
Definition
822date.c:20
h
mess822_header h
Definition
822date.c:24
secunix
time_t secunix
Definition
822date.c:22
secpack
unsigned char secpack[TAI_PACK]
Definition
822date.c:21
t
mess822_time t
Definition
822date.c:19
main
int main()
Definition
822print.c:351
caltime_utc
void caltime_utc(struct caltime *ct, struct tai *t, int *pwday, int *pyday)
Definition
caltime_utc.c:8
mess822_time
Definition
mess822.h:7
mess822_action
Definition
mess822.h:12
mess822_header
Definition
mess822.h:22
Generated on
for mess822x by
1.14.0