Commit a853faaa authored by Hisham Muhammad's avatar Hisham Muhammad
Browse files

Rename TypedVector to Vector, matching dit.

parent 7b2265b2
......@@ -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*) TypedVector_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]);
......
......@@ -16,7 +16,7 @@ typedef struct ColumnsListBox_ {
ListBox super;
Settings* settings;
TypedVector* columns;
Vector* columns;
ScreenManager* scr;
} ColumnsListBox;
......
......@@ -19,8 +19,8 @@ typedef enum HeaderSide_ {
} HeaderSide;
typedef struct Header_ {
TypedVector* leftMeters;
TypedVector* 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 = TypedVector_new(METER_CLASS, true, DEFAULT_SIZE);
this->rightMeters = TypedVector_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) {
TypedVector_delete(this->leftMeters);
TypedVector_delete(this->rightMeters);
Vector_delete(this->leftMeters);
Vector_delete(this->rightMeters);
free(this);
}
void Header_createMeter(Header* this, char* name, HeaderSide side) {
TypedVector* 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)) {
TypedVector_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) {
TypedVector* meters = side == LEFT_HEADER
Vector* meters = side == LEFT_HEADER
? this->leftMeters
: this->rightMeters;
Meter* meter = (Meter*) TypedVector_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) {
TypedVector* meters = side == LEFT_HEADER
Vector* meters = side == LEFT_HEADER
? this->leftMeters
: this->rightMeters;
Meter* meter = Meter_new(this->pl, param, type);
TypedVector_add(meters, meter);
Vector_add(meters, meter);
return meter;
}
int Header_size(Header* this, HeaderSide side) {
TypedVector* meters = side == LEFT_HEADER
Vector* meters = side == LEFT_HEADER
? this->leftMeters
: this->rightMeters;
return TypedVector_size(meters);
return Vector_size(meters);
}
char* Header_readMeterName(Header* this, int i, HeaderSide side) {
TypedVector* meters = side == LEFT_HEADER
Vector* meters = side == LEFT_HEADER
? this->leftMeters
: this->rightMeters;
Meter* meter = (Meter*) TypedVector_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) {
TypedVector* meters = side == LEFT_HEADER
Vector* meters = side == LEFT_HEADER
? this->leftMeters
: this->rightMeters;
Meter* meter = (Meter*) TypedVector_get(meters, i);
Meter* meter = (Meter*) Vector_get(meters, i);
return meter->mode;
}
void Header_defaultMeters(Header* this) {
TypedVector_add(this->leftMeters, Meter_new(this->pl, 0, &AllCPUsMeter));
TypedVector_add(this->leftMeters, Meter_new(this->pl, 0, &MemoryMeter));
TypedVector_add(this->leftMeters, Meter_new(this->pl, 0, &SwapMeter));
TypedVector_add(this->rightMeters, Meter_new(this->pl, 0, &TasksMeter));
TypedVector_add(this->rightMeters, Meter_new(this->pl, 0, &LoadAverageMeter));
TypedVector_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 < TypedVector_size(this->leftMeters); i++) {
Meter* meter = (Meter*) TypedVector_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 < TypedVector_size(this->rightMeters); i++) {
Meter* meter = (Meter*) TypedVector_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 < TypedVector_size(this->leftMeters); i++) {
Meter* meter = (Meter*) TypedVector_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 < TypedVector_size(this->rightMeters); i++) {
Meter* meter = (Meter*) TypedVector_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;
......
......@@ -21,8 +21,8 @@ typedef enum HeaderSide_ {
} HeaderSide;
typedef struct Header_ {
TypedVector* leftMeters;
TypedVector* rightMeters;
Vector* leftMeters;
Vector* rightMeters;
ProcessList* pl;
bool margin;
int height;
......
......@@ -7,7 +7,7 @@ in the source distribution for its full text.
#include "Object.h"
#include "ListBox.h"
#include "TypedVector.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;
TypedVector* 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 = TypedVector_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);
TypedVector_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);
TypedVector_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);
TypedVector_add(this->items, o);
Vector_add(this->items, o);
this->needsRedraw = true;
}
void ListBox_insert(ListBox* this, int i, Object* o) {
assert (this != NULL);
TypedVector_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);
TypedVector_set(this->items, i, o);
Vector_set(this->items, i, o);
}
Object* ListBox_get(ListBox* this, int i) {
assert (this != NULL);
return TypedVector_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 = TypedVector_remove(this->items, i);
if (this->selected > 0 && this->selected >= TypedVector_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 TypedVector_get(this->items, this->selected);
return Vector_get(this->items, this->selected);
}
void ListBox_moveSelectedUp(ListBox* this) {
assert (this != NULL);
TypedVector_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);
TypedVector_moveDown(this->items, this->selected);
if (this->selected + 1 < TypedVector_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 TypedVector_size(this->items);
return Vector_size(this->items);
}
void ListBox_setSelected(ListBox* this, int selected) {
assert (this != NULL);
selected = MAX(0, MIN(TypedVector_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 = TypedVector_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 = TypedVector_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 = TypedVector_get(this->items, this->oldSelected);
Object* oldObj = Vector_get(this->items, this->oldSelected);
RichString oldRef = RichString_new();
oldObj->display(oldObj, &oldRef);
Object* newObj = TypedVector_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 < TypedVector_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 = TypedVector_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 = TypedVector_size(this->items) - 1;
this->selected = Vector_size(this->items) - 1;
break;
}
}
......@@ -10,7 +10,7 @@ in the source distribution for its full text.
*/
#include "Object.h"
#include "TypedVector.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;
TypedVector* items;
Vector* items;
int selected;
int scrollV, scrollH;
int oldSelected;
......
......@@ -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 TypedVector.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 \
TypedVector.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
......
......@@ -14,13 +14,13 @@ typedef struct MetersListBox_ {
ListBox super;
Settings* settings;
TypedVector* meters;
Vector* meters;
ScreenManager* scr;
} MetersListBox;
}*/
MetersListBox* MetersListBox_new(Settings* settings, char* header, TypedVector* 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 < TypedVector_size(meters); i++) {
Meter* meter = (Meter*) TypedVector_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*) TypedVector_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 '-':
{
TypedVector_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 '+':
{
TypedVector_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 < TypedVector_size(this->meters)) {
TypedVector_remove(this->meters, selected);
if (selected < Vector_size(this->meters)) {
Vector_remove(this->meters, selected);
ListBox_remove(super, selected);
}
result = HANDLED;
......
......@@ -16,12 +16,12 @@ typedef struct MetersListBox_ {
ListBox super;
Settings* settings;
TypedVector* meters;
Vector* meters;
ScreenManager* scr;
} MetersListBox;
MetersListBox* MetersListBox_new(Settings* settings, char* header, TypedVector* meters, ScreenManager* scr);
MetersListBox* MetersListBox_new(Settings* settings, char* header, Vector* meters, ScreenManager* scr);
void MetersListBox_delete(Object* object);
......
......@@ -12,7 +12,7 @@ in the source distribution for its full text.
#include "ProcessList.h"
#include "Process.h"
#include "TypedVector.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_ {
TypedVector* processes;
TypedVector* 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 = TypedVector_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 = TypedVector_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 TypedVector,
// 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);
TypedVector_delete(this->processes);
TypedVector_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) {
TypedVector_prune(this->processes);
Vector_prune(this->processes);
}
void ProcessList_add(ProcessList* this, Process* p) {
TypedVector_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 = TypedVector_indexOf(this->processes, p);
TypedVector_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*) (TypedVector_get(this->processes, index));
return (Process*) (Vector_get(this->processes, index));
}
int ProcessList_size(ProcessList* this) {
return (TypedVector_size(this->processes));
return (Vector_size(this->processes));
}
/* private */
void ProcessList_buildTree(ProcessList* this, int pid, int level, int indent, int direction) {
TypedVector* children = TypedVector_new(PROCESS_CLASS, false, DEFAULT_SIZE);
Vector* children = Vector_new(PROCESS_CLASS, false, DEFAULT_SIZE);
for (int i = 0; i < TypedVector_size(this->processes); i++) {
Process* process = (Process*) (TypedVector_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*) (TypedVector_take(this->processes, i));
TypedVector_add(children, process);
Process* process = (Process*) (Vector_take(this->processes, i));
Vector_add(children, process);
i--;
}
}
int size = TypedVector_size(children);
int size = Vector_size(children);
for (int i = 0; i < size; i++) {
Process* process = (Process*) (TypedVector_get(children, i));
Process* process = (Process*) (Vector_get(children, i));
if (direction == 1)
TypedVector_add(this->processes2, process);
Vector_add(this->processes2, process);
else
TypedVector_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);
}
TypedVector_delete(children);
Vector_delete(children);
}
void ProcessList_sort(ProcessList* this) {
if (!this->treeView) {
TypedVector_sort(this->processes);
Vector_sort(this->processes);
} else {
int direction = this->direction;
int sortKey = this->sortKey;
this->sortKey = PID;
this->direction = 1;
TypedVector_sort(this->processes);
Vector_sort(this->processes);
this->sortKey = sortKey;
this->direction = direction;
Process* init = (Process*) (TypedVector_take(this->processes, 0));
Process* init = (Process*) (Vector_take(this->processes, 0));
assert(init->pid == 1);
init->indent = 0;
TypedVector_add(this->processes2, init);
Vector_add(this->processes2, init);
ProcessList_buildTree(this, init->pid, 0, 0, direction);
TypedVector* 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 < TypedVector_size(this->processes); i++) {
Process* p = (Process*) TypedVector_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 = TypedVector_size(this->processes) - 1; i >= 0; i--) {
Process* p = (Process*) TypedVector_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
......
......@@ -15,7 +15,7 @@ in the source distribution for its full text.
#endif
#include "Process.h"
#include "TypedVector.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_ {
TypedVector* processes;
TypedVector* processes2;
Vector* processes;
Vector* processes2;
Hashtable* processTable;
Process* prototype;
UsersTable* usersTable;
......
......@@ -8,7 +8,7 @@ in the source distribution for its full text.
#include "ScreenManager.h"
#include "ListBox.h"
#include "Object.h"
#include "TypedVector.h"
#include "Vector.h"
#include "FunctionBar.h"
#include "debug.h"
......@@ -29,8 +29,8 @@ typedef struct ScreenManager_ {
int x2;
int y2;
Orientation orientation;
TypedVector* items;
TypedVector* 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 = TypedVector_new(LISTBOX_CLASS, owner, DEFAULT_SIZE);
this->fuBars = TypedVector_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) {
TypedVector_delete(this->items);
TypedVector_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*) TypedVector_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
TypedVector_add(this->items, item);
Vector_add(this->items, item);
if (fuBar)
TypedVector_add(this->fuBars, fuBar);
Vector_add(this->fuBars, fuBar);
else
TypedVector_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*) TypedVector_remove(this->items, index);
TypedVector_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*) TypedVector_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*) TypedVector_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*) TypedVector_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*) TypedVector_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*) TypedVector_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*) TypedVector_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*) TypedVector_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*) TypedVector_get(this->items, focus);
lbFocus = (ListBox*) Vector_get(this->items, focus);
if (ListBox_getSize(lbFocus) == 0 && focus < this->itemCount - 1)
goto tryRight;
break;
......
......@@ -11,7 +11,7 @@ in the source distribution for its full text.
#include "ListBox.h"
#include "Object.h"
#include "TypedVector.h"
#include "Vector.h"
#include "FunctionBar.h"
#include "debug.h"
......@@ -31,10 +31,10 @@ typedef struct ScreenManager_ {
int x2;
int y2;
Orientation orientation;
TypedVector* items;
Vector* items;
int itemCount;
FunctionBar* fuBar;
TypedVector* fuBars;
Vector* fuBars;
bool owner;
} ScreenManager;
......
......@@ -5,7 +5,7 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#include "TypedVector.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(*TypedVector_procedure)(void*);
typedef void(*Vector_procedure)(void*);
typedef struct TypedVector_ {
typedef struct Vector_ {
Object **array;
int arraySize;
int growthRate;
int items;
char* vectorType;
bool owner;
} TypedVector;
} Vector;
}*/
TypedVector* TypedVector_new(char* vectorType_, bool owner, int size) {
TypedVector* this;
Vector* Vector_new(char* vectorType_, bool owner, int size) {
Vector* this;
if (size == DEFAULT_SIZE)
size = 10;
this = (TypedVector*) malloc(sizeof(TypedVector));
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 TypedVector_delete(TypedVector* 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 TypedVector_isConsistent(TypedVector* 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 TypedVector_prune(TypedVector* this) {
assert(TypedVector_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 TypedVector_sort(TypedVector* this) {
assert(TypedVector_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(TypedVector_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 TypedVector_checkArraySize(TypedVector* this) {
assert(TypedVector_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(TypedVector_isConsistent(this));
assert(Vector_isConsistent(this));
}
void TypedVector_insert(TypedVector* 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(TypedVector_isConsistent(this));
assert(Vector_isConsistent(this));
TypedVector_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(TypedVector_isConsistent(this));
assert(Vector_isConsistent(this));
}
Object* TypedVector_take(TypedVector* this, int index) {
Object* Vector_take(Vector* this, int index) {
assert(index >= 0 && index < this->items);
assert(TypedVector_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(TypedVector_isConsistent(this));
assert(Vector_isConsistent(this));
return removed;
}
Object* TypedVector_remove(TypedVector* this, int index) {
Object* removed = TypedVector_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 TypedVector_moveUp(TypedVector* this, int index) {
void Vector_moveUp(Vector* this, int index) {
assert(index >= 0 && index < this->items);
assert(TypedVector_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 TypedVector_moveDown(TypedVector* this, int index) {
void Vector_moveDown(Vector* this, int index) {
assert(index >= 0 && index < this->items);
assert(TypedVector_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 TypedVector_set(TypedVector* 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(TypedVector_isConsistent(this));
assert(Vector_isConsistent(this));
TypedVector_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(TypedVector_isConsistent(this));
assert(Vector_isConsistent(this));
}
inline Object* TypedVector_get(TypedVector* this, int index) {
inline Object* Vector_get(Vector* this, int index) {
assert(index < this->items);
assert(TypedVector_isConsistent(this));
assert(Vector_isConsistent(this));
return this->array[index];
}
inline int TypedVector_size(TypedVector* this) {
assert(TypedVector_isConsistent(this));
inline int Vector_size(Vector* this) {
assert(Vector_isConsistent(this));
return this->items;
}
void TypedVector_merge(TypedVector* this, TypedVector* v2) {
void Vector_merge(Vector* this, Vector* v2) {
int i;
assert(TypedVector_isConsistent(this));
assert(Vector_isConsistent(this));
for (i = 0; i < v2->items; i++)
TypedVector_add(this, v2->array[i]);
Vector_add(this, v2->array[i]);
v2->items = 0;
TypedVector_delete(v2);
assert(TypedVector_isConsistent(this));
Vector_delete(v2);
assert(Vector_isConsistent(this));
}
void TypedVector_add(TypedVector* this, void* data_) {
void Vector_add(Vector* this, void* data_) {
assert(data_ && ((Object*)data_)->class == this->vectorType);
Object* data = data_;
assert(TypedVector_isConsistent(this));
assert(Vector_isConsistent(this));
TypedVector_set(this, this->items, data);
assert(TypedVector_isConsistent(this));
Vector_set(this, this->items, data);
assert(Vector_isConsistent(this));
}
inline int TypedVector_indexOf(TypedVector* this, void* search_) {
inline int Vector_indexOf(Vector* this, void* search_) {
assert(((Object*)search_)->class == this->vectorType);
Object* search = search_;
assert(TypedVector_isConsistent(this));
assert(Vector_isConsistent(this));
int i;
......@@ -247,11 +247,11 @@ inline int TypedVector_indexOf(TypedVector* this, void* search_) {
return -1;
}
void TypedVector_foreach(TypedVector* this, TypedVector_procedure f) {
void Vector_foreach(Vector* this, Vector_procedure f) {
int i;
assert(TypedVector_isConsistent(this));
assert(Vector_isConsistent(this));
for (i = 0; i < this->items; i++)
f(this->array[i]);
assert(TypedVector_isConsistent(this));
assert(Vector_isConsistent(this));
}
/* Do not edit this file. It was automatically genarated. */
#ifndef HEADER_TypedVector
#define HEADER_TypedVector
#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(*TypedVector_procedure)(void*);
typedef void(*Vector_procedure)(void*);
typedef struct TypedVector_ {
typedef struct Vector_ {
Object **array;
int arraySize;
int growthRate;
int items;
char* vectorType;
bool owner;
} TypedVector;
} Vector;
TypedVector* TypedVector_new(char* vectorType_, bool owner, int size);
Vector* Vector_new(char* vectorType_, bool owner, int size);
void TypedVector_delete(TypedVector* this);
void Vector_delete(Vector* this);
void TypedVector_prune(TypedVector* this);
void Vector_prune(Vector* this);
void TypedVector_sort(TypedVector* this);
void Vector_sort(Vector* this);
void TypedVector_insert(TypedVector* this, int index, void* data_);
void Vector_insert(Vector* this, int index, void* data_);
Object* TypedVector_take(TypedVector* this, int index);
Object* Vector_take(Vector* this, int index);
Object* TypedVector_remove(TypedVector* this, int index);
Object* Vector_remove(Vector* this, int index);
void TypedVector_moveUp(TypedVector* this, int index);
void Vector_moveUp(Vector* this, int index);
void TypedVector_moveDown(TypedVector* this, int index);
void Vector_moveDown(Vector* this, int index);
void TypedVector_set(TypedVector* this, int index, void* data_);
void Vector_set(Vector* this, int index, void* data_);
inline Object* TypedVector_get(TypedVector* this, int index);
inline Object* Vector_get(Vector* this, int index);
inline int TypedVector_size(TypedVector* this);
inline int Vector_size(Vector* this);
void TypedVector_merge(TypedVector* this, TypedVector* v2);
void Vector_merge(Vector* this, Vector* v2);
void TypedVector_add(TypedVector* this, void* data_);
void Vector_add(Vector* this, void* data_);
inline int TypedVector_indexOf(TypedVector* this, void* search_);
inline int Vector_indexOf(Vector* this, void* search_);
void TypedVector_foreach(TypedVector* this, TypedVector_procedure f);
void Vector_foreach(Vector* this, Vector_procedure f);
#endif
......@@ -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);
TypedVector_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 "};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment