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: main.c,v 1.12 1999/12/13 21:25:26 hm Exp $
32 * $FreeBSD: src/usr.sbin/i4b/isdntel/main.c,v 1.8.2.1 2001/08/01 17:45:07 obrien Exp $
33 * $DragonFly: src/usr.sbin/i4b/isdntel/main.c,v 1.2 2003/06/17 04:29:55 dillon Exp $
35 * last edit-date: [Mon Dec 13 21:54:26 1999]
37 *----------------------------------------------------------------------------*/
44 static void usage( void );
46 static int top_dis = 0;
47 static int bot_dis = 0;
48 static int cur_pos_scr = 0;
50 static void makecurrent(int cur_pos, struct onefile *cur_file, int cold);
52 /*---------------------------------------------------------------------------*
54 *---------------------------------------------------------------------------*/
56 main(int argc, char **argv)
61 char *spooldir = SPOOLDIR;
62 char *playstring = PLAYCMD;
63 char *aliasfile = ALIASFILE;
64 int rrtimeout = REREADTIMEOUT;
68 setlocale( LC_ALL, "");
70 while ((i = getopt(argc, argv, "a:d:p:t:")) != -1)
89 rrtimeout = strtoul(optarg, NULL, 10);
107 if((chdir(spooldir)) != 0)
108 fatal("cannot change directory to spooldir %s!", spooldir);
110 init_alias(aliasfile);
121 struct timeval timeout;
124 FD_SET(STDIN_FILENO, &set);
125 timeout.tv_sec = rrtimeout;
128 /* if no char is available within timeout, reread spool */
130 if((select(STDIN_FILENO + 1, &set, NULL, NULL, &timeout)) <= 0)
136 kchar = wgetch(main_w); /* get char */
148 case KEY_UP: /* up-move cursor */
149 if(cur_file && cur_file->prev)
151 cur_file = cur_file->prev;
158 case KEY_DOWN: /* down-move cursor */
159 if(cur_file && cur_file->next)
161 cur_file = cur_file->next;
166 case KEY_HOME: /* move cursor to first dir */
169 case KEY_LL: /* move cursor to last file */
176 case CNTRL_L: /* refresh */
182 makecurrent(cur_pos, cur_file, 0);
190 /*---------------------------------------------------------------------------*
191 * handle horizontal selection bar movement
192 *---------------------------------------------------------------------------*/
194 makecurrent(int cur_pos, struct onefile *cur_file, int cold)
197 static struct onefile *lastfile;
200 /* un-higlight current horizontal bar */
202 if(!cold && lastfile && cur_file)
204 sprintf(buffer, "%s %s %-16s %-16s %-20s %-6s%*s",
205 lastfile->date, lastfile->time,
206 lastfile->dstnumber, lastfile->srcnumber,
207 lastfile->alias == NULL ? "-/-" : lastfile->alias,
209 COLS - LAST_POS - 2, "");
211 wattroff(main_w, A_REVERSE);
212 mvwprintw(main_w, lastpos, 0, "%s", buffer);
213 wattroff(main_w, A_REVERSE);
218 lastpos = cur_pos_scr;
223 /* have to scroll up or down ? */
225 if(cur_pos >= bot_dis)
233 cur_pos_scr = LINES-START_O-3;
235 else if(cur_pos < top_dis)
247 cur_pos_scr = cur_pos - top_dis;
250 sprintf(buffer, "%s %s %-16s %-16s %-20s %-6s%*s",
251 cur_file->date, cur_file->time,
252 cur_file->dstnumber, cur_file->srcnumber,
253 cur_file->alias == NULL ? "-/-" : cur_file->alias,
255 COLS - LAST_POS - 2, "");
257 wattron(main_w, A_REVERSE);
258 mvwprintw(main_w, cur_pos_scr, 0, "%s", buffer);
259 wattroff(main_w, A_REVERSE);
261 lastpos = cur_pos_scr;
267 /*---------------------------------------------------------------------------*
269 *---------------------------------------------------------------------------*/
280 /*---------------------------------------------------------------------------*
281 * usage display and exit
282 *---------------------------------------------------------------------------*/
286 fprintf(stderr, "\n");
287 fprintf(stderr, "isdntel - isdn telephone answering management support utility (version %d.%d.%d)\n", VERSION, REL, STEP);
288 fprintf(stderr, " usage: isdntel -a <filename> -d <directory> -p <command> -t <timeout>\n");
289 fprintf(stderr, " -a <filename> use filename as alias file\n");
290 fprintf(stderr, " -d <directory> use directory as spool directory\n");
291 fprintf(stderr, " -p <command> specify commandline for play command\n");
292 fprintf(stderr, " -t <timeout> spool directory reread timeout in seconds\n");
293 fprintf(stderr, "\n");
297 /*---------------------------------------------------------------------------*
299 *---------------------------------------------------------------------------*/
301 fatal(char *fmt, ...)
315 fprintf(stderr, "\nFatal error: ");
316 vfprintf(stderr, fmt, ap);
317 fprintf(stderr, "\n\n");
324 /*---------------------------------------------------------------------------*
326 *---------------------------------------------------------------------------*/
328 error(char *fmt, ...)
336 wprintw(main_w, "ERROR: ");
337 vwprintw(main_w, fmt, ap);
338 wprintw(main_w, "\n");
343 fprintf(stderr, "ERROR: ");
344 vfprintf(stderr, fmt, ap);
345 fprintf(stderr, "\n");
351 /*---------------------------------------------------------------------------*
352 * read files and fill display
353 *---------------------------------------------------------------------------*/
355 init_files(int inipos)
359 nofiles = fill_list();
372 for(i=0; (i < nofiles) && (i < (LINES-START_O-2)); i++)
374 mvwprintw(main_w, i, 0, "%s %s", cur_file->date, cur_file->time);
375 mvwprintw(main_w, i, DST_POS, "%s", cur_file->dstnumber);
376 mvwprintw(main_w, i, SRC_POS, "%s", cur_file->srcnumber);
377 mvwprintw(main_w, i, ALI_POS,"%s", cur_file->alias == NULL ? "-/-" : cur_file->alias);
378 mvwprintw(main_w, i, SEC_POS,"%s", cur_file->seconds);
382 if((cur_file = cur_file->next) == NULL)
390 for(i=0; i < inipos; i++)
392 if(cur_file->next != NULL)
393 cur_file = cur_file->next;
398 makecurrent(cur_pos, cur_file, 1);