Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nccf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
702
Provoz
nccf
Commits
c4be23a4
Commit
c4be23a4
authored
16 years ago
by
Yorhel
Browse files
Options
Downloads
Patches
Plain Diff
Each state can have it's own global variable
parent
f392bf3e
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/calc.c
+30
-30
30 additions, 30 deletions
src/calc.c
src/main.c
+9
-12
9 additions, 12 deletions
src/main.c
src/ncdu.h
+12
-14
12 additions, 14 deletions
src/ncdu.h
with
51 additions
and
56 deletions
src/calc.c
+
30
−
30
View file @
c4be23a4
...
@@ -173,7 +173,7 @@ int calc_item(struct dir *par, char *path, char *name) {
...
@@ -173,7 +173,7 @@ int calc_item(struct dir *par, char *path, char *name) {
if
(
matchExclude
(
tmp
))
if
(
matchExclude
(
tmp
))
d
->
flags
|=
FF_EXL
;
d
->
flags
|=
FF_EXL
;
if
(
sflags
&
SF_SMFS
&&
p
st
ate
.
calc
.
curdev
!=
fs
.
st_dev
)
if
(
sflags
&
SF_SMFS
&&
stcalc
.
curdev
!=
fs
.
st_dev
)
d
->
flags
|=
FF_OTHFS
;
d
->
flags
|=
FF_OTHFS
;
/* determine type of this item */
/* determine type of this item */
...
@@ -213,7 +213,7 @@ int calc_dir(struct dir *dest, char *path) {
...
@@ -213,7 +213,7 @@ int calc_dir(struct dir *dest, char *path) {
/* open directory */
/* open directory */
if
((
dir
=
opendir
(
path
))
==
NULL
)
{
if
((
dir
=
opendir
(
path
))
==
NULL
)
{
strcpy
(
p
st
ate
.
calc
.
lasterr
,
path
);
strcpy
(
stcalc
.
lasterr
,
path
);
dest
->
flags
|=
FF_ERR
;
dest
->
flags
|=
FF_ERR
;
t
=
dest
;
t
=
dest
;
while
((
t
=
t
->
parent
)
!=
NULL
)
while
((
t
=
t
->
parent
)
!=
NULL
)
...
@@ -274,29 +274,29 @@ void calc_draw_progress() {
...
@@ -274,29 +274,29 @@ void calc_draw_progress() {
nccreate
(
10
,
60
,
dat
==
NULL
?
"Calculating..."
:
"Recalculating..."
);
nccreate
(
10
,
60
,
dat
==
NULL
?
"Calculating..."
:
"Recalculating..."
);
ncprint
(
2
,
2
,
"Total items: %-8d size: %s"
,
ncprint
(
2
,
2
,
"Total items: %-8d size: %s"
,
p
st
ate
.
calc
.
parent
->
items
,
cropsize
(
p
st
ate
.
calc
.
parent
->
size
));
stcalc
.
parent
->
items
,
cropsize
(
stcalc
.
parent
->
size
));
ncprint
(
3
,
2
,
"Current dir: %s"
,
cropdir
(
p
st
ate
.
calc
.
cur
,
43
));
ncprint
(
3
,
2
,
"Current dir: %s"
,
cropdir
(
stcalc
.
cur
,
43
));
ncaddstr
(
8
,
43
,
"Press q to quit"
);
ncaddstr
(
8
,
43
,
"Press q to quit"
);
/* show warning if we couldn't open a dir */
/* show warning if we couldn't open a dir */
if
(
p
st
ate
.
calc
.
lasterr
[
0
]
!=
'\0'
)
{
if
(
stcalc
.
lasterr
[
0
]
!=
'\0'
)
{
attron
(
A_BOLD
);
attron
(
A_BOLD
);
ncaddstr
(
5
,
2
,
"Warning:"
);
ncaddstr
(
5
,
2
,
"Warning:"
);
attroff
(
A_BOLD
);
attroff
(
A_BOLD
);
ncprint
(
5
,
11
,
"could not open %-32s"
,
cropdir
(
p
st
ate
.
calc
.
lasterr
,
32
));
ncprint
(
5
,
11
,
"could not open %-32s"
,
cropdir
(
stcalc
.
lasterr
,
32
));
ncaddstr
(
6
,
3
,
"some directory sizes may not be correct"
);
ncaddstr
(
6
,
3
,
"some directory sizes may not be correct"
);
}
}
/* animation - but only if the screen refreshes more than or once every second */
/* animation - but only if the screen refreshes more than or once every second */
if
(
sdelay
<=
1000
)
{
if
(
sdelay
<=
1000
)
{
if
(
++
p
st
ate
.
calc
.
anpos
==
28
)
if
(
++
stcalc
.
anpos
==
28
)
p
st
ate
.
calc
.
anpos
=
0
;
stcalc
.
anpos
=
0
;
strcpy
(
ani
,
" "
);
strcpy
(
ani
,
" "
);
if
(
p
st
ate
.
calc
.
anpos
<
14
)
if
(
stcalc
.
anpos
<
14
)
for
(
i
=
0
;
i
<=
p
st
ate
.
calc
.
anpos
;
i
++
)
for
(
i
=
0
;
i
<=
stcalc
.
anpos
;
i
++
)
ani
[
i
]
=
antext
[
i
];
ani
[
i
]
=
antext
[
i
];
else
else
for
(
i
=
13
;
i
>
p
st
ate
.
calc
.
anpos
-
14
;
i
--
)
for
(
i
=
13
;
i
>
stcalc
.
anpos
-
14
;
i
--
)
ani
[
i
]
=
antext
[
i
];
ani
[
i
]
=
antext
[
i
];
}
else
}
else
strcpy
(
ani
,
antext
);
strcpy
(
ani
,
antext
);
...
@@ -320,17 +320,17 @@ void calc_draw_error(char *cur, char *msg) {
...
@@ -320,17 +320,17 @@ void calc_draw_error(char *cur, char *msg) {
int
calc_draw
()
{
int
calc_draw
()
{
struct
timeval
tv
;
struct
timeval
tv
;
if
(
p
st
ate
.
calc
.
err
)
{
if
(
stcalc
.
err
)
{
calc_draw_error
(
p
st
ate
.
calc
.
cur
,
p
st
ate
.
calc
.
errmsg
);
calc_draw_error
(
stcalc
.
cur
,
stcalc
.
errmsg
);
return
0
;
return
0
;
}
}
/* should we really draw the screen again? */
/* should we really draw the screen again? */
gettimeofday
(
&
tv
,
(
void
*
)
NULL
);
gettimeofday
(
&
tv
,
(
void
*
)
NULL
);
tv
.
tv_usec
=
(
1000
*
(
tv
.
tv_sec
%
1000
)
+
(
tv
.
tv_usec
/
1000
))
/
sdelay
;
tv
.
tv_usec
=
(
1000
*
(
tv
.
tv_sec
%
1000
)
+
(
tv
.
tv_usec
/
1000
))
/
sdelay
;
if
(
p
st
ate
.
calc
.
lastupdate
!=
tv
.
tv_usec
)
{
if
(
stcalc
.
lastupdate
!=
tv
.
tv_usec
)
{
calc_draw_progress
();
calc_draw_progress
();
p
st
ate
.
calc
.
lastupdate
=
tv
.
tv_usec
;
stcalc
.
lastupdate
=
tv
.
tv_usec
;
return
0
;
return
0
;
}
}
return
1
;
return
1
;
...
@@ -338,7 +338,7 @@ int calc_draw() {
...
@@ -338,7 +338,7 @@ int calc_draw() {
int
calc_key
(
int
ch
)
{
int
calc_key
(
int
ch
)
{
if
(
p
st
ate
.
calc
.
err
)
if
(
stcalc
.
err
)
return
1
;
return
1
;
if
(
ch
==
'q'
)
if
(
ch
==
'q'
)
return
1
;
return
1
;
...
@@ -352,15 +352,15 @@ void calc_process() {
...
@@ -352,15 +352,15 @@ void calc_process() {
struct
dir
*
t
;
struct
dir
*
t
;
/* init/reset global vars */
/* init/reset global vars */
p
st
ate
.
calc
.
err
=
0
;
stcalc
.
err
=
0
;
p
st
ate
.
calc
.
lastupdate
=
999
;
stcalc
.
lastupdate
=
999
;
p
st
ate
.
calc
.
lasterr
[
0
]
=
0
;
stcalc
.
lasterr
[
0
]
=
0
;
p
st
ate
.
calc
.
anpos
=
0
;
stcalc
.
anpos
=
0
;
/* check root directory */
/* check root directory */
if
(
rpath
(
p
st
ate
.
calc
.
cur
,
tmp
)
==
NULL
||
lstat
(
tmp
,
&
fs
)
!=
0
||
!
S_ISDIR
(
fs
.
st_mode
))
{
if
(
rpath
(
stcalc
.
cur
,
tmp
)
==
NULL
||
lstat
(
tmp
,
&
fs
)
!=
0
||
!
S_ISDIR
(
fs
.
st_mode
))
{
p
st
ate
.
calc
.
err
=
1
;
stcalc
.
err
=
1
;
strcpy
(
p
st
ate
.
calc
.
errmsg
,
"Directory not found"
);
strcpy
(
stcalc
.
errmsg
,
"Directory not found"
);
goto
fail
;
goto
fail
;
}
}
...
@@ -371,21 +371,21 @@ void calc_process() {
...
@@ -371,21 +371,21 @@ void calc_process() {
t
->
flags
|=
FF_DIR
;
t
->
flags
|=
FF_DIR
;
t
->
name
=
(
char
*
)
malloc
(
strlen
(
tmp
)
+
1
);
t
->
name
=
(
char
*
)
malloc
(
strlen
(
tmp
)
+
1
);
strcpy
(
t
->
name
,
tmp
);
strcpy
(
t
->
name
,
tmp
);
p
st
ate
.
calc
.
parent
=
t
;
stcalc
.
parent
=
t
;
p
st
ate
.
calc
.
curdev
=
fs
.
st_dev
;
stcalc
.
curdev
=
fs
.
st_dev
;
/* start calculating */
/* start calculating */
if
(
!
calc_dir
(
p
st
ate
.
calc
.
parent
,
tmp
)
&&
!
p
st
ate
.
calc
.
err
)
{
if
(
!
calc_dir
(
stcalc
.
parent
,
tmp
)
&&
!
stcalc
.
err
)
{
pstate
.
st
=
ST_BROWSE
;
pstate
=
ST_BROWSE
;
return
;
return
;
}
}
/* something went wrong... */
/* something went wrong... */
freedir
(
p
st
ate
.
calc
.
parent
);
freedir
(
stcalc
.
parent
);
fail:
fail:
while
(
p
st
ate
.
calc
.
err
&&
!
input_handle
(
0
))
while
(
stcalc
.
err
&&
!
input_handle
(
0
))
;
;
pstate
.
st
=
dat
!=
NULL
?
ST_BROWSE
:
ST_QUIT
;
pstate
=
stcalc
.
sterr
;
return
;
return
;
}
}
This diff is collapsed.
Click to expand it.
src/main.c
+
9
−
12
View file @
c4be23a4
...
@@ -31,12 +31,13 @@ int winrows, wincols;
...
@@ -31,12 +31,13 @@ int winrows, wincols;
char
sdir
[
PATH_MAX
];
char
sdir
[
PATH_MAX
];
int
sflags
,
bflags
,
sdelay
,
bgraph
;
int
sflags
,
bflags
,
sdelay
,
bgraph
;
int
subwinc
,
subwinr
;
int
subwinc
,
subwinr
;
struct
state
pstate
;
int
pstate
;
struct
state_calc
stcalc
;
void
screen_draw
()
{
void
screen_draw
()
{
int
n
=
1
;
int
n
=
1
;
switch
(
pstate
.
st
)
{
switch
(
pstate
)
{
case
ST_CALC
:
n
=
calc_draw
();
case
ST_CALC
:
n
=
calc_draw
();
}
}
if
(
!
n
)
if
(
!
n
)
...
@@ -55,7 +56,7 @@ int input_handle(int wait) {
...
@@ -55,7 +56,7 @@ int input_handle(int wait) {
screen_draw
();
screen_draw
();
continue
;
continue
;
}
}
switch
(
pstate
.
st
)
{
switch
(
pstate
)
{
case
ST_CALC
:
return
calc_key
(
ch
);
case
ST_CALC
:
return
calc_key
(
ch
);
}
}
}
}
...
@@ -131,9 +132,9 @@ void argv_parse(int argc, char **argv, char *dir) {
...
@@ -131,9 +132,9 @@ void argv_parse(int argc, char **argv, char *dir) {
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
dat
=
NULL
;
dat
=
NULL
;
memset
((
void
*
)
&
pstate
,
0
,
sizeof
(
struct
state
)
);
argv_parse
(
argc
,
argv
,
stcalc
.
cur
);
argv_parse
(
argc
,
argv
,
pstate
.
calc
.
cur
)
;
pstate
=
ST_CALC
;
p
st
ate
.
st
=
ST_
CALC
;
st
calc
.
sterr
=
ST_
QUIT
;
initscr
();
initscr
();
cbreak
();
cbreak
();
...
@@ -142,17 +143,13 @@ int main(int argc, char **argv) {
...
@@ -142,17 +143,13 @@ int main(int argc, char **argv) {
keypad
(
stdscr
,
TRUE
);
keypad
(
stdscr
,
TRUE
);
ncresize
();
ncresize
();
while
(
pstate
.
st
!=
ST_QUIT
)
{
while
(
pstate
!=
ST_QUIT
)
{
if
(
pstate
.
st
==
ST_CALC
)
if
(
pstate
==
ST_CALC
)
calc_process
();
calc_process
();
/*else
/*else
wait_for_input() */
wait_for_input() */
}
}
/*
if((dat = showCalc(pstate.calc.root)) != NULL)
showBrowser();*/
erase
();
erase
();
refresh
();
refresh
();
endwin
();
endwin
();
...
...
This diff is collapsed.
Click to expand it.
src/ncdu.h
+
12
−
14
View file @
c4be23a4
...
@@ -136,19 +136,16 @@ struct dir {
...
@@ -136,19 +136,16 @@ struct dir {
unsigned
char
flags
;
unsigned
char
flags
;
};
};
struct
state
{
struct
state_calc
{
int
st
;
/* SC_x */
char
err
;
/* 1/0, error or not */
struct
{
char
cur
[
PATH_MAX
];
/* current dir/item */
char
err
;
char
lasterr
[
PATH_MAX
];
/* last unreadable dir/item */
char
cur
[
PATH_MAX
];
char
errmsg
[
128
];
/* error message, when err=1 */
char
lasterr
[
PATH_MAX
];
struct
dir
*
parent
;
/* parent directory for the calculation */
char
errmsg
[
128
];
dev_t
curdev
;
/* current device we're calculating on */
struct
dir
*
parent
;
suseconds_t
lastupdate
;
/* time of the last screen update */
dev_t
curdev
;
int
anpos
;
/* position of the animation string */
suseconds_t
lastupdate
;
int
sterr
;
/* state to go to on error (ST_BROWSE/ST_QUIT) */
int
anpos
;
}
calc
;
/* TODO: information structs for the other states */
};
};
...
@@ -168,7 +165,8 @@ extern int sflags, bflags, sdelay, bgraph;
...
@@ -168,7 +165,8 @@ extern int sflags, bflags, sdelay, bgraph;
/* used for creating windows */
/* used for creating windows */
extern
int
subwinr
,
subwinc
;
extern
int
subwinr
,
subwinc
;
/* program state */
/* program state */
extern
struct
state
pstate
;
extern
int
pstate
;
extern
struct
state_calc
stcalc
;
/*
/*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment