From 70605d6fea205dc6b6d2c30c95cfb449c170108a Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Sat, 8 Oct 2011 18:58:36 +0000 Subject: slicesDump éclatée en vue d'une mise à jour partielle de la fenetre à chaque modification. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///var/svn/2011-ddhardrescue/trunk@26 d3078510-dda0-49f1-841c-895ef4b7ec81 --- src/slices.c | 89 ++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 48 insertions(+), 41 deletions(-) diff --git a/src/slices.c b/src/slices.c index 06fa1b7..fae363a 100644 --- a/src/slices.c +++ b/src/slices.c @@ -203,19 +203,61 @@ slice_t *slicesFindLargestFast(slices_t *slices, address_t *foundMax, sliceStatu return sMax; } +void _sliceDump(char *dump, slice_t *curr, address_t blockSize, unsigned int charCount, address_t begin, address_t end) { + address_t sb,se,i; + char ci; + + // If "curr" slice is (partially) contained/visible in the [begin,end] display interval + if ( !(curr->end < begin) && !(curr->begin > end) ) { + // Draw the slice on the right number of characters + // Mathematically correct, but crashes because address_t is UNSIGNED + // sb=MAX(0, (curr->begin - begin) / *blockSize); + sb=(curr->begin < begin)?0:(curr->begin - begin) / blockSize; + se=MIN((curr->end - begin) / blockSize, charCount-1); + + /* Debug "assertion" + if (sb >= charCount || se >= charCount) { + printf("BUG : sb==%lli, se=%lli, charCount==%i\n", sb, se, charCount); + printf("BUG : MAX(0, (%lli - %lli) / %lli)", curr->begin, begin, blockSize); + pthread_mutex_unlock(&(slices->writeOrConsistentReadMutex)); + exit(42); + }*/ + + // Choose from the current slice status the right char to draw + switch (curr->status) { + case S_UNKNOWN: ci='_'; break; + case S_UNREADABLE: ci='!'; break; + case S_RECOVERED: ci='.'; break; + default: ci='~'; break; + } + + // Draw on the right number of characters, paying attention with information collision + for (i=sb;i<=se;i++) { + if (dump[i] == ' ' ) { + // This is a new information + dump[i]=ci; + } else if ( dump[i] == ci || dump[i] == '!' ) { + // Already the right information or error, don't modify + } else { + // Multiple information on the same character + dump[i]='#'; + } + } + } +} + char *slicesDump(slices_t *slices, address_t *blockSize, unsigned int charCount, address_t begin, address_t end) { int res; slice_t *curr; - address_t sb,se,i; - char *dump, ci; + char *dump; res=pthread_mutex_lock(&(slices->writeOrConsistentReadMutex)); if (res!=0) { + //FIXME Trashy code perror("slicesDump, pb lock mutex"); exit(42); } - curr = slices->first; // If blockSize is 0, try to autodetect to display entire slice chain if (*blockSize == 0) { *blockSize=(end-begin+1)/(charCount-1); @@ -228,45 +270,10 @@ char *slicesDump(slices_t *slices, address_t *blockSize, unsigned int charCount, memset(dump, ' ', charCount); dump[charCount]=0; - //For each slice + //For each slice write in dump ASCII representation + curr = slices->first; while (curr != NULL) { - // If "curr" slice is (partially) contained/visible in the [begin,end] display interval - if ( !(curr->end < begin) && !(curr->begin > end) ) { - // Draw the slice on the right number of characters - // Mathematically correct, but crashes because address_t is UNSIGNED - // sb=MAX(0, (curr->begin - begin) / *blockSize); - sb=(curr->begin < begin)?0:(curr->begin - begin) / *blockSize; - se=MIN((curr->end - begin) / *blockSize, charCount-1); - - /* Debug "assertion" - if (sb >= charCount || se >= charCount) { - printf("BUG : sb==%lli, se=%lli, charCount==%i\n", sb, se, charCount); - printf("BUG : MAX(0, (%lli - %lli) / %lli)", curr->begin, begin, *blockSize); - pthread_mutex_unlock(&(slices->writeOrConsistentReadMutex)); - exit(42); - }*/ - - // Choose from the current slice status the right char to draw - switch (curr->status) { - case S_UNKNOWN: ci='_'; break; - case S_UNREADABLE: ci='!'; break; - case S_RECOVERED: ci='.'; break; - default: ci='~'; break; - } - - // Draw on the right number of characters, paying attention with information collision - for (i=sb;i<=se;i++) { - if (dump[i] == ' ' ) { - // This is a new information - dump[i]=ci; - } else if ( dump[i] == ci || dump[i] == '!' ) { - // Already the right information or error, don't modify - } else { - // Multiple information on the same character - dump[i]='#'; - } - } - } + _sliceDump(dump, curr, *blockSize, charCount, begin, end); curr=curr->next; } -- cgit v1.2.3