summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryorhel <yorhel@ce56bc8d-f834-0410-b703-f827bd498a76>2007-08-01 13:17:26 +0000
committeryorhel <yorhel@ce56bc8d-f834-0410-b703-f827bd498a76>2007-08-01 13:17:26 +0000
commitfa0aa6b53b98ed0c54c0e45dee887a3696543e12 (patch)
treef72c1fcef8f11c63ea2460d155052d47bb96ef38
parent4859bc8810ffe3d340c8a9c25e1598a400f49999 (diff)
* Calculate both apparent size and disk usage
* Removed apparent sizes option * Combined "files" and "dirs" to "items" in the dir structure * Updated TODO git-svn-id: svn://blicky.net/ncdu/trunk@18 ce56bc8d-f834-0410-b703-f827bd498a76
-rw-r--r--TODO4
-rw-r--r--src/browser.c14
-rw-r--r--src/calc.c32
-rw-r--r--src/ncdu.h9
-rw-r--r--src/settings.c35
-rw-r--r--src/util.c5
6 files changed, 42 insertions, 57 deletions
diff --git a/TODO b/TODO
index 4d875fa..e099b2a 100644
--- a/TODO
+++ b/TODO
@@ -13,3 +13,7 @@ Small list of planned features/changes, suggestions are always welcome.
- Improve browser interface
* Mutt-like status bar?
* Browser always on background, even on startup
+
+- Remove...
+ * Switching to powers of 1000 (is there *anyone* who actually uses that
+ feature?)
diff --git a/src/browser.c b/src/browser.c
index 8d25ae8..d7cc2c2 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -143,11 +143,11 @@ void drawBrowser(int change) {
mvhline(0, 0, ' ', wincols);
mvhline(winrows-1, 0, ' ', wincols);
mvprintw(0,0,"%s %s ~ Use the arrow keys to navigate, press ? for help", PACKAGE_NAME, PACKAGE_VERSION);
-
- mvprintw(winrows-1, 0, " Total size: %s Files: %-6d Dirs: %-6d",
- cropsize(bcur->parent->size), bcur->parent->files, bcur->parent->dirs);
- attroff(A_REVERSE);
+ mvprintw(winrows-1, 0, " Total disk usage: %s Apparent size: %s Items: %d",
+ cropsize(bcur->parent->size), cropsize(bcur->parent->asize), bcur->parent->items);
+ attroff(A_REVERSE);
+
mvhline(1, 0, '-', wincols);
mvaddstr(1, 3, cropdir(getpath(bcur, tmp), wincols-5));
@@ -370,8 +370,7 @@ void showBrowser(void) {
/* update parent dir */
bcur->sub = n->sub;
- bcur->files = n->files;
- bcur->dirs = n->dirs;
+ bcur->items = n->items;
bcur->size = n->size;
for(t = bcur->sub; t != NULL; t = t->next)
t->parent = bcur;
@@ -379,8 +378,7 @@ void showBrowser(void) {
/* update sizes of parent dirs */
for(t = bcur; (t = t->parent) != NULL; ) {
t->size += bcur->size;
- t->files += bcur->files;
- t->dirs += bcur->dirs+1;
+ t->items += bcur->items;
}
/* add reference to parent dir */
diff --git a/src/calc.c b/src/calc.c
index 5a6f528..4701b48 100644
--- a/src/calc.c
+++ b/src/calc.c
@@ -145,8 +145,8 @@ static void drawProgress(char *cdir) {
mvwaddstr(prg, 0, 4, dat == NULL ? "Calculating..." : "Recalculating...");
wattroff(prg, A_BOLD);
- mvwprintw(prg, 2, 2, "Total files: %-8d dirs: %-8d size: %s",
- parent->files, parent->dirs, cropsize(parent->size));
+ mvwprintw(prg, 2, 2, "Total items: %-8d size: %s",
+ parent->items, cropsize(parent->size));
mvwprintw(prg, 3, 2, "Current dir: %s", cropdir(cdir, 43));
mvwaddstr(prg, 8, 43, "Press q to quit");
@@ -302,24 +302,25 @@ int calcDir(struct dir *dest, char *path) {
if(sflags & SF_SMFS && curdev != fs.st_dev)
d->flags |= FF_OTHFS;
- /* determine type of this item and update parent dirs */
- if(S_ISREG(fs.st_mode)) {
+ /* determine type of this item */
+ if(S_ISREG(fs.st_mode))
d->flags |= FF_FILE;
- if(!(d->flags & FF_EXL))
- for(t = dest; t != NULL; t = t->parent)
- t->files++;
- } else if(S_ISDIR(fs.st_mode)) {
+ else if(S_ISDIR(fs.st_mode))
d->flags |= FF_DIR;
- if(!(d->flags & FF_EXL))
- for(t = dest; t != NULL; t = t->parent)
- t->dirs++;
- }
+
+ /* update parent dirs */
+ if(!(d->flags & FF_EXL))
+ for(t = dest; t != NULL; t = t->parent)
+ t->items++;
/* count the size */
if(!(d->flags & FF_EXL || d->flags & FF_OTHFS)) {
- d->size = sflags & SF_AS ? fs.st_size : fs.st_blocks * 512;
- for(t = dest; t != NULL; t = t->parent)
+ d->size = fs.st_blocks * 512;
+ d->asize = fs.st_size;
+ for(t = dest; t != NULL; t = t->parent) {
t->size += d->size;
+ t->asize += d->asize;
+ }
}
/* show status */
@@ -383,7 +384,8 @@ struct dir *showCalc(char *path) {
return(NULL);
}
parent = calloc(sizeof(struct dir), 1);
- parent->size = sflags & SF_AS ? fs.st_size : fs.st_blocks * 512;
+ parent->size = fs.st_blocks * 512;
+ parent->asize = fs.st_size;
parent->flags |= FF_DIR;
curdev = fs.st_dev;
parent->name = malloc(strlen(tmp)+1);
diff --git a/src/ncdu.h b/src/ncdu.h
index 7e947b6..452164d 100644
--- a/src/ncdu.h
+++ b/src/ncdu.h
@@ -91,7 +91,6 @@
/* Settings Flags (int sflags) */
#define SF_SMFS 1 /* same filesystem */
-#define SF_AS 2 /* apparent sizes */
#define SF_SI 4 /* use powers of 1000 instead of 1024 */
#define SF_IGNS 8 /* ignore too small terminal sizes */
#define SF_NOCFM 16 /* don't confirm file deletion */
@@ -112,10 +111,10 @@
struct dir {
struct dir *parent, *next, *sub;
char *name;
- off_t size;
- unsigned int files, dirs;
- unsigned short flags;
-};
+ off_t size, asize;
+ unsigned int items;
+ unsigned char flags;
+};
/*
diff --git a/src/settings.c b/src/settings.c
index 2b386d6..45fc9df 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -55,13 +55,11 @@ int settingsCli(int argc, char **argv) {
}
for(j=1; j < strlen(argv[i]); j++)
switch(argv[i][j]) {
- case 'a': sflags |= SF_AS; break;
case 'x': sflags |= SF_SMFS; break;
case 'q': sdelay = 2000; break;
case '?':
case 'h':
printf("ncdu [-ahvx] [dir]\n\n");
- printf(" -a Apparent sizes\n");
printf(" -h This help message\n");
printf(" -q x Set the refresh interval in seconds\n");
printf(" -v Print version\n");
@@ -97,12 +95,9 @@ int settingsGet(void) {
fields[2] = new_field(1, 16, 1, 11, 0, 0);
fields[3] = new_field(1, 1, 1, 27, 0, 0);
fields[4] = new_field(1, 1, 1, 28, 0, 0);
- fields[5] = new_field(1, 16, 2, 12, 0, 0);
- fields[6] = new_field(1, 1, 2, 27, 0, 0);
- fields[7] = new_field(1, 1, 2, 28, 0, 0);
- fields[8] = new_field(1, 6, 3, 11, 0, 0);
- fields[9] = new_field(1, 9, 3, 19, 0, 0);
- fields[10] = NULL;
+ fields[5] = new_field(1, 6, 3, 11, 0, 0);
+ fields[6] = new_field(1, 9, 3, 19, 0, 0);
+ fields[7] = NULL;
/* Directory */
field_opts_off(fields[0], O_ACTIVE);
@@ -120,17 +115,9 @@ int settingsGet(void) {
set_field_buffer(fields[3], 0, sflags & SF_SMFS ? "X" : " ");
field_opts_off(fields[4], O_ACTIVE);
set_field_buffer(fields[4], 0, "]");
- /* Apparent sizes */
- field_opts_off(fields[5], O_ACTIVE);
- set_field_buffer(fields[5], 0, "Apparent size [");
- field_opts_off(fields[6], O_AUTOSKIP);
- set_field_back(fields[6], A_UNDERLINE);
- set_field_buffer(fields[6], 0, sflags & SF_AS ? "X" : " ");
- field_opts_off(fields[7], O_ACTIVE);
- set_field_buffer(fields[7], 0, "]");
/* buttons */
- set_field_buffer(fields[8], 0, "[OK]");
- set_field_buffer(fields[9], 0, "[CLOSE]");
+ set_field_buffer(fields[5], 0, "[OK]");
+ set_field_buffer(fields[6], 0, "[CLOSE]");
setf = new_form(fields);
h=8;w=60;
@@ -184,16 +171,16 @@ int settingsGet(void) {
case '\t': form_driver(setf, REQ_NEXT_FIELD); break;
case KEY_RESIZE: rst = 1; goto setend; break;
default:
- if(i == 9) {
+ if(i == 6) {
rst = 2;
goto setend;
}
- if(i == 8 || ch == '\n')
+ if(i == 5 || ch == '\n')
goto setend;
- if(i == 3 || i == 6)
+ if(i == 3)
set_field_buffer(fields[i], 0, buf[0] == ' ' ? "X" : " ");
else if(!isprint(ch)) break;
- else if(i == 9) {
+ else if(i == 6) {
if(!isdigit(ch)) strcpy(tmp, " 0");
else if(buf[0] != ' ' || buf[1] == ' ' || buf[1] == '0') sprintf(tmp, " %c", ch);
else sprintf(tmp, "%c%c", buf[1], ch);
@@ -221,11 +208,9 @@ int settingsGet(void) {
sflags = sflags & SF_IGNS;
buf = field_buffer(fields[3], 0);
if(buf[0] != ' ') sflags |= SF_SMFS;
- buf = field_buffer(fields[6], 0);
- if(buf[0] != ' ') sflags |= SF_AS;
unpost_form(setf);
- for(i=10;--i>=0;)
+ for(i=7;--i>=0;)
free_field(fields[i]);
werase(set);
delwin(set);
diff --git a/src/util.c b/src/util.c
index 2bc4e32..b8cca5f 100644
--- a/src/util.c
+++ b/src/util.c
@@ -112,12 +112,9 @@ struct dir *freedir(struct dir *dr) {
/* update sizes of parent directories */
tmp = dr;
- if(dr->flags & FF_FILE) dr->files++;
- if(dr->flags & FF_DIR) dr->dirs++;
while((tmp = tmp->parent) != NULL) {
tmp->size -= dr->size;
- tmp->files -= dr->files;
- tmp->dirs -= dr->dirs;
+ tmp->items -= dr->items+1;
}
/* free dr->sub recursive */