From 7db6f09bbf06dfc15cd9aef486229637514d607a Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Sat, 5 Mar 2011 16:45:22 +0000 Subject: Restructuration du code. Création d'un Makefile avec génération automatique des dépendances. J'ai pomé 3 heures de boulot en écrasant tous mes .c par des fichiers vides, dégouté. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///var/svn/2011-ddhardrescue/trunk@6 d3078510-dda0-49f1-841c-895ef4b7ec81 --- inc/recover.h | 11 +++++++++++ inc/slices.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/essais/compil.sh | 2 +- src/essais/test.c | 32 +++++++++++++++++++++++--------- src/recover.h | 11 ----------- src/slices.h | 35 ----------------------------------- src/todo.txt | 2 -- todo.txt | 2 ++ 8 files changed, 81 insertions(+), 58 deletions(-) create mode 100755 inc/recover.h create mode 100755 inc/slices.h delete mode 100755 src/recover.h delete mode 100755 src/slices.h delete mode 100644 src/todo.txt create mode 100644 todo.txt diff --git a/inc/recover.h b/inc/recover.h new file mode 100755 index 0000000..85f1738 --- /dev/null +++ b/inc/recover.h @@ -0,0 +1,11 @@ +#ifndef RECOVER_H +#define RECOVER_H + +#include "slices.h" + +extern int end; + +slices_t *recover(char *src, char *dst, char*ddOpts, address_t beginSector, address_t endSector/*, int depth*/); +int tryRecoverUntilError(slice_t *sliceToRead, address_t *firstError, char *src, char *dst, char *ddOpts); + +#endif /*RECOVER_H*/ diff --git a/inc/slices.h b/inc/slices.h new file mode 100755 index 0000000..4b60ebc --- /dev/null +++ b/inc/slices.h @@ -0,0 +1,44 @@ +#ifndef SLICES_H +#define SLICES_H + +#include +#include + +/* IMPORTANT NOTES +Slice are inclusive intervals. Let say sliceNew(1,2,S_UNKNOWN,NULL) return a [1;2] interval, + so interval lenght is end-begin+1. Here, it is 2 sectors lenght slice. +*/ + +typedef enum { S_UNKNOWN, S_RECOVERED, S_UNREADABLE } sliceStatus_t; +typedef unsigned long long int address_t; + +typedef struct _slice { + address_t begin, end; + sliceStatus_t status; + struct _slice *next; +} slice_t; + +typedef struct { + int count; + slice_t *first, *last; +} slices_t; + +slice_t *sliceNew(address_t begin, address_t end, sliceStatus_t status, slice_t *next); + +// Return the numbers of slices after split (3 in the general case, 2 or 1 in particular cases. -1 is memory error) +int sliceSplit(slices_t *slices, slice_t *initialSlice, address_t splitAt, sliceStatus_t statusBefore, sliceStatus_t statusAt, sliceStatus_t statusAfter); + + +slices_t *slicesNewEmpty(); + +slices_t *sliceNewSingleton(begin, end, sliceStatus_t status); + +void slicesAppend(slices_t *slices, slice_t *slice); + +slice_t *slicesFindLargest(slices_t *slices, sliceStatus_t status); + +slice_t *slicesFindLargestFast(slices_t *slices, address_t *foundMax, sliceStatus_t status, address_t knownMax, slice_t *firstToTry); + +char *slicesDump(slices_t *slices, address_t *blockSize, unsigned int charCount, address_t begin, address_t end); + +#endif /*SLICES_H*/ diff --git a/src/essais/compil.sh b/src/essais/compil.sh index 0b2eda7..1581e9d 100755 --- a/src/essais/compil.sh +++ b/src/essais/compil.sh @@ -1 +1 @@ -gcc -Wall -lncurses test.c +gcc -Wall -g -lncurses test.c diff --git a/src/essais/test.c b/src/essais/test.c index 5e3a185..f8ce2b7 100644 --- a/src/essais/test.c +++ b/src/essais/test.c @@ -5,11 +5,9 @@ WINDOW *create_newwin(int height, int width, int starty, int startx) { WINDOW *local_win; local_win = newwin(height, width, starty, startx); - box(local_win, 0 , 0); /* 0, 0 gives default characters - * for the vertical and horizontal - * lines */ - wrefresh(local_win); /* Show that box */ - + wborder(local_win, '|', '|', '-', '-', '+', '+', '+', '+'); +// box(local_win,0,0); + wrefresh(local_win); return local_win; } @@ -33,23 +31,40 @@ int main() { int row,col; char msg[256]; WINDOW *w1; + MEVENT event; initscr(); getmaxyx(stdscr,row,col); raw(); keypad(stdscr, TRUE); noecho(); + + start_color(); + init_pair(1, COLOR_WHITE, COLOR_BLUE); + mousemask(ALL_MOUSE_EVENTS, NULL); +//http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/windows.html + //w1 = create_newwin(row/2, col/2, row/4, col/4); + w1 = create_newwin(10, 10, 10, 10); + attron(COLOR_PAIR(1) | A_BOLD); mvprintw(row-2,0,"This screen has %d rows and %d columns\n",row,col); + attroff(COLOR_PAIR(1) | A_BOLD); move(0,0); - -//http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/windows.html - w1 = create_newwin(row/2, col/2, row/4, col/4); + end=0; while (!end) { + refresh(); ch=getch(); switch(ch) { + case KEY_MOUSE: + if(getmouse(&event) == OK) { /* When the user clicks left mouse button */ + if(event.bstate & BUTTON1_PRESSED) { + attrset(A_NORMAL); + printw("mouse button1\n"); + } + } + break; case KEY_F(2): attrset(A_NORMAL); printw("F2 key\n"); @@ -65,7 +80,6 @@ int main() { wattrset(w1,A_BOLD | A_UNDERLINE); wprintw(w1, msg); } - refresh(); } endwin(); diff --git a/src/recover.h b/src/recover.h deleted file mode 100755 index 84c7286..0000000 --- a/src/recover.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef RECOVER_H -#define RECOVER_H - -#include "slices.h" - -extern int end; - -slices_t *recover(char *src, char *dst, char*ddOpts, address_t beginSector, address_t endSector/*, int depth*/); -int tryRecoverUntilError(slice_t *sliceToRead, address_t *firstError, char *src, char *dst, char*ddOpts); - -#endif /*RECOVER_H*/ diff --git a/src/slices.h b/src/slices.h deleted file mode 100755 index 85cb621..0000000 --- a/src/slices.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef SLICES_H -#define SLICES_H - -#include -#include - -/* IMPORTANT NOTES -Slice are inclusive intervals. Let say sliceNew(1,2,S_UNKNOWN,NULL) return a [1;2] interval, - so interval lenght is end-begin+1. Here, it is 2 sectors lenght slice. -*/ - -typedef enum { S_UNKNOWN, S_RECOVERED, S_UNREADABLE } sliceStatus_t; -typedef unsigned long long int address_t; - -typedef struct _slice { - address_t begin, end; - sliceStatus_t status; - struct _slice *next; -} slice_t; - -typedef struct { - int count; - slice_t *first, *last; -} slices_t; - -slice_t *sliceNew(address_t begin, address_t end, sliceStatus_t status, slice_t *next); -int sliceSplit(slices_t *slices, slice_t *initialSlice, address_t splitAt, sliceStatus_t statusBefore, sliceStatus_t statusAt, sliceStatus_t statusAfter); - -slices_t *slicesNew(); -void slicesAppend(slices_t *slices, slice_t *slice); -slice_t *slicesFindLargest(slices_t *slices, sliceStatus_t status); -slice_t *slicesFindLargestFast(slices_t *slices, address_t *foundMax, sliceStatus_t status, address_t knownMax, slice_t *firstToTry); -char *slicesDump(slices_t *slices, address_t *blockSize, unsigned int charCount, address_t begin, address_t end); - -#endif /*SLICES_H*/ diff --git a/src/todo.txt b/src/todo.txt deleted file mode 100644 index b4b48a2..0000000 --- a/src/todo.txt +++ /dev/null @@ -1,2 +0,0 @@ -a terter : exécution avec un dd qui fait 0 read error d'emblée ! -au qu'a dernier secteur.. diff --git a/todo.txt b/todo.txt new file mode 100644 index 0000000..b4b48a2 --- /dev/null +++ b/todo.txt @@ -0,0 +1,2 @@ +a terter : exécution avec un dd qui fait 0 read error d'emblée ! +au qu'a dernier secteur.. -- cgit v1.2.3