]> Pileus Git - ~andy/lamechat/blob - chat.c
Import and basic UI working.
[~andy/lamechat] / chat.c
1 /*
2  * Copyright (C) 2017 Andy Spencer <andy753421@gmail.com>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include <stdlib.h>
19 #include <string.h>
20 #include <time.h>
21
22 #include "util.h"
23 #include "conf.h"
24 #include "chat.h"
25
26 /* Global data */
27 log_t *chat_log;
28 int    chat_len;
29
30 /* Local data */
31 static buf_t log_buf;
32
33 /* Local functions */
34
35 /* View init */
36 void chat_init(void)
37 {
38         chat_log = log_buf.data;
39         chat_len = 0;
40
41         // Append some lines */
42         chat_send("Copyright (C) 2017 Andy Spencer <andy753421@gmail.com>");
43         chat_send("This program 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 3 of the License, or (at your option) any later version.");
44         chat_send("This program 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.");
45         chat_send("You should have received a copy of the GNU General Public License along with this program.  If not, see <http://www.gnu.org/licenses/>.");
46 }
47
48 void chat_send(const char *msg)
49 {
50         append(&log_buf, NULL, sizeof(log_t));
51         chat_log = log_buf.data;
52
53         log_t *log = &chat_log[chat_len];
54         log->when = time(NULL);
55         log->from = "andy";
56         log->room = "room";
57         log->msg  = strcopy(msg);
58
59         chat_len++;
60 }
61
62 void chat_exit(void)
63 {
64         for (int i = 0; i < chat_len; i++)
65                 free((void*)chat_log[i].msg);
66         release(&log_buf);
67 }