2009-04-13 19:25:46 +04:00
|
|
|
/* ncdu - NCurses Disk Usage
|
|
|
|
|
2009-01-11 12:34:19 +03:00
|
|
|
Copyright (c) 2007-2009 Yoran Heling
|
2007-07-20 15:15:46 +04:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
a copy of this software and associated documentation files (the
|
|
|
|
"Software"), to deal in the Software without restriction, including
|
|
|
|
without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
the following conditions:
|
2009-04-13 19:25:46 +04:00
|
|
|
|
2007-07-20 15:15:46 +04:00
|
|
|
The above copyright notice and this permission notice shall be included
|
|
|
|
in all copies or substantial portions of the Software.
|
2009-04-13 19:25:46 +04:00
|
|
|
|
2007-07-20 15:15:46 +04:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ncdu.h"
|
2009-04-13 19:25:46 +04:00
|
|
|
#include "browser.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "calc.h"
|
2007-07-20 15:15:46 +04:00
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ncurses.h>
|
2007-07-20 15:15:46 +04:00
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
#define ishidden(x) (stbrowse.flags & BF_HIDE && (\
|
|
|
|
(x->next != stbrowse.cur && (x->name[0] == '.' || x->name[strlen(x->name)-1] == '~'))\
|
|
|
|
|| x->flags & FF_EXL))
|
2007-07-20 15:15:46 +04:00
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
struct state_browser stbrowse;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2007-08-01 19:01:42 +04:00
|
|
|
void drawInfo(struct dir *dr) {
|
|
|
|
char path[PATH_MAX];
|
|
|
|
|
2007-08-16 12:36:58 +04:00
|
|
|
nccreate(11, 60, "Item info");
|
2007-08-01 19:01:42 +04:00
|
|
|
|
2007-08-16 12:36:58 +04:00
|
|
|
attron(A_BOLD);
|
|
|
|
ncaddstr(2, 3, "Name:");
|
|
|
|
ncaddstr(3, 3, "Path:");
|
|
|
|
ncaddstr(4, 3, "Type:");
|
|
|
|
ncaddstr(6, 3, " Disk usage:");
|
|
|
|
ncaddstr(7, 3, "Apparent size:");
|
|
|
|
attroff(A_BOLD);
|
2007-08-01 19:01:42 +04:00
|
|
|
|
2007-08-16 12:36:58 +04:00
|
|
|
ncaddstr(2, 9, cropdir(dr->name, 49));
|
|
|
|
ncaddstr(3, 9, cropdir(getpath(dr, path), 49));
|
|
|
|
ncaddstr(4, 9, dr->flags & FF_DIR ? "Directory"
|
2007-08-01 19:01:42 +04:00
|
|
|
: dr->flags & FF_FILE ? "File" : "Other (link, device, socket, ..)");
|
2007-08-16 12:36:58 +04:00
|
|
|
ncprint(6, 18, "%s (%s B)", cropsize(dr->size), fullsize(dr->size));
|
|
|
|
ncprint(7, 18, "%s (%s B)", cropsize(dr->asize), fullsize(dr->asize));
|
2007-08-01 19:01:42 +04:00
|
|
|
|
2008-09-20 13:35:21 +04:00
|
|
|
ncaddstr(9, 32, "Press i to hide this window");
|
2007-08-01 19:01:42 +04:00
|
|
|
}
|
2009-04-13 19:25:46 +04:00
|
|
|
*/
|
2007-08-01 19:01:42 +04:00
|
|
|
|
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
int browse_cmp(struct dir *x, struct dir *y) {
|
2007-07-20 15:15:46 +04:00
|
|
|
struct dir *a, *b;
|
|
|
|
int r = 0;
|
2007-07-24 11:58:22 +04:00
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
if(stbrowse.flags & BF_DESC) {
|
2007-07-20 15:15:46 +04:00
|
|
|
a = y; b = x;
|
|
|
|
} else {
|
|
|
|
b = y; a = x;
|
|
|
|
}
|
2009-04-13 19:25:46 +04:00
|
|
|
if(!(stbrowse.flags & BF_NDIRF) && y->flags & FF_DIR && !(x->flags & FF_DIR))
|
2007-07-24 12:53:55 +04:00
|
|
|
return(1);
|
2009-04-13 19:25:46 +04:00
|
|
|
if(!(stbrowse.flags & BF_NDIRF) && !(y->flags & FF_DIR) && x->flags & FF_DIR)
|
2007-07-24 12:53:55 +04:00
|
|
|
return(-1);
|
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
if(stbrowse.flags & BF_NAME)
|
2007-07-20 15:15:46 +04:00
|
|
|
r = strcmp(a->name, b->name);
|
2009-04-13 19:25:46 +04:00
|
|
|
if(stbrowse.flags & BF_AS) {
|
2008-12-11 20:13:03 +03:00
|
|
|
if(r == 0)
|
|
|
|
r = a->asize > b->asize ? 1 : (a->asize == b->asize ? 0 : -1);
|
|
|
|
if(r == 0)
|
|
|
|
r = a->size > b->size ? 1 : (a->size == b->size ? 0 : -1);
|
|
|
|
} else {
|
|
|
|
if(r == 0)
|
|
|
|
r = a->size > b->size ? 1 : (a->size == b->size ? 0 : -1);
|
|
|
|
if(r == 0)
|
|
|
|
r = a->asize > b->asize ? 1 : (a->asize == b->asize ? 0 : -1);
|
|
|
|
}
|
2007-07-24 12:53:55 +04:00
|
|
|
if(r == 0)
|
2007-07-26 20:37:33 +04:00
|
|
|
r = strcmp(x->name, y->name);
|
2007-07-20 15:15:46 +04:00
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
|
|
|
|
struct dir *browse_sort(struct dir *list) {
|
2007-07-20 15:15:46 +04:00
|
|
|
struct dir *p, *q, *e, *tail;
|
|
|
|
int insize, nmerges, psize, qsize, i;
|
|
|
|
|
|
|
|
insize = 1;
|
|
|
|
while(1) {
|
|
|
|
p = list;
|
|
|
|
list = NULL;
|
|
|
|
tail = NULL;
|
|
|
|
nmerges = 0;
|
|
|
|
while(p) {
|
|
|
|
nmerges++;
|
|
|
|
q = p;
|
|
|
|
psize = 0;
|
|
|
|
for(i=0; i<insize; i++) {
|
|
|
|
psize++;
|
|
|
|
q = q->next;
|
|
|
|
if(!q) break;
|
|
|
|
}
|
|
|
|
qsize = insize;
|
|
|
|
while(psize > 0 || (qsize > 0 && q)) {
|
|
|
|
if(psize == 0) {
|
|
|
|
e = q; q = q->next; qsize--;
|
|
|
|
} else if(qsize == 0 || !q) {
|
|
|
|
e = p; p = p->next; psize--;
|
2009-04-13 19:25:46 +04:00
|
|
|
} else if(browse_cmp(p,q) <= 0) {
|
2007-07-20 15:15:46 +04:00
|
|
|
e = p; p = p->next; psize--;
|
|
|
|
} else {
|
|
|
|
e = q; q = q->next; qsize--;
|
|
|
|
}
|
|
|
|
if(tail) tail->next = e;
|
|
|
|
else list = e;
|
|
|
|
tail = e;
|
|
|
|
}
|
|
|
|
p = q;
|
|
|
|
}
|
|
|
|
tail->next = NULL;
|
|
|
|
if(nmerges <= 1)
|
|
|
|
return list;
|
|
|
|
insize *= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
void browse_draw_item(struct dir *n, int row, off_t max, int ispar) {
|
|
|
|
char tmp[1000], ct, dt, *size, gr[11];
|
|
|
|
int i, o;
|
|
|
|
float pc;
|
2007-07-20 15:15:46 +04:00
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
if(n->flags & FF_BSEL)
|
|
|
|
attron(A_REVERSE);
|
|
|
|
|
|
|
|
/* reference to parent dir has a different format */
|
|
|
|
if(ispar) {
|
|
|
|
mvhline(row, 0, ' ', wincols);
|
|
|
|
o = stbrowse.graph == 0 ? 11 :
|
|
|
|
stbrowse.graph == 1 ? 23 :
|
|
|
|
stbrowse.graph == 2 ? 18 :
|
|
|
|
29 ;
|
|
|
|
mvaddstr(row, o, "/..");
|
|
|
|
if(n->flags & FF_BSEL)
|
|
|
|
attroff(A_REVERSE);
|
|
|
|
return;
|
|
|
|
}
|
2007-07-20 15:15:46 +04:00
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
/* determine indication character */
|
|
|
|
ct = n->flags & FF_EXL ? '<' :
|
|
|
|
n->flags & FF_ERR ? '!' :
|
|
|
|
n->flags & FF_SERR ? '.' :
|
|
|
|
n->flags & FF_OTHFS ? '>' :
|
|
|
|
!(n->flags & FF_FILE
|
|
|
|
|| n->flags & FF_DIR) ? '@' :
|
|
|
|
n->flags & FF_DIR
|
|
|
|
&& n->sub == NULL ? 'e' :
|
|
|
|
' ' ;
|
|
|
|
dt = n->flags & FF_DIR ? '/' : ' ';
|
|
|
|
size = formatsize(stbrowse.flags & BF_AS ? n->asize : n->size, sflags & SF_SI);
|
|
|
|
|
|
|
|
/* create graph (if necessary) */
|
|
|
|
pc = ((float)(stbrowse.flags & BF_AS ? n->asize : n->size) / (float)(stbrowse.flags & BF_AS ? n->parent->asize : n->parent->size)) * 100.0f;
|
|
|
|
if(stbrowse.graph == 1 || stbrowse.graph == 3) {
|
|
|
|
o = (int)(10.0f*(float)(stbrowse.flags & BF_AS ? n->asize : n->size) / (float)max);
|
|
|
|
for(i=0; i<10; i++)
|
|
|
|
gr[i] = i < o ? '#' : ' ';
|
|
|
|
gr[10] = '\0';
|
|
|
|
}
|
2007-07-24 11:58:22 +04:00
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
/* format and add item to the list */
|
|
|
|
switch(stbrowse.graph) {
|
|
|
|
case 0:
|
|
|
|
sprintf(tmp, "%%c %%7s %%c%%-%ds", wincols-12);
|
|
|
|
mvprintw(row, 0, tmp, ct, size, dt, cropstr(n->name, wincols-12));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
sprintf(tmp, "%%c %%7s [%%10s] %%c%%-%ds", wincols-24);
|
|
|
|
mvprintw(row, 0, tmp, ct, size, gr, dt, cropstr(n->name, wincols-24));
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
sprintf(tmp, "%%c %%7s [%%4.1f%%%%] %%c%%-%ds", wincols-19);
|
|
|
|
mvprintw(row, 0, tmp, ct, size, pc, dt, cropstr(n->name, wincols-19));
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
sprintf(tmp, "%%c %%7s [%%4.1f%%%% %%10s] %%c%%-%ds", wincols-30);
|
|
|
|
mvprintw(row, 0, tmp, ct, size, pc, gr, dt, cropstr(n->name, wincols-30));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(n->flags & FF_BSEL)
|
|
|
|
attroff(A_REVERSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int browse_draw() {
|
|
|
|
struct dir *n, ref, *cur;
|
|
|
|
char tmp[PATH_MAX];
|
|
|
|
int selected, i;
|
2007-07-29 14:50:48 +04:00
|
|
|
off_t max = 1;
|
2007-07-20 15:15:46 +04:00
|
|
|
|
2007-07-24 11:58:22 +04:00
|
|
|
erase();
|
2009-04-13 19:25:46 +04:00
|
|
|
cur = stbrowse.cur;
|
2007-07-24 11:58:22 +04:00
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
/* exit if there are no items to display */
|
|
|
|
if(cur == NULL || cur->parent == NULL) {
|
|
|
|
if(cur == NULL || cur->sub == NULL) {
|
2007-07-20 15:15:46 +04:00
|
|
|
erase();
|
|
|
|
refresh();
|
|
|
|
endwin();
|
|
|
|
printf("No items to display...\n");
|
|
|
|
exit(0);
|
|
|
|
} else
|
2009-04-13 19:25:46 +04:00
|
|
|
stbrowse.cur = cur = cur->sub;
|
2007-07-20 15:15:46 +04:00
|
|
|
}
|
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
/* create header and status bar */
|
2007-07-20 15:15:46 +04:00
|
|
|
attron(A_REVERSE);
|
2007-07-24 11:58:22 +04:00
|
|
|
mvhline(0, 0, ' ', wincols);
|
|
|
|
mvhline(winrows-1, 0, ' ', wincols);
|
2007-07-20 15:15:46 +04:00
|
|
|
mvprintw(0,0,"%s %s ~ Use the arrow keys to navigate, press ? for help", PACKAGE_NAME, PACKAGE_VERSION);
|
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
strcpy(tmp, formatsize(cur->parent->size, sflags & SF_SI));
|
2007-08-01 17:17:26 +04:00
|
|
|
mvprintw(winrows-1, 0, " Total disk usage: %s Apparent size: %s Items: %d",
|
2009-04-13 19:25:46 +04:00
|
|
|
tmp, formatsize(cur->parent->asize, sflags & SF_SI), cur->parent->items);
|
2007-08-01 17:17:26 +04:00
|
|
|
attroff(A_REVERSE);
|
2009-04-13 19:25:46 +04:00
|
|
|
|
2007-07-24 11:58:22 +04:00
|
|
|
mvhline(1, 0, '-', wincols);
|
2008-08-02 22:29:35 +04:00
|
|
|
mvaddch(1, 3, ' ');
|
2009-04-13 19:25:46 +04:00
|
|
|
getpath(cur, tmp);
|
|
|
|
mvaddstr(1, 4, cropstr(tmp, wincols-8));
|
|
|
|
mvaddch(1, 4+((int)strlen(tmp) > wincols-8 ? wincols-8 : (int)strlen(tmp)), ' ');
|
2007-07-24 11:58:22 +04:00
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
/* TODO: don't sort when it's not necessary */
|
|
|
|
cur = stbrowse.cur = browse_sort(cur);
|
|
|
|
cur->parent->sub = cur;
|
|
|
|
|
|
|
|
/* add reference to parent dir */
|
2007-08-12 13:52:24 +04:00
|
|
|
memset(&ref, 0, sizeof(struct dir));
|
2009-04-13 19:25:46 +04:00
|
|
|
if(cur->parent->parent) {
|
2007-08-12 13:52:24 +04:00
|
|
|
ref.name = "..";
|
2009-04-13 19:25:46 +04:00
|
|
|
ref.next = cur;
|
|
|
|
ref.parent = cur->parent;
|
|
|
|
cur = &ref;
|
2007-08-12 13:52:24 +04:00
|
|
|
}
|
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
/* get maximum size and selected item */
|
|
|
|
for(n=cur, selected=i=0; n!=NULL; n=n->next) {
|
|
|
|
if(ishidden(n))
|
|
|
|
continue;
|
2007-07-24 11:58:22 +04:00
|
|
|
if(n->flags & FF_BSEL)
|
|
|
|
selected = i;
|
2009-04-13 19:25:46 +04:00
|
|
|
if((stbrowse.flags & BF_AS ? n->asize : n->size) > max)
|
|
|
|
max = stbrowse.flags & BF_AS ? n->asize : n->size;
|
|
|
|
i++;
|
2007-07-20 15:15:46 +04:00
|
|
|
}
|
2009-04-13 19:25:46 +04:00
|
|
|
if(!selected)
|
|
|
|
cur->flags |= FF_BSEL;
|
2007-07-20 15:15:46 +04:00
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
/* determine start position */
|
|
|
|
for(n=cur,i=0; n!=NULL; n=n->next) {
|
|
|
|
if(ishidden(n))
|
|
|
|
continue;
|
2007-07-24 11:58:22 +04:00
|
|
|
if(i == (selected / (winrows-3)) * (winrows-3))
|
|
|
|
break;
|
2009-04-13 19:25:46 +04:00
|
|
|
i++;
|
2007-07-24 11:58:22 +04:00
|
|
|
}
|
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
/* print the list to the screen */
|
|
|
|
for(i=0; n!=NULL && i<winrows-3; n=n->next) {
|
|
|
|
if(ishidden(n))
|
2007-07-20 15:15:46 +04:00
|
|
|
continue;
|
2009-04-13 19:25:46 +04:00
|
|
|
browse_draw_item(n, 2+i++, max, n == &ref);
|
2007-07-20 15:15:46 +04:00
|
|
|
}
|
2007-08-12 13:52:24 +04:00
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
/* move cursor to selected row for accessibility */
|
2008-08-02 17:31:21 +04:00
|
|
|
move(selected+2, 0);
|
2009-04-13 19:25:46 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-02 17:31:21 +04:00
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
|
|
|
|
#define toggle(x,y) if(x & y) x -=y; else x |= y
|
|
|
|
#define hideinfo if(stbrowse.flags & BF_INFO) stbrowse.flags -= BF_INFO
|
|
|
|
|
|
|
|
void browse_key_sel(int change) {
|
|
|
|
struct dir *n, *cur, par;
|
|
|
|
int i, max;
|
|
|
|
|
|
|
|
cur = stbrowse.cur;
|
|
|
|
par.next = cur;
|
|
|
|
if(stbrowse.cur->parent->parent)
|
|
|
|
cur = ∥
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
max = -1;
|
|
|
|
for(n=cur; n!=NULL; n=n->next) {
|
|
|
|
if(!ishidden(n)) {
|
|
|
|
max++;
|
|
|
|
if(n->flags & FF_BSEL)
|
|
|
|
i = max;
|
|
|
|
}
|
|
|
|
n->flags &= ~FF_BSEL;
|
2008-09-20 13:35:21 +04:00
|
|
|
}
|
2009-04-13 19:25:46 +04:00
|
|
|
i += change;
|
|
|
|
i = i<0 ? 0 : i>max ? max : i;
|
2008-09-20 13:35:21 +04:00
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
for(n=cur; n!=NULL; n=n->next)
|
|
|
|
if(!ishidden(n) && !i--)
|
|
|
|
n->flags |= FF_BSEL;
|
2007-07-24 11:58:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
int browse_key(int ch) {
|
|
|
|
struct dir *n;
|
2007-07-24 11:58:22 +04:00
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
switch(ch) {
|
|
|
|
/* selecting items */
|
|
|
|
case KEY_UP:
|
|
|
|
browse_key_sel(-1);
|
|
|
|
break;
|
|
|
|
case KEY_DOWN:
|
|
|
|
browse_key_sel(1);
|
|
|
|
break;
|
|
|
|
case KEY_HOME:
|
|
|
|
browse_key_sel(-1*(1<<30));
|
|
|
|
break;
|
|
|
|
case KEY_LL:
|
|
|
|
case KEY_END:
|
|
|
|
browse_key_sel(1<<30);
|
|
|
|
break;
|
|
|
|
case KEY_PPAGE:
|
|
|
|
browse_key_sel(-1*(winrows-3));
|
|
|
|
break;
|
|
|
|
case KEY_NPAGE:
|
|
|
|
browse_key_sel(winrows-3);
|
|
|
|
break;
|
2007-07-24 11:58:22 +04:00
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
/* sorting items */
|
|
|
|
case 'n':
|
|
|
|
hideinfo;
|
|
|
|
if(stbrowse.flags & BF_NAME)
|
|
|
|
toggle(stbrowse.flags, BF_DESC);
|
|
|
|
else
|
|
|
|
stbrowse.flags = (stbrowse.flags & BF_HIDE) + (stbrowse.flags & BF_NDIRF) + BF_NAME;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
hideinfo;
|
|
|
|
if(stbrowse.flags & BF_SIZE)
|
|
|
|
toggle(stbrowse.flags, BF_DESC);
|
|
|
|
else
|
|
|
|
stbrowse.flags = (stbrowse.flags & BF_HIDE) + (stbrowse.flags & BF_NDIRF) + BF_SIZE + BF_DESC;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
hideinfo;
|
|
|
|
toggle(sflags, SF_SI);
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
hideinfo;
|
|
|
|
toggle(stbrowse.flags, BF_HIDE);
|
|
|
|
browse_key_sel(0);
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
hideinfo;
|
|
|
|
toggle(stbrowse.flags, BF_NDIRF);
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
hideinfo;
|
|
|
|
toggle(stbrowse.flags, BF_AS);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* browsing */
|
|
|
|
case 10:
|
|
|
|
case KEY_RIGHT:
|
|
|
|
hideinfo;
|
|
|
|
for(n=stbrowse.cur; n!=NULL; n=n->next)
|
|
|
|
if(n->flags & FF_BSEL)
|
|
|
|
break;
|
|
|
|
if(n != NULL && n->sub != NULL)
|
|
|
|
stbrowse.cur = n->sub;
|
|
|
|
if(n == NULL && stbrowse.cur->parent->parent)
|
|
|
|
stbrowse.cur = stbrowse.cur->parent->parent->sub;
|
|
|
|
break;
|
|
|
|
case KEY_LEFT:
|
|
|
|
hideinfo;
|
|
|
|
if(stbrowse.cur->parent->parent != NULL)
|
|
|
|
stbrowse.cur = stbrowse.cur->parent->parent->sub;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* refresh *
|
|
|
|
case 'r':
|
|
|
|
hideinfo;
|
|
|
|
drawBrowser(0);
|
|
|
|
if((n = showCalc(getpath(bcur, tmp))) != NULL) {
|
|
|
|
* free current items *
|
|
|
|
d = bcur;
|
|
|
|
bcur = bcur->parent;
|
|
|
|
while(d != NULL) {
|
|
|
|
t = d;
|
|
|
|
d = t->next;
|
|
|
|
freedir(t);
|
2007-07-24 11:58:22 +04:00
|
|
|
}
|
2009-04-13 19:25:46 +04:00
|
|
|
|
|
|
|
* update parent dir *
|
|
|
|
bcur->sub = n->sub;
|
|
|
|
bcur->items = n->items;
|
|
|
|
bcur->size = n->size;
|
|
|
|
bcur->asize = n->asize;
|
|
|
|
for(t = bcur->sub; t != NULL; t = t->next)
|
|
|
|
t->parent = bcur;
|
|
|
|
|
|
|
|
* update sizes of parent dirs *
|
|
|
|
for(t = bcur; (t = t->parent) != NULL; ) {
|
|
|
|
t->size += bcur->size;
|
|
|
|
t->asize += bcur->asize;
|
|
|
|
t->items += bcur->items;
|
2007-07-26 16:56:24 +04:00
|
|
|
}
|
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
bcur = bcur->sub;
|
|
|
|
free(n->name);
|
|
|
|
free(n);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* and other stuff */
|
|
|
|
case 'q':
|
|
|
|
return 1;
|
|
|
|
case 'g':
|
|
|
|
hideinfo;
|
|
|
|
if(++stbrowse.graph > 3) stbrowse.graph = 0;
|
|
|
|
break;
|
|
|
|
/*
|
|
|
|
case '?':
|
|
|
|
hideinfo;
|
|
|
|
showHelp();
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
toggle(stbrowse.flags, BF_INFO);
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
hideinfo;
|
|
|
|
drawBrowser(0);
|
|
|
|
n = selected();
|
|
|
|
if(n != bcur->parent)
|
|
|
|
bcur = showDelete(n);
|
|
|
|
if(bcur && bcur->parent)
|
|
|
|
bcur = bcur->parent->sub;
|
|
|
|
break;
|
|
|
|
*/
|
2007-07-20 15:15:46 +04:00
|
|
|
}
|
2009-04-13 19:25:46 +04:00
|
|
|
return 0;
|
2007-07-20 15:15:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|