The "reference to parent directory" hack is now only used in drawBrowser in browser.c, and is not included in the main dir structure anymore. (less code, easier, faster, less memory usage)
git-svn-id: svn://blicky.net/ncdu/trunk@26 ce56bc8d-f834-0410-b703-f827bd498a76
Этот коммит содержится в:
родитель
55405140f7
Коммит
96d0ffffa2
@ -61,11 +61,6 @@ int cmp(struct dir *x, struct dir *y) {
|
||||
struct dir *a, *b;
|
||||
int r = 0;
|
||||
|
||||
if(y->flags & FF_PAR)
|
||||
return(1);
|
||||
if(x->flags & FF_PAR)
|
||||
return(-1);
|
||||
|
||||
if(bflags & BF_DESC) {
|
||||
a = y; b = x;
|
||||
} else {
|
||||
@ -150,7 +145,7 @@ char *graph(off_t max, off_t size) {
|
||||
) { i--; continue; }
|
||||
|
||||
void drawBrowser(int change) {
|
||||
struct dir *n;
|
||||
struct dir *n, ref;
|
||||
char tmp[PATH_MAX], ct, dt, *size;
|
||||
int selected, i, o;
|
||||
off_t max = 1;
|
||||
@ -189,6 +184,16 @@ void drawBrowser(int change) {
|
||||
bflags |= BF_SORT;
|
||||
}
|
||||
|
||||
/* add reference to parent dir */
|
||||
memset(&ref, 0, sizeof(struct dir));
|
||||
if(bcur->parent->parent) {
|
||||
ref.flags |= FF_PAR;
|
||||
ref.name = "..";
|
||||
ref.next = bcur;
|
||||
ref.parent = bcur->parent;
|
||||
bcur = &ref;
|
||||
}
|
||||
|
||||
/* get maximum size and selected item */
|
||||
for(n = bcur, selected = i = 0; n != NULL; n = n->next, i++) {
|
||||
exlhid(n)
|
||||
@ -295,6 +300,10 @@ void drawBrowser(int change) {
|
||||
if(i == selected)
|
||||
attroff(A_REVERSE);
|
||||
}
|
||||
|
||||
/* remove reference to parent dir */
|
||||
if(bcur == &ref)
|
||||
bcur = ref.next;
|
||||
}
|
||||
|
||||
struct dir * selected(void) {
|
||||
@ -303,6 +312,8 @@ struct dir * selected(void) {
|
||||
if(n->flags & FF_BSEL)
|
||||
return n;
|
||||
} while((n = n->next) != NULL);
|
||||
if(bcur->parent->parent)
|
||||
return(bcur->parent);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -380,7 +391,7 @@ void showBrowser(void) {
|
||||
case 10:
|
||||
case KEY_RIGHT:
|
||||
n = selected();
|
||||
if(n->flags & FF_PAR)
|
||||
if(n == bcur->parent)
|
||||
bcur = bcur->parent->parent->sub;
|
||||
else if(n->sub != NULL)
|
||||
bcur = n->sub;
|
||||
@ -416,17 +427,6 @@ void showBrowser(void) {
|
||||
t->items += bcur->items;
|
||||
}
|
||||
|
||||
/* add reference to parent dir */
|
||||
if(bcur->parent) {
|
||||
t = calloc(sizeof(struct dir), 1);
|
||||
t->name = malloc(3);
|
||||
t->flags |= FF_PAR;
|
||||
strcpy(t->name, "..");
|
||||
t->parent = bcur;
|
||||
t->next = bcur->sub;
|
||||
bcur->sub = t;
|
||||
}
|
||||
|
||||
bcur = bcur->sub;
|
||||
free(n->name);
|
||||
free(n);
|
||||
@ -445,7 +445,7 @@ void showBrowser(void) {
|
||||
break;
|
||||
case 'i':
|
||||
n = selected();
|
||||
if(!(n->flags & FF_PAR)) {
|
||||
if(n != bcur->parent) {
|
||||
drawInfo(n);
|
||||
while(getch() == KEY_RESIZE) {
|
||||
drawBrowser(0);
|
||||
@ -455,7 +455,7 @@ void showBrowser(void) {
|
||||
break;
|
||||
case 'd':
|
||||
n = selected();
|
||||
if(!(n->flags & FF_PAR))
|
||||
if(n != bcur->parent)
|
||||
bcur = showDelete(n);
|
||||
if(bcur && bcur->parent)
|
||||
bcur = bcur->parent->sub;
|
||||
|
17
src/calc.c
17
src/calc.c
@ -345,17 +345,8 @@ int calcDir(struct dir *dest, char *path) {
|
||||
}
|
||||
|
||||
if(dest->sub) {
|
||||
/* add reference to parent dir */
|
||||
d = calloc(sizeof(struct dir), 1);
|
||||
d->flags |= FF_PAR;
|
||||
d->name = malloc(3);
|
||||
strcpy(d->name, "..");
|
||||
d->next = dest->sub;
|
||||
d->parent = dest;
|
||||
dest->sub = d;
|
||||
|
||||
/* calculate subdirectories */
|
||||
while((d = d->next) != NULL)
|
||||
for(d = dest->sub; d != NULL; d = d->next)
|
||||
if(d->flags & FF_DIR && !(d->flags & FF_EXL || d->flags & FF_OTHFS)) {
|
||||
strcpy(tmp, path);
|
||||
strcat(tmp, d->name);
|
||||
@ -406,12 +397,6 @@ struct dir *showCalc(char *path) {
|
||||
freedir(parent);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* remove reference to parent dir if we are in the parent dir */
|
||||
t = parent->sub;
|
||||
parent->sub = t->next;
|
||||
free(t->name);
|
||||
free(t);
|
||||
|
||||
return(parent);
|
||||
}
|
||||
|
@ -149,15 +149,13 @@ struct dir *deleteDir(struct dir *dr) {
|
||||
while(nxt != NULL) {
|
||||
cur = nxt;
|
||||
nxt = cur->next;
|
||||
if(cur->flags & FF_PAR)
|
||||
continue;
|
||||
if(deleteDir(cur) == NULL)
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
ch = rmdir(file);
|
||||
} else
|
||||
ch = unlink(file);
|
||||
ch = unlink(file);
|
||||
|
||||
/* error occured, ask user what to do */
|
||||
if(ch == -1 && !(sflags & SF_IGNE)) {
|
||||
|
17
src/export.c
17
src/export.c
@ -69,8 +69,6 @@ void _writeInt(FILE *wr, unsigned char *word, int storage, int size) {
|
||||
long calcItems(struct dir *dr) {
|
||||
int count = 0;
|
||||
do {
|
||||
if(dr->flags & FF_PAR)
|
||||
continue;
|
||||
if(dr->sub)
|
||||
count += calcItems(dr->sub);
|
||||
count++;
|
||||
@ -84,9 +82,6 @@ void writeDirs(FILE *wr, struct dir *dr) {
|
||||
unsigned char f;
|
||||
|
||||
do {
|
||||
if(dr->flags & FF_PAR)
|
||||
continue;
|
||||
|
||||
/* flags - the slow but portable way */
|
||||
f = 0;
|
||||
if(dr->flags & FF_DIR) f += EF_DIR;
|
||||
@ -202,17 +197,7 @@ struct dir *importFile(char *filename) {
|
||||
if(!prev)
|
||||
parent = cur;
|
||||
else if(curlev > level) {
|
||||
/* create a reference to the parent dir... meh, stupid hack */
|
||||
if(curlev > 1) {
|
||||
tmp = calloc(sizeof(struct dir), 1);
|
||||
tmp->name = malloc(3);
|
||||
strcpy(tmp->name, "..");
|
||||
tmp->flags |= FF_PAR;
|
||||
prev->sub = tmp;
|
||||
tmp->next = cur;
|
||||
tmp->parent = prev;
|
||||
} else
|
||||
prev->sub = cur;
|
||||
prev->sub = cur;
|
||||
cur->parent = prev;
|
||||
} else if(curlev == level) {
|
||||
prev->next = cur;
|
||||
|
@ -94,7 +94,7 @@ static unsigned int endian_test = 1;
|
||||
#define FF_EXL 0x10 /* excluded using exlude patterns */
|
||||
#define FF_SERR 0x20 /* error in subdirectory */
|
||||
#define FF_BSEL 0x40 /* selected */
|
||||
#define FF_PAR 0x80 /* reference to parent directory (hack) */
|
||||
#define FF_PAR 0x80 /* reference to parent directory (hack - only used in browser.c) */
|
||||
|
||||
/* Settings Flags (int sflags) */
|
||||
#define SF_SMFS 0x01 /* same filesystem */
|
||||
|
@ -134,6 +134,7 @@ struct dir *freedir(struct dir *dr) {
|
||||
tmp = dr;
|
||||
while((tmp = tmp->parent) != NULL) {
|
||||
tmp->size -= dr->size;
|
||||
tmp->asize -= dr->asize;
|
||||
tmp->items -= dr->items+1;
|
||||
}
|
||||
|
||||
@ -155,6 +156,9 @@ struct dir *freedir(struct dir *dr) {
|
||||
tmp->next = dr->next;
|
||||
cur = tmp;
|
||||
}
|
||||
/* no previous item, refer to parent dir */
|
||||
if(cur == NULL && dr->parent->parent)
|
||||
cur = dr->parent;
|
||||
}
|
||||
if(cur != NULL)
|
||||
cur->flags |= FF_BSEL;
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user