summaryrefslogtreecommitdiffstats
path: root/Process.c
diff options
context:
space:
mode:
Diffstat (limited to 'Process.c')
-rw-r--r--Process.c71
1 files changed, 44 insertions, 27 deletions
diff --git a/Process.c b/Process.c
index 842232f7..72360e39 100644
--- a/Process.c
+++ b/Process.c
@@ -43,7 +43,9 @@ static char Process_titleBuffer[20][20];
void Process_setupColumnWidths() {
int maxPid = Platform_getMaxPid();
- if (maxPid == -1) return;
+ if (maxPid == -1)
+ return;
+
int digits = ceil(log10(maxPid));
assert(digits < 20);
for (int i = 0; Process_pidColumns[i].label; i++) {
@@ -74,7 +76,7 @@ void Process_humanNumber(RichString* str, unsigned long long number, bool colori
RichString_appendn(str, processColor, buffer, len);
} else if (number < 100000) {
//2 digit MB, 3 digit KB
- len = snprintf(buffer, 10, "%2llu", number/1000);
+ len = snprintf(buffer, 10, "%2llu", number / 1000);
RichString_appendn(str, processMegabytesColor, buffer, len);
number %= 1000;
len = snprintf(buffer, 10, "%03llu ", number);
@@ -87,7 +89,7 @@ void Process_humanNumber(RichString* str, unsigned long long number, bool colori
} else if (number < 10000 * ONE_K) {
//1 digit GB, 3 digit MB
number /= ONE_K;
- len = snprintf(buffer, 10, "%1llu", number/1000);
+ len = snprintf(buffer, 10, "%1llu", number / 1000);
RichString_appendn(str, processGigabytesColor, buffer, len);
number %= 1000;
len = snprintf(buffer, 10, "%03lluM ", number);
@@ -95,7 +97,7 @@ void Process_humanNumber(RichString* str, unsigned long long number, bool colori
} else if (number < 100000 * ONE_K) {
//2 digit GB, 1 digit MB
number /= 100 * ONE_K;
- len = snprintf(buffer, 10, "%2llu", number/10);
+ len = snprintf(buffer, 10, "%2llu", number / 10);
RichString_appendn(str, processGigabytesColor, buffer, len);
number %= 10;
len = snprintf(buffer, 10, ".%1lluG ", number);
@@ -108,14 +110,14 @@ void Process_humanNumber(RichString* str, unsigned long long number, bool colori
} else if (number < 10000ULL * ONE_M) {
//1 digit TB, 3 digit GB
number /= ONE_M;
- len = snprintf(buffer, 10, "%1llu", number/1000);
+ len = snprintf(buffer, 10, "%1llu", number / 1000);
RichString_appendn(str, largeNumberColor, buffer, len);
number %= 1000;
len = snprintf(buffer, 10, "%03lluG ", number);
RichString_appendn(str, processGigabytesColor, buffer, len);
} else {
//2 digit TB and above
- len = snprintf(buffer, 10, "%4.1lfT ", (double)number/ONE_G);
+ len = snprintf(buffer, 10, "%4.1lfT ", (double)number / ONE_G);
RichString_appendn(str, largeNumberColor, buffer, len);
}
}
@@ -142,18 +144,18 @@ void Process_colorNumber(RichString* str, unsigned long long number, bool colori
} else if (number >= 100LL * ONE_DECIMAL_T) {
xSnprintf(buffer, 13, "%11llu ", number / ONE_DECIMAL_M);
RichString_appendn(str, largeNumberColor, buffer, 8);
- RichString_appendn(str, processMegabytesColor, buffer+8, 4);
+ RichString_appendn(str, processMegabytesColor, buffer + 8, 4);
} else if (number >= 10LL * ONE_DECIMAL_G) {
xSnprintf(buffer, 13, "%11llu ", number / ONE_DECIMAL_K);
RichString_appendn(str, largeNumberColor, buffer, 5);
- RichString_appendn(str, processMegabytesColor, buffer+5, 3);
- RichString_appendn(str, processColor, buffer+8, 4);
+ RichString_appendn(str, processMegabytesColor, buffer + 5, 3);
+ RichString_appendn(str, processColor, buffer + 8, 4);
} else {
xSnprintf(buffer, 13, "%11llu ", number);
RichString_appendn(str, largeNumberColor, buffer, 2);
- RichString_appendn(str, processMegabytesColor, buffer+2, 3);
- RichString_appendn(str, processColor, buffer+5, 3);
- RichString_appendn(str, processShadowColor, buffer+8, 4);
+ RichString_appendn(str, processMegabytesColor, buffer + 2, 3);
+ RichString_appendn(str, processColor, buffer + 5, 3);
+ RichString_appendn(str, processShadowColor, buffer + 8, 4);
}
}
@@ -201,10 +203,11 @@ static inline void Process_writeCommand(const Process* this, int attr, int basea
}
}
if (!finish) {
- if (this->settings->showProgramPath)
+ if (this->settings->showProgramPath) {
start += basename;
- else
+ } else {
comm += basename;
+ }
finish = this->basenameOffset - basename;
}
finish += start - 1;
@@ -212,8 +215,9 @@ static inline void Process_writeCommand(const Process* this, int attr, int basea
RichString_append(str, attr, comm);
- if (this->settings->highlightBaseName)
+ if (this->settings->highlightBaseName) {
RichString_setAttrn(str, baseattr, start, finish);
+ }
}
void Process_outputRate(RichString* str, char* buffer, int n, double rate, int coloring) {
@@ -285,15 +289,19 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field
bool lastItem = (this->indent < 0);
int indent = (this->indent < 0 ? -this->indent : this->indent);
- for (int i = 0; i < 32; i++)
- if (indent & (1U << i))
- maxIndent = i+1;
- for (int i = 0; i < maxIndent - 1; i++) {
+ for (int i = 0; i < 32; i++) {
+ if (indent & (1U << i)) {
+ maxIndent = i + 1;
+ }
+ }
+
+ for (int i = 0; i < maxIndent - 1; i++) {
int written, ret;
- if (indent & (1 << i))
+ if (indent & (1 << i)) {
ret = snprintf(buf, n, "%s ", CRT_treeStr[TREE_STR_VERT]);
- else
+ } else {
ret = snprintf(buf, n, " ");
+ }
if (ret < 0 || ret >= n) {
written = n;
} else {
@@ -325,7 +333,7 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field
case PID: xSnprintf(buffer, n, Process_pidFormat, this->pid); break;
case PPID: xSnprintf(buffer, n, Process_pidFormat, this->ppid); break;
case PRIORITY: {
- if(this->priority <= -100)
+ if (this->priority <= -100)
xSnprintf(buffer, n, " RT ");
else
xSnprintf(buffer, n, "%3ld ", this->priority);
@@ -377,10 +385,15 @@ void Process_display(const Object* cast, RichString* out) {
RichString_prune(out);
for (int i = 0; fields[i]; i++)
As_Process(this)->writeField(this, out, fields[i]);
- if (this->settings->shadowOtherUsers && (int)this->st_uid != Process_getuid)
+
+ if (this->settings->shadowOtherUsers && (int)this->st_uid != Process_getuid) {
RichString_setAttr(out, CRT_colors[PROCESS_SHADOW]);
- if (this->tag == true)
+ }
+
+ if (this->tag == true) {
RichString_setAttr(out, CRT_colors[PROCESS_TAG]);
+ }
+
assert(out->chlen > 0);
}
@@ -406,7 +419,10 @@ void Process_init(Process* this, const struct Settings_* settings) {
this->show = true;
this->updated = false;
this->basenameOffset = -1;
- if (Process_getuid == -1) Process_getuid = getuid();
+
+ if (Process_getuid == -1) {
+ Process_getuid = getuid();
+ }
}
void Process_toggleTag(Process* this) {
@@ -483,10 +499,11 @@ long Process_compare(const void* v1, const void* v2) {
case SESSION:
return (p1->session - p2->session);
case STARTTIME: {
- if (p1->starttime_ctime == p2->starttime_ctime)
+ if (p1->starttime_ctime == p2->starttime_ctime) {
return (p1->pid - p2->pid);
- else
+ } else {
return (p1->starttime_ctime - p2->starttime_ctime);
+ }
}
case STATE:
return (Process_sortState(p1->state) - Process_sortState(p2->state));