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