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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
/*
* Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*---------------------------------------------------------------------------
*
* isdntel - isdn4bsd telephone answering machine support
* ======================================================
*
* $FreeBSD$
*
* last edit-date: [Sun Feb 14 10:19:38 1999]
*
*----------------------------------------------------------------------------*/
#include "defs.h"
/*---------------------------------------------------------------------------*
* create a doubly linked list in sorted order, return pointer to new
* first element of list
*---------------------------------------------------------------------------*/
struct onefile *store
(register struct onefile *new, /* new entry to store into list */
register struct onefile *top) /* current first entry in list */
{
register struct onefile *old, *p;
if (last == NULL) /* enter very first element ? */
{
new->next = NULL;
new->prev = NULL;
last = new; /* init last */
return (new); /* return new first */
}
p = top; /* p = old first element */
old = NULL;
while (p)
{
if ((strcmp(p->fname, new->fname)) < 0) /* current less new ? */
{
old = p;
p = p->next;
}
else
{ /* current >= new */
if (p->prev)
{
p->prev->next = new;
new->next = p;
new->prev = p->prev;
p->prev = new;
return (top);
}
new->next = p;
new->prev = NULL;
p->prev = new;
return (new);
}
}
old->next = new;
new->next = NULL;
new->prev = old;
last = new;
return (first);
}
/*---------------------------------------------------------------------------*
* read current directory and build up a doubly linked sorted list
*---------------------------------------------------------------------------*/
int
fill_list(void)
{
#if defined(__FreeBSD__) && __FreeBSD__ >= 3
register struct dirent *dp;
#else
register struct direct *dp;
#endif
register struct onefile *new_entry;
register DIR *dirp;
int flcnt = 0;
char tmp[80];
char *s, *d;
if ((dirp = opendir(spooldir)) == NULL)
fatal("cannot open spooldirectory %s!\n", spooldir);
for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
{
if(!isdigit(*(dp->d_name)))
continue;
if ((new_entry = (struct onefile *) malloc(sizeof(struct onefile))) == NULL)
{
fatal("files.c, fill_list(): structure onefile malloc failed");
}
/* alloc filename memory and copy name into it */
if ((new_entry->fname = (char *) malloc(strlen(dp->d_name) + 1)) == NULL)
{
fatal("files.c, fill_list(): malloc filename string memory failed");
}
strcpy(new_entry->fname, dp->d_name);
/* fill in remaining fields from filename */
tmp[0] = dp->d_name[4]; /* day msb */
tmp[1] = dp->d_name[5]; /* day lsb */
tmp[2] = '.';
tmp[3] = dp->d_name[2]; /* month msb */
tmp[4] = dp->d_name[3]; /* month lsb */
tmp[5] = '.';
tmp[6] = dp->d_name[0]; /* year msb */
tmp[7] = dp->d_name[1]; /* year lsb */
tmp[8] = '\0';
if((new_entry->date = (char *) malloc(strlen(tmp) + 1)) == NULL)
{
fatal("files.c, fill_list(): malloc date string memory failed");
}
strcpy(new_entry->date, tmp);
tmp[0] = dp->d_name[6]; /* hour msb */
tmp[1] = dp->d_name[7]; /* hour lsb */
tmp[2] = ':';
tmp[3] = dp->d_name[8]; /* minute msb */
tmp[4] = dp->d_name[9]; /* minute lsb */
tmp[5] = ':';
tmp[6] = dp->d_name[10]; /* second msb */
tmp[7] = dp->d_name[11]; /* second lsb */
tmp[8] = '\0';
if((new_entry->time = (char *) malloc(strlen(tmp) + 1)) == NULL)
{
fatal("files.c, fill_list(): malloc time string memory failed");
}
strcpy(new_entry->time, tmp);
/* destination number */
s = &dp->d_name[13];
d = &tmp[0];
while(*s && (*s != '-'))
*d++ = *s++;
*d = '\0';
if((new_entry->dstnumber = (char *) malloc(strlen(tmp) + 1)) == NULL)
{
fatal("files.c, fill_list(): malloc dstnumber string memory failed");
}
strcpy(new_entry->dstnumber, tmp);
/* source number */
s++;
d = &tmp[0];
while(*s && (*s != '-'))
*d++ = *s++;
*d = '\0';
if((new_entry->srcnumber = (char *) malloc(strlen(tmp) + 1)) == NULL)
{
fatal("files.c, fill_list(): malloc srcnumber string memory failed");
}
strcpy(new_entry->srcnumber, tmp);
/* length in seconds */
s++;
d = &tmp[0];
while(*s && (*s != '-'))
*d++ = *s++;
*d = '\0';
if((new_entry->seconds = (char *) malloc(strlen(tmp) + 1)) == NULL)
{
fatal("files.c, fill_list(): malloc seconds string memory failed");
}
strcpy(new_entry->seconds, tmp);
/* search for alias and add if found */
new_entry->alias = get_alias(new_entry->srcnumber);
/* sort entry into linked list */
first = store(new_entry, first);
flcnt++; /* increment file count */
}
closedir(dirp); /* close current dir */
return(flcnt); /* ok return */
}
/*---------------------------------------------------------------------------*
* free the current malloc'ed list
*---------------------------------------------------------------------------*/
void
free_list(void)
{
register struct onefile *dir;
register struct onefile *tmp;
dir = first; /* start of linked list */
while (dir) /* free all */
{
tmp = dir->next; /* save ptr to next entry */
free(dir->fname); /* free filename space */
free(dir->date);
free(dir->time);
free(dir->srcnumber);
free(dir->dstnumber);
free(dir->seconds);
free(dir); /* free struct space */
dir = tmp; /* ptr = ptr to next entry */
}
first = NULL; /* first ptr = NULL */
last = NULL; /* last ptr = NULL */
}
/*---------------------------------------------------------------------------*
* delete a file
*---------------------------------------------------------------------------*/
void
delete(struct onefile *this)
{
char buffer[MAXPATHLEN+1];
if(this == NULL)
return;
sprintf(buffer, "%s", this->fname);
unlink(buffer);
free_list();
wclear(main_w);
init_files(cur_pos);
}
/*---------------------------------------------------------------------------*
* reread the spool directory
*---------------------------------------------------------------------------*/
void
reread(void)
{
free_list();
wclear(main_w);
init_files(cur_pos);
}
/*---------------------------------------------------------------------------*
* play a file
*---------------------------------------------------------------------------*/
void
play(struct onefile *this)
{
char buffer[MAXPATHLEN+1];
if(this == NULL)
return;
sprintf(buffer, playstring, this->fname);
system(buffer);
}
/*---------------------------------- EOF -------------------------------------*/
|