modules: pull in most of FreeBSD's module linker changes
[dragonfly.git] / usr.sbin / i4b / isdnphone / display.c
blob0d2f28f40c8b4711295328631177c17460549df0
1 /*
2 * Copyright (c) 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
6 * are met:
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
23 * SUCH DAMAGE.
25 *---------------------------------------------------------------------------
27 * isdnphone - some display operations
28 * ===================================
30 * $Id: display.c,v 1.4 1999/12/13 21:25:26 hm Exp $
32 * $FreeBSD: src/usr.sbin/i4b/isdnphone/display.c,v 1.1.2.1 2001/08/01 17:45:06 obrien Exp $
33 * $DragonFly: src/usr.sbin/i4b/isdnphone/display.c,v 1.2 2003/06/17 04:29:55 dillon Exp $
35 * last edit-date: [Mon Dec 13 21:52:55 1999]
37 *----------------------------------------------------------------------------*/
39 #include "defs.h"
41 /*---------------------------------------------------------------------------*
42 * init curses fullscreen display
43 *---------------------------------------------------------------------------*/
44 void
45 init_mainw(void)
47 char buffer[512];
49 initscr(); /* curses init */
51 if((COLS < 80) || (LINES < 24))
52 fatal(0, "ERROR, minimal screensize must be 80x24, is %dx%d, terminating!", COLS, LINES);
55 if((main_w = newwin(MW_HEIGHT, MW_WIDTH, MW_ROW, MW_COL)) == NULL)
56 fatal("ERROR, curses init main window, terminating!");
58 if(opt_d)
60 if((dbg_w = newwin(DB_HGT, DB_WID, DB_ROW, DB_COL)) == NULL)
61 fatal("ERROR, curses init debug window, terminating!");
62 scrollok(dbg_w, TRUE);
65 raw(); /* raw input */
66 noecho(); /* do not echo input */
67 keypad(stdscr, TRUE); /* use special keys */
68 keypad(main_w, TRUE); /* use special keys */
70 box(main_w, 0, 0);
72 sprintf(buffer, "isdnphone %d.%d ", VERSION, REL);
74 wstandout(main_w);
75 mvwaddstr(main_w, 0, (MW_WIDTH / 2) - (strlen(buffer) / 2), buffer);
76 wstandend(main_w);
78 mvwaddstr(main_w, MW_STATEY, MW_STATEX, " state: ");
79 mvwprintw(main_w, MW_STATEY, MW_STX, "%s", states[state]);
80 wmove(main_w, MW_STATEY+1, 1);
81 whline(main_w, 0, MW_WIDTH-2);
83 mvwaddstr(main_w, MW_NUMY, MW_NUMX, " number: ");
84 wmove(main_w, MW_NUMY+1, 1);
85 whline(main_w, 0, MW_WIDTH-2);
87 mvwaddstr(main_w, MW_MSGY, MW_MSGX, "message: ");
89 wrefresh(main_w);
91 curses_ready = 1;
94 /*---------------------------------------------------------------------------*
95 * curses menu for fullscreen command mode
96 *---------------------------------------------------------------------------*/
97 void
98 do_menu(void)
100 static char *menu[WMITEMS] =
102 "Hangup",
103 #define HANGUP 0
104 "Dial",
105 #define DIAL 1
106 "Refresh",
107 #define REFRESH 2
108 "Exit",
109 #define EXIT 3
112 WINDOW *menu_w;
113 int c;
114 int mpos;
116 /* create a new window in the lower screen area */
118 if((menu_w = newwin(WMENU_HGT, WMENU_LEN, WMENU_POSLN, WMENU_POSCO )) == NULL)
119 return;
121 keypad(menu_w, TRUE); /* use special keys */
123 /* draw border around the window */
125 box(menu_w, 0, 0);
127 /* add a title */
129 wstandout(menu_w);
130 mvwaddstr(menu_w, 0, (WMENU_LEN / 2) - (strlen(WMENU_TITLE) / 2), WMENU_TITLE);
131 wstandend(menu_w);
133 /* fill the window with the menu options */
135 for(mpos=0; mpos <= (WMITEMS-1); mpos++)
136 mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]);
138 /* highlight the first menu option */
140 mpos = 0;
141 wstandout(menu_w);
142 mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]);
143 wstandend(menu_w);
145 /* input loop */
147 for(;;)
149 wrefresh(menu_w);
151 c = wgetch(menu_w);
153 switch(c)
155 case TAB:
156 case KEY_DOWN: /* down-move cursor */
157 case ' ':
158 mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]);
159 mpos++;
160 if(mpos >= WMITEMS)
161 mpos = 0;
162 wstandout(menu_w);
163 mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]);
164 wstandend(menu_w);
165 break;
167 case KEY_UP: /* up-move cursor */
168 mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]);
169 if(mpos)
170 mpos--;
171 else
172 mpos = WMITEMS-1;
173 wstandout(menu_w);
174 mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]);
175 wstandend(menu_w);
176 break;
178 case 'R':
179 case 'r':
180 wrefresh(curscr);
181 goto mexit;
183 case 'E':
184 case 'e':
185 case 'Q':
186 case 'q':
187 case 'X':
188 case 'x':
189 do_quit(0);
190 goto mexit;
191 break;
193 case 'H':
194 case 'h':
195 do_hangup();
196 goto mexit;
197 break;
199 case 'D':
200 case 'd':
201 goto mexit;
202 break;
204 case CR:
205 case LF: /* exec highlighted option */
206 #ifdef KEY_ENTER
207 case KEY_ENTER:
208 #endif
209 switch(mpos)
211 case DIAL:
212 goto mexit;
213 break;
214 case HANGUP:
215 do_hangup();
216 goto mexit;
217 break;
218 case REFRESH:
219 wrefresh(curscr);
220 break;
221 case EXIT:
222 do_quit(0);
223 break;
225 goto mexit;
226 break;
228 default:
229 goto mexit;
230 break;
234 mexit:
235 /* delete the menu window */
237 wclear(menu_w);
238 wrefresh(menu_w);
239 delwin(menu_w);
241 /* re-display the original lower window contents */
243 touchwin(main_w);
244 wrefresh(main_w);
247 /* EOF */