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
a853faaa
Commit
a853faaa
authored
May 30, 2006
by
Hisham Muhammad
Browse files
Rename TypedVector to Vector, matching dit.
parent
7b2265b2
Changes
16
Hide whitespace changes
Inline
Side-by-side
ColorsListBox.c
View file @
a853faaa
...
@@ -88,7 +88,7 @@ HandlerResult ColorsListBox_EventHandler(ListBox* super, int ch) {
...
@@ -88,7 +88,7 @@ HandlerResult ColorsListBox_EventHandler(ListBox* super, int ch) {
this
->
settings
->
changed
=
true
;
this
->
settings
->
changed
=
true
;
Header
*
header
=
this
->
settings
->
header
;
Header
*
header
=
this
->
settings
->
header
;
CRT_setColors
(
mark
);
CRT_setColors
(
mark
);
ListBox
*
lbMenu
=
(
ListBox
*
)
Typed
Vector_get
(
this
->
scr
->
items
,
0
);
ListBox
*
lbMenu
=
(
ListBox
*
)
Vector_get
(
this
->
scr
->
items
,
0
);
Header_draw
(
header
);
Header_draw
(
header
);
RichString_setAttr
(
&
(
super
->
header
),
CRT_colors
[
PANEL_HEADER_FOCUS
]);
RichString_setAttr
(
&
(
super
->
header
),
CRT_colors
[
PANEL_HEADER_FOCUS
]);
RichString_setAttr
(
&
(
lbMenu
->
header
),
CRT_colors
[
PANEL_HEADER_UNFOCUS
]);
RichString_setAttr
(
&
(
lbMenu
->
header
),
CRT_colors
[
PANEL_HEADER_UNFOCUS
]);
...
...
ColumnsListBox.h
View file @
a853faaa
...
@@ -16,7 +16,7 @@ typedef struct ColumnsListBox_ {
...
@@ -16,7 +16,7 @@ typedef struct ColumnsListBox_ {
ListBox
super
;
ListBox
super
;
Settings
*
settings
;
Settings
*
settings
;
Typed
Vector
*
columns
;
Vector
*
columns
;
ScreenManager
*
scr
;
ScreenManager
*
scr
;
}
ColumnsListBox
;
}
ColumnsListBox
;
...
...
Header.c
View file @
a853faaa
...
@@ -19,8 +19,8 @@ typedef enum HeaderSide_ {
...
@@ -19,8 +19,8 @@ typedef enum HeaderSide_ {
} HeaderSide;
} HeaderSide;
typedef struct Header_ {
typedef struct Header_ {
Typed
Vector* leftMeters;
Vector* leftMeters;
Typed
Vector* rightMeters;
Vector* rightMeters;
ProcessList* pl;
ProcessList* pl;
bool margin;
bool margin;
int height;
int height;
...
@@ -35,21 +35,21 @@ typedef struct Header_ {
...
@@ -35,21 +35,21 @@ typedef struct Header_ {
Header
*
Header_new
(
ProcessList
*
pl
)
{
Header
*
Header_new
(
ProcessList
*
pl
)
{
Header
*
this
=
malloc
(
sizeof
(
Header
));
Header
*
this
=
malloc
(
sizeof
(
Header
));
this
->
leftMeters
=
Typed
Vector_new
(
METER_CLASS
,
true
,
DEFAULT_SIZE
);
this
->
leftMeters
=
Vector_new
(
METER_CLASS
,
true
,
DEFAULT_SIZE
);
this
->
rightMeters
=
Typed
Vector_new
(
METER_CLASS
,
true
,
DEFAULT_SIZE
);
this
->
rightMeters
=
Vector_new
(
METER_CLASS
,
true
,
DEFAULT_SIZE
);
this
->
margin
=
true
;
this
->
margin
=
true
;
this
->
pl
=
pl
;
this
->
pl
=
pl
;
return
this
;
return
this
;
}
}
void
Header_delete
(
Header
*
this
)
{
void
Header_delete
(
Header
*
this
)
{
Typed
Vector_delete
(
this
->
leftMeters
);
Vector_delete
(
this
->
leftMeters
);
Typed
Vector_delete
(
this
->
rightMeters
);
Vector_delete
(
this
->
rightMeters
);
free
(
this
);
free
(
this
);
}
}
void
Header_createMeter
(
Header
*
this
,
char
*
name
,
HeaderSide
side
)
{
void
Header_createMeter
(
Header
*
this
,
char
*
name
,
HeaderSide
side
)
{
Typed
Vector
*
meters
=
side
==
LEFT_HEADER
Vector
*
meters
=
side
==
LEFT_HEADER
?
this
->
leftMeters
?
this
->
leftMeters
:
this
->
rightMeters
;
:
this
->
rightMeters
;
...
@@ -62,44 +62,44 @@ void Header_createMeter(Header* this, char* name, HeaderSide side) {
...
@@ -62,44 +62,44 @@ void Header_createMeter(Header* this, char* name, HeaderSide side) {
}
}
for
(
MeterType
**
type
=
Meter_types
;
*
type
;
type
++
)
{
for
(
MeterType
**
type
=
Meter_types
;
*
type
;
type
++
)
{
if
(
String_eq
(
name
,
(
*
type
)
->
name
))
{
if
(
String_eq
(
name
,
(
*
type
)
->
name
))
{
Typed
Vector_add
(
meters
,
Meter_new
(
this
->
pl
,
param
,
*
type
));
Vector_add
(
meters
,
Meter_new
(
this
->
pl
,
param
,
*
type
));
break
;
break
;
}
}
}
}
}
}
void
Header_setMode
(
Header
*
this
,
int
i
,
MeterModeId
mode
,
HeaderSide
side
)
{
void
Header_setMode
(
Header
*
this
,
int
i
,
MeterModeId
mode
,
HeaderSide
side
)
{
Typed
Vector
*
meters
=
side
==
LEFT_HEADER
Vector
*
meters
=
side
==
LEFT_HEADER
?
this
->
leftMeters
?
this
->
leftMeters
:
this
->
rightMeters
;
:
this
->
rightMeters
;
Meter
*
meter
=
(
Meter
*
)
Typed
Vector_get
(
meters
,
i
);
Meter
*
meter
=
(
Meter
*
)
Vector_get
(
meters
,
i
);
Meter_setMode
(
meter
,
mode
);
Meter_setMode
(
meter
,
mode
);
}
}
Meter
*
Header_addMeter
(
Header
*
this
,
MeterType
*
type
,
int
param
,
HeaderSide
side
)
{
Meter
*
Header_addMeter
(
Header
*
this
,
MeterType
*
type
,
int
param
,
HeaderSide
side
)
{
Typed
Vector
*
meters
=
side
==
LEFT_HEADER
Vector
*
meters
=
side
==
LEFT_HEADER
?
this
->
leftMeters
?
this
->
leftMeters
:
this
->
rightMeters
;
:
this
->
rightMeters
;
Meter
*
meter
=
Meter_new
(
this
->
pl
,
param
,
type
);
Meter
*
meter
=
Meter_new
(
this
->
pl
,
param
,
type
);
Typed
Vector_add
(
meters
,
meter
);
Vector_add
(
meters
,
meter
);
return
meter
;
return
meter
;
}
}
int
Header_size
(
Header
*
this
,
HeaderSide
side
)
{
int
Header_size
(
Header
*
this
,
HeaderSide
side
)
{
Typed
Vector
*
meters
=
side
==
LEFT_HEADER
Vector
*
meters
=
side
==
LEFT_HEADER
?
this
->
leftMeters
?
this
->
leftMeters
:
this
->
rightMeters
;
:
this
->
rightMeters
;
return
Typed
Vector_size
(
meters
);
return
Vector_size
(
meters
);
}
}
char
*
Header_readMeterName
(
Header
*
this
,
int
i
,
HeaderSide
side
)
{
char
*
Header_readMeterName
(
Header
*
this
,
int
i
,
HeaderSide
side
)
{
Typed
Vector
*
meters
=
side
==
LEFT_HEADER
Vector
*
meters
=
side
==
LEFT_HEADER
?
this
->
leftMeters
?
this
->
leftMeters
:
this
->
rightMeters
;
:
this
->
rightMeters
;
Meter
*
meter
=
(
Meter
*
)
Typed
Vector_get
(
meters
,
i
);
Meter
*
meter
=
(
Meter
*
)
Vector_get
(
meters
,
i
);
int
nameLen
=
strlen
(
meter
->
type
->
name
);
int
nameLen
=
strlen
(
meter
->
type
->
name
);
int
len
=
nameLen
+
100
;
int
len
=
nameLen
+
100
;
...
@@ -113,21 +113,21 @@ char* Header_readMeterName(Header* this, int i, HeaderSide side) {
...
@@ -113,21 +113,21 @@ char* Header_readMeterName(Header* this, int i, HeaderSide side) {
}
}
MeterModeId
Header_readMeterMode
(
Header
*
this
,
int
i
,
HeaderSide
side
)
{
MeterModeId
Header_readMeterMode
(
Header
*
this
,
int
i
,
HeaderSide
side
)
{
Typed
Vector
*
meters
=
side
==
LEFT_HEADER
Vector
*
meters
=
side
==
LEFT_HEADER
?
this
->
leftMeters
?
this
->
leftMeters
:
this
->
rightMeters
;
:
this
->
rightMeters
;
Meter
*
meter
=
(
Meter
*
)
Typed
Vector_get
(
meters
,
i
);
Meter
*
meter
=
(
Meter
*
)
Vector_get
(
meters
,
i
);
return
meter
->
mode
;
return
meter
->
mode
;
}
}
void
Header_defaultMeters
(
Header
*
this
)
{
void
Header_defaultMeters
(
Header
*
this
)
{
Typed
Vector_add
(
this
->
leftMeters
,
Meter_new
(
this
->
pl
,
0
,
&
AllCPUsMeter
));
Vector_add
(
this
->
leftMeters
,
Meter_new
(
this
->
pl
,
0
,
&
AllCPUsMeter
));
Typed
Vector_add
(
this
->
leftMeters
,
Meter_new
(
this
->
pl
,
0
,
&
MemoryMeter
));
Vector_add
(
this
->
leftMeters
,
Meter_new
(
this
->
pl
,
0
,
&
MemoryMeter
));
Typed
Vector_add
(
this
->
leftMeters
,
Meter_new
(
this
->
pl
,
0
,
&
SwapMeter
));
Vector_add
(
this
->
leftMeters
,
Meter_new
(
this
->
pl
,
0
,
&
SwapMeter
));
Typed
Vector_add
(
this
->
rightMeters
,
Meter_new
(
this
->
pl
,
0
,
&
TasksMeter
));
Vector_add
(
this
->
rightMeters
,
Meter_new
(
this
->
pl
,
0
,
&
TasksMeter
));
Typed
Vector_add
(
this
->
rightMeters
,
Meter_new
(
this
->
pl
,
0
,
&
LoadAverageMeter
));
Vector_add
(
this
->
rightMeters
,
Meter_new
(
this
->
pl
,
0
,
&
LoadAverageMeter
));
Typed
Vector_add
(
this
->
rightMeters
,
Meter_new
(
this
->
pl
,
0
,
&
UptimeMeter
));
Vector_add
(
this
->
rightMeters
,
Meter_new
(
this
->
pl
,
0
,
&
UptimeMeter
));
}
}
void
Header_draw
(
Header
*
this
)
{
void
Header_draw
(
Header
*
this
)
{
...
@@ -138,13 +138,13 @@ void Header_draw(Header* this) {
...
@@ -138,13 +138,13 @@ void Header_draw(Header* this) {
for
(
int
y
=
0
;
y
<
height
;
y
++
)
{
for
(
int
y
=
0
;
y
<
height
;
y
++
)
{
mvhline
(
y
,
0
,
' '
,
COLS
);
mvhline
(
y
,
0
,
' '
,
COLS
);
}
}
for
(
int
y
=
(
pad
/
2
),
i
=
0
;
i
<
Typed
Vector_size
(
this
->
leftMeters
);
i
++
)
{
for
(
int
y
=
(
pad
/
2
),
i
=
0
;
i
<
Vector_size
(
this
->
leftMeters
);
i
++
)
{
Meter
*
meter
=
(
Meter
*
)
Typed
Vector_get
(
this
->
leftMeters
,
i
);
Meter
*
meter
=
(
Meter
*
)
Vector_get
(
this
->
leftMeters
,
i
);
meter
->
draw
(
meter
,
pad
,
y
,
COLS
/
2
-
(
pad
*
2
-
1
)
-
1
);
meter
->
draw
(
meter
,
pad
,
y
,
COLS
/
2
-
(
pad
*
2
-
1
)
-
1
);
y
+=
meter
->
h
;
y
+=
meter
->
h
;
}
}
for
(
int
y
=
(
pad
/
2
),
i
=
0
;
i
<
Typed
Vector_size
(
this
->
rightMeters
);
i
++
)
{
for
(
int
y
=
(
pad
/
2
),
i
=
0
;
i
<
Vector_size
(
this
->
rightMeters
);
i
++
)
{
Meter
*
meter
=
(
Meter
*
)
Typed
Vector_get
(
this
->
rightMeters
,
i
);
Meter
*
meter
=
(
Meter
*
)
Vector_get
(
this
->
rightMeters
,
i
);
meter
->
draw
(
meter
,
COLS
/
2
+
pad
,
y
,
COLS
/
2
-
(
pad
*
2
-
1
)
-
1
);
meter
->
draw
(
meter
,
COLS
/
2
+
pad
,
y
,
COLS
/
2
-
(
pad
*
2
-
1
)
-
1
);
y
+=
meter
->
h
;
y
+=
meter
->
h
;
}
}
...
@@ -155,12 +155,12 @@ int Header_calculateHeight(Header* this) {
...
@@ -155,12 +155,12 @@ int Header_calculateHeight(Header* this) {
int
leftHeight
=
pad
;
int
leftHeight
=
pad
;
int
rightHeight
=
pad
;
int
rightHeight
=
pad
;
for
(
int
i
=
0
;
i
<
Typed
Vector_size
(
this
->
leftMeters
);
i
++
)
{
for
(
int
i
=
0
;
i
<
Vector_size
(
this
->
leftMeters
);
i
++
)
{
Meter
*
meter
=
(
Meter
*
)
Typed
Vector_get
(
this
->
leftMeters
,
i
);
Meter
*
meter
=
(
Meter
*
)
Vector_get
(
this
->
leftMeters
,
i
);
leftHeight
+=
meter
->
h
;
leftHeight
+=
meter
->
h
;
}
}
for
(
int
i
=
0
;
i
<
Typed
Vector_size
(
this
->
rightMeters
);
i
++
)
{
for
(
int
i
=
0
;
i
<
Vector_size
(
this
->
rightMeters
);
i
++
)
{
Meter
*
meter
=
(
Meter
*
)
Typed
Vector_get
(
this
->
rightMeters
,
i
);
Meter
*
meter
=
(
Meter
*
)
Vector_get
(
this
->
rightMeters
,
i
);
rightHeight
+=
meter
->
h
;
rightHeight
+=
meter
->
h
;
}
}
this
->
pad
=
pad
;
this
->
pad
=
pad
;
...
...
Header.h
View file @
a853faaa
...
@@ -21,8 +21,8 @@ typedef enum HeaderSide_ {
...
@@ -21,8 +21,8 @@ typedef enum HeaderSide_ {
}
HeaderSide
;
}
HeaderSide
;
typedef
struct
Header_
{
typedef
struct
Header_
{
Typed
Vector
*
leftMeters
;
Vector
*
leftMeters
;
Typed
Vector
*
rightMeters
;
Vector
*
rightMeters
;
ProcessList
*
pl
;
ProcessList
*
pl
;
bool
margin
;
bool
margin
;
int
height
;
int
height
;
...
...
ListBox.c
View file @
a853faaa
...
@@ -7,7 +7,7 @@ in the source distribution for its full text.
...
@@ -7,7 +7,7 @@ in the source distribution for its full text.
#include "Object.h"
#include "Object.h"
#include "ListBox.h"
#include "ListBox.h"
#include "
Typed
Vector.h"
#include "Vector.h"
#include "CRT.h"
#include "CRT.h"
#include "RichString.h"
#include "RichString.h"
...
@@ -36,7 +36,7 @@ struct ListBox_ {
...
@@ -36,7 +36,7 @@ struct ListBox_ {
Object super;
Object super;
int x, y, w, h;
int x, y, w, h;
WINDOW* window;
WINDOW* window;
Typed
Vector* items;
Vector* items;
int selected;
int selected;
int scrollV, scrollH;
int scrollV, scrollH;
int oldSelected;
int oldSelected;
...
@@ -81,7 +81,7 @@ void ListBox_init(ListBox* this, int x, int y, int w, int h, char* type, bool ow
...
@@ -81,7 +81,7 @@ void ListBox_init(ListBox* this, int x, int y, int w, int h, char* type, bool ow
this
->
w
=
w
;
this
->
w
=
w
;
this
->
h
=
h
;
this
->
h
=
h
;
this
->
eventHandler
=
NULL
;
this
->
eventHandler
=
NULL
;
this
->
items
=
Typed
Vector_new
(
type
,
owner
,
DEFAULT_SIZE
);
this
->
items
=
Vector_new
(
type
,
owner
,
DEFAULT_SIZE
);
this
->
scrollV
=
0
;
this
->
scrollV
=
0
;
this
->
scrollH
=
0
;
this
->
scrollH
=
0
;
this
->
selected
=
0
;
this
->
selected
=
0
;
...
@@ -93,7 +93,7 @@ void ListBox_init(ListBox* this, int x, int y, int w, int h, char* type, bool ow
...
@@ -93,7 +93,7 @@ void ListBox_init(ListBox* this, int x, int y, int w, int h, char* type, bool ow
void
ListBox_done
(
ListBox
*
this
)
{
void
ListBox_done
(
ListBox
*
this
)
{
assert
(
this
!=
NULL
);
assert
(
this
!=
NULL
);
RichString_delete
(
this
->
header
);
RichString_delete
(
this
->
header
);
Typed
Vector_delete
(
this
->
items
);
Vector_delete
(
this
->
items
);
}
}
inline
void
ListBox_setRichHeader
(
ListBox
*
this
,
RichString
header
)
{
inline
void
ListBox_setRichHeader
(
ListBox
*
this
,
RichString
header
)
{
...
@@ -135,7 +135,7 @@ void ListBox_resize(ListBox* this, int w, int h) {
...
@@ -135,7 +135,7 @@ void ListBox_resize(ListBox* this, int w, int h) {
void
ListBox_prune
(
ListBox
*
this
)
{
void
ListBox_prune
(
ListBox
*
this
)
{
assert
(
this
!=
NULL
);
assert
(
this
!=
NULL
);
Typed
Vector_prune
(
this
->
items
);
Vector_prune
(
this
->
items
);
this
->
scrollV
=
0
;
this
->
scrollV
=
0
;
this
->
selected
=
0
;
this
->
selected
=
0
;
this
->
oldSelected
=
0
;
this
->
oldSelected
=
0
;
...
@@ -145,35 +145,35 @@ void ListBox_prune(ListBox* this) {
...
@@ -145,35 +145,35 @@ void ListBox_prune(ListBox* this) {
void
ListBox_add
(
ListBox
*
this
,
Object
*
o
)
{
void
ListBox_add
(
ListBox
*
this
,
Object
*
o
)
{
assert
(
this
!=
NULL
);
assert
(
this
!=
NULL
);
Typed
Vector_add
(
this
->
items
,
o
);
Vector_add
(
this
->
items
,
o
);
this
->
needsRedraw
=
true
;
this
->
needsRedraw
=
true
;
}
}
void
ListBox_insert
(
ListBox
*
this
,
int
i
,
Object
*
o
)
{
void
ListBox_insert
(
ListBox
*
this
,
int
i
,
Object
*
o
)
{
assert
(
this
!=
NULL
);
assert
(
this
!=
NULL
);
Typed
Vector_insert
(
this
->
items
,
i
,
o
);
Vector_insert
(
this
->
items
,
i
,
o
);
this
->
needsRedraw
=
true
;
this
->
needsRedraw
=
true
;
}
}
void
ListBox_set
(
ListBox
*
this
,
int
i
,
Object
*
o
)
{
void
ListBox_set
(
ListBox
*
this
,
int
i
,
Object
*
o
)
{
assert
(
this
!=
NULL
);
assert
(
this
!=
NULL
);
Typed
Vector_set
(
this
->
items
,
i
,
o
);
Vector_set
(
this
->
items
,
i
,
o
);
}
}
Object
*
ListBox_get
(
ListBox
*
this
,
int
i
)
{
Object
*
ListBox_get
(
ListBox
*
this
,
int
i
)
{
assert
(
this
!=
NULL
);
assert
(
this
!=
NULL
);
return
Typed
Vector_get
(
this
->
items
,
i
);
return
Vector_get
(
this
->
items
,
i
);
}
}
Object
*
ListBox_remove
(
ListBox
*
this
,
int
i
)
{
Object
*
ListBox_remove
(
ListBox
*
this
,
int
i
)
{
assert
(
this
!=
NULL
);
assert
(
this
!=
NULL
);
this
->
needsRedraw
=
true
;
this
->
needsRedraw
=
true
;
Object
*
removed
=
Typed
Vector_remove
(
this
->
items
,
i
);
Object
*
removed
=
Vector_remove
(
this
->
items
,
i
);
if
(
this
->
selected
>
0
&&
this
->
selected
>=
Typed
Vector_size
(
this
->
items
))
if
(
this
->
selected
>
0
&&
this
->
selected
>=
Vector_size
(
this
->
items
))
this
->
selected
--
;
this
->
selected
--
;
return
removed
;
return
removed
;
}
}
...
@@ -181,13 +181,13 @@ Object* ListBox_remove(ListBox* this, int i) {
...
@@ -181,13 +181,13 @@ Object* ListBox_remove(ListBox* this, int i) {
Object
*
ListBox_getSelected
(
ListBox
*
this
)
{
Object
*
ListBox_getSelected
(
ListBox
*
this
)
{
assert
(
this
!=
NULL
);
assert
(
this
!=
NULL
);
return
Typed
Vector_get
(
this
->
items
,
this
->
selected
);
return
Vector_get
(
this
->
items
,
this
->
selected
);
}
}
void
ListBox_moveSelectedUp
(
ListBox
*
this
)
{
void
ListBox_moveSelectedUp
(
ListBox
*
this
)
{
assert
(
this
!=
NULL
);
assert
(
this
!=
NULL
);
Typed
Vector_moveUp
(
this
->
items
,
this
->
selected
);
Vector_moveUp
(
this
->
items
,
this
->
selected
);
if
(
this
->
selected
>
0
)
if
(
this
->
selected
>
0
)
this
->
selected
--
;
this
->
selected
--
;
}
}
...
@@ -195,8 +195,8 @@ void ListBox_moveSelectedUp(ListBox* this) {
...
@@ -195,8 +195,8 @@ void ListBox_moveSelectedUp(ListBox* this) {
void
ListBox_moveSelectedDown
(
ListBox
*
this
)
{
void
ListBox_moveSelectedDown
(
ListBox
*
this
)
{
assert
(
this
!=
NULL
);
assert
(
this
!=
NULL
);
Typed
Vector_moveDown
(
this
->
items
,
this
->
selected
);
Vector_moveDown
(
this
->
items
,
this
->
selected
);
if
(
this
->
selected
+
1
<
Typed
Vector_size
(
this
->
items
))
if
(
this
->
selected
+
1
<
Vector_size
(
this
->
items
))
this
->
selected
++
;
this
->
selected
++
;
}
}
...
@@ -209,13 +209,13 @@ int ListBox_getSelectedIndex(ListBox* this) {
...
@@ -209,13 +209,13 @@ int ListBox_getSelectedIndex(ListBox* this) {
int
ListBox_getSize
(
ListBox
*
this
)
{
int
ListBox_getSize
(
ListBox
*
this
)
{
assert
(
this
!=
NULL
);
assert
(
this
!=
NULL
);
return
Typed
Vector_size
(
this
->
items
);
return
Vector_size
(
this
->
items
);
}
}
void
ListBox_setSelected
(
ListBox
*
this
,
int
selected
)
{
void
ListBox_setSelected
(
ListBox
*
this
,
int
selected
)
{
assert
(
this
!=
NULL
);
assert
(
this
!=
NULL
);
selected
=
MAX
(
0
,
MIN
(
Typed
Vector_size
(
this
->
items
)
-
1
,
selected
));
selected
=
MAX
(
0
,
MIN
(
Vector_size
(
this
->
items
)
-
1
,
selected
));
this
->
selected
=
selected
;
this
->
selected
=
selected
;
}
}
...
@@ -223,7 +223,7 @@ void ListBox_draw(ListBox* this, bool focus) {
...
@@ -223,7 +223,7 @@ void ListBox_draw(ListBox* this, bool focus) {
assert
(
this
!=
NULL
);
assert
(
this
!=
NULL
);
int
first
,
last
;
int
first
,
last
;
int
itemCount
=
Typed
Vector_size
(
this
->
items
);
int
itemCount
=
Vector_size
(
this
->
items
);
int
scrollH
=
this
->
scrollH
;
int
scrollH
=
this
->
scrollH
;
int
y
=
this
->
y
;
int
x
=
this
->
x
;
int
y
=
this
->
y
;
int
x
=
this
->
x
;
first
=
this
->
scrollV
;
first
=
this
->
scrollV
;
...
@@ -269,7 +269,7 @@ void ListBox_draw(ListBox* this, bool focus) {
...
@@ -269,7 +269,7 @@ void ListBox_draw(ListBox* this, bool focus) {
if
(
this
->
needsRedraw
)
{
if
(
this
->
needsRedraw
)
{
for
(
int
i
=
first
,
j
=
0
;
j
<
this
->
h
&&
i
<
last
;
i
++
,
j
++
)
{
for
(
int
i
=
first
,
j
=
0
;
j
<
this
->
h
&&
i
<
last
;
i
++
,
j
++
)
{
Object
*
itemObj
=
Typed
Vector_get
(
this
->
items
,
i
);
Object
*
itemObj
=
Vector_get
(
this
->
items
,
i
);
RichString
itemRef
=
RichString_new
();
RichString
itemRef
=
RichString_new
();
itemObj
->
display
(
itemObj
,
&
itemRef
);
itemObj
->
display
(
itemObj
,
&
itemRef
);
int
amt
=
MIN
(
itemRef
.
len
-
scrollH
,
this
->
w
);
int
amt
=
MIN
(
itemRef
.
len
-
scrollH
,
this
->
w
);
...
@@ -291,10 +291,10 @@ void ListBox_draw(ListBox* this, bool focus) {
...
@@ -291,10 +291,10 @@ void ListBox_draw(ListBox* this, bool focus) {
this
->
needsRedraw
=
false
;
this
->
needsRedraw
=
false
;
}
else
{
}
else
{
Object
*
oldObj
=
Typed
Vector_get
(
this
->
items
,
this
->
oldSelected
);
Object
*
oldObj
=
Vector_get
(
this
->
items
,
this
->
oldSelected
);
RichString
oldRef
=
RichString_new
();
RichString
oldRef
=
RichString_new
();
oldObj
->
display
(
oldObj
,
&
oldRef
);
oldObj
->
display
(
oldObj
,
&
oldRef
);
Object
*
newObj
=
Typed
Vector_get
(
this
->
items
,
this
->
selected
);
Object
*
newObj
=
Vector_get
(
this
->
items
,
this
->
selected
);
RichString
newRef
=
RichString_new
();
RichString
newRef
=
RichString_new
();
newObj
->
display
(
newObj
,
&
newRef
);
newObj
->
display
(
newObj
,
&
newRef
);
mvhline
(
y
+
this
->
oldSelected
-
this
->
scrollV
,
x
+
0
,
' '
,
this
->
w
);
mvhline
(
y
+
this
->
oldSelected
-
this
->
scrollV
,
x
+
0
,
' '
,
this
->
w
);
...
@@ -315,7 +315,7 @@ void ListBox_onKey(ListBox* this, int key) {
...
@@ -315,7 +315,7 @@ void ListBox_onKey(ListBox* this, int key) {
assert
(
this
!=
NULL
);
assert
(
this
!=
NULL
);
switch
(
key
)
{
switch
(
key
)
{
case
KEY_DOWN
:
case
KEY_DOWN
:
if
(
this
->
selected
+
1
<
Typed
Vector_size
(
this
->
items
))
if
(
this
->
selected
+
1
<
Vector_size
(
this
->
items
))
this
->
selected
++
;
this
->
selected
++
;
break
;
break
;
case
KEY_UP
:
case
KEY_UP
:
...
@@ -339,7 +339,7 @@ void ListBox_onKey(ListBox* this, int key) {
...
@@ -339,7 +339,7 @@ void ListBox_onKey(ListBox* this, int key) {
break
;
break
;
case
KEY_NPAGE
:
case
KEY_NPAGE
:
this
->
selected
+=
this
->
h
;
this
->
selected
+=
this
->
h
;
int
size
=
Typed
Vector_size
(
this
->
items
);
int
size
=
Vector_size
(
this
->
items
);
if
(
this
->
selected
>=
size
)
if
(
this
->
selected
>=
size
)
this
->
selected
=
size
-
1
;
this
->
selected
=
size
-
1
;
break
;
break
;
...
@@ -347,7 +347,7 @@ void ListBox_onKey(ListBox* this, int key) {
...
@@ -347,7 +347,7 @@ void ListBox_onKey(ListBox* this, int key) {
this
->
selected
=
0
;
this
->
selected
=
0
;
break
;
break
;
case
KEY_END
:
case
KEY_END
:
this
->
selected
=
Typed
Vector_size
(
this
->
items
)
-
1
;
this
->
selected
=
Vector_size
(
this
->
items
)
-
1
;
break
;
break
;
}
}
}
}
ListBox.h
View file @
a853faaa
...
@@ -10,7 +10,7 @@ in the source distribution for its full text.
...
@@ -10,7 +10,7 @@ in the source distribution for its full text.
*/
*/
#include "Object.h"
#include "Object.h"
#include "
Typed
Vector.h"
#include "Vector.h"
#include "CRT.h"
#include "CRT.h"
#include "RichString.h"
#include "RichString.h"
...
@@ -39,7 +39,7 @@ struct ListBox_ {
...
@@ -39,7 +39,7 @@ struct ListBox_ {
Object
super
;
Object
super
;
int
x
,
y
,
w
,
h
;
int
x
,
y
,
w
,
h
;
WINDOW
*
window
;
WINDOW
*
window
;
Typed
Vector
*
items
;
Vector
*
items
;
int
selected
;
int
selected
;
int
scrollV
,
scrollH
;
int
scrollV
,
scrollH
;
int
oldSelected
;
int
oldSelected
;
...
...
Makefile.am
View file @
a853faaa
...
@@ -15,14 +15,14 @@ CPUMeter.c CRT.c DebugMemory.c DisplayOptionsListBox.c FunctionBar.c \
...
@@ -15,14 +15,14 @@ CPUMeter.c CRT.c DebugMemory.c DisplayOptionsListBox.c FunctionBar.c \
Hashtable.c Header.c htop.c ListBox.c ListItem.c LoadAverageMeter.c
\
Hashtable.c Header.c htop.c ListBox.c ListItem.c LoadAverageMeter.c
\
MemoryMeter.c Meter.c MetersListBox.c Object.c Process.c
\
MemoryMeter.c Meter.c MetersListBox.c Object.c Process.c
\
ProcessList.c RichString.c ScreenManager.c Settings.c SignalItem.c
\
ProcessList.c RichString.c ScreenManager.c Settings.c SignalItem.c
\
SignalsListBox.c String.c SwapMeter.c TasksMeter.c
Typed
Vector.c
\
SignalsListBox.c String.c SwapMeter.c TasksMeter.c Vector.c
\
UptimeMeter.c UsersTable.c AvailableMetersListBox.h CategoriesListBox.h
\
UptimeMeter.c UsersTable.c AvailableMetersListBox.h CategoriesListBox.h
\
ClockMeter.h config.h CPUMeter.h CRT.h debug.h DebugMemory.h
\
ClockMeter.h config.h CPUMeter.h CRT.h debug.h DebugMemory.h
\
DisplayOptionsListBox.h FunctionBar.h Hashtable.h Header.h htop.h ListBox.h
\
DisplayOptionsListBox.h FunctionBar.h Hashtable.h Header.h htop.h ListBox.h
\
ListItem.h LoadAverageMeter.h MemoryMeter.h Meter.h
\
ListItem.h LoadAverageMeter.h MemoryMeter.h Meter.h
\
MetersListBox.h Object.h Process.h ProcessList.h RichString.h ScreenManager.h
\
MetersListBox.h Object.h Process.h ProcessList.h RichString.h ScreenManager.h
\
Settings.h SignalItem.h SignalsListBox.h String.h SwapMeter.h TasksMeter.h
\
Settings.h SignalItem.h SignalsListBox.h String.h SwapMeter.h TasksMeter.h
\
Typed
Vector.h UptimeMeter.h UsersTable.h CheckItem.c CheckItem.h
\
Vector.h UptimeMeter.h UsersTable.h CheckItem.c CheckItem.h
\
ColorsListBox.c ColorsListBox.h TraceScreen.c TraceScreen.h
\
ColorsListBox.c ColorsListBox.h TraceScreen.c TraceScreen.h
\
AvailableColumnsListBox.c AvailableColumnsListBox.h ColumnsListBox.c
\
AvailableColumnsListBox.c AvailableColumnsListBox.h ColumnsListBox.c
\
ColumnsListBox.h
ColumnsListBox.h
...
...
MetersListBox.c
View file @
a853faaa
...
@@ -14,13 +14,13 @@ typedef struct MetersListBox_ {
...
@@ -14,13 +14,13 @@ typedef struct MetersListBox_ {
ListBox super;
ListBox super;
Settings* settings;
Settings* settings;
Typed
Vector* meters;
Vector* meters;
ScreenManager* scr;
ScreenManager* scr;
} MetersListBox;
} MetersListBox;
}*/
}*/
MetersListBox
*
MetersListBox_new
(
Settings
*
settings
,
char
*
header
,
Typed
Vector
*
meters
,
ScreenManager
*
scr
)
{
MetersListBox
*
MetersListBox_new
(
Settings
*
settings
,
char
*
header
,
Vector
*
meters
,
ScreenManager
*
scr
)
{
MetersListBox
*
this
=
(
MetersListBox
*
)
malloc
(
sizeof
(
MetersListBox
));
MetersListBox
*
this
=
(
MetersListBox
*
)
malloc
(
sizeof
(
MetersListBox
));
ListBox
*
super
=
(
ListBox
*
)
this
;
ListBox
*
super
=
(
ListBox
*
)
this
;
ListBox_init
(
super
,
1
,
1
,
1
,
1
,
LISTITEM_CLASS
,
true
);
ListBox_init
(
super
,
1
,
1
,
1
,
1
,
LISTITEM_CLASS
,
true
);
...
@@ -31,8 +31,8 @@ MetersListBox* MetersListBox_new(Settings* settings, char* header, TypedVector*
...
@@ -31,8 +31,8 @@ MetersListBox* MetersListBox_new(Settings* settings, char* header, TypedVector*
this
->
scr
=
scr
;
this
->
scr
=
scr
;
super
->
eventHandler
=
MetersListBox_EventHandler
;
super
->
eventHandler
=
MetersListBox_EventHandler
;
ListBox_setHeader
(
super
,
header
);
ListBox_setHeader
(
super
,
header
);
for
(
int
i
=
0
;
i
<
Typed
Vector_size
(
meters
);
i
++
)
{
for
(
int
i
=
0
;
i
<
Vector_size
(
meters
);
i
++
)
{
Meter
*
meter
=
(
Meter
*
)
Typed
Vector_get
(
meters
,
i
);
Meter
*
meter
=
(
Meter
*
)
Vector_get
(
meters
,
i
);
ListBox_add
(
super
,
(
Object
*
)
Meter_toListItem
(
meter
));
ListBox_add
(
super
,
(
Object
*
)
Meter_toListItem
(
meter
));
}
}
return
this
;
return
this
;
...
@@ -58,7 +58,7 @@ HandlerResult MetersListBox_EventHandler(ListBox* super, int ch) {
...
@@ -58,7 +58,7 @@ HandlerResult MetersListBox_EventHandler(ListBox* super, int ch) {
case
KEY_F
(
4
):
case
KEY_F
(
4
):
case
't'
:
case
't'
:
{
{
Meter
*
meter
=
(
Meter
*
)
Typed
Vector_get
(
this
->
meters
,
selected
);
Meter
*
meter
=
(
Meter
*
)
Vector_get
(
this
->
meters
,
selected
);
int
mode
=
meter
->
mode
+
1
;
int
mode
=
meter
->
mode
+
1
;
if
(
mode
==
LAST_METERMODE
)
mode
=
1
;
if
(
mode
==
LAST_METERMODE
)
mode
=
1
;
Meter_setMode
(
meter
,
mode
);
Meter_setMode
(
meter
,
mode
);
...
@@ -70,7 +70,7 @@ HandlerResult MetersListBox_EventHandler(ListBox* super, int ch) {
...
@@ -70,7 +70,7 @@ HandlerResult MetersListBox_EventHandler(ListBox* super, int ch) {
case
'['
:
case
'['
:
case
'-'
:
case
'-'
:
{
{
Typed
Vector_moveUp
(
this
->
meters
,
selected
);
Vector_moveUp
(
this
->
meters
,
selected
);
ListBox_moveSelectedUp
(
super
);
ListBox_moveSelectedUp
(
super
);
result
=
HANDLED
;
result
=
HANDLED
;
break
;
break
;
...
@@ -79,7 +79,7 @@ HandlerResult MetersListBox_EventHandler(ListBox* super, int ch) {
...
@@ -79,7 +79,7 @@ HandlerResult MetersListBox_EventHandler(ListBox* super, int ch) {
case
']'
:
case
']'
:
case
'+'
:
case
'+'
:
{
{
Typed
Vector_moveDown
(
this
->
meters
,
selected
);
Vector_moveDown
(
this
->
meters
,
selected
);
ListBox_moveSelectedDown
(
super
);
ListBox_moveSelectedDown
(
super
);
result
=
HANDLED
;
result
=
HANDLED
;
break
;
break
;
...
@@ -87,8 +87,8 @@ HandlerResult MetersListBox_EventHandler(ListBox* super, int ch) {
...
@@ -87,8 +87,8 @@ HandlerResult MetersListBox_EventHandler(ListBox* super, int ch) {
case
KEY_F
(
9
):
case
KEY_F
(
9
):
case
KEY_DC
:
case
KEY_DC
:
{
{
if
(
selected
<
Typed
Vector_size
(
this
->
meters
))
{
if
(
selected
<
Vector_size
(
this
->
meters
))
{
Typed
Vector_remove
(
this
->
meters
,
selected
);
Vector_remove
(
this
->
meters
,
selected
);
ListBox_remove
(
super
,
selected
);
ListBox_remove
(
super
,
selected
);
}
}
result
=
HANDLED
;
result
=
HANDLED
;
...
...
MetersListBox.h
View file @
a853faaa
...
@@ -16,12 +16,12 @@ typedef struct MetersListBox_ {
...
@@ -16,12 +16,12 @@ typedef struct MetersListBox_ {
ListBox
super
;
ListBox
super
;
Settings
*
settings
;
Settings
*
settings
;
Typed
Vector
*
meters
;
Vector
*
meters
;
ScreenManager
*
scr
;
ScreenManager
*
scr
;
}
MetersListBox
;
}
MetersListBox
;
MetersListBox
*
MetersListBox_new
(
Settings
*
settings
,
char
*
header
,
Typed
Vector
*
meters
,
ScreenManager
*
scr
);
MetersListBox
*
MetersListBox_new
(
Settings
*
settings
,
char
*
header
,
Vector
*
meters
,
ScreenManager
*
scr
);
void
MetersListBox_delete
(
Object
*
object
);
void
MetersListBox_delete
(
Object
*
object
);
...
...
ProcessList.c
View file @
a853faaa
...
@@ -12,7 +12,7 @@ in the source distribution for its full text.
...
@@ -12,7 +12,7 @@ in the source distribution for its full text.
#include "ProcessList.h"
#include "ProcessList.h"
#include "Process.h"
#include "Process.h"
#include "
Typed
Vector.h"
#include "Vector.h"
#include "UsersTable.h"
#include "UsersTable.h"
#include "Hashtable.h"
#include "Hashtable.h"
...
@@ -56,8 +56,8 @@ in the source distribution for its full text.
...
@@ -56,8 +56,8 @@ in the source distribution for its full text.
/*{
/*{
typedef struct ProcessList_ {
typedef struct ProcessList_ {
Typed
Vector* processes;
Vector* processes;
Typed
Vector* processes2;
Vector* processes2;
Hashtable* processTable;
Hashtable* processTable;
Process* prototype;
Process* prototype;
UsersTable* usersTable;
UsersTable* usersTable;
...
@@ -168,13 +168,13 @@ static inline int ProcessList_xread(ProcessList* this, vxscanf fn, void* buffer,
...
@@ -168,13 +168,13 @@ static inline int ProcessList_xread(ProcessList* this, vxscanf fn, void* buffer,
ProcessList
*
ProcessList_new
(
UsersTable
*
usersTable
)
{
ProcessList
*
ProcessList_new
(
UsersTable
*
usersTable
)
{
ProcessList
*
this
;
ProcessList
*
this
;
this
=
malloc
(
sizeof
(
ProcessList
));
this
=
malloc
(
sizeof
(
ProcessList
));
this
->
processes
=
Typed
Vector_new
(
PROCESS_CLASS
,
true
,
DEFAULT_SIZE
);
this
->
processes
=
Vector_new
(
PROCESS_CLASS
,
true
,
DEFAULT_SIZE
);
this
->
processTable
=
Hashtable_new
(
20
,
false
);
this
->
processTable
=
Hashtable_new
(
20
,
false
);
this
->
prototype
=
Process_new
(
this
);
this
->
prototype
=
Process_new
(
this
);
this
->
usersTable
=
usersTable
;
this
->
usersTable
=
usersTable
;
/* tree-view auxiliary buffers */
/* tree-view auxiliary buffers */
this
->
processes2
=
Typed
Vector_new
(
PROCESS_CLASS
,
true
,
DEFAULT_SIZE
);
this
->
processes2
=
Vector_new
(
PROCESS_CLASS
,
true
,
DEFAULT_SIZE
);
#ifdef DEBUG
#ifdef DEBUG
this
->
traceFile
=
fopen
(
"/tmp/htop-proc-trace"
,
"w"
);
this
->
traceFile
=
fopen
(
"/tmp/htop-proc-trace"
,
"w"
);
...
@@ -206,7 +206,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable) {
...
@@ -206,7 +206,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable) {
}
}
this
->
fields
=
calloc
(
sizeof
(
ProcessField
),
LAST_PROCESSFIELD
+
1
);
this
->
fields
=
calloc
(
sizeof
(
ProcessField
),
LAST_PROCESSFIELD
+
1
);
// TODO: turn 'fields' into a
Typed
Vector,
// TODO: turn 'fields' into a Vector,
// (and ProcessFields into proper objects).
// (and ProcessFields into proper objects).
for
(
int
i
=
0
;
defaultHeaders
[
i
];
i
++
)
{
for
(
int
i
=
0
;
defaultHeaders
[
i
];
i
++
)
{
this
->
fields
[
i
]
=
defaultHeaders
[
i
];
this
->
fields
[
i
]
=
defaultHeaders
[
i
];
...
@@ -226,8 +226,8 @@ ProcessList* ProcessList_new(UsersTable* usersTable) {
...
@@ -226,8 +226,8 @@ ProcessList* ProcessList_new(UsersTable* usersTable) {
void
ProcessList_delete
(
ProcessList
*
this
)
{
void
ProcessList_delete
(
ProcessList
*
this
)
{
Hashtable_delete
(
this
->
processTable
);
Hashtable_delete
(
this
->
processTable
);
Typed
Vector_delete
(
this
->
processes
);
Vector_delete
(
this
->
processes
);
Typed
Vector_delete
(
this
->
processes2
);
Vector_delete
(
this
->
processes2
);
Process_delete
((
Object
*
)
this
->
prototype
);
Process_delete
((
Object
*
)
this
->
prototype
);
free
(
this
->
totalTime
);
free
(
this
->
totalTime
);
...
@@ -271,11 +271,11 @@ RichString ProcessList_printHeader(ProcessList* this) {
...
@@ -271,11 +271,11 @@ RichString ProcessList_printHeader(ProcessList* this) {
void
ProcessList_prune
(
ProcessList
*
this
)
{
void
ProcessList_prune
(
ProcessList
*
this
)
{
Typed
Vector_prune
(
this
->
processes
);
Vector_prune
(
this
->
processes
);
}
}
void
ProcessList_add
(
ProcessList
*
this
,
Process
*
p
)
{
void
ProcessList_add
(
ProcessList
*
this
,
Process
*
p
)
{
Typed
Vector_add
(
this
->
processes
,
p
);
Vector_add
(
this
->
processes
,
p
);
Hashtable_put
(
this
->
processTable
,
p
->
pid
,
p
);
Hashtable_put
(
this
->
processTable
,
p
->
pid
,
p
);
}
}
...
@@ -283,64 +283,64 @@ void ProcessList_remove(ProcessList* this, Process* p) {
...
@@ -283,64 +283,64 @@ void ProcessList_remove(ProcessList* this, Process* p) {
Hashtable_remove
(
this
->
processTable
,
p
->
pid
);
Hashtable_remove
(
this
->
processTable
,
p
->
pid
);
ProcessField
pf
=
this
->
sortKey
;
ProcessField
pf
=
this
->
sortKey
;
this
->
sortKey
=
PID
;
this
->
sortKey
=
PID
;
int
index
=
Typed
Vector_indexOf
(
this
->
processes
,
p
);
int
index
=
Vector_indexOf
(
this
->
processes
,
p
);
Typed
Vector_remove
(
this
->
processes
,
index
);
Vector_remove
(
this
->
processes
,
index
);
this
->
sortKey
=
pf
;
this
->
sortKey
=
pf
;
}
}
Process
*
ProcessList_get
(
ProcessList
*
this
,
int
index
)
{
Process
*
ProcessList_get
(
ProcessList
*
this
,
int
index
)
{
return
(
Process
*
)
(
Typed
Vector_get
(
this
->
processes
,
index
));
return
(
Process
*
)
(
Vector_get
(
this
->
processes
,
index
));
}
}
int
ProcessList_size
(
ProcessList
*
this
)
{
int
ProcessList_size
(
ProcessList
*
this
)
{
return
(
Typed
Vector_size
(
this
->
processes
));
return
(
Vector_size
(
this
->
processes
));
}
}
/* private */
/* private */
void
ProcessList_buildTree
(
ProcessList
*
this
,
int
pid
,
int
level
,
int
indent
,
int
direction
)
{
void
ProcessList_buildTree
(
ProcessList
*
this
,
int
pid
,
int
level
,
int
indent
,
int
direction
)
{
Typed
Vector
*
children
=
Typed
Vector_new
(
PROCESS_CLASS
,
false
,
DEFAULT_SIZE
);
Vector
*
children
=
Vector_new
(
PROCESS_CLASS
,
false
,
DEFAULT_SIZE
);
for
(
int
i
=
0
;
i
<
Typed
Vector_size
(
this
->
processes
);
i
++
)
{
for
(
int
i
=
0
;
i
<
Vector_size
(
this
->
processes
);
i
++
)
{
Process
*
process
=
(
Process
*
)
(
Typed
Vector_get
(
this
->
processes
,
i
));
Process
*
process
=
(
Process
*
)
(
Vector_get
(
this
->
processes
,
i
));
if
(
process
->
ppid
==
pid
)
{
if
(
process
->
ppid
==
pid
)
{
Process
*
process
=
(
Process
*
)
(
Typed
Vector_take
(
this
->
processes
,
i
));
Process
*
process
=
(
Process
*
)
(
Vector_take
(
this
->
processes
,
i
));
Typed
Vector_add
(
children
,
process
);
Vector_add
(
children
,
process
);
i
--
;
i
--
;
}
}
}
}
int
size
=
Typed
Vector_size
(
children
);
int
size
=
Vector_size
(
children
);
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
Process
*
process
=
(
Process
*
)
(
Typed
Vector_get
(
children
,
i
));
Process
*
process
=
(
Process
*
)
(
Vector_get
(
children
,
i
));
if
(
direction
==
1
)
if
(
direction
==
1
)
Typed
Vector_add
(
this
->
processes2
,
process
);
Vector_add
(
this
->
processes2
,
process
);
else
else
Typed
Vector_insert
(
this
->
processes2
,
0
,
process
);
Vector_insert
(
this
->
processes2
,
0
,
process
);
int
nextIndent
=
indent
;
int
nextIndent
=
indent
;
if
(
i
<
size
-
1
)
if
(
i
<
size
-
1
)
nextIndent
=
indent
|
(
1
<<
level
);
nextIndent
=
indent
|
(
1
<<
level
);
ProcessList_buildTree
(
this
,
process
->
pid
,
level
+
1
,
nextIndent
,
direction
);
ProcessList_buildTree
(
this
,
process
->
pid
,
level
+
1
,
nextIndent
,
direction
);
process
->
indent
=
indent
|
(
1
<<
level
);
process
->
indent
=
indent
|
(
1
<<
level
);
}
}
Typed
Vector_delete
(
children
);
Vector_delete
(
children
);
}
}
void
ProcessList_sort
(
ProcessList
*
this
)
{
void
ProcessList_sort
(
ProcessList
*
this
)
{
if
(
!
this
->
treeView
)
{
if
(
!
this
->
treeView
)
{
Typed
Vector_sort
(
this
->
processes
);
Vector_sort
(
this
->
processes
);
}
else
{
}
else
{
int
direction
=
this
->
direction
;
int
direction
=
this
->
direction
;
int
sortKey
=
this
->
sortKey
;
int
sortKey
=
this
->
sortKey
;
this
->
sortKey
=
PID
;
this
->
sortKey
=
PID
;
this
->
direction
=
1
;
this
->
direction
=
1
;
Typed
Vector_sort
(
this
->
processes
);
Vector_sort
(
this
->
processes
);
this
->
sortKey
=
sortKey
;
this
->
sortKey
=
sortKey
;
this
->
direction
=
direction
;
this
->
direction
=
direction
;
Process
*
init
=
(
Process
*
)
(
Typed
Vector_take
(
this
->
processes
,
0
));
Process
*
init
=
(
Process
*
)
(
Vector_take
(
this
->
processes
,
0
));
assert
(
init
->
pid
==
1
);
assert
(
init
->
pid
==
1
);
init
->
indent
=
0
;
init
->
indent
=
0
;
Typed
Vector_add
(
this
->
processes2
,
init
);
Vector_add
(
this
->
processes2
,
init
);
ProcessList_buildTree
(
this
,
init
->
pid
,
0
,
0
,
direction
);
ProcessList_buildTree
(
this
,
init
->
pid
,
0
,
0
,
direction
);
Typed
Vector
*
t
=
this
->
processes
;
Vector
*
t
=
this
->
processes
;
this
->
processes
=
this
->
processes2
;
this
->
processes
=
this
->
processes2
;
this
->
processes2
=
t
;
this
->
processes2
=
t
;
}
}
...
@@ -642,8 +642,8 @@ void ProcessList_scan(ProcessList* this) {
...
@@ -642,8 +642,8 @@ void ProcessList_scan(ProcessList* this) {
fclose
(
status
);
fclose
(
status
);
// mark all process as "dirty"
// mark all process as "dirty"
for
(
int
i
=
0
;
i
<
Typed
Vector_size
(
this
->
processes
);
i
++
)
{
for
(
int
i
=
0
;
i
<
Vector_size
(
this
->
processes
);
i
++
)
{
Process
*
p
=
(
Process
*
)
Typed
Vector_get
(
this
->
processes
,
i
);
Process
*
p
=
(
Process
*
)
Vector_get
(
this
->
processes
,
i
);
p
->
updated
=
false
;
p
->
updated
=
false
;
}
}
...
@@ -655,8 +655,8 @@ void ProcessList_scan(ProcessList* this) {
...
@@ -655,8 +655,8 @@ void ProcessList_scan(ProcessList* this) {
ProcessList_processEntries
(
this
,
PROCDIR
,
0
,
period
);
ProcessList_processEntries
(
this
,
PROCDIR
,
0
,
period
);
signal
(
11
,
SIG_DFL
);
signal
(
11
,
SIG_DFL
);
for
(
int
i
=
Typed
Vector_size
(
this
->
processes
)
-
1
;
i
>=
0
;
i
--
)
{
for
(
int
i
=
Vector_size
(
this
->
processes
)
-
1
;
i
>=
0
;
i
--
)
{
Process
*
p
=
(
Process
*
)
Typed
Vector_get
(
this
->
processes
,
i
);
Process
*
p
=
(
Process
*
)
Vector_get
(
this
->
processes
,
i
);
if
(
p
->
updated
==
false
)
if
(
p
->
updated
==
false
)
ProcessList_remove
(
this
,
p
);
ProcessList_remove
(
this
,
p
);
else
else
...
...
ProcessList.h
View file @
a853faaa
...
@@ -15,7 +15,7 @@ in the source distribution for its full text.
...
@@ -15,7 +15,7 @@ in the source distribution for its full text.
#endif
#endif
#include "Process.h"
#include "Process.h"
#include "
Typed
Vector.h"
#include "Vector.h"
#include "UsersTable.h"
#include "UsersTable.h"
#include "Hashtable.h"
#include "Hashtable.h"
...
@@ -56,8 +56,8 @@ in the source distribution for its full text.
...
@@ -56,8 +56,8 @@ in the source distribution for its full text.
typedef
struct
ProcessList_
{
typedef
struct
ProcessList_
{
Typed
Vector
*
processes
;
Vector
*
processes
;
Typed
Vector
*
processes2
;
Vector
*
processes2
;
Hashtable
*
processTable
;
Hashtable
*
processTable
;
Process
*
prototype
;
Process
*
prototype
;
UsersTable
*
usersTable
;
UsersTable
*
usersTable
;
...
...
ScreenManager.c
View file @
a853faaa
...
@@ -8,7 +8,7 @@ in the source distribution for its full text.
...
@@ -8,7 +8,7 @@ in the source distribution for its full text.
#include "ScreenManager.h"
#include "ScreenManager.h"
#include "ListBox.h"
#include "ListBox.h"
#include "Object.h"
#include "Object.h"
#include "
Typed
Vector.h"
#include "Vector.h"
#include "FunctionBar.h"
#include "FunctionBar.h"
#include "debug.h"
#include "debug.h"
...
@@ -29,8 +29,8 @@ typedef struct ScreenManager_ {
...
@@ -29,8 +29,8 @@ typedef struct ScreenManager_ {
int x2;
int x2;
int y2;
int y2;
Orientation orientation;
Orientation orientation;
Typed
Vector* items;
Vector* items;
Typed
Vector* fuBars;
Vector* fuBars;
int itemCount;
int itemCount;
FunctionBar* fuBar;
FunctionBar* fuBar;
bool owner;
bool owner;
...
@@ -47,16 +47,16 @@ ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation ori
...
@@ -47,16 +47,16 @@ ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation ori
this
->
y2
=
y2
;
this
->
y2
=
y2
;
this
->
fuBar
=
NULL
;
this
->
fuBar
=
NULL
;
this
->
orientation
=
orientation
;
this
->
orientation
=
orientation
;
this
->
items
=
Typed
Vector_new
(
LISTBOX_CLASS
,
owner
,
DEFAULT_SIZE
);
this
->
items
=
Vector_new
(
LISTBOX_CLASS
,
owner
,
DEFAULT_SIZE
);
this
->
fuBars
=
Typed
Vector_new
(
FUNCTIONBAR_CLASS
,
true
,
DEFAULT_SIZE
);
this
->
fuBars
=
Vector_new
(
FUNCTIONBAR_CLASS
,
true
,
DEFAULT_SIZE
);
this
->
itemCount
=
0
;
this
->
itemCount
=
0
;
this
->
owner
=
owner
;
this
->
owner
=
owner
;
return
this
;
return
this
;
}
}
void
ScreenManager_delete
(
ScreenManager
*
this
)
{
void
ScreenManager_delete
(
ScreenManager
*
this
)
{
Typed
Vector_delete
(
this
->
items
);
Vector_delete
(
this
->
items
);
Typed
Vector_delete
(
this
->
fuBars
);
Vector_delete
(
this
->
fuBars
);
free
(
this
);
free
(
this
);
}
}
...
@@ -68,7 +68,7 @@ void ScreenManager_add(ScreenManager* this, ListBox* item, FunctionBar* fuBar, i
...
@@ -68,7 +68,7 @@ void ScreenManager_add(ScreenManager* this, ListBox* item, FunctionBar* fuBar, i
if
(
this
->
orientation
==
HORIZONTAL
)
{
if
(
this
->
orientation
==
HORIZONTAL
)
{
int
lastX
=
0
;
int
lastX
=
0
;
if
(
this
->
itemCount
>
0
)
{
if
(
this
->
itemCount
>
0
)
{
ListBox
*
last
=
(
ListBox
*
)
Typed
Vector_get
(
this
->
items
,
this
->
itemCount
-
1
);
ListBox
*
last
=
(
ListBox
*
)
Vector_get
(
this
->
items
,
this
->
itemCount
-
1
);
lastX
=
last
->
x
+
last
->
w
+
1
;
lastX
=
last
->
x
+
last
->
w
+
1
;
}
}
if
(
size
>
0
)
{
if
(
size
>
0
)
{
...
@@ -79,11 +79,11 @@ void ScreenManager_add(ScreenManager* this, ListBox* item, FunctionBar* fuBar, i
...
@@ -79,11 +79,11 @@ void ScreenManager_add(ScreenManager* this, ListBox* item, FunctionBar* fuBar, i
ListBox_move
(
item
,
lastX
,
this
->
y1
);
ListBox_move
(
item
,
lastX
,
this
->
y1
);
}
}
// TODO: VERTICAL
// TODO: VERTICAL
Typed
Vector_add
(
this
->
items
,
item
);
Vector_add
(
this
->
items
,
item
);
if
(
fuBar
)
if
(
fuBar
)
Typed
Vector_add
(
this
->
fuBars
,
fuBar
);
Vector_add
(
this
->
fuBars
,
fuBar
);
else
else
Typed
Vector_add
(
this
->
fuBars
,
FunctionBar_new
(
0
,
NULL
,
NULL
,
NULL
));
Vector_add
(
this
->
fuBars
,
FunctionBar_new
(
0
,
NULL
,
NULL
,
NULL
));
if
(
!
this
->
fuBar
&&
fuBar
)
this
->
fuBar
=
fuBar
;
if
(
!
this
->
fuBar
&&
fuBar
)
this
->
fuBar
=
fuBar
;
item
->
needsRedraw
=
true
;
item
->
needsRedraw
=
true
;
this
->
itemCount
++
;
this
->
itemCount
++
;
...
@@ -91,8 +91,8 @@ void ScreenManager_add(ScreenManager* this, ListBox* item, FunctionBar* fuBar, i
...
@@ -91,8 +91,8 @@ void ScreenManager_add(ScreenManager* this, ListBox* item, FunctionBar* fuBar, i
ListBox
*
ScreenManager_remove
(
ScreenManager
*
this
,
int
index
)
{
ListBox
*
ScreenManager_remove
(
ScreenManager
*
this
,
int
index
)
{
assert
(
this
->
itemCount
>
index
);
assert
(
this
->
itemCount
>
index
);
ListBox
*
lb
=
(
ListBox
*
)
Typed
Vector_remove
(
this
->
items
,
index
);
ListBox
*
lb
=
(
ListBox
*
)
Vector_remove
(
this
->
items
,
index
);
Typed
Vector_remove
(
this
->
fuBars
,
index
);
Vector_remove
(
this
->
fuBars
,
index
);
this
->
fuBar
=
NULL
;
this
->
fuBar
=
NULL
;
this
->
itemCount
--
;
this
->
itemCount
--
;
return
lb
;
return
lb
;
...
@@ -112,12 +112,12 @@ void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2) {
...
@@ -112,12 +112,12 @@ void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2) {
int
items
=
this
->
itemCount
;
int
items
=
this
->
itemCount
;
int
lastX
=
0
;
int
lastX
=
0
;
for
(
int
i
=
0
;
i
<
items
-
1
;
i
++
)
{
for
(
int
i
=
0
;
i
<
items
-
1
;
i
++
)
{
ListBox
*
lb
=
(
ListBox
*
)
Typed
Vector_get
(
this
->
items
,
i
);
ListBox
*
lb
=
(
ListBox
*
)
Vector_get
(
this
->
items
,
i
);
ListBox_resize
(
lb
,
lb
->
w
,
LINES
-
y1
+
y2
);
ListBox_resize
(
lb
,
lb
->
w
,
LINES
-
y1
+
y2
);
ListBox_move
(
lb
,
lastX
,
y1
);
ListBox_move
(
lb
,
lastX
,
y1
);
lastX
=
lb
->
x
+
lb
->
w
+
1
;
lastX
=
lb
->
x
+
lb
->
w
+
1
;
}
}
ListBox
*
lb
=
(
ListBox
*
)
Typed
Vector_get
(
this
->
items
,
items
-
1
);
ListBox
*
lb
=
(
ListBox
*
)
Vector_get
(
this
->
items
,
items
-
1
);
ListBox_resize
(
lb
,
COLS
-
x1
+
x2
-
lastX
,
LINES
-
y1
+
y2
);
ListBox_resize
(
lb
,
COLS
-
x1
+
x2
-
lastX
,
LINES
-
y1
+
y2
);
ListBox_move
(
lb
,
lastX
,
y1
);
ListBox_move
(
lb
,
lastX
,
y1
);
}
}
...
@@ -126,7 +126,7 @@ void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey) {
...
@@ -126,7 +126,7 @@ void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey) {
bool
quit
=
false
;
bool
quit
=
false
;
int
focus
=
0
;
int
focus
=
0
;
ListBox
*
lbFocus
=
(
ListBox
*
)
Typed
Vector_get
(
this
->
items
,
focus
);
ListBox
*
lbFocus
=
(
ListBox
*
)
Vector_get
(
this
->
items
,
focus
);
if
(
this
->
fuBar
)
if
(
this
->
fuBar
)
FunctionBar_draw
(
this
->
fuBar
,
NULL
);
FunctionBar_draw
(
this
->
fuBar
,
NULL
);
...
@@ -134,7 +134,7 @@ void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey) {
...
@@ -134,7 +134,7 @@ void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey) {
while
(
!
quit
)
{
while
(
!
quit
)
{
int
items
=
this
->
itemCount
;
int
items
=
this
->
itemCount
;
for
(
int
i
=
0
;
i
<
items
;
i
++
)
{
for
(
int
i
=
0
;
i
<
items
;
i
++
)
{
ListBox
*
lb
=
(
ListBox
*
)
Typed
Vector_get
(
this
->
items
,
i
);
ListBox
*
lb
=
(
ListBox
*
)
Vector_get
(
this
->
items
,
i
);
ListBox_draw
(
lb
,
i
==
focus
);
ListBox_draw
(
lb
,
i
==
focus
);
if
(
i
<
items
)
{
if
(
i
<
items
)
{
if
(
this
->
orientation
==
HORIZONTAL
)
{
if
(
this
->
orientation
==
HORIZONTAL
)
{
...
@@ -142,7 +142,7 @@ void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey) {
...
@@ -142,7 +142,7 @@ void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey) {
}
}
}
}
}
}
FunctionBar
*
bar
=
(
FunctionBar
*
)
Typed
Vector_get
(
this
->
fuBars
,
focus
);
FunctionBar
*
bar
=
(
FunctionBar
*
)
Vector_get
(
this
->
fuBars
,
focus
);
if
(
bar
)
if
(
bar
)
this
->
fuBar
=
bar
;
this
->
fuBar
=
bar
;
if
(
this
->
fuBar
)
if
(
this
->
fuBar
)
...
@@ -159,7 +159,7 @@ void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey) {
...
@@ -159,7 +159,7 @@ void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey) {
ch
=
FunctionBar_synthesizeEvent
(
this
->
fuBar
,
mevent
.
x
);
ch
=
FunctionBar_synthesizeEvent
(
this
->
fuBar
,
mevent
.
x
);
}
else
{
}
else
{
for
(
int
i
=
0
;
i
<
this
->
itemCount
;
i
++
)
{
for
(
int
i
=
0
;
i
<
this
->
itemCount
;
i
++
)
{
ListBox
*
lb
=
(
ListBox
*
)
Typed
Vector_get
(
this
->
items
,
i
);
ListBox
*
lb
=
(
ListBox
*
)
Vector_get
(
this
->
items
,
i
);
if
(
mevent
.
x
>
lb
->
x
&&
mevent
.
x
<=
lb
->
x
+
lb
->
w
&&
if
(
mevent
.
x
>
lb
->
x
&&
mevent
.
x
<=
lb
->
x
+
lb
->
w
&&
mevent
.
y
>
lb
->
y
&&
mevent
.
y
<=
lb
->
y
+
lb
->
h
)
{
mevent
.
y
>
lb
->
y
&&
mevent
.
y
<=
lb
->
y
+
lb
->
h
)
{
focus
=
i
;
focus
=
i
;
...
@@ -196,7 +196,7 @@ void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey) {
...
@@ -196,7 +196,7 @@ void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey) {
tryLeft:
tryLeft:
if
(
focus
>
0
)
if
(
focus
>
0
)
focus
--
;
focus
--
;
lbFocus
=
(
ListBox
*
)
Typed
Vector_get
(
this
->
items
,
focus
);
lbFocus
=
(
ListBox
*
)
Vector_get
(
this
->
items
,
focus
);
if
(
ListBox_getSize
(
lbFocus
)
==
0
&&
focus
>
0
)
if
(
ListBox_getSize
(
lbFocus
)
==
0
&&
focus
>
0
)
goto
tryLeft
;
goto
tryLeft
;
break
;
break
;
...
@@ -205,7 +205,7 @@ void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey) {
...
@@ -205,7 +205,7 @@ void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey) {
tryRight:
tryRight:
if
(
focus
<
this
->
itemCount
-
1
)
if
(
focus
<
this
->
itemCount
-
1
)
focus
++
;
focus
++
;
lbFocus
=
(
ListBox
*
)
Typed
Vector_get
(
this
->
items
,
focus
);
lbFocus
=
(
ListBox
*
)
Vector_get
(
this
->
items
,
focus
);
if
(
ListBox_getSize
(
lbFocus
)
==
0
&&
focus
<
this
->
itemCount
-
1
)
if
(
ListBox_getSize
(
lbFocus
)
==
0
&&
focus
<
this
->
itemCount
-
1
)
goto
tryRight
;
goto
tryRight
;
break
;
break
;
...
...
ScreenManager.h
View file @
a853faaa
...
@@ -11,7 +11,7 @@ in the source distribution for its full text.
...
@@ -11,7 +11,7 @@ in the source distribution for its full text.
#include "ListBox.h"
#include "ListBox.h"
#include "Object.h"
#include "Object.h"
#include "
Typed
Vector.h"
#include "Vector.h"
#include "FunctionBar.h"
#include "FunctionBar.h"
#include "debug.h"
#include "debug.h"
...
@@ -31,10 +31,10 @@ typedef struct ScreenManager_ {
...
@@ -31,10 +31,10 @@ typedef struct ScreenManager_ {
int
x2
;
int
x2
;
int
y2
;
int
y2
;
Orientation
orientation
;
Orientation
orientation
;
Typed
Vector
*
items
;
Vector
*
items
;
int
itemCount
;
int
itemCount
;
FunctionBar
*
fuBar
;
FunctionBar
*
fuBar
;
Typed
Vector
*
fuBars
;
Vector
*
fuBars
;
bool
owner
;
bool
owner
;
}
ScreenManager
;
}
ScreenManager
;
...
...
Typed
Vector.c
→
Vector.c
View file @
a853faaa
...
@@ -5,7 +5,7 @@ Released under the GNU GPL, see the COPYING file
...
@@ -5,7 +5,7 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
in the source distribution for its full text.
*/
*/
#include "
Typed
Vector.h"
#include "Vector.h"
#include "Object.h"
#include "Object.h"
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
...
@@ -20,25 +20,25 @@ in the source distribution for its full text.
...
@@ -20,25 +20,25 @@ in the source distribution for its full text.
#define DEFAULT_SIZE -1
#define DEFAULT_SIZE -1
#endif
#endif
typedef void(*
Typed
Vector_procedure)(void*);
typedef void(*Vector_procedure)(void*);
typedef struct
Typed
Vector_ {
typedef struct Vector_ {
Object **array;
Object **array;
int arraySize;
int arraySize;
int growthRate;
int growthRate;
int items;
int items;
char* vectorType;
char* vectorType;
bool owner;
bool owner;
}
Typed
Vector;
} Vector;
}*/
}*/
Typed
Vector
*
Typed
Vector_new
(
char
*
vectorType_
,
bool
owner
,
int
size
)
{
Vector
*
Vector_new
(
char
*
vectorType_
,
bool
owner
,
int
size
)
{
Typed
Vector
*
this
;
Vector
*
this
;
if
(
size
==
DEFAULT_SIZE
)
if
(
size
==
DEFAULT_SIZE
)
size
=
10
;
size
=
10
;
this
=
(
Typed
Vector
*
)
malloc
(
sizeof
(
Typed
Vector
));
this
=
(
Vector
*
)
malloc
(
sizeof
(
Vector
));
this
->
growthRate
=
size
;
this
->
growthRate
=
size
;
this
->
array
=
(
Object
**
)
calloc
(
size
,
sizeof
(
Object
*
));
this
->
array
=
(
Object
**
)
calloc
(
size
,
sizeof
(
Object
*
));
this
->
arraySize
=
size
;
this
->
arraySize
=
size
;
...
@@ -48,7 +48,7 @@ TypedVector* TypedVector_new(char* vectorType_, bool owner, int size) {
...
@@ -48,7 +48,7 @@ TypedVector* TypedVector_new(char* vectorType_, bool owner, int size) {
return
this
;
return
this
;
}
}
void
Typed
Vector_delete
(
Typed
Vector
*
this
)
{
void
Vector_delete
(
Vector
*
this
)
{
if
(
this
->
owner
)
{
if
(
this
->
owner
)
{
for
(
int
i
=
0
;
i
<
this
->
items
;
i
++
)
for
(
int
i
=
0
;
i
<
this
->
items
;
i
++
)
if
(
this
->
array
[
i
])
if
(
this
->
array
[
i
])
...
@@ -59,7 +59,7 @@ void TypedVector_delete(TypedVector* this) {
...
@@ -59,7 +59,7 @@ void TypedVector_delete(TypedVector* this) {
}
}
/* private */
/* private */
bool
Typed
Vector_isConsistent
(
Typed
Vector
*
this
)
{
bool
Vector_isConsistent
(
Vector
*
this
)
{
if
(
this
->
owner
)
{
if
(
this
->
owner
)
{
for
(
int
i
=
0
;
i
<
this
->
items
;
i
++
)
for
(
int
i
=
0
;
i
<
this
->
items
;
i
++
)
if
(
this
->
array
[
i
]
&&
this
->
array
[
i
]
->
class
!=
this
->
vectorType
)
if
(
this
->
array
[
i
]
&&
this
->
array
[
i
]
->
class
!=
this
->
vectorType
)
...
@@ -70,8 +70,8 @@ bool TypedVector_isConsistent(TypedVector* this) {
...
@@ -70,8 +70,8 @@ bool TypedVector_isConsistent(TypedVector* this) {
}
}
}
}
void
Typed
Vector_prune
(
Typed
Vector
*
this
)
{
void
Vector_prune
(
Vector
*
this
)
{
assert
(
Typed
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
int
i
;
int
i
;
for
(
i
=
0
;
i
<
this
->
items
;
i
++
)
for
(
i
=
0
;
i
<
this
->
items
;
i
++
)
...
@@ -83,8 +83,8 @@ void TypedVector_prune(TypedVector* this) {
...
@@ -83,8 +83,8 @@ void TypedVector_prune(TypedVector* this) {
this
->
items
=
0
;
this
->
items
=
0
;
}
}
void
Typed
Vector_sort
(
Typed
Vector
*
this
)
{
void
Vector_sort
(
Vector
*
this
)
{
assert
(
Typed
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
int
i
,
j
;
int
i
,
j
;
for
(
i
=
1
;
i
<
this
->
items
;
i
++
)
{
for
(
i
=
1
;
i
<
this
->
items
;
i
++
)
{
void
*
t
=
this
->
array
[
i
];
void
*
t
=
this
->
array
[
i
];
...
@@ -92,7 +92,7 @@ void TypedVector_sort(TypedVector* this) {
...
@@ -92,7 +92,7 @@ void TypedVector_sort(TypedVector* this) {
this
->
array
[
j
+
1
]
=
this
->
array
[
j
];
this
->
array
[
j
+
1
]
=
this
->
array
[
j
];
this
->
array
[
j
+
1
]
=
t
;
this
->
array
[
j
+
1
]
=
t
;
}
}
assert
(
Typed
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
/*
/*
for (int i = 0; i < this->items; i++) {
for (int i = 0; i < this->items; i++) {
...
@@ -108,8 +108,8 @@ void TypedVector_sort(TypedVector* this) {
...
@@ -108,8 +108,8 @@ void TypedVector_sort(TypedVector* this) {
}
}
/* private */
/* private */
void
Typed
Vector_checkArraySize
(
Typed
Vector
*
this
)
{
void
Vector_checkArraySize
(
Vector
*
this
)
{
assert
(
Typed
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
if
(
this
->
items
>=
this
->
arraySize
)
{
if
(
this
->
items
>=
this
->
arraySize
)
{
int
i
;
int
i
;
i
=
this
->
arraySize
;
i
=
this
->
arraySize
;
...
@@ -118,40 +118,40 @@ void TypedVector_checkArraySize(TypedVector* this) {
...
@@ -118,40 +118,40 @@ void TypedVector_checkArraySize(TypedVector* this) {
for
(;
i
<
this
->
arraySize
;
i
++
)
for
(;
i
<
this
->
arraySize
;
i
++
)
this
->
array
[
i
]
=
NULL
;
this
->
array
[
i
]
=
NULL
;
}
}
assert
(
Typed
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
}
}
void
Typed
Vector_insert
(
Typed
Vector
*
this
,
int
index
,
void
*
data_
)
{
void
Vector_insert
(
Vector
*
this
,
int
index
,
void
*
data_
)
{
assert
(
index
>=
0
);
assert
(
index
>=
0
);
assert
(((
Object
*
)
data_
)
->
class
==
this
->
vectorType
);
assert
(((
Object
*
)
data_
)
->
class
==
this
->
vectorType
);
Object
*
data
=
data_
;
Object
*
data
=
data_
;
assert
(
Typed
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
Typed
Vector_checkArraySize
(
this
);
Vector_checkArraySize
(
this
);
assert
(
this
->
array
[
this
->
items
]
==
NULL
);
assert
(
this
->
array
[
this
->
items
]
==
NULL
);
for
(
int
i
=
this
->
items
;
i
>=
index
;
i
--
)
{
for
(
int
i
=
this
->
items
;
i
>=
index
;
i
--
)
{
this
->
array
[
i
+
1
]
=
this
->
array
[
i
];
this
->
array
[
i
+
1
]
=
this
->
array
[
i
];
}
}
this
->
array
[
index
]
=
data
;
this
->
array
[
index
]
=
data
;
this
->
items
++
;
this
->
items
++
;
assert
(
Typed
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
}
}
Object
*
Typed
Vector_take
(
Typed
Vector
*
this
,
int
index
)
{
Object
*
Vector_take
(
Vector
*
this
,
int
index
)
{
assert
(
index
>=
0
&&
index
<
this
->
items
);
assert
(
index
>=
0
&&
index
<
this
->
items
);
assert
(
Typed
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
Object
*
removed
=
this
->
array
[
index
];
Object
*
removed
=
this
->
array
[
index
];
assert
(
removed
!=
NULL
);
assert
(
removed
!=
NULL
);
this
->
items
--
;
this
->
items
--
;
for
(
int
i
=
index
;
i
<
this
->
items
;
i
++
)
for
(
int
i
=
index
;
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
(
Typed
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
return
removed
;
return
removed
;
}
}
Object
*
Typed
Vector_remove
(
Typed
Vector
*
this
,
int
index
)
{
Object
*
Vector_remove
(
Vector
*
this
,
int
index
)
{
Object
*
removed
=
Typed
Vector_take
(
this
,
index
);
Object
*
removed
=
Vector_take
(
this
,
index
);
if
(
this
->
owner
)
{
if
(
this
->
owner
)
{
removed
->
delete
(
removed
);
removed
->
delete
(
removed
);
return
NULL
;
return
NULL
;
...
@@ -159,9 +159,9 @@ Object* TypedVector_remove(TypedVector* this, int index) {
...
@@ -159,9 +159,9 @@ Object* TypedVector_remove(TypedVector* this, int index) {
return
removed
;
return
removed
;
}
}
void
Typed
Vector_moveUp
(
Typed
Vector
*
this
,
int
index
)
{
void
Vector_moveUp
(
Vector
*
this
,
int
index
)
{
assert
(
index
>=
0
&&
index
<
this
->
items
);
assert
(
index
>=
0
&&
index
<
this
->
items
);
assert
(
Typed
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
if
(
index
==
0
)
if
(
index
==
0
)
return
;
return
;
Object
*
temp
=
this
->
array
[
index
];
Object
*
temp
=
this
->
array
[
index
];
...
@@ -169,9 +169,9 @@ void TypedVector_moveUp(TypedVector* this, int index) {
...
@@ -169,9 +169,9 @@ void TypedVector_moveUp(TypedVector* this, int index) {
this
->
array
[
index
-
1
]
=
temp
;
this
->
array
[
index
-
1
]
=
temp
;
}
}
void
Typed
Vector_moveDown
(
Typed
Vector
*
this
,
int
index
)
{
void
Vector_moveDown
(
Vector
*
this
,
int
index
)
{
assert
(
index
>=
0
&&
index
<
this
->
items
);
assert
(
index
>=
0
&&
index
<
this
->
items
);
assert
(
Typed
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
if
(
index
==
this
->
items
-
1
)
if
(
index
==
this
->
items
-
1
)
return
;
return
;
Object
*
temp
=
this
->
array
[
index
];
Object
*
temp
=
this
->
array
[
index
];
...
@@ -179,13 +179,13 @@ void TypedVector_moveDown(TypedVector* this, int index) {
...
@@ -179,13 +179,13 @@ void TypedVector_moveDown(TypedVector* this, int index) {
this
->
array
[
index
+
1
]
=
temp
;
this
->
array
[
index
+
1
]
=
temp
;
}
}
void
Typed
Vector_set
(
Typed
Vector
*
this
,
int
index
,
void
*
data_
)
{
void
Vector_set
(
Vector
*
this
,
int
index
,
void
*
data_
)
{
assert
(
index
>=
0
);
assert
(
index
>=
0
);
assert
(((
Object
*
)
data_
)
->
class
==
this
->
vectorType
);
assert
(((
Object
*
)
data_
)
->
class
==
this
->
vectorType
);
Object
*
data
=
data_
;
Object
*
data
=
data_
;
assert
(
Typed
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
Typed
Vector_checkArraySize
(
this
);
Vector_checkArraySize
(
this
);
if
(
index
>=
this
->
items
)
{
if
(
index
>=
this
->
items
)
{
this
->
items
=
index
+
1
;
this
->
items
=
index
+
1
;
}
else
{
}
else
{
...
@@ -198,44 +198,44 @@ void TypedVector_set(TypedVector* this, int index, void* data_) {
...
@@ -198,44 +198,44 @@ void TypedVector_set(TypedVector* this, int index, void* data_) {
}
}
}
}
this
->
array
[
index
]
=
data
;
this
->
array
[
index
]
=
data
;
assert
(
Typed
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
}
}
inline
Object
*
Typed
Vector_get
(
Typed
Vector
*
this
,
int
index
)
{
inline
Object
*
Vector_get
(
Vector
*
this
,
int
index
)
{
assert
(
index
<
this
->
items
);
assert
(
index
<
this
->
items
);
assert
(
Typed
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
return
this
->
array
[
index
];
return
this
->
array
[
index
];
}
}
inline
int
Typed
Vector_size
(
Typed
Vector
*
this
)
{
inline
int
Vector_size
(
Vector
*
this
)
{
assert
(
Typed
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
return
this
->
items
;
return
this
->
items
;
}
}
void
Typed
Vector_merge
(
Typed
Vector
*
this
,
Typed
Vector
*
v2
)
{
void
Vector_merge
(
Vector
*
this
,
Vector
*
v2
)
{
int
i
;
int
i
;
assert
(
Typed
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
for
(
i
=
0
;
i
<
v2
->
items
;
i
++
)
for
(
i
=
0
;
i
<
v2
->
items
;
i
++
)
Typed
Vector_add
(
this
,
v2
->
array
[
i
]);
Vector_add
(
this
,
v2
->
array
[
i
]);
v2
->
items
=
0
;
v2
->
items
=
0
;
Typed
Vector_delete
(
v2
);
Vector_delete
(
v2
);
assert
(
Typed
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
}
}
void
Typed
Vector_add
(
Typed
Vector
*
this
,
void
*
data_
)
{
void
Vector_add
(
Vector
*
this
,
void
*
data_
)
{
assert
(
data_
&&
((
Object
*
)
data_
)
->
class
==
this
->
vectorType
);
assert
(
data_
&&
((
Object
*
)
data_
)
->
class
==
this
->
vectorType
);
Object
*
data
=
data_
;
Object
*
data
=
data_
;
assert
(
Typed
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
Typed
Vector_set
(
this
,
this
->
items
,
data
);
Vector_set
(
this
,
this
->
items
,
data
);
assert
(
Typed
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
}
}
inline
int
Typed
Vector_indexOf
(
Typed
Vector
*
this
,
void
*
search_
)
{
inline
int
Vector_indexOf
(
Vector
*
this
,
void
*
search_
)
{
assert
(((
Object
*
)
search_
)
->
class
==
this
->
vectorType
);
assert
(((
Object
*
)
search_
)
->
class
==
this
->
vectorType
);
Object
*
search
=
search_
;
Object
*
search
=
search_
;
assert
(
Typed
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
int
i
;
int
i
;
...
@@ -247,11 +247,11 @@ inline int TypedVector_indexOf(TypedVector* this, void* search_) {
...
@@ -247,11 +247,11 @@ inline int TypedVector_indexOf(TypedVector* this, void* search_) {
return
-
1
;
return
-
1
;
}
}
void
Typed
Vector_foreach
(
Typed
Vector
*
this
,
Typed
Vector_procedure
f
)
{
void
Vector_foreach
(
Vector
*
this
,
Vector_procedure
f
)
{
int
i
;
int
i
;
assert
(
Typed
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
for
(
i
=
0
;
i
<
this
->
items
;
i
++
)
for
(
i
=
0
;
i
<
this
->
items
;
i
++
)
f
(
this
->
array
[
i
]);
f
(
this
->
array
[
i
]);
assert
(
Typed
Vector_isConsistent
(
this
));
assert
(
Vector_isConsistent
(
this
));
}
}
Typed
Vector.h
→
Vector.h
View file @
a853faaa
/* Do not edit this file. It was automatically genarated. */
/* Do not edit this file. It was automatically genarated. */
#ifndef HEADER_
Typed
Vector
#ifndef HEADER_Vector
#define HEADER_
Typed
Vector
#define HEADER_Vector
/*
/*
htop
htop
(C) 2004-2006 Hisham H. Muhammad
(C) 2004-2006 Hisham H. Muhammad
...
@@ -22,48 +22,48 @@ in the source distribution for its full text.
...
@@ -22,48 +22,48 @@ in the source distribution for its full text.
#define DEFAULT_SIZE -1
#define DEFAULT_SIZE -1
#endif
#endif
typedef
void
(
*
Typed
Vector_procedure
)(
void
*
);
typedef
void
(
*
Vector_procedure
)(
void
*
);
typedef
struct
Typed
Vector_
{
typedef
struct
Vector_
{
Object
**
array
;
Object
**
array
;
int
arraySize
;
int
arraySize
;
int
growthRate
;
int
growthRate
;
int
items
;
int
items
;
char
*
vectorType
;
char
*
vectorType
;
bool
owner
;
bool
owner
;
}
Typed
Vector
;
}
Vector
;
Typed
Vector
*
Typed
Vector_new
(
char
*
vectorType_
,
bool
owner
,
int
size
);
Vector
*
Vector_new
(
char
*
vectorType_
,
bool
owner
,
int
size
);
void
Typed
Vector_delete
(
Typed
Vector
*
this
);
void
Vector_delete
(
Vector
*
this
);
void
Typed
Vector_prune
(
Typed
Vector
*
this
);
void
Vector_prune
(
Vector
*
this
);
void
Typed
Vector_sort
(
Typed
Vector
*
this
);
void
Vector_sort
(
Vector
*
this
);
void
Typed
Vector_insert
(
Typed
Vector
*
this
,
int
index
,
void
*
data_
);
void
Vector_insert
(
Vector
*
this
,
int
index
,
void
*
data_
);
Object
*
Typed
Vector_take
(
Typed
Vector
*
this
,
int
index
);
Object
*
Vector_take
(
Vector
*
this
,
int
index
);
Object
*
Typed
Vector_remove
(
Typed
Vector
*
this
,
int
index
);
Object
*
Vector_remove
(
Vector
*
this
,
int
index
);
void
Typed
Vector_moveUp
(
Typed
Vector
*
this
,
int
index
);
void
Vector_moveUp
(
Vector
*
this
,
int
index
);
void
Typed
Vector_moveDown
(
Typed
Vector
*
this
,
int
index
);
void
Vector_moveDown
(
Vector
*
this
,
int
index
);
void
Typed
Vector_set
(
Typed
Vector
*
this
,
int
index
,
void
*
data_
);
void
Vector_set
(
Vector
*
this
,
int
index
,
void
*
data_
);
inline
Object
*
Typed
Vector_get
(
Typed
Vector
*
this
,
int
index
);
inline
Object
*
Vector_get
(
Vector
*
this
,
int
index
);
inline
int
Typed
Vector_size
(
Typed
Vector
*
this
);
inline
int
Vector_size
(
Vector
*
this
);
void
Typed
Vector_merge
(
Typed
Vector
*
this
,
Typed
Vector
*
v2
);
void
Vector_merge
(
Vector
*
this
,
Vector
*
v2
);
void
Typed
Vector_add
(
Typed
Vector
*
this
,
void
*
data_
);
void
Vector_add
(
Vector
*
this
,
void
*
data_
);
inline
int
Typed
Vector_indexOf
(
Typed
Vector
*
this
,
void
*
search_
);
inline
int
Vector_indexOf
(
Vector
*
this
,
void
*
search_
);
void
Typed
Vector_foreach
(
Typed
Vector
*
this
,
Typed
Vector_procedure
f
);
void
Vector_foreach
(
Vector
*
this
,
Vector_procedure
f
);
#endif
#endif
htop.c
View file @
a853faaa
...
@@ -512,7 +512,7 @@ int main(int argc, char** argv) {
...
@@ -512,7 +512,7 @@ int main(int argc, char** argv) {
ListBox
*
lbu
=
ListBox_new
(
0
,
0
,
0
,
0
,
LISTITEM_CLASS
,
true
);
ListBox
*
lbu
=
ListBox_new
(
0
,
0
,
0
,
0
,
LISTITEM_CLASS
,
true
);
ListBox_setHeader
(
lbu
,
"Show processes of:"
);
ListBox_setHeader
(
lbu
,
"Show processes of:"
);
UsersTable_foreach
(
ut
,
addUserToList
,
lbu
);
UsersTable_foreach
(
ut
,
addUserToList
,
lbu
);
Typed
Vector_sort
(
lbu
->
items
);
Vector_sort
(
lbu
->
items
);
ListItem
*
allUsers
=
ListItem_new
(
"All users"
,
-
1
);
ListItem
*
allUsers
=
ListItem_new
(
"All users"
,
-
1
);
ListBox_insert
(
lbu
,
0
,
(
Object
*
)
allUsers
);
ListBox_insert
(
lbu
,
0
,
(
Object
*
)
allUsers
);
char
*
fuFunctions
[
2
]
=
{
"Show "
,
"Cancel "
};
char
*
fuFunctions
[
2
]
=
{
"Show "
,
"Cancel "
};
...
...
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