-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaway.c
76 lines (61 loc) · 1.38 KB
/
away.c
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
/**
** bsflite - bs-free AIM client
**
** (C) 2003-2007 by Claudio Leite <leitec at leitec dot org>
**
** NO WARRANTY. Read the file COPYING for more details.
**/
#include "bsf.h"
extern struct Conn *conn;
/* PROTO */
void
read_away_messages(void)
{
FILE *away;
char buf[1024], *tptr;
struct AwayMessages *nn, *tv, *todel;
#if !defined(__MINGW32__) && !defined(__DJGPP__)
char *home;
#ifdef PLAN9
if ((home = getenv("home")) == NULL)
home = ".";
snprintf(buf, sizeof(buf), "%s/lib/bsflite/awaymessages", home);
#else
if ((home = getenv("HOME")) == NULL)
home = ".";
snprintf(buf, sizeof(buf), "%s/.bsflite/awaymessages", home);
#endif
#else
snprintf(buf, sizeof(buf), "awaymsgs.txt");
#endif
away = fopen(buf, "r");
if (away == NULL)
return;
if (conn->awaymsgs != NULL) {
for (tv = conn->awaymsgs; tv != NULL;) {
todel = tv;
tv = tv->next;
free(todel);
}
conn->awaymsgs = NULL;
}
while (!feof(away)) {
memset(buf, 0, sizeof(buf));
fgets(buf, sizeof(buf), away);
tptr = strchr(buf, '\n');
if (tptr != NULL)
tptr[0] = 0;
if (strlen(buf) == 0)
break;
nn = malloc(sizeof(struct AwayMessages));
nn->message = strdup(buf);
nn->next = NULL;
if (conn->awaymsgs == NULL) {
conn->awaymsgs = nn;
} else {
for (tv = conn->awaymsgs; tv->next != NULL; tv = tv->next);
tv->next = nn;
}
}
fclose(away);
}