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 $
34 * last edit-date: [Mon Dec 13 21:54:06 1999]
36 *----------------------------------------------------------------------------*/
40 /*---------------------------------------------------------------------------*
41 * create a doubly linked list in sorted order, return pointer to new
42 * first element of list
43 *---------------------------------------------------------------------------*/
45 (register struct onefile *new, /* new entry to store into list */
46 register struct onefile *top) /* current first entry in list */
48 register struct onefile *old, *p;
50 if (last == NULL) /* enter very first element ? */
54 last = new; /* init last */
55 return (new); /* return new first */
57 p = top; /* p = old first element */
61 if ((strcmp(p->fname, new->fname)) < 0) /* current less new ? */
67 { /* current >= new */
90 /*---------------------------------------------------------------------------*
91 * read current directory and build up a doubly linked sorted list
92 *---------------------------------------------------------------------------*/
96 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
97 register struct dirent *dp;
99 register struct direct *dp;
101 register struct onefile *new_entry;
107 if ((dirp = opendir(spooldir)) == NULL)
108 fatal("cannot open spooldirectory %s!\n", spooldir);
110 for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
112 if(!isdigit(*(dp->d_name)))
115 if ((new_entry = (struct onefile *) malloc(sizeof(struct onefile))) == NULL)
117 fatal("files.c, fill_list(): structure onefile malloc failed");
120 /* alloc filename memory and copy name into it */
122 if ((new_entry->fname = (char *) malloc(strlen(dp->d_name) + 1)) == NULL)
124 fatal("files.c, fill_list(): malloc filename string memory failed");
127 strcpy(new_entry->fname, dp->d_name);
129 /* fill in remaining fields from filename */
131 tmp[0] = dp->d_name[4]; /* day msb */
132 tmp[1] = dp->d_name[5]; /* day lsb */
134 tmp[3] = dp->d_name[2]; /* month msb */
135 tmp[4] = dp->d_name[3]; /* month lsb */
137 tmp[6] = dp->d_name[0]; /* year msb */
138 tmp[7] = dp->d_name[1]; /* year lsb */
141 if((new_entry->date = (char *) malloc(strlen(tmp) + 1)) == NULL)
143 fatal("files.c, fill_list(): malloc date string memory failed");
146 strcpy(new_entry->date, tmp);
148 tmp[0] = dp->d_name[6]; /* hour msb */
149 tmp[1] = dp->d_name[7]; /* hour lsb */
151 tmp[3] = dp->d_name[8]; /* minute msb */
152 tmp[4] = dp->d_name[9]; /* minute lsb */
154 tmp[6] = dp->d_name[10]; /* second msb */
155 tmp[7] = dp->d_name[11]; /* second lsb */
158 if((new_entry->time = (char *) malloc(strlen(tmp) + 1)) == NULL)
160 fatal("files.c, fill_list(): malloc time string memory failed");
163 strcpy(new_entry->time, tmp);
165 /* destination number */
170 while(*s && (*s != '-'))
175 if((new_entry->dstnumber = (char *) malloc(strlen(tmp) + 1)) == NULL)
177 fatal("files.c, fill_list(): malloc dstnumber string memory failed");
180 strcpy(new_entry->dstnumber, tmp);
187 while(*s && (*s != '-'))
192 if((new_entry->srcnumber = (char *) malloc(strlen(tmp) + 1)) == NULL)
194 fatal("files.c, fill_list(): malloc srcnumber string memory failed");
197 strcpy(new_entry->srcnumber, tmp);
199 /* length in seconds */
204 while(*s && (*s != '-'))
209 if((new_entry->seconds = (char *) malloc(strlen(tmp) + 1)) == NULL)
211 fatal("files.c, fill_list(): malloc seconds string memory failed");
214 strcpy(new_entry->seconds, tmp);
216 /* search for alias and add if found */
218 new_entry->alias = get_alias(new_entry->srcnumber);
220 /* sort entry into linked list */
222 first = store(new_entry, first);
224 flcnt++; /* increment file count */
226 closedir(dirp); /* close current dir */
227 return(flcnt); /* ok return */
230 /*---------------------------------------------------------------------------*
231 * free the current malloc'ed list
232 *---------------------------------------------------------------------------*/
236 register struct onefile *dir;
237 register struct onefile *tmp;
239 dir = first; /* start of linked list */
241 while (dir) /* free all */
243 tmp = dir->next; /* save ptr to next entry */
244 free(dir->fname); /* free filename space */
247 free(dir->srcnumber);
248 free(dir->dstnumber);
250 free(dir); /* free struct space */
251 dir = tmp; /* ptr = ptr to next entry */
253 first = NULL; /* first ptr = NULL */
254 last = NULL; /* last ptr = NULL */
257 /*---------------------------------------------------------------------------*
259 *---------------------------------------------------------------------------*/
261 delete(struct onefile *this)
263 char buffer[MAXPATHLEN+1];
268 sprintf(buffer, "%s", this->fname);
279 /*---------------------------------------------------------------------------*
280 * reread the spool directory
281 *---------------------------------------------------------------------------*/
292 /*---------------------------------------------------------------------------*
294 *---------------------------------------------------------------------------*/
296 play(struct onefile *this)
298 char buffer[MAXPATHLEN+1];
303 sprintf(buffer, playstring, this->fname);
308 /*---------------------------------- EOF -------------------------------------*/