From 809fe0d67eb39f9ec08bca65735241803bc923f3 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Sat, 8 Oct 2011 17:05:19 +0000 Subject: Correction du bug de zoom (c'était juste le calcul de "pos" qui était foireux). Création des méthodes sliceDelete et slicesDelete et utilisation à la fin du main. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///var/svn/2011-ddhardrescue/trunk@25 d3078510-dda0-49f1-841c-895ef4b7ec81 --- src/cursesview.c | 28 ++++++++++++++++++---------- src/ddhardrescue.c | 16 +++------------- src/slices.c | 16 ++++++++++++++++ 3 files changed, 37 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/cursesview.c b/src/cursesview.c index 36e125e..0b346fb 100644 --- a/src/cursesview.c +++ b/src/cursesview.c @@ -23,7 +23,7 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin void makeWin(WINDOW **win, PANEL **panel, int h, int w, int y, int x, char title[]); void cursesMainLoop(slices_evt_t *slicesEvt) { - char msgViewedArea[255]; + char msg[255]; int ch, i; WINDOW *wins[CURSESWIN_COUNT]; @@ -59,6 +59,7 @@ void cursesMainLoop(slices_evt_t *slicesEvt) { switch(ch) { // Zoom handling + //FIXME : Do something less stupid. Try to reuse mouse event zoom code for keyboard case KEY_F(5): sliceDumpEnd=(sliceDumpBegin+sliceDumpEnd)/2; break; @@ -97,11 +98,10 @@ void cursesMainLoop(slices_evt_t *slicesEvt) { // If we found a panel, dispatch the event if a listener is set if (p != NULL) { - dispatched=0; mouseEventListener=(int (*)(MEVENT mevent, WINDOW *winDebug)) panel_userptr(p); - if (mouseEventListener != NULL) dispatched=mouseEventListener(mevent, wins[0]); + dispatched=(mouseEventListener==NULL)?0:mouseEventListener(mevent, wins[0]); if ( ! dispatched ) { - // If no listener or event not consumed, use the default behavior : set the panel on top + // If no listener or event not consumed, use the default behavior : set the panel on top if BUTTON1_CLICKED if ( (mevent.bstate & BUTTON1_CLICKED) == BUTTON1_CLICKED) { top_panel(p); } @@ -110,13 +110,18 @@ void cursesMainLoop(slices_evt_t *slicesEvt) { } break; #endif + default: + sprintf(msg, "Unhandled key ch==0x%x", ch); + wattron(wins[0], COLOR_PAIR(4)); + mvwprintw(wins[0], 2, 0, msg); + } doupdate(); - sprintf(msgViewedArea, "Viewing [%lli-%lli] of [%lli-%lli] working region ", sliceDumpBegin, sliceDumpEnd, slicesEvt->data->min, slicesEvt->data->max); + sprintf(msg, "Viewing [%lli-%lli] of [%lli-%lli] working region ", sliceDumpBegin, sliceDumpEnd, slicesEvt->data->min, slicesEvt->data->max); wattron(wins[0], COLOR_PAIR(4)); - mvwprintw(wins[0], 1, 0, msgViewedArea); + mvwprintw(wins[0], 1, 0, msg); pthread_mutex_unlock(&ncursesWriteMutex); } @@ -137,23 +142,26 @@ int winUpdateSliceDumpMouseEventListener(MEVENT mevent, WINDOW *winDebug) { int pX, pY, maxX, maxY; address_t delta; float pos; - char buf[255]; + // For debugging char buf[255]; pY=mevent.y; pX=mevent.x; resb=wmouse_trafo(winUpdateSliceDump, &pY, &pX, false); if ( resb == TRUE ) { getmaxyx(winUpdateSliceDump, maxY, maxX); - pos=(0.0f+pY*maxX+pX)/(maxY*maxX); + // First ligne (pY) is line 1 but first char (pX) is char 0 so we have to translate Y coords by -1 + pos=(0.0f+(pY-1)*maxX+pX)/((maxY-1)*maxX-1); delta=sliceDumpEnd-sliceDumpBegin; sliceDumpBegin+=delta*pos/DEFAULT_ZOOM_FACTOR*(DEFAULT_ZOOM_FACTOR-1); sliceDumpEnd-=delta*(1-pos)/DEFAULT_ZOOM_FACTOR*(DEFAULT_ZOOM_FACTOR-1); } -//FIXME : pb avec le zoom factor - sprintf(buf, "Debug : pos==%f, sliceDumpEnd==%lli, sliceDumpBegin=%lli, delta==%lli", pos, sliceDumpEnd, sliceDumpBegin, delta); +/* + // Debug code + sprintf(buf, "Debug : pX==%i, pY==%i, maxX==%i, maxY==%i, pos==%f, sliceDumpEnd==%lli, sliceDumpBegin=%lli, delta==%lli", pX, pY, maxX, maxY, pos, sliceDumpEnd, sliceDumpBegin, delta); wattron(winDebug, COLOR_PAIR(4)); mvwprintw(winDebug, 2, 0, buf); +*/ return 1; } diff --git a/src/ddhardrescue.c b/src/ddhardrescue.c index 67c061b..c83fffd 100644 --- a/src/ddhardrescue.c +++ b/src/ddhardrescue.c @@ -36,7 +36,7 @@ int main(int argc, char **argv) { struct threadArgs tArgs; // Algorithmic needs - int res, i; + int res; // Parse command-line arguments res=parseArgs(argc, argv, &args); @@ -101,18 +101,8 @@ int main(int argc, char **argv) { //Resources desallocation (void) pthread_mutex_destroy(&(slices.eventListenerMutex)); - - //XXX Method for that - slice_t *curr, *toFree; - i=0; curr=slices.data->first; - while (curr!=NULL) { - i++; - toFree=curr; - curr=curr->next; - free(toFree); - } - free(slices.data); - + slicesDelete(slices.data); + return 0; } diff --git a/src/slices.c b/src/slices.c index 36f7bb1..06fa1b7 100644 --- a/src/slices.c +++ b/src/slices.c @@ -20,6 +20,10 @@ slice_t *sliceNew(address_t begin, address_t end, sliceStatus_t status, slice_t return s; } +void sliceDelete(slice_t *s) { + free(s); +} + // 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) { slice_t *secondSlice, *thirdSlice, *rightSlice; @@ -122,6 +126,18 @@ slices_t *slicesNewSingleton(address_t begin, address_t end, sliceStatus_t statu return ss; } +void slicesDelete(slices_t *ss) { + slice_t *curr, *toFree; + + curr=ss->first; + while (curr!=NULL) { + toFree=curr; + curr=curr->next; + sliceDelete(toFree); + } + free(ss); +} + void slicesAppend(slices_t *slices, slice_t *slice) { pthread_mutex_lock(&(slices->writeOrConsistentReadMutex)); -- cgit v1.2.3