1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
#include <stdio.h>
#include <string.h>
#include "utils.h"
int parseArgs(int argc, char **argv, struct progArgs *args) {
//TODO : implement that
args->src="/dev/sdb";
args->dst="./test.img";
args->ddOpts="";
args->beginSector=0;
args->endSector=21474836480ULL; //10 Tio
return 0;
}
void usage(char *progname) {
printf(
"Usage %s <src> <dst> [<beginSector> <endSector> [ddOpts]]\n\
<src>\t\t\n\
<dst>\t\t\n\
<beginSector>\t\n\
<endSector>\t\n\
<ddOpts>\t\n\
", progname);
}
void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color)
{ int length, x, y;
float temp;
if(win == NULL)
win = stdscr;
getyx(win, y, x);
if(startx != 0)
x = startx;
if(starty != 0)
y = starty;
if(width == 0)
width = 80;
length = strlen(string);
temp = (width - length)/ 2;
x = startx + (int)temp;
wattron(win, color);
mvwprintw(win, y, x, "%s", string);
wattroff(win, color);
refresh();
}
void makeWin(WINDOW **win, PANEL **panel, int h, int w, int y, int x, char title[]) {
int i;
*win = newwin(h, w, y, x);
mvwprintw(*win, 0, 0, "%s", title);
mvwchgat(*win, 0, 0, -1, A_BOLD, 2, NULL);
for(i=1;i<h;i++) mvwchgat(*win, i, 0, -1, A_STANDOUT, 1, NULL);
*panel = new_panel(*win);
}
int cursesInit(WINDOW *wins[], PANEL *panels[], int count) {
int screenH, screenW;
/* Initialize curses */
initscr();
start_color();
raw();
keypad(stdscr, TRUE);
noecho();
/* Initialize all the colors */
init_pair(1, COLOR_WHITE, COLOR_BLACK);
init_pair(2, COLOR_WHITE, COLOR_BLUE);
init_pair(3, COLOR_BLUE, COLOR_BLACK);
init_pair(4, COLOR_CYAN, COLOR_BLACK);
/* Initialize windows and panels */
getmaxyx(stdscr, screenH, screenW);
if ( screenH < 8 || screenW < 40 ) return 1;
makeWin(wins+0, panels+0, 3 , screenW, 0 , 0, "Menu");
makeWin(wins+1, panels+1, screenH-6 , screenW, 3 , 0, "Main Win");
makeWin(wins+2, panels+2, 2 , screenW, screenH-3 , 0, "Commands");
/* Set up the user pointers to the next panel
set_panel_userptr(panels[0], panels[1]);
set_panel_userptr(panels[1], panels[2]);
set_panel_userptr(panels[2], panels[0]);
*/
/* Update the stacking order. 2nd panel will be on top */
update_panels();
return 0;
}
void cursesUnInit(WINDOW *wins[], PANEL *panels[], int count) {
int i;
for (i=0;i<count;i++) {
del_panel(panels[i]);
delwin(wins[i]);
}
endwin();
}
|