From e2b58f0ab81b2aafeb8c29a69abad7829fa21ab3 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 11 Apr 2016 13:00:30 +0200 Subject: Imported Upstream version 1.0.1 --- ProcessList.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 68 insertions(+), 16 deletions(-) (limited to 'ProcessList.c') diff --git a/ProcessList.c b/ProcessList.c index be01ca6..1f47408 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -5,19 +5,13 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#ifndef CONFIG_H -#define CONFIG_H -#include "config.h" -#endif - #include "ProcessList.h" -#include "Process.h" -#include "Vector.h" -#include "UsersTable.h" -#include "Hashtable.h" + +#include "CRT.h" #include "String.h" -#include +#include +#include #include #include #include @@ -25,14 +19,19 @@ in the source distribution for its full text. #include #include #include -#include #include #include - -#include "debug.h" +#include +#include #include /*{ +#include "Vector.h" +#include "Hashtable.h" +#include "UsersTable.h" +#include "Panel.h" +#include "Process.h" +#include #ifndef PROCDIR #define PROCDIR "/proc" @@ -109,6 +108,13 @@ typedef struct ProcessList_ { Hashtable* processTable; UsersTable* usersTable; + Panel* panel; + int following; + bool userOnly; + uid_t userId; + bool filtering; + const char* incFilter; + int cpuCount; int totalTasks; int userlandThreads; @@ -243,6 +249,10 @@ void ProcessList_delete(ProcessList* this) { free(this); } +void ProcessList_setPanel(ProcessList* this, Panel* panel) { + this->panel = panel; +} + void ProcessList_invertSortOrder(ProcessList* this) { if (this->direction == 1) this->direction = -1; @@ -605,7 +615,7 @@ static bool ProcessList_readCmdlineFile(Process* process, const char* dirname, c command[amtRead] = '\0'; fclose(file); free(process->comm); - process->comm = String_copy(command); + process->comm = strdup(command); return true; } @@ -698,11 +708,11 @@ static bool ProcessList_processEntries(ProcessList* this, const char* dirname, P if (process->state == 'Z') { free(process->comm); - process->comm = String_copy(command); + process->comm = strdup(command); } else if (Process_isThread(process)) { if (this->showThreadNames || Process_isKernelThread(process) || process->state == 'Z') { free(process->comm); - process->comm = String_copy(command); + process->comm = strdup(command); } else if (this->showingThreadNames) { if (! ProcessList_readCmdlineFile(process, dirname, name)) goto errorReadingProcess; @@ -888,3 +898,45 @@ void ProcessList_expandTree(ProcessList* this) { process->showChildren = true; } } + +void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, bool userOnly, uid_t userId, bool filtering, const char* incFilter) { + if (!flags) { + following = this->following; + userOnly = this->userOnly; + userId = this->userId; + filtering = this->filtering; + incFilter = this->incFilter; + } else { + this->following = following; + this->userOnly = userOnly; + this->userId = userId; + this->filtering = filtering; + this->incFilter = incFilter; + } + + int currPos = Panel_getSelectedIndex(this->panel); + pid_t currPid = following ? following : 0; + int currScrollV = this->panel->scrollV; + + Panel_prune(this->panel); + int size = ProcessList_size(this); + int idx = 0; + for (int i = 0; i < size; i++) { + bool hidden = false; + Process* p = ProcessList_get(this, i); + + if ( (!p->show) + || (userOnly && (p->st_uid != userId)) + || (filtering && !(String_contains_i(p->comm, incFilter))) ) + hidden = true; + + if (!hidden) { + Panel_set(this->panel, idx, (Object*)p); + if ((following == -1 && idx == currPos) || (following != -1 && p->pid == currPid)) { + Panel_setSelected(this->panel, idx); + this->panel->scrollV = currScrollV; + } + idx++; + } + } +} -- cgit v1.2.3