summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2014-02-27 17:11:23 -0300
committerHisham Muhammad <hisham@gobolinux.org>2014-02-27 17:11:23 -0300
commitf2a190b0e91947c645698c568b8fd55c59da90a0 (patch)
tree7bf8983507aa4dc72da2b76796da085f572e223f
parent61bd770689be132ffc64bc585d70721ffb0bb10e (diff)
New logic for highlighting basenames with spaces
-rw-r--r--Process.c18
-rw-r--r--Process.h1
-rw-r--r--ProcessList.c14
3 files changed, 24 insertions, 9 deletions
diff --git a/Process.c b/Process.c
index 6568bba0..04804810 100644
--- a/Process.c
+++ b/Process.c
@@ -165,6 +165,7 @@ typedef struct Process_ {
#endif
int exit_signal;
+ int basenameOffset;
bool updated;
#ifdef DEBUG
@@ -404,14 +405,19 @@ static inline void Process_writeCommand(Process* this, int attr, int baseattr, R
RichString_append(str, attr, this->comm);
if (this->pl->highlightBaseName) {
int finish = RichString_size(str) - 1;
- int space = RichString_findChar(str, ' ', start);
+ int space = start + this->basenameOffset;
if (space != -1)
finish = space - 1;
- for (;;) {
- int slash = RichString_findChar(str, '/', start);
- if (slash == -1 || slash > finish)
- break;
- start = slash + 1;
+ int colon = RichString_findChar(str, ':', start);
+ if (colon != -1 && colon < finish) {
+ finish = colon;
+ } else {
+ for (int i = finish - start; i > 0; i--) {
+ if (this->comm[i] == '/') {
+ start += i+1;
+ break;
+ }
+ }
}
RichString_setAttrn(str, baseattr, start, finish);
}
diff --git a/Process.h b/Process.h
index 626f1a87..a8234776 100644
--- a/Process.h
+++ b/Process.h
@@ -144,6 +144,7 @@ typedef struct Process_ {
#endif
int exit_signal;
+ int basenameOffset;
bool updated;
#ifdef DEBUG
diff --git a/ProcessList.c b/ProcessList.c
index 4676a264..850715e8 100644
--- a/ProcessList.c
+++ b/ProcessList.c
@@ -667,15 +667,15 @@ static void ProcessList_readOomData(Process* process, const char* dirname, const
snprintf(filename, MAX_NAME, "%s/%s/oom_score", dirname, name);
FILE* file = fopen(filename, "r");
if (!file)
- return;
+ return;
char buffer[256];
if (!fgets(buffer, 255, file)) {
- return;
+ return;
}
unsigned int oom;
int ok = sscanf(buffer, "%u", &oom);
if (ok >= 1) {
- process->oom = oom;
+ process->oom = oom;
}
fclose(file);
}
@@ -695,12 +695,20 @@ static bool ProcessList_readCmdlineFile(Process* process, const char* dirname, c
char command[4096+1]; // max cmdline length on Linux
int amtRead = xread(fd, command, sizeof(command) - 1);
close(fd);
+ int tokenEnd = 0;
if (amtRead > 0) {
for (int i = 0; i < amtRead; i++)
if (command[i] == '\0' || command[i] == '\n') {
+ if (tokenEnd == 0) {
+ tokenEnd = i;
+ }
command[i] = ' ';
}
}
+ if (tokenEnd == 0) {
+ tokenEnd = amtRead;
+ }
+ process->basenameOffset = tokenEnd;
command[amtRead] = '\0';
free(process->comm);
process->comm = strdup(command);

© 2014-2024 Faster IT GmbH | imprint | privacy policy