mess822x 1.24
mess822x
Loading...
Searching...
No Matches
parsedate.c
Go to the documentation of this file.
1#include "buffer.h"
2#include "logmsg.h"
3#include "getln.h"
4#include "mess822.h"
5#include "leapsecs.h"
6#include "caltime.h"
7#include "tai.h"
8#include "exit.h"
9
10#define WHO "parsedate"
11
12static void nomem()
13{
14 logmsg(WHO,111,FATAL,"out of memory");
15}
16
17stralloc line = {0};
19
21struct tai sec;
22
23int main()
24{
25 int i;
26
27 if (leapsecs_init() == -1)
28 logmsg(WHO,111,FATAL,"unable to init leapsecs: ");
29
30 for (;;) {
31 if (getln(buffer_0,&line,&match,'\n') == -1)
32 logmsg(WHO,111,FATAL,"unable to read input: ");
33 if (!line.len) break;
34 if (match) --line.len;
35
36 for (i = 0; i < line.len; ++i)
37 if (line.s[i] == 0)
38 line.s[i] = '\n';
39 if (!stralloc_0(&line)) nomem();
40
41 t.known = 0;
42 if (!mess822_when(&t,line.s)) nomem();
43
44 if (t.known) {
45 if (!stralloc_ready(&line,caltime_fmt((char *) 0,&t.ct))) nomem();
46 buffer_put(buffer_1,line.s,caltime_fmt(line.s,&t.ct));
47 if (t.known == 1)
48 buffer_put(buffer_1,"?",1);
49 buffer_put(buffer_1,"\t",1);
50
51 caltime_tai(&t.ct,&sec);
52
53 caltime_utc(&t.ct,&sec,(int *) 0,(int *) 0);
54 if (!stralloc_ready(&line,caltime_fmt((char *) 0,&t.ct))) nomem();
55 buffer_put(buffer_1,line.s,caltime_fmt(line.s,&t.ct));
56 }
57
58 buffer_puts(buffer_1,"\n");
59 if (!match) break;
60 }
61
62 buffer_flush(buffer_1);
63 _exit(0);
64}
int mess822_when(mess822_time *, char *)
Definition mess822_when.c:9
int leapsecs_init(void)
stralloc line
Definition 822body.c:9
int match
Definition 822body.c:10
#define WHO
Definition 822body.c:7
unsigned int caltime_fmt(char *s, struct caltime *ct)
Definition caltime_fmt.c:4
int main()
Definition parsedate.c:23
void nomem()
Definition quote.c:8
void caltime_tai(struct caltime *ct, struct tai *t)
Definition caltime_tai.c:8
struct tai sec
Definition 822date.c:20
mess822_time t
Definition 822date.c:19
void caltime_utc(struct caltime *ct, struct tai *t, int *pwday, int *pyday)
Definition caltime_utc.c:8