diff options
author | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2011-03-13 21:43:30 +0000 |
---|---|---|
committer | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2011-03-13 21:43:30 +0000 |
commit | c4cf066956da0754d3383e60a6ff9f4e7abc9bca (patch) | |
tree | 3746cac035c1677886b65b0cb9543563082d612d /src | |
parent | 312f5b5917befaba8489288623fed4bcc0912f8d (diff) | |
download | 2011-ddhardrescue-c4cf066956da0754d3383e60a6ff9f4e7abc9bca.tar.gz 2011-ddhardrescue-c4cf066956da0754d3383e60a6ff9f4e7abc9bca.tar.bz2 2011-ddhardrescue-c4cf066956da0754d3383e60a6ff9f4e7abc9bca.zip |
Début du codage de la partie ncurses.
Suppression des printf de debug qui pollue l'écran.
git-svn-id: file:///var/svn/2011-ddhardrescue/trunk@13 d3078510-dda0-49f1-841c-895ef4b7ec81
Diffstat (limited to 'src')
-rw-r--r-- | src/ddhardrescue.c | 46 | ||||
-rw-r--r-- | src/essais/test2.c | 3 | ||||
-rw-r--r-- | src/recover.c | 6 | ||||
-rwxr-xr-x | src/utils.c | 73 |
4 files changed, 114 insertions, 14 deletions
diff --git a/src/ddhardrescue.c b/src/ddhardrescue.c index 9f355b3..de89c26 100644 --- a/src/ddhardrescue.c +++ b/src/ddhardrescue.c @@ -4,7 +4,7 @@ #include <stdint.h> #include <string.h> #include <pthread.h> - + #include "slices_evt.h" #include "recover.h" #include "utils.h" @@ -24,15 +24,17 @@ void sigHookAbrt() { end=1; } -//TODO : remove that when procViewer is done +/*TODO : remove that when procViewer is done void dumper(slices_evt_t *slicesEvt, slice_t *modifiedSlice) { address_t blockSize=0; char *dump; - dump=slicesDump(slicesEvt->data, &blockSize, 1000, 0, 21474836480ULL); + dump=slicesDump(slicesEvt->data, &blockSize, 3000, 0, 21474836480ULL); + system("clear"); puts(dump); free(dump); } +*/ void *procWorker(void *a); void *procViewer(void *a); @@ -40,7 +42,7 @@ void *procViewer(void *a); int main(int argc, char **argv) { // System structures struct sigaction sa; - pthread_t tWorker, tViewer; + pthread_t tWorker; // Main data structures slices_evt_t slices; @@ -74,7 +76,7 @@ int main(int argc, char **argv) { // Data structure initialization memset(&slices, 0, sizeof(slices)); slices.data=slicesNewSingleton(args.beginSector, args.endSector, S_UNKNOWN); - slices.eventListener=dumper; +// slices.eventListener=dumper; res=pthread_mutex_init(&(slices.mutex), NULL); if (res!=0) { return 3; @@ -90,14 +92,11 @@ int main(int argc, char **argv) { return 4; } - res=pthread_create(&tViewer, NULL, procViewer, &tArgs); - if (res!=0) { - return 5; - } + // Ncurses interface run in the main thread + (void) procViewer((void*)&tArgs); // Thread join point (void) pthread_join(tWorker, NULL); - (void) pthread_join(tViewer, NULL); /*Final dump of datas address_t blockSize=0; @@ -138,7 +137,34 @@ void * procWorker(void *a) { return a; } +#define CURSESWIN_COUNT 3 void *procViewer(void *a) { + WINDOW *wins[CURSESWIN_COUNT]; + PANEL *panels[CURSESWIN_COUNT]; + int ch; + //struct threadArgs *tArgs = (struct threadArgs *)a; + + cursesInit(wins, panels, CURSESWIN_COUNT); + + /* Show it on the screen */ + attron(COLOR_PAIR(4)); + mvprintw(LINES - 2, 0, "Use tab to browse through the windows (F2 to Exit)"); + attroff(COLOR_PAIR(4)); + doupdate(); + + while((ch = getch()) != KEY_F(2)) { + switch(ch) { + case 1: + case 2: + case 3: + top_panel(panels[ch]); + break; + } + + update_panels(); + doupdate(); + } + endwin(); return a; } diff --git a/src/essais/test2.c b/src/essais/test2.c index 3a34414..3512329 100644 --- a/src/essais/test2.c +++ b/src/essais/test2.c @@ -66,7 +66,8 @@ int main() /* Put all the windows */ void init_wins(WINDOW **wins, int n) -{ int x, y, i; +{ + int x, y, i; char label[80]; y = 2; diff --git a/src/recover.c b/src/recover.c index b4f0da7..9b1719b 100644 --- a/src/recover.c +++ b/src/recover.c @@ -76,7 +76,7 @@ void recover(slices_evt_t *slicesEvt, char *src, char *dst, char *ddOpts) { int tryRecoverUntilError(slice_t *sliceToRead, address_t *firstError, char *src, char *dst, char*ddOpts) { //TODO : implement realy that - char ddinvocation[256]; +// char ddinvocation[256]; int res; address_t seek, count; @@ -84,8 +84,8 @@ int tryRecoverUntilError(slice_t *sliceToRead, address_t *firstError, char *src, seek=sliceToRead->begin; count=sliceToRead->end - seek + 1; - res=snprintf(ddinvocation, 255, "dd %s %s %s seek=%lld skip=%lld count=%lld", src, dst, ddOpts, seek, seek, count); - puts(ddinvocation); +// res=snprintf(ddinvocation, 255, "dd %s %s %s seek=%lld skip=%lld count=%lld", src, dst, ddOpts, seek, seek, count); +//TODO : listener to put that info on the interface puts(ddinvocation); /* // Simulate that we have systematically a read error at first sector diff --git a/src/utils.c b/src/utils.c index a19b021..e4fdbc0 100755 --- a/src/utils.c +++ b/src/utils.c @@ -1,4 +1,6 @@ #include <stdio.h> +#include <string.h> + #include "utils.h" int parseArgs(int argc, char **argv, struct progArgs *args) { @@ -22,3 +24,74 @@ void usage(char *progname) { <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(); + noecho(); + keypad(stdscr, TRUE); + + /* 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; +} + |