2 * Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 *---------------------------------------------------------------------------
27 * isdntel - isdn4bsd telephone answering machine support
28 * ======================================================
30 * $Id: files.c,v 1.8 1999/12/13 21:25:26 hm Exp $
32 * $FreeBSD: src/usr.sbin/i4b/isdntel/files.c,v 1.6.2.1 2001/08/01 17:45:06 obrien Exp $
33 * $DragonFly: src/usr.sbin/i4b/isdntel/files.c,v 1.6 2005/10/30 23:00:57 swildner Exp $
35 * last edit-date: [Mon Dec 13 21:54:06 1999]
37 *----------------------------------------------------------------------------*/
41 /*---------------------------------------------------------------------------*
42 * create a doubly linked list in sorted order, return pointer to new
43 * first element of list
44 *---------------------------------------------------------------------------*/
46 store(struct onefile *new, /* new entry to store into list */
47 struct onefile *top) /* current first entry in list */
49 struct onefile *old, *p;
51 if (last == NULL) /* enter very first element ? */
55 last = new; /* init last */
56 return (new); /* return new first */
58 p = top; /* p = old first element */
62 if ((strcmp(p->fname, new->fname)) < 0) /* current less new ? */
68 { /* current >= new */
91 /*---------------------------------------------------------------------------*
92 * read current directory and build up a doubly linked sorted list
93 *---------------------------------------------------------------------------*/
97 #if defined(__DragonFly__)
102 struct onefile *new_entry;
108 if ((dirp = opendir(spooldir)) == NULL)
109 fatal("cannot open spooldirectory %s!\n", spooldir);
111 for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
113 if(!isdigit(*(dp->d_name)))
116 if ((new_entry = (struct onefile *) malloc(sizeof(struct onefile))) == NULL)
118 fatal("files.c, fill_list(): structure onefile malloc failed");
121 /* alloc filename memory and copy name into it */
123 if ((new_entry->fname = (char *) malloc(strlen(dp->d_name) + 1)) == NULL)
125 fatal("files.c, fill_list(): malloc filename string memory failed");
128 strcpy(new_entry->fname, dp->d_name);
130 /* fill in remaining fields from filename */
132 tmp[0] = dp->d_name[4]; /* day msb */
133 tmp[1] = dp->d_name[5]; /* day lsb */
135 tmp[3] = dp->d_name[2]; /* month msb */
136 tmp[4] = dp->d_name[3]; /* month lsb */
138 tmp[6] = dp->d_name[0]; /* year msb */
139 tmp[7] = dp->d_name[1]; /* year lsb */
142 if((new_entry->date = (char *) malloc(strlen(tmp) + 1)) == NULL)
144 fatal("files.c, fill_list(): malloc date string memory failed");
147 strcpy(new_entry->date, tmp);
149 tmp[0] = dp->d_name[6]; /* hour msb */
150 tmp[1] = dp->d_name[7]; /* hour lsb */
152 tmp[3] = dp->d_name[8]; /* minute msb */
153 tmp[4] = dp->d_name[9]; /* minute lsb */
155 tmp[6] = dp->d_name[10]; /* second msb */
156 tmp[7] = dp->d_name[11]; /* second lsb */
159 if((new_entry->time = (char *) malloc(strlen(tmp) + 1)) == NULL)
161 fatal("files.c, fill_list(): malloc time string memory failed");
164 strcpy(new_entry->time, tmp);
166 /* destination number */
171 while(*s && (*s != '-'))
176 if((new_entry->dstnumber = (char *) malloc(strlen(tmp) + 1)) == NULL)
178 fatal("files.c, fill_list(): malloc dstnumber string memory failed");
181 strcpy(new_entry->dstnumber, tmp);
188 while(*s && (*s != '-'))
193 if((new_entry->srcnumber = (char *) malloc(strlen(tmp) + 1)) == NULL)
195 fatal("files.c, fill_list(): malloc srcnumber string memory failed");
198 strcpy(new_entry->srcnumber, tmp);
200 /* length in seconds */
205 while(*s && (*s != '-'))
210 if((new_entry->seconds = (char *) malloc(strlen(tmp) + 1)) == NULL)
212 fatal("files.c, fill_list(): malloc seconds string memory failed");
215 strcpy(new_entry->seconds, tmp);
217 /* search for alias and add if found */
219 new_entry->alias = get_alias(new_entry->srcnumber);
221 /* sort entry into linked list */
223 first = store(new_entry, first);
225 flcnt++; /* increment file count */
227 closedir(dirp); /* close current dir */
228 return(flcnt); /* ok return */
231 /*---------------------------------------------------------------------------*
232 * free the current malloc'ed list
233 *---------------------------------------------------------------------------*/
240 dir = first; /* start of linked list */
242 while (dir) /* free all */
244 tmp = dir->next; /* save ptr to next entry */
245 free(dir->fname); /* free filename space */
248 free(dir->srcnumber);
249 free(dir->dstnumber);
251 free(dir); /* free struct space */
252 dir = tmp; /* ptr = ptr to next entry */
254 first = NULL; /* first ptr = NULL */
255 last = NULL; /* last ptr = NULL */
258 /*---------------------------------------------------------------------------*
260 *---------------------------------------------------------------------------*/
262 delete(struct onefile *this)
264 char buffer[MAXPATHLEN+1];
269 sprintf(buffer, "%s", this->fname);
280 /*---------------------------------------------------------------------------*
281 * reread the spool directory
282 *---------------------------------------------------------------------------*/
293 /*---------------------------------------------------------------------------*
295 *---------------------------------------------------------------------------*/
297 play(struct onefile *this)
299 char buffer[MAXPATHLEN+1];
304 sprintf(buffer, playstring, this->fname);
309 /*---------------------------------- EOF -------------------------------------*/