1*6a54128fSAndroid Build Coastguard Worker /*
2*6a54128fSAndroid Build Coastguard Worker
3*6a54128fSAndroid Build Coastguard Worker /usr/src/ext2ed/win.c
4*6a54128fSAndroid Build Coastguard Worker
5*6a54128fSAndroid Build Coastguard Worker A part of the extended file system 2 disk editor.
6*6a54128fSAndroid Build Coastguard Worker
7*6a54128fSAndroid Build Coastguard Worker --------------------------------------------------------
8*6a54128fSAndroid Build Coastguard Worker Window management - Interfacing with the ncurses library
9*6a54128fSAndroid Build Coastguard Worker --------------------------------------------------------
10*6a54128fSAndroid Build Coastguard Worker
11*6a54128fSAndroid Build Coastguard Worker First written on: April 17 1995
12*6a54128fSAndroid Build Coastguard Worker Modified on : April 05 2001 [email protected]
13*6a54128fSAndroid Build Coastguard Worker it looks like readline does not like that initscr decides to set the tty to
14*6a54128fSAndroid Build Coastguard Worker noecho.
15*6a54128fSAndroid Build Coastguard Worker
16*6a54128fSAndroid Build Coastguard Worker Copyright (C) 1995 Gadi Oxman
17*6a54128fSAndroid Build Coastguard Worker
18*6a54128fSAndroid Build Coastguard Worker */
19*6a54128fSAndroid Build Coastguard Worker
20*6a54128fSAndroid Build Coastguard Worker #include "config.h"
21*6a54128fSAndroid Build Coastguard Worker #include <stdio.h>
22*6a54128fSAndroid Build Coastguard Worker #include <stdlib.h>
23*6a54128fSAndroid Build Coastguard Worker #include <string.h>
24*6a54128fSAndroid Build Coastguard Worker #include <termios.h>
25*6a54128fSAndroid Build Coastguard Worker #include <unistd.h>
26*6a54128fSAndroid Build Coastguard Worker #include <sys/ioctl.h>
27*6a54128fSAndroid Build Coastguard Worker
28*6a54128fSAndroid Build Coastguard Worker #include "ext2ed.h"
29*6a54128fSAndroid Build Coastguard Worker #include "../version.h"
30*6a54128fSAndroid Build Coastguard Worker
31*6a54128fSAndroid Build Coastguard Worker struct struct_pad_info show_pad_info;
32*6a54128fSAndroid Build Coastguard Worker WINDOW *title_win,*show_win,*command_win,*mt_win1,*mt_win2,*show_pad;
33*6a54128fSAndroid Build Coastguard Worker
34*6a54128fSAndroid Build Coastguard Worker /* to remember configuration after initscr
35*6a54128fSAndroid Build Coastguard Worker * and modify it
36*6a54128fSAndroid Build Coastguard Worker */
37*6a54128fSAndroid Build Coastguard Worker struct termios termioInit, termioCurrent;
38*6a54128fSAndroid Build Coastguard Worker
draw_title_win(void)39*6a54128fSAndroid Build Coastguard Worker void draw_title_win (void)
40*6a54128fSAndroid Build Coastguard Worker {
41*6a54128fSAndroid Build Coastguard Worker char title_string [128];
42*6a54128fSAndroid Build Coastguard Worker
43*6a54128fSAndroid Build Coastguard Worker werase(title_win);
44*6a54128fSAndroid Build Coastguard Worker box (title_win,0,0);
45*6a54128fSAndroid Build Coastguard Worker sprintf (title_string,"EXT2ED - Extended-2 File System editor ver %s (%s)", E2FSPROGS_VERSION, E2FSPROGS_DATE);
46*6a54128fSAndroid Build Coastguard Worker wmove (title_win,TITLE_WIN_LINES/2,(COLS-strlen (title_string))/2);
47*6a54128fSAndroid Build Coastguard Worker wprintw (title_win,title_string);
48*6a54128fSAndroid Build Coastguard Worker wrefresh(title_win);
49*6a54128fSAndroid Build Coastguard Worker }
50*6a54128fSAndroid Build Coastguard Worker
setup_show_win(void)51*6a54128fSAndroid Build Coastguard Worker void setup_show_win(void)
52*6a54128fSAndroid Build Coastguard Worker {
53*6a54128fSAndroid Build Coastguard Worker wbkgdset (show_win,A_REVERSE);werase (show_win);
54*6a54128fSAndroid Build Coastguard Worker show_pad_info.line=0;
55*6a54128fSAndroid Build Coastguard Worker show_pad_info.col=0;
56*6a54128fSAndroid Build Coastguard Worker show_pad_info.display_lines=LINES-TITLE_WIN_LINES-SHOW_WIN_LINES-COMMAND_WIN_LINES-2;
57*6a54128fSAndroid Build Coastguard Worker show_pad_info.display_cols=COLS;
58*6a54128fSAndroid Build Coastguard Worker show_pad_info.max_line=show_pad_info.display_lines-1;show_pad_info.max_col=show_pad_info.display_cols-1;
59*6a54128fSAndroid Build Coastguard Worker show_pad_info.disable_output=0;
60*6a54128fSAndroid Build Coastguard Worker }
61*6a54128fSAndroid Build Coastguard Worker
init_windows(void)62*6a54128fSAndroid Build Coastguard Worker void init_windows (void)
63*6a54128fSAndroid Build Coastguard Worker {
64*6a54128fSAndroid Build Coastguard Worker initscr ();
65*6a54128fSAndroid Build Coastguard Worker tcgetattr(0,&termioInit); /* save initial config */
66*6a54128fSAndroid Build Coastguard Worker termioCurrent = termioInit;
67*6a54128fSAndroid Build Coastguard Worker termioCurrent.c_lflag |= ECHO; /* set echo on */
68*6a54128fSAndroid Build Coastguard Worker tcsetattr(0,TCSANOW,&termioCurrent);
69*6a54128fSAndroid Build Coastguard Worker
70*6a54128fSAndroid Build Coastguard Worker if (LINES<TITLE_WIN_LINES+SHOW_WIN_LINES+COMMAND_WIN_LINES+3) {
71*6a54128fSAndroid Build Coastguard Worker printf ("Sorry, your terminal screen is too small\n");
72*6a54128fSAndroid Build Coastguard Worker printf ("Error - Can not initialize windows\n");
73*6a54128fSAndroid Build Coastguard Worker exit (1);
74*6a54128fSAndroid Build Coastguard Worker }
75*6a54128fSAndroid Build Coastguard Worker
76*6a54128fSAndroid Build Coastguard Worker title_win=newwin (TITLE_WIN_LINES,COLS,0,0);
77*6a54128fSAndroid Build Coastguard Worker show_win=newwin (SHOW_WIN_LINES,COLS,TITLE_WIN_LINES,0);
78*6a54128fSAndroid Build Coastguard Worker show_pad=newpad (SHOW_PAD_LINES,SHOW_PAD_COLS);
79*6a54128fSAndroid Build Coastguard Worker mt_win1=newwin (1,COLS,TITLE_WIN_LINES+SHOW_WIN_LINES,0);
80*6a54128fSAndroid Build Coastguard Worker mt_win2=newwin (1,COLS,LINES-COMMAND_WIN_LINES-1,0);
81*6a54128fSAndroid Build Coastguard Worker command_win=newwin (COMMAND_WIN_LINES,COLS,LINES-COMMAND_WIN_LINES,0);
82*6a54128fSAndroid Build Coastguard Worker
83*6a54128fSAndroid Build Coastguard Worker if (title_win==NULL || show_win==NULL || show_pad==NULL || command_win==NULL) {
84*6a54128fSAndroid Build Coastguard Worker printf ("Error - Not enough memory - Can not initialize windows\n");exit (1);
85*6a54128fSAndroid Build Coastguard Worker }
86*6a54128fSAndroid Build Coastguard Worker
87*6a54128fSAndroid Build Coastguard Worker draw_title_win();
88*6a54128fSAndroid Build Coastguard Worker
89*6a54128fSAndroid Build Coastguard Worker setup_show_win();
90*6a54128fSAndroid Build Coastguard Worker
91*6a54128fSAndroid Build Coastguard Worker scrollok (command_win,TRUE);
92*6a54128fSAndroid Build Coastguard Worker
93*6a54128fSAndroid Build Coastguard Worker refresh_title_win ();
94*6a54128fSAndroid Build Coastguard Worker refresh_show_win ();
95*6a54128fSAndroid Build Coastguard Worker refresh_show_pad();
96*6a54128fSAndroid Build Coastguard Worker refresh_command_win ();
97*6a54128fSAndroid Build Coastguard Worker wrefresh(mt_win1);
98*6a54128fSAndroid Build Coastguard Worker wrefresh(mt_win2);
99*6a54128fSAndroid Build Coastguard Worker }
100*6a54128fSAndroid Build Coastguard Worker
refresh_title_win(void)101*6a54128fSAndroid Build Coastguard Worker void refresh_title_win (void)
102*6a54128fSAndroid Build Coastguard Worker {
103*6a54128fSAndroid Build Coastguard Worker wrefresh (title_win);
104*6a54128fSAndroid Build Coastguard Worker }
105*6a54128fSAndroid Build Coastguard Worker
refresh_show_win(void)106*6a54128fSAndroid Build Coastguard Worker void refresh_show_win (void)
107*6a54128fSAndroid Build Coastguard Worker {
108*6a54128fSAndroid Build Coastguard Worker int current_page,total_pages;
109*6a54128fSAndroid Build Coastguard Worker
110*6a54128fSAndroid Build Coastguard Worker current_page=show_pad_info.line/show_pad_info.display_lines+1;
111*6a54128fSAndroid Build Coastguard Worker if (show_pad_info.line%show_pad_info.display_lines)
112*6a54128fSAndroid Build Coastguard Worker current_page++;
113*6a54128fSAndroid Build Coastguard Worker total_pages=show_pad_info.max_line/show_pad_info.display_lines+1;
114*6a54128fSAndroid Build Coastguard Worker
115*6a54128fSAndroid Build Coastguard Worker wmove (show_win,2,COLS-18);
116*6a54128fSAndroid Build Coastguard Worker wprintw (show_win,"Page %d of %d\n",current_page,total_pages);
117*6a54128fSAndroid Build Coastguard Worker
118*6a54128fSAndroid Build Coastguard Worker wmove (show_win,2,COLS-18);
119*6a54128fSAndroid Build Coastguard Worker wrefresh (show_win);
120*6a54128fSAndroid Build Coastguard Worker }
121*6a54128fSAndroid Build Coastguard Worker
122*6a54128fSAndroid Build Coastguard Worker
refresh_show_pad(void)123*6a54128fSAndroid Build Coastguard Worker void refresh_show_pad (void)
124*6a54128fSAndroid Build Coastguard Worker
125*6a54128fSAndroid Build Coastguard Worker {
126*6a54128fSAndroid Build Coastguard Worker int left,top,right,bottom,i;
127*6a54128fSAndroid Build Coastguard Worker
128*6a54128fSAndroid Build Coastguard Worker if (show_pad_info.disable_output)
129*6a54128fSAndroid Build Coastguard Worker return;
130*6a54128fSAndroid Build Coastguard Worker
131*6a54128fSAndroid Build Coastguard Worker if (show_pad_info.max_line < show_pad_info.display_lines-1) {
132*6a54128fSAndroid Build Coastguard Worker for (i=show_pad_info.max_line+1;i<show_pad_info.display_lines;i++) {
133*6a54128fSAndroid Build Coastguard Worker wmove (show_pad,i,0);wprintw (show_pad,"\n");
134*6a54128fSAndroid Build Coastguard Worker }
135*6a54128fSAndroid Build Coastguard Worker }
136*6a54128fSAndroid Build Coastguard Worker left=0;right=show_pad_info.display_cols-1;
137*6a54128fSAndroid Build Coastguard Worker top=TITLE_WIN_LINES+SHOW_WIN_LINES+1;bottom=top+show_pad_info.display_lines-1;
138*6a54128fSAndroid Build Coastguard Worker
139*6a54128fSAndroid Build Coastguard Worker if (show_pad_info.line > show_pad_info.max_line-show_pad_info.display_lines+1)
140*6a54128fSAndroid Build Coastguard Worker show_pad_info.line=show_pad_info.max_line-show_pad_info.display_lines+1;
141*6a54128fSAndroid Build Coastguard Worker
142*6a54128fSAndroid Build Coastguard Worker if (show_pad_info.line < 0)
143*6a54128fSAndroid Build Coastguard Worker show_pad_info.line=0;
144*6a54128fSAndroid Build Coastguard Worker
145*6a54128fSAndroid Build Coastguard Worker #ifdef OLD_NCURSES
146*6a54128fSAndroid Build Coastguard Worker prefresh (show_pad,show_pad_info.line,show_pad_info.col,top,left,show_pad_info.display_lines-1,show_pad_info.display_cols-1);
147*6a54128fSAndroid Build Coastguard Worker #else
148*6a54128fSAndroid Build Coastguard Worker prefresh (show_pad,show_pad_info.line,show_pad_info.col,top,left,top+show_pad_info.display_lines-1,left+show_pad_info.display_cols-1);
149*6a54128fSAndroid Build Coastguard Worker #endif
150*6a54128fSAndroid Build Coastguard Worker }
151*6a54128fSAndroid Build Coastguard Worker
refresh_command_win(void)152*6a54128fSAndroid Build Coastguard Worker void refresh_command_win (void)
153*6a54128fSAndroid Build Coastguard Worker {
154*6a54128fSAndroid Build Coastguard Worker wrefresh (command_win);
155*6a54128fSAndroid Build Coastguard Worker }
156*6a54128fSAndroid Build Coastguard Worker
close_windows(void)157*6a54128fSAndroid Build Coastguard Worker void close_windows (void)
158*6a54128fSAndroid Build Coastguard Worker {
159*6a54128fSAndroid Build Coastguard Worker // echo ();
160*6a54128fSAndroid Build Coastguard Worker tcsetattr(0,TCSANOW,&termioInit);
161*6a54128fSAndroid Build Coastguard Worker
162*6a54128fSAndroid Build Coastguard Worker delwin (title_win);
163*6a54128fSAndroid Build Coastguard Worker delwin (command_win);
164*6a54128fSAndroid Build Coastguard Worker delwin (show_win);
165*6a54128fSAndroid Build Coastguard Worker delwin (show_pad);
166*6a54128fSAndroid Build Coastguard Worker
167*6a54128fSAndroid Build Coastguard Worker endwin ();
168*6a54128fSAndroid Build Coastguard Worker }
169*6a54128fSAndroid Build Coastguard Worker
show_info(void)170*6a54128fSAndroid Build Coastguard Worker void show_info (void)
171*6a54128fSAndroid Build Coastguard Worker {
172*6a54128fSAndroid Build Coastguard Worker int block_num,block_offset;
173*6a54128fSAndroid Build Coastguard Worker
174*6a54128fSAndroid Build Coastguard Worker block_num=device_offset/file_system_info.block_size;
175*6a54128fSAndroid Build Coastguard Worker block_offset=device_offset%file_system_info.block_size;
176*6a54128fSAndroid Build Coastguard Worker
177*6a54128fSAndroid Build Coastguard Worker wmove (show_win,0,0);
178*6a54128fSAndroid Build Coastguard Worker wprintw (show_win,"Offset %-3ld in block %ld. ",block_offset,block_num);
179*6a54128fSAndroid Build Coastguard Worker if (current_type != NULL)
180*6a54128fSAndroid Build Coastguard Worker wprintw (show_win,"Type: %s\n",current_type->name);
181*6a54128fSAndroid Build Coastguard Worker else
182*6a54128fSAndroid Build Coastguard Worker wprintw (show_win,"Type: %s\n","none");
183*6a54128fSAndroid Build Coastguard Worker
184*6a54128fSAndroid Build Coastguard Worker refresh_show_win ();
185*6a54128fSAndroid Build Coastguard Worker }
186*6a54128fSAndroid Build Coastguard Worker
187*6a54128fSAndroid Build Coastguard Worker
redraw_all(void)188*6a54128fSAndroid Build Coastguard Worker void redraw_all (void)
189*6a54128fSAndroid Build Coastguard Worker {
190*6a54128fSAndroid Build Coastguard Worker int min_lines = TITLE_WIN_LINES+SHOW_WIN_LINES+COMMAND_WIN_LINES+3;
191*6a54128fSAndroid Build Coastguard Worker struct winsize ws;
192*6a54128fSAndroid Build Coastguard Worker int save_col, save_lines;
193*6a54128fSAndroid Build Coastguard Worker
194*6a54128fSAndroid Build Coastguard Worker /* get the size of the terminal connected to stdout */
195*6a54128fSAndroid Build Coastguard Worker ioctl(1, TIOCGWINSZ, &ws);
196*6a54128fSAndroid Build Coastguard Worker /*
197*6a54128fSAndroid Build Coastguard Worker * Do it again because GDB doesn't stop before the first ioctl
198*6a54128fSAndroid Build Coastguard Worker * call, we want an up-to-date size when we're
199*6a54128fSAndroid Build Coastguard Worker * single-stepping.
200*6a54128fSAndroid Build Coastguard Worker */
201*6a54128fSAndroid Build Coastguard Worker if (ioctl(1, TIOCGWINSZ, &ws) == 0) {
202*6a54128fSAndroid Build Coastguard Worker if (ws.ws_row < min_lines)
203*6a54128fSAndroid Build Coastguard Worker ws.ws_row = min_lines;
204*6a54128fSAndroid Build Coastguard Worker if ((ws.ws_row != LINES) || (ws.ws_col != COLS)) {
205*6a54128fSAndroid Build Coastguard Worker wmove (show_win,2,COLS-18);
206*6a54128fSAndroid Build Coastguard Worker wclrtoeol(show_win);
207*6a54128fSAndroid Build Coastguard Worker wrefresh(show_win);
208*6a54128fSAndroid Build Coastguard Worker resizeterm(ws.ws_row, ws.ws_col);
209*6a54128fSAndroid Build Coastguard Worker wresize(title_win, TITLE_WIN_LINES,COLS);
210*6a54128fSAndroid Build Coastguard Worker wresize(show_win, SHOW_WIN_LINES,COLS);
211*6a54128fSAndroid Build Coastguard Worker wresize(command_win, COMMAND_WIN_LINES,COLS);
212*6a54128fSAndroid Build Coastguard Worker wresize(mt_win1, 1,COLS);
213*6a54128fSAndroid Build Coastguard Worker wresize(mt_win2, 1,COLS);
214*6a54128fSAndroid Build Coastguard Worker mvwin(mt_win2, LINES-COMMAND_WIN_LINES-1,0);
215*6a54128fSAndroid Build Coastguard Worker mvwin(command_win, LINES-COMMAND_WIN_LINES,0);
216*6a54128fSAndroid Build Coastguard Worker draw_title_win();
217*6a54128fSAndroid Build Coastguard Worker show_pad_info.display_lines=LINES-TITLE_WIN_LINES-SHOW_WIN_LINES-COMMAND_WIN_LINES-2;
218*6a54128fSAndroid Build Coastguard Worker show_pad_info.display_cols=COLS;
219*6a54128fSAndroid Build Coastguard Worker }
220*6a54128fSAndroid Build Coastguard Worker }
221*6a54128fSAndroid Build Coastguard Worker clearok(title_win, 1);
222*6a54128fSAndroid Build Coastguard Worker clearok(show_win, 1);
223*6a54128fSAndroid Build Coastguard Worker clearok(command_win, 1);
224*6a54128fSAndroid Build Coastguard Worker clearok(mt_win1, 1);
225*6a54128fSAndroid Build Coastguard Worker clearok(mt_win2, 1);
226*6a54128fSAndroid Build Coastguard Worker wrefresh(mt_win1);
227*6a54128fSAndroid Build Coastguard Worker wrefresh(mt_win2);
228*6a54128fSAndroid Build Coastguard Worker refresh_show_pad();
229*6a54128fSAndroid Build Coastguard Worker refresh_show_win();
230*6a54128fSAndroid Build Coastguard Worker refresh_title_win ();
231*6a54128fSAndroid Build Coastguard Worker refresh_command_win ();
232*6a54128fSAndroid Build Coastguard Worker }
233