Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
htop
Commits
02a30bfe
Commit
02a30bfe
authored
Feb 25, 2010
by
Hisham Muhammad
Browse files
warning fixes
parent
5cc89986
Changes
35
Hide whitespace changes
Inline
Side-by-side
ProcessList.c
View file @
02a30bfe
...
@@ -27,6 +27,7 @@ in the source distribution for its full text.
...
@@ -27,6 +27,7 @@ in the source distribution for its full text.
#include <stdbool.h>
#include <stdbool.h>
#include <sys/utsname.h>
#include <sys/utsname.h>
#include <stdarg.h>
#include <stdarg.h>
#include <math.h>
#include "debug.h"
#include "debug.h"
#include <assert.h>
#include <assert.h>
...
@@ -699,6 +700,7 @@ static bool ProcessList_processEntries(ProcessList* this, const char* dirname, P
...
@@ -699,6 +700,7 @@ static bool ProcessList_processEntries(ProcessList* this, const char* dirname, P
int
percent_cpu
=
(
process
->
utime
+
process
->
stime
-
lasttimes
)
/
int
percent_cpu
=
(
process
->
utime
+
process
->
stime
-
lasttimes
)
/
period
*
100
.
0
;
period
*
100
.
0
;
process
->
percent_cpu
=
MAX
(
MIN
(
percent_cpu
,
processors
*
100
.
0
),
0
.
0
);
process
->
percent_cpu
=
MAX
(
MIN
(
percent_cpu
,
processors
*
100
.
0
),
0
.
0
);
if
(
isnan
(
process
->
percent_cpu
))
process
->
percent_cpu
=
0
.
0
;
process
->
percent_mem
=
(
process
->
m_resident
*
PAGE_SIZE_KB
)
/
process
->
percent_mem
=
(
process
->
m_resident
*
PAGE_SIZE_KB
)
/
(
float
)(
this
->
totalMem
)
*
(
float
)(
this
->
totalMem
)
*
...
...
ProcessList.h
View file @
02a30bfe
...
@@ -30,6 +30,7 @@ in the source distribution for its full text.
...
@@ -30,6 +30,7 @@ in the source distribution for its full text.
#include <stdbool.h>
#include <stdbool.h>
#include <sys/utsname.h>
#include <sys/utsname.h>
#include <stdarg.h>
#include <stdarg.h>
#include <math.h>
#include "debug.h"
#include "debug.h"
#include <assert.h>
#include <assert.h>
...
...
RichString.c
View file @
02a30bfe
...
@@ -52,7 +52,7 @@ typedef struct RichString_ {
...
@@ -52,7 +52,7 @@ typedef struct RichString_ {
#ifdef HAVE_LIBNCURSESW
#ifdef HAVE_LIBNCURSESW
inline
void
RichString_appendn
(
RichString
*
this
,
int
attrs
,
char
*
data_c
,
int
len
)
{
inline
void
RichString_appendn
(
RichString
*
this
,
int
attrs
,
const
char
*
data_c
,
int
len
)
{
wchar_t
data
[
RICHSTRING_MAXLEN
];
wchar_t
data
[
RICHSTRING_MAXLEN
];
len
=
mbstowcs
(
data
,
data_c
,
RICHSTRING_MAXLEN
);
len
=
mbstowcs
(
data
,
data_c
,
RICHSTRING_MAXLEN
);
if
(
len
<
0
)
if
(
len
<
0
)
...
@@ -88,7 +88,7 @@ int RichString_findChar(RichString *this, char c, int start) {
...
@@ -88,7 +88,7 @@ int RichString_findChar(RichString *this, char c, int start) {
#else
#else
inline
void
RichString_appendn
(
RichString
*
this
,
int
attrs
,
char
*
data_c
,
int
len
)
{
inline
void
RichString_appendn
(
RichString
*
this
,
int
attrs
,
const
char
*
data_c
,
int
len
)
{
int
last
=
MIN
(
RICHSTRING_MAXLEN
-
1
,
len
+
this
->
len
);
int
last
=
MIN
(
RICHSTRING_MAXLEN
-
1
,
len
+
this
->
len
);
for
(
int
i
=
this
->
len
,
j
=
0
;
i
<
last
;
i
++
,
j
++
)
for
(
int
i
=
this
->
len
,
j
=
0
;
i
<
last
;
i
++
,
j
++
)
this
->
chstr
[
i
]
=
(
isprint
(
data_c
[
j
])
?
data_c
[
j
]
:
'?'
)
|
attrs
;
this
->
chstr
[
i
]
=
(
isprint
(
data_c
[
j
])
?
data_c
[
j
]
:
'?'
)
|
attrs
;
...
@@ -108,7 +108,7 @@ void RichString_setAttrn(RichString *this, int attrs, int start, int finish) {
...
@@ -108,7 +108,7 @@ void RichString_setAttrn(RichString *this, int attrs, int start, int finish) {
int
RichString_findChar
(
RichString
*
this
,
char
c
,
int
start
)
{
int
RichString_findChar
(
RichString
*
this
,
char
c
,
int
start
)
{
chtype
*
ch
=
this
->
chstr
+
start
;
chtype
*
ch
=
this
->
chstr
+
start
;
for
(
int
i
=
start
;
i
<
this
->
len
;
i
++
)
{
for
(
int
i
=
start
;
i
<
this
->
len
;
i
++
)
{
if
((
*
ch
&
0xff
)
==
c
)
if
((
*
ch
&
0xff
)
==
(
chtype
)
c
)
return
i
;
return
i
;
ch
++
;
ch
++
;
}
}
...
@@ -125,16 +125,16 @@ void RichString_setAttr(RichString *this, int attrs) {
...
@@ -125,16 +125,16 @@ void RichString_setAttr(RichString *this, int attrs) {
RichString_setAttrn
(
this
,
attrs
,
0
,
this
->
len
-
1
);
RichString_setAttrn
(
this
,
attrs
,
0
,
this
->
len
-
1
);
}
}
inline
void
RichString_append
(
RichString
*
this
,
int
attrs
,
char
*
data
)
{
inline
void
RichString_append
(
RichString
*
this
,
int
attrs
,
const
char
*
data
)
{
RichString_appendn
(
this
,
attrs
,
data
,
strlen
(
data
));
RichString_appendn
(
this
,
attrs
,
data
,
strlen
(
data
));
}
}
void
RichString_write
(
RichString
*
this
,
int
attrs
,
char
*
data
)
{
void
RichString_write
(
RichString
*
this
,
int
attrs
,
const
char
*
data
)
{
RichString_init
(
this
);
RichString_init
(
this
);
RichString_append
(
this
,
attrs
,
data
);
RichString_append
(
this
,
attrs
,
data
);
}
}
RichString
RichString_quickString
(
int
attrs
,
char
*
data
)
{
RichString
RichString_quickString
(
int
attrs
,
const
char
*
data
)
{
RichString
str
;
RichString
str
;
RichString_initVal
(
str
);
RichString_initVal
(
str
);
RichString_write
(
&
str
,
attrs
,
data
);
RichString_write
(
&
str
,
attrs
,
data
);
...
...
RichString.h
View file @
02a30bfe
...
@@ -53,7 +53,7 @@ typedef struct RichString_ {
...
@@ -53,7 +53,7 @@ typedef struct RichString_ {
#ifdef HAVE_LIBNCURSESW
#ifdef HAVE_LIBNCURSESW
extern
void
RichString_appendn
(
RichString
*
this
,
int
attrs
,
char
*
data_c
,
int
len
);
extern
void
RichString_appendn
(
RichString
*
this
,
int
attrs
,
const
char
*
data_c
,
int
len
);
extern
void
RichString_setAttrn
(
RichString
*
this
,
int
attrs
,
int
start
,
int
finish
);
extern
void
RichString_setAttrn
(
RichString
*
this
,
int
attrs
,
int
start
,
int
finish
);
...
@@ -61,7 +61,7 @@ int RichString_findChar(RichString *this, char c, int start);
...
@@ -61,7 +61,7 @@ int RichString_findChar(RichString *this, char c, int start);
#else
#else
extern
void
RichString_appendn
(
RichString
*
this
,
int
attrs
,
char
*
data_c
,
int
len
);
extern
void
RichString_appendn
(
RichString
*
this
,
int
attrs
,
const
char
*
data_c
,
int
len
);
void
RichString_setAttrn
(
RichString
*
this
,
int
attrs
,
int
start
,
int
finish
);
void
RichString_setAttrn
(
RichString
*
this
,
int
attrs
,
int
start
,
int
finish
);
...
@@ -73,10 +73,10 @@ void RichString_prune(RichString* this);
...
@@ -73,10 +73,10 @@ void RichString_prune(RichString* this);
void
RichString_setAttr
(
RichString
*
this
,
int
attrs
);
void
RichString_setAttr
(
RichString
*
this
,
int
attrs
);
extern
void
RichString_append
(
RichString
*
this
,
int
attrs
,
char
*
data
);
extern
void
RichString_append
(
RichString
*
this
,
int
attrs
,
const
char
*
data
);
void
RichString_write
(
RichString
*
this
,
int
attrs
,
char
*
data
);
void
RichString_write
(
RichString
*
this
,
int
attrs
,
const
char
*
data
);
RichString
RichString_quickString
(
int
attrs
,
char
*
data
);
RichString
RichString_quickString
(
int
attrs
,
const
char
*
data
);
#endif
#endif
ScreenManager.c
View file @
02a30bfe
...
@@ -89,10 +89,10 @@ void ScreenManager_add(ScreenManager* this, Panel* item, FunctionBar* fuBar, int
...
@@ -89,10 +89,10 @@ void ScreenManager_add(ScreenManager* this, Panel* item, FunctionBar* fuBar, int
this
->
itemCount
++
;
this
->
itemCount
++
;
}
}
Panel
*
ScreenManager_remove
(
ScreenManager
*
this
,
int
i
nde
x
)
{
Panel
*
ScreenManager_remove
(
ScreenManager
*
this
,
int
i
d
x
)
{
assert
(
this
->
itemCount
>
i
nde
x
);
assert
(
this
->
itemCount
>
i
d
x
);
Panel
*
panel
=
(
Panel
*
)
Vector_remove
(
this
->
items
,
i
nde
x
);
Panel
*
panel
=
(
Panel
*
)
Vector_remove
(
this
->
items
,
i
d
x
);
Vector_remove
(
this
->
fuBars
,
i
nde
x
);
Vector_remove
(
this
->
fuBars
,
i
d
x
);
this
->
fuBar
=
NULL
;
this
->
fuBar
=
NULL
;
this
->
itemCount
--
;
this
->
itemCount
--
;
return
panel
;
return
panel
;
...
...
ScreenManager.h
View file @
02a30bfe
...
@@ -47,7 +47,7 @@ extern int ScreenManager_size(ScreenManager* this);
...
@@ -47,7 +47,7 @@ extern int ScreenManager_size(ScreenManager* this);
void
ScreenManager_add
(
ScreenManager
*
this
,
Panel
*
item
,
FunctionBar
*
fuBar
,
int
size
);
void
ScreenManager_add
(
ScreenManager
*
this
,
Panel
*
item
,
FunctionBar
*
fuBar
,
int
size
);
Panel
*
ScreenManager_remove
(
ScreenManager
*
this
,
int
i
nde
x
);
Panel
*
ScreenManager_remove
(
ScreenManager
*
this
,
int
i
d
x
);
void
ScreenManager_resize
(
ScreenManager
*
this
,
int
x1
,
int
y1
,
int
x2
,
int
y2
);
void
ScreenManager_resize
(
ScreenManager
*
this
,
int
x1
,
int
y1
,
int
x2
,
int
y2
);
...
...
SignalItem.c
View file @
02a30bfe
...
@@ -19,7 +19,7 @@ in the source distribution for its full text.
...
@@ -19,7 +19,7 @@ in the source distribution for its full text.
typedef struct Signal_ {
typedef struct Signal_ {
Object super;
Object super;
char* name;
const
char* name;
int number;
int number;
} Signal;
} Signal;
...
@@ -47,7 +47,7 @@ static void Signal_display(Object* cast, RichString* out) {
...
@@ -47,7 +47,7 @@ static void Signal_display(Object* cast, RichString* out) {
RichString_write
(
out
,
CRT_colors
[
DEFAULT_COLOR
],
buffer
);
RichString_write
(
out
,
CRT_colors
[
DEFAULT_COLOR
],
buffer
);
}
}
static
Signal
*
Signal_new
(
char
*
name
,
int
number
)
{
static
Signal
*
Signal_new
(
const
char
*
name
,
int
number
)
{
Signal
*
this
=
malloc
(
sizeof
(
Signal
));
Signal
*
this
=
malloc
(
sizeof
(
Signal
));
Object_setClass
(
this
,
SIGNAL_CLASS
);
Object_setClass
(
this
,
SIGNAL_CLASS
);
((
Object
*
)
this
)
->
display
=
Signal_display
;
((
Object
*
)
this
)
->
display
=
Signal_display
;
...
...
SignalItem.h
View file @
02a30bfe
...
@@ -21,7 +21,7 @@ in the source distribution for its full text.
...
@@ -21,7 +21,7 @@ in the source distribution for its full text.
typedef
struct
Signal_
{
typedef
struct
Signal_
{
Object
super
;
Object
super
;
char
*
name
;
const
char
*
name
;
int
number
;
int
number
;
}
Signal
;
}
Signal
;
...
...
SignalsPanel.c
View file @
02a30bfe
...
@@ -26,13 +26,13 @@ static HandlerResult SignalsPanel_eventHandler(Panel* super, int ch) {
...
@@ -26,13 +26,13 @@ static HandlerResult SignalsPanel_eventHandler(Panel* super, int ch) {
int
size
=
Panel_size
(
super
);
int
size
=
Panel_size
(
super
);
if
(
ch
<=
255
&&
isdigit
(
ch
))
{
if
(
ch
<=
255
&&
isdigit
(
ch
))
{
int
s
i
gn
al
=
ch
-
48
+
this
->
state
;
int
sgn
=
ch
-
48
+
this
->
state
;
for
(
int
i
=
0
;
i
<
size
;
i
++
)
for
(
int
i
=
0
;
i
<
size
;
i
++
)
if
(((
Signal
*
)
Panel_get
(
super
,
i
))
->
number
==
s
i
gn
al
)
{
if
(((
Signal
*
)
Panel_get
(
super
,
i
))
->
number
==
sgn
)
{
Panel_setSelected
(
super
,
i
);
Panel_setSelected
(
super
,
i
);
break
;
break
;
}
}
this
->
state
=
s
i
gn
al
*
10
;
this
->
state
=
sgn
*
10
;
if
(
this
->
state
>
100
)
if
(
this
->
state
>
100
)
this
->
state
=
0
;
this
->
state
=
0
;
return
HANDLED
;
return
HANDLED
;
...
...
String.c
View file @
02a30bfe
...
@@ -18,11 +18,11 @@ in the source distribution for its full text.
...
@@ -18,11 +18,11 @@ in the source distribution for its full text.
#define String_startsWith(s, match) (strstr((s), (match)) == (s))
#define String_startsWith(s, match) (strstr((s), (match)) == (s))
}*/
}*/
inline
char
*
String_copy
(
char
*
orig
)
{
inline
char
*
String_copy
(
const
char
*
orig
)
{
return
strdup
(
orig
);
return
strdup
(
orig
);
}
}
char
*
String_cat
(
char
*
s1
,
char
*
s2
)
{
char
*
String_cat
(
const
char
*
s1
,
const
char
*
s2
)
{
int
l1
=
strlen
(
s1
);
int
l1
=
strlen
(
s1
);
int
l2
=
strlen
(
s2
);
int
l2
=
strlen
(
s2
);
char
*
out
=
malloc
(
l1
+
l2
+
1
);
char
*
out
=
malloc
(
l1
+
l2
+
1
);
...
@@ -31,7 +31,7 @@ char* String_cat(char* s1, char* s2) {
...
@@ -31,7 +31,7 @@ char* String_cat(char* s1, char* s2) {
return
out
;
return
out
;
}
}
char
*
String_trim
(
char
*
in
)
{
char
*
String_trim
(
const
char
*
in
)
{
while
(
in
[
0
]
==
' '
||
in
[
0
]
==
'\t'
||
in
[
0
]
==
'\n'
)
{
while
(
in
[
0
]
==
' '
||
in
[
0
]
==
'\t'
||
in
[
0
]
==
'\n'
)
{
in
++
;
in
++
;
}
}
...
@@ -55,7 +55,7 @@ inline int String_eq(const char* s1, const char* s2) {
...
@@ -55,7 +55,7 @@ inline int String_eq(const char* s1, const char* s2) {
return
(
strcmp
(
s1
,
s2
)
==
0
);
return
(
strcmp
(
s1
,
s2
)
==
0
);
}
}
char
**
String_split
(
char
*
s
,
char
sep
)
{
char
**
String_split
(
const
char
*
s
,
char
sep
)
{
const
int
rate
=
10
;
const
int
rate
=
10
;
char
**
out
=
(
char
**
)
malloc
(
sizeof
(
char
*
)
*
rate
);
char
**
out
=
(
char
**
)
malloc
(
sizeof
(
char
*
)
*
rate
);
int
ctr
=
0
;
int
ctr
=
0
;
...
@@ -93,7 +93,7 @@ void String_freeArray(char** s) {
...
@@ -93,7 +93,7 @@ void String_freeArray(char** s) {
free
(
s
);
free
(
s
);
}
}
int
String_contains_i
(
char
*
s
,
char
*
match
)
{
int
String_contains_i
(
const
char
*
s
,
const
char
*
match
)
{
int
lens
=
strlen
(
s
);
int
lens
=
strlen
(
s
);
int
lenmatch
=
strlen
(
match
);
int
lenmatch
=
strlen
(
match
);
for
(
int
i
=
0
;
i
<
lens
-
lenmatch
;
i
++
)
{
for
(
int
i
=
0
;
i
<
lens
-
lenmatch
;
i
++
)
{
...
...
String.h
View file @
02a30bfe
...
@@ -19,19 +19,19 @@ in the source distribution for its full text.
...
@@ -19,19 +19,19 @@ in the source distribution for its full text.
#define String_startsWith(s, match) (strstr((s), (match)) == (s))
#define String_startsWith(s, match) (strstr((s), (match)) == (s))
extern
char
*
String_copy
(
char
*
orig
);
extern
char
*
String_copy
(
const
char
*
orig
);
char
*
String_cat
(
char
*
s1
,
char
*
s2
);
char
*
String_cat
(
const
char
*
s1
,
const
char
*
s2
);
char
*
String_trim
(
char
*
in
);
char
*
String_trim
(
const
char
*
in
);
extern
int
String_eq
(
const
char
*
s1
,
const
char
*
s2
);
extern
int
String_eq
(
const
char
*
s1
,
const
char
*
s2
);
char
**
String_split
(
char
*
s
,
char
sep
);
char
**
String_split
(
const
char
*
s
,
char
sep
);
void
String_freeArray
(
char
**
s
);
void
String_freeArray
(
char
**
s
);
int
String_contains_i
(
char
*
s
,
char
*
match
);
int
String_contains_i
(
const
char
*
s
,
const
char
*
match
);
char
*
String_getToken
(
const
char
*
line
,
const
unsigned
short
int
numMatch
);
char
*
String_getToken
(
const
char
*
line
,
const
unsigned
short
int
numMatch
);
...
...
TraceScreen.c
View file @
02a30bfe
...
@@ -32,9 +32,9 @@ typedef struct TraceScreen_ {
...
@@ -32,9 +32,9 @@ typedef struct TraceScreen_ {
}*/
}*/
static
char
*
tbFunctions
[]
=
{
"AutoScroll "
,
"Stop Tracing "
,
"Done "
,
NULL
};
static
const
char
*
tbFunctions
[]
=
{
"AutoScroll "
,
"Stop Tracing "
,
"Done "
,
NULL
};
static
char
*
tbKeys
[]
=
{
"F4"
,
"F5"
,
"Esc"
};
static
const
char
*
tbKeys
[]
=
{
"F4"
,
"F5"
,
"Esc"
};
static
int
tbEvents
[]
=
{
KEY_F
(
4
),
KEY_F
(
5
),
27
};
static
int
tbEvents
[]
=
{
KEY_F
(
4
),
KEY_F
(
5
),
27
};
...
...
Vector.c
View file @
02a30bfe
...
@@ -127,37 +127,37 @@ static void Vector_checkArraySize(Vector* this) {
...
@@ -127,37 +127,37 @@ static void Vector_checkArraySize(Vector* this) {
assert
(
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
}
}
void
Vector_insert
(
Vector
*
this
,
int
i
nde
x
,
void
*
data_
)
{
void
Vector_insert
(
Vector
*
this
,
int
i
d
x
,
void
*
data_
)
{
assert
(
i
nde
x
>=
0
);
assert
(
i
d
x
>=
0
);
assert
(((
Object
*
)
data_
)
->
class
==
this
->
vectorType
);
assert
(((
Object
*
)
data_
)
->
class
==
this
->
vectorType
);
Object
*
data
=
data_
;
Object
*
data
=
data_
;
assert
(
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
Vector_checkArraySize
(
this
);
Vector_checkArraySize
(
this
);
assert
(
this
->
array
[
this
->
items
]
==
NULL
);
assert
(
this
->
array
[
this
->
items
]
==
NULL
);
for
(
int
i
=
this
->
items
;
i
>=
i
nde
x
;
i
--
)
{
for
(
int
i
=
this
->
items
;
i
>=
i
d
x
;
i
--
)
{
this
->
array
[
i
+
1
]
=
this
->
array
[
i
];
this
->
array
[
i
+
1
]
=
this
->
array
[
i
];
}
}
this
->
array
[
i
nde
x
]
=
data
;
this
->
array
[
i
d
x
]
=
data
;
this
->
items
++
;
this
->
items
++
;
assert
(
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
}
}
Object
*
Vector_take
(
Vector
*
this
,
int
i
nde
x
)
{
Object
*
Vector_take
(
Vector
*
this
,
int
i
d
x
)
{
assert
(
i
nde
x
>=
0
&&
i
nde
x
<
this
->
items
);
assert
(
i
d
x
>=
0
&&
i
d
x
<
this
->
items
);
assert
(
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
Object
*
removed
=
this
->
array
[
i
nde
x
];
Object
*
removed
=
this
->
array
[
i
d
x
];
assert
(
removed
!=
NULL
);
assert
(
removed
!=
NULL
);
this
->
items
--
;
this
->
items
--
;
for
(
int
i
=
i
nde
x
;
i
<
this
->
items
;
i
++
)
for
(
int
i
=
i
d
x
;
i
<
this
->
items
;
i
++
)
this
->
array
[
i
]
=
this
->
array
[
i
+
1
];
this
->
array
[
i
]
=
this
->
array
[
i
+
1
];
this
->
array
[
this
->
items
]
=
NULL
;
this
->
array
[
this
->
items
]
=
NULL
;
assert
(
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
return
removed
;
return
removed
;
}
}
Object
*
Vector_remove
(
Vector
*
this
,
int
i
nde
x
)
{
Object
*
Vector_remove
(
Vector
*
this
,
int
i
d
x
)
{
Object
*
removed
=
Vector_take
(
this
,
i
nde
x
);
Object
*
removed
=
Vector_take
(
this
,
i
d
x
);
if
(
this
->
owner
)
{
if
(
this
->
owner
)
{
removed
->
delete
(
removed
);
removed
->
delete
(
removed
);
return
NULL
;
return
NULL
;
...
@@ -165,52 +165,52 @@ Object* Vector_remove(Vector* this, int index) {
...
@@ -165,52 +165,52 @@ Object* Vector_remove(Vector* this, int index) {
return
removed
;
return
removed
;
}
}
void
Vector_moveUp
(
Vector
*
this
,
int
i
nde
x
)
{
void
Vector_moveUp
(
Vector
*
this
,
int
i
d
x
)
{
assert
(
i
nde
x
>=
0
&&
i
nde
x
<
this
->
items
);
assert
(
i
d
x
>=
0
&&
i
d
x
<
this
->
items
);
assert
(
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
if
(
i
nde
x
==
0
)
if
(
i
d
x
==
0
)
return
;
return
;
Object
*
temp
=
this
->
array
[
i
nde
x
];
Object
*
temp
=
this
->
array
[
i
d
x
];
this
->
array
[
i
nde
x
]
=
this
->
array
[
i
nde
x
-
1
];
this
->
array
[
i
d
x
]
=
this
->
array
[
i
d
x
-
1
];
this
->
array
[
i
nde
x
-
1
]
=
temp
;
this
->
array
[
i
d
x
-
1
]
=
temp
;
}
}
void
Vector_moveDown
(
Vector
*
this
,
int
i
nde
x
)
{
void
Vector_moveDown
(
Vector
*
this
,
int
i
d
x
)
{
assert
(
i
nde
x
>=
0
&&
i
nde
x
<
this
->
items
);
assert
(
i
d
x
>=
0
&&
i
d
x
<
this
->
items
);
assert
(
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
if
(
i
nde
x
==
this
->
items
-
1
)
if
(
i
d
x
==
this
->
items
-
1
)
return
;
return
;
Object
*
temp
=
this
->
array
[
i
nde
x
];
Object
*
temp
=
this
->
array
[
i
d
x
];
this
->
array
[
i
nde
x
]
=
this
->
array
[
i
nde
x
+
1
];
this
->
array
[
i
d
x
]
=
this
->
array
[
i
d
x
+
1
];
this
->
array
[
i
nde
x
+
1
]
=
temp
;
this
->
array
[
i
d
x
+
1
]
=
temp
;
}
}
void
Vector_set
(
Vector
*
this
,
int
i
nde
x
,
void
*
data_
)
{
void
Vector_set
(
Vector
*
this
,
int
i
d
x
,
void
*
data_
)
{
assert
(
i
nde
x
>=
0
);
assert
(
i
d
x
>=
0
);
assert
(((
Object
*
)
data_
)
->
class
==
this
->
vectorType
);
assert
(((
Object
*
)
data_
)
->
class
==
this
->
vectorType
);
Object
*
data
=
data_
;
Object
*
data
=
data_
;
assert
(
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
Vector_checkArraySize
(
this
);
Vector_checkArraySize
(
this
);
if
(
i
nde
x
>=
this
->
items
)
{
if
(
i
d
x
>=
this
->
items
)
{
this
->
items
=
i
nde
x
+
1
;
this
->
items
=
i
d
x
+
1
;
}
else
{
}
else
{
if
(
this
->
owner
)
{
if
(
this
->
owner
)
{
Object
*
removed
=
this
->
array
[
i
nde
x
];
Object
*
removed
=
this
->
array
[
i
d
x
];
assert
(
removed
!=
NULL
);
assert
(
removed
!=
NULL
);
if
(
this
->
owner
)
{
if
(
this
->
owner
)
{
removed
->
delete
(
removed
);
removed
->
delete
(
removed
);
}
}
}
}
}
}
this
->
array
[
i
nde
x
]
=
data
;
this
->
array
[
i
d
x
]
=
data
;
assert
(
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
}
}
inline
Object
*
Vector_get
(
Vector
*
this
,
int
i
nde
x
)
{
inline
Object
*
Vector_get
(
Vector
*
this
,
int
i
d
x
)
{
assert
(
i
nde
x
<
this
->
items
);
assert
(
i
d
x
<
this
->
items
);
assert
(
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
return
this
->
array
[
i
nde
x
];
return
this
->
array
[
i
d
x
];
}
}
inline
int
Vector_size
(
Vector
*
this
)
{
inline
int
Vector_size
(
Vector
*
this
)
{
...
...
Vector.h
View file @
02a30bfe
...
@@ -49,19 +49,19 @@ void Vector_prune(Vector* this);
...
@@ -49,19 +49,19 @@ void Vector_prune(Vector* this);
void
Vector_sort
(
Vector
*
this
);
void
Vector_sort
(
Vector
*
this
);
void
Vector_insert
(
Vector
*
this
,
int
i
nde
x
,
void
*
data_
);
void
Vector_insert
(
Vector
*
this
,
int
i
d
x
,
void
*
data_
);
Object
*
Vector_take
(
Vector
*
this
,
int
i
nde
x
);
Object
*
Vector_take
(
Vector
*
this
,
int
i
d
x
);
Object
*
Vector_remove
(
Vector
*
this
,
int
i
nde
x
);
Object
*
Vector_remove
(
Vector
*
this
,
int
i
d
x
);
void
Vector_moveUp
(
Vector
*
this
,
int
i
nde
x
);
void
Vector_moveUp
(
Vector
*
this
,
int
i
d
x
);
void
Vector_moveDown
(
Vector
*
this
,
int
i
nde
x
);
void
Vector_moveDown
(
Vector
*
this
,
int
i
d
x
);
void
Vector_set
(
Vector
*
this
,
int
i
nde
x
,
void
*
data_
);
void
Vector_set
(
Vector
*
this
,
int
i
d
x
,
void
*
data_
);
extern
Object
*
Vector_get
(
Vector
*
this
,
int
i
nde
x
);
extern
Object
*
Vector_get
(
Vector
*
this
,
int
i
d
x
);
extern
int
Vector_size
(
Vector
*
this
);
extern
int
Vector_size
(
Vector
*
this
);
...
...
htop.c
View file @
02a30bfe
...
@@ -151,7 +151,7 @@ static void showHelp(ProcessList* pl) {
...
@@ -151,7 +151,7 @@ static void showHelp(ProcessList* pl) {
clear
();
clear
();
}
}
static
char
*
CategoriesFunctions
[]
=
{
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
"Done "
,
NULL
};
static
const
char
*
CategoriesFunctions
[]
=
{
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
"Done "
,
NULL
};
static
void
Setup_run
(
Settings
*
settings
,
int
headerHeight
)
{
static
void
Setup_run
(
Settings
*
settings
,
int
headerHeight
)
{
ScreenManager
*
scr
=
ScreenManager_new
(
0
,
headerHeight
,
0
,
-
1
,
HORIZONTAL
,
true
);
ScreenManager
*
scr
=
ScreenManager_new
(
0
,
headerHeight
,
0
,
-
1
,
HORIZONTAL
,
true
);
...
@@ -184,13 +184,14 @@ static bool changePriority(Panel* panel, int delta) {
...
@@ -184,13 +184,14 @@ static bool changePriority(Panel* panel, int delta) {
}
}
static
HandlerResult
pickWithEnter
(
Panel
*
panel
,
int
ch
)
{
static
HandlerResult
pickWithEnter
(
Panel
*
panel
,
int
ch
)
{
(
void
)
panel
;
if
(
ch
==
13
)
if
(
ch
==
13
)
return
BREAK_LOOP
;
return
BREAK_LOOP
;
return
IGNORED
;
return
IGNORED
;
}
}
static
Object
*
pickFromVector
(
Panel
*
panel
,
Panel
*
list
,
int
x
,
int
y
,
char
**
keyLabels
,
FunctionBar
*
prevBar
)
{
static
Object
*
pickFromVector
(
Panel
*
panel
,
Panel
*
list
,
int
x
,
int
y
,
const
char
**
keyLabels
,
FunctionBar
*
prevBar
)
{
char
*
fuKeys
[]
=
{
"Enter"
,
"Esc"
,
NULL
};
const
char
*
fuKeys
[]
=
{
"Enter"
,
"Esc"
,
NULL
};
int
fuEvents
[]
=
{
13
,
27
};
int
fuEvents
[]
=
{
13
,
27
};
if
(
!
list
->
eventHandler
)
if
(
!
list
->
eventHandler
)
Panel_setEventHandler
(
list
,
pickWithEnter
);
Panel_setEventHandler
(
list
,
pickWithEnter
);
...
@@ -325,12 +326,12 @@ int main(int argc, char** argv) {
...
@@ -325,12 +326,12 @@ int main(int argc, char** argv) {
}
}
Panel_setRichHeader
(
panel
,
ProcessList_printHeader
(
pl
));
Panel_setRichHeader
(
panel
,
ProcessList_printHeader
(
pl
));
char
*
searchFunctions
[]
=
{
"Next "
,
"Exit "
,
" Search: "
,
NULL
};
const
char
*
searchFunctions
[]
=
{
"Next "
,
"Exit "
,
" Search: "
,
NULL
};
char
*
searchKeys
[]
=
{
"F3"
,
"Esc"
,
" "
};
const
char
*
searchKeys
[]
=
{
"F3"
,
"Esc"
,
" "
};
int
searchEvents
[]
=
{
KEY_F
(
3
),
27
,
ERR
};
int
searchEvents
[]
=
{
KEY_F
(
3
),
27
,
ERR
};
FunctionBar
*
searchBar
=
FunctionBar_new
(
searchFunctions
,
searchKeys
,
searchEvents
);
FunctionBar
*
searchBar
=
FunctionBar_new
(
searchFunctions
,
searchKeys
,
searchEvents
);
char
*
defaultFunctions
[]
=
{
"Help "
,
"Setup "
,
"Search"
,
"Invert"
,
"Tree "
,
const
char
*
defaultFunctions
[]
=
{
"Help "
,
"Setup "
,
"Search"
,
"Invert"
,
"Tree "
,
"SortBy"
,
"Nice -"
,
"Nice +"
,
"Kill "
,
"Quit "
,
NULL
};
"SortBy"
,
"Nice -"
,
"Nice +"
,
"Kill "
,
"Quit "
,
NULL
};
FunctionBar
*
defaultBar
=
FunctionBar_new
(
defaultFunctions
,
NULL
,
NULL
);
FunctionBar
*
defaultBar
=
FunctionBar_new
(
defaultFunctions
,
NULL
,
NULL
);
...
@@ -358,7 +359,7 @@ int main(int argc, char** argv) {
...
@@ -358,7 +359,7 @@ int main(int argc, char** argv) {
oldTime
=
newTime
;
oldTime
=
newTime
;
if
(
doRefresh
)
{
if
(
doRefresh
)
{
int
currPos
=
Panel_getSelectedIndex
(
panel
);
int
currPos
=
Panel_getSelectedIndex
(
panel
);
unsigned
in
t
currPid
=
0
;
pid_
t
currPid
=
0
;
int
currScrollV
=
panel
->
scrollV
;
int
currScrollV
=
panel
->
scrollV
;
if
(
follow
)
if
(
follow
)
currPid
=
ProcessList_get
(
pl
,
currPos
)
->
pid
;
currPid
=
ProcessList_get
(
pl
,
currPos
)
->
pid
;
...
@@ -372,16 +373,16 @@ int main(int argc, char** argv) {
...
@@ -372,16 +373,16 @@ int main(int argc, char** argv) {
}
}
Panel_prune
(
panel
);
Panel_prune
(
panel
);
int
size
=
ProcessList_size
(
pl
);
int
size
=
ProcessList_size
(
pl
);
int
i
nde
x
=
0
;
int
i
d
x
=
0
;
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
Process
*
p
=
ProcessList_get
(
pl
,
i
);
Process
*
p
=
ProcessList_get
(
pl
,
i
);
if
(
!
userOnly
||
(
p
->
st_uid
==
userId
))
{
if
(
!
userOnly
||
(
p
->
st_uid
==
userId
))
{
Panel_set
(
panel
,
i
nde
x
,
(
Object
*
)
p
);
Panel_set
(
panel
,
i
d
x
,
(
Object
*
)
p
);
if
((
!
follow
&&
i
nde
x
==
currPos
)
||
(
follow
&&
p
->
pid
==
currPid
))
{
if
((
!
follow
&&
i
d
x
==
currPos
)
||
(
follow
&&
p
->
pid
==
currPid
))
{
Panel_setSelected
(
panel
,
i
nde
x
);
Panel_setSelected
(
panel
,
i
d
x
);
panel
->
scrollV
=
currScrollV
;
panel
->
scrollV
=
currScrollV
;
}
}
i
nde
x
++
;
i
d
x
++
;
}
}
}
}
}
}
...
@@ -452,7 +453,7 @@ int main(int argc, char** argv) {
...
@@ -452,7 +453,7 @@ int main(int argc, char** argv) {
continue
;
continue
;
}
}
if
(
isdigit
((
char
)
ch
))
{
if
(
isdigit
((
char
)
ch
))
{
unsigned
in
t
pid
=
ch
-
48
+
acc
;
pid_
t
pid
=
ch
-
48
+
acc
;
for
(
int
i
=
0
;
i
<
ProcessList_size
(
pl
)
&&
((
Process
*
)
Panel_getSelected
(
panel
))
->
pid
!=
pid
;
i
++
)
for
(
int
i
=
0
;
i
<
ProcessList_size
(
pl
)
&&
((
Process
*
)
Panel_getSelected
(
panel
))
->
pid
!=
pid
;
i
++
)
Panel_setSelected
(
panel
,
i
);
Panel_setSelected
(
panel
,
i
);
acc
=
pid
*
10
;
acc
=
pid
*
10
;
...
@@ -600,7 +601,7 @@ int main(int argc, char** argv) {
...
@@ -600,7 +601,7 @@ int main(int argc, char** argv) {
Vector_sort
(
usersPanel
->
items
);
Vector_sort
(
usersPanel
->
items
);
ListItem
*
allUsers
=
ListItem_new
(
"All users"
,
-
1
);
ListItem
*
allUsers
=
ListItem_new
(
"All users"
,
-
1
);
Panel_insert
(
usersPanel
,
0
,
(
Object
*
)
allUsers
);
Panel_insert
(
usersPanel
,
0
,
(
Object
*
)
allUsers
);
char
*
fuFunctions
[]
=
{
"Show "
,
"Cancel "
,
NULL
};
const
char
*
fuFunctions
[]
=
{
"Show "
,
"Cancel "
,
NULL
};
ListItem
*
picked
=
(
ListItem
*
)
pickFromVector
(
panel
,
usersPanel
,
20
,
headerHeight
,
fuFunctions
,
defaultBar
);
ListItem
*
picked
=
(
ListItem
*
)
pickFromVector
(
panel
,
usersPanel
,
20
,
headerHeight
,
fuFunctions
,
defaultBar
);
if
(
picked
)
{
if
(
picked
)
{
if
(
picked
==
allUsers
)
{
if
(
picked
==
allUsers
)
{
...
@@ -619,10 +620,10 @@ int main(int argc, char** argv) {
...
@@ -619,10 +620,10 @@ int main(int argc, char** argv) {
killPanel
=
(
Panel
*
)
SignalsPanel_new
(
0
,
0
,
0
,
0
);
killPanel
=
(
Panel
*
)
SignalsPanel_new
(
0
,
0
,
0
,
0
);
}
}
SignalsPanel_reset
((
SignalsPanel
*
)
killPanel
);
SignalsPanel_reset
((
SignalsPanel
*
)
killPanel
);
char
*
fuFunctions
[]
=
{
"Send "
,
"Cancel "
,
NULL
};
const
char
*
fuFunctions
[]
=
{
"Send "
,
"Cancel "
,
NULL
};
Signal
*
s
i
gn
al
=
(
Signal
*
)
pickFromVector
(
panel
,
killPanel
,
15
,
headerHeight
,
fuFunctions
,
defaultBar
);
Signal
*
sgn
=
(
Signal
*
)
pickFromVector
(
panel
,
killPanel
,
15
,
headerHeight
,
fuFunctions
,
defaultBar
);
if
(
s
i
gn
al
)
{
if
(
sgn
)
{
if
(
s
i
gn
al
->
number
!=
0
)
{
if
(
sgn
->
number
!=
0
)
{
Panel_setHeader
(
panel
,
"Sending..."
);
Panel_setHeader
(
panel
,
"Sending..."
);
Panel_draw
(
panel
,
true
);
Panel_draw
(
panel
,
true
);
refresh
();
refresh
();
...
@@ -630,13 +631,13 @@ int main(int argc, char** argv) {
...
@@ -630,13 +631,13 @@ int main(int argc, char** argv) {
for
(
int
i
=
0
;
i
<
Panel_size
(
panel
);
i
++
)
{
for
(
int
i
=
0
;
i
<
Panel_size
(
panel
);
i
++
)
{
Process
*
p
=
(
Process
*
)
Panel_get
(
panel
,
i
);
Process
*
p
=
(
Process
*
)
Panel_get
(
panel
,
i
);
if
(
p
->
tag
)
{
if
(
p
->
tag
)
{
Process_sendSignal
(
p
,
s
i
gn
al
->
number
);
Process_sendSignal
(
p
,
sgn
->
number
);
anyTagged
=
true
;
anyTagged
=
true
;
}
}
}
}
if
(
!
anyTagged
)
{
if
(
!
anyTagged
)
{
Process
*
p
=
(
Process
*
)
Panel_getSelected
(
panel
);
Process
*
p
=
(
Process
*
)
Panel_getSelected
(
panel
);
Process_sendSignal
(
p
,
s
i
gn
al
->
number
);
Process_sendSignal
(
p
,
sgn
->
number
);
}
}
napms
(
500
);
napms
(
500
);
}
}
...
@@ -651,12 +652,11 @@ int main(int argc, char** argv) {
...
@@ -651,12 +652,11 @@ int main(int argc, char** argv) {
if
(
pl
->
processorCount
==
1
)
if
(
pl
->
processorCount
==
1
)
break
;
break
;
Process
*
p
=
(
Process
*
)
Panel_getSelected
(
panel
);
unsigned
long
curr
=
Process_getAffinity
((
Process
*
)
Panel_getSelected
(
panel
));
unsigned
long
curr
=
Process_getAffinity
(
p
);
Panel
*
affinityPanel
=
AffinityPanel_new
(
pl
->
processorCount
,
curr
);
Panel
*
affinityPanel
=
AffinityPanel_new
(
pl
->
processorCount
,
curr
);
char
*
fuFunctions
[]
=
{
"Set "
,
"Cancel "
,
NULL
};
const
char
*
fuFunctions
[]
=
{
"Set "
,
"Cancel "
,
NULL
};
void
*
set
=
pickFromVector
(
panel
,
affinityPanel
,
15
,
headerHeight
,
fuFunctions
,
defaultBar
);
void
*
set
=
pickFromVector
(
panel
,
affinityPanel
,
15
,
headerHeight
,
fuFunctions
,
defaultBar
);
if
(
set
)
{
if
(
set
)
{
unsigned
long
new
=
AffinityPanel_getAffinity
(
affinityPanel
);
unsigned
long
new
=
AffinityPanel_getAffinity
(
affinityPanel
);
...
@@ -695,7 +695,7 @@ int main(int argc, char** argv) {
...
@@ -695,7 +695,7 @@ int main(int argc, char** argv) {
{
{
Panel
*
sortPanel
=
Panel_new
(
0
,
0
,
0
,
0
,
LISTITEM_CLASS
,
true
,
ListItem_compare
);
Panel
*
sortPanel
=
Panel_new
(
0
,
0
,
0
,
0
,
LISTITEM_CLASS
,
true
,
ListItem_compare
);
Panel_setHeader
(
sortPanel
,
"Sort by"
);
Panel_setHeader
(
sortPanel
,
"Sort by"
);
char
*
fuFunctions
[]
=
{
"Sort "
,
"Cancel "
,
NULL
};
const
char
*
fuFunctions
[]
=
{
"Sort "
,
"Cancel "
,
NULL
};
ProcessField
*
fields
=
pl
->
fields
;
ProcessField
*
fields
=
pl
->
fields
;
for
(
int
i
=
0
;
fields
[
i
];
i
++
)
{
for
(
int
i
=
0
;
fields
[
i
];
i
++
)
{
char
*
name
=
String_trim
(
Process_fieldTitles
[
fields
[
i
]]);
char
*
name
=
String_trim
(
Process_fieldTitles
[
fields
[
i
]]);
...
...
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment